|
|
|
@ -25,8 +25,12 @@ 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.ApplicationManager;
|
|
|
|
|
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.exception.UnknownApplicationTypeException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.ApplicationManagementAdminService;
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.InputValidationException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.MDMAndroidOperationUtil;
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.MDMIOSOperationUtil;
|
|
|
|
@ -53,30 +57,45 @@ public class ApplicationManagementAdminServiceImpl implements ApplicationManagem
|
|
|
|
|
public Response installApplication(ApplicationWrapper applicationWrapper) {
|
|
|
|
|
ApplicationManager appManagerConnector;
|
|
|
|
|
Operation operation = null;
|
|
|
|
|
|
|
|
|
|
RequestValidationUtil.validateApplicationInstallationContext(applicationWrapper);
|
|
|
|
|
try {
|
|
|
|
|
appManagerConnector = DeviceMgtAPIUtils.getAppManagementService();
|
|
|
|
|
MobileApp mobileApp = applicationWrapper.getApplication();
|
|
|
|
|
|
|
|
|
|
if (applicationWrapper.getDeviceIdentifiers() != null) {
|
|
|
|
|
for (DeviceIdentifier deviceIdentifier : applicationWrapper.getDeviceIdentifiers()) {
|
|
|
|
|
if (deviceIdentifier.getType().equals(Platform.ANDROID.toString())) {
|
|
|
|
|
if (Platform.ANDROID.toString().equals(deviceIdentifier.getType())) {
|
|
|
|
|
operation = MDMAndroidOperationUtil.createInstallAppOperation(mobileApp);
|
|
|
|
|
} else if (deviceIdentifier.getType().equals(Platform.IOS.toString())) {
|
|
|
|
|
} else if (Platform.IOS.toString().equals(deviceIdentifier.getType())) {
|
|
|
|
|
operation = MDMIOSOperationUtil.createInstallAppOperation(mobileApp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers());
|
|
|
|
|
if (applicationWrapper.getRoleNameList() != null && applicationWrapper.getRoleNameList().size() > 0) {
|
|
|
|
|
appManagerConnector.installApplicationForUserRoles(operation, applicationWrapper.getRoleNameList());
|
|
|
|
|
} else if (applicationWrapper.getUserNameList() != null &&
|
|
|
|
|
applicationWrapper.getUserNameList().size() > 0) {
|
|
|
|
|
appManagerConnector.installApplicationForUsers(operation, applicationWrapper.getUserNameList());
|
|
|
|
|
} else if (applicationWrapper.getDeviceIdentifiers() != null &&
|
|
|
|
|
applicationWrapper.getDeviceIdentifiers().size() > 0) {
|
|
|
|
|
appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers());
|
|
|
|
|
} else {
|
|
|
|
|
throw new InputValidationException(new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(
|
|
|
|
|
"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 " +
|
|
|
|
|
"to the device").build();
|
|
|
|
|
"to the device(s)").build();
|
|
|
|
|
} catch (ApplicationManagementException e) {
|
|
|
|
|
String msg = "ErrorResponse occurred while processing application installation request";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
|
} catch (UnknownApplicationTypeException e) {
|
|
|
|
|
String msg = "The type of application requested to be installed is not supported";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -86,30 +105,45 @@ public class ApplicationManagementAdminServiceImpl implements ApplicationManagem
|
|
|
|
|
public Response uninstallApplication(ApplicationWrapper applicationWrapper) {
|
|
|
|
|
ApplicationManager appManagerConnector;
|
|
|
|
|
org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation = null;
|
|
|
|
|
|
|
|
|
|
RequestValidationUtil.validateApplicationInstallationContext(applicationWrapper);
|
|
|
|
|
try {
|
|
|
|
|
appManagerConnector = DeviceMgtAPIUtils.getAppManagementService();
|
|
|
|
|
MobileApp mobileApp = applicationWrapper.getApplication();
|
|
|
|
|
|
|
|
|
|
if (applicationWrapper.getDeviceIdentifiers() != null) {
|
|
|
|
|
for (DeviceIdentifier deviceIdentifier : applicationWrapper.getDeviceIdentifiers()) {
|
|
|
|
|
if (deviceIdentifier.getType().equals(Platform.ANDROID.toString())) {
|
|
|
|
|
if (Platform.ANDROID.toString().equals(deviceIdentifier.getType())) {
|
|
|
|
|
operation = MDMAndroidOperationUtil.createAppUninstallOperation(mobileApp);
|
|
|
|
|
} else if (deviceIdentifier.getType().equals(Platform.IOS.toString())) {
|
|
|
|
|
operation = MDMIOSOperationUtil.createAppUninstallOperation(mobileApp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers());
|
|
|
|
|
if (applicationWrapper.getRoleNameList() != null && applicationWrapper.getRoleNameList().size() > 0) {
|
|
|
|
|
appManagerConnector.installApplicationForUserRoles(operation, applicationWrapper.getRoleNameList());
|
|
|
|
|
} else if (applicationWrapper.getUserNameList() != null &&
|
|
|
|
|
applicationWrapper.getUserNameList().size() > 0) {
|
|
|
|
|
appManagerConnector.installApplicationForUsers(operation, applicationWrapper.getUserNameList());
|
|
|
|
|
} else if (applicationWrapper.getDeviceIdentifiers() != null &&
|
|
|
|
|
applicationWrapper.getDeviceIdentifiers().size() > 0) {
|
|
|
|
|
appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers());
|
|
|
|
|
} else {
|
|
|
|
|
throw new InputValidationException(new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(
|
|
|
|
|
"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 " +
|
|
|
|
|
"been sent to the device").build();
|
|
|
|
|
"been sent to the given device(s)").build();
|
|
|
|
|
} catch (ApplicationManagementException e) {
|
|
|
|
|
String msg = "ErrorResponse occurred while processing application un-installation request";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
|
} catch (UnknownApplicationTypeException e) {
|
|
|
|
|
String msg = "The type of application requested to be un-installed is not supported";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|