diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml index 99b22c95fb..5bcc57cbc9 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml @@ -22,13 +22,13 @@ apimgt-extensions org.wso2.carbon.devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.annotations - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT bundle WSO2 Carbon - API Management Annotations WSO2 Carbon - API Management Custom Annotation Module diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml index 31f085021c..739f00404f 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml @@ -21,12 +21,12 @@ apimgt-extensions org.wso2.carbon.devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml 4.0.0 - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT org.wso2.carbon.apimgt.application.extension.api war WSO2 Carbon - API Application Management API diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml index 88fba8a1c2..461cc64cda 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml @@ -22,12 +22,12 @@ apimgt-extensions org.wso2.carbon.devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml 4.0.0 - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT org.wso2.carbon.apimgt.application.extension bundle WSO2 Carbon - API Application Management diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/pom.xml index 99e02f1b37..2b73b19504 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.handlers/pom.xml @@ -21,13 +21,13 @@ apimgt-extensions org.wso2.carbon.devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.handlers - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT bundle WSO2 Carbon - API Security Handler Component WSO2 Carbon - API Management Security Handler Module diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/pom.xml index 72eedc75aa..81981fb4a2 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/pom.xml @@ -13,13 +13,13 @@ apimgt-extensions org.wso2.carbon.devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.integration.client - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT bundle WSO2 Carbon - API Management Integration Client WSO2 Carbon - API Management Integration Client diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/IntegrationClientServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/IntegrationClientServiceImpl.java index 7878bcfffd..94c6f7e87c 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/IntegrationClientServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/IntegrationClientServiceImpl.java @@ -22,11 +22,16 @@ import feign.RequestInterceptor; import org.wso2.carbon.apimgt.integration.client.publisher.PublisherClient; import org.wso2.carbon.apimgt.integration.client.service.IntegrationClientService; import org.wso2.carbon.apimgt.integration.client.store.StoreClient; +import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo; + +import java.util.HashMap; +import java.util.Map; public class IntegrationClientServiceImpl implements IntegrationClientService { private static StoreClient storeClient; private static PublisherClient publisherClient; + private static Map tenantUserTokenMap = new HashMap<>(); public IntegrationClientServiceImpl() { RequestInterceptor oAuthRequestInterceptor = new OAuthRequestInterceptor(); @@ -42,4 +47,8 @@ public class IntegrationClientServiceImpl implements IntegrationClientService { public PublisherClient getPublisherClient() { return publisherClient; } + + public static Map getTenantUserTokenMap() { + return tenantUserTokenMap; + } } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/OAuthRequestInterceptor.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/OAuthRequestInterceptor.java index a1ab7d6c73..b78f258c27 100755 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/OAuthRequestInterceptor.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/OAuthRequestInterceptor.java @@ -55,7 +55,6 @@ public class OAuthRequestInterceptor implements RequestInterceptor { private static final long DEFAULT_REFRESH_TIME_OFFSET_IN_MILLIS = 100000; private DCRClient dcrClient; private static OAuthApplication oAuthApplication; - private static Map tenantUserTokenMap = new HashMap<>(); private static final Log log = LogFactory.getLog(OAuthRequestInterceptor.class); /** @@ -89,7 +88,7 @@ public class OAuthRequestInterceptor implements RequestInterceptor { if (!tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { username = username + "@" + tenantDomain; } - AccessTokenInfo tenantBasedAccessTokenInfo = tenantUserTokenMap.get(username); + AccessTokenInfo tenantBasedAccessTokenInfo = IntegrationClientServiceImpl.getTenantUserTokenMap().get(username); if ((tenantBasedAccessTokenInfo == null || ((System.currentTimeMillis() + DEFAULT_REFRESH_TIME_OFFSET_IN_MILLIS) > tenantBasedAccessTokenInfo.getExpiresIn()))) { @@ -106,7 +105,7 @@ public class OAuthRequestInterceptor implements RequestInterceptor { } if (tenantBasedAccessTokenInfo.getScopes().contains(APIM_SUBSCRIBE_SCOPE)) { - tenantUserTokenMap.put(username, tenantBasedAccessTokenInfo); + IntegrationClientServiceImpl.getTenantUserTokenMap().put(username, tenantBasedAccessTokenInfo); } } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/pom.xml index f9d267bccd..a43eabfd19 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/pom.xml @@ -13,13 +13,13 @@ apimgt-extensions org.wso2.carbon.devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.integration.generated.client - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT bundle WSO2 Carbon - API Management Integration Generated Client WSO2 Carbon - API Management Integration Client diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml index c02e8b3627..cfbfa5b3ea 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml @@ -22,13 +22,13 @@ apimgt-extensions org.wso2.carbon.devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.apimgt.webapp.publisher - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT bundle WSO2 Carbon - API Management Webapp Publisher WSO2 Carbon - API Management Webapp Publisher diff --git a/components/apimgt-extensions/pom.xml b/components/apimgt-extensions/pom.xml index c68630e532..2409e0e735 100644 --- a/components/apimgt-extensions/pom.xml +++ b/components/apimgt-extensions/pom.xml @@ -22,13 +22,13 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../../pom.xml 4.0.0 apimgt-extensions - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT pom WSO2 Carbon - API Management Extensions Component http://wso2.org diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml index 7de05aac12..da658031d6 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml @@ -22,7 +22,7 @@ certificate-mgt org.wso2.carbon.devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml index 0e0f5ea20a..137fdfabc8 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml @@ -22,7 +22,7 @@ certificate-mgt org.wso2.carbon.devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml index 166bcd7911..1f026df1d1 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml @@ -21,13 +21,13 @@ org.wso2.carbon.devicemgt certificate-mgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.certificate.mgt.core - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT bundle WSO2 Carbon - Certificate Management Core WSO2 Carbon - Certificate Management Core diff --git a/components/certificate-mgt/pom.xml b/components/certificate-mgt/pom.xml index 44830d45e9..f8343dff94 100644 --- a/components/certificate-mgt/pom.xml +++ b/components/certificate-mgt/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../../pom.xml 4.0.0 org.wso2.carbon.devicemgt certificate-mgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT pom WSO2 Carbon - Certificate Management Component http://wso2.org diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml index 1c90d4ac8f..207cc5edab 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml index 74e3ba1981..4b98205c46 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml index ad59d20f86..8fe557d23a 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml index 5d859b4138..c89a82b7ba 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml index c10f9f0ccc..c4256da803 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml index 6521c67a98..9a727ee8bb 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/pom.xml b/components/device-mgt-extensions/pom.xml index 04b84e9667..f6bfa14709 100644 --- a/components/device-mgt-extensions/pom.xml +++ b/components/device-mgt-extensions/pom.xml @@ -22,7 +22,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml index d73ef6e716..f3c81a2885 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml @@ -3,7 +3,7 @@ org.wso2.carbon.devicemgt device-mgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml index 6b6ad31609..116b20ff09 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml index c617e38214..313ca80058 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml @@ -362,6 +362,11 @@ org.wso2.carbon.event.stream.persistence.stub provided + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.integration.client + provided + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/CredentialManagementResponseBuilder.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/CredentialManagementResponseBuilder.java index 7007aa0d3e..a44444aa3d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/CredentialManagementResponseBuilder.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/CredentialManagementResponseBuilder.java @@ -20,7 +20,10 @@ package org.wso2.carbon.device.mgt.jaxrs.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.apimgt.integration.client.IntegrationClientServiceImpl; +import org.wso2.carbon.apimgt.integration.client.service.IntegrationClientService; import org.wso2.carbon.context.CarbonContext; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.PasswordResetWrapper; @@ -63,6 +66,9 @@ public class CredentialManagementResponseBuilder { username = CarbonContext.getThreadLocalCarbonContext().getUsername(); userStoreManager.updateCredential(username, credentials.getNewPassword(), credentials.getOldPassword()); + IntegrationClientServiceImpl integrationClientService = (IntegrationClientServiceImpl) PrivilegedCarbonContext. + getThreadLocalCarbonContext().getOSGiService(IntegrationClientService.class, null); + integrationClientService.getTenantUserTokenMap().remove(username); return Response.status(Response.Status.OK).entity("UserImpl password by username: " + username + " was successfully changed.").build(); } catch (UserStoreException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml index 32d0609fa9..bfb1b61a26 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml @@ -21,7 +21,7 @@ device-mgt org.wso2.carbon.devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/GroupPaginationRequest.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/GroupPaginationRequest.java index a0dfb9351b..3c17ce32a9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/GroupPaginationRequest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/GroupPaginationRequest.java @@ -65,4 +65,10 @@ public class GroupPaginationRequest { this.groupName = groupName; } + @Override + public String toString() { + return "Group Name '" + this.groupName + "' num of rows: " + this.rowCount + " start index: " + this.startIndex + + " owner' " + this.owner + "'"; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationRequest.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationRequest.java index 3799b397ba..e71ba71773 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationRequest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationRequest.java @@ -129,4 +129,12 @@ public class PaginationRequest { public void setOwnerPattern(String ownerPattern) { this.ownerPattern = ownerPattern; } + + @Override + public String toString() { + return "Device type '" + this.deviceType + "' Device Name '" + this.deviceName + "' row count: " + this.rowCount + + " Owner role '" + this.ownerRole + "' owner pattern '" + this.ownerPattern + "' ownership " + + this.ownership + "' Status '" + this.status + "' owner '" + this.owner + "' groupId: " + this.groupId + + " start index: " + this.startIndex; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index 3a62c46315..f70db5569c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 2f414e8f7b..a4afef2f48 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -160,6 +160,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public boolean enrollDevice(Device device) throws DeviceManagementException { + if (device == null) { + String msg = "Received empty device for device enrollment"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Enrolling the device " + device.getId() + "of type '" + device.getType() + "'"); + } boolean status = false; DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()); @@ -228,9 +236,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } } catch (DeviceManagementDAOException e) { DeviceManagementDAOFactory.rollbackTransaction(); - throw new DeviceManagementException("Error occurred while adding enrolment related metadata", e); + String msg = "Error occurred while adding enrolment related metadata for device: " + device.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (TransactionManagementException e) { - throw new DeviceManagementException("Error occurred while initiating transaction", e); + String msg = "Error occurred while initiating transaction to enrol device: " + device.getId(); + log.error(msg); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred while enrolling device: " + device.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -246,10 +262,18 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv DeviceManagementDAOFactory.commitTransaction(); } catch (DeviceManagementDAOException e) { DeviceManagementDAOFactory.rollbackTransaction(); - throw new DeviceManagementException("Error occurred while adding metadata of '" + device.getType() + - "' device carrying the identifier '" + device.getDeviceIdentifier() + "'", e); + String msg = "Error occurred while adding metadata of '" + device.getType() + + "' device carrying the identifier '" + device.getDeviceIdentifier() + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (TransactionManagementException e) { - throw new DeviceManagementException("Error occurred while initiating transaction", e); + String msg = "Error occurred while initiating transaction"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred while enrolling device: " + device.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -266,7 +290,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv if (status) { addDeviceToGroups(deviceIdentifier, device.getEnrolmentInfo().getOwnership()); addInitialOperations(deviceIdentifier, device.getType()); - } return status; } @@ -274,6 +297,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public boolean modifyEnrollment(Device device) throws DeviceManagementException { + if (device == null) { + String msg = "Required values are not set to modify device enrollment"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Modifying enrollment for device: " + device.getId() + " of type '" + device.getType() + "'"); + } DeviceManager deviceManager = this.getDeviceManager(device.getType()); DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()); if (deviceManager == null) { @@ -301,10 +332,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv this.removeDeviceFromCache(deviceIdentifier); } catch (DeviceManagementDAOException e) { DeviceManagementDAOFactory.rollbackTransaction(); - throw new DeviceManagementException("Error occurred while modifying the device " + - "'" + device.getId() + "'", e); + String msg = "Error occurred while modifying the device '" + device.getId() + "'"; + log.error(msg); + throw new DeviceManagementException(msg, e); } catch (TransactionManagementException e) { - throw new DeviceManagementException("Error occurred while initiating transaction", e); + String msg = "Error occurred while initiating transaction to modify device: " + device.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred while modifying device: " + device.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -313,15 +351,31 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv private List getEnrollmentsOfUser(int deviceId, String user) throws DeviceManagementException { + if (user == null || user.isEmpty()) { + String msg = "Required values are not set to getEnrollmentsOfUser"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get enrollments for user '" + user + "' device: " + deviceId); + } List enrolmentInfos = new ArrayList<>(); try { DeviceManagementDAOFactory.openConnection(); enrolmentInfos = enrollmentDAO.getEnrollmentsOfUser(deviceId, user, this.getTenantId()); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while obtaining the enrollment information device for" + - "id '" + deviceId + "' and user : " + user, e); + String msg = "Error occurred while obtaining the enrollment information device for id '" + deviceId + + "' and user : " + user; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getEnrollmentsOfUser user '" + user + "' device: " + deviceId; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -330,6 +384,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + if (deviceId == null) { + String msg = "Required values are not set to dis-enroll device"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Dis-enrolling device: " + deviceId.getId() + " of type '" + deviceId.getType() + "'"); + } DeviceManager deviceManager = this.getDeviceManager(deviceId.getType()); if (deviceManager == null) { if (log.isDebugEnabled()) { @@ -351,7 +413,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv if (device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.REMOVED)) { if (log.isDebugEnabled()) { - log.debug("Device has already disenrolled : " + deviceId.getId() + "'"); + log.debug("Device has already dis-enrolled : " + deviceId.getId() + "'"); } return true; } @@ -362,15 +424,22 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv DeviceManagementDAOFactory.beginTransaction(); enrollmentDAO.updateEnrollment(device.getId(), device.getEnrolmentInfo(), tenantId); deviceDAO.updateDevice(device, tenantId); - DeviceManagementDAOFactory.commitTransaction(); this.removeDeviceFromCache(deviceId); } catch (DeviceManagementDAOException e) { DeviceManagementDAOFactory.rollbackTransaction(); - throw new DeviceManagementException("Error occurred while dis-enrolling '" + deviceId.getType() + - "' device with the identifier '" + deviceId.getId() + "'", e); + String msg = "Error occurred while dis-enrolling '" + deviceId.getType() + + "' device with the identifier '" + deviceId.getId() + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (TransactionManagementException e) { - throw new DeviceManagementException("Error occurred while initiating transaction", e); + String msg = "Error occurred while initiating transaction"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred while dis-enrolling device: " + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -419,6 +488,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public List getAllDevices(String deviceType, boolean requireDeviceInfo) throws DeviceManagementException { + if (deviceType == null) { + String msg = "Device type is empty for method getAllDevices"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Getting all devices of type '" + deviceType + "' and requiredDeviceInfo: " + requireDeviceInfo); + } List allDevices; try { DeviceManagementDAOFactory.openConnection(); @@ -430,14 +507,21 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return null; } } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while retrieving all devices of type '" + - deviceType + "' that are being managed within the scope of current tenant", e); + String msg = "Error occurred while retrieving all devices of type '" + + deviceType + "' that are being managed within the scope of current tenant"; + log.error(msg); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred while getting all devices of device type '" + deviceType + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } - if (requireDeviceInfo) { return this.getAllDeviceInfo(allDevices); } @@ -451,15 +535,25 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public List getAllDevices(boolean requireDeviceInfo) throws DeviceManagementException { + if (log.isDebugEnabled()) { + log.debug("Getting all devices with requiredDeviceInfo: " + requireDeviceInfo); + } List allDevices; try { DeviceManagementDAOFactory.openConnection(); allDevices = deviceDAO.getDevices(this.getTenantId()); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while retrieving device list pertaining to " + - "the current tenant", e); + String msg = "Error occurred while retrieving device list pertaining to the current tenant"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in get all devices"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -477,15 +571,31 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public List getDevices(Date since, boolean requireDeviceInfo) throws DeviceManagementException { + if (since == null) { + String msg = "Given date is empty for method getDevices"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Getting all devices since date '" + since.toString() + "' and required device info: " + + requireDeviceInfo); + } List allDevices; try { DeviceManagementDAOFactory.openConnection(); allDevices = deviceDAO.getDevices(since.getTime(), this.getTenantId()); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while retrieving device list pertaining to " + - "the current tenant", e); + String msg = "Error occurred while retrieving device list pertaining to the current tenant"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred get devices since '" + since.toString() + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -503,6 +613,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public PaginationResult getDevicesByType(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException { + if (request == null) { + String msg = "Received incomplete pagination request for getDevicesByType"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get devices with pagination " + request.toString() + " and required deviceinfo: " + + requireDeviceInfo); + } PaginationResult paginationResult = new PaginationResult(); List allDevices = new ArrayList<>(); int count = 0; @@ -514,10 +633,18 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv allDevices = deviceDAO.getDevices(request, tenantId); count = deviceDAO.getDeviceCountByType(deviceType, tenantId); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while retrieving device list pertaining to " + - "the current tenant of type " + deviceType, e); + String msg = "Error occurred while retrieving device list pertaining to the current tenant of type " + + deviceType; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getDeviceByType"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -540,6 +667,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public PaginationResult getAllDevices(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException { + if (request == null) { + String msg = "Received incomplete pagination request for method getAllDevices"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get devices with pagination " + request.toString() + " and requiredDeviceInfo: " + requireDeviceInfo); + } List devicesForRoles = null; PaginationResult paginationResult = new PaginationResult(); List allDevices = new ArrayList<>(); @@ -560,10 +695,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv allDevices = deviceDAO.getDevices(request, tenantId); count = deviceDAO.getDeviceCount(request, tenantId); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while retrieving device list pertaining to " + - "the current tenant", e); + String msg = "Error occurred while retrieving device list pertaining to the current tenant"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getAllDevices"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -580,6 +722,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public Device getDevice(DeviceIdentifier deviceId, boolean requireDeviceInfo) throws DeviceManagementException { + if (deviceId == null) { + String msg = "Received null device identifier for method getDevice"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get device by device id :" + deviceId.getId() + " of type '" + deviceId.getType() + + "' and requiredDeviceInfo: " + requireDeviceInfo); + } int tenantId = this.getTenantId(); Device device = this.getDeviceFromCache(deviceId); if (device == null) { @@ -596,10 +747,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } this.addDeviceToCache(deviceId, device); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while obtaining the device for id " + - "'" + deviceId.getId() + "'", e); + String msg = "Error occurred while obtaining the device for '" + deviceId.getId() + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getDevice: " + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -612,6 +770,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public void sendEnrolmentInvitation(String templateName, EmailMetaInfo metaInfo) throws DeviceManagementException { + if (metaInfo == null) { + String msg = "Received incomplete data to method sendEnrolmentInvitation"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Send enrollment invitation, templateName '" + templateName + "'"); + } Map, Object>> params = new HashMap<>(); Properties props = metaInfo.getProperties(); Enumeration e = props.propertyNames(); @@ -629,12 +795,26 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv metaInfo.getRecipients()).build(); DeviceManagementDataHolder.getInstance().getEmailSenderService().sendEmail(ctx); } catch (EmailSendingFailedException ex) { - throw new DeviceManagementException("Error occurred while sending enrollment invitation." + ex.getMessage(), ex); + String msg = "Error occurred while sending enrollment invitation"; + log.error(msg, ex); + throw new DeviceManagementException(msg, ex); + } catch (Exception ex) { + String msg = "Error occurred in setEnrollmentInvitation"; + log.error(msg, ex); + throw new DeviceManagementException(msg, ex); } } @Override public void sendRegistrationEmail(EmailMetaInfo metaInfo) throws DeviceManagementException { + if (metaInfo == null) { + String msg = "Received incomplete request for sendRegistrationEmail"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Send registration email"); + } Map, Object>> params = new HashMap<>(); params.put(org.wso2.carbon.device.mgt.core.DeviceManagementConstants.EmailAttributes.FIRST_NAME, new TypedValue, Object>(String.class, metaInfo.getProperty("first-name"))); @@ -657,12 +837,27 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv metaInfo.getRecipients()).build(); DeviceManagementDataHolder.getInstance().getEmailSenderService().sendEmail(ctx); } catch (EmailSendingFailedException e) { - throw new DeviceManagementException("Error occurred while sending user registration notification", e); + String msg = "Error occurred while sending user registration notification." + e.getMessage(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in sendRegistrationEmail"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } } @Override public HashMap getTenantedDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { + if (deviceIdentifier == null) { + String msg = "Received null deviceIdentifier for getTenantedDevice"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get tenanted device with id: " + deviceIdentifier.getId() + " of type '" + + deviceIdentifier.getType() + "'"); + } HashMap deviceHashMap; try { DeviceManagementDAOFactory.openConnection(); @@ -675,10 +870,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return null; } } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while obtaining the device for id " + - "'" + deviceIdentifier.getId() + "'", e); + String msg = "Error occurred while obtaining the device for id '" + deviceIdentifier.getId() + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getTenantedDevice device: " + deviceIdentifier.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -692,6 +894,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public Device getDeviceWithTypeProperties(DeviceIdentifier deviceId) throws DeviceManagementException { + if (deviceId == null) { + String msg = "Received null deviceIdentifier for getDeviceWithTypeProperties"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get tenanted device with type properties, deviceId: " + deviceId.getId()); + } Device device = this.getDevice(deviceId, false); DeviceManager deviceManager = this.getDeviceManager(device.getType()); @@ -718,6 +928,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public Device getDevice(DeviceIdentifier deviceId, Date since, boolean requireDeviceInfo) throws DeviceManagementException { + if (deviceId == null || since == null) { + String msg = "Received incomplete data for getDevice"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get device since '" + since.toString() + "' with identifier: " + deviceId.getId() + + " and type '" + deviceId.getType() + "'"); + } Device device; try { DeviceManagementDAOFactory.openConnection(); @@ -730,10 +949,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return null; } } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while obtaining the device for id " + - "'" + deviceId.getId() + "'", e); + String msg = "Error occurred while obtaining the device for id '" + deviceId.getId() + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getDevice for device: " + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -751,6 +977,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public Device getDevice(DeviceIdentifier deviceId, EnrolmentInfo.Status status, boolean requireDeviceInfo) throws DeviceManagementException { + if (deviceId == null) { + String msg = "Received null deviceIdentifier for getDevice"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get device with identifier: " + deviceId.getId() + " and type '" + deviceId.getType() + "'"); + } Device device; try { DeviceManagementDAOFactory.openConnection(); @@ -763,22 +997,31 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return null; } } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while obtaining the device for id " + - "'" + deviceId.getId() + "'", e); + String msg = "Error occurred while obtaining the device for id '" + deviceId.getId() + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getDevice for device: " + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } if (requireDeviceInfo) { device = this.getAllDeviceInfo(device); } - return device; } @Override public List getAvailableDeviceTypes() throws DeviceManagementException { + if (log.isDebugEnabled()) { + log.debug("Get available device types"); + } List deviceTypesProvidedByTenant; List publicSharedDeviceTypesInDB; List deviceTypesResponse = new ArrayList<>(); @@ -814,9 +1057,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while obtaining the device types.", e); + String msg = "Error occurred while obtaining the device types."; + log.info(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.info(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getAvailableDeviceTypes"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -825,6 +1076,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public boolean updateDeviceInfo(DeviceIdentifier deviceId, Device device) throws DeviceManagementException { + if (deviceId == null || device == null) { + String msg = "Received incomplete data for updateDeviceInfo"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Update device info of device: " + deviceId.getId()); + } DeviceManager deviceManager = this.getDeviceManager(deviceId.getType()); if (deviceManager == null) { if (log.isDebugEnabled()) { @@ -838,6 +1097,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException { + if (deviceId == null) { + String msg = "Received incomplete data for setOwnership"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Set ownership of device: " + deviceId.getId() + " ownership type '" + ownershipType + "'"); + } DeviceManager deviceManager = this.getDeviceManager(deviceId.getType()); if (deviceManager == null) { if (log.isDebugEnabled()) { @@ -865,6 +1132,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public boolean setStatus(DeviceIdentifier deviceId, String currentOwner, EnrolmentInfo.Status status) throws DeviceManagementException { + if (deviceId == null) { + String msg = "Received null deviceIdentifier for setStatus"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Set status of device: " + deviceId.getId()); + } try { boolean success = false; int tenantId = this.getTenantId(); @@ -879,9 +1154,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return success; } catch (DeviceManagementDAOException e) { DeviceManagementDAOFactory.rollbackTransaction(); - throw new DeviceManagementException("Error occurred while setting enrollment status", e); + String msg = "Error occurred while setting enrollment status"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (TransactionManagementException e) { - throw new DeviceManagementException("Error occurred while initiating transaction", e); + String msg = "Error occurred while initiating transaction"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in setStatus for device :" + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -890,6 +1173,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public boolean setStatus(String currentOwner, EnrolmentInfo.Status status) throws DeviceManagementException { + if (log.isDebugEnabled()) { + log.debug("Update enrollment with status"); + } try { boolean success = false; int tenantId = this.getTenantId(); @@ -899,9 +1185,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return success; } catch (DeviceManagementDAOException e) { DeviceManagementDAOFactory.rollbackTransaction(); - throw new DeviceManagementException("Error occurred while setting enrollment status", e); + String msg = "Error occurred while setting enrollment status"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (TransactionManagementException e) { - throw new DeviceManagementException("Error occurred while initiating transaction", e); + String msg = "Error occurred while initiating transaction"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in setStatus"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -923,6 +1217,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public License getLicense(String deviceType, String languageCode) throws DeviceManagementException { + if (deviceType == null || languageCode == null) { + String msg = "Received incomplete data for getLicence"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get the licence for device type '" + deviceType + "' languageCode '" + languageCode + "'"); + } DeviceManager deviceManager = this.getDeviceManager(deviceType); License license; if (deviceManager == null) { @@ -941,13 +1243,27 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } return license; } catch (LicenseManagementException e) { - throw new DeviceManagementException("Error occurred while retrieving license configured for " + - "device type '" + deviceType + "' and language code '" + languageCode + "'", e); + String msg = "Error occurred while retrieving license configured for " + + "device type '" + deviceType + "' and language code '" + languageCode + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getLicence for device type '" + deviceType + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } } @Override public void addLicense(String deviceType, License license) throws DeviceManagementException { + if (deviceType == null || license == null) { + String msg = "Received incomplete data for addLicence"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Add the licence for device type '" + deviceType + "'"); + } DeviceManager deviceManager = this.getDeviceManager(deviceType); if (deviceManager == null) { if (log.isDebugEnabled()) { @@ -959,8 +1275,13 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv try { deviceManager.addLicense(license); } catch (LicenseManagementException e) { - throw new DeviceManagementException("Error occurred while adding license for " + - "device type '" + deviceType + "'", e); + String msg = "Error occurred while adding license for device type '" + deviceType + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in addLicence for device type '" + deviceType + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } } @@ -1092,15 +1413,31 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public List getDevicesOfUser(String username, boolean requireDeviceInfo) throws DeviceManagementException { + if (username == null) { + String msg = "Username null in getDevicesOfUser"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get devices of user with username '" + username + "' and requiredDeviceInfo " + requireDeviceInfo); + } List userDevices; try { DeviceManagementDAOFactory.openConnection(); userDevices = deviceDAO.getDevicesOfUser(username, this.getTenantId()); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while retrieving the list of devices that " + - "belong to the user '" + username + "'", e); + String msg = "Error occurred while retrieving the list of devices that " + + "belong to the user '" + username + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getDevicesOfUser for username '" + username + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -1113,21 +1450,38 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public List getDevicesOfUser(String username, String deviceType) throws DeviceManagementException { - return this.getDevicesOfUser(username, deviceType, true); + return this.getDevicesOfUser(username, deviceType, true); } @Override public List getDevicesOfUser(String username, String deviceType, boolean requireDeviceInfo) throws DeviceManagementException { + if (username == null || deviceType == null) { + String msg = "Received incomplete data for getDevicesOfUser"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get '" + deviceType + "' devices of user with username '" + username + "' requiredDeviceInfo: " + + requireDeviceInfo); + } List userDevices; try { DeviceManagementDAOFactory.openConnection(); userDevices = deviceDAO.getDevicesOfUser(username, deviceType, this.getTenantId()); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while retrieving the list of devices that " + - "belong to the user '" + username + "'", e); + String msg = "Error occurred while retrieving the list of devices that " + + "belong to the user '" + username + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getDevicesOfUser for '" + username + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -1146,6 +1500,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public PaginationResult getDevicesOfUser(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException { + if (request == null) { + String msg = "Received incomplete pagination request for getDevicesOfUser"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get paginated results of devices of user " + request.toString() + " and requiredDeviceInfo: " + + requireDeviceInfo); + } PaginationResult result = new PaginationResult(); int deviceCount = 0; int tenantId = this.getTenantId(); @@ -1157,10 +1520,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv userDevices = deviceDAO.getDevicesOfUser(request, tenantId); deviceCount = deviceDAO.getDeviceCountByUser(username, tenantId); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while retrieving the list of devices that " + - "belong to the user '" + username + "'", e); + String msg = "Error occurred while retrieving the list of devices that belong to the user '" + username + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getDevicesOfUser"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -1185,6 +1555,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public PaginationResult getDevicesByOwnership(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException { + if (request == null) { + String msg = "Received incomplete data for getDevicesByOwnership"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get devices by ownership " + request.toString()); + } PaginationResult result = new PaginationResult(); List allDevices; int deviceCount = 0; @@ -1196,10 +1574,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv allDevices = deviceDAO.getDevicesByOwnership(request, tenantId); deviceCount = deviceDAO.getDeviceCountByOwnership(ownerShip, tenantId); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException( - "Error occurred while fetching the list of devices that matches to ownership : '" + ownerShip + "'", e); + String msg = "Error occurred while fetching the list of devices that matches to ownership : '" + ownerShip + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getDevicesByOwnership"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -1221,6 +1606,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public List getAllDevicesOfRole(String role, boolean requireDeviceInfo) throws DeviceManagementException { + if (role == null || role.isEmpty()) { + String msg = "Received empty role for the method getAllDevicesOfRole"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get devices of role '" + role + "' and requiredDeviceInfo: " + requireDeviceInfo); + } List devices = new ArrayList<>(); String[] users; int tenantId = this.getTenantId(); @@ -1228,8 +1621,13 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv users = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId) .getUserStoreManager().getUserListOfRole(role); } catch (UserStoreException e) { - throw new DeviceManagementException("Error occurred while obtaining the users, who are assigned " + - "with the role '" + role + "'", e); + String msg = "Error occurred while obtaining the users, who are assigned with the role '" + role + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getAllDevicesOfRole for role '" + role + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } List userDevices; @@ -1239,7 +1637,13 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv DeviceManagementDAOFactory.openConnection(); userDevices = deviceDAO.getDevicesOfUser(user, tenantId); } catch (DeviceManagementDAOException | SQLException e) { - log.error("Error occurred while obtaining the devices of user '" + user + "'", e); + String msg = "Error occurred while obtaining the devices of user '" + user + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred getAllDevicesOfRole for role '" + role + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -1252,14 +1656,29 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public int getDeviceCount(String username) throws DeviceManagementException { + if (username == null) { + String msg = "Received empty username for getDeviceCount"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Getting device count of the user '" + username + "'"); + } try { DeviceManagementDAOFactory.openConnection(); return deviceDAO.getDeviceCount(username, this.getTenantId()); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while retrieving the device count of user '" - + username + "'", e); + String msg = "Error occurred while retrieving the device count of user '" + username + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getDeviceCount for username '" + username + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -1267,13 +1686,24 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public int getDeviceCount() throws DeviceManagementException { + if (log.isDebugEnabled()) { + log.debug("Get devices count"); + } try { DeviceManagementDAOFactory.openConnection(); return deviceDAO.getDeviceCount(this.getTenantId()); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while retrieving the device count", e); + String msg = "Error occurred while retrieving the device count"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getDeviceCount"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -1282,6 +1712,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public List getDevicesByNameAndType(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException { + if (request == null) { + String msg = "Received incomplete data for getDevicesByNameAndType"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get devices by name " + request.toString() + " and requiredDeviceInfo: " + requireDeviceInfo); + } List devices = new ArrayList<>(); List allDevices; int limit = DeviceManagerUtil.validateDeviceListPageSize(request.getRowCount()); @@ -1289,11 +1727,21 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv DeviceManagementDAOFactory.openConnection(); allDevices = deviceDAO.getDevicesByNameAndType(request.getDeviceName(), request.getDeviceType(), this.getTenantId(), request.getStartIndex(), limit); + List filterd = null; + filterd.get(0); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while fetching the list of devices that matches to '" - + request.getDeviceName() + "'", e); + String msg = "Error occurred while fetching the list of devices that matches to '" + + request.getDeviceName() + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getDevicesByNameAndType"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -1312,6 +1760,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public PaginationResult getDevicesByName(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException { + if (request == null) { + String msg = "Received incomplete data for getDevicesByName"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get devices by name " + request.toString() + " requiredDeviceInfo: " + requireDeviceInfo); + } PaginationResult result = new PaginationResult(); int tenantId = this.getTenantId(); List allDevices = new ArrayList<>(); @@ -1324,10 +1780,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv result.setRecordsTotal(deviceCount); result.setRecordsFiltered(deviceCount); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while fetching the list of devices that matches to '" - + deviceName + "'", e); + String msg = "Error occurred while fetching the list of devices that matches to '" + deviceName + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getDevicesByName"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -1342,6 +1805,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public void updateDeviceEnrolmentInfo(Device device, EnrolmentInfo.Status status) throws DeviceManagementException { try { + if (device == null || status == null) { + String msg = "Received incomplete data for updateDeviceEnrolmentInfo"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Updating enrolment for device: " + device.getId() + " of type '" + device.getType() + "'"); + } DeviceManagementDAOFactory.beginTransaction(); device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime()); device.getEnrolmentInfo().setStatus(status); @@ -1349,10 +1820,18 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv DeviceManagementDAOFactory.commitTransaction(); } catch (DeviceManagementDAOException e) { DeviceManagementDAOFactory.rollbackTransaction(); - throw new DeviceManagementException("Error occurred update device enrolment status : '" + - device.getId() + "'", e); + String msg = "Error occurred while updating device enrolment status for " + device.getDeviceIdentifier() + + " of type " + device.getType(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (TransactionManagementException e) { - throw new DeviceManagementException("Error occurred while initiating transaction", e); + String msg = "Error occurred while initiating transaction"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in updateDeviceEnrolmentInfo"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -1360,21 +1839,34 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public void registerDeviceManagementService(DeviceManagementService deviceManagementService) { + if (log.isDebugEnabled()) { + log.debug("Registering device management service"); + } try { pluginRepository.addDeviceManagementProvider(deviceManagementService); } catch (DeviceManagementException e) { - log.error("Error occurred while registering device management plugin '" + - deviceManagementService.getType() + "'", e); + String msg = "Error occurred while registering device management plugin '" + + deviceManagementService.getType() + "'"; + log.error(msg, e); + } catch (Exception e) { + String msg = "Error occurred in registerDeviceManagementService"; + log.error(msg, e); } } @Override public void unregisterDeviceManagementService(DeviceManagementService deviceManagementService) { + if (log.isDebugEnabled()) { + log.debug("Unregister a device management service"); + } try { pluginRepository.removeDeviceManagementProvider(deviceManagementService); } catch (DeviceManagementException e) { log.error("Error occurred while un-registering device management plugin '" + deviceManagementService.getType() + "'", e); + } catch (Exception e) { + String msg = "Error occurred in unregisterDeviceManagementService"; + log.error(msg, e); } } @@ -1386,6 +1878,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public List getDevicesByStatus(EnrolmentInfo.Status status, boolean requireDeviceInfo) throws DeviceManagementException { + if (log.isDebugEnabled()) { + log.debug("get devices by status and requiredDeviceInfo: " + requireDeviceInfo); + } List allDevices; try { DeviceManagementDAOFactory.openConnection(); @@ -1394,7 +1889,13 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv throw new DeviceManagementException( "Error occurred while fetching the list of devices that matches to status: '" + status + "'", e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getDevicesByStatus"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -1412,8 +1913,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public PaginationResult getDevicesByStatus(PaginationRequest request, boolean requireDeviceInfo) throws DeviceManagementException { + if (request == null) { + String msg = "Received incomplete data for getDevicesByStatus"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get devices by status " + request.toString() + " and requiredDeviceInfo: " + + requireDeviceInfo); + } PaginationResult result = new PaginationResult(); - List allDevices = new ArrayList<>(); + List allDevices; int tenantId = this.getTenantId(); String status = request.getStatus(); request = DeviceManagerUtil.validateDeviceListPageSize(request); @@ -1424,10 +1934,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv result.setRecordsTotal(deviceCount); result.setRecordsFiltered(deviceCount); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException( - "Error occurred while fetching the list of devices that matches to status: '" + status + "'", e); + String msg = "Error occurred while fetching the list of devices that matches to status: '" + status + "'"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getDevicesByStatus"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -1470,6 +1987,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public boolean changeDeviceStatus(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status newStatus) throws DeviceManagementException { + if (deviceIdentifier == null) { + String msg = "Received incomplete data for getDevicesByStatus"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Change device status of device: " + deviceIdentifier.getId() + " of type '" + + deviceIdentifier.getType() + "'"); + } boolean isDeviceUpdated = false; Device device = getDevice(deviceIdentifier, false); int deviceId = device.getId(); @@ -1494,14 +2020,24 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public List getDeviceEnrolledTenants() throws DeviceManagementException { + if (log.isDebugEnabled()) { + log.debug("get device enrolled tenants"); + } try { DeviceManagementDAOFactory.openConnection(); return deviceDAO.getDeviceEnrolledTenants(); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while retrieving the tenants " + - "which have device enrolled.", e); + String msg = "Error occurred while retrieving the tenants which have device enrolled."; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getDeviceEnrolledTenants"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -1509,6 +2045,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv private boolean updateEnrollment(int deviceId, EnrolmentInfo enrolmentInfo, int tenantId) throws DeviceManagementException { + if (log.isDebugEnabled()) { + log.debug("Update enrollment of device: " + deviceId); + } boolean isUpdatedEnrollment = false; boolean isAutoCommit = true; try { @@ -1520,10 +2059,18 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv isUpdatedEnrollment = true; } } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while updating the enrollment information device for" + - "id '" + deviceId + "' .", e); + String msg = "Error occurred while updating the enrollment information device for" + + "id '" + deviceId + "' ."; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in updateEnrollment for deviceId: " + deviceId; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { try { DeviceManagementDAOFactory.getConnection().setAutoCommit(isAutoCommit); @@ -1562,6 +2109,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv */ private void addDeviceToGroups(DeviceIdentifier deviceIdentifier, EnrolmentInfo.OwnerShip ownership) throws DeviceManagementException { + if (deviceIdentifier == null) { + String msg = "Received incomplete data for addDeviceToGroup"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Add device:" + deviceIdentifier.getId() + " to default group"); + } GroupManagementProviderService groupManagementProviderService = new GroupManagementProviderServiceImpl(); try { DeviceGroup defaultGroup = createDefaultGroup(groupManagementProviderService, ownership.toString()); @@ -1571,14 +2126,30 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv groupManagementProviderService.addDevices(defaultGroup.getGroupId(), deviceIdentifiers); } } catch (DeviceNotFoundException e) { - throw new DeviceManagementException("Unable to find the device with the id: '" + deviceIdentifier.getId(), - e); + String msg = "Unable to find the device with the id: '" + deviceIdentifier.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (GroupManagementException e) { - throw new DeviceManagementException("An error occurred when adding the device to the group.", e); + String msg = "An error occurred when adding the device to the group."; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } } private void addInitialOperations(DeviceIdentifier deviceIdentifier, String deviceType) throws DeviceManagementException { + if (deviceIdentifier == null || deviceType == null) { + String msg = "Received incomplete data for getDevicesByStatus"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Add initial operations to the device:" + deviceIdentifier.getId() + " of type '" + + deviceType + "'"); + } DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance(). getDeviceManagementProvider(); DeviceManagementService deviceManagementService = @@ -1597,11 +2168,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv try { deviceManagementProviderService.addOperation(deviceType, operation, deviceIdentifiers); } catch (OperationManagementException e) { - throw new DeviceManagementException("Unable to add the operation for the device with the id: '" - + deviceIdentifier.getId(), e); + String msg = "Unable to add the operation for the device with the id: '" + deviceIdentifier.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (InvalidDeviceException e) { - throw new DeviceManagementException("Unable to find the device with the id: '" - + deviceIdentifier.getId(), e); + String msg = "Unable to find the device with the id: '" + deviceIdentifier.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } } } @@ -1618,6 +2195,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv */ private DeviceGroup createDefaultGroup(GroupManagementProviderService service, String groupName) throws GroupManagementException { + if (service == null || groupName == null) { + String msg = "Received incomplete data for createDefaultGroup"; + log.error(msg); + throw new GroupManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Create default group with name '" + groupName + "'"); + } DeviceGroup defaultGroup = service.getGroup(groupName); if (defaultGroup == null) { defaultGroup = new DeviceGroup(groupName); @@ -1628,10 +2213,13 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv service.createGroup(defaultGroup, DeviceGroupConstants.Roles.DEFAULT_ADMIN_ROLE, DeviceGroupConstants.Permissions.DEFAULT_ADMIN_PERMISSIONS); } catch (GroupAlreadyExistException e) { - if (log.isDebugEnabled()) { - log.debug("Default group: " + defaultGroup.getName() + " already exists. Skipping group creation.", - e); - } + String msg = "Default group: " + defaultGroup.getName() + " already exists. Skipping group creation."; + log.error(msg); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } return service.getGroup(groupName); } else { @@ -1648,14 +2236,31 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public DeviceType getDeviceType(String deviceType) throws DeviceManagementException { + if (deviceType != null) { + if (log.isDebugEnabled()) { + log.debug("Get device type '" + deviceType + "'"); + } + } else { + String msg = "Received null deviceType for getDeviceType"; + log.error(msg); + throw new DeviceManagementException(msg); + } try { DeviceManagementDAOFactory.openConnection(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); return deviceTypeDAO.getDeviceType(deviceType, tenantId); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while obtaining the device type " + deviceType, e); + String msg = "Error occurred while obtaining the device type " + deviceType; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -1663,15 +2268,25 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public List getDeviceTypes() throws DeviceManagementException { + if (log.isDebugEnabled()) { + log.debug("Get device types"); + } int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); try { DeviceManagementDAOFactory.openConnection(); return deviceTypeDAO.getDeviceTypes(tenantId); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while obtaining the device types for tenant " - + tenantId, e); + String msg = "Error occurred while obtaining the device types for tenant " + tenantId; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getDeviceTypes"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -1680,28 +2295,39 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public void notifyPullNotificationSubscriber(DeviceIdentifier deviceIdentifier, Operation operation) throws PullNotificationExecutionFailedException { + if (log.isDebugEnabled()) { + log.debug("Notify pull notification subscriber"); + } DeviceManagementService dms = pluginRepository.getDeviceManagementService(deviceIdentifier.getType(), this.getTenantId()); if (dms == null) { - String message = "Device type '" + deviceIdentifier.getType() + "' does not have an associated device management " + - "plugin registered within the framework"; - if (log.isDebugEnabled()) { - log.debug(message); - } + String message = "Device type '" + deviceIdentifier.getType() + "' does not have an associated " + + "device management plugin registered within the framework"; + log.error(message); throw new PullNotificationExecutionFailedException(message); } PullNotificationSubscriber pullNotificationSubscriber = dms.getPullNotificationSubscriber(); if (pullNotificationSubscriber == null) { - throw new PullNotificationExecutionFailedException("Pull Notification Subscriber is not configured " + - "for device type" + deviceIdentifier.getType()); + String message = "Pull Notification Subscriber is not configured " + + "for device type" + deviceIdentifier.getType(); + log.error(message); + throw new PullNotificationExecutionFailedException(message); } pullNotificationSubscriber.execute(deviceIdentifier, operation); } /** - * Returns all the device-info including location of the given device. + * Returns all the device-info including location of the given device. */ - private DeviceInfo getDeviceInfo(Device device) { + private DeviceInfo getDeviceInfo(Device device) throws DeviceManagementException { + if (device == null) { + String msg = "Received incomplete data for getDeviceInfo"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get device info of device: " + device.getId() + " of type '" + device.getType() + "'"); + } DeviceInfo info = null; try { DeviceManagementDAOFactory.openConnection(); @@ -1711,10 +2337,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv info.setLocation(location); } } catch (DeviceDetailsMgtDAOException e) { - log.error("Error occurred while retrieving advance info of '" + device.getType() + - "' that carries the id '" + device.getDeviceIdentifier() + "'"); + String msg = "Error occurred while retrieving advance info of '" + device.getType() + + "' that carries the id '" + device.getDeviceIdentifier() + "'"; + log.error(msg); + throw new DeviceManagementException(msg, e); } catch (SQLException e) { - log.error("Error occurred while opening a connection to the data source", e); + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getDeviceInfo for device: " + device.getId(); + log.error(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -1722,9 +2355,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } /** - * Returns all the installed apps of the given device. + * Returns all the installed apps of the given device. */ private List getInstalledApplications(Device device) { + if (log.isDebugEnabled()) { + log.debug("Get installed applications of device: " + device.getId() + " of type '" + device.getType() + "'"); + } List applications = new ArrayList<>(); try { DeviceManagementDAOFactory.openConnection(); @@ -1735,6 +2371,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv "which carries the id '" + device.getId() + "'", e); } catch (SQLException e) { log.error("Error occurred while opening a connection to the data source", e); + } catch (Exception e) { + String msg = "Error occurred in getInstalledApplications"; + log.error(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); } @@ -1742,17 +2381,23 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } /** - * Returns all the available information (device-info, location, applications and plugin-db data) - * of the given device list. + * Returns all the available information (device-info, location, applications and plugin-db data) + * of the given device list. */ - private List getAllDeviceInfo(List allDevices) - throws DeviceManagementException { + private List getAllDeviceInfo(List allDevices) throws DeviceManagementException { + if (allDevices.size() == 0) { + String msg = "Received empty device list for getAllDeviceInfo"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get all device info of devices, num of devices: " + allDevices.size()); + } List devices = new ArrayList<>(); if (allDevices != null) { for (Device device : allDevices) { device.setDeviceInfo(this.getDeviceInfo(device)); device.setApplications(this.getInstalledApplications(device)); - DeviceManager deviceManager = this.getDeviceManager(device.getType()); if (deviceManager == null) { if (log.isDebugEnabled()) { @@ -1775,10 +2420,18 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } /** - * Returns all the available information (device-info, location, applications and plugin-db data) - * of a given device. + * Returns all the available information (device-info, location, applications and plugin-db data) + * of a given device. */ private Device getAllDeviceInfo(Device device) throws DeviceManagementException { + if (device == null) { + String msg = "Received empty device for getAllDeviceInfo"; + log.error(msg); + throw new DeviceManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get all device info of device: " + device.getId() + " of type '" + device.getType() + "'"); + } device.setDeviceInfo(this.getDeviceInfo(device)); device.setApplications(this.getInstalledApplications(device)); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java index ad8ecf77d1..b5a2a4f635 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java @@ -65,6 +65,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid @Override public void createGroup(DeviceGroup deviceGroup, String defaultRole, String[] defaultPermissions) throws GroupManagementException, GroupAlreadyExistException { + if (deviceGroup == null) { + String msg = "Received incomplete data for createGroup"; + log.error(msg); + throw new GroupManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Creating group '" + deviceGroup.getName() + "'"); + } if (deviceGroup == null) { throw new GroupManagementException("DeviceGroup cannot be null.", new NullPointerException()); } @@ -80,10 +88,17 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid } } catch (GroupManagementDAOException e) { GroupManagementDAOFactory.rollbackTransaction(); - throw new GroupManagementException("Error occurred while adding deviceGroup " + - "'" + deviceGroup.getName() + "' to database.", e); + String msg = "Error occurred while adding deviceGroup '" + deviceGroup.getName() + "' to database."; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (TransactionManagementException e) { - throw new GroupManagementException("Error occurred while initiating transaction.", e); + String msg = "Error occurred while initiating transaction."; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in creating group '" + deviceGroup.getName() + "'"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } finally { GroupManagementDAOFactory.closeConnection(); } @@ -99,6 +114,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid @Override public void updateGroup(DeviceGroup deviceGroup, int groupId) throws GroupManagementException, GroupAlreadyExistException { + if (deviceGroup == null) { + String msg = "Received incomplete data for updateGroup"; + log.error(msg); + throw new GroupManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("update group '" + deviceGroup.getName() + "'"); + } if (deviceGroup == null) { throw new GroupManagementException("DeviceGroup cannot be null.", new NullPointerException()); } @@ -114,10 +137,17 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid } } catch (GroupManagementDAOException e) { GroupManagementDAOFactory.rollbackTransaction(); - throw new GroupManagementException("Error occurred while modifying deviceGroup " + - "'" + deviceGroup.getName() + "'.", e); + String msg = "Error occurred while modifying deviceGroup '" + deviceGroup.getName() + "'."; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (TransactionManagementException e) { - throw new GroupManagementException("Error occurred while initiating transaction.", e); + String msg = "Error occurred while initiating transaction."; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in updating group '" + deviceGroup.getName() + "'"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } finally { GroupManagementDAOFactory.closeConnection(); } @@ -128,6 +158,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid */ @Override public boolean deleteGroup(int groupId) throws GroupManagementException { + if (log.isDebugEnabled()) { + log.debug("Delete group: " + groupId); + } DeviceGroup deviceGroup = getGroup(groupId); if (deviceGroup == null) { return false; @@ -142,9 +175,17 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid return true; } catch (GroupManagementDAOException e) { GroupManagementDAOFactory.rollbackTransaction(); - throw new GroupManagementException("Error occurred while removing group data.", e); + String msg = "Error occurred while removing group data."; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (TransactionManagementException e) { - throw new GroupManagementException("Error occurred while initiating transaction.", e); + String msg = "Error occurred while initiating transaction."; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in deleting group: " + groupId; + log.error(msg, e); + throw new GroupManagementException(msg, e); } finally { GroupManagementDAOFactory.closeConnection(); } @@ -155,14 +196,25 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid */ @Override public DeviceGroup getGroup(int groupId) throws GroupManagementException { + if (log.isDebugEnabled()) { + log.debug("Get group by id: " + groupId); + } DeviceGroup deviceGroup; try { GroupManagementDAOFactory.openConnection(); deviceGroup = this.groupDAO.getGroup(groupId, CarbonContext.getThreadLocalCarbonContext().getTenantId()); } catch (GroupManagementDAOException e) { - throw new GroupManagementException("Error occurred while obtaining group '" + groupId + "'", e); + String msg = "Error occurred while obtaining group '" + groupId + "'"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (SQLException e) { - throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); + String msg = "Error occurred while opening a connection to the data source."; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getGroup for groupId: " + groupId; + log.error(msg, e); + throw new GroupManagementException(msg, e); } finally { GroupManagementDAOFactory.closeConnection(); } @@ -174,14 +226,30 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid */ @Override public DeviceGroup getGroup(String groupName) throws GroupManagementException { + if (groupName == null) { + String msg = "Received empty groupName for getGroup"; + log.error(msg); + throw new GroupManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get group by name '" + groupName + "'"); + } DeviceGroup deviceGroup; try { GroupManagementDAOFactory.openConnection(); deviceGroup = this.groupDAO.getGroup(groupName, CarbonContext.getThreadLocalCarbonContext().getTenantId()); } catch (GroupManagementDAOException e) { - throw new GroupManagementException("Error occurred while obtaining group with name: '" + groupName + "'", e); + String msg = "Error occurred while obtaining group with name: '" + groupName + "'"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (SQLException e) { - throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); + String msg = "Error occurred while opening a connection to the data source."; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getGroup with name " + groupName; + log.error(msg, e); + throw new GroupManagementException(msg, e); } finally { GroupManagementDAOFactory.closeConnection(); } @@ -190,15 +258,26 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid @Override public List getGroups() throws GroupManagementException { + if (log.isDebugEnabled()) { + log.debug("Get groups"); + } List deviceGroups = new ArrayList<>(); try { int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); GroupManagementDAOFactory.openConnection(); deviceGroups = this.groupDAO.getGroups(tenantId); } catch (GroupManagementDAOException e) { - throw new GroupManagementException("Error occurred while retrieving all groups in tenant", e); + String msg = "Error occurred while retrieving all groups in tenant"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (SQLException e) { - throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); + String msg = "Error occurred while opening a connection to the data source."; + log.error(msg); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getGroups"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } finally { GroupManagementDAOFactory.closeConnection(); } @@ -207,6 +286,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid @Override public PaginationResult getGroups(GroupPaginationRequest request) throws GroupManagementException { + if (request == null) { + String msg = "Received incomplete data for getGroup"; + log.error(msg); + throw new GroupManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get groups with pagination " + request.toString()); + } request = DeviceManagerUtil.validateGroupListPageSize(request); List deviceGroups = new ArrayList<>(); try { @@ -214,9 +301,17 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid GroupManagementDAOFactory.openConnection(); deviceGroups = this.groupDAO.getGroups(request, tenantId); } catch (GroupManagementDAOException e) { - throw new GroupManagementException("Error occurred while retrieving all groups in tenant", e); + String msg = "Error occurred while retrieving all groups in tenant"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (SQLException e) { - throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); + String msg = "Error occurred while opening a connection to the data source."; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getGroups"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } finally { GroupManagementDAOFactory.closeConnection(); } @@ -228,6 +323,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid @Override public List getGroups(String username) throws GroupManagementException { + if (username == null || username.isEmpty()) { + String msg = "Received null user name for getGroups"; + log.error(msg); + throw new GroupManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get groups of owner '" + username + "'"); + } Map groups = new HashMap<>(); UserStoreManager userStoreManager; try { @@ -245,11 +348,20 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid groups.put(deviceGroup.getGroupId(), deviceGroup); } } catch (UserStoreException e) { - throw new GroupManagementException("Error occurred while getting user store manager.", e); + String msg = "Error occurred while getting user store manager."; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (SQLException e) { - throw new GroupManagementException("Error occurred while retrieving all groups accessible to user.", e); + String msg = "Error occurred while retrieving all groups accessible to user."; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (GroupManagementDAOException e) { + log.error(e); throw new GroupManagementException(e); + } catch (Exception e) { + String msg = "Error occurred in getGroups for " + username; + log.error(msg, e); + throw new GroupManagementException(msg, e); } finally { GroupManagementDAOFactory.closeConnection(); } @@ -257,6 +369,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid } private List getGroupIds(String username) throws GroupManagementException { + if (username == null || username.isEmpty()) { + String msg = "Received empty user name for getGroupIds"; + log.error(msg); + throw new GroupManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get groups Ids of owner '" + username + "'"); + } UserStoreManager userStoreManager; List deviceGroupIds = new ArrayList<>(); try { @@ -268,11 +388,20 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid deviceGroupIds = this.groupDAO.getOwnGroupIds(username, tenantId); deviceGroupIds.addAll(this.groupDAO.getGroupIds(roleList, tenantId)); } catch (UserStoreException e) { - throw new GroupManagementException("Error occurred while getting user store manager.", e); + String msg = "Error occurred while getting user store manager."; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (SQLException e) { - throw new GroupManagementException("Error occurred while retrieving all groups accessible to user.", e); + String msg = "Error occurred while retrieving all groups accessible to user."; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (GroupManagementDAOException e) { + log.error(e); throw new GroupManagementException(e); + } catch (Exception e) { + String msg = "Error occurred in getGroups for username '" + username + "'"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } finally { GroupManagementDAOFactory.closeConnection(); } @@ -282,6 +411,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid @Override public PaginationResult getGroups(String currentUser, GroupPaginationRequest request) throws GroupManagementException { + if (currentUser == null || request == null) { + String msg = "Received incomplete date for getGroups"; + log.error(msg); + throw new GroupManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get all groups of user '" + currentUser + "' pagination request " + request.toString()); + } request = DeviceManagerUtil.validateGroupListPageSize(request); List allDeviceGroupIdsOfUser = getGroupIds(currentUser); List allMatchingGroups = new ArrayList<>(); @@ -290,9 +427,17 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid GroupManagementDAOFactory.openConnection(); allMatchingGroups = this.groupDAO.getGroups(request, allDeviceGroupIdsOfUser, tenantId); } catch (GroupManagementDAOException e) { - throw new GroupManagementException("Error occurred while retrieving all groups in tenant", e); + String msg = "Error occurred while retrieving all groups in tenant"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (SQLException e) { - throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); + String msg = "Error occurred while opening a connection to the data source."; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getGroups"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } finally { GroupManagementDAOFactory.closeConnection(); } @@ -304,28 +449,55 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid @Override public int getGroupCount() throws GroupManagementException { + if (log.isDebugEnabled()) { + log.debug("Get groups count"); + } try { int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); GroupManagementDAOFactory.openConnection(); return groupDAO.getGroupCount(tenantId); } catch (GroupManagementDAOException e) { - throw new GroupManagementException("Error occurred while retrieving all groups in tenant", e); + String msg = "Error occurred while retrieving all groups in tenant"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (SQLException e) { - throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); + String msg = "Error occurred while opening a connection to the data source."; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } finally { GroupManagementDAOFactory.closeConnection(); } } private int getGroupCount(GroupPaginationRequest request) throws GroupManagementException { + if (request == null) { + String msg = "Received empty request for getGroupCount"; + log.error(msg); + throw new GroupManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get groups count, pagination request " + request.toString()); + } try { int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); GroupManagementDAOFactory.openConnection(); return groupDAO.getGroupCount(request, tenantId); } catch (GroupManagementDAOException e) { - throw new GroupManagementException("Error occurred while retrieving all groups in tenant", e); + String msg = "Error occurred while retrieving all groups in tenant"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (SQLException e) { - throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); + String msg = "Error occurred while opening a connection to the data source."; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getGroupCount"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } finally { GroupManagementDAOFactory.closeConnection(); } @@ -336,6 +508,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid */ @Override public int getGroupCount(String username) throws GroupManagementException { + if (username == null || username.isEmpty()) { + String msg = "Received empty user name for getGroupCount"; + log.error(msg); + throw new GroupManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get groups count of '" + username + "'"); + } UserStoreManager userStoreManager; int count; try { @@ -348,11 +528,21 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid count += groupDAO.getGroupsCount(roleList, tenantId); return count; } catch (UserStoreException e) { - throw new GroupManagementException("Error occurred while getting user store manager.", e); + String msg = "Error occurred while getting user store manager."; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (GroupManagementDAOException e) { - throw new GroupManagementException("Error occurred while retrieving group count of user '" + username + "'", e); + String msg = "Error occurred while retrieving group count of user '" + username + "'"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (SQLException e) { - throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); + String msg = "Error occurred while opening a connection to the data source."; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getGroupCount for username '" + username + "'"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } finally { GroupManagementDAOFactory.closeConnection(); } @@ -364,41 +554,52 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid @Override public void manageGroupSharing(int groupId, List newRoles) throws GroupManagementException, RoleDoesNotExistException { - int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); - UserStoreManager userStoreManager; - try { - userStoreManager = - DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm( - tenantId).getUserStoreManager(); - List currentUserRoles = getRoles(groupId); - GroupManagementDAOFactory.beginTransaction(); - if (newRoles != null) { - for (String role : newRoles) { - if (!userStoreManager.isExistingRole(role)) { - throw new RoleDoesNotExistException("Role '" + role + "' does not exists in the user store."); - } - // Removing role from current user roles of the group will return true if role exist. - // So we don't need to add it to the db again. - if (!currentUserRoles.remove(role)) { - // If group doesn't have the role, it is adding to the db. - groupDAO.addRole(groupId, role, tenantId); - } + if (log.isDebugEnabled()) { + log.debug("Manage group sharing for group: " + groupId); + } + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + UserStoreManager userStoreManager; + try { + userStoreManager = + DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm( + tenantId).getUserStoreManager(); + List currentUserRoles = getRoles(groupId); + GroupManagementDAOFactory.beginTransaction(); + if (newRoles != null) { + for (String role : newRoles) { + if (!userStoreManager.isExistingRole(role)) { + throw new RoleDoesNotExistException("Role '" + role + "' does not exists in the user store."); + } + // Removing role from current user roles of the group will return true if role exist. + // So we don't need to add it to the db again. + if (!currentUserRoles.remove(role)) { + // If group doesn't have the role, it is adding to the db. + groupDAO.addRole(groupId, role, tenantId); } } - for (String role : currentUserRoles) { - // Removing old roles from db which are not available in the new roles list. - groupDAO.removeRole(groupId, role, tenantId); - } - GroupManagementDAOFactory.commitTransaction(); - } catch (GroupManagementDAOException e) { - GroupManagementDAOFactory.rollbackTransaction(); - throw new GroupManagementException(e); - } catch (UserStoreException e) { - throw new GroupManagementException("User store error in updating sharing roles.", e); - } catch (TransactionManagementException e) { - throw new GroupManagementException(e); - } finally { - GroupManagementDAOFactory.closeConnection(); + } + for (String role : currentUserRoles) { + // Removing old roles from db which are not available in the new roles list. + groupDAO.removeRole(groupId, role, tenantId); + } + GroupManagementDAOFactory.commitTransaction(); + } catch (GroupManagementDAOException e) { + GroupManagementDAOFactory.rollbackTransaction(); + log.error(e); + throw new GroupManagementException(e); + } catch (UserStoreException e) { + String msg = "User store error in updating sharing roles."; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (TransactionManagementException e) { + log.error(e); + throw new GroupManagementException(e); + } catch (Exception e) { + String msg = "Error occurred in manageGroupSharing for groupId: " + groupId; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } finally { + GroupManagementDAOFactory.closeConnection(); } } @@ -407,14 +608,25 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid */ @Override public List getRoles(int groupId) throws GroupManagementException { + if (log.isDebugEnabled()) { + log.debug("Group roles for group: " + groupId); + } try { int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); GroupManagementDAOFactory.openConnection(); return groupDAO.getRoles(groupId, tenantId); } catch (GroupManagementDAOException e) { - throw new GroupManagementException("Error occurred while retrieving all groups in tenant", e); + String msg = "Error occurred while retrieving all groups in tenant"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (SQLException e) { - throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); + String msg = "Error occurred while opening a connection to the data source."; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getRoles for groupId: " + groupId; + log.error(msg, e); + throw new GroupManagementException(msg, e); } finally { GroupManagementDAOFactory.closeConnection(); } @@ -426,6 +638,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid @Override public List getDevices(int groupId, int startIndex, int rowCount) throws GroupManagementException { + if (log.isDebugEnabled()) { + log.debug("Group devices of group: " + groupId + " start index " + startIndex + " row count " + rowCount); + } int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); List devices; try { @@ -433,11 +648,21 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid GroupManagementDAOFactory.openConnection(); devices = this.groupDAO.getDevices(groupId, startIndex, rowCount, tenantId); } catch (GroupManagementDAOException e) { - throw new GroupManagementException("Error occurred while getting devices in group.", e); + String msg = "Error occurred while getting devices in group."; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (SQLException e) { - throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); + String msg = "Error occurred while opening a connection to the data source."; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (DeviceManagementException e) { - throw new GroupManagementException("Error occurred while validating the limit of the devices to be returned", e); + String msg = "Error occurred while validating the limit of the devices to be returned"; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getDevices for groupId: " + groupId; + log.error(msg, e); + throw new GroupManagementException(msg, e); } finally { GroupManagementDAOFactory.closeConnection(); } @@ -449,13 +674,24 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid */ @Override public int getDeviceCount(int groupId) throws GroupManagementException { + if (log.isDebugEnabled()) { + log.debug("Group devices count of group: " + groupId); + } try { GroupManagementDAOFactory.openConnection(); return groupDAO.getDeviceCount(groupId, CarbonContext.getThreadLocalCarbonContext().getTenantId()); } catch (GroupManagementDAOException e) { - throw new GroupManagementException("Error occurred while retrieving all groups in tenant", e); + String msg = "Error occurred while retrieving all groups in tenant"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (SQLException e) { - throw new GroupManagementException("Error occurred while opening a connection to the data source.", e); + String msg = "Error occurred while opening a connection to the data source."; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getDeviceCount for groupId: " + groupId; + log.error(msg, e); + throw new GroupManagementException(msg, e); } finally { GroupManagementDAOFactory.closeConnection(); } @@ -467,6 +703,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid @Override public void addDevices(int groupId, List deviceIdentifiers) throws GroupManagementException, DeviceNotFoundException { + if (log.isDebugEnabled()) { + log.debug("Group devices to the group: " + groupId); + } Device device; try { int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); @@ -483,12 +722,22 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid } GroupManagementDAOFactory.commitTransaction(); } catch (DeviceManagementException e) { - throw new GroupManagementException("Error occurred while retrieving device.", e); + String msg = "Error occurred while retrieving device."; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (GroupManagementDAOException e) { GroupManagementDAOFactory.rollbackTransaction(); - throw new GroupManagementException("Error occurred while adding device to group.", e); + String msg = "Error occurred while adding device to group."; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (TransactionManagementException e) { - throw new GroupManagementException("Error occurred while initiating transaction.", e); + String msg = "Error occurred while initiating transaction."; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in addDevices for groupId " + groupId; + log.error(msg, e); + throw new GroupManagementException(msg, e); } finally { GroupManagementDAOFactory.closeConnection(); } @@ -500,6 +749,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid @Override public void removeDevice(int groupId, List deviceIdentifiers) throws GroupManagementException, DeviceNotFoundException { + if (log.isDebugEnabled()) { + log.debug("Remove devices from the group: " + groupId); + } Device device; try { int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); @@ -514,12 +766,22 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid } GroupManagementDAOFactory.commitTransaction(); } catch (DeviceManagementException e) { - throw new GroupManagementException("Error occurred while retrieving device.", e); + String msg = "Error occurred while retrieving device."; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (TransactionManagementException e) { - throw new GroupManagementException("Error occurred while initiating transaction.", e); + String msg = "Error occurred while initiating transaction."; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (GroupManagementDAOException e) { GroupManagementDAOFactory.rollbackTransaction(); - throw new GroupManagementException("Error occurred while adding device to group.", e); + String msg = "Error occurred while adding device to group."; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in removeDevice for groupId: " + groupId; + log.error(msg, e); + throw new GroupManagementException(msg, e); } finally { GroupManagementDAOFactory.closeConnection(); } @@ -530,6 +792,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid */ @Override public List getGroups(String username, String permission) throws GroupManagementException { + if (log.isDebugEnabled()) { + log.debug("Get groups of user '" + username + "'"); + } List deviceGroups = getGroups(username); Map permittedDeviceGroups = new HashMap<>(); UserRealm userRealm; @@ -546,13 +811,27 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid } } } catch (UserStoreException e) { - throw new GroupManagementException("Error occurred while getting user realm.", e); + String msg = "Error occurred while getting user realm."; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getGroups for username '" + username + "'"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } return new ArrayList<>(permittedDeviceGroups.values()); } @Override public List getGroups(DeviceIdentifier deviceIdentifier) throws GroupManagementException { + if (deviceIdentifier == null) { + String msg = "Received empty device identifier for getGroups"; + log.error(msg); + throw new GroupManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Get groups of device " + deviceIdentifier.getId()); + } DeviceManagementProviderService managementProviderService = new DeviceManagementProviderServiceImpl(); try { Device device = managementProviderService.getDevice(deviceIdentifier, false); @@ -560,11 +839,21 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid return groupDAO.getGroups(device.getId(), PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); } catch (DeviceManagementException e) { - throw new GroupManagementException("Error occurred while retrieving the device details.", e); + String msg = "Error occurred while retrieving the device details."; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (GroupManagementDAOException e) { - throw new GroupManagementException("Error occurred while retrieving device groups.", e); + String msg = "Error occurred while retrieving device groups."; + log.error(msg, e); + throw new GroupManagementException(msg, e); } catch (SQLException e) { - throw new GroupManagementException("Error occurred while opening database connection.", e); + String msg = "Error occurred while opening database connection."; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in getGroups"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } finally { GroupManagementDAOFactory.closeConnection(); } @@ -575,7 +864,9 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid */ @Override public DeviceGroup createDefaultGroup(String groupName) throws GroupManagementException { - + if (log.isDebugEnabled()) { + log.debug("Create default group " + groupName); + } DeviceGroup defaultGroup = this.getGroup(groupName); if (defaultGroup == null) { defaultGroup = new DeviceGroup(groupName); @@ -586,10 +877,13 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid this.createGroup(defaultGroup, DeviceGroupConstants.Roles.DEFAULT_ADMIN_ROLE, DeviceGroupConstants.Permissions.DEFAULT_ADMIN_PERMISSIONS); } catch (GroupAlreadyExistException e) { - if (log.isDebugEnabled()) { - log.debug("Default group: " + defaultGroup.getName() + " already exists. Skipping group creation.", - e); - } + String msg = "Default group: " + defaultGroup.getName() + " already exists. Skipping group creation."; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in createDefaultGroup for groupName '" + groupName + "'"; + log.error(msg, e); + throw new GroupManagementException(msg, e); } return this.getGroup(groupName); } else { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml index af03f4fad9..9629cbd85a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml index 80c10f51cc..25ce73bbfc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 3.0.87-SNAPSHOT + 3.0.90-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js index 452c09f012..bafbd11a41 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js @@ -158,7 +158,7 @@ function resetPassword(username) { domain = username.substr(0, username.indexOf('/')); username = username.substr(username.indexOf('/') + 1); } - var resetPasswordServiceURL = apiBasePath + "/admin/users/" + username + "/credentials"; + var resetPasswordServiceURL = apiBasePath + "/admin/users/" + encodeURIComponent(username) + "/credentials"; if (domain) { resetPasswordServiceURL += '?domain=' + encodeURIComponent(domain); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.default.user-menu/public/js/user-menu.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.default.user-menu/public/js/user-menu.js index ecd93a8bc6..7ef1c320bc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.default.user-menu/public/js/user-menu.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.default.user-menu/public/js/user-menu.js @@ -86,7 +86,9 @@ $(document).ready(function () { $("#change-password-success-link").click(function () { hidePopup(); }); - window.location.href = "/devicemgt/logout"; + setTimeout(function(){ + window.location.href = "/devicemgt/logout"; + },10000); } }, function (jqXHR) { if (jqXHR.status == 400) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.default.user-menu/user-menu.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.default.user-menu/user-menu.hbs index ee2ccdc968..7e0fac5d3e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.default.user-menu/user-menu.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.default.user-menu/user-menu.hbs @@ -104,7 +104,7 @@