From 137d970fc7af388b361e1ece1d0f4175a86a77c1 Mon Sep 17 00:00:00 2001 From: amalhub Date: Mon, 11 Sep 2017 15:40:30 +0530 Subject: [PATCH] App-mgt store response refactor --- .../impl/SubscriptionManagementAPIImpl.java | 18 +++++++++++------- .../common/services/SubscriptionManager.java | 8 ++++---- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/SubscriptionManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/SubscriptionManagementAPIImpl.java index 881da552bc..5c3797e82d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/SubscriptionManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/SubscriptionManagementAPIImpl.java @@ -31,6 +31,8 @@ import javax.validation.Valid; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; +import javax.ws.rs.core.Variant; +import java.util.HashMap; import java.util.List; /** @@ -45,23 +47,25 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ @Override public Response installApplication(@ApiParam(name = "installationDetails", value = "The application ID and list" + " the devices/users/roles", required = true) @Valid InstallationDetails installationDetails) { - Object response; + Object result; SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); try { - String applicationUUTD = installationDetails.getApplicationUUID(); + String applicationUUID = installationDetails.getApplicationUUID(); if (!installationDetails.getDeviceIdentifiers().isEmpty()) { List deviceList = installationDetails.getDeviceIdentifiers(); - response = subscriptionManager.installApplicationForDevices(applicationUUTD, deviceList); + result = subscriptionManager.installApplicationForDevices(applicationUUID, deviceList); } else if (!installationDetails.getUserNameList().isEmpty()) { List userList = installationDetails.getUserNameList(); - response = subscriptionManager.installApplicationForUsers(applicationUUTD, userList); + result = subscriptionManager.installApplicationForUsers(applicationUUID, userList); } else if (!installationDetails.getRoleNameList().isEmpty()) { List roleList = installationDetails.getRoleNameList(); - response = subscriptionManager.installApplicationForRoles(applicationUUTD, roleList); + result = subscriptionManager.installApplicationForRoles(applicationUUID, roleList); } else { - response = "Missing request data!"; - return Response.status(Response.Status.BAD_REQUEST).entity(response).build(); + result = "Missing request data!"; + return Response.status(Response.Status.BAD_REQUEST).entity(result).build(); } + HashMap response = new HashMap<>(); + response.put("failedDevices", result); return Response.status(Response.Status.OK).entity(response).build(); } catch (ApplicationManagementException e) { String msg = "Error occurred while installing the application"; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java index 43ecf89ed8..6f207e3f4d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/SubscriptionManager.java @@ -31,7 +31,7 @@ public interface SubscriptionManager { * To install an application to given list of devices. * @param applicationUUID Application ID * @param deviceList Device list - * @return DeviceList which the application has been installed + * @return Failed Device List which the application was unable to install * @throws ApplicationManagementException Application Management Exception */ List installApplicationForDevices(String applicationUUID, @@ -42,7 +42,7 @@ public interface SubscriptionManager { * To install an application to given list of users. * @param applicationUUID Application ID * @param userList User list - * @return User list which the application has been installed + * @return Failed User List which the application was unable to install * @throws ApplicationManagementException Application Management Exception */ List installApplicationForUsers(String applicationUUID, @@ -53,7 +53,7 @@ public interface SubscriptionManager { * To install an application to given list of users. * @param applicationUUID Application ID * @param roleList Role list - * @return Role list which the application has been installed + * @return Failed Role List which the application was unable to install * @throws ApplicationManagementException Application Management Exception */ List installApplicationForRoles(String applicationUUID, @@ -64,7 +64,7 @@ public interface SubscriptionManager { * To uninstall an application from a given list of devices. * @param applicationUUID Application ID * @param deviceList Device list - * @return DeviceList which the application has been uninstalled + * @return Failed Device List which the application was unable to uninstall * @throws ApplicationManagementException Application Management Exception */ List uninstallApplication(String applicationUUID,