diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/FileTransfer.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/FileTransfer.java index 0ecf3d4fe6..2e8af23a7c 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/FileTransfer.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/FileTransfer.java @@ -33,6 +33,9 @@ public class FileTransfer extends AndroidOperation implements Serializable { @ApiModelProperty(name = "fileURL", value = "File URL", required = true) private String fileURL; + @ApiModelProperty(name = "userName", value = "User Name", required = true) + private String userName; + @ApiModelProperty(name = "ftpPassword", value = "FTP password", required = true) private String ftpPassword; @@ -62,4 +65,12 @@ public class FileTransfer extends AndroidOperation implements Serializable { public void setFileLocation(String fileLocation) { this.fileLocation = fileLocation; } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java index 6fa0d1fd2a..eb25d917b8 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java @@ -94,16 +94,17 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe @Path("/file-transfer") @Override public Response fileTransfer(FileTransferBeanWrapper fileTransferBeanWrapper) { - try { - if (fileTransferBeanWrapper == null || fileTransferBeanWrapper.getOperation() == null) { - String errorMessage = "The payload of the file transfer operation is incorrect."; - log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); - } - if (fileTransferBeanWrapper.getDeviceIDs() != null && log.isDebugEnabled()) { - log.debug("Invoking Android file transfer operation for " + fileTransferBeanWrapper.getDeviceIDs()); - } + try { + if (fileTransferBeanWrapper == null || fileTransferBeanWrapper.getOperation() == null + || fileTransferBeanWrapper.getDeviceIDs() == null) { + String errorMessage = "The payload of the file transfer operation is incorrect."; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + if (log.isDebugEnabled()) { + log.debug("Invoking Android file transfer operation for " + fileTransferBeanWrapper.getDeviceIDs()); + } FileTransfer file = fileTransferBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); if (fileTransferBeanWrapper.isUpload()) { @@ -1105,7 +1106,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } } - private static void validateScheduleDate(String dateString){ + private static void validateScheduleDate(String dateString) { try { if (dateString != null && !dateString.isEmpty()) { SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-bar/public/js/operation-bar.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-bar/public/js/operation-bar.js index ea8c424da3..8d7b74d779 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-bar/public/js/operation-bar.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-bar/public/js/operation-bar.js @@ -24,6 +24,9 @@ function operationSelect(selection) { $(modalPopupContent).addClass("operation-data"); $(modalPopupContent).html($(" .operation[data-operation-code=" + selection + "]").html()); $(modalPopupContent).data("operation-code", selection); + if (selection === "FILE_TRANSFER") { + fillUserName(); + } showPopup(); } @@ -32,6 +35,24 @@ var resetLoader = function () { $('#lbl-execution').addClass("hidden"); }; +function fillUserName() { + var inputBox = document.getElementById('fileURL'); + var regexp = ':\/\/[^\/]*@'; + var pattern = new RegExp(regexp); + jQuery(inputBox).on('input', function () { + var fileUrl = inputBox.value; + var res = pattern.test(fileUrl); + if (res) { + var name = fileUrl.match(regexp).toString(); + document.getElementById('userName').value = name.substring(3, name.length - 1); + } else { + document.getElementById('userName').value = ""; + document.getElementById('userName').placeholder = "User Name" + } + } + ); +} + /** * This changes the text box label when the operation is toggled between FILE UPLOAD and FILE DOWNLOAD * and shows an info label for FILE UPLOAD regarding saving location. @@ -42,13 +63,14 @@ function changeLabel(type) { 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 = "HTTP/FTP URL of the file"; + document.getElementById('fileURL').placeholder = "File URL"; 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('fileURL').placeholder = "URL for file upload"; document.getElementById('fileLocation').placeholder = "File location in the device"; } + fillUserName(); } function submitForm(formId) { @@ -97,7 +119,7 @@ function submitForm(formId) { var defaultStatusClasses = "fw fw-stack-1x"; var content = $("#operation-response-template").find(".content"); var title = content.find("#title"); - title.attr("class","center-block text-center"); + title.attr("class", "center-block text-center"); var statusIcon = content.find("#status-icon"); var description = content.find("#description"); description.html(""); @@ -275,6 +297,7 @@ var generatePayload = function (operationCode, operationData, deviceList) { payload = { "operation": { "fileURL": operationData["fileURL"], + "userName": operationData["userName"], "ftpPassword": operationData["ftpPassword"], "fileLocation": operationData["fileLocation"] }, diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/private/config.json b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/private/config.json index 05b8e1432e..de5969c5c2 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/private/config.json +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/private/config.json @@ -151,13 +151,19 @@ "type": "text", "id": "fileURL", "optional": false, - "label": "FTP URL of the folder to upload file" + "label": "URL for file upload" + }, + { + "type": "text", + "id": "userName", + "optional": false, + "label": "User Name (Ignore if you don't need authentication.)" }, { "type": "password", "id": "ftpPassword", "optional": false, - "label": "Password (Ignore if you don't need any)" + "label": "Password (Ignore if you don't need authentication.)" }, { "type": "text",