Improve APPM subscribing flow

revert-70ac1926
tcdlpds@gmail.com 4 years ago
parent 7b71947073
commit e96145db25

@ -0,0 +1,52 @@
/* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.application.mgt.common;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import java.util.ArrayList;
import java.util.List;
public class ApplicationSubscriptionInfo {
List<Device> devices;
List<String> subscribers;
List<DeviceIdentifier> errorDeviceIdentifiers;
String appSupportingDeviceTypeName;
public List<Device> getDevices() { return devices; }
public void setDevices(List<Device> devices) { this.devices = devices; }
public List<String> getSubscribers() { return subscribers; }
public void setSubscribers(List<String> subscribers) { this.subscribers = subscribers; }
public List<DeviceIdentifier> getErrorDeviceIdentifiers() { return errorDeviceIdentifiers; }
public void setErrorDeviceIdentifiers(List<DeviceIdentifier> errorDeviceIdentifiers) {
this.errorDeviceIdentifiers = errorDeviceIdentifiers;
}
public String getAppSupportingDeviceTypeName() { return appSupportingDeviceTypeName; }
public void setAppSupportingDeviceTypeName(String appSupportingDeviceTypeName) {
this.appSupportingDeviceTypeName = appSupportingDeviceTypeName;
}
}

@ -29,6 +29,7 @@ import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException; import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.ApplicationInstallResponse; import org.wso2.carbon.device.application.mgt.common.ApplicationInstallResponse;
import org.wso2.carbon.device.application.mgt.common.ApplicationSubscriptionInfo;
import org.wso2.carbon.device.application.mgt.common.ApplicationType; import org.wso2.carbon.device.application.mgt.common.ApplicationType;
import org.wso2.carbon.device.application.mgt.common.DeviceSubscriptionData; import org.wso2.carbon.device.application.mgt.common.DeviceSubscriptionData;
import org.wso2.carbon.device.application.mgt.common.DeviceTypes; import org.wso2.carbon.device.application.mgt.common.DeviceTypes;
@ -76,7 +77,6 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus; import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus;
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.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
@ -120,84 +120,16 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
log.debug("Install application release which has UUID " + applicationUUID + " to " + params.size() log.debug("Install application release which has UUID " + applicationUUID + " to " + params.size()
+ " users."); + " users.");
} }
try {
validateRequest(params, subType, action);
DeviceManagementProviderService deviceManagementProviderService = HelperUtil
.getDeviceManagementProviderService();
GroupManagementProviderService groupManagementProviderService = HelperUtil
.getGroupManagementProviderService();
String deviceTypeName = null;
List<Device> devices = new ArrayList<>();
List<String> subscribers = new ArrayList<>();
List<DeviceIdentifier> errorDeviceIdentifiers = new ArrayList<>();
ApplicationInstallResponse applicationInstallResponse;
validateRequest(params, subType, action);
//todo validate users, groups and roles //todo validate users, groups and roles
ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID); ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID);
if (SubscriptionType.DEVICE.toString().equals(subType)) { ApplicationSubscriptionInfo applicationSubscriptionInfo = getAppSubscriptionInfo(applicationDTO, subType, params);
for (T param : params) { ApplicationInstallResponse applicationInstallResponse = performActionOnDevices(applicationSubscriptionInfo.getAppSupportingDeviceTypeName(),
DeviceIdentifier deviceIdentifier = (DeviceIdentifier) param; applicationSubscriptionInfo.getDevices(), applicationDTO, subType, applicationSubscriptionInfo.getSubscribers(), action);
if (StringUtils.isEmpty(deviceIdentifier.getId()) || StringUtils
.isEmpty(deviceIdentifier.getType())) {
log.warn("Found a device identifier which has either empty identity of the device or empty"
+ " device type. Hence ignoring the device identifier. ");
continue;
}
if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) {
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
if (!deviceType.getName().equals(deviceIdentifier.getType())) {
log.warn("Found a device identifier which is not matched with the supported device type "
+ "of the application release which has UUID " + applicationUUID + " Application "
+ "supported device type is " + deviceType.getName() + " and the "
+ "identifier of which has a different device type is " + deviceIdentifier.getId());
errorDeviceIdentifiers.add(deviceIdentifier);
continue;
}
}
devices.add(deviceManagementProviderService.getDevice(deviceIdentifier, false));
}
} else if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
for (T param : params) {
String username = (String) param;
subscribers.add(username);
devices.addAll(deviceManagementProviderService.getDevicesOfUser(username));
}
} else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
for (T param : params) {
String roleName = (String) param;
subscribers.add(roleName);
devices.addAll(deviceManagementProviderService.getAllDevicesOfRole(roleName));
}
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
for (T param : params) {
String groupName = (String) param;
subscribers.add(groupName);
devices.addAll(groupManagementProviderService.getAllDevicesOfGroup(groupName, true));
}
}
if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType()) && !SubscriptionType.DEVICE
.toString().equals(subType)) {
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
deviceTypeName = deviceType.getName();
//filter devices by device type
String tmpDeviceTypeName = deviceTypeName;
devices.removeIf(device -> !tmpDeviceTypeName.equals(device.getType()));
}
applicationInstallResponse = performActionOnDevices(deviceTypeName, devices, applicationDTO, applicationInstallResponse.setErrorDeviceIdentifiers(applicationSubscriptionInfo.getErrorDeviceIdentifiers());
subType, subscribers, action);
applicationInstallResponse.setErrorDeviceIdentifiers(errorDeviceIdentifiers);
return applicationInstallResponse; return applicationInstallResponse;
} catch (DeviceManagementException e) {
String msg = "Error occurred while getting devices of given users or given roles.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (GroupManagementException e) {
String msg = "Error occurred while getting devices of given groups";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
} }
@Override @Override
@ -321,13 +253,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
@Override @Override
public <T> void performEntAppSubscription(String applicationUUID, List<T> params, String subType, String action, public <T> void performEntAppSubscription(String applicationUUID, List<T> params, String subType, String action,
boolean requiresUpdatingExternal) boolean requiresUpdatingExternal) throws ApplicationManagementException {
throws ApplicationManagementException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Google Ent app Install operation is received to application which has UUID " log.debug("Google Ent app Install operation is received to application which has UUID " + applicationUUID
+ applicationUUID + " to perform on " + params.size() + " params."); + " to perform on " + params.size() + " params.");
} }
try {
if (params.isEmpty()) { if (params.isEmpty()) {
String msg = "In order to subscribe/unsubscribe application release, you should provide list of " String msg = "In order to subscribe/unsubscribe application release, you should provide list of "
+ "subscribers. But found an empty list of subscribers."; + "subscribers. But found an empty list of subscribers.";
@ -354,76 +284,17 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
DeviceManagementProviderService deviceManagementProviderService = HelperUtil
.getDeviceManagementProviderService();
List<Device> devices = new ArrayList<>();
List<String> subscribers = new ArrayList<>();
List<Integer> appSubscribingDeviceIds;
List<Integer> appReSubscribingDeviceIds = new ArrayList<>(); List<Integer> appReSubscribingDeviceIds = new ArrayList<>();
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>(); List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
//todo validate users, groups and roles ApplicationSubscriptionInfo applicationSubscriptionInfo = getAppSubscriptionInfo(applicationDTO, subType,
if (SubscriptionType.DEVICE.toString().equals(subType)) { params);
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()); applicationSubscriptionInfo.getDevices().forEach(device -> {
for (T param : params) {
DeviceIdentifier deviceIdentifier = (DeviceIdentifier) param;
if (StringUtils.isEmpty(deviceIdentifier.getId()) || StringUtils
.isEmpty(deviceIdentifier.getType())) {
log.warn("Found a device identifier which has either empty identity of the device or empty"
+ " device type. Hence ignoring the device identifier. ");
continue;
}
if (!deviceType.getName().equals(deviceIdentifier.getType())) {
log.warn("Found a device identifier which is not matched with the supported device type "
+ "of the application release which has UUID " + applicationUUID + " Application "
+ "supported device type is " + deviceType.getName() + " and the "
+ "identifier of which has a different device type is " + deviceIdentifier.getId());
continue;
}
deviceIdentifiers.add(deviceIdentifier);
devices.add(deviceManagementProviderService.getDevice(deviceIdentifier, false));
}
} else if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
for (T param : params) {
String username = (String) param;
subscribers.add(username);
devices.addAll(deviceManagementProviderService.getDevicesOfUser(username));
}
} else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
for (T param : params) {
String roleName = (String) param;
subscribers.add(roleName);
devices.addAll(deviceManagementProviderService.getAllDevicesOfRole(roleName));
}
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
GroupManagementProviderService groupManagementProviderService = HelperUtil
.getGroupManagementProviderService();
for (T param : params) {
String groupName = (String) param;
subscribers.add(groupName);
devices.addAll(groupManagementProviderService.getAllDevicesOfGroup(groupName, false));
}
} else {
String msg = "Found invalid subscription type " + subType+ " to install application release" ;
log.error(msg);
throw new BadRequestException(msg);
}
/*If subscription type is not device we need to crete device identifiers object list by referring retrieved
list of devices.*/
if (!SubscriptionType.DEVICE.toString().equalsIgnoreCase(subType)) {
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
String deviceTypeName = deviceType.getName();
//filter devices by device type
devices.removeIf(device -> !deviceTypeName.equals(device.getType()));
devices.forEach(device -> {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(device.getDeviceIdentifier()); deviceIdentifier.setId(device.getDeviceIdentifier());
deviceIdentifier.setType(device.getType()); deviceIdentifier.setType(device.getType());
deviceIdentifiers.add(deviceIdentifier); deviceIdentifiers.add(deviceIdentifier);
}); });
}
if (requiresUpdatingExternal) { if (requiresUpdatingExternal) {
//Installing the application //Installing the application
@ -434,28 +305,21 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
installEnrollmentApplications(applicationPolicyDTO); installEnrollmentApplications(applicationPolicyDTO);
} }
appSubscribingDeviceIds = devices.stream().map(Device::getId).collect(Collectors.toList()); List<Integer> appSubscribingDeviceIds = applicationSubscriptionInfo.getDevices().stream().map(Device::getId)
.collect(Collectors.toList());
Map<Integer, DeviceSubscriptionDTO> deviceSubscriptions = getDeviceSubscriptions(appSubscribingDeviceIds, Map<Integer, DeviceSubscriptionDTO> deviceSubscriptions = getDeviceSubscriptions(appSubscribingDeviceIds,
applicationReleaseId); applicationReleaseId);
for (Map.Entry<Integer, DeviceSubscriptionDTO> deviceSubscription: deviceSubscriptions.entrySet()){ for (Map.Entry<Integer, DeviceSubscriptionDTO> deviceSubscription : deviceSubscriptions.entrySet()) {
appReSubscribingDeviceIds.add(deviceSubscription.getKey()); appReSubscribingDeviceIds.add(deviceSubscription.getKey());
appSubscribingDeviceIds.remove(deviceSubscription.getKey()); appSubscribingDeviceIds.remove(deviceSubscription.getKey());
} }
updateSubscriptionsForEntInstall(applicationReleaseId, appSubscribingDeviceIds, appReSubscribingDeviceIds, updateSubscriptionsForEntInstall(applicationReleaseId, appSubscribingDeviceIds, appReSubscribingDeviceIds,
subscribers, subType, action); applicationSubscriptionInfo.getSubscribers(), subType, action);
} catch (DeviceManagementException e) {
String msg = "Error occurred while getting devices of given users or given roles.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (GroupManagementException e) {
String msg = "Error occurred while getting devices of given groups";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
} }
@Override public void installAppsForDevice(DeviceIdentifier deviceIdentifier, List<String> releaseUUIDs) @Override
public void installAppsForDevice(DeviceIdentifier deviceIdentifier, List<String> releaseUUIDs)
throws ApplicationManagementException { throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -519,6 +383,105 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
} }
/**
* Gets Application subscribing info by using requesting params
*
* @param applicationDTO Application DTO
* @param params list of subscribers. This list can be of either
* {@link org.wso2.carbon.device.mgt.common.DeviceIdentifier} if {@param subType} is equal
* to DEVICE or
* {@link String} if {@param subType} is USER, ROLE or GROUP
* @param subType subscription type. E.g. <code>DEVICE, USER, ROLE, GROUP</code> {@see {
* @param <T> generic type of the method.
* @return {@link ApplicationSubscriptionInfo}
* @throws ApplicationManagementException if error occurred while getting Application subscription info
*/
private <T> ApplicationSubscriptionInfo getAppSubscriptionInfo(ApplicationDTO applicationDTO, String subType,
List<T> params) throws ApplicationManagementException {
DeviceManagementProviderService deviceManagementProviderService = HelperUtil
.getDeviceManagementProviderService();
GroupManagementProviderService groupManagementProviderService = HelperUtil.getGroupManagementProviderService();
List<Device> devices = new ArrayList<>();
List<String> subscribers = new ArrayList<>();
List<DeviceIdentifier> errorDeviceIdentifiers = new ArrayList<>();
String deviceTypeName = null;
try {
if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) {
deviceTypeName = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()).getName();
}
if (SubscriptionType.DEVICE.toString().equals(subType)) {
for (T param : params) {
DeviceIdentifier deviceIdentifier = (DeviceIdentifier) param;
if (StringUtils.isEmpty(deviceIdentifier.getId()) || StringUtils
.isEmpty(deviceIdentifier.getType())) {
log.warn("Found a device identifier which has either empty identity of the device or empty"
+ " device type. Hence ignoring the device identifier. ");
continue;
}
if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType()) && !deviceIdentifier
.getType().equals(deviceTypeName)) {
log.warn("Found a device identifier which is not matched with the supported device type "
+ "of the application release which has UUID " + applicationDTO
.getApplicationReleaseDTOs().get(0).getUuid() + " Application "
+ "supported device type is " + deviceTypeName + " and the identifier of which has a "
+ "different device type is " + deviceIdentifier.getId());
errorDeviceIdentifiers.add(deviceIdentifier);
continue;
}
devices.add(deviceManagementProviderService.getDevice(deviceIdentifier, false));
}
} else if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
for (T param : params) {
String username = (String) param;
subscribers.add(username);
devices.addAll(deviceManagementProviderService.getDevicesOfUser(username));
}
} else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
for (T param : params) {
String roleName = (String) param;
subscribers.add(roleName);
devices.addAll(deviceManagementProviderService.getAllDevicesOfRole(roleName));
}
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
for (T param : params) {
String groupName = (String) param;
subscribers.add(groupName);
devices.addAll(groupManagementProviderService.getAllDevicesOfGroup(groupName, true));
}
} else {
String msg = "Found invalid subscription type " + subType+ " to install application release" ;
log.error(msg);
throw new BadRequestException(msg);
}
if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType()) && !SubscriptionType.DEVICE
.toString().equals(subType)) {
//filter devices by device type
String tmpDeviceTypeName = deviceTypeName;
devices.removeIf(device -> !tmpDeviceTypeName.equals(device.getType()));
}
ApplicationSubscriptionInfo applicationSubscriptionInfo = new ApplicationSubscriptionInfo();
applicationSubscriptionInfo.setDevices(devices);
applicationSubscriptionInfo.setSubscribers(subscribers);
applicationSubscriptionInfo.setErrorDeviceIdentifiers(errorDeviceIdentifiers);
applicationSubscriptionInfo.setAppSupportingDeviceTypeName(deviceTypeName);
return applicationSubscriptionInfo;
} catch (DeviceManagementException e) {
String msg = "Error occurred while getting devices of given users or given roles or while getting device "
+ "type info.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (GroupManagementException e) {
String msg = "Error occurred while getting devices of given groups";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
}
/** /**
* This method is responsible to update subscription data for google enterprise install. * This method is responsible to update subscription data for google enterprise install.
* *
@ -567,8 +530,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
} }
/** /**
* THis method is responsible to validate application install or uninstall request. * THis method is responsible to validate application install or uninstall request.
* *
@ -704,14 +665,12 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|| Operation.Status.IN_PROGRESS.toString().equals(deviceSubscriptionDTO.getStatus())) { || Operation.Status.IN_PROGRESS.toString().equals(deviceSubscriptionDTO.getStatus())) {
subscribingDeviceIdHolder.getSkippedDevices().put(deviceIdentifier, device.getId()); subscribingDeviceIdHolder.getSkippedDevices().put(deviceIdentifier, device.getId());
} else if (deviceSubscriptionDTO.isUnsubscribed()) { } else if (deviceSubscriptionDTO.isUnsubscribed()) {
if (Operation.Status.COMPLETED.toString().equals(deviceSubscriptionDTO.getStatus())) { if (!Operation.Status.COMPLETED.toString().equals(deviceSubscriptionDTO.getStatus())) {
subscribingDeviceIdHolder.getAppReInstallableDevices().put(deviceIdentifier, device.getId());
} else {
/*We can't ensure whether app is uninstalled successfully or not hence allow to perform both /*We can't ensure whether app is uninstalled successfully or not hence allow to perform both
install and uninstall operations*/ install and uninstall operations*/
subscribingDeviceIdHolder.getAppReUnInstallableDevices().put(deviceIdentifier, device.getId()); subscribingDeviceIdHolder.getAppReUnInstallableDevices().put(deviceIdentifier, device.getId());
subscribingDeviceIdHolder.getAppReInstallableDevices().put(deviceIdentifier, device.getId());
} }
subscribingDeviceIdHolder.getAppReInstallableDevices().put(deviceIdentifier, device.getId());
} else if (!deviceSubscriptionDTO.isUnsubscribed() && Operation.Status.COMPLETED.toString() } else if (!deviceSubscriptionDTO.isUnsubscribed() && Operation.Status.COMPLETED.toString()
.equals(deviceSubscriptionDTO.getStatus())) { .equals(deviceSubscriptionDTO.getStatus())) {
subscribingDeviceIdHolder.getAppInstalledDevices().put(deviceIdentifier, device.getId()); subscribingDeviceIdHolder.getAppInstalledDevices().put(deviceIdentifier, device.getId());
@ -1126,8 +1085,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
@Override @Override
public PaginationResult getAppInstalledDevices(int offsetValue, int limitValue, String appUUID, public PaginationResult getAppInstalledDevices(int offsetValue, int limitValue, String appUUID, String status)
String status)
throws ApplicationManagementException { throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
DeviceManagementProviderService deviceManagementProviderService = HelperUtil DeviceManagementProviderService deviceManagementProviderService = HelperUtil

@ -20,24 +20,20 @@ package org.wso2.carbon.device.application.mgt.core.util;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
import java.util.List;
import java.util.UUID;
/** /**
* Utility methods used in the Application Management. * Utility methods used in the Application Management.
*/ */
public class HelperUtil { public class HelperUtil {
private static Log log = LogFactory.getLog(HelperUtil.class); private static final Log log = LogFactory.getLog(HelperUtil.class);
private static DeviceManagementProviderService deviceManagementProviderService; private static DeviceManagementProviderService deviceManagementProviderService;
private static GroupManagementProviderService groupManagementProviderService; private static GroupManagementProviderService groupManagementProviderService;
public static DeviceManagementProviderService getDeviceManagementProviderService() { public static synchronized DeviceManagementProviderService getDeviceManagementProviderService() {
if (deviceManagementProviderService == null) { if (deviceManagementProviderService == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
deviceManagementProviderService = (DeviceManagementProviderService) ctx deviceManagementProviderService = (DeviceManagementProviderService) ctx
@ -51,7 +47,7 @@ public class HelperUtil {
return deviceManagementProviderService; return deviceManagementProviderService;
} }
public static GroupManagementProviderService getGroupManagementProviderService() { public static synchronized GroupManagementProviderService getGroupManagementProviderService() {
if (groupManagementProviderService == null) { if (groupManagementProviderService == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
groupManagementProviderService = (GroupManagementProviderService) ctx groupManagementProviderService = (GroupManagementProviderService) ctx

Loading…
Cancel
Save