From 212dcae8e729d69802450df17bab44af13ddf79a Mon Sep 17 00:00:00 2001 From: harshanl Date: Thu, 22 Sep 2016 18:24:58 +0530 Subject: [PATCH] Added scheduled time to App-install operation --- .../android/bean/ApplicationInstallation.java | 10 ++++++++ .../bean/ApplicationUninstallation.java | 11 --------- .../android/bean/ApplicationUpdate.java | 2 +- .../DeviceManagementAdminServiceImpl.java | 24 +++++++++++++++++++ 4 files changed, 35 insertions(+), 12 deletions(-) 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/ApplicationInstallation.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/ApplicationInstallation.java index 454dc905a8..8a69e2eff9 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/ApplicationInstallation.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/ApplicationInstallation.java @@ -44,6 +44,8 @@ public class ApplicationInstallation extends AndroidOperation implements Seriali @ApiModelProperty(name = "url", value = "Application URL", required = true) private String url; + @ApiModelProperty(name = "schedule", value = "Application install schedule.", required = false) + private String schedule; public String getAppIdentifier() { return appIdentifier; @@ -68,4 +70,12 @@ public class ApplicationInstallation extends AndroidOperation implements Seriali public void setUrl(String url) { this.url = url; } + + public String getSchedule() { + return schedule; + } + + public void setSchedule(String schedule) { + this.schedule = schedule; + } } 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/ApplicationUninstallation.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/ApplicationUninstallation.java index 5c078f87db..a5356ae59c 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/ApplicationUninstallation.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/ApplicationUninstallation.java @@ -43,10 +43,6 @@ public class ApplicationUninstallation extends AndroidOperation implements Seria @Pattern(regexp = "^[A-Za-z]*$") private String type; - @ApiModelProperty(name = "name", value = "The name of the application.", required = true) - @Size(min = 2, max = 45) - private String name; - public String getAppIdentifier() { return appIdentifier; } @@ -63,11 +59,4 @@ public class ApplicationUninstallation extends AndroidOperation implements Seria this.type = type; } - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } } 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/ApplicationUpdate.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/ApplicationUpdate.java index 14f7c31dbc..95241b4443 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/ApplicationUpdate.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/ApplicationUpdate.java @@ -44,7 +44,7 @@ public class ApplicationUpdate extends AndroidOperation implements Serializable private String type; @ApiModelProperty(name = "url", value = "The URL of the application.", required = true) private String url; - @ApiModelProperty(name = "schedule", value = "Application update schedule.", required = true) + @ApiModelProperty(name = "schedule", value = "Application update schedule.", required = false) private String schedule; public String getAppIdentifier() { 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 11840a6697..71e0a1c30d 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 @@ -534,6 +534,18 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe throw new BadRequestException( new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } + String scheduledTime = applicationInstallationBeanWrapper.getOperation().getSchedule(); + if (scheduledTime != null && !scheduledTime.isEmpty()) { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); + try { + String formattedScheduledDate = format.format(format.parse(scheduledTime)); + applicationInstallationBeanWrapper.getOperation().setSchedule(formattedScheduledDate); + } catch (ParseException e) { + String errorMessage = "Invalid date string is provided in for schedule parameter"; + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + } ApplicationInstallation applicationInstallation = applicationInstallationBeanWrapper.getOperation(); JSONObject payload = new JSONObject(applicationInstallation.toJSON()); @@ -615,6 +627,18 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe throw new BadRequestException( new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } + String scheduledTime = applicationUpdateBeanWrapper.getOperation().getSchedule(); + if (scheduledTime != null && !scheduledTime.isEmpty()) { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); + try { + String formattedScheduledDate = format.format(format.parse(scheduledTime)); + applicationUpdateBeanWrapper.getOperation().setSchedule(formattedScheduledDate); + } catch (ParseException e) { + String errorMessage = "Invalid date string is provided in for schedule parameter"; + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + } ApplicationUpdate applicationUpdate = applicationUpdateBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.UPDATE_APPLICATION);