Merge branch 'rest-api-improvements' of https://github.com/wso2/carbon-device-mgt into rest-api-improvements

revert-70aa11f8
prabathabey 9 years ago
commit 697c727801

@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api.admin;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.wso2.carbon.apimgt.annotations.api.API; import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.jaxrs.beans.ApplicationWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.ApplicationWrapper;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
@ -48,11 +49,13 @@ public interface ApplicationManagementAdminService {
httpMethod = "POST", httpMethod = "POST",
value = "Application installation API.(Internal API)", value = "Application installation API.(Internal API)",
notes = "This is an internal API used for application installation on a device.", notes = "This is an internal API used for application installation on a device.",
response = Activity.class,
tags = "Application Management Administrative Service") tags = "Application Management Administrative Service")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 202, code = 202,
message = "OK. \n Install application operation will be delivered to the given devices"), message = "OK. \n Install application operation will be delivered to the given devices",
response = Activity.class),
@ApiResponse( @ApiResponse(
code = 400, code = 400,
message = "Bad Request. \n Invalid request or validation error.", message = "Bad Request. \n Invalid request or validation error.",
@ -84,11 +87,13 @@ public interface ApplicationManagementAdminService {
httpMethod = "POST", httpMethod = "POST",
value = "Application un-installation API.(Internal API)", value = "Application un-installation API.(Internal API)",
notes = "This is an internal API used for application un-installation on a device.", notes = "This is an internal API used for application un-installation on a device.",
response = Activity.class,
tags = "Application Management Administrative Service") tags = "Application Management Administrative Service")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 202, code = 202,
message = "OK. \n Uninstall application operation will be delivered to the provided devices"), message = "OK. \n Uninstall application operation will be delivered to the provided devices",
response = Activity.class),
@ApiResponse( @ApiResponse(
code = 400, code = 400,
message = "Bad Request. \n Invalid request or validation error.", message = "Bad Request. \n Invalid request or validation error.",

@ -24,6 +24,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.Platform; import org.wso2.carbon.device.mgt.common.Platform;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.exception.UnknownApplicationTypeException; import org.wso2.carbon.device.mgt.jaxrs.exception.UnknownApplicationTypeException;
@ -57,6 +58,7 @@ public class ApplicationManagementAdminServiceImpl implements ApplicationManagem
public Response installApplication(ApplicationWrapper applicationWrapper) { public Response installApplication(ApplicationWrapper applicationWrapper) {
ApplicationManager appManagerConnector; ApplicationManager appManagerConnector;
Operation operation = null; Operation operation = null;
Activity activity = null;
RequestValidationUtil.validateApplicationInstallationContext(applicationWrapper); RequestValidationUtil.validateApplicationInstallationContext(applicationWrapper);
try { try {
@ -72,20 +74,19 @@ public class ApplicationManagementAdminServiceImpl implements ApplicationManagem
} }
} }
if (applicationWrapper.getRoleNameList() != null && applicationWrapper.getRoleNameList().size() > 0) { if (applicationWrapper.getRoleNameList() != null && applicationWrapper.getRoleNameList().size() > 0) {
appManagerConnector.installApplicationForUserRoles(operation, applicationWrapper.getRoleNameList()); activity = appManagerConnector.installApplicationForUserRoles(operation, applicationWrapper.getRoleNameList());
} else if (applicationWrapper.getUserNameList() != null && } else if (applicationWrapper.getUserNameList() != null &&
applicationWrapper.getUserNameList().size() > 0) { applicationWrapper.getUserNameList().size() > 0) {
appManagerConnector.installApplicationForUsers(operation, applicationWrapper.getUserNameList()); activity = appManagerConnector.installApplicationForUsers(operation, applicationWrapper.getUserNameList());
} else if (applicationWrapper.getDeviceIdentifiers() != null && } else if (applicationWrapper.getDeviceIdentifiers() != null &&
applicationWrapper.getDeviceIdentifiers().size() > 0) { applicationWrapper.getDeviceIdentifiers().size() > 0) {
appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers()); activity = appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers());
} else { } else {
throw new InputValidationException(new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage( throw new InputValidationException(new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(
"No application installation criteria i.e. user/role/device is given").build()); "No application installation criteria i.e. user/role/device is given").build());
} }
} }
return Response.status(Response.Status.ACCEPTED).entity("Application installation request has been sent " + return Response.status(Response.Status.ACCEPTED).entity(activity).build();
"to the device(s)").build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
String msg = "ErrorResponse occurred while processing application installation request"; String msg = "ErrorResponse occurred while processing application installation request";
log.error(msg, e); log.error(msg, e);
@ -105,6 +106,7 @@ public class ApplicationManagementAdminServiceImpl implements ApplicationManagem
public Response uninstallApplication(ApplicationWrapper applicationWrapper) { public Response uninstallApplication(ApplicationWrapper applicationWrapper) {
ApplicationManager appManagerConnector; ApplicationManager appManagerConnector;
org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation = null; org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation = null;
Activity activity = null;
RequestValidationUtil.validateApplicationInstallationContext(applicationWrapper); RequestValidationUtil.validateApplicationInstallationContext(applicationWrapper);
try { try {
@ -120,21 +122,20 @@ public class ApplicationManagementAdminServiceImpl implements ApplicationManagem
} }
} }
if (applicationWrapper.getRoleNameList() != null && applicationWrapper.getRoleNameList().size() > 0) { if (applicationWrapper.getRoleNameList() != null && applicationWrapper.getRoleNameList().size() > 0) {
appManagerConnector.installApplicationForUserRoles(operation, applicationWrapper.getRoleNameList()); activity = appManagerConnector.installApplicationForUserRoles(operation, applicationWrapper.getRoleNameList());
} else if (applicationWrapper.getUserNameList() != null && } else if (applicationWrapper.getUserNameList() != null &&
applicationWrapper.getUserNameList().size() > 0) { applicationWrapper.getUserNameList().size() > 0) {
appManagerConnector.installApplicationForUsers(operation, applicationWrapper.getUserNameList()); activity = appManagerConnector.installApplicationForUsers(operation, applicationWrapper.getUserNameList());
} else if (applicationWrapper.getDeviceIdentifiers() != null && } else if (applicationWrapper.getDeviceIdentifiers() != null &&
applicationWrapper.getDeviceIdentifiers().size() > 0) { applicationWrapper.getDeviceIdentifiers().size() > 0) {
appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers()); activity = appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers());
} else { } else {
throw new InputValidationException( throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage( new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(
"No application un-installation criteria i.e. user/role/device is given").build()); "No application un-installation criteria i.e. user/role/device is given").build());
} }
} }
return Response.status(Response.Status.ACCEPTED).entity("Application un-installation request has " + return Response.status(Response.Status.ACCEPTED).entity(activity).build();
"been sent to the given device(s)").build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
String msg = "ErrorResponse occurred while processing application un-installation request"; String msg = "ErrorResponse occurred while processing application un-installation request";
log.error(msg, e); log.error(msg, e);

Loading…
Cancel
Save