From 3836d393facb1c73e84e1ab55865a2846b32d705 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Tue, 12 Jul 2016 11:58:23 +0530 Subject: [PATCH 1/2] removing Device type from AndroidDevice bean --- .../android/bean/wrapper/AndroidDevice.java | 21 ++----------------- .../impl/DeviceManagementServiceImpl.java | 10 ++++----- 2 files changed, 6 insertions(+), 25 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/wrapper/AndroidDevice.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/wrapper/AndroidDevice.java index 4ec09db9c..9f5b7bd64 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/wrapper/AndroidDevice.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/wrapper/AndroidDevice.java @@ -41,14 +41,6 @@ public class AndroidDevice implements Serializable { @Size(min = 2, max = 45) @Pattern(regexp = "^[A-Za-z0-9]*$") private String name; - @ApiModelProperty( - name = "type", - value = "The OS type of the device.", - required = true - ) - @Size(min = 2, max = 45) - @Pattern(regexp = "^[A-Za-z]*$") - private String type; @ApiModelProperty( name = "description", value = "Additional information on the device.", @@ -93,9 +85,8 @@ public class AndroidDevice implements Serializable { public AndroidDevice() { } - public AndroidDevice(String name, String type, String description, String deviceId, EnrolmentInfo enrolmentInfo, List features, List properties) { + public AndroidDevice(String name, String description, String deviceId, EnrolmentInfo enrolmentInfo, List features, List properties) { this.name = name; - this.type = type; this.description = description; this.deviceIdentifier = deviceId; this.enrolmentInfo = enrolmentInfo; @@ -111,14 +102,6 @@ public class AndroidDevice implements Serializable { this.name = name; } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - public String getDescription() { return this.description; } @@ -176,7 +159,7 @@ public class AndroidDevice implements Serializable { } public String toString() { - return "device [name=" + this.name + ";" + "type=" + this.type + ";" + "description=" + this.description + ";" + "identifier=" + this.deviceIdentifier + ";" + "]"; + return "device [name=" + this.name + ";" + ";" + "description=" + this.description + ";" + "identifier=" + this.deviceIdentifier + ";" + "]"; } public boolean equals(Object o) { 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/DeviceManagementServiceImpl.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/DeviceManagementServiceImpl.java index 3ac5afa55..69c0c5def 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/DeviceManagementServiceImpl.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/DeviceManagementServiceImpl.java @@ -200,7 +200,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { device.setDeviceInfo(androidDevice.getDeviceInfo()); device.setDeviceIdentifier(androidDevice.getDeviceIdentifier()); device.setDescription(androidDevice.getDescription()); - device.setType(androidDevice.getType()); device.setName(androidDevice.getName()); device.setFeatures(androidDevice.getFeatures()); device.setProperties(androidDevice.getProperties()); @@ -208,23 +207,23 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { boolean status = AndroidAPIUtils.getDeviceManagementService().enrollDevice(device); PolicyManagerService policyManagerService = AndroidAPIUtils.getPolicyManagerService(); - policyManagerService.getEffectivePolicy(new DeviceIdentifier(androidDevice.getDeviceIdentifier(), androidDevice.getType())); + policyManagerService.getEffectivePolicy(new DeviceIdentifier(androidDevice.getDeviceIdentifier(), device.getType())); if (status) { return Response.status(Response.Status.OK).entity("Android device, which carries the id '" + androidDevice.getDeviceIdentifier() + "' has successfully been enrolled").build(); } else { return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Failed to enroll '" + - androidDevice.getType() + "' device, which carries the id '" + + device.getType() + "' device, which carries the id '" + androidDevice.getDeviceIdentifier() + "'").build(); } } catch (DeviceManagementException e) { - String msg = "Error occurred while enrolling the '" + androidDevice.getType() + "', which carries the id '" + + String msg = "Error occurred while enrolling the android, which carries the id '" + androidDevice.getDeviceIdentifier() + "'"; log.error(msg, e); throw new UnexpectedServerErrorException( new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); } catch (PolicyManagementException e) { - String msg = "Error occurred while enforcing default enrollment policy upon '" + androidDevice.getType() + + String msg = "Error occurred while enforcing default enrollment policy upon android " + "', which carries the id '" + androidDevice.getDeviceIdentifier() + "'"; log.error(msg, e); @@ -267,7 +266,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { device.setDeviceInfo(androidDevice.getDeviceInfo()); device.setDeviceIdentifier(androidDevice.getDeviceIdentifier()); device.setDescription(androidDevice.getDescription()); - device.setType(androidDevice.getType()); device.setName(androidDevice.getName()); device.setFeatures(androidDevice.getFeatures()); device.setProperties(androidDevice.getProperties()); From 672d90472bfa7b20cbe86c2349f1f86fe557471e Mon Sep 17 00:00:00 2001 From: hasuniea Date: Tue, 12 Jul 2016 12:48:09 +0530 Subject: [PATCH 2/2] adding validation --- .../services/android/services/DeviceManagementService.java | 6 ------ 1 file changed, 6 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/services/DeviceManagementService.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/DeviceManagementService.java index 3c8bbe585..f760130ed 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/DeviceManagementService.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/DeviceManagementService.java @@ -293,9 +293,6 @@ public interface DeviceManagementService { @ApiParam( name = "id", value = "Device Identifier") - @NotNull - @Size(min = 2 , max = 45) - @Pattern(regexp = "^[A-Za-z0-9]*$") @PathParam("id") String id, @ApiParam( name = "device", @@ -325,9 +322,6 @@ public interface DeviceManagementService { @ApiParam( name = "id", value = "Device Identifier") - @NotNull - @Size(min = 2 , max = 45) - @Pattern(regexp = "^[A-Za-z0-9]*$") @PathParam("id") String id); }