Refactored Util methods

revert-dabc3590
charitha 7 years ago
parent 4cbcb5d2e6
commit e37e722ac6

@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory;
import org.json.JSONException;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
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.OperationManagementException;
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
@ -109,7 +110,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setType(Operation.Type.PROFILE);
operation.setEnabled(true);
operation.setPayLoad(lock.toJSON());
return AndroidAPIUtils.getOperationResponse(deviceLockBeanWrapper.getDeviceIDs(), operation);
Activity activity = AndroidAPIUtils.getOperationResponse(deviceLockBeanWrapper.getDeviceIDs(), operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -141,7 +143,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.DEVICE_UNLOCK);
operation.setType(Operation.Type.COMMAND);
operation.setEnabled(true);
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
Activity activity = AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -172,7 +175,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
CommandOperation operation = new CommandOperation();
operation.setCode(AndroidConstants.OperationCodes.DEVICE_LOCATION);
operation.setType(Operation.Type.COMMAND);
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
Activity activity = AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -203,7 +207,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
CommandOperation operation = new CommandOperation();
operation.setCode(AndroidConstants.OperationCodes.CLEAR_PASSWORD);
operation.setType(Operation.Type.COMMAND);
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
Activity activity = AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -242,7 +247,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.CAMERA);
operation.setType(Operation.Type.COMMAND);
operation.setEnabled(camera.isEnabled());
return AndroidAPIUtils.getOperationResponse(cameraBeanWrapper.getDeviceIDs(), operation);
Activity activity = AndroidAPIUtils.getOperationResponse(cameraBeanWrapper.getDeviceIDs(), operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -273,7 +279,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
CommandOperation operation = new CommandOperation();
operation.setCode(AndroidConstants.OperationCodes.DEVICE_INFO);
operation.setType(Operation.Type.COMMAND);
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
Activity activity = AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -303,7 +310,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
CommandOperation operation = new CommandOperation();
operation.setCode(AndroidConstants.OperationCodes.LOGCAT);
operation.setType(Operation.Type.COMMAND);
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
Activity activity = AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -333,7 +341,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
CommandOperation operation = new CommandOperation();
operation.setCode(AndroidConstants.OperationCodes.ENTERPRISE_WIPE);
operation.setType(Operation.Type.COMMAND);
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
Activity activity = AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -372,7 +381,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.WIPE_DATA);
operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(wipeData.toJSON());
return AndroidAPIUtils.getOperationResponse(wipeDataBeanWrapper.getDeviceIDs(), operation);
Activity activity = AndroidAPIUtils.getOperationResponse(wipeDataBeanWrapper.getDeviceIDs(), operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -403,7 +413,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
CommandOperation operation = new CommandOperation();
operation.setCode(AndroidConstants.OperationCodes.APPLICATION_LIST);
operation.setType(Operation.Type.COMMAND);
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
Activity activity = AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -434,7 +445,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
CommandOperation operation = new CommandOperation();
operation.setCode(AndroidConstants.OperationCodes.DEVICE_RING);
operation.setType(Operation.Type.COMMAND);
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
Activity activity = AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -465,7 +477,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
CommandOperation operation = new CommandOperation();
operation.setCode(AndroidConstants.OperationCodes.DEVICE_REBOOT);
operation.setType(Operation.Type.COMMAND);
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
Activity activity = AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -497,7 +510,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.DEVICE_MUTE);
operation.setType(Operation.Type.COMMAND);
operation.setEnabled(true);
return AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
Activity activity = AndroidAPIUtils.getOperationResponse(deviceIDs, operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -542,8 +556,9 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.INSTALL_APPLICATION);
operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(applicationInstallation.toJSON());
return AndroidAPIUtils.getOperationResponse(applicationInstallationBeanWrapper.getDeviceIDs(),
operation);
Activity activity = AndroidAPIUtils
.getOperationResponse(applicationInstallationBeanWrapper.getDeviceIDs(), operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (JSONException e) {
String errorMessage = "Invalid payload for the operation.";
log.error(errorMessage);
@ -592,8 +607,9 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(applicationUpdate.toJSON());
return AndroidAPIUtils.getOperationResponse(applicationUpdateBeanWrapper.getDeviceIDs(),
operation);
Activity activity = AndroidAPIUtils
.getOperationResponse(applicationUpdateBeanWrapper.getDeviceIDs(), operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -635,9 +651,9 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.UNINSTALL_APPLICATION);
operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(applicationUninstallation.toJSON());
return AndroidAPIUtils.getOperationResponse(applicationUninstallationBeanWrapper.getDeviceIDs(),
operation);
Activity activity = AndroidAPIUtils
.getOperationResponse(applicationUninstallationBeanWrapper.getDeviceIDs(), operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -676,8 +692,9 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.BLACKLIST_APPLICATIONS);
operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(blacklistApplications.toJSON());
return AndroidAPIUtils.getOperationResponse(blacklistApplicationsBeanWrapper.getDeviceIDs(),
operation);
Activity activity = AndroidAPIUtils
.getOperationResponse(blacklistApplicationsBeanWrapper.getDeviceIDs(), operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -718,7 +735,9 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.UPGRADE_FIRMWARE);
operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(upgradeFirmware.toJSON());
return AndroidAPIUtils.getOperationResponse(upgradeFirmwareBeanWrapper.getDeviceIDs(), operation);
Activity activity = AndroidAPIUtils
.getOperationResponse(upgradeFirmwareBeanWrapper.getDeviceIDs(), operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -757,8 +776,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.VPN);
operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(vpn.toJSON());
return AndroidAPIUtils.getOperationResponse(vpnConfiguration.getDeviceIDs(),
operation);
Activity activity = AndroidAPIUtils.getOperationResponse(vpnConfiguration.getDeviceIDs(), operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -797,8 +816,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.NOTIFICATION);
operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(notification.toJSON());
return AndroidAPIUtils.getOperationResponse(notificationBeanWrapper.getDeviceIDs(),
operation);
Activity activity = AndroidAPIUtils.getOperationResponse(notificationBeanWrapper.getDeviceIDs(), operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -838,8 +857,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(wifi.toJSON());
return AndroidAPIUtils.getOperationResponse(wifiBeanWrapper.getDeviceIDs(),
operation);
Activity activity = AndroidAPIUtils.getOperationResponse(wifiBeanWrapper.getDeviceIDs(), operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -878,8 +897,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.ENCRYPT_STORAGE);
operation.setType(Operation.Type.COMMAND);
operation.setEnabled(deviceEncryption.isEncrypted());
return AndroidAPIUtils.getOperationResponse(encryptionBeanWrapper.getDeviceIDs(),
operation);
Activity activity = AndroidAPIUtils.getOperationResponse(encryptionBeanWrapper.getDeviceIDs(), operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -918,8 +937,8 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.CHANGE_LOCK_CODE);
operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(lockCode.toJSON());
return AndroidAPIUtils.getOperationResponse(lockCodeBeanWrapper.getDeviceIDs(),
operation);
Activity activity = AndroidAPIUtils.getOperationResponse(lockCodeBeanWrapper.getDeviceIDs(), operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -959,8 +978,9 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(passcodePolicy.toJSON());
return AndroidAPIUtils.getOperationResponse(passwordPolicyBeanWrapper.getDeviceIDs(),
operation);
Activity activity = AndroidAPIUtils
.getOperationResponse(passwordPolicyBeanWrapper.getDeviceIDs(), operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
@ -1000,7 +1020,9 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.WEBCLIP);
operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(webClip.toJSON());
return AndroidAPIUtils.getOperationResponse(webClipBeanWrapper.getDeviceIDs(), operation);
Activity activity = AndroidAPIUtils.getOperationResponse(webClipBeanWrapper.getDeviceIDs(), operation);
return Response.status(Response.Status.CREATED).entity(activity).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);

@ -123,7 +123,7 @@ public class AndroidAPIUtils {
return responseMediaType;
}
public static Response getOperationResponse(List<String> deviceIDs, Operation operation)
public static Activity getOperationResponse(List<String> deviceIDs, Operation operation)
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
if (deviceIDs == null || deviceIDs.size() == 0) {
String errorMessage = "Device identifier list is empty";
@ -139,20 +139,8 @@ public class AndroidAPIUtils {
deviceIdentifier.setType(AndroidConstants.DEVICE_TYPE_ANDROID);
deviceIdentifiers.add(deviceIdentifier);
}
Activity activity = getDeviceManagementService().addOperation(
return getDeviceManagementService().addOperation(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, operation, deviceIdentifiers);
// if (activity != null) {
// GCMService gcmService = getGCMService();
// if (gcmService.isFCMEnabled()) {
// List<DeviceIdentifier> deviceIDList = deviceIDHolder.getValidDeviceIDList();
// List<Device> devices = new ArrayList<Device>(deviceIDList.size());
// for (DeviceIdentifier deviceIdentifier : deviceIDList) {
// devices.add(getDeviceManagementService().getDevice(deviceIdentifier));
// }
// getGCMService().sendNotification(operation.getCode(), devices);
// }
// }
return Response.status(Response.Status.CREATED).entity(activity).build();
}

Loading…
Cancel
Save