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 f0253db39..7f1b92178 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 @@ -40,6 +40,9 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; @Path("/admin/devices") @@ -48,6 +51,7 @@ import java.util.List; public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminService { private static final Log log = LogFactory.getLog(DeviceManagementAdminServiceImpl.class); + private static final String DATE_FORMAT = "MM-dd-yyyy hh:mm a"; @POST @Path("/lock-devices") @@ -573,6 +577,14 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } UpgradeFirmware upgradeFirmware = upgradeFirmwareBeanWrapper.getOperation(); + + //validate date + if(upgradeFirmware != null && upgradeFirmware.getSchedule() != null){ + SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); + sdf.setLenient(false); + Date date = sdf.parse(upgradeFirmware.getSchedule()); + } + ProfileOperation operation = new ProfileOperation(); operation.setCode(AndroidConstants.OperationCodes.UPGRADE_FIRMWARE); operation.setType(Operation.Type.PROFILE); @@ -588,6 +600,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe log.error(errorMessage, e); throw new UnexpectedServerErrorException( new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + }catch (ParseException e) { + String errorMessage = "Issue in validating the schedule date"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } }