From dc6bbdd282d7653df302c570f45957be50f7c6ba Mon Sep 17 00:00:00 2001 From: Dharmakeerthi Lasantha Date: Wed, 12 Jul 2023 00:05:02 +0530 Subject: [PATCH] Improve functionality and fix formatting issues --- .../mgt/core/impl/ApplicationManagerImpl.java | 6 +++--- .../mgt/core/impl/SubscriptionManagerImpl.java | 12 +++++++++++- .../core/application/mgt/core/util/Constants.java | 3 +++ .../service/impl/RoleManagementServiceImpl.java | 12 ++++++++++-- .../mgt/core/operation/mgt/OperationManagerImpl.java | 9 ++++++++- .../service/DeviceManagementProviderServiceImpl.java | 10 +++++++++- .../service/GroupManagementProviderServiceImpl.java | 2 +- 7 files changed, 45 insertions(+), 9 deletions(-) diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/ApplicationManagerImpl.java index fba517f148..6b4d590fa8 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/ApplicationManagerImpl.java @@ -1250,7 +1250,7 @@ public class ApplicationManagerImpl implements ApplicationManager { this.changeLifecycleState(applicationReleaseDTO, lifecycleChanger); } } - if (applicationDTO.getType().equals("ENTERPRISE") || applicationDTO.getType().equals("PUBLIC") ) { + if (Constants.ENTERPRISE_APP_TYPE.equals(applicationDTO.getType()) || Constants.PUBLIC_APP_TYPE.equals(applicationDTO.getType())) { persistAppIconInfo(applicationReleaseDTO); } applicationReleaseEntities.add(applicationReleaseDTO); @@ -1690,8 +1690,8 @@ public class ApplicationManagerImpl implements ApplicationManager { List allMetadata; allMetadata = APIUtil.getMetadataManagementService().retrieveAllMetadata(); if (allMetadata != null && !allMetadata.isEmpty()) { - for(Metadata metadata : allMetadata){ - if(Constants.SHOW_ALL_ROLES.equals(metadata.getMetaKey())){ + for (Metadata metadata : allMetadata) { + if (Constants.SHOW_ALL_ROLES.equals(metadata.getMetaKey())) { String metaValue = metadata.getMetaValue(); if (metaValue != null) { JSONObject jsonObject; diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/SubscriptionManagerImpl.java index 92c1a93f18..5fdbbfaca1 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -684,7 +684,17 @@ public class SubscriptionManagerImpl implements SubscriptionManager { Activity activity = addAppOperationOnDevices(applicationDTO, deviceIdentifiers, deviceType, action, properties); activityList.add(activity); for (DeviceIdentifier identifier : deviceIdentifiers) { - log.info(String.format("App %s triggered", action), appInstallLogContextBuilder.setAppId(String.valueOf(applicationDTO.getId())).setAppName(applicationDTO.getName()).setAppType(applicationDTO.getType()).setSubType(subType).setTenantId(tenantId).setTenantDomain(tenantDomain).setDevice(String.valueOf(identifier)).setUserName(username).setAction(action).build()); + log.info(String.format("App %s triggered", action), appInstallLogContextBuilder + .setAppId(String.valueOf(applicationDTO.getId())) + .setAppName(applicationDTO.getName()) + .setAppType(applicationDTO.getType()) + .setSubType(subType) + .setTenantId(tenantId) + .setTenantDomain(tenantDomain) + .setDevice(String.valueOf(identifier)) + .setUserName(username) + .setAction(action) + .build()); } } diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/Constants.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/Constants.java index efd848cdb1..c3e7c49160 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/Constants.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/Constants.java @@ -94,6 +94,9 @@ public class Constants { public static final String MSI = "MSI"; public static final String APPX = "APPX"; + public static final String ENTERPRISE_APP_TYPE = "ENTERPRISE"; + public static final String PUBLIC_APP_TYPE = "ENTERPRISE"; + private static final Map AGENT_DATA = new HashMap<>(); static { AGENT_DATA.put("android", "android-agent.apk"); diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/RoleManagementServiceImpl.java index 44150409ad..5c04516650 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -17,6 +17,7 @@ */ package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl; +import com.google.common.base.Strings; import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException; import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata; @@ -35,6 +36,7 @@ import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.SetReferenceTransformer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.util.StringUtils; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.context.CarbonContext; @@ -57,6 +59,12 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URLEncoder; import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; import static io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.Constants.PRIMARY_USER_STORE; @@ -120,7 +128,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { if (limit == 0){ limit = Constants.DEFAULT_PAGE_LIMIT; } - if (domain != null && !domain.isEmpty()) { + if (!Strings.isNullOrEmpty(domain)) { username = domain + '/' + username; } Metadata metadata; @@ -133,7 +141,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { JSONObject jsonObject = (JSONObject) parser.parse(metaValue); boolean decision = (boolean) jsonObject.get(Constants.IS_USER_ABLE_TO_VIEW_ALL_ROLES); if (decision) { - if (userStore == null || "".equals(userStore)){ + if (Strings.isNullOrEmpty(userStore)){ userStore = PRIMARY_USER_STORE; } try { diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/OperationManagerImpl.java index 223eb95564..e752475939 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -721,7 +721,14 @@ public class OperationManagerImpl implements OperationManager { DeviceCacheManagerImpl.getInstance().removeDeviceFromCache(deviceId, tenantId); break; } - log.info("Device Connected", deviceConnectivityLogContextBuilder.setDeviceId(deviceId.getId()).setDeviceType(deviceId.getType()).setActionTag("PENDING_OPERATION").setTenantDomain(tenantDomain).setTenantId(String.valueOf(tenantId)).setUserName(userName).build()); + log.info("Device Connected", deviceConnectivityLogContextBuilder + .setDeviceId(deviceId.getId()) + .setDeviceType(deviceId.getType()) + .setActionTag("PENDING_OPERATION") + .setTenantDomain(tenantDomain) + .setTenantId(String.valueOf(tenantId)) + .setUserName(userName) + .build()); return getOperations(deviceId, Operation.Status.PENDING, enrolmentId); } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 31b77ebef3..eb1a60c48c 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -331,7 +331,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv device.getType() + " upon the user '" + device.getEnrolmentInfo().getOwner() + "'"); } - log.info("Device enrolled successfully", deviceEnrolmentLogContextBuilder.setDeviceId(String.valueOf(existingDevice.getId())).setDeviceType(String.valueOf(existingDevice.getType())).setOwner(newEnrolmentInfo.getOwner()).setOwnership(String.valueOf(newEnrolmentInfo.getOwnership())).setTenantID(String.valueOf(tenantId)).setTenantDomain(tenantDomain).setUserName(userName).build()); + log.info("Device enrolled successfully", deviceEnrolmentLogContextBuilder + .setDeviceId(String.valueOf(existingDevice.getId())) + .setDeviceType(String.valueOf(existingDevice.getType())) + .setOwner(newEnrolmentInfo.getOwner()) + .setOwnership(String.valueOf(newEnrolmentInfo.getOwnership())) + .setTenantID(String.valueOf(tenantId)) + .setTenantDomain(tenantDomain) + .setUserName(userName) + .build()); status = true; } else { log.warn("Unable to update device enrollment for device : " + device.getDeviceIdentifier() + diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderServiceImpl.java index 3e03301769..a35d4d74bb 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderServiceImpl.java @@ -314,7 +314,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid newParentPath = DeviceGroupConstants.HierarchicalGroup.SEPERATOR; } childrenGroup.setParentPath(newParentPath); - if (!newParentPath.equals(DeviceGroupConstants.HierarchicalGroup.SEPERATOR)) { + if (!DeviceGroupConstants.HierarchicalGroup.SEPERATOR.equals(newParentPath)) { String[] groupIds = newParentPath.split(DeviceGroupConstants.HierarchicalGroup.SEPERATOR); int latestGroupId = Integer.parseInt(groupIds[groupIds.length - 1]); childrenGroup.setParentGroupId(latestGroupId);