Fix formatting

revert-dabc3590
Madawa Soysa 6 years ago
parent ec9451d444
commit 6470efcb31

@ -57,23 +57,21 @@ import java.util.List;
import java.util.Properties;
public class ApplicationOperationsImpl implements ApplicationOperations {
private static final Log log = LogFactory.getLog(ApplicationOperationsImpl.class);
public static final String MEDIA_TYPE_XML = "application/xml";
public static final String INSTALL = "install";
public static final String UNINSTALL = "uninstall";
private static final String MEDIA_TYPE_XML = "application/xml";
private static final String INSTALL = "install";
private static final String UNINSTALL = "uninstall";
/**
* @param applicationOperationAction holds the information needs to perform an action on mdm.
* @throws MobileApplicationException
* @throws MobileApplicationException If error occurred while performing the action.
*/
public String performAction(ApplicationOperationAction applicationOperationAction)
throws MobileApplicationException {
if (log.isDebugEnabled()) {
log.debug(applicationOperationAction.getAction() + " action is triggered for " +
applicationOperationAction.getType() +".");
applicationOperationAction.getType() + ".");
}
Operation operation = null;
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
List<org.wso2.carbon.device.mgt.common.Device> deviceList;
@ -82,11 +80,9 @@ public class ApplicationOperationsImpl implements ApplicationOperations {
try {
for (String param : applicationOperationAction.getParams()) {
userName = param;
deviceList = MDMServiceAPIUtils
.getDeviceManagementService(applicationOperationAction.getTenantId()).
getDevicesOfUser(userName);
for (org.wso2.carbon.device.mgt.common.Device device : deviceList) {
if (MDMAppConstants.WEBAPP.equals(applicationOperationAction.getApp().getPlatform()) ||
applicationOperationAction.getApp().getPlatform().equalsIgnoreCase(device.getType())) {
@ -98,8 +94,7 @@ public class ApplicationOperationsImpl implements ApplicationOperations {
}
}
} catch (DeviceManagementException devEx) {
String errorMsg = "Error occurred fetch device for user " + userName +
" at app installation";
String errorMsg = "Error occurred fetch device for user " + userName + " at app installation";
logError(errorMsg, devEx);
throw new MobileApplicationException(errorMsg, devEx);
}
@ -108,11 +103,9 @@ public class ApplicationOperationsImpl implements ApplicationOperations {
try {
for (String param : applicationOperationAction.getParams()) {
userRole = param;
deviceList = MDMServiceAPIUtils
.getDeviceManagementService(applicationOperationAction.getTenantId()).
getAllDevicesOfRole(userRole);
for (org.wso2.carbon.device.mgt.common.Device device : deviceList) {
if (MDMAppConstants.ACTIVE.equalsIgnoreCase(device.getEnrolmentInfo().getStatus().toString())) {
deviceIdentifiers.add(getDeviceIdentifierByDevice(device));
@ -120,12 +113,10 @@ public class ApplicationOperationsImpl implements ApplicationOperations {
}
}
} catch (DeviceManagementException devMgtEx) {
String errorMsg = "Error occurred fetch device for user role " + userRole +
" at app installation";
String errorMsg = "Error occurred fetch device for user role " + userRole + " at app installation";
logError(errorMsg, devMgtEx);
throw new MobileApplicationException(errorMsg, devMgtEx);
}
} else if (MDMAppConstants.DEVICE.equals(applicationOperationAction.getType())) {
DeviceIdentifier deviceIdentifier;
for (String param : applicationOperationAction.getParams()) {
@ -141,7 +132,6 @@ public class ApplicationOperationsImpl implements ApplicationOperations {
logError("Device Identifier is not valid json object.", e);
throw new MobileApplicationException(e);
}
}
}
} else {
@ -206,16 +196,11 @@ public class ApplicationOperationsImpl implements ApplicationOperations {
}
activity = MDMServiceAPIUtils.getAppManagementService(applicationOperationAction.getTenantId())
.installApplicationForDevices(operation, deviceIdentifiers);
}
if(activity != null){
if (activity != null) {
return activity.getActivityId();
}
return null;
} catch (DeviceApplicationException mdmExce) {
logError("Error in creating operation object using app.", mdmExce);
throw new MobileApplicationException(mdmExce.getMessage());
@ -223,31 +208,28 @@ public class ApplicationOperationsImpl implements ApplicationOperations {
logError("Error in app installation.", appMgtExce);
throw new MobileApplicationException(appMgtExce.getErrorMessage());
}
}
/**
* Create a new device identifier from Device object.
*
* @param device device which is to be retrieved type and id
* @return created device identifier
*/
private static DeviceIdentifier getDeviceIdentifierByDevice(
org.wso2.carbon.device.mgt.common.Device device) {
private static DeviceIdentifier getDeviceIdentifierByDevice(org.wso2.carbon.device.mgt.common.Device device) {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(device.getDeviceIdentifier());
deviceIdentifier.setType(device.getType());
return deviceIdentifier;
}
/**
* @param applicationOperationDevice holds the information needs to retrieve device list.
* @return List of devices
* @throws MobileApplicationException If unexpected error occur in getting devices or if app platform is not supported.
* @throws MobileApplicationException If an error occurred in getting devices or if app platform is not supported.
*/
public List<Device> getDevices(ApplicationOperationDevice applicationOperationDevice)
throws MobileApplicationException {
List<Device> devices;
List<org.wso2.carbon.device.mgt.common.Device> deviceList;
try {
@ -266,11 +248,13 @@ public class ApplicationOperationsImpl implements ApplicationOperations {
deviceList = deviceManagementService.getDevicesOfUser(username, MDMAppConstants.IOS);
break;
default:
throw new MobileApplicationException("App platform:" + platform + "is not supported.");
String msg = "App platform:" + platform + "is not supported.";
log.error(msg);
throw new MobileApplicationException(msg);
}
devices = new ArrayList<>(deviceList.size());
if(log.isDebugEnabled()){
log.debug("device list got from mdm "+ deviceList.toString());
if (log.isDebugEnabled()) {
log.debug("device list got from mdm " + deviceList.toString());
}
for (org.wso2.carbon.device.mgt.common.Device commonDevice : deviceList) {
if (MDMAppConstants.ACTIVE
@ -330,7 +314,7 @@ public class ApplicationOperationsImpl implements ApplicationOperations {
}
}
public static UserStoreManager getUserStoreManager() throws UserStoreException {
private static UserStoreManager getUserStoreManager() throws UserStoreException {
RealmService realmService;
UserStoreManager userStoreManager;
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
@ -368,7 +352,6 @@ public class ApplicationOperationsImpl implements ApplicationOperations {
@Override
public void run() {
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext privilegedCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
@ -462,6 +445,4 @@ public class ApplicationOperationsImpl implements ApplicationOperations {
}
}
}
}

Loading…
Cancel
Save