fileTransferfeature, uploading files from device to ftp server

revert-dabc3590
Nirothipan 7 years ago
parent 80941b8d2b
commit c9bac2c860

@ -23,7 +23,9 @@ import org.wso2.carbon.mdm.services.android.bean.AndroidOperation;
import java.io.Serializable; import java.io.Serializable;
/**
* This class represents the information of file transfer operation payload.
*/
@ApiModel(value = "FileTransfer", @ApiModel(value = "FileTransfer",
description = "This class carries all information related to file transfer operation.") description = "This class carries all information related to file transfer operation.")
public class FileTransfer extends AndroidOperation implements Serializable { public class FileTransfer extends AndroidOperation implements Serializable {
@ -34,8 +36,8 @@ public class FileTransfer extends AndroidOperation implements Serializable {
@ApiModelProperty(name = "ftpPassword", value = "FTP password", required = true) @ApiModelProperty(name = "ftpPassword", value = "FTP password", required = true)
private String ftpPassword; private String ftpPassword;
@ApiModelProperty(name = "savingDirectory", value = "savingDirectory", required = true) @ApiModelProperty(name = "fileLocation", value = "fileLocation", required = true)
private String savingDirectory; private String fileLocation;
public String getFileURL() { public String getFileURL() {
return fileURL; return fileURL;
@ -54,11 +56,11 @@ public class FileTransfer extends AndroidOperation implements Serializable {
this.ftpPassword = ftpPassword; this.ftpPassword = ftpPassword;
} }
public String getSavingDirectory() { public String getFileLocation() {
return savingDirectory; return fileLocation;
} }
public void setSavingDirectory(String savingDirectory) { public void setFileLocation(String fileLocation) {
this.savingDirectory = savingDirectory; this.fileLocation = fileLocation;
} }
} }

@ -30,9 +30,12 @@ import java.util.List;
description = "FileTransfer related Information.") description = "FileTransfer related Information.")
public class FileTransferBeanWrapper { public class FileTransferBeanWrapper {
@ApiModelProperty(name = "deviceIDs", value = "Device id list to which the operation to be executed.", required = true) @ApiModelProperty(name = "deviceIDs", value = "Device id list of the operation to be executed.", required = true)
private List<String> deviceIDs; private List<String> deviceIDs;
@ApiModelProperty(name = "upload", value = "This is an inbound file transfer or out bound file transfer respective to the device.", required = true)
private boolean upload;
@ApiModelProperty(name = "operation", value = "Information of the File Transfer Operation.", required = true) @ApiModelProperty(name = "operation", value = "Information of the File Transfer Operation.", required = true)
private FileTransfer operation; private FileTransfer operation;
@ -52,4 +55,11 @@ public class FileTransferBeanWrapper {
this.operation = operation; this.operation = operation;
} }
public boolean isUpload() {
return upload;
}
public void setUpload(boolean upload) {
this.upload = upload;
}
} }

@ -107,7 +107,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
} }
FileTransfer file = fileTransferBeanWrapper.getOperation(); FileTransfer file = fileTransferBeanWrapper.getOperation();
ProfileOperation operation = new ProfileOperation(); ProfileOperation operation = new ProfileOperation();
operation.setCode(AndroidConstants.OperationCodes.FILE_TRANSFER); if (fileTransferBeanWrapper.isUpload()) {
operation.setCode(AndroidConstants.OperationCodes.FILE_DOWNLOAD);
} else {
operation.setCode(AndroidConstants.OperationCodes.FILE_UPLOAD);
}
operation.setType(Operation.Type.PROFILE); operation.setType(Operation.Type.PROFILE);
operation.setEnabled(true); operation.setEnabled(true);
operation.setPayLoad(file.toJSON()); operation.setPayLoad(file.toJSON());
@ -153,10 +157,10 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setPayLoad(lock.toJSON()); operation.setPayLoad(lock.toJSON());
return AndroidAPIUtils.getOperationResponse(deviceLockBeanWrapper.getDeviceIDs(), operation); return AndroidAPIUtils.getOperationResponse(deviceLockBeanWrapper.getDeviceIDs(), operation);
} catch (InvalidDeviceException e) { } catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found."; String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e); log.error(errorMessage, e);
throw new BadRequestException( throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
} catch (OperationManagementException e) { } catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance"; String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e); log.error(errorMessage, e);
@ -568,7 +572,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
try { try {
if (applicationInstallationBeanWrapper == null || applicationInstallationBeanWrapper.getOperation() == if (applicationInstallationBeanWrapper == null || applicationInstallationBeanWrapper.getOperation() ==
null) { null) {
String errorMessage = "The payload of the application installing operation is incorrect"; String errorMessage = "The payload of the application installing operation is incorrect";
log.error(errorMessage); log.error(errorMessage);
throw new BadRequestException( throw new BadRequestException(
@ -585,7 +589,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setType(Operation.Type.PROFILE); operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(applicationInstallation.toJSON()); operation.setPayLoad(applicationInstallation.toJSON());
return AndroidAPIUtils.getOperationResponse(applicationInstallationBeanWrapper.getDeviceIDs(), return AndroidAPIUtils.getOperationResponse(applicationInstallationBeanWrapper.getDeviceIDs(),
operation); operation);
} catch (JSONException e) { } catch (JSONException e) {
String errorMessage = "Invalid payload for the operation."; String errorMessage = "Invalid payload for the operation.";
log.error(errorMessage); log.error(errorMessage);
@ -1065,7 +1069,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
try { try {
URL url = new URL(apkUrl); URL url = new URL(apkUrl);
URLConnection conn = url.openConnection(); URLConnection conn = url.openConnection();
if(((HttpURLConnection) conn).getResponseCode() != HttpURLConnection.HTTP_OK) { if (((HttpURLConnection) conn).getResponseCode() != HttpURLConnection.HTTP_OK) {
String errorMessage = "URL is not pointed to a downloadable file."; String errorMessage = "URL is not pointed to a downloadable file.";
log.error(errorMessage); log.error(errorMessage);
throw new BadRequestException( throw new BadRequestException(
@ -1087,8 +1091,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
private static void validateApplicationType(String type) { private static void validateApplicationType(String type) {
if (type != null) { if (type != null) {
if (!"enterprise".equalsIgnoreCase(type) if (!"enterprise".equalsIgnoreCase(type)
&& !"public".equalsIgnoreCase(type) && !"public".equalsIgnoreCase(type)
&& !"webapp".equalsIgnoreCase(type)) { && !"webapp".equalsIgnoreCase(type)) {
String errorMessage = "Invalid application type."; String errorMessage = "Invalid application type.";
log.error(errorMessage); log.error(errorMessage);
throw new BadRequestException( throw new BadRequestException(

@ -74,7 +74,8 @@ public final class AndroidConstants {
} }
public static final String DEVICE_LOCK = "DEVICE_LOCK"; public static final String DEVICE_LOCK = "DEVICE_LOCK";
public static final String FILE_TRANSFER = "FILE_TRANSFER"; public static final String FILE_DOWNLOAD = "FILE_UPLOAD_TO_THE_DEVICE";
public static final String FILE_UPLOAD = "FILE_UPLOAD_BY_THE_DEVICE";
public static final String DEVICE_UNLOCK = "DEVICE_UNLOCK"; public static final String DEVICE_UNLOCK = "DEVICE_UNLOCK";
public static final String DEVICE_LOCATION = "DEVICE_LOCATION"; public static final String DEVICE_LOCATION = "DEVICE_LOCATION";
public static final String WIFI = "WIFI"; public static final String WIFI = "WIFI";

@ -71,6 +71,10 @@
<i class="icon fw fw-error"></i><span></span> <i class="icon fw fw-error"></i><span></span>
</div> </div>
<div id="operation-warn-msg" class="info alert-info hidden" role="alert">
<i class="icon fw fw-info"></i><span></span>
</div>
<div id="operation-form"> <div id="operation-form">
<form action="{{params.0.uri}}" method="{{params.0.method}}" <form action="{{params.0.uri}}" method="{{params.0.method}}"
style="padding-bottom: 20px;" style="padding-bottom: 20px;"
@ -94,6 +98,24 @@
<br/> <br/>
{{/each}} {{/each}}
{{#each uiParams}} {{#each uiParams}}
{{#equal this.type "bi-radio"}}
<input type="radio" id="{{this.id}}"
name="{{this.name}}"
value="{{this.yesValue}}"
checked="checked"
class="radio"
onclick="changeLabel('yes')"
data-param-type="form"/>
{{this.yesValue}}
<input type="radio" id="{{this.id}}"
name="{{this.name}}"
value="{{this.noValue}}"
class="radio"
onclick="changeLabel('no')"
data-param-type="form"/>
{{this.noValue}}
<br/> <br/>
{{/equal}}
{{#equal this.type "checkbox"}} {{#equal this.type "checkbox"}}
<input type="{{this.type}}" id="{{this.id}}" <input type="{{this.type}}" id="{{this.id}}"
class="checkbox" class="checkbox"

@ -32,6 +32,20 @@ var resetLoader = function () {
$('#lbl-execution').addClass("hidden"); $('#lbl-execution').addClass("hidden");
}; };
function changeLabel(type) {
$(".modal #operation-error-msg").addClass("hidden");
if (type == "no") {
$(".modal #operation-warn-msg span").text("File will be saved in default location if not specified.");
$(".modal #operation-warn-msg").removeClass("hidden");
document.getElementById('fileURL').placeholder = "FTP URL of the file";
document.getElementById('fileLocation').placeholder = "Location to save file in device";
} else {
$(".modal #operation-warn-msg").addClass("hidden");
document.getElementById('fileURL').placeholder = "FTP URL of the folder to upload file";
document.getElementById('fileLocation').placeholder = "File location in the device";
}
}
function submitForm(formId) { function submitForm(formId) {
$("#btnSend").addClass("hidden"); $("#btnSend").addClass("hidden");
$("#lbl-execution").removeClass("hidden"); $("#lbl-execution").removeClass("hidden");
@ -57,6 +71,8 @@ function submitForm(formId) {
payload[input.attr("id")] = input.val(); payload[input.attr("id")] = input.val();
} else if (input.attr("type") == "checkbox") { } else if (input.attr("type") == "checkbox") {
payload[input.attr("id")] = input.is(":checked"); payload[input.attr("id")] = input.is(":checked");
} else if (input.attr("type") == "radio") {
payload[input.attr("id")] = input.is(":checked");
} }
} }
}); });
@ -180,12 +196,15 @@ function validatePayload(operationCode, payload) {
} }
break; break;
case "FILE_TRANSFER": case "FILE_TRANSFER":
if (!payload.fileURL) { if (payload.upload && !payload.fileURL) {
returnVal = "Please enter the URL of the file in server"; returnVal = "Please enter the FTP URL of the file";
}else if(!payload.ftpPassword){ } else if (!payload.upload && !payload.fileURL) {
returnVal = "Please enter the FTP URL of the folder to upload file";
}
else if (!payload.ftpPassword) {
returnVal = "Please enter FTP password"; returnVal = "Please enter FTP password";
}else if(!payload.savingDirectory){ } else if (!payload.upload && !payload.fileLocation) {
returnVal = "Please enter the location in device where you wan to save the file"; returnVal = "Please specify the file location in device";
} }
break; break;
default: default:
@ -254,8 +273,9 @@ var generatePayload = function (operationCode, operationData, deviceList) {
"operation": { "operation": {
"fileURL": operationData["fileURL"], "fileURL": operationData["fileURL"],
"ftpPassword": operationData["ftpPassword"], "ftpPassword": operationData["ftpPassword"],
"savingDirectory": operationData["savingDirectory"] "fileLocation": operationData["fileLocation"]
} },
"upload": operationData["upload"]
}; };
break; break;
case androidOperationConstants["ENCRYPT_STORAGE_OPERATION_CODE"]: case androidOperationConstants["ENCRYPT_STORAGE_OPERATION_CODE"]:

@ -139,11 +139,19 @@
"FILE_TRANSFER": { "FILE_TRANSFER": {
"icon": "fw-save", "icon": "fw-save",
"formParams": [ "formParams": [
{
"type": "bi-radio",
"name": "selection",
"id": "upload",
"optional": false,
"yesValue": "Upload by the Device",
"noValue": "Upload to the Device"
},
{ {
"type": "text", "type": "text",
"id": "fileURL", "id": "fileURL",
"optional": false, "optional": false,
"label": "FTP URL of the file to be sent" "label": "FTP URL of the folder to upload file"
}, },
{ {
"type": "password", "type": "password",
@ -153,9 +161,9 @@
}, },
{ {
"type": "text", "type": "text",
"id": "savingDirectory", "id": "fileLocation",
"optional": false, "optional": false,
"label": "Location in device to save file" "label": "File location in the device"
} }
], ],
"permission": "/device-mgt/devices/owning-device/operations/android/file-transfer" "permission": "/device-mgt/devices/owning-device/operations/android/file-transfer"

Loading…
Cancel
Save