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;
/**
* This class represents the information of file transfer operation payload.
*/
@ApiModel(value = "FileTransfer",
description = "This class carries all information related to file transfer operation.")
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)
private String ftpPassword;
@ApiModelProperty(name = "savingDirectory", value = "savingDirectory", required = true)
private String savingDirectory;
@ApiModelProperty(name = "fileLocation", value = "fileLocation", required = true)
private String fileLocation;
public String getFileURL() {
return fileURL;
@ -54,11 +56,11 @@ public class FileTransfer extends AndroidOperation implements Serializable {
this.ftpPassword = ftpPassword;
}
public String getSavingDirectory() {
return savingDirectory;
public String getFileLocation() {
return fileLocation;
}
public void setSavingDirectory(String savingDirectory) {
this.savingDirectory = savingDirectory;
public void setFileLocation(String fileLocation) {
this.fileLocation = fileLocation;
}
}

@ -30,9 +30,12 @@ import java.util.List;
description = "FileTransfer related Information.")
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;
@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)
private FileTransfer operation;
@ -52,4 +55,11 @@ public class FileTransferBeanWrapper {
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();
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.setEnabled(true);
operation.setPayLoad(file.toJSON());
@ -1065,7 +1069,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
try {
URL url = new URL(apkUrl);
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.";
log.error(errorMessage);
throw new BadRequestException(

@ -74,7 +74,8 @@ public final class AndroidConstants {
}
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_LOCATION = "DEVICE_LOCATION";
public static final String WIFI = "WIFI";

@ -71,6 +71,10 @@
<i class="icon fw fw-error"></i><span></span>
</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">
<form action="{{params.0.uri}}" method="{{params.0.method}}"
style="padding-bottom: 20px;"
@ -94,6 +98,24 @@
<br/>
{{/each}}
{{#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"}}
<input type="{{this.type}}" id="{{this.id}}"
class="checkbox"

@ -32,6 +32,20 @@ var resetLoader = function () {
$('#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) {
$("#btnSend").addClass("hidden");
$("#lbl-execution").removeClass("hidden");
@ -57,6 +71,8 @@ function submitForm(formId) {
payload[input.attr("id")] = input.val();
} else if (input.attr("type") == "checkbox") {
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;
case "FILE_TRANSFER":
if (!payload.fileURL) {
returnVal = "Please enter the URL of the file in server";
}else if(!payload.ftpPassword){
if (payload.upload && !payload.fileURL) {
returnVal = "Please enter the FTP URL of the file";
} 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";
}else if(!payload.savingDirectory){
returnVal = "Please enter the location in device where you wan to save the file";
} else if (!payload.upload && !payload.fileLocation) {
returnVal = "Please specify the file location in device";
}
break;
default:
@ -254,8 +273,9 @@ var generatePayload = function (operationCode, operationData, deviceList) {
"operation": {
"fileURL": operationData["fileURL"],
"ftpPassword": operationData["ftpPassword"],
"savingDirectory": operationData["savingDirectory"]
}
"fileLocation": operationData["fileLocation"]
},
"upload": operationData["upload"]
};
break;
case androidOperationConstants["ENCRYPT_STORAGE_OPERATION_CODE"]:

@ -139,11 +139,19 @@
"FILE_TRANSFER": {
"icon": "fw-save",
"formParams": [
{
"type": "bi-radio",
"name": "selection",
"id": "upload",
"optional": false,
"yesValue": "Upload by the Device",
"noValue": "Upload to the Device"
},
{
"type": "text",
"id": "fileURL",
"optional": false,
"label": "FTP URL of the file to be sent"
"label": "FTP URL of the folder to upload file"
},
{
"type": "password",
@ -153,9 +161,9 @@
},
{
"type": "text",
"id": "savingDirectory",
"id": "fileLocation",
"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"

Loading…
Cancel
Save