diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml index 5ddd2eacf84..b0bb0b1788c 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml index b8f04c797d3..b48dfaad138 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml index 020ebeec6b5..dc7de957147 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/impl/GrafanaQueryServiceImpl.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/impl/GrafanaQueryServiceImpl.java index b15ebed76ab..7af9acf5596 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/impl/GrafanaQueryServiceImpl.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/service/impl/GrafanaQueryServiceImpl.java @@ -68,8 +68,23 @@ public class GrafanaQueryServiceImpl implements GrafanaQueryService { int datasourceId = datasourceIdJson.getAsInt(); CacheManager cacheManager = CacheManager.getInstance(); String encodedQuery = cacheManager.getEncodedQueryCache().getIfPresent(rawSql); - if (cacheManager.getEncodedQueryCache().getIfPresent(rawSql) != null) { - queryObj.addProperty(GrafanaConstants.RAW_SQL_KEY, encodedQuery); + if (encodedQuery != null && !encodedQuery.isEmpty()) { + // Checks if the tenant ID in the cached query (encodedQuery) is matching the current tenant ID + // taken from Carbon Context and if it's not matching then the query is modified with the current + // tenant ID and then added to the cache + if (encodedQuery.contains(GrafanaConstants.ENCODED_QUERY_TENANT_ID_KEY)) { + String encodedQueryTenantId = GrafanaPreparedQueryBuilder.getEncodedQueryTenantId(encodedQuery); + boolean isMatchingTenantId = GrafanaPreparedQueryBuilder.isMatchingTenantId(encodedQueryTenantId); + if (isMatchingTenantId) { + queryObj.addProperty(GrafanaConstants.RAW_SQL_KEY, encodedQuery); + } else { + String modifiedEncodedQuery = GrafanaPreparedQueryBuilder.modifyEncodedQuery(encodedQuery); + CacheManager.getInstance().getEncodedQueryCache().put(rawSql, modifiedEncodedQuery); + queryObj.addProperty(GrafanaConstants.RAW_SQL_KEY, modifiedEncodedQuery); + } + } else { + queryObj.addProperty(GrafanaConstants.RAW_SQL_KEY, encodedQuery); + } return; } Datasource datasource = cacheManager.getDatasourceAPICache().getIfPresent(datasourceId); diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/GrafanaPreparedQueryBuilder.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/GrafanaPreparedQueryBuilder.java index 8b8606dacb8..da14278cafc 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/GrafanaPreparedQueryBuilder.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/sql/query/GrafanaPreparedQueryBuilder.java @@ -38,6 +38,7 @@ public class GrafanaPreparedQueryBuilder { private static final String VAR_PARAM_TEMPLATE = "$param"; private static final String GRAFANA_QUOTED_VAR_REGEX = "('\\$(\\d|\\w|_)+')|('\\$\\{.*?\\}')|(\"\\$(\\d|\\w|_)+\")|(\"\\$\\{.*?\\}\")"; private static final String GRAFANA_VAR_REGEX = "(\\$(\\d|\\w|_)+)|(\\$\\{.*?\\})"; + private static final String ENCODED_QUERY_TENANT_ID_REGEX = "TENANT_ID\\s=\\s('[^']+'|-?[1-9]\\d*|0)"; public static PreparedQuery build(String queryTemplate, String rawQuery) throws QueryMisMatch { @@ -125,6 +126,60 @@ public class GrafanaPreparedQueryBuilder { return new PreparedQuery(preparedQueryBuilder.toString(), parameters); } + /** + * Get the tenant ID used in the cached query with the matching regex pattern which are integers that + * may or may not have surrounding single quotes and could have a minus sign (e.g., '-1234') + * @param encodedQuery the cached query + * @return returns the tenant ID extracted from the cached query + */ + public static String getEncodedQueryTenantId(String encodedQuery) { + Pattern pattern = Pattern.compile(ENCODED_QUERY_TENANT_ID_REGEX); + Matcher matcher = pattern.matcher(encodedQuery); + String encodedQueryTenantId = ""; + while (matcher.find()) { + encodedQueryTenantId = matcher.group(1); + if (encodedQueryTenantId != null && !encodedQueryTenantId.isEmpty()) { + break; + } + } + return unQuoteString(encodedQueryTenantId); + } + + /** + * Checks if passed tenant ID is matching with tenant ID from Carbon Context + * @param encodedQueryTenantId the tenant ID + * @return true if tenant IDs match otherwise false + */ + public static boolean isMatchingTenantId(String encodedQueryTenantId) { + if (encodedQueryTenantId != null && !encodedQueryTenantId.isEmpty()) { + return GrafanaUtil.getTenantId() == Integer.parseInt(encodedQueryTenantId); + } + return false; + } + + /** + * Modify the tenant ID used in the cached query to the current tenant ID taken from Carbon Context + * with the matching regex pattern which are integers that may or may not have surrounding single quotes and + * could have a minus sign (e.g., '-1234') + * @param encodedQuery the cached query + * @return returns the modified query with the current tenant ID + */ + public static String modifyEncodedQuery(String encodedQuery) { + Pattern pattern = Pattern.compile(ENCODED_QUERY_TENANT_ID_REGEX); + Matcher matcher = pattern.matcher(encodedQuery); + StringBuffer stringBuffer = new StringBuffer(encodedQuery.length()); + String encodedQueryTenantId = ""; + while (matcher.find()) { + encodedQueryTenantId = matcher.group(1); + if (encodedQueryTenantId != null && !encodedQueryTenantId.isEmpty()) { + matcher.appendReplacement(stringBuffer, Matcher.quoteReplacement( + GrafanaConstants.ENCODED_QUERY_TENANT_ID_KEY + " " + GrafanaUtil.getTenantId())); + } + } + matcher.appendTail(stringBuffer); + return stringBuffer.toString(); + } + private static String[] splitByComma(String str) { // Using regex to avoid splitting by comma inside quotes return str.split("(\\s|\\t)*,(\\s|\\t)*(?=(?:[^'\"]*['|\"][^'\"]*['|\"])*[^'\"]*$)"); @@ -194,5 +249,4 @@ public class GrafanaPreparedQueryBuilder { private static String singleQuoteString(String str) { return "'" + str + "'"; } - } diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/util/GrafanaConstants.java b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/util/GrafanaConstants.java index b8a33f8b329..0abed858b79 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/util/GrafanaConstants.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/analytics/mgt/grafana/proxy/core/util/GrafanaConstants.java @@ -39,6 +39,7 @@ public class GrafanaConstants { public static final int IFRAME_URL_DASHBOARD_UID_INDEX = 1; public static final String TENANT_ID_VAR_NAME = "tenantId"; + public static final String ENCODED_QUERY_TENANT_ID_KEY = "TENANT_ID ="; public static final String VAR_PREFIX = "$"; public static final String TENANT_ID_VAR = VAR_PREFIX + TENANT_ID_VAR_NAME; public static final String QUERY_PARAM_VAR_PREFIX = "var-"; diff --git a/components/analytics-mgt/grafana-mgt/pom.xml b/components/analytics-mgt/grafana-mgt/pom.xml index 17251bd9496..dec81b3aa51 100644 --- a/components/analytics-mgt/grafana-mgt/pom.xml +++ b/components/analytics-mgt/grafana-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt analytics-mgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/analytics-mgt/pom.xml b/components/analytics-mgt/pom.xml index 9e3978e7176..7722cd48682 100644 --- a/components/analytics-mgt/pom.xml +++ b/components/analytics-mgt/pom.xml @@ -3,7 +3,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/pom.xml index 6f1da82ae9a..c4dbc2d8342 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/pom.xml +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/pom.xml @@ -20,7 +20,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT 4.0.0 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 dec91246ab7..147df32e6a3 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml @@ -22,7 +22,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml 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 e72bcc5d3b4..eae69d7327b 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,7 +21,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml 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 a7bcd9a3d09..9634e1ffe00 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,7 +22,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java index 41ee18da8a9..399ac015199 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java @@ -104,7 +104,7 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); if (StringUtils.isEmpty(username)) { - username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername() + "@" + tenantDomain; } try { APIConsumer apiConsumer = API_MANAGER_FACTORY.getAPIConsumer(username); diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml index 6af6ec43bfa..2716ef61dee 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml @@ -3,7 +3,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT 4.0.0 diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/pom.xml index c122a2f8028..c5db4f8668b 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/pom.xml @@ -3,7 +3,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml 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 1db744409df..3289983dd2e 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,7 +22,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/apimgt-extensions/pom.xml b/components/apimgt-extensions/pom.xml index 93638f60da4..5d84e68023e 100644 --- a/components/apimgt-extensions/pom.xml +++ b/components/apimgt-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.addons/pom.xml b/components/application-mgt/io.entgra.application.mgt.addons/pom.xml index 5b018fa6912..95d6aaeeffc 100644 --- a/components/application-mgt/io.entgra.application.mgt.addons/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.addons/pom.xml @@ -20,7 +20,7 @@ application-mgt org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.api/pom.xml b/components/application-mgt/io.entgra.application.mgt.api/pom.xml index 34e852922e5..0b4be779e1d 100644 --- a/components/application-mgt/io.entgra.application.mgt.api/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.api/pom.xml @@ -22,7 +22,7 @@ application-mgt org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.common/pom.xml b/components/application-mgt/io.entgra.application.mgt.common/pom.xml index ec5c4ecbc85..35e4696bda4 100644 --- a/components/application-mgt/io.entgra.application.mgt.common/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.common/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt application-mgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.core/pom.xml b/components/application-mgt/io.entgra.application.mgt.core/pom.xml index 79bfb74e1e0..43ea757d71d 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.core/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt application-mgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java index 4ea91300ce0..98a50e427a1 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java @@ -402,7 +402,7 @@ public class ApplicationManagerImpl implements ApplicationManager { */ private void validateRemoveAppFromFavouritesRequest(int appId) throws ApplicationManagementException { if (!isFavouriteApp(appId)) { - String msg = "Provided appId " + appId + " is not a favourite app in order remove from favourites"; + String msg = "Provided application is not a favourite app in order remove from favourites"; throw new BadRequestException(msg); } } @@ -417,11 +417,11 @@ public class ApplicationManagerImpl implements ApplicationManager { try { getApplication(appId); } catch (NotFoundException e) { - String msg = " No application exists for the provided appId " + appId; + String msg = "Requested application does not exists for add to favourites."; throw new BadRequestException(msg); } if (isFavouriteApp(appId)) { - String msg = "Provided appId " + appId + " is already a favourite app"; + String msg = "Requested application is already in favourites list."; throw new BadRequestException(msg); } } @@ -1505,7 +1505,7 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg, e); throw new ApplicationManagementException(msg, e); } catch (ApplicationManagementDAOException e) { - String msg = "Error occured when getting, either application tags or application categories"; + String msg = "Error occurred when getting, either application tags or application categories"; log.error(msg, e); throw new ApplicationManagementException(msg, e); } finally { @@ -1779,7 +1779,7 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ApplicationManagementException(msg, e); } catch (LifeCycleManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occured while deleting life-cycle state data of application releases of the application" + String msg = "Error occurred while deleting life-cycle state data of application releases of the application" + " which has application ID: " + applicationDTO.getId(); log.error(msg, e); throw new ApplicationManagementException(msg, e); @@ -1896,7 +1896,7 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ApplicationManagementException(msg, e); } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occurred while verifying whether application relase has an subscription or " + String msg = "Error occurred while verifying whether application release has an subscription or " + "not. Application release UUID: " + releaseUuid; log.error(msg, e); throw new ApplicationManagementException(msg, e); @@ -1945,7 +1945,7 @@ public class ApplicationManagerImpl implements ApplicationManager { ConnectionManagerUtil.commitDBTransaction(); } catch (DBConnectionException e) { String msg = - "Error occured when getting DB connection to update image artifacts of the application release " + "Error occurred when getting DB connection to update image artifacts of the application release " + "which has uuid " + uuid; log.error(msg, e); throw new ApplicationManagementException(msg, e); @@ -1957,13 +1957,13 @@ public class ApplicationManagerImpl implements ApplicationManager { } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); String msg = - "Error occured while getting application release data for updating image artifacts of the application release uuid " + "Error occurred while getting application release data for updating image artifacts of the application release uuid " + uuid + "."; log.error(msg, e); throw new ApplicationManagementException(msg, e); } catch (ResourceManagementException e) { ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occured while updating image artifacts of the application release uuid " + uuid + "."; + String msg = "Error occurred while updating image artifacts of the application release uuid " + uuid + "."; log.error(msg, e); throw new ApplicationManagementException(msg , e); } finally { @@ -1992,7 +1992,7 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new BadRequestException(msg); } } catch (DeviceManagementException e) { - String msg = "Error occured while getting supported device types in IoTS"; + String msg = "Error occurred while getting supported device types in IoTS"; log.error(msg, e); throw new ApplicationManagementException(msg, e); } @@ -2034,16 +2034,16 @@ public class ApplicationManagerImpl implements ApplicationManager { ConnectionManagerUtil.commitDBTransaction(); } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occured while getting/updating APPM DB for updating application Installer."; + String msg = "Error occurred while getting/updating APPM DB for updating application Installer."; log.error(msg, e); throw new ApplicationManagementException(msg, e); } catch (TransactionManagementException e) { - String msg = "Error occured while starting the transaction to update application release artifact which has " + String msg = "Error occurred while starting the transaction to update application release artifact which has " + "application uuid " + releaseUuid + "."; log.error(msg, e); throw new ApplicationManagementException(msg, e); } catch (DBConnectionException e) { - String msg = "Error occured when getting DB connection to update application release artifact of the " + String msg = "Error occurred when getting DB connection to update application release artifact of the " + "application release uuid " + releaseUuid + "."; log.error(msg, e); throw new ApplicationManagementException(msg, e); @@ -2054,7 +2054,7 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ApplicationManagementException(msg, e); } catch (ResourceManagementException e) { ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occured when updating application installer."; + String msg = "Error occurred when updating application installer."; log.error(msg, e); throw new ApplicationManagementException(msg, e); } finally { @@ -2252,7 +2252,7 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ApplicationManagementException(msg, e); } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occured when getting existing categories or when inserting new application categories."; + String msg = "Error occurred when getting existing categories or when inserting new application categories."; log.error(msg, e); throw new ApplicationManagementException(msg, e); } finally { @@ -2574,7 +2574,7 @@ public class ApplicationManagerImpl implements ApplicationManager { applicationDAO.deleteApplicationTag(tag.getId(), applicationDTO.getId(), tenantId); ConnectionManagerUtil.commitDBTransaction(); } else { - String msg = "Tag " + tagName + " is not an application tag. Application ID: " + appId; + String msg = "Tag " + tagName + " is not an application tag. Application name: " + applicationDTO.getName(); log.error(msg); throw new BadRequestException(msg); } @@ -2782,7 +2782,7 @@ public class ApplicationManagerImpl implements ApplicationManager { .collect(Collectors.toList()); } else { String msg = "Tag list is either null or empty. In order to add new tags for application which has " - + "application ID: " + appId +", tag list should be a list of Stings. Therefore please " + + "application name: " + applicationDTO.getName() +", tag list should be a list of Stings. Therefore please " + "verify the payload."; log.error(msg); throw new BadRequestException(msg); @@ -2888,11 +2888,17 @@ public class ApplicationManagerImpl implements ApplicationManager { @Override public void updateCategory(String oldCategoryName, String newCategoryName) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + if (StringUtils.isEmpty(oldCategoryName) || StringUtils.isEmpty(newCategoryName)) { + String msg = "Either old category name or new category name contains empty/null value. Hence please verify the " + + "request."; + log.error(msg); + throw new BadRequestException(msg); + } try { ConnectionManagerUtil.beginDBTransaction(); CategoryDTO category = applicationDAO.getCategoryForCategoryName(oldCategoryName, tenantId); if (category == null){ - String msg = "Couldn't found a category for tag name " + oldCategoryName + "."; + String msg = "Couldn't found a category for category name " + oldCategoryName + "."; log.error(msg); throw new NotFoundException(msg); } @@ -2904,7 +2910,7 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg, e); throw new ApplicationManagementException(msg, e); } catch (TransactionManagementException e) { - String msg = "Database access error is occurred when updating categiry."; + String msg = "Database access error is occurred when updating category."; log.error(msg, e); throw new ApplicationManagementException(msg, e); } catch (ApplicationManagementDAOException e) { @@ -3079,11 +3085,11 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ApplicationManagementException(msg, e); } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occured when updating Ent Application release of UUID: " + releaseUuid; + String msg = "Error occurred when updating Ent Application release of UUID: " + releaseUuid; log.error(msg, e); throw new ApplicationManagementException(msg, e); } catch (ResourceManagementException e) { - String msg = "Error occured when updating application release artifact in the file system. Ent App release " + String msg = "Error occurred when updating application release artifact in the file system. Ent App release " + "UUID:" + releaseUuid; log.error(msg, e); throw new ApplicationManagementException(msg, e); @@ -3148,11 +3154,11 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ApplicationManagementException(msg, e); } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occured when updating public app release of UUID: " + releaseUuid; + String msg = "Error occurred when updating public app release of UUID: " + releaseUuid; log.error(msg, e); throw new ApplicationManagementException(msg, e); } catch (ResourceManagementException e) { - String msg = "Error occured when updating public app release artifact in the file system. Public app " + String msg = "Error occurred when updating public app release artifact in the file system. Public app " + "release UUID:" + releaseUuid; log.error(msg, e); throw new ApplicationManagementException(msg, e); @@ -3213,11 +3219,11 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ApplicationManagementException(msg, e); } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occured when updating web app release for web app Release UUID: " + releaseUuid; + String msg = "Error occurred when updating web app release for web app Release UUID: " + releaseUuid; log.error(msg, e); throw new ApplicationManagementException(msg, e); } catch (ResourceManagementException e) { - String msg = "Error occured when updating web app release artifact in the file system. Web app " + String msg = "Error occurred when updating web app release artifact in the file system. Web app " + "release UUID:" + releaseUuid; log.error(msg, e); throw new ApplicationManagementException(msg, e); @@ -3343,11 +3349,11 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ApplicationManagementException(msg, e); } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occured when updating Ent Application release of UUID: " + releaseUuid; + String msg = "Error occurred when updating Ent Application release of UUID: " + releaseUuid; log.error(msg, e); throw new ApplicationManagementException(msg, e); } catch (ResourceManagementException e) { - String msg = "Error occured when updating application release artifact in the file system. Ent App release " + String msg = "Error occurred when updating application release artifact in the file system. Ent App release " + "UUID:" + releaseUuid; log.error(msg, e); throw new ApplicationManagementException(msg, e); @@ -3721,7 +3727,7 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new BadRequestException(msg); } if (StringUtils.isEmpty(webAppReleaseWrapper.getUrl())) { - String msg = "URL should't be null for the application release creating request for application type " + String msg = "URL shouldn't be null for the application release creating request for application type " + "WEB_CLIP"; log.error(msg); throw new BadRequestException(msg); @@ -3901,11 +3907,11 @@ public class ApplicationManagerImpl implements ApplicationManager { } ConnectionManagerUtil.commitDBTransaction(); } catch (ApplicationManagementDAOException e) { - String msg = "Error occured while updating app subscription status of the device."; + String msg = "Error occurred while updating app subscription status of the device."; log.error(msg, e); throw new ApplicationManagementException(msg, e); } catch (DBConnectionException e) { - String msg = "Error occurred while obersving the database connection to update aoo subscription status of " + String msg = "Error occurred while observing the database connection to update aoo subscription status of " + "device."; log.error(msg, e); throw new ApplicationManagementException(msg, e); @@ -3932,11 +3938,11 @@ public class ApplicationManagerImpl implements ApplicationManager { } ConnectionManagerUtil.commitDBTransaction(); } catch (ApplicationManagementDAOException e) { - String msg = "Error occured while updating app subscription status of the device."; + String msg = "Error occurred while updating app subscription status of the device."; log.error(msg, e); throw new ApplicationManagementException(msg, e); } catch (DBConnectionException e) { - String msg = "Error occurred while obersving the database connection to update aoo subscription status of " + String msg = "Error occurred while observing the database connection to update aoo subscription status of " + "device."; log.error(msg, e); throw new ApplicationManagementException(msg, e); diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ReviewManagerImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ReviewManagerImpl.java index 323149d8941..facbfa4163a 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ReviewManagerImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ReviewManagerImpl.java @@ -224,7 +224,7 @@ public class ReviewManagerImpl implements ReviewManager { throw new ReviewManagementException(msg, e); } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occured while verifying whether application release is exists or not for UUID " + uuid; + String msg = "Error occurred while verifying whether application release is exists or not for UUID " + uuid; log.error(msg, e); throw new ReviewManagementException(msg, e); } finally { @@ -360,7 +360,7 @@ public class ReviewManagerImpl implements ReviewManager { return null; } catch (ReviewManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occured while getting reviewTmp with reviewTmp id " + reviewId + "."; + String msg = "Error occurred while getting reviewTmp with reviewTmp id " + reviewId + "."; log.error(msg, e); throw new ReviewManagementException(msg, e); } catch (DBConnectionException e) { @@ -393,11 +393,11 @@ public class ReviewManagerImpl implements ReviewManager { } return getReviewTree(this.reviewDAO.getAllReleaseReviews(releaseDTO.getId(), request, tenantId)); } catch (ReviewManagementDAOException e) { - String msg = "Error occured while getting all reviews for application uuid: " + uuid; + String msg = "Error occurred while getting all reviews for application uuid: " + uuid; log.error(msg, e); throw new ReviewManagementException(msg, e); } catch (DBConnectionException e) { - String msg ="Error occured while getting the DB connection to get all reviews for application release which" + String msg ="Error occurred while getting the DB connection to get all reviews for application release which" + " has UUID " + uuid; log.error(msg, e); throw new ReviewManagementException(msg, e); @@ -423,12 +423,12 @@ public class ReviewManagerImpl implements ReviewManager { ConnectionManagerUtil.openDBConnection(); return getReviewTree(this.reviewDAO.getAllActiveAppReviews(applicationReleaseIds, request, tenantId)); } catch (ReviewManagementDAOException e) { - String msg = "Error occured while getting all reviews for application which has an " + String msg = "Error occurred while getting all reviews for application which has an " + "application release of uuid: " + uuid; log.error(msg, e); throw new ReviewManagementException(msg, e); } catch (DBConnectionException e) { - String msg = "Error occured while getting the DB connection to get app app reviews."; + String msg = "Error occurred while getting the DB connection to get app app reviews."; log.error(msg, e); throw new ReviewManagementException(msg, e); } finally { @@ -458,12 +458,12 @@ public class ReviewManagerImpl implements ReviewManager { } return getReviewTree(reviewDtos); } catch (ReviewManagementDAOException e) { - String msg = "Error occured while getting all " + username + "'s reviews for application which has an " + String msg = "Error occurred while getting all " + username + "'s reviews for application which has an " + "application release of uuid: " + uuid; log.error(msg, e); throw new ReviewManagementException(msg, e); } catch (DBConnectionException e) { - String msg = "Error occured while getting DB connection to get all " + username + "'s reviews for " + String msg = "Error occurred while getting DB connection to get all " + username + "'s reviews for " + "application which has an application release of uuid: " + uuid; log.error(msg, e); throw new ReviewManagementException(msg, e); @@ -486,7 +486,7 @@ public class ReviewManagerImpl implements ReviewManager { .collect(Collectors.toList()); } catch (DBConnectionException e) { String msg = - "Error occured while getting the DB connection to get application which has application release" + "Error occurred while getting the DB connection to get application which has application release" + " of UUID: " + uuid; log.error(msg, e); throw new ReviewManagementException(msg, e); @@ -526,7 +526,7 @@ public class ReviewManagerImpl implements ReviewManager { paginationResult.setRecordsTotal(numOfReviews); return paginationResult; } catch (ReviewManagementDAOException e) { - String msg = "Error occured while getting all reply comments for given review list"; + String msg = "Error occurred while getting all reply comments for given review list"; log.error(msg, e); throw new ReviewManagementException(msg, e); } @@ -635,11 +635,11 @@ public class ReviewManagerImpl implements ReviewManager { throw new ReviewManagementException(msg, e); } catch (ReviewManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occured while deleting review with review id " + reviewId + "."; + String msg = "Error occurred while deleting review with review id " + reviewId + "."; log.error(msg, e); throw new ReviewManagementException(msg, e); } catch (TransactionManagementException e) { - String msg = "Error occurred when handleing transaction to delete application reviews."; + String msg = "Error occurred when handling transaction to delete application reviews."; log.error(msg, e); throw new ReviewManagementException(msg, e); } finally { @@ -663,16 +663,16 @@ public class ReviewManagerImpl implements ReviewManager { return rating; } catch (ApplicationManagementDAOException e) { String msg = - "Error occured while getting the rating value of the application release uuid: " + appReleaseUuid; + "Error occurred while getting the rating value of the application release uuid: " + appReleaseUuid; log.error(msg, e); throw new ReviewManagementException(msg, e); } catch (DBConnectionException e) { - String msg = "DB Connection error occured while getting the rating value of the application release uuid: " + String msg = "DB Connection error occurred while getting the rating value of the application release uuid: " + appReleaseUuid; log.error(msg, e); throw new ReviewManagementException(msg, e); } catch (ReviewManagementDAOException e) { - String msg = "Error occured while getting all rating values for the application release UUID: " + String msg = "Error occurred while getting all rating values for the application release UUID: " + appReleaseUuid; log.error(msg, e); throw new ReviewManagementException(msg, e); @@ -704,18 +704,18 @@ public class ReviewManagerImpl implements ReviewManager { return rating; } catch (DBConnectionException e) { String msg = - "DB Connection error occured while getting app rating of the application which has application " + "DB Connection error occurred while getting app rating of the application which has application " + "release for uuid: " + appReleaseUuid; log.error(msg, e); throw new ReviewManagementException(msg, e); } catch (ApplicationManagementDAOException e) { - String msg = "Error occured while getting the application DTO for the application release uuid: " + String msg = "Error occurred while getting the application DTO for the application release uuid: " + appReleaseUuid; log.error(msg, e); throw new ReviewManagementException(msg, e); } catch (ReviewManagementDAOException e) { String msg = - "Error occured while getting all rating values of application which has the application release " + "Error occurred while getting all rating values of application which has the application release " + "for UUID: " + appReleaseUuid; log.error(msg, e); throw new ReviewManagementException(msg, e); diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/SubscriptionManagerImpl.java index 74d423a8732..a2cb17b079b 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -367,14 +367,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager { try { device = DataHolder.getInstance().getDeviceManagementService().getDevice(deviceIdentifier, false); if (device == null) { - String msg = "Invalid device identifier is received and couldn't find an deveice for the requested " + String msg = "Invalid device identifier is received and couldn't find an device for the requested " + "device identifier. Device UUID: " + deviceIdentifier.getId() + " Device Type: " + deviceIdentifier.getType(); log.error(msg); throw new BadRequestException(msg); } } catch (DeviceManagementException e) { - String msg = "Error occured while getting device data for given device identifier.Device UUID: " + String msg = "Error occurred while getting device data for given device identifier.Device UUID: " + deviceIdentifier.getId() + " Device Type: " + deviceIdentifier.getType(); log.error(msg, e); throw new ApplicationManagementException(msg, e); diff --git a/components/application-mgt/io.entgra.application.mgt.publisher.api/pom.xml b/components/application-mgt/io.entgra.application.mgt.publisher.api/pom.xml index b866b041e24..b10691e62cb 100644 --- a/components/application-mgt/io.entgra.application.mgt.publisher.api/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.publisher.api/pom.xml @@ -22,7 +22,7 @@ application-mgt org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java index e8c0211166b..df98b1ee8ac 100644 --- a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java @@ -89,11 +89,11 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem ApplicationList applications = applicationManager.getApplications(filter); return Response.status(Response.Status.OK).entity(applications).build(); } catch (BadRequestException e) { - String msg = "Incompatible request payload is found. Please try with valid request payload."; + String msg = e.getMessage(); log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (UnexpectedServerErrorException e) { - String msg = "Error Occured when getting supported device types by Entgra IoTS"; + String msg = "Error occurred when getting supported device types by Entgra IoTS"; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (ApplicationManagementException e) { @@ -173,7 +173,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem try { return createApplication(applicationWrapper, isPublished); } catch (BadRequestException e) { - String msg = "Found incompatible payload with ent. app creating request."; + String msg = "Found incompatible payload with ent. app creating request. Please try with valid request payload."; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ApplicationManagementException e) { @@ -195,7 +195,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem try { return createApplication(webAppWrapper, isPublished); } catch (BadRequestException e) { - String msg = "Found incompatible payload with web app creating request."; + String msg = "Found incompatible payload with web app creating request. Please try with valid request payload."; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ApplicationManagementException e) { @@ -217,7 +217,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem try { return createApplication(publicAppWrapper, isPublished); } catch (BadRequestException e) { - String msg = "Found incompatible payload with pub app creating request."; + String msg = "Found incompatible payload with pub app creating request. Please try with valid request payload."; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ApplicationManagementException e) { @@ -239,7 +239,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem try { return createApplication(customAppWrapper, isPublished); } catch (BadRequestException e) { - String msg = "Found incompatible payload with custom app creating request."; + String msg = "Found incompatible payload with custom app creating request. Please try with valid request payload."; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ApplicationManagementException e) { @@ -267,7 +267,11 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem ApplicationRelease release = applicationManager.createEntAppRelease(appId, entAppReleaseWrapper, isPublished); return Response.status(Response.Status.CREATED).entity(release).build(); } catch (RequestValidatingException e) { - String msg = "Error occurred while validating binaryArtifact"; + String msg = e.getMessage(); + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); + } catch (BadRequestException e){ + String msg = e.getMessage(); log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ApplicationManagementException e) { @@ -291,6 +295,10 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem applicationManager.validatePublicAppReleaseCreatingRequest(publicAppReleaseWrapper, deviceTypeName); ApplicationRelease applicationRelease = applicationManager.createPubAppRelease(appId, publicAppReleaseWrapper, isPublished); return Response.status(Response.Status.CREATED).entity(applicationRelease).build(); + } catch (BadRequestException e) { + String msg = e.getMessage(); + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ApplicationManagementException e) { String msg = "Error occurred while creating application release for the application with the id " + appId; log.error(msg, e); @@ -300,7 +308,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (RequestValidatingException e) { - String msg = "Invalid payload found in public app release create request"; + String msg = e.getMessage(); log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } @@ -318,6 +326,10 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem applicationManager.validateWebAppReleaseCreatingRequest(webAppReleaseWrapper); ApplicationRelease applicationRelease= applicationManager.createWebAppRelease(appId, webAppReleaseWrapper, isPublished); return Response.status(Response.Status.CREATED).entity(applicationRelease).build(); + } catch (BadRequestException e) { + String msg = e.getMessage(); + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ResourceManagementException e) { String msg = "Error occurred while uploading application release artifacts"; log.error(msg, e); @@ -327,7 +339,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (RequestValidatingException e) { - String msg = "Invalid payload found in web app release create request"; + String msg = e.getMessage(); log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } @@ -346,8 +358,12 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem applicationManager.validateCustomAppReleaseCreatingRequest(customAppReleaseWrapper, deviceTypeName); ApplicationRelease release = applicationManager.createCustomAppRelease(appId, customAppReleaseWrapper, isPublished); return Response.status(Response.Status.CREATED).entity(release).build(); + } catch (BadRequestException e) { + String msg = e.getMessage(); + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (RequestValidatingException e) { - String msg = "Error occurred while validating binaryArtifact"; + String msg = e.getMessage(); log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ResourceManagementException e) { @@ -386,7 +402,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem } return Response.status(Response.Status.OK).build(); } catch (BadRequestException e) { - String msg = "Found invalid device type to check application existence."; + String msg = e.getMessage(); log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ApplicationManagementException e) { @@ -460,6 +476,10 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem String msg = "Found an invalid device type: " + deviceType + " with the request"; log.error(msg); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); + } catch (ForbiddenException e) { + String msg = e.getMessage(); + log.error(msg, e); + return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); } catch (ApplicationManagementException e) { String msg = "Error occurred while updating the image artifacts of the application with the uuid " + applicationReleaseUuid; @@ -483,8 +503,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (BadRequestException e) { - String msg = "Error occurred while modifying the application. Found bad request payload for updating the " - + "application"; + String msg = e.getMessage(); log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ApplicationManagementException e) { @@ -514,8 +533,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem } return Response.status(Response.Status.OK).entity(applicationRelease).build(); } catch (BadRequestException e) { - String msg = - "Invalid request to update ent app release for application release UUID " + applicationUUID; + String msg = e.getMessage(); log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (NotFoundException e) { @@ -555,7 +573,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem } return Response.status(Response.Status.OK).entity(applicationRelease).build(); } catch (BadRequestException e) { - String msg = "Invalid request to update public app release for application release UUID " + applicationUUID; + String msg = e.getMessage(); log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (NotFoundException e) { @@ -595,7 +613,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem } return Response.status(Response.Status.OK).entity(applicationRelease).build(); } catch (BadRequestException e) { - String msg = "Invalid request to update web app release for web app release UUID " + applicationUUID; + String msg = e.getMessage(); log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (NotFoundException e) { @@ -634,8 +652,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem } return Response.status(Response.Status.OK).entity(applicationRelease).build(); } catch (BadRequestException e) { - String msg = - "Invalid request to update ent app release for application release UUID " + applicationUUID; + String msg = e.getMessage(); log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (NotFoundException e) { @@ -685,7 +702,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem .changeLifecycleState(applicationUuid, lifecycleChanger); return Response.status(Response.Status.CREATED).entity(applicationRelease).build(); } catch (BadRequestException e) { - String msg = "Request payload contains invalid data, hence verify the request payload."; + String msg = e.getMessage(); log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).build(); } catch (ForbiddenException e) { @@ -847,6 +864,10 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem try { List applicationTags = applicationManager.addApplicationTags(appId, tagNames); return Response.status(Response.Status.OK).entity(applicationTags).build(); + } catch (BadRequestException e) { + String msg = e.getMessage(); + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (NotFoundException e) { String msg = e.getMessage(); log.error(msg, e); diff --git a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/SPApplicationServiceImpl.java b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/SPApplicationServiceImpl.java index 4abe861ce81..4eacf5accf4 100644 --- a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/SPApplicationServiceImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/SPApplicationServiceImpl.java @@ -96,6 +96,7 @@ public class SPApplicationServiceImpl implements SPApplicationService { } catch (NotFoundException e) { String msg = "Identity server with the id " + id + " does not exist."; log.error(msg, e); + // TODO : the correct way is to use the NOT_FOUND response here. In order to do it changes are needed for the UI code as well return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ApplicationManagementException e) { String errMsg = "Error occurred while trying to merge identity server apps with existing apps"; @@ -115,6 +116,7 @@ public class SPApplicationServiceImpl implements SPApplicationService { } catch (NotFoundException e) { String msg = "Identity server with the id " + id + " does not exist."; log.error(msg, e); + // TODO : the correct way is to use the NOT_FOUND response here. In order to do it changes are needed for the UI code as well return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ApplicationManagementException e) { String errMsg = "Error occurred while trying to merge identity server apps with existing apps"; @@ -134,9 +136,10 @@ public class SPApplicationServiceImpl implements SPApplicationService { } catch (NotFoundException e) { String msg = "Identity server with the id " + id + " does not exist."; log.error(msg, e); + // TODO : the correct way is to use the NOT_FOUND response here. In order to do it changes are needed for the UI code as well return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (BadRequestException e) { - String errMsg = "Identity server request payload is invalid"; + String errMsg = e.getMessage(); log.error(errMsg, e); return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build(); } catch (ApplicationManagementException e) { @@ -156,8 +159,8 @@ public class SPApplicationServiceImpl implements SPApplicationService { IdentityServerResponse identityServer = spAppManager.createIdentityServer(identityServerDTO); return Response.status(Response.Status.CREATED).entity(identityServer).build(); } catch (BadRequestException e) { - String errMsg = "Identity server request payload is invalid"; - log.error(errMsg, e); + String errMsg = e.getMessage(); + log.error(errMsg, e); return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build(); } catch (ApplicationManagementException e) { String errMsg = "Error occurred while trying to merge identity server apps with existing apps"; @@ -232,6 +235,7 @@ public class SPApplicationServiceImpl implements SPApplicationService { } catch (NotFoundException e) { String errMsg = "No Identity server exist with the id: " + identityServerId; log.error(errMsg, e); + // TODO : the correct way is to use the NOT_FOUND response here. In order to do it changes are needed for the UI code as well return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build(); } catch (ApplicationManagementException e) { String errMsg = "Error occurred while trying to merge identity server apps with existing apps"; @@ -252,6 +256,7 @@ public class SPApplicationServiceImpl implements SPApplicationService { } catch (NotFoundException e) { String msg = "No identity server exist with the id " + identityServerId; log.error(msg, e); + // TODO : the correct way is to use the NOT_FOUND response here. In order to do it changes are needed for the UI code as well return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (BadRequestException e) { String msg = "Invalid appIds provided"; @@ -277,6 +282,7 @@ public class SPApplicationServiceImpl implements SPApplicationService { } catch (NotFoundException e) { String msg = "No identity server exist with the id " + identityServerId; log.error(msg, e); + // TODO : the correct way is to use the NOT_FOUND response here. In order to do it changes are needed for the UI code as well return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (BadRequestException e) { String msg = "Invalid appIds provided"; @@ -343,6 +349,7 @@ public class SPApplicationServiceImpl implements SPApplicationService { } catch (NotFoundException e) { String msg = "No identity server exist with the id " + identityServerId; log.error(msg, e); + // TODO : the correct way is to use the NOT_FOUND response here. In order to do it changes are needed for the UI code as well return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (BadRequestException e) { String msg = "Found incompatible payload with create service provider app request."; diff --git a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java index 9dae875ca88..6fd83760103 100644 --- a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java @@ -155,6 +155,10 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa applicationManager.updateCategory(oldCategoryName, newCategoryName); return Response.status(Response.Status.OK) .entity("Category is updated from " + oldCategoryName + " to " + newCategoryName).build(); + } catch (BadRequestException e) { + String msg = e.getMessage(); + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (NotFoundException e) { String msg = e.getMessage(); log.error(msg, e); @@ -181,6 +185,10 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa String msg = e.getMessage(); log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); + } catch (ForbiddenException e) { + String msg = e.getMessage(); + log.error(msg, e); + return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); } catch (ApplicationManagementException e) { String msg = "Error Occurred while deleting registered category."; log.error(msg, e); diff --git a/components/application-mgt/io.entgra.application.mgt.store.api/pom.xml b/components/application-mgt/io.entgra.application.mgt.store.api/pom.xml index dfbdceb72f1..1ca97cfc0ea 100644 --- a/components/application-mgt/io.entgra.application.mgt.store.api/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.store.api/pom.xml @@ -22,7 +22,7 @@ application-mgt org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.store.api/src/main/java/io/entgra/application/mgt/store/api/services/impl/ApplicationManagementAPIImpl.java b/components/application-mgt/io.entgra.application.mgt.store.api/src/main/java/io/entgra/application/mgt/store/api/services/impl/ApplicationManagementAPIImpl.java index 5f1f124d636..f771645a771 100644 --- a/components/application-mgt/io.entgra.application.mgt.store.api/src/main/java/io/entgra/application/mgt/store/api/services/impl/ApplicationManagementAPIImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.store.api/src/main/java/io/entgra/application/mgt/store/api/services/impl/ApplicationManagementAPIImpl.java @@ -58,7 +58,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { applicationManager.addAppToFavourites(appId); return Response.status(Response.Status.OK).build(); } catch (BadRequestException e) { - String msg = "Invalid payload found in the request. Hence verify the request payload."; + String msg = e.getMessage(); log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ApplicationManagementException e) { @@ -78,7 +78,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { applicationManager.removeAppFromFavourites(appId); return Response.status(Response.Status.OK).build(); } catch (BadRequestException e) { - String msg = "Invalid payload found in the request. Hence verify the request payload."; + String msg = e.getMessage(); log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ApplicationManagementException e) { @@ -147,7 +147,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { String msg = "Could not found an application release which is in " + applicationManager .getInstallableLifecycleState() + " state."; log.error(msg); - return Response.status(Response.Status.OK).entity(msg).build(); + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } return Response.status(Response.Status.OK).entity(application).build(); } catch (NotFoundException e) { diff --git a/components/application-mgt/io.entgra.application.mgt.store.api/src/main/java/io/entgra/application/mgt/store/api/services/impl/ReviewManagementAPIImpl.java b/components/application-mgt/io.entgra.application.mgt.store.api/src/main/java/io/entgra/application/mgt/store/api/services/impl/ReviewManagementAPIImpl.java index 8aa8b728af9..b07f1ea9c61 100644 --- a/components/application-mgt/io.entgra.application.mgt.store.api/src/main/java/io/entgra/application/mgt/store/api/services/impl/ReviewManagementAPIImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.store.api/src/main/java/io/entgra/application/mgt/store/api/services/impl/ReviewManagementAPIImpl.java @@ -131,7 +131,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI { log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (BadRequestException e) { - String msg = "Found invalid payload data with the request. Hence, please verify the request payload."; + String msg = e.getMessage(); log.error(msg); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ForbiddenException e) { @@ -144,7 +144,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI { log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (ApplicationManagementException e) { - String msg = "Error occured while accessing application release for UUID: " + uuid; + String msg = "Error occurred while accessing application release for UUID: " + uuid; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } @@ -164,7 +164,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI { if (isRepliedForReview) { return Response.status(Response.Status.CREATED).entity(reviewWrapper).build(); } else { - String msg = "Error occured when adding reply comment for the review. Please contact the administrator.."; + String msg = "Error occurred when adding reply comment for the review. Please contact the administrator.."; log.error(msg); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } @@ -173,7 +173,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI { log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (BadRequestException e) { - String msg = "Found invalid payload data with the request to add reply comment. Hence, please verify the " + String msg = "Invalid payload data found with the requested add reply comment. Hence, please verify the " + "request payload."; log.error(msg); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); @@ -182,7 +182,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI { log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (ApplicationManagementException e) { - String msg = "Error occured while accessing application release for UUID: " + uuid; + String msg = "Error occurred while accessing application release for UUID: " + uuid; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } @@ -214,8 +214,12 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI { String msg = "Couldn't found application release data for UUID " + uuid + " or Review for review ID: " + reviewId; log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); + } catch (BadRequestException e) { + String msg = "Invalid payload data found with the request. Hence, please verify the request payload."; + log.error(msg); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ForbiddenException e) { - String msg = "You dont have permission to update application release review."; + String msg = "You don't have permission to update application release review."; log.error(msg, e); return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); } catch (ApplicationManagementException e) { @@ -267,7 +271,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI { log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (ReviewManagementException | ApplicationManagementException e) { - String msg = "Error occured while getting review data for application release UUID: " + uuid; + String msg = "Error occurred while getting review data for application release UUID: " + uuid; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } diff --git a/components/application-mgt/io.entgra.application.mgt.store.api/src/main/java/io/entgra/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java b/components/application-mgt/io.entgra.application.mgt.store.api/src/main/java/io/entgra/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java index 11b1ffa6893..ab13168e174 100644 --- a/components/application-mgt/io.entgra.application.mgt.store.api/src/main/java/io/entgra/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.store.api/src/main/java/io/entgra/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java @@ -93,12 +93,11 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ SubAction.valueOf(action.toUpperCase()), timestamp, properties); } } catch (NotFoundException e) { - String msg = "Couldn't found an application release for UUI: " + uuid; + String msg = "Couldn't found an application release for UUID: " + uuid; log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (BadRequestException e) { - String msg = "Found invalid payload for installing application which has UUID: " + uuid + ". Hence verify " - + "the payload"; + String msg = e.getMessage(); log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ForbiddenException e) { @@ -147,8 +146,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (BadRequestException e) { - String msg = "Found invalid payload for installing application which has UUID: " + uuid + ". Hence verify " - + "the payload"; + String msg = e.getMessage(); log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ForbiddenException e) { @@ -187,13 +185,12 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ SubAction.valueOf(SubAction.INSTALL.toString().toUpperCase()), timestamp, null); } } catch (NotFoundException e) { - String msg = "Couldn't found an application release for UUI: " + uuid + " to perform ent app installation " + String msg = "Couldn't found an application release for UUID: " + uuid + " to perform ent app installation " + "on subscriber's devices"; log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (BadRequestException e) { - String msg = "Found invalid payload when performing ent app installation on application which has UUID: " - + uuid + ". Hence verify the payload of the request."; + String msg = e.getMessage(); log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ForbiddenException e) { @@ -237,8 +234,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (BadRequestException e) { - String msg = "Found invalid payload when performing ent app installation on application which has UUID: " - + uuid + ". Hence verify the payload of the request."; + String msg = e.getMessage(); log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ForbiddenException e) { @@ -360,7 +356,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (BadRequestException e) { - String msg = "User requested details are not valid"; + String msg = "User requested details are not valid. Please verify the payload of the request."; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ForbiddenException e) { @@ -424,8 +420,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (BadRequestException e) { - String msg = "Found invalid payload for getting application which has UUID: " + uuid - + ". Hence verify the payload"; + String msg = "Invalid payload found when getting application. Hence verify the payload"; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ForbiddenException e) { @@ -502,6 +497,10 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ String msg = "Application with application release UUID: " + uuid + " is not found"; log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); + } catch (BadRequestException e) { + String msg = "Invalid payload found with the request. Please verify the payload."; + log.error(msg,e); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ApplicationManagementException e) { String msg = "Error occurred while getting application with the application " + "release uuid: " + uuid; diff --git a/components/application-mgt/io.entgra.application.mgt.store.api/src/main/java/io/entgra/application/mgt/store/api/services/impl/admin/SubscriptionManagementAdminAPIImpl.java b/components/application-mgt/io.entgra.application.mgt.store.api/src/main/java/io/entgra/application/mgt/store/api/services/impl/admin/SubscriptionManagementAdminAPIImpl.java index 158696d65e0..08226c72bf0 100644 --- a/components/application-mgt/io.entgra.application.mgt.store.api/src/main/java/io/entgra/application/mgt/store/api/services/impl/admin/SubscriptionManagementAdminAPIImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.store.api/src/main/java/io/entgra/application/mgt/store/api/services/impl/admin/SubscriptionManagementAdminAPIImpl.java @@ -133,7 +133,7 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (BadRequestException e) { - String msg = "User requested details are not valid"; + String msg = "User requested details are not valid. Please verify the request payload."; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ApplicationManagementException e) { diff --git a/components/application-mgt/pom.xml b/components/application-mgt/pom.xml index 603debde5b0..ef99d4dbf9f 100644 --- a/components/application-mgt/pom.xml +++ b/components/application-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml 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 401bf1e2902..3794a693414 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 - 5.0.22-SNAPSHOT + 5.0.25-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 ca00607aa1c..05fd5a7ae62 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 - 5.0.22-SNAPSHOT + 5.0.25-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 b78bc2a6dc1..daa86010f3f 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 @@ -38,7 +38,7 @@ org.wso2.carbon.devicemgt certificate-mgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/pom.xml b/components/certificate-mgt/pom.xml index 34f37128a7e..577a4ff1f40 100644 --- a/components/certificate-mgt/pom.xml +++ b/components/certificate-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager/pom.xml index 8e56f845ac9..5311acc66c1 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager/pom.xml @@ -23,7 +23,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/pom.xml index d71db177578..53ec6cf0e66 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine/pom.xml index ac423deb81a..224941c71d3 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine/pom.xml @@ -23,7 +23,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml 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 a16f0e46ca4..2cc77447ed5 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 - 5.0.22-SNAPSHOT + 5.0.25-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 3d9e19dd8a0..cd95a6fe391 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 - 5.0.22-SNAPSHOT + 5.0.25-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 658b51a8ceb..fe857c4bcfa 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 - 5.0.22-SNAPSHOT + 5.0.25-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 0d107ecda81..a5c33e4a3a1 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 - 5.0.22-SNAPSHOT + 5.0.25-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 ba38443cd27..3e9bf65388a 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 - 5.0.22-SNAPSHOT + 5.0.25-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 7f4e6d7386d..d07439f4f4b 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 - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/pom.xml b/components/device-mgt-extensions/pom.xml index 5b2bf7774f8..2f906d4fcdc 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 - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/components/device-mgt/io.entgra.carbon.device.mgt.config.api/pom.xml b/components/device-mgt/io.entgra.carbon.device.mgt.config.api/pom.xml index 7ffc616573a..356ab22c755 100644 --- a/components/device-mgt/io.entgra.carbon.device.mgt.config.api/pom.xml +++ b/components/device-mgt/io.entgra.carbon.device.mgt.config.api/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/io.entgra.carbon.device.mgt.config.api/src/main/java/io/entgra/carbon/device/mgt/config/jaxrs/service/impl/DeviceManagementConfigServiceImpl.java b/components/device-mgt/io.entgra.carbon.device.mgt.config.api/src/main/java/io/entgra/carbon/device/mgt/config/jaxrs/service/impl/DeviceManagementConfigServiceImpl.java index 4f13273e217..8aea316c557 100644 --- a/components/device-mgt/io.entgra.carbon.device.mgt.config.api/src/main/java/io/entgra/carbon/device/mgt/config/jaxrs/service/impl/DeviceManagementConfigServiceImpl.java +++ b/components/device-mgt/io.entgra.carbon.device.mgt.config.api/src/main/java/io/entgra/carbon/device/mgt/config/jaxrs/service/impl/DeviceManagementConfigServiceImpl.java @@ -91,9 +91,7 @@ public class DeviceManagementConfigServiceImpl implements DeviceManagementConfig if (properties == null || properties.isEmpty()) { String msg = "Devices configuration retrieval criteria cannot be null or empty."; log.error(msg); - return Response.status(Response.Status.BAD_REQUEST).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build() - ).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } ObjectMapper mapper = new ObjectMapper(); @@ -113,18 +111,15 @@ public class DeviceManagementConfigServiceImpl implements DeviceManagementConfig new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } catch (DeviceNotFoundException e) { log.warn(e.getMessage()); - return Response.status(Response.Status.BAD_REQUEST).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(e.getMessage()).build()).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build(); } catch (AmbiguousConfigurationException e) { String msg = "Configurations are ambiguous. " + e.getMessage(); log.warn(msg); - return Response.status(Response.Status.BAD_REQUEST).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (JsonParseException | JsonMappingException e) { String msg = "Malformed device property structure"; log.error(msg.concat(" ").concat(properties), e); - return Response.status(Response.Status.BAD_REQUEST).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (IOException e) { String msg = "Error occurred while parsing query param JSON data."; log.error(msg.concat(" ").concat(properties), e); @@ -150,8 +145,7 @@ public class DeviceManagementConfigServiceImpl implements DeviceManagementConfig if (devicesTransferred.isEmpty()) { String msg = "Devices are not enrolled to super tenant"; log.warn(msg); - return Response.status(Response.Status.BAD_REQUEST).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } else { return Response.status(Response.Status.OK).entity(devicesTransferred).build(); } @@ -163,8 +157,7 @@ public class DeviceManagementConfigServiceImpl implements DeviceManagementConfig new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } catch (DeviceNotFoundException e) { log.error(e.getMessage(), e); - return Response.status(Response.Status.BAD_REQUEST).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(e.getMessage()).build()).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build(); } } 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 fd55008151f..7077d976727 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 - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java index a080208de25..16a3b1ba6dd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java @@ -425,59 +425,6 @@ public interface DeviceManagementService { @QueryParam("limit") int limit); - @GET - @Produces(MediaType.APPLICATION_JSON) - @ApiOperation( - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "Getting Details of Registered Devices Owned by an Authenticated User to generate token for Traccar", - notes = "Provides details of devices enrolled by authenticated users to generate token for Traccar.", - tags = "Device Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view") - }) - } - ) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of devices.", - response = DeviceList.class, - responseHeaders = { - @ResponseHeader( - name = "Content-Type", - description = "The content type of the body"), - @ResponseHeader( - name = "ETag", - description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), - @ResponseHeader( - name = "Last-Modified", - description = "Date and time the resource was last modified.\n" + - "Used by caches, or in conditional requests."), - }), - @ApiResponse( - code = 304, - message = "Not Modified. \n Empty body because the client already has the latest version of " + - "the requested resource.\n"), - @ApiResponse( - code = 400, - message = "The incoming request has more than one selection criteria defined via the query parameters.", - response = ErrorResponse.class), - @ApiResponse( - code = 404, - message = "The search criteria did not match any device registered with the server.", - response = ErrorResponse.class), - @ApiResponse( - code = 406, - message = "Not Acceptable.\n The requested media type is not supported."), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Server error occurred while fetching the device list.", - response = ErrorResponse.class) - }) - @Path("/traccar-user-token") - Response getTraccarUserToken(); - @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{groupId}/location-history") diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java index 9c253c4fa6e..d0539f7b8b5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java @@ -74,9 +74,9 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService dmService = DeviceMgtAPIUtils.getDeviceManagementService(); activity = dmService.getOperationByActivityId(id); if (activity == null) { - return Response.status(404).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("No activity can be " + - "found upon the provided activity id '" + id + "'").build()).build(); + String msg = "No activity can be " + + "found upon the provided activity id '" + id + "'"; + return Response.status(404).entity(msg).build(); } return Response.status(Response.Status.OK).entity(activity).build(); } catch (OperationManagementException e) { @@ -98,10 +98,9 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService List idList; idList = activityIdList.getIdList(); if (idList == null || idList.isEmpty()) { - String msg = "Activity Ids shouldn't be empty"; + String msg = "Activities should not be empty"; log.error(msg); - return Response.status(400).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + return Response.status(400).entity(msg).build(); } Response validationFailedResponse = validateAdminPermission(); if (validationFailedResponse == null) { @@ -125,8 +124,7 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService } else { String msg = "No activity found with the given IDs."; log.error(msg); - return Response.status(404).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + return Response.status(404).entity(msg).build(); } } catch (OperationManagementException e) { String msg = "ErrorResponse occurred while fetching the activity list for the supplied ids."; @@ -162,9 +160,9 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService dmService = DeviceMgtAPIUtils.getDeviceManagementService(); activity = dmService.getOperationByActivityIdAndDevice(id, deviceIdentifier); if (activity == null) { - return Response.status(404).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("No activity can be " + - "found upon the provided activity id '" + id + "'").build()).build(); + String msg = "No activity can be " + + "found upon the provided activity id '" + id + "'"; + return Response.status(404).entity(msg).build(); } return Response.status(Response.Status.OK).entity(activity).build(); } catch (OperationManagementException e) { @@ -247,9 +245,8 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService try { ifSinceDate = format.parse(ifModifiedSince); } catch (ParseException e) { - return Response.status(400).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage( - "Invalid date string is provided in 'If-Modified-Since' header").build()).build(); + String msg = "Invalid date string is provided in [If-Modified-Since] header."; + return Response.status(400).entity(msg).build(); } ifModifiedSinceTimestamp = ifSinceDate.getTime(); timestamp = ifModifiedSinceTimestamp / 1000; @@ -259,9 +256,8 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService try { sinceDate = format.parse(since); } catch (ParseException e) { - return Response.status(400).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage( - "Invalid date string is provided in 'since' filter").build()).build(); + String msg = "Invalid date string is provided in [since] filter."; + return Response.status(400).entity(msg).build(); } sinceTimestamp = sinceDate.getTime(); timestamp = sinceTimestamp / 1000; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index 6d0696df84e..46a37b9f59c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -169,10 +169,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { @QueryParam("limit") int limit) { try { if (!StringUtils.isEmpty(name) && !StringUtils.isEmpty(role)) { - return Response.status(Response.Status.BAD_REQUEST).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("Request contains both name and role " + - "parameters. Only one is allowed " + - "at once.").build()).build(); + String msg = "Request contains both name and role parameters. Only one is allowed at once."; + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } // RequestValidationUtil.validateSelectionCriteria(type, user, roleName, ownership, status); RequestValidationUtil.validatePaginationParameters(offset, limit); @@ -261,9 +259,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { try { sinceDate = format.parse(ifModifiedSince); } catch (ParseException e) { - return Response.status(Response.Status.BAD_REQUEST).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("Invalid date " + - "string is provided in 'If-Modified-Since' header").build()).build(); + String msg = "Invalid date string is provided in [If-Modified-Since] header"; + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } request.setSince(sinceDate); if (requireDeviceInfo) { @@ -282,9 +279,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { try { sinceDate = format.parse(since); } catch (ParseException e) { - return Response.status(Response.Status.BAD_REQUEST).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("Invalid date " + - "string is provided in 'since' filter").build()).build(); + String msg = "Invalid date string is provided in [since] filter"; + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } request.setSince(sinceDate); if (requireDeviceInfo) { @@ -357,103 +353,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } } - @GET - @Override - @Path("/traccar-user-token") - public Response getTraccarUserToken() { - - if (HttpReportingUtil.isTrackerEnabled()) { - String currentUser = CarbonContext.getThreadLocalCarbonContext().getUsername(); - DeviceAPIClientService deviceAPIClientService = DeviceMgtAPIUtils.getDeviceAPIClientService(); - JSONObject obj = new JSONObject(deviceAPIClientService.returnUser(currentUser)); - - if (obj.has("error")) { - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(obj.getString("error")).build(); - } else { - int userId = obj.getInt("id"); - List traccarValidIdList = new ArrayList<>(); - /*Get Device Id List*/ - try { - DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService(); - DeviceAccessAuthorizationService deviceAccessAuthorizationService = - DeviceMgtAPIUtils.getDeviceAccessAuthorizationService(); - PaginationRequest request = new PaginationRequest(0, 0); - PaginationResult result; - DeviceList devices = new DeviceList(); - List status = new ArrayList<>(); - status.add("ACTIVE"); - status.add("INACTIVE"); - status.add("CREATED"); - status.add("UNREACHABLE"); - request.setStatusList(status); - // this is the user who initiates the request - String authorizedUser = MultitenantUtils.getTenantAwareUsername(currentUser); - // check whether the user is device-mgt admin - if (!deviceAccessAuthorizationService.isDeviceAdminUser()) { - request.setOwner(authorizedUser); - } - - result = dms.getAllDevicesIds(request); - if (result == null || result.getData() == null || result.getData().isEmpty()) { - devices.setList(new ArrayList()); - devices.setCount(0); - } else { - devices.setList((List) result.getData()); - devices.setCount(result.getRecordsTotal()); - } - - int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); - TrackerDeviceInfo trackerDevice; - for (Device device : devices.getList()) { - trackerDevice = deviceAPIClientService.getTrackerDevice(device.getId(), tenantId); - if(trackerDevice != null) { - int traccarDeviceId = trackerDevice.getTraccarDeviceId(); - boolean getPermission = deviceAPIClientService.getUserIdofPermissionByDeviceIdNUserId(traccarDeviceId, userId); - traccarValidIdList.add(traccarDeviceId); - if (!getPermission) { - deviceAPIClientService.addTrackerUserDevicePermission(userId, traccarDeviceId); - } - } - } - //Remove necessary - List getAllUserDevices = - deviceAPIClientService.getUserIdofPermissionByUserIdNIdList(userId, traccarValidIdList); - for (TrackerPermissionInfo getAllUserDevice : getAllUserDevices) { - deviceAPIClientService.removeTrackerUserDevicePermission( - getAllUserDevice.getTraccarUserId(), - getAllUserDevice.getTraccarDeviceId(), - TraccarHandlerConstants.Types.REMOVE_TYPE_SINGLE); - } - } catch (DeviceManagementException e) { - String msg = "Error occurred while fetching all enrolled devices. "; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } catch (DeviceAccessAuthorizationException e) { - String msg = "Error occurred while checking device access authorization. "; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } catch (TrackerManagementDAOException e) { - String msg = "Error occurred while mapping with deviceId ."; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } catch (ExecutionException e) { - String msg = "Execution error occurred handling traccar device permissions"; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } catch (InterruptedException e) { - String msg = "Interruption error occurred handling traccar device permissions"; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } - - /*Get Device Id List*/ - return Response.status(Response.Status.OK).entity(obj.getString("token")).build(); - } - } else { - return Response.status(Response.Status.BAD_REQUEST).entity("Traccar is not enabled").build(); - } - } - /** * Validate group Id and group Id greater than 0 and exist. * @@ -517,6 +416,10 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { String msg = "Error occurred while retrieving role list of user '" + authorizedUser + "'"; log.error(msg); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + }catch (BadRequestException e){ + String msg = "Error occurred while validating the device group."; + log.error(msg); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } PaginationResult result = dms.getAllDevices(request, false); @@ -533,7 +436,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } return Response.status(Response.Status.OK).entity(devices).build(); } catch (BadRequestException e) { - String msg = "Invalid type, use either 'path' or 'full'"; + String msg = "Invalid type, use either [path] or [full]"; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (UnAuthorizedException e) { @@ -567,12 +470,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { boolean response = deviceManagementProviderService.disenrollDevice(deviceIdentifier); return Response.status(Response.Status.OK).entity(response).build(); } catch (DeviceManagementException e) { - String msg = "Error encountered while deleting device of type : " + deviceType + " and " + - "ID : " + deviceId; + String msg = "Error encountered while deleting requested device of type : " + deviceType ; log.error(msg, e); - return Response.status(Response.Status.BAD_REQUEST).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build() - ).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } } @@ -594,11 +494,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { return Response.status(Response.Status.CREATED).entity(response).build(); } catch (DeviceManagementException e) { - log.error("Error encountered while updating device of type : " + deviceType + " and " + - "ID : " + deviceId); - return Response.status(Response.Status.BAD_REQUEST).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("Error while updating " + - "device of type " + deviceType + " and ID : " + deviceId).build()).build(); + String msg = "Error encountered while updating requested device of type : " + deviceType ; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } } @@ -639,10 +537,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { sinceDate = format.parse(ifModifiedSince); deviceData.setLastModifiedDate(sinceDate); } catch (ParseException e) { - String msg = "Invalid date string is provided in 'If-Modified-Since' header"; + String msg = "Invalid date string is provided in [If-Modified-Since] header"; log.error(msg, e); - return Response.status(Response.Status.BAD_REQUEST).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } } @@ -669,9 +566,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { return Response.status(Response.Status.NOT_MODIFIED).entity("No device is modified " + "after the timestamp provided in 'If-Modified-Since' header").build(); } - return Response.status(Response.Status.NOT_FOUND).entity( - new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_NOT_FOUND).setMessage("Requested device of type '" + - type + "', which carries id '" + id + "' does not exist").build()).build(); + String msg = "Requested device of type " + type + " does not exist"; + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } return Response.status(Response.Status.OK).entity(device).build(); } @@ -692,7 +588,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { dms); return Response.status(Response.Status.OK).entity(snapshotWrapper).build(); } catch (BadRequestException e) { - String msg = "Invalid type, use either 'path' or 'full'"; + String msg = "Invalid type, use either [path] or [full]"; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (UnAuthorizedException e) { @@ -738,12 +634,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { try { sinceDate = format.parse(ifModifiedSince); } catch (ParseException e) { - String message = "Error occurred while parse the since date.Invalid date string is provided in " + - "'If-Modified-Since' header"; + String message = "Invalid date string is provided in [If-Modified-Since] header"; log.error(message, e); - return Response.status(Response.Status.BAD_REQUEST).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("Invalid date " + - "string is provided in 'If-Modified-Since' header").build()).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(message).build(); } } if (sinceDate != null) { @@ -752,16 +645,15 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { String message = "No device is modified after the timestamp provided in 'If-Modified-Since' header"; log.error(message); return Response.status(Response.Status.NOT_MODIFIED).entity("No device is modified " + - "after the timestamp provided in 'If-Modified-Since' header").build(); + "after the timestamp provided in [If-Modified-Since] header").build(); } } else { device = dms.getDevice(id, requireDeviceInfo); } if (device == null) { - String message = "Device does not exist with id '" + id + "'"; + String message = "Device does not exist"; log.error(message); - return Response.status(Response.Status.NOT_FOUND).entity( - new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage(message).build()).build(); + return Response.status(Response.Status.NOT_FOUND).entity(message).build(); } DeviceIdentifier deviceIdentifier = new DeviceIdentifier(id, device.getType()); // check whether the user is authorized @@ -819,7 +711,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { DeviceManagementProviderService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceManagementService(); if (deviceIds == null || deviceIds.isEmpty()) { - String msg = "Required values of device identifiers are not set.."; + String msg = "Required values of device identifiers are not set."; log.error(msg); return Response.status(Response.Status.BAD_REQUEST).build(); } @@ -1000,9 +892,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { try { fm = dms.getFeatureManager(type); } catch (DeviceTypeNotFoundException e) { - return Response.status(Response.Status.NOT_FOUND).entity( - new ErrorResponse.ErrorResponseBuilder() - .setMessage("No device type found with name '" + type + "'").build()).build(); + String msg = "No device type found with name : " + type ; + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } if (fm != null) { features = fm.getFeatures(); @@ -1223,8 +1114,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } catch (InputValidationException e) { - String msg = "Error occurred while fetching the operations for the '" + type + "' device, which " + - "carries the id '" + id + "'"; + String msg = "Error occurred while fetching the operations for the type : " + type + " device"; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (DeviceManagementException e) { @@ -1233,7 +1123,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (DeviceTypeNotFoundException e) { - String msg = "No device type found with name '" + type + "'"; + String msg = "No device type found with name : " + type ; log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } @@ -1343,11 +1233,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { boolean response = deviceManagementProviderService.changeDeviceStatus(deviceIdentifier, newsStatus); return Response.status(Response.Status.OK).entity(response).build(); } catch (DeviceManagementException e) { - String msg = "Error occurred while changing device status of type : " + type + " and " + - "device id : " + id; + String msg = "Error occurred while changing device status of device type : " + type ; log.error(msg); - return Response.status(Response.Status.BAD_REQUEST).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } } @@ -1375,11 +1263,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { List deviceStatusHistory = deviceManagementProviderService.getDeviceStatusHistory(persistedDevice); return Response.status(Response.Status.OK).entity(deviceStatusHistory).build(); } catch (DeviceManagementException e) { - String msg = "Error occurred while retreiving device status history for device of type : " + type + " and " + - "device id : " + id; + String msg = "Error occurred while retrieving device status history for device of type : " + type ; log.error(msg); - return Response.status(Response.Status.BAD_REQUEST).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } } @@ -1407,11 +1293,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { List deviceStatusHistory = deviceManagementProviderService.getDeviceCurrentEnrolmentStatusHistory(persistedDevice); return Response.status(Response.Status.OK).entity(deviceStatusHistory).build(); } catch (DeviceManagementException e) { - String msg = "Error occurred while retreiving device status history for device of type : " + type + " and " + - "device id : " + id; + String msg = "Error occurred while retrieving device status history for device of type : " + type; log.error(msg); - return Response.status(Response.Status.BAD_REQUEST).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } } @@ -1488,7 +1372,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); } catch (DeviceManagementException e) { - String errorMessage = "Issue in retrieving deivce management service instance"; + String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build(); @@ -1688,7 +1572,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { DeviceType deviceTypeObj = DeviceManagerUtil.getDeviceType( deviceType, tenantId); if (deviceTypeObj == null) { - String msg = "Error, device of type: " + deviceType + " does not exist"; + String msg = "Device of type: " + deviceType + " does not exist"; log.error(msg); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java index 393fd31ff59..b8d7aeb97ac 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java @@ -141,16 +141,15 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ DeviceManagementProviderService dms; try { if (StringUtils.isEmpty(type)) { - return Response.status(Response.Status.BAD_REQUEST).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("Type cannot be empty.").build()).build(); + String msg = "Type cannot be empty."; + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } dms = DeviceMgtAPIUtils.getDeviceManagementService(); FeatureManager fm = dms.getFeatureManager(type); if (fm == null) { - return Response.status(Response.Status.NOT_FOUND).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("No feature manager is " + - "registered with the given type '" + type + "'").build()).build(); + String msg = "No feature manager is registered with the given type : " + type ; + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } if (StringUtils.isEmpty(hidden)) { @@ -165,11 +164,9 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } catch (DeviceTypeNotFoundException e) { - String msg = "No device type found with name '" + type + "'"; + String msg = "No device type found with name : " + type ; log.error(msg, e); - return Response.status(Response.Status.NOT_FOUND).entity( - new ErrorResponse.ErrorResponseBuilder() - .setMessage(msg).build()).build(); + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } return Response.status(Response.Status.OK).entity(features).build(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java index 2207957a2ac..b2063f8985c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java @@ -63,6 +63,7 @@ import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.EventAction; import org.wso2.carbon.device.mgt.jaxrs.beans.GeofenceWrapper; +import org.wso2.carbon.device.mgt.jaxrs.exception.BadRequestException; import org.wso2.carbon.device.mgt.jaxrs.service.api.GeoLocationBasedService; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.InputValidationException; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; @@ -107,8 +108,9 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { @QueryParam("from") long from, @QueryParam("to") long to) { try { if (!DeviceManagerUtil.isPublishLocationResponseEnabled()) { + String msg = "Unable to retrieve Geo Device stats. Geo Data publishing does not enabled."; return Response.status(Response.Status.BAD_REQUEST.getStatusCode()) - .entity("Unable to retrive Geo Device stats. Geo Data publishing does not enabled.").build(); + .entity(msg).build(); } } catch (DeviceManagementException e) { return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).entity(e.getMessage()).build(); @@ -277,7 +279,8 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { if (log.isDebugEnabled()) { log.debug("Device not found: " + identifier.toString()); } - return Response.status(Response.Status.NOT_FOUND.getStatusCode()).build(); + String msg = "Device not found."; + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService(); @@ -288,12 +291,11 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { log.error(error, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build(); } catch (AlertAlreadyExistException e) { - String error = "A geo alert with this name already exists."; + String error = "A geo alert with this name already exists. Try with another name."; log.error(error, e); return Response.status(Response.Status.BAD_REQUEST).entity(error).build(); } catch (DeviceManagementException e) { - String error = "Error occurred while retrieving the device enrollment info of " + - deviceType + " with id: " + deviceId; + String error = "Error occurred while retrieving the device enrollment info of requested "+ deviceType + " device."; log.error(error, e); return Response.status(Response.Status.BAD_REQUEST).entity(error).build(); } @@ -314,7 +316,7 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { log.error(error, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build(); } catch (AlertAlreadyExistException e) { - String error = "A geo alert with this name already exists."; + String error = "A geo alert with this name already exists. Try with another name."; log.error(error, e); return Response.status(Response.Status.BAD_REQUEST).entity(error).build(); } @@ -344,23 +346,23 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { if (log.isDebugEnabled()) { log.debug("Device not found: " + identifier.toString()); } - return Response.status(Response.Status.NOT_FOUND.getStatusCode()).build(); + String msg = "Device not found."; + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService(); geoService.updateGeoAlert(alert, identifier, alertType, device.getEnrolmentInfo().getOwner()); return Response.ok().build(); } catch (DeviceAccessAuthorizationException | GeoLocationBasedServiceException e) { - String error = "Error occurred while creating the geo alert for " + deviceType + " with id: " + deviceId; + String error = "Error occurred while updating the geo alert for " + deviceType + " with id: " + deviceId; log.error(error, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build(); } catch (AlertAlreadyExistException e) { - String error = "A geo alert with this name already exists."; + String error = "A geo alert with this name already exists. Try with another name."; log.error(error, e); return Response.status(Response.Status.BAD_REQUEST).entity(error).build(); } catch (DeviceManagementException e) { - String error = "Error occurred while retrieving the device enrollment info of " + - deviceType + " with id: " + deviceId; + String error = "Error occurred while retrieving the device enrollment info of requested " + deviceType + " device."; log.error(error, e); return Response.status(Response.Status.BAD_REQUEST).entity(error).build(); } @@ -380,7 +382,7 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { log.error(error, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build(); } catch (AlertAlreadyExistException e) { - String error = "A geo alert with this name already exists."; + String error = "A geo alert with this name already exists. Try with another name."; log.error(error, e); return Response.status(Response.Status.BAD_REQUEST).entity(error).build(); } @@ -410,7 +412,8 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { if (log.isDebugEnabled()) { log.debug("Device not found: " + identifier.toString()); } - return Response.status(Response.Status.NOT_FOUND.getStatusCode()).build(); + String msg = "Device not found."; + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService(); @@ -421,8 +424,7 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { log.error(error, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build(); } catch (DeviceManagementException e) { - String error = "Error occurred while retrieving the device enrollment info of " + - deviceType + " with id: " + deviceId; + String error = "Error occurred while retrieving the device enrollment info of requested " +deviceType + " device"; log.error(error, e); return Response.status(Response.Status.BAD_REQUEST).entity(error).build(); } @@ -467,7 +469,8 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { if (log.isDebugEnabled()) { log.debug("Device not found: " + identifier.toString()); } - return Response.status(Response.Status.NOT_FOUND.getStatusCode()).build(); + String msg = "Device not found."; + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService(); @@ -497,8 +500,7 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { log.error(error, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build(); } catch (DeviceManagementException e) { - String error = "Error occurred while retrieving the device enrollment info of " + - deviceType + " with id: " + deviceId; + String error = "Error occurred while retrieving the device enrollment info of requested " + deviceType + " device"; log.error(error, e); return Response.status(Response.Status.BAD_REQUEST).entity(error).build(); } @@ -687,9 +689,9 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { @Consumes("application/json") @Produces("application/json") public Response createGeofence(GeofenceWrapper geofenceWrapper) { - RequestValidationUtil.validateGeofenceData(geofenceWrapper); - RequestValidationUtil.validateEventConfigurationData(geofenceWrapper.getEventConfig()); try { + RequestValidationUtil.validateGeofenceData(geofenceWrapper); + RequestValidationUtil.validateEventConfigurationData(geofenceWrapper.getEventConfig()); GeofenceData geofenceData = mapRequestGeofenceData(geofenceWrapper); GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService(); if (!geoService.createGeofence(geofenceData)) { @@ -699,6 +701,8 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } return Response.status(Response.Status.CREATED).entity("Geo Fence record created successfully").build(); + } catch (BadRequestException e){ + return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build(); } catch (GeoLocationBasedServiceException e) { String msg = "Failed to create geofence"; log.error(msg, e); @@ -895,9 +899,9 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { public Response updateGeofence(GeofenceWrapper geofenceWrapper, @PathParam("fenceId") int fenceId, @QueryParam("eventIds") int[] eventIds) { - RequestValidationUtil.validateGeofenceData(geofenceWrapper); - RequestValidationUtil.validateEventConfigurationData(geofenceWrapper.getEventConfig()); try { + RequestValidationUtil.validateGeofenceData(geofenceWrapper); + RequestValidationUtil.validateEventConfigurationData(geofenceWrapper.getEventConfig()); GeofenceData geofenceData = mapRequestGeofenceData(geofenceWrapper); GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService(); if (!geoService.updateGeofence(geofenceData, fenceId)) { @@ -912,6 +916,8 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { geoService.updateGeoEventConfigurations(geofenceData, eventsToRemove, geofenceData.getGroupIds(), fenceId); return Response.status(Response.Status.CREATED).entity("Geo Fence update successfully").build(); + } catch (BadRequestException e){ + return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build(); } catch (GeoLocationBasedServiceException e) { String msg = "Failed to update geofence"; log.error(msg, e); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java index 898ffb6c23a..514685507df 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java @@ -167,7 +167,7 @@ public class GroupManagementServiceImpl implements GroupManagementService { log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (GroupAlreadyExistException e) { - String msg = "Group already exists with name " + group.getName() + "."; + String msg = "Group already exists with name : " + group.getName() + "."; log.warn(msg); return Response.status(Response.Status.CONFLICT).entity(msg).build(); } @@ -181,7 +181,7 @@ public class GroupManagementServiceImpl implements GroupManagementService { if (deviceGroup != null) { return Response.status(Response.Status.OK).entity(deviceGroup).build(); } else { - return Response.status(Response.Status.NOT_FOUND).build(); + return Response.status(Response.Status.NOT_FOUND).entity("Group not found.").build(); } } catch (GroupManagementException e) { String error = "Error occurred while getting the group."; @@ -198,7 +198,7 @@ public class GroupManagementServiceImpl implements GroupManagementService { if (deviceGroup != null) { return Response.status(Response.Status.OK).entity(deviceGroup).build(); } else { - return Response.status(Response.Status.NOT_FOUND).build(); + return Response.status(Response.Status.NOT_FOUND).entity("Group not found.").build(); } } catch (GroupManagementException e) { String error = "Error occurred while getting the group."; @@ -220,11 +220,11 @@ public class GroupManagementServiceImpl implements GroupManagementService { log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (GroupNotExistException e) { - String msg = "Group doesn't exist with ID '" + deviceGroup.getGroupId() + "'."; + String msg = "Group does not exist."; log.warn(msg); return Response.status(Response.Status.CONFLICT).entity(msg).build(); } catch (GroupAlreadyExistException e) { - String msg = "Group already exists with name '" + deviceGroup.getName() + "'."; + String msg = "Group already exists with name : '" + deviceGroup.getName() + "'."; log.warn(msg); return Response.status(Response.Status.CONFLICT).entity(msg).build(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java index 6a2dbe68a3c..7405a73e722 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java @@ -40,6 +40,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; @@ -83,8 +84,9 @@ public class PolicyManagementServiceImpl implements PolicyManagementService { .validatePolicyDetails(policyWrapper); // validation failure results; if (!features.isEmpty()) { - log.error("Policy feature/s validation failed."); - return Response.status(Response.Status.BAD_REQUEST).entity(features).build(); + String msg = "Policy feature/s validation failed." ; + log.error(msg); + return Response.status(Response.Status.BAD_REQUEST).entity(msg + " Features : " + features).build(); } PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService(); @@ -212,9 +214,8 @@ public class PolicyManagementServiceImpl implements PolicyManagementService { PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP(); policy = policyAdministratorPoint.getPolicy(id); if (policy == null) { - return Response.status(Response.Status.NOT_FOUND).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage( - "No policy found with the id '" + id + "'").build()).build(); + String msg = "Policy not found."; + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } } catch (PolicyManagementException e) { String msg = "Error occurred while retrieving policy corresponding to the id '" + id + "'"; @@ -233,8 +234,9 @@ public class PolicyManagementServiceImpl implements PolicyManagementService { .validatePolicyDetails(policyWrapper); // validation failure results; if (!features.isEmpty()) { - log.error("Policy feature/s validation failed."); - return Response.status(Response.Status.BAD_REQUEST).entity(features).build(); + String msg = "Policy feature/s validation failed." ; + log.error(msg); + return Response.status(Response.Status.BAD_REQUEST).entity(msg + " Features : " + features).build(); } PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService(); try { @@ -296,10 +298,8 @@ public class PolicyManagementServiceImpl implements PolicyManagementService { //TODO:Check of this logic is correct String modifiedInvalidPolicyIds = invalidPolicyIds.substring(0, invalidPolicyIds.length() - 1); - return Response.status(Response.Status.BAD_REQUEST). - entity(new ErrorResponse.ErrorResponseBuilder(). - setMessage("Policies with the policy ID " + modifiedInvalidPolicyIds + - " doesn't exist").build()).build(); + String msg = "Policies does not exist."; + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } } @@ -329,9 +329,8 @@ public class PolicyManagementServiceImpl implements PolicyManagementService { return Response.status(Response.Status.OK).entity("Selected policies have been successfully activated") .build(); } else { - return Response.status(Response.Status.NOT_FOUND).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("Selected policies have " + - "not been activated").build()).build(); + String msg = "Selected policies have not been activated."; + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } } @@ -361,9 +360,8 @@ public class PolicyManagementServiceImpl implements PolicyManagementService { return Response.status(Response.Status.OK).entity("Selected policies have been successfully " + "deactivated").build(); } else { - return Response.status(Response.Status.NOT_FOUND).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("Selected policies have " + - "not been deactivated").build()).build(); + String msg = "Selected policies have not been activated."; + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } } @@ -412,9 +410,8 @@ public class PolicyManagementServiceImpl implements PolicyManagementService { + "updated.").build(); } else { - return Response.status(Response.Status.NOT_FOUND).entity( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Policy priorities did " - + "not update. Bad Request.").build()).build(); + String msg = "Policy priorities did not update. Bad Request."; + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } } @@ -440,9 +437,8 @@ public class PolicyManagementServiceImpl implements PolicyManagementService { } policy = policyManagementService.getAppliedPolicyToDevice(device); if (policy == null) { - return Response.status(Response.Status.NOT_FOUND).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage( - "No policy found for device ID '" + deviceId + "'"+ deviceId).build()).build(); + String msg = "Policy not found for the requested device."; + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } } catch (PolicyManagementException e) { String msg = "Error occurred while retrieving policy corresponding to the id '" + deviceType + "'"+ deviceId; @@ -491,8 +487,9 @@ public class PolicyManagementServiceImpl implements PolicyManagementService { = RequestValidationUtil.validateProfileFeatures(profileFeaturesList); // validation failure results; if (!features.isEmpty()) { - log.error("Policy feature/s validation failed."); - return Response.status(Response.Status.BAD_REQUEST).entity(features).build(); + String msg = "Policy feature/s validation failed." ; + log.error(msg); + return Response.status(Response.Status.BAD_REQUEST).entity(msg + " Features : " +features).build(); } return Response.status(Response.Status.OK).entity("Valid request").build(); @@ -508,18 +505,13 @@ public class PolicyManagementServiceImpl implements PolicyManagementService { RequestValidationUtil.validatePaginationParameters(offset, limit); PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService(); List policies; - List filteredPolicies; PolicyList targetPolicies = new PolicyList(); + PaginationRequest request = new PaginationRequest(offset, limit); try { PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP(); - policies = policyAdministratorPoint.getPolicyList(); - targetPolicies.setCount(policies.size()); - if (offset == 0 && limit == 0) { - targetPolicies.setList(policies); - } else { - filteredPolicies = FilteringUtil.getFilteredList(policies, offset, limit); - targetPolicies.setList(filteredPolicies); - } + policies = policyAdministratorPoint.getPolicyList(request); + targetPolicies.setCount(policyAdministratorPoint.getPolicyCount()); + targetPolicies.setList(policies); } catch (PolicyManagementException e) { String msg = "Error occurred while retrieving all available policies"; log.error(msg, e); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java index af05da7991f..0894b2f2cd6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -169,8 +169,9 @@ public class RoleManagementServiceImpl implements RoleManagementService { try { final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm(); if (!userRealm.getUserStoreManager().isExistingRole(roleName)) { - return Response.status(404).entity(new ErrorResponse.ErrorResponseBuilder().setMessage( - "No role exists with the name '" + roleName + "'").build()).build(); + + String msg = "No role exists with the name : " + roleName ; + return Response.status(404).entity(msg).build(); } final UIPermissionNode rolePermissions = this.getUIPermissionNode(roleName, userRealm); @@ -249,9 +250,8 @@ public class RoleManagementServiceImpl implements RoleManagementService { final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm(); if (!userStoreManager.isExistingRole(roleName)) { - return Response.status(404).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("No role exists with the name '" + - roleName + "'").build()).build(); + String msg = "No role exists with the name : " + roleName ; + return Response.status(404).entity(msg).build(); } roleInfo.setRoleName(roleName); roleInfo.setUsers(userStoreManager.getUserListOfRole(roleName)); @@ -325,7 +325,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { } if (ErrorMessages.ERROR_CODE_ROLE_ALREADY_EXISTS.getCode().equals(errorCode)) { String roleName = roleInfo.getRoleName().split("/")[1]; - String msg = "Role already exists with name " + roleName + "."; + String msg = "Role already exists with name : " + roleName + ". Try with another role name."; log.warn(msg); return Response.status(Response.Status.CONFLICT).entity(msg).build(); } else { @@ -354,10 +354,8 @@ public class RoleManagementServiceImpl implements RoleManagementService { roleName = userStoreName + "/" + roleName; } if (roles.size() < 2) { - return Response.status(400).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("Combining Roles requires at least two roles.") - .build() - ).build(); + String msg = "Combining Roles requires at least two roles."; + return Response.status(400).entity(msg).build(); } for (String role : roles) { RequestValidationUtil.validateRoleName(role); @@ -374,9 +372,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { mergePermissions(new UIPermissionNode[]{getRolePermissions(role)}, permsSet); } } catch (IllegalArgumentException e) { - return Response.status(404).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(e.getMessage()).build() - ).build(); + return Response.status(404).entity(e.getMessage()).build(); } Permission[] permissions = permsSet.toArray(new Permission[permsSet.size()]); @@ -424,9 +420,8 @@ public class RoleManagementServiceImpl implements RoleManagementService { final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm(); final UserStoreManager userStoreManager = userRealm.getUserStoreManager(); if (!userStoreManager.isExistingRole(roleName)) { - return Response.status(404).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("No role exists with the name '" + - roleName + "'").build()).build(); + String msg = "No role exists with the name : " + roleName ; + return Response.status(404).entity(msg).build(); } final AuthorizationManager authorizationManager = userRealm.getAuthorizationManager(); @@ -481,10 +476,23 @@ public class RoleManagementServiceImpl implements RoleManagementService { return Response.status(Response.Status.OK).entity("Role '" + roleInfo.getRoleName() + "' has " + "successfully been updated").build(); } catch (UserStoreException e) { - String msg = "Error occurred while updating role '" + roleName + "'"; - log.error(msg, e); - return Response.serverError().entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + String errorCode = ""; + String errorMessage = e.getMessage(); + if (errorMessage != null && !errorMessage.isEmpty() && + errorMessage.contains(ErrorMessages.ERROR_CODE_ROLE_ALREADY_EXISTS.getCode())) { + errorCode = e.getMessage().split("-")[0].trim(); + } + if (ErrorMessages.ERROR_CODE_ROLE_ALREADY_EXISTS.getCode().equals(errorCode)) { + String role = roleInfo.getRoleName().split("/")[1]; + String msg = "Role already exists with name : " + role + ". Try with another role name."; + log.warn(msg); + return Response.status(Response.Status.CONFLICT).entity(msg).build(); + }else{ + String msg = "Error occurred while updating role '" + roleName + "'"; + log.error(msg, e); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } } catch (UserAdminException e) { String msg = "Error occurred while updating permissions of the role '" + roleName + "'"; log.error(msg, e); @@ -559,9 +567,8 @@ public class RoleManagementServiceImpl implements RoleManagementService { final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm(); final UserStoreManager userStoreManager = userRealm.getUserStoreManager(); if (!userStoreManager.isExistingRole(roleName)) { - return Response.status(404).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("No role exists with the name '" + - roleName + "'").build()).build(); + String msg = "No role exists with the name : " + roleName ; + return Response.status(404).entity(msg).build(); } final AuthorizationManager authorizationManager = userRealm.getAuthorizationManager(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java index 1fbb402dcd0..c6f6d882e05 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java @@ -157,10 +157,8 @@ public class UserManagementServiceImpl implements UserManagementService { " already exists. Therefore, request made to add user was refused."); } // returning response with bad request state - return Response.status(Response.Status.CONFLICT).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("User by username: " + - userInfo.getUsername() + " already exists. Therefore, request made to add user " + - "was refused.").build()).build(); + String msg = "User by username: " + userInfo.getUsername() + " already exists. Try with another username." ; + return Response.status(Response.Status.CONFLICT).entity(msg).build(); } String initialUserPassword; @@ -290,9 +288,8 @@ public class UserManagementServiceImpl implements UserManagementService { if (log.isDebugEnabled()) { log.debug("User by username: " + username + " does not exist."); } - return Response.status(Response.Status.NOT_FOUND).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage( - "User doesn't exist.").build()).build(); + String msg = "User by username: " + username + " does not exist."; + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } BasicUserInfo user = this.getBasicUserInfo(username); @@ -318,9 +315,8 @@ public class UserManagementServiceImpl implements UserManagementService { log.debug("User by username: " + username + " doesn't exists. Therefore, request made to update user was refused."); } - return Response.status(Response.Status.NOT_FOUND).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("User by username: " + - username + " doesn't exist.").build()).build(); + String msg = "User by username: " + username + " does not exist."; + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } Map defaultUserClaims = @@ -396,9 +392,8 @@ public class UserManagementServiceImpl implements UserManagementService { if (log.isDebugEnabled()) { log.debug("User by username: " + username + " does not exist for removal."); } - return Response.status(Response.Status.NOT_FOUND).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("User '" + - username + "' does not exist for removal.").build()).build(); + String msg = "User by username: " + username + " does not exist for removal."; + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } // Un-enroll all devices for the user DeviceManagementProviderService deviceManagementService = DeviceMgtAPIUtils.getDeviceManagementService(); @@ -430,9 +425,8 @@ public class UserManagementServiceImpl implements UserManagementService { if (log.isDebugEnabled()) { log.debug("User by username: " + username + " does not exist for role retrieval."); } - return Response.status(Response.Status.NOT_FOUND).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("User by username: " + username + - " does not exist for role retrieval.").build()).build(); + String msg = "User by username: " + username + " does not exist for role retrieval."; + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } RoleList result = new RoleList(); @@ -867,8 +861,8 @@ public class UserManagementServiceImpl implements UserManagementService { try { ifSinceDate = format.parse(ifModifiedSince); } catch (ParseException e) { - return Response.status(400).entity(new ErrorResponse.ErrorResponseBuilder() - .setMessage("Invalid date string is provided in 'If-Modified-Since' header").build()).build(); + String msg = "Invalid date string is provided in [If-Modified-Since] header"; + return Response.status(400).entity(msg).build(); } ifModifiedSinceTimestamp = ifSinceDate.getTime(); isIfModifiedSinceSet = true; @@ -879,8 +873,8 @@ public class UserManagementServiceImpl implements UserManagementService { try { sinceDate = format.parse(since); } catch (ParseException e) { - return Response.status(400).entity(new ErrorResponse.ErrorResponseBuilder() - .setMessage("Invalid date string is provided in 'since' filter").build()).build(); + String msg = "Invalid date string is provided in [since] filter"; + return Response.status(400).entity(msg).build(); } sinceTimestamp = sinceDate.getTime(); timestamp = sinceTimestamp / 1000; @@ -1094,8 +1088,7 @@ public class UserManagementServiceImpl implements UserManagementService { if (!userStoreManager.isExistingUser(username)) { String message = "User by username: " + username + " does not exist for permission retrieval."; log.error(message); - return Response.status(Response.Status.NOT_FOUND) - .entity(new ErrorResponse.ErrorResponseBuilder().setMessage(message).build()).build(); + return Response.status(Response.Status.NOT_FOUND).entity(message).build(); } // Get a list of roles which the user assigned to List roles = getFilteredRoles(userStoreManager, username); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/WhiteLabelServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/WhiteLabelServiceImpl.java index 97621667dcd..9c11dcd6f06 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/WhiteLabelServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/WhiteLabelServiceImpl.java @@ -127,13 +127,9 @@ public class WhiteLabelServiceImpl implements WhiteLabelService { WhiteLabelTheme whiteLabelTheme = DeviceMgtAPIUtils.getWhiteLabelManagementService().getWhiteLabelTheme(tenantDomain); return Response.status(Response.Status.CREATED).entity(whiteLabelTheme).build(); } catch (MetadataManagementException e) { - String msg = "Error occurred while deleting whitelabel for tenant"; + String msg = "Error occurred while getting whitelabel for tenant"; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } catch (NotFoundException e) { - String msg = "Not white label theme configured for this tenant"; - log.error(msg, e); - return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (DeviceManagementException e) { String msg = "Error occurred while retrieving tenant details of whitelabel"; log.error(msg, e); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/ApplicationManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/ApplicationManagementAdminServiceImpl.java index d942c77e7b0..55c8c2ff1d0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/ApplicationManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/ApplicationManagementAdminServiceImpl.java @@ -81,9 +81,8 @@ public class ApplicationManagementAdminServiceImpl implements ApplicationManagem applicationWrapper.getDeviceIdentifiers().size() > 0) { activity = appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers()); } else { - return Response.status(Response.Status.BAD_REQUEST).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage( - "No application installation criteria i.e. user/role/device is given").build()).build(); + String msg = "No application installation criteria i.e. user/role/device is given"; + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } } return Response.status(Response.Status.ACCEPTED).entity(activity).build(); @@ -131,9 +130,8 @@ public class ApplicationManagementAdminServiceImpl implements ApplicationManagem applicationWrapper.getDeviceIdentifiers().size() > 0) { activity = appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers()); } else { - return Response.status(Response.Status.BAD_REQUEST).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage( - "No application un-installation criteria i.e. user/role/device is given").build()).build(); + String msg = "No application un-installation criteria i.e. user/role/device is given"; + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } } return Response.status(Response.Status.ACCEPTED).entity(activity).build(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java index acadf926f2b..1137beceed6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java @@ -169,7 +169,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (UserNotFoundException e) { - String msg = "Couldn't found the owner in user store to update the owner of devices."; + String msg = "Could not found the owner in user store to update the owner of devices."; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } @@ -197,8 +197,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } catch (InvalidDeviceException e) { String msg = "Found Invalid devices"; log.error(msg, e); - return Response.status(Response.Status.BAD_REQUEST).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } } @@ -222,7 +221,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe log.error(msg); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (BadRequestException e) { - String msg = "Bad request, can't proceed. Hence verify the request and re-try"; + String msg = "Bad request, cannot proceed. Hence verify the request and re-try"; log.error(msg); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (DeviceManagementException e) { @@ -230,7 +229,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe log.error(msg); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (DeviceNotFoundException e) { - String msg = "Couldn't find an device for device identifier: " + deviceIdentifier; + String msg = "Could not find an device"; log.error(msg); return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/GroupManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/GroupManagementAdminServiceImpl.java index a461b71b500..9dd67617e81 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/GroupManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/GroupManagementAdminServiceImpl.java @@ -156,7 +156,7 @@ public class GroupManagementAdminServiceImpl implements GroupManagementAdminServ log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (GroupAlreadyExistException e) { - String msg = "Group already exists with name " + group.getName() + "."; + String msg = "Group already exists with name : " + group.getName() + ". Try with another group name."; log.warn(msg); return Response.status(Response.Status.CONFLICT).entity(msg).build(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java index 564e16f8dde..bb15685f2cc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java @@ -49,6 +49,7 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.ProfileFeature; import org.wso2.carbon.device.mgt.jaxrs.beans.RoleInfo; import org.wso2.carbon.device.mgt.jaxrs.beans.Scope; +import org.wso2.carbon.device.mgt.jaxrs.exception.BadRequestException; import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.policy.mgt.common.PolicyPayloadValidator; @@ -849,8 +850,7 @@ public class RequestValidationUtil { if (geofenceWrapper.getFenceName() == null || geofenceWrapper.getFenceName().trim().isEmpty()) { String msg = "Geofence name should not be null or empty"; log.error(msg); - throw new InputValidationException( - new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build()); + throw new BadRequestException(msg); } if (geofenceWrapper.getGeoJson() != null && !geofenceWrapper.getGeoJson().trim().isEmpty()) { isGeoJsonExists = true; @@ -858,26 +858,22 @@ public class RequestValidationUtil { if ((geofenceWrapper.getLatitude() < -90 || geofenceWrapper.getLatitude() > 90) && !isGeoJsonExists) { String msg = "Latitude should be a value between -90 and 90"; log.error(msg); - throw new InputValidationException( - new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build()); + throw new BadRequestException(msg); } if ((geofenceWrapper.getLongitude() < -180 || geofenceWrapper.getLongitude() > 180) && !isGeoJsonExists) { String msg = "Longitude should be a value between -180 and 180"; log.error(msg); - throw new InputValidationException( - new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build()); + throw new BadRequestException(msg); } if (geofenceWrapper.getRadius() < 1 && !isGeoJsonExists) { String msg = "Minimum radius of the fence should be 1m"; log.error(msg); - throw new InputValidationException( - new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build()); + throw new BadRequestException(msg); } if (geofenceWrapper.getFenceShape().trim().isEmpty()) { String msg = "Fence shape should not be empty"; log.error(msg); - throw new InputValidationException( - new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build()); + throw new BadRequestException(msg); } } @@ -889,23 +885,20 @@ public class RequestValidationUtil { if (eventConfig == null ||eventConfig.isEmpty()) { String msg = "Event configuration is mandatory, since should not be null or empty"; log.error(msg); - throw new InputValidationException( - new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build()); + throw new BadRequestException(msg); } for (EventConfig config : eventConfig) { if (config.getActions() == null || config.getActions().isEmpty()) { String msg = "Event actions are mandatory, since should not be null or empty"; log.error(msg); - throw new InputValidationException( - new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build()); + throw new BadRequestException(msg); } if (config.getEventLogic() == null || config.getEventLogic().trim().isEmpty()) { String msg = "Event logic is mandatory, since should not be null or empty"; log.error(msg); - throw new InputValidationException( - new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build()); + throw new BadRequestException(msg); } } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java index 37a08c7e00f..e2100f03eb1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java @@ -77,6 +77,7 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.report.mgt.ReportManagementService; import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService; import org.wso2.carbon.device.mgt.common.spi.OTPManagementService; +import org.wso2.carbon.device.mgt.common.spi.TraccarManagementService; import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService; import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; import org.wso2.carbon.device.mgt.core.dto.DeviceTypeVersion; 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 b769df09061..a93ef7f3ad0 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 - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/metadata/mgt/WhiteLabelManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/metadata/mgt/WhiteLabelManagementService.java index 6ccf82eab47..6fc34c52dda 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/metadata/mgt/WhiteLabelManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/metadata/mgt/WhiteLabelManagementService.java @@ -79,5 +79,5 @@ public interface WhiteLabelManagementService { * This method is useful to get existing white label theme * @throws MetadataManagementException if error while getting existing white label theme */ - WhiteLabelTheme getWhiteLabelTheme(String tenantDomain) throws MetadataManagementException, NotFoundException, DeviceManagementException; + WhiteLabelTheme getWhiteLabelTheme(String tenantDomain) throws MetadataManagementException, DeviceManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/otp/mgt/wrapper/DownloadURLDetails.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/otp/mgt/wrapper/DownloadURLDetails.java deleted file mode 100644 index e6a8557b66d..00000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/otp/mgt/wrapper/DownloadURLDetails.java +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. - * - * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.common.otp.mgt.wrapper; - -public class DownloadURLDetails { - - private String firstName; - private String URL; - private String email; - - public String getURL() { - return URL; - } - - public void setURL(String URL) { - this.URL = URL; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/OTPManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/OTPManagementService.java index 27e20328c5b..bf1d112875f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/OTPManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/OTPManagementService.java @@ -22,21 +22,11 @@ import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.exceptions.OTPManagementException; import org.wso2.carbon.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitation; import org.wso2.carbon.device.mgt.common.otp.mgt.dto.OneTimePinDTO; -import org.wso2.carbon.device.mgt.common.otp.mgt.wrapper.DownloadURLDetails; -import org.wso2.carbon.device.mgt.common.otp.mgt.wrapper.OTPWrapper; import java.util.Map; public interface OTPManagementService { - /** - * Create OTP token and store tenant details in the DB - * @param otpWrapper OTP Mail Wrapper object which contains tenant details of registering user - * @throws OTPManagementException if error occurs while creating OTP token and storing tenant details. - * @throws BadRequestException if found and incompatible payload to create OTP token. - */ - String sendUserVerifyingMail(OTPWrapper otpWrapper) throws OTPManagementException, DeviceManagementException; - /** * Check the validity of the OTP * @param oneTimeToken OTP @@ -64,12 +54,13 @@ public interface OTPManagementService { void sendDeviceEnrollmentInvitationMail(DeviceEnrollmentInvitation deviceEnrollmentInvitation) throws OTPManagementException; - /** - * Send an e-mail to the requesting e-mail address with a product download URL - * @param downloadURLDetails Contains the details to send product download e-mail - * @throws OTPManagementException if request payload doesn't contains required details to send the product - * download mail. - */ - void shareProductDownloadUrl(DownloadURLDetails downloadURLDetails) throws OTPManagementException; - } + boolean hasEmailRegistered(String email, String emailDomain) throws OTPManagementException, + DeviceManagementException; + + OneTimePinDTO generateOneTimePin(String email, String emailType, String userName, Object metaDataObj, + int tenantId, boolean persistPin) throws OTPManagementException; + + OneTimePinDTO getRenewedOtpByEmailAndMailType(String email, String emailType) throws OTPManagementException; + +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/TraccarManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/TraccarManagementService.java new file mode 100644 index 00000000000..0c3379eedfa --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/TraccarManagementService.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.common.spi; + +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; + +public interface TraccarManagementService { + + /** + * Add the provided device to Traccar. + * @param device The device to be added to Traccar. + */ + void addDevice(Device device); + + /** + * Removes the Traccar device with the specified device ID from the logged in user. + * @param deviceEnrollmentId The enrollment ID of the device to be removed from Traccar. + */ + void unLinkTraccarDevice(int deviceEnrollmentId); + + /** + * Update the provided device to Traccar. + * @param device The device to be updated on Traccar. + */ + void updateDevice(Device device); + + /** + * Removes the device with the specified enrollment ID from Traccar. + * @param deviceEnrollmentId The enrollment ID of the device to be removed from Traccar. + */ + void removeDevice(int deviceEnrollmentId); + + /** + * Updates the location of the provided device with the specified device location. + * @param device The device whose location is to be updated. + * @param deviceLocation The new location of the device. + */ + void updateLocation(Device device, DeviceLocation deviceLocation); +} 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 07d7cdc4a7d..1265503f186 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 - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java index cc82921cbc4..7dde5efb162 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java @@ -354,4 +354,4 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem DeviceManagementDAOFactory.closeConnection(); } } -} \ No newline at end of file +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java index b293798ba26..f17719d228d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java @@ -382,25 +382,11 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { deviceLocation.getBearing(), deviceLocation.getDistance() }; -// DeviceManagerUtil.getEventPublisherService().publishEvent( -// LOCATION_EVENT_STREAM_DEFINITION, "1.0.0", metaData, new Object[0], payload -// ); } //Tracker update GPS Location if (HttpReportingUtil.isLocationPublishing() && HttpReportingUtil.isTrackerEnabled()) { - try { - DeviceManagementDataHolder.getInstance().getDeviceAPIClientService() - .updateLocation(device, deviceLocation, CarbonContext.getThreadLocalCarbonContext().getTenantId()); - } catch (ExecutionException e) { - log.error("ExecutionException : " + e); - //throw new RuntimeException(e); - //Exception was not thrown due to being conflicted with non-traccar features - } catch (InterruptedException e) { - log.error("InterruptedException : " + e); - //throw new RuntimeException(e); - //Exception was not thrown due to being conflicted with non-traccar features - } + DeviceManagementDataHolder.getInstance().getTraccarManagementService().updateLocation(device, deviceLocation); } else { if(!HttpReportingUtil.isLocationPublishing()) { if (log.isDebugEnabled()) { @@ -413,8 +399,6 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { } } } - //Tracker update GPS Location - DeviceManagementDAOFactory.commitTransaction(); } catch (TransactionManagementException e) { throw new DeviceDetailsMgtException("Transactional error occurred while adding the device location " + @@ -453,18 +437,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { for (DeviceLocation deviceLocation: deviceLocations) { //Tracker update GPS Location if (HttpReportingUtil.isLocationPublishing() && HttpReportingUtil.isTrackerEnabled()) { - try { - DeviceManagementDataHolder.getInstance().getDeviceAPIClientService() - .updateLocation(device, deviceLocation, CarbonContext.getThreadLocalCarbonContext().getTenantId()); - } catch (ExecutionException e) { - log.error("ExecutionException : " + e); - //throw new RuntimeException(e); - // NOTE: Exception was not thrown due to being conflicted with non-traccar features - } catch (InterruptedException e) { - log.error("InterruptedException : " + e); - //throw new RuntimeException(e); - // NOTE: Exception was not thrown due to being conflicted with non-traccar features - } + DeviceManagementDataHolder.getInstance().getTraccarManagementService().updateLocation(device, deviceLocation); } else { if(!HttpReportingUtil.isLocationPublishing()) { if (log.isDebugEnabled()) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java index 13999efbc7e..08cfdff5911 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java @@ -19,6 +19,7 @@ package org.wso2.carbon.device.mgt.core.internal; import io.entgra.server.bootup.heartbeat.beacon.service.HeartBeatManagementService; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; @@ -30,6 +31,7 @@ import org.wso2.carbon.device.mgt.common.metadata.mgt.MetadataManagementService; import org.wso2.carbon.device.mgt.common.metadata.mgt.WhiteLabelManagementService; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService; +import org.wso2.carbon.device.mgt.common.spi.TraccarManagementService; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig; import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; @@ -90,6 +92,7 @@ public class DeviceManagementDataHolder { private DeviceAPIClientService deviceAPIClientService; private MetadataManagementService metadataManagementService; private WhiteLabelManagementService whiteLabelManagementService; + private TraccarManagementService traccarManagementService; private final Map deviceStatusTaskPluginConfigs = Collections.synchronizedMap( new HashMap<>()); @@ -357,7 +360,7 @@ public class DeviceManagementDataHolder { OperationTimeoutTaskManagerService operationTimeoutTaskManagerService) { this.operationTimeoutTaskManagerService = operationTimeoutTaskManagerService; } - + public DeviceAPIClientService getDeviceAPIClientService() { return deviceAPIClientService; } @@ -381,4 +384,20 @@ public class DeviceManagementDataHolder { public void setWhiteLabelManagementService(WhiteLabelManagementService whiteLabelManagementService) { this.whiteLabelManagementService = whiteLabelManagementService; } + + public TraccarManagementService getTraccarManagementService() { + TraccarManagementService traccarManagementService; + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + traccarManagementService = (TraccarManagementService) ctx.getOSGiService( + TraccarManagementService.class, null); + if (traccarManagementService == null) { + String msg = "Traccar management service not initialized."; + throw new IllegalStateException(msg); + } + return traccarManagementService; + } + + public void setTraccarManagementService(TraccarManagementService traccarManagementService) { + this.traccarManagementService = traccarManagementService; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/WhiteLabelManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/WhiteLabelManagementServiceImpl.java index ec2bca767e0..79e0c7ec017 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/WhiteLabelManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/WhiteLabelManagementServiceImpl.java @@ -26,7 +26,6 @@ import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; -import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Base64File; import org.wso2.carbon.device.mgt.common.FileResponse; @@ -329,10 +328,6 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ } finally { MetadataManagementDAOFactory.closeConnection(); } - } catch (NotFoundException e) { - String msg = "Error occurred while retrieving existing white label theme"; - log.error(msg, e); - throw new MetadataManagementException(msg, e); } catch (DeviceManagementException e) { String msg = "Error occurred while getting tenant details of white label"; log.error(msg, e); @@ -429,20 +424,36 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ } @Override - public WhiteLabelTheme getWhiteLabelTheme(String tenantDomain) throws MetadataManagementException, NotFoundException, DeviceManagementException { + public WhiteLabelTheme getWhiteLabelTheme(String tenantDomain) throws MetadataManagementException, DeviceManagementException { int tenantId = DeviceManagerUtil.getTenantId(tenantDomain); if (log.isDebugEnabled()) { log.debug("Retrieving whitelabel theme for tenant: " + tenantId); } - try { - MetadataManagementDAOFactory.openConnection(); - Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.WHITELABEL_META_KEY); + Metadata metadata = getWhiteLabelMetaData(tenantId); + if (metadata == null) { + addDefaultWhiteLabelThemeIfNotExist(tenantId); + metadata = getWhiteLabelMetaData(tenantId); if (metadata == null) { - String msg = "Whitelabel theme not found for tenant: " + tenantId; + String msg = "Whitelabel theme not found for tenant: " + tenantId + ". Further, Default White Label " + + "Theming Adding step failed."; log.error(msg); - throw new NotFoundException(msg); + throw new MetadataManagementException(msg); } - return new Gson().fromJson(metadata.getMetaValue(), WhiteLabelTheme.class); + } + return new Gson().fromJson(metadata.getMetaValue(), WhiteLabelTheme.class); + } + + /** + * Load White label Meta Data for given tenant Id. + * @param tenantId Id of the tenant + * @return {@link Metadata} + * @throws MetadataManagementException if an error occurred while getting Meta-Data info from Database for a + * given tenant ID. + */ + private Metadata getWhiteLabelMetaData (int tenantId) throws MetadataManagementException { + try { + MetadataManagementDAOFactory.openConnection(); + return metadataDAO.getMetadata(tenantId, MetadataConstants.WHITELABEL_META_KEY); } catch (MetadataManagementDAOException e) { String msg = "Error occurred while retrieving white label theme for tenant:" + tenantId; log.error(msg, e); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/dao/OTPManagementDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/dao/OTPManagementDAO.java index 44bb2a3064f..58a4e54f3ea 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/dao/OTPManagementDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/dao/OTPManagementDAO.java @@ -54,6 +54,9 @@ public interface OTPManagementDAO { */ void renewOneTimeToken(int id, String oneTimeToken) throws OTPManagementDAOException; + void restoreOneTimeToken(int id, String oneTimeToken) throws OTPManagementDAOException; + + /** * To veify whether email and email type exists or not * @param email email @@ -62,4 +65,7 @@ public interface OTPManagementDAO { * @throws OTPManagementDAOException if error occurred while verify existance of the email and email type */ boolean isEmailExist (String email, String emailType) throws OTPManagementDAOException; + + OneTimePinDTO getOtpDataByEmailAndMailType(String email, String emailType) throws OTPManagementDAOException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/dao/impl/GenericOTPManagementDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/dao/impl/GenericOTPManagementDAOImpl.java index 58b55197a06..574d6e7904b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/dao/impl/GenericOTPManagementDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/dao/impl/GenericOTPManagementDAOImpl.java @@ -204,6 +204,41 @@ public class GenericOTPManagementDAOImpl extends AbstractDAOImpl implements OTPM } } + public void restoreOneTimeToken(int id, String oneTimeToken) throws OTPManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to update an OTP data entry for OTP"); + log.debug("OTP Details : OTP key : " + oneTimeToken ); + } + + String sql = "UPDATE DM_OTP_DATA " + + "SET " + + "OTP_TOKEN = ?, " + + "CREATED_AT = ?, " + + "IS_EXPIRED = false " + + "WHERE ID = ?"; + + try { + Connection conn = this.getDBConnection(); + Calendar calendar = Calendar.getInstance(); + Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, oneTimeToken); + stmt.setTimestamp(2, timestamp); + stmt.setInt(3, id); + stmt.executeUpdate(); + } + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the DB connection to update the OTP token."; + log.error(msg, e); + throw new OTPManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred when executing sql query to update the OTP token."; + log.error(msg, e); + throw new OTPManagementDAOException(msg, e); + } + } + + @Override public boolean isEmailExist (String email, String emailType) throws OTPManagementDAOException { @@ -239,4 +274,62 @@ public class GenericOTPManagementDAOImpl extends AbstractDAOImpl implements OTPM throw new OTPManagementDAOException(msg, e); } } + + @Override + public OneTimePinDTO getOtpDataByEmailAndMailType(String email, String emailType) throws OTPManagementDAOException { + + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to verify whether email was registed with emai type in OTP"); + log.debug("OTP Details : email : " + email + " email type: " + emailType ); + } + + String sql = "SELECT " + + "ID, " + + "OTP_TOKEN, " + + "EMAIL, " + + "EMAIL_TYPE, " + + "META_INFO, " + + "CREATED_AT, " + + "EXPIRY_TIME, " + + "IS_EXPIRED, " + + "TENANT_ID, " + + "USERNAME " + + "FROM DM_OTP_DATA " + + "WHERE EMAIL = ? AND " + + "EMAIL_TYPE = ?"; + + try { + Connection conn = this.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, email); + stmt.setString(2, emailType); + try (ResultSet rs = stmt.executeQuery()) { + if (rs.next()) { + OneTimePinDTO oneTimePinDTO = new OneTimePinDTO(); + oneTimePinDTO.setId(rs.getInt("ID")); + oneTimePinDTO.setOtpToken(rs.getString("OTP_TOKEN")); + oneTimePinDTO.setEmail(rs.getString("EMAIL")); + oneTimePinDTO.setEmailType(rs.getString("EMAIL_TYPE")); + oneTimePinDTO.setMetaInfo(rs.getString("META_INFO")); + oneTimePinDTO.setCreatedAt(rs.getTimestamp("CREATED_AT")); + oneTimePinDTO.setExpiryTime(rs.getInt("EXPIRY_TIME")); + oneTimePinDTO.setExpired(rs.getBoolean("IS_EXPIRED")); + oneTimePinDTO.setTenantId(rs.getInt("TENANT_ID")); + oneTimePinDTO.setUsername(rs.getString("USERNAME")); + return oneTimePinDTO; + } + return null; } + } + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the DB connection to verify email and email type exist in OTP." + + " Email: " + email + "Email Type: " + emailType; + log.error(msg, e); + throw new OTPManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while executing SQL to verify email and email type exist in OTP. Email: " + + email + "Email Type: " + emailType; + log.error(msg, e); + throw new OTPManagementDAOException(msg, e); + } + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java index 1417dae501c..4c8161e100b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java @@ -20,7 +20,6 @@ import com.google.gson.Gson; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException; import org.wso2.carbon.device.mgt.common.exceptions.BadRequestException; @@ -28,42 +27,32 @@ import org.wso2.carbon.device.mgt.common.exceptions.DBConnectionException; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.exceptions.OTPManagementException; import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; -import org.wso2.carbon.device.mgt.common.exceptions.UnAuthorizedException; import org.wso2.carbon.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitation; import org.wso2.carbon.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitationDetails; import org.wso2.carbon.device.mgt.common.invitation.mgt.DeviceEnrollmentType; -import org.wso2.carbon.device.mgt.common.metadata.mgt.Metadata; import org.wso2.carbon.device.mgt.common.otp.mgt.OTPEmailTypes; import org.wso2.carbon.device.mgt.common.otp.mgt.dto.OneTimePinDTO; -import org.wso2.carbon.device.mgt.common.otp.mgt.wrapper.DownloadURLDetails; import org.wso2.carbon.device.mgt.common.spi.OTPManagementService; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; -import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; -import org.wso2.carbon.device.mgt.core.config.keymanager.KeyManagerConfigurations; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.otp.mgt.dao.OTPManagementDAO; -import org.wso2.carbon.device.mgt.common.otp.mgt.wrapper.OTPWrapper; import org.wso2.carbon.device.mgt.core.otp.mgt.dao.OTPManagementDAOFactory; import org.wso2.carbon.device.mgt.core.otp.mgt.exception.OTPManagementDAOException; import org.wso2.carbon.device.mgt.core.otp.mgt.util.ConnectionManagerUtil; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo; -import org.apache.commons.validator.routines.EmailValidator; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.user.api.Tenant; import org.wso2.carbon.user.api.UserStoreException; -import static org.wso2.carbon.device.mgt.common.DeviceManagementConstants.OTPProperties; - import java.sql.Timestamp; +import java.util.ArrayList; import java.util.Calendar; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.UUID; -import java.util.ArrayList; -import java.util.Collections; public class OTPManagementServiceImpl implements OTPManagementService { @@ -79,60 +68,61 @@ public class OTPManagementServiceImpl implements OTPManagementService { } @Override - public String sendUserVerifyingMail(OTPWrapper otpWrapper) throws OTPManagementException, DeviceManagementException { - Tenant tenant = validateTenantCreatingDetails(otpWrapper); - OneTimePinDTO oneTimePinDTO = createOneTimePin(otpWrapper.getEmail(), otpWrapper.getEmailType(), - otpWrapper.getUsername(), tenant, -1234); + public boolean hasEmailRegistered(String email, String emailDomain) throws OTPManagementException, + DeviceManagementException { + try { + ConnectionManagerUtil.openDBConnection(); + if (otpManagementDAO.isEmailExist(email, emailDomain)) { + return true; + } + } catch (DBConnectionException e) { + String msg = "Error occurred while getting database connection to validate the given email and email type."; + log.error(msg); + throw new DeviceManagementException(msg); + } catch (OTPManagementDAOException e) { + String msg = "Error occurred while executing SQL query to validate the given email and email type."; + log.error(msg); + throw new OTPManagementException(msg); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + return false; + } + + public OneTimePinDTO getRenewedOtpByEmailAndMailType(String email, String emailType) throws OTPManagementException{ + OneTimePinDTO oneTimePinDTO; + String newToken = UUID.randomUUID().toString(); try { ConnectionManagerUtil.beginDBTransaction(); - this.otpManagementDAO.addOTPData(Collections.singletonList(oneTimePinDTO)); -// Properties props = new Properties(); -// props.setProperty("first-name", tenant.getAdminFirstName()); -// props.setProperty("otp-token", oneTimePinDTO.getOtpToken()); -// sendMail(props, tenant.getEmail(), DeviceManagementConstants.EmailAttributes.USER_VERIFY_TEMPLATE); + oneTimePinDTO = otpManagementDAO.getOtpDataByEmailAndMailType(email, emailType); + if (oneTimePinDTO == null) { + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = "Can't find OTP data for email: " + email + " and email type: " + emailType; + log.error(msg); + throw new OTPManagementException(msg); + } + otpManagementDAO.restoreOneTimeToken(oneTimePinDTO.getId(), newToken); ConnectionManagerUtil.commitDBTransaction(); - return oneTimePinDTO.getOtpToken(); - } catch (TransactionManagementException e) { - String msg = "Error occurred while disabling AutoCommit."; - log.error(msg, e); - throw new OTPManagementException(msg, e); + } catch (DBConnectionException e) { - String msg = "Error occurred while getting database connection to add OPT data."; + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = "Error occurred while getting database connection to validate the given email and email type."; log.error(msg, e); throw new OTPManagementException(msg, e); } catch (OTPManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occurred while saving the OTP data for given email" ; + String msg = "Error occurred while executing SQL query to validate the given email and email type."; + log.error(msg, e); + throw new OTPManagementException(msg); + } catch (TransactionManagementException e) { + String msg = "Error occurred while starting the DB transaction"; log.error(msg, e); throw new OTPManagementException(msg, e); } finally { ConnectionManagerUtil.closeDBConnection(); } - } - - @Override - public void shareProductDownloadUrl(DownloadURLDetails downloadURLDetails) throws OTPManagementException { - if (StringUtils.isBlank(downloadURLDetails.getURL())) { - String msg = "Couldn't find the download URL with the request."; - log.error(msg); - throw new OTPManagementException(msg); - } - if (StringUtils.isBlank(downloadURLDetails.getFirstName())) { - String msg = "Couldn't find the First Name with the request."; - log.error(msg); - throw new OTPManagementException(msg); - } - if (StringUtils.isBlank(downloadURLDetails.getEmail())) { - String msg = "Couldn't find the e-mail address with the request."; - log.error(msg); - throw new OTPManagementException(msg); - } - - Properties props = new Properties(); - props.setProperty("first-name", downloadURLDetails.getFirstName()); - props.setProperty("download-url", downloadURLDetails.getURL()); - sendMail(props, downloadURLDetails.getEmail(), - DeviceManagementConstants.EmailAttributes.PRODUCT_DOWNLOAD_LINK_SHARING_TEMPLATE); + oneTimePinDTO.setOtpToken(newToken); + return oneTimePinDTO; } @Override @@ -157,7 +147,7 @@ public class OTPManagementServiceImpl implements OTPManagementService { Calendar calendar = Calendar.getInstance(); Timestamp currentTimestamp = new Timestamp(calendar.getTime().getTime()); Timestamp expiredTimestamp = new Timestamp( - oneTimePinDTO.getCreatedAt().getTime() + oneTimePinDTO.getExpiryTime() * 1000); + oneTimePinDTO.getCreatedAt().getTime() + oneTimePinDTO.getExpiryTime() * 1000L); if (currentTimestamp.after(expiredTimestamp)) { String renewedOTP = UUID.randomUUID().toString(); @@ -168,6 +158,8 @@ public class OTPManagementServiceImpl implements OTPManagementService { Properties props = new Properties(); props.setProperty("first-name", tenant.getAdminFirstName()); props.setProperty("otp-token", renewedOTP); + props.setProperty("email", oneTimePinDTO.getEmail()); + props.setProperty("type", oneTimePinDTO.getEmailType()); sendMail(props, oneTimePinDTO.getEmail(), DeviceManagementConstants.EmailAttributes.USER_VERIFY_TEMPLATE); return null; } @@ -233,7 +225,7 @@ public class OTPManagementServiceImpl implements OTPManagementService { deviceEnrollmentInvitationDetails = dms.getDeviceEnrollmentInvitationDetails( deviceEnrollmentType.getDeviceType()); if (deviceEnrollmentInvitationDetails != null && - deviceEnrollmentInvitationDetails.getEnrollmentDetails() != null) { + deviceEnrollmentInvitationDetails.getEnrollmentDetails() != null) { for (String enrollmentType : deviceEnrollmentType.getEnrollmentType()) { deviceEnrollmentInvitationDetails.getEnrollmentDetails().stream() .filter(details -> enrollmentType.equals(details.getEnrollmentType())).findFirst() @@ -251,8 +243,8 @@ public class OTPManagementServiceImpl implements OTPManagementService { for (String username : deviceEnrollmentInvitation.getUsernames()) { String emailAddress = DeviceManagerUtil.getUserClaimValue( username, DeviceManagementConstants.User.CLAIM_EMAIL_ADDRESS); - oneTimePinDTO = createOneTimePin(emailAddress, OTPEmailTypes.DEVICE_ENROLLMENT.toString(), username, - null, tenantId); + oneTimePinDTO = generateOneTimePin(emailAddress, OTPEmailTypes.DEVICE_ENROLLMENT.toString(), username, + null, tenantId, false); oneTimePinDTOList.add(oneTimePinDTO); props.setProperty("first-name", DeviceManagerUtil. getUserClaimValue(username, DeviceManagementConstants.User.CLAIM_FIRST_NAME)); @@ -284,7 +276,6 @@ public class OTPManagementServiceImpl implements OTPManagementService { } } - /** * Create One Time Token * @param email email @@ -294,8 +285,9 @@ public class OTPManagementServiceImpl implements OTPManagementService { * @param tenantId tenant Id * @return {@link OneTimePinDTO} */ - private OneTimePinDTO createOneTimePin(String email, String emailType, String userName, Object metaDataObj, - int tenantId) { + @Override + public OneTimePinDTO generateOneTimePin(String email, String emailType, String userName, Object metaDataObj, + int tenantId, boolean persistPin) throws OTPManagementException { String otpValue = UUID.randomUUID().toString(); @@ -310,6 +302,28 @@ public class OTPManagementServiceImpl implements OTPManagementService { oneTimePinDTO.setMetaInfo(metaInfo); oneTimePinDTO.setOtpToken(otpValue); + if (persistPin) { + try { + ConnectionManagerUtil.beginDBTransaction(); + this.otpManagementDAO.addOTPData(Collections.singletonList(oneTimePinDTO)); + ConnectionManagerUtil.commitDBTransaction(); + } catch (TransactionManagementException e) { + String msg = "Error occurred while disabling AutoCommit."; + log.error(msg, e); + throw new OTPManagementException(msg, e); + } catch (DBConnectionException e) { + String msg = "Error occurred while getting database connection to add OPT data."; + log.error(msg, e); + throw new OTPManagementException(msg, e); + } catch (OTPManagementDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = "Error occurred while saving the OTP data for given email" ; + log.error(msg, e); + throw new OTPManagementException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } return oneTimePinDTO; } @@ -319,7 +333,7 @@ public class OTPManagementServiceImpl implements OTPManagementService { * @return {@link OneTimePinDTO} * @throws OTPManagementException if error occurred while getting OTP data for given OTP in DB */ - private OneTimePinDTO getOTPDataByToken ( String oneTimeToken) throws OTPManagementException { + private OneTimePinDTO getOTPDataByToken (String oneTimeToken) throws OTPManagementException { try { ConnectionManagerUtil.openDBConnection(); return otpManagementDAO.getOTPDataByToken(oneTimeToken); @@ -336,121 +350,6 @@ public class OTPManagementServiceImpl implements OTPManagementService { } } - /** - * Validate Tenant details - * @param otpWrapper OTP-Wrapper - * @return {@link Tenant} if its valid payload otherwise throws {@link DeviceManagementException} - * @throws DeviceManagementException if invalid payload or unauthorized request received - */ - private Tenant validateTenantCreatingDetails(OTPWrapper otpWrapper) throws DeviceManagementException { - - DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance() - .getDeviceManagementConfig(); - KeyManagerConfigurations kmConfig = deviceManagementConfig.getKeyManagerConfigurations(); - - if (StringUtils.isBlank(otpWrapper.getUsername())) { - String msg = "Received Blank username to create OTP. Username: " + otpWrapper.getUsername(); - log.error(msg); - throw new BadRequestException(msg); - } - - String[] superTenantDetails = otpWrapper.getUsername().split("@"); - if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(superTenantDetails[superTenantDetails.length - 1]) - || !superTenantDetails[0].equals(kmConfig.getAdminUsername())) { - String msg = "You don't have required permission to create OTP"; - log.error(msg); - throw new UnAuthorizedException(msg); - } - - Tenant tenant = new Tenant(); - List properties = otpWrapper.getProperties(); - for (Metadata property : properties) { - if (property == null) { - String msg = "Received invalid property to create OTP."; - log.error(msg); - throw new BadRequestException(msg); - } - switch (property.getMetaKey()) { - case OTPProperties.FIRST_NAME: - String firstName = property.getMetaValue(); - if (StringUtils.isBlank(firstName)) { - String msg = "Received empty or blank first name field with OTP creating payload."; - log.error(msg); - throw new BadRequestException(msg); - } - tenant.setAdminFirstName(firstName); - break; - case OTPProperties.LAST_NAME: - String lastName = property.getMetaValue(); - if (StringUtils.isBlank(lastName)) { - String msg = "Received empty or blank last name field with OTP creating payload."; - log.error(msg); - throw new BadRequestException(msg); - } - tenant.setAdminLastName(lastName); - break; - case OTPProperties.TENANT_ADMIN_PASSWORD: - String pwd = property.getMetaValue(); - if (StringUtils.isBlank(pwd)) { - String msg = "Received empty or blank admin password field with OTP creating payload."; - log.error(msg); - throw new BadRequestException(msg); - } - tenant.setAdminPassword(pwd); - break; - default: - String msg = "Received invalid key with OTP properties for creating OTP."; - log.error(msg); - throw new BadRequestException(msg); - } - } - - if (StringUtils.isBlank(otpWrapper.getEmail())) { - String msg = "Received empty or blank email field with OTP creating payload."; - log.error(msg); - throw new BadRequestException(msg); - } - - EmailValidator validator = EmailValidator.getInstance(); - if (!validator.isValid(otpWrapper.getEmail())) { - String msg = "Found invalid email. Hence please verify the email address and re-try. Email: " + otpWrapper - .getEmail(); - log.error(msg); - throw new BadRequestException(msg); - } - - if (StringUtils.isBlank(otpWrapper.getEmailType())) { - String msg = "Received empty or blank email type field with OTP creating payload."; - log.error(msg); - throw new BadRequestException(msg); - } - - try { - ConnectionManagerUtil.openDBConnection(); - if (otpManagementDAO.isEmailExist(otpWrapper.getEmail(), otpWrapper.getEmailType())) { - String msg = "Email is registered to execute the same action. Hence can't proceed."; - log.error(msg); - throw new BadRequestException(msg); - } - } catch (DBConnectionException e) { - String msg = "Error occurred while getting database connection to validate the given email and email type."; - log.error(msg); - throw new DeviceManagementException(msg); - } catch (OTPManagementDAOException e) { - String msg = "Error occurred while executing SQL query to validate the given email and email type."; - log.error(msg); - throw new DeviceManagementException(msg); - } finally { - ConnectionManagerUtil.closeDBConnection(); - } - - String[] tenantUsernameDetails = otpWrapper.getEmail().split("@"); - tenant.setAdminName(tenantUsernameDetails[0]); - tenant.setDomain(tenantUsernameDetails[tenantUsernameDetails.length - 1]); - tenant.setEmail(otpWrapper.getEmail()); - return tenant; - } - /** * If OTP expired, resend the user verifying mail with renewed OTP * @param props Mail body properties @@ -502,4 +401,4 @@ public class OTPManagementServiceImpl implements OTPManagementService { ConnectionManagerUtil.closeDBConnection(); } } -} +} \ No newline at end of file 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 6257e0b34d2..d3363717ada 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 @@ -48,6 +48,7 @@ import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.protocol.HTTP; +import org.opensaml.xmlsec.signature.P; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; @@ -433,23 +434,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv //enroll Traccar device if (HttpReportingUtil.isTrackerEnabled()) { - try { - DeviceManagementDataHolder.getInstance().getDeviceAPIClientService().addDevice(device, tenantId); - } catch (ExecutionException e) { - log.error("ExecutionException : " + e); - //throw new RuntimeException(e); - //Exception was not thrown due to being conflicted with non-traccar features - } catch (InterruptedException e) { - log.error("InterruptedException : " + e); - //throw new RuntimeException(e); - //Exception was not thrown due to being conflicted with non-traccar features - } + DeviceManagementDataHolder.getInstance().getTraccarManagementService().addDevice(device); } else { if (log.isDebugEnabled()) { log.debug("Traccar is disabled"); } } - //enroll Traccar device if (status) { addDeviceToGroups(deviceIdentifier, device.getEnrolmentInfo().getOwnership()); @@ -534,24 +524,13 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv extractDeviceLocationToUpdate(device); //enroll Traccar device if (HttpReportingUtil.isTrackerEnabled()) { - try { - int tenantId = this.getTenantId(); - DeviceManagementDataHolder.getInstance().getDeviceAPIClientService().modifyDevice(device, tenantId); - } catch (ExecutionException e) { - log.error("ExecutionException : " + e); - //throw new RuntimeException(e); - //Exception was not thrown due to being conflicted with non-traccar features - } catch (InterruptedException e) { - log.error("InterruptedException : " + e); - //throw new RuntimeException(e); - //Exception was not thrown due to being conflicted with non-traccar features - } + DeviceManagementDataHolder.getInstance().getTraccarManagementService().updateDevice(device); } else { if (log.isDebugEnabled()) { log.debug("Traccar is disabled"); } } - //enroll Traccar device + return status; } @@ -635,8 +614,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv //procees to dis-enroll a device from traccar starts if (HttpReportingUtil.isTrackerEnabled()) { - DeviceManagementDataHolder.getInstance().getDeviceAPIClientService() - .disEnrollDevice(device.getId(), tenantId); + DeviceManagementDataHolder.getInstance().getTraccarManagementService().unLinkTraccarDevice(device.getEnrolmentInfo().getId()); + } else { + if (log.isDebugEnabled()) { + log.debug("Traccar is disabled"); + } } //procees to dis-enroll a device from traccar ends @@ -756,6 +738,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv if (log.isDebugEnabled()) { log.debug("Successfully permanently deleted the details of devices : " + validDeviceIdentifiers); } + if (HttpReportingUtil.isTrackerEnabled()) { + for (int enrollmentId : enrollmentIds) { + DeviceManagementDataHolder.getInstance().getTraccarManagementService().removeDevice(enrollmentId); + } + } else { + if (log.isDebugEnabled()) { + log.debug("Traccar is disabled"); + } + } return true; } catch (TransactionManagementException e) { String msg = "Error occurred while initiating transaction"; 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 9981333428d..1881aeed55e 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 @@ -132,27 +132,8 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid this.groupDAO.addGroupProperties(deviceGroup, updatedGroupID, tenantId); } GroupManagementDAOFactory.commitTransaction(); - - //add new group in traccar - if (HttpReportingUtil.isTrackerEnabled()) { - DeviceManagementDataHolder.getInstance().getDeviceAPIClientService() - .addGroup(deviceGroup, updatedGroupID, tenantId); - } - //add new group in traccar } else { - // add a group if not exist in traccar starts - if (HttpReportingUtil.isTrackerEnabled()){ - existingGroup = this.groupDAO.getGroup(deviceGroup.getName(), tenantId); - int groupId = existingGroup.getGroupId(); - try { - DeviceManagementDataHolder.getInstance().getDeviceAPIClientService() - .addGroup(deviceGroup, groupId, tenantId); - } catch (TrackerAlreadyExistException e) { - throw new GroupAlreadyExistException("Group exist with name " + deviceGroup.getName()); - } - } else { - throw new GroupAlreadyExistException("Group exist with name " + deviceGroup.getName()); - } + throw new GroupAlreadyExistException("Group exist with name " + deviceGroup.getName()); } } catch (GroupManagementDAOException e) { GroupManagementDAOFactory.rollbackTransaction(); @@ -234,13 +215,6 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid this.groupDAO.updateGroupProperties(deviceGroup, groupId, tenantId); } - //procees to update a group in traccar starts - if (HttpReportingUtil.isTrackerEnabled()) { - DeviceManagementDataHolder.getInstance().getDeviceAPIClientService() - .updateGroup(deviceGroup, groupId, tenantId); - } - //procees to update a group in traccar starts - GroupManagementDAOFactory.commitTransaction(); } else { throw new GroupNotExistException("Group with ID - '" + groupId + "' doesn't exists!"); @@ -300,21 +274,6 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid } } - //procees to delete a group from traccar starts - if (HttpReportingUtil.isTrackerEnabled()) { - try { - DeviceManagementDataHolder.getInstance().getDeviceAPIClientService() - .deleteGroup(groupId, tenantId); - } catch (TrackerManagementDAOException e) { - String msg = "Failed while deleting traccar group " + groupId; - log.error(msg, e); - } catch (ExecutionException | InterruptedException e) { - String msg = "Failed while deleting traccar group "+groupId+" due to concurrent execution failure"; - log.error(msg, e); - } - } - //procees to delete a group from traccar ends - if (isDeleteChildren) { groupIdsToDelete.add(groupId); groupDAO.deleteGroupsMapping(groupIdsToDelete, tenantId); 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 a7be85cc99e..2a420a91ef4 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 - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml index 65d76a4ce82..a110b174ac0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml @@ -23,7 +23,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/pom.xml b/components/device-mgt/pom.xml index 33b9d79a2d2..251617c2372 100644 --- a/components/device-mgt/pom.xml +++ b/components/device-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml index 675795d5513..08e44848251 100644 --- a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml +++ b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt heartbeat-management - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/heartbeat-management/pom.xml b/components/heartbeat-management/pom.xml index 0c11fed91d3..a35a88f848f 100644 --- a/components/heartbeat-management/pom.xml +++ b/components/heartbeat-management/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml index 79bd49ff21a..699a82cc62c 100644 --- a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml +++ b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt identity-extensions - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml b/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml index 58c581c51a6..190eabc7851 100644 --- a/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml +++ b/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt identity-extensions - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/identity-extensions/pom.xml b/components/identity-extensions/pom.xml index f5f8d9e4f68..a217060c943 100644 --- a/components/identity-extensions/pom.xml +++ b/components/identity-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/components/logger/io.entgra.notification.logger/pom.xml b/components/logger/io.entgra.notification.logger/pom.xml index b0e30a6d4bb..4cafda1771f 100644 --- a/components/logger/io.entgra.notification.logger/pom.xml +++ b/components/logger/io.entgra.notification.logger/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt logger - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT io.entgra.notification.logger diff --git a/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/UserLogContext.java b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/UserLogContext.java index 13702d570b8..49f8d0f189d 100644 --- a/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/UserLogContext.java +++ b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/UserLogContext.java @@ -25,12 +25,18 @@ public class UserLogContext extends LogContext { private final String userEmail; private final String metaInfo; private final String tenantID; + private final boolean isUserRegistered; + private final boolean isDeviceRegisterged; + private final String tenantDomain; private UserLogContext(Builder builder) { this.userEmail = builder.userEmail; this.userName = builder.userName; this.metaInfo = builder.metaInfo; this.tenantID = builder.tenantID; + this.isUserRegistered = builder.isUserRegistered; + this.isDeviceRegisterged = builder.isDeviceRegisterged; + this.tenantDomain = builder.tenantDomain; } public String getTenantID() { @@ -49,12 +55,26 @@ public class UserLogContext extends LogContext { return metaInfo; } + public boolean isUserRegistered() { + return isUserRegistered; + } + + public boolean isDeviceRegisterged() { + return isDeviceRegisterged; + } + + public String getTenantDomain() { + return tenantDomain; + } public static class Builder { private String userName; private String userEmail; private String metaInfo; private String tenantID; + private boolean isUserRegistered; + private boolean isDeviceRegisterged; + private String tenantDomain; public Builder() { } @@ -95,6 +115,33 @@ public class UserLogContext extends LogContext { return this; } + public boolean getIsUserRegistered() { + return isUserRegistered; + } + + public Builder setUserRegistered(boolean userRegistered) { + isUserRegistered = userRegistered; + return this; + } + + public boolean getIsDeviceRegisterged() { + return isDeviceRegisterged; + } + + public Builder setDeviceRegisterged(boolean deviceRegisterged) { + isDeviceRegisterged = deviceRegisterged; + return this; + } + + public String getTenantDomain() { + return tenantDomain; + } + + public Builder setTenantDomain(String tenantDomain) { + this.tenantDomain = tenantDomain; + return this; + } + public UserLogContext build() { return new UserLogContext(this); } diff --git a/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/util/MDCContextUtil.java b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/util/MDCContextUtil.java index fd78c26dba3..7db6830a1a5 100644 --- a/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/util/MDCContextUtil.java +++ b/components/logger/io.entgra.notification.logger/src/main/java/io/entgra/notification/logger/util/MDCContextUtil.java @@ -51,6 +51,16 @@ public final class MDCContextUtil { if (mdcContext.getTenantID() != null) { MDC.put("TenantId", mdcContext.getTenantID()); } + if (mdcContext.isUserRegistered()) { + MDC.put("IsUserRegistered", "Registered"); + } + if (mdcContext.isDeviceRegisterged()) { + MDC.put("IsDeviceRegistered", mdcContext.isDeviceRegisterged()); + } + if (mdcContext.getTenantDomain() != null) { + MDC.put("TenantDomain", mdcContext.getTenantDomain()); + } + } } diff --git a/components/logger/pom.xml b/components/logger/pom.xml index bc0f814449f..6ca86be582e 100644 --- a/components/logger/pom.xml +++ b/components/logger/pom.xml @@ -22,7 +22,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml index d35d3b55904..82dc852bed7 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml @@ -3,7 +3,7 @@ org.wso2.carbon.devicemgt policy-mgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml index 63bf49d90e3..290b78bee65 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml @@ -3,7 +3,7 @@ org.wso2.carbon.devicemgt policy-mgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml index ad871a76f38..06d4ec3256c 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt policy-mgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java index 591761db5f1..5c12cead8d1 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java @@ -19,6 +19,7 @@ package org.wso2.carbon.policy.mgt.common; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DynamicTaskContext; +import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; import org.wso2.carbon.device.mgt.common.policy.mgt.Profile; @@ -164,5 +165,12 @@ public interface PolicyAdministratorPoint { */ List getPolicies(String policyType) throws PolicyManagementException; - List getPolicyList() throws PolicyManagementException; + /** + * Returns a list of policies filtered by offset and limit + * @param request {@link PaginationRequest} contains offset and limit + * @return {@link List} - list of policies for current tenant + * @throws PolicyManagementException when there is an error while retrieving the policies from database or + * while retrieving device groups + */ + List getPolicyList(PaginationRequest request) throws PolicyManagementException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml index 00861dea8bf..715349438d0 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt policy-mgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java index 20b53f81a99..c5ae7c0a522 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java @@ -36,6 +36,7 @@ package org.wso2.carbon.policy.mgt.core.dao; import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.policy.mgt.CorrectiveAction; import org.wso2.carbon.policy.mgt.common.Criterion; import org.wso2.carbon.device.mgt.common.policy.mgt.DeviceGroupWrapper; @@ -214,4 +215,13 @@ public interface PolicyDAO { HashMap getAppliedPolicyIdsDeviceIds() throws PolicyManagerDAOException; List getAllPolicies(String policyType) throws PolicyManagerDAOException; + + /** + * This method is used to retrieve policies from the database based on the offset and limit + * sent through the PaginationRequest + * @param request {@link PaginationRequest} contains offset and limit + * @return {@link List} - list of policies for current tenant + * @throws PolicyManagerDAOException when there is an error while retrieving the policies from database + */ + List getAllPolicies(PaginationRequest request) throws PolicyManagerDAOException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagementDAOFactory.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagementDAOFactory.java index 78d5434d01e..a0a83c454d9 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagementDAOFactory.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagementDAOFactory.java @@ -26,11 +26,14 @@ import org.wso2.carbon.device.mgt.common.exceptions.UnsupportedDatabaseEngineExc import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.policy.mgt.core.config.datasource.JNDILookupDefinition; import org.wso2.carbon.policy.mgt.core.dao.impl.MonitoringDAOImpl; -import org.wso2.carbon.policy.mgt.core.dao.impl.PolicyDAOImpl; import org.wso2.carbon.policy.mgt.core.dao.impl.ProfileDAOImpl; import org.wso2.carbon.policy.mgt.core.dao.impl.feature.GenericFeatureDAOImpl; import org.wso2.carbon.policy.mgt.core.dao.impl.feature.OracleServerFeatureDAOImpl; import org.wso2.carbon.policy.mgt.core.dao.impl.feature.SQLServerFeatureDAOImpl; +import org.wso2.carbon.policy.mgt.core.dao.impl.policy.GenericPolicyDAOImpl; +import org.wso2.carbon.policy.mgt.core.dao.impl.policy.OraclePolicyDAOImpl; +import org.wso2.carbon.policy.mgt.core.dao.impl.policy.PostgreSQLPolicyDAOImpl; +import org.wso2.carbon.policy.mgt.core.dao.impl.policy.SQLServerPolicyDAOImpl; import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil; import javax.sql.DataSource; @@ -65,7 +68,22 @@ public class PolicyManagementDAOFactory { } public static PolicyDAO getPolicyDAO() { - return new PolicyDAOImpl(); + if (databaseEngine != null) { + switch (databaseEngine) { + case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MSSQL: + return new SQLServerPolicyDAOImpl(); + case DeviceManagementConstants.DataBaseTypes.DB_TYPE_ORACLE: + return new OraclePolicyDAOImpl(); + case DeviceManagementConstants.DataBaseTypes.DB_TYPE_POSTGRESQL: + return new PostgreSQLPolicyDAOImpl(); + case DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2: + case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL: + return new GenericPolicyDAOImpl(); + default: + throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); + } + } + throw new IllegalStateException("Database engine has not initialized properly."); } public static ProfileDAO getProfileDAO() { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/policy/AbstractPolicyDAOImpl.java similarity index 99% rename from components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java rename to components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/policy/AbstractPolicyDAOImpl.java index 063b5c47a89..02dc4005780 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/policy/AbstractPolicyDAOImpl.java @@ -33,7 +33,7 @@ * under the License. */ -package org.wso2.carbon.policy.mgt.core.dao.impl; +package org.wso2.carbon.policy.mgt.core.dao.impl.policy; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -66,9 +66,12 @@ import java.util.HashMap; import java.util.List; import java.util.Properties; -public class PolicyDAOImpl implements PolicyDAO { +/** + * Abstract implementation of PolicyDAO which holds generic SQL queries. + */ +public abstract class AbstractPolicyDAOImpl implements PolicyDAO { - private static final Log log = LogFactory.getLog(PolicyDAOImpl.class); + private static final Log log = LogFactory.getLog(AbstractPolicyDAOImpl.class); @Override public Policy addPolicy(Policy policy) throws PolicyManagerDAOException { @@ -1838,7 +1841,7 @@ public class PolicyDAOImpl implements PolicyDAO { } } - private List extractPolicyListFromDbResult(ResultSet resultSet, int tenantId) throws SQLException { + protected List extractPolicyListFromDbResult(ResultSet resultSet, int tenantId) throws SQLException { List policies = new ArrayList<>(); while (resultSet.next()) { Policy policy = new Policy(); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/policy/GenericPolicyDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/policy/GenericPolicyDAOImpl.java new file mode 100644 index 00000000000..d8916c95a95 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/policy/GenericPolicyDAOImpl.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2018 - 2023 Entgra (Pvt) Ltd, Inc - All Rights Reserved. + * + * Unauthorised copying/redistribution of this file, via any medium is strictly prohibited. + * + * Licensed under the Entgra Commercial License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://entgra.io/licenses/entgra-commercial/1.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.policy.mgt.core.dao.impl.policy; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.common.PaginationRequest; +import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; +import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory; +import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +public class GenericPolicyDAOImpl extends AbstractPolicyDAOImpl { + + private static final Log log = LogFactory.getLog(GenericPolicyDAOImpl.class); + + private Connection getConnection() { + return PolicyManagementDAOFactory.getConnection(); + } + + @Override + public List getAllPolicies(PaginationRequest request) throws PolicyManagerDAOException { + Connection conn; + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + + try { + conn = this.getConnection(); + String query = "SELECT * " + + "FROM DM_POLICY " + + "WHERE TENANT_ID = ? " + + "ORDER BY ID LIMIT ?,?"; + + try (PreparedStatement stmt = conn.prepareStatement(query)) { + stmt.setInt(1, tenantId); + stmt.setInt(2, request.getStartIndex()); + stmt.setInt(3, request.getRowCount()); + try (ResultSet resultSet = stmt.executeQuery()) { + return this.extractPolicyListFromDbResult(resultSet, tenantId); + } + } + } catch (SQLException e) { + String msg = "Error occurred while reading the policies from the database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } + } +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/policy/OraclePolicyDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/policy/OraclePolicyDAOImpl.java new file mode 100644 index 00000000000..c8f89a906af --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/policy/OraclePolicyDAOImpl.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2018 - 2023 Entgra (Pvt) Ltd, Inc - All Rights Reserved. + * + * Unauthorised copying/redistribution of this file, via any medium is strictly prohibited. + * + * Licensed under the Entgra Commercial License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://entgra.io/licenses/entgra-commercial/1.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.policy.mgt.core.dao.impl.policy; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.common.PaginationRequest; +import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; +import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory; +import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +public class OraclePolicyDAOImpl extends AbstractPolicyDAOImpl { + private static final Log log = LogFactory.getLog(OraclePolicyDAOImpl.class); + + private Connection getConnection() { + return PolicyManagementDAOFactory.getConnection(); + } + + @Override + public List getAllPolicies(PaginationRequest request) throws PolicyManagerDAOException { + Connection conn; + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + + try { + conn = this.getConnection(); + String query = "SELECT * " + + "FROM DM_POLICY " + + "WHERE TENANT_ID = ? " + + "ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + + try (PreparedStatement stmt = conn.prepareStatement(query)) { + stmt.setInt(1, tenantId); + stmt.setInt(2, request.getStartIndex()); + stmt.setInt(3, request.getRowCount()); + try (ResultSet resultSet = stmt.executeQuery()) { + return this.extractPolicyListFromDbResult(resultSet, tenantId); + } + } + } catch (SQLException e) { + String msg = "Error occurred while reading the policies from the database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } + } +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/policy/PostgreSQLPolicyDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/policy/PostgreSQLPolicyDAOImpl.java new file mode 100644 index 00000000000..afb57d3466b --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/policy/PostgreSQLPolicyDAOImpl.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2018 - 2023 Entgra (Pvt) Ltd, Inc - All Rights Reserved. + * + * Unauthorised copying/redistribution of this file, via any medium is strictly prohibited. + * + * Licensed under the Entgra Commercial License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://entgra.io/licenses/entgra-commercial/1.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.policy.mgt.core.dao.impl.policy; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.common.PaginationRequest; +import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; +import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory; +import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +public class PostgreSQLPolicyDAOImpl extends AbstractPolicyDAOImpl { + private static final Log log = LogFactory.getLog(PostgreSQLPolicyDAOImpl.class); + + private Connection getConnection() { + return PolicyManagementDAOFactory.getConnection(); + } + + @Override + public List getAllPolicies(PaginationRequest request) throws PolicyManagerDAOException { + Connection conn; + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + + try { + conn = this.getConnection(); + String query = "SELECT * " + + "FROM DM_POLICY " + + "WHERE TENANT_ID = ? " + + "ORDER BY ID LIMIT ? OFFSET ?"; + + try (PreparedStatement stmt = conn.prepareStatement(query)) { + stmt.setInt(1, tenantId); + stmt.setInt(2, request.getRowCount()); + stmt.setInt(3, request.getStartIndex()); + try (ResultSet resultSet = stmt.executeQuery()) { + return this.extractPolicyListFromDbResult(resultSet, tenantId); + } + } + } catch (SQLException e) { + String msg = "Error occurred while reading the policies from the database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } + } +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/policy/SQLServerPolicyDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/policy/SQLServerPolicyDAOImpl.java new file mode 100644 index 00000000000..dc7e4024397 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/policy/SQLServerPolicyDAOImpl.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2018 - 2023 Entgra (Pvt) Ltd, Inc - All Rights Reserved. + * + * Unauthorised copying/redistribution of this file, via any medium is strictly prohibited. + * + * Licensed under the Entgra Commercial License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://entgra.io/licenses/entgra-commercial/1.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.policy.mgt.core.dao.impl.policy; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.common.PaginationRequest; +import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; +import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory; +import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +public class SQLServerPolicyDAOImpl extends AbstractPolicyDAOImpl { + private static final Log log = LogFactory.getLog(SQLServerPolicyDAOImpl.class); + + private Connection getConnection() { + return PolicyManagementDAOFactory.getConnection(); + } + + @Override + public List getAllPolicies(PaginationRequest request) throws PolicyManagerDAOException { + Connection conn; + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + + try { + conn = this.getConnection(); + String query = "SELECT * " + + "FROM DM_POLICY " + + "WHERE TENANT_ID = ? " + + "ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + try (PreparedStatement stmt = conn.prepareStatement(query)) { + stmt.setInt(1, tenantId); + stmt.setInt(2, request.getStartIndex()); + stmt.setInt(3, request.getRowCount()); + try (ResultSet resultSet = stmt.executeQuery()) { + return this.extractPolicyListFromDbResult(resultSet, tenantId); + } + } + } catch (SQLException e) { + String msg = "Error occurred while reading the policies from the database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } + } +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java index 42e34bf4907..f3249e48140 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java @@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DynamicTaskContext; +import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; import org.wso2.carbon.device.mgt.common.policy.mgt.Profile; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; @@ -334,7 +335,7 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { } @Override - public List getPolicyList() throws PolicyManagementException { - return policyManager.getPolicyList(); + public List getPolicyList(PaginationRequest request) throws PolicyManagementException { + return policyManager.getPolicyList(request); } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/PolicyManager.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/PolicyManager.java index b0b2c241d00..8f45900a21d 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/PolicyManager.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/PolicyManager.java @@ -20,6 +20,7 @@ package org.wso2.carbon.policy.mgt.core.mgt; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DynamicTaskContext; +import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.core.mgt.bean.UpdatedPolicyDeviceListBean; @@ -90,5 +91,12 @@ public interface PolicyManager { List getPolicies(String type) throws PolicyManagementException; - List getPolicyList() throws PolicyManagementException; + /** + * Returns list of policies with users, roles and groups attached to that policy + * @param request {@link PaginationRequest} contains offset and limit + * @return {@link List} - list of policies for current tenant + * @throws PolicyManagementException when there is an error while retrieving the policies from database or + * while retrieving device groups + */ + List getPolicyList(PaginationRequest request) throws PolicyManagementException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java index 13e8665102e..1bd77a398f4 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java @@ -41,6 +41,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DynamicTaskContext; +import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; @@ -1504,12 +1505,11 @@ public class PolicyManagerImpl implements PolicyManager { } @Override - public List getPolicyList() throws PolicyManagementException { - + public List getPolicyList(PaginationRequest request) throws PolicyManagementException { List policyList; try { PolicyManagementDAOFactory.openConnection(); - policyList = policyDAO.getAllPolicies(); + policyList = policyDAO.getAllPolicies(request); for (Policy policy : policyList) { policy.setRoles(policyDAO.getPolicyAppliedRoles(policy.getId())); policy.setUsers(policyDAO.getPolicyAppliedUsers(policy.getId())); @@ -1521,11 +1521,17 @@ public class PolicyManagerImpl implements PolicyManager { } Collections.sort(policyList); } catch (PolicyManagerDAOException e) { - throw new PolicyManagementException("Error occurred while getting all the policies.", e); + String msg = "Error occurred while getting all the policies."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); } catch (SQLException e) { - throw new PolicyManagementException("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 PolicyManagementException(msg, e); } catch (GroupManagementException e) { - throw new PolicyManagementException("Error occurred while getting device groups.", e); + String msg = "Error occurred while getting device groups."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); } finally { PolicyManagementDAOFactory.closeConnection(); } diff --git a/components/policy-mgt/pom.xml b/components/policy-mgt/pom.xml index 6709e908710..6cdec66ca3a 100644 --- a/components/policy-mgt/pom.xml +++ b/components/policy-mgt/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/components/task-mgt/pom.xml b/components/task-mgt/pom.xml index 3dd072c407e..1d7fc8d2efe 100755 --- a/components/task-mgt/pom.xml +++ b/components/task-mgt/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/pom.xml b/components/task-mgt/task-manager/io.entgra.task.mgt.common/pom.xml index e58e7e49694..cc8bd843401 100755 --- a/components/task-mgt/task-manager/io.entgra.task.mgt.common/pom.xml +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/pom.xml @@ -20,7 +20,7 @@ task-manager org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/pom.xml b/components/task-mgt/task-manager/io.entgra.task.mgt.core/pom.xml index d0621effa7d..897f9a612b2 100755 --- a/components/task-mgt/task-manager/io.entgra.task.mgt.core/pom.xml +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt task-manager - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/task-mgt/task-manager/pom.xml b/components/task-mgt/task-manager/pom.xml index 0b666e4a3e7..6edd1e33dcd 100755 --- a/components/task-mgt/task-manager/pom.xml +++ b/components/task-mgt/task-manager/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt task-mgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/pom.xml b/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/pom.xml index 26ee6b6e665..21fea0cd512 100755 --- a/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/pom.xml +++ b/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt task-watcher - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/task-mgt/task-watcher/pom.xml b/components/task-mgt/task-watcher/pom.xml index 4e70adb6361..005dbeed265 100755 --- a/components/task-mgt/task-watcher/pom.xml +++ b/components/task-mgt/task-watcher/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt task-mgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/email-sender/org.wso2.carbon.email.sender.core/pom.xml b/components/transport-mgt/email-sender/org.wso2.carbon.email.sender.core/pom.xml index 2b39b919794..7bdf9922499 100644 --- a/components/transport-mgt/email-sender/org.wso2.carbon.email.sender.core/pom.xml +++ b/components/transport-mgt/email-sender/org.wso2.carbon.email.sender.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt email-sender - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/email-sender/pom.xml b/components/transport-mgt/email-sender/pom.xml index c4a5ab633ef..35c8d36c064 100644 --- a/components/transport-mgt/email-sender/pom.xml +++ b/components/transport-mgt/email-sender/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt transport-mgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/pom.xml b/components/transport-mgt/pom.xml index 7f600bc7b0c..69f1f2b02f1 100644 --- a/components/transport-mgt/pom.xml +++ b/components/transport-mgt/pom.xml @@ -3,7 +3,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api/pom.xml b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api/pom.xml index 0685e390189..1bc860ed3d5 100644 --- a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api/pom.xml +++ b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.common/pom.xml b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.common/pom.xml index 95e61579975..908957c988b 100644 --- a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.common/pom.xml +++ b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.common/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.core/pom.xml b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.core/pom.xml index f97f7c1e019..0a64c24297b 100644 --- a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.core/pom.xml +++ b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/sms-handler/pom.xml b/components/transport-mgt/sms-handler/pom.xml index 170ea23fefb..60742becc62 100644 --- a/components/transport-mgt/sms-handler/pom.xml +++ b/components/transport-mgt/sms-handler/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt transport-mgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml index 811940eca09..b4c89c0eaa9 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml @@ -21,7 +21,7 @@ ui-request-interceptor io.entgra.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT 4.0.0 diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/HubspotHandler.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/HubspotHandler.java index b649d341fe5..e489f1883c2 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/HubspotHandler.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/HubspotHandler.java @@ -26,6 +26,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.http.HttpHeaders; import org.apache.http.HttpStatus; +import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; @@ -86,6 +87,21 @@ public class HubspotHandler extends HttpServlet { } } + @Override + protected void doDelete(HttpServletRequest req, HttpServletResponse resp){ + try{ + if(validateRequest(req, resp)){ + HttpDelete deleteRequest = new HttpDelete(HandlerUtil.generateBackendRequestURL(req,hubspotEndpoint)); + deleteRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/json"); + deleteRequest.setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BEARER + chatConfig); + ProxyResponse proxyResponse = HandlerUtil.execute(deleteRequest); + HandlerUtil.handleSuccess(resp, proxyResponse); + } + } catch (IOException e){ + log.error("Error occurred when processing DELETE request.", e); + } + } + /*** * Validates the hubspot's incoming request. * diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/UserHandler.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/UserHandler.java index 997015ce8f6..53be11141e4 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/UserHandler.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/UserHandler.java @@ -22,11 +22,12 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; +import io.entgra.device.mgt.extensions.logger.spi.EntgraLogger; +import io.entgra.notification.logger.UserLogContext; +import io.entgra.notification.logger.impl.EntgraUserLoggerImpl; import io.entgra.ui.request.interceptor.beans.AuthData; import io.entgra.ui.request.interceptor.util.HandlerConstants; import io.entgra.ui.request.interceptor.util.HandlerUtil; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.apache.http.HttpHeaders; import org.apache.http.HttpStatus; import org.apache.http.client.methods.HttpPost; @@ -48,7 +49,8 @@ import java.util.Base64; @MultipartConfig @WebServlet("/user") public class UserHandler extends HttpServlet { - private static final Log log = LogFactory.getLog(UserHandler.class); + private static final EntgraLogger log = new EntgraUserLoggerImpl(UserHandler.class); + UserLogContext.Builder userLogContextBuilder = new UserLogContext.Builder(); private static final long serialVersionUID = 9050048549140517002L; @Override @@ -118,6 +120,7 @@ public class UserHandler extends HttpServlet { proxyResponse.setData( jTokenResultAsJsonObject.get("username").getAsString().replaceAll("@carbon.super", "")); HandlerUtil.handleSuccess(resp, proxyResponse); + log.info("Customer login", userLogContextBuilder.setUserName(proxyResponse.getData()).setUserRegistered(true).build()); } } catch (IOException e) { log.error("Error occurred while sending the response into the socket. ", e); diff --git a/components/ui-request-interceptor/pom.xml b/components/ui-request-interceptor/pom.xml index 0e28cc938ac..692ea269775 100644 --- a/components/ui-request-interceptor/pom.xml +++ b/components/ui-request-interceptor/pom.xml @@ -21,7 +21,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml index cb4a230459e..8f23a1cb63a 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt webapp-authenticator-framework - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/components/webapp-authenticator-framework/pom.xml b/components/webapp-authenticator-framework/pom.xml index 081ec8435d5..266aa06eb64 100644 --- a/components/webapp-authenticator-framework/pom.xml +++ b/components/webapp-authenticator-framework/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml index cf405ce8725..0f8eef62926 100644 --- a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml +++ b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml index 6ca64815a7a..f63f0dab760 100644 --- a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml +++ b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/analytics-mgt/grafana-mgt/pom.xml b/features/analytics-mgt/grafana-mgt/pom.xml index 95fad6f184a..198de84f7a7 100644 --- a/features/analytics-mgt/grafana-mgt/pom.xml +++ b/features/analytics-mgt/grafana-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt analytics-mgt-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/analytics-mgt/pom.xml b/features/analytics-mgt/pom.xml index cc859b27c82..0782957fd11 100644 --- a/features/analytics-mgt/pom.xml +++ b/features/analytics-mgt/pom.xml @@ -3,7 +3,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/pom.xml b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/pom.xml index bbe2d2226e9..6703c23a7db 100644 --- a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/pom.xml +++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/pom.xml @@ -20,7 +20,7 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml index a0f0b246eb8..ab7dad3cd44 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml index f202cbf25f5..5f7c41c612a 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml index bcfce9faed2..2fbefd84571 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/apimgt-extensions/pom.xml b/features/apimgt-extensions/pom.xml index 45123719f01..950a6bb76d8 100644 --- a/features/apimgt-extensions/pom.xml +++ b/features/apimgt-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/features/application-mgt/io.entgra.application.mgt.api.feature/pom.xml b/features/application-mgt/io.entgra.application.mgt.api.feature/pom.xml index 40f8b41c8b0..b65017bbdbe 100644 --- a/features/application-mgt/io.entgra.application.mgt.api.feature/pom.xml +++ b/features/application-mgt/io.entgra.application.mgt.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt application-mgt-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/application-mgt/io.entgra.application.mgt.server.feature/pom.xml b/features/application-mgt/io.entgra.application.mgt.server.feature/pom.xml index eb0727491a4..f1d0f4ae1c6 100644 --- a/features/application-mgt/io.entgra.application.mgt.server.feature/pom.xml +++ b/features/application-mgt/io.entgra.application.mgt.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt application-mgt-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/application-mgt/pom.xml b/features/application-mgt/pom.xml index 5148a57452c..a8c8e7d1f00 100644 --- a/features/application-mgt/pom.xml +++ b/features/application-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml index acfdb1ab6cd..dd5b7736bc7 100644 --- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt certificate-mgt-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml index 5dc6185f234..10bccb16ceb 100644 --- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt certificate-mgt-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml index 0c05cd78ffc..d9cc05af65e 100644 --- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt certificate-mgt-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/certificate-mgt/pom.xml b/features/certificate-mgt/pom.xml index f21dfc2695d..e8ab115dd78 100644 --- a/features/certificate-mgt/pom.xml +++ b/features/certificate-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager.feature/pom.xml b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager.feature/pom.xml index fed8c0f25b9..c5a49e83967 100644 --- a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager.feature/pom.xml +++ b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.logger.feature/pom.xml b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.logger.feature/pom.xml index 8f57e439c8b..213f436a611 100644 --- a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.logger.feature/pom.xml +++ b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.logger.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine.feature/pom.xml b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine.feature/pom.xml index 8dd649d652a..ce45313eda1 100644 --- a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine.feature/pom.xml +++ b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml index 0016ab0066f..e236aa89143 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml index 2ef24d1914c..0f6a8c9df95 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml index 46d7df4f25a..6cfddf491cf 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml index 42442839ded..6ba02faac50 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml index b89b6ff19e5..1a9beb136e8 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/pom.xml b/features/device-mgt-extensions/pom.xml index 58eac7c911d..bdfa204a195 100644 --- a/features/device-mgt-extensions/pom.xml +++ b/features/device-mgt-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml index 9a9b95bdf8e..c16be537ad4 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml index 14457650ac8..7e4c7203c60 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql index f383c5d5b9c..960fedcc20a 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -786,4 +786,17 @@ CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES ( CONSTRAINT FK_DYNAMIC_TASK_TASK_PROPERTIES FOREIGN KEY (DYNAMIC_TASK_ID) REFERENCES DYNAMIC_TASK (DYNAMIC_TASK_ID) ON DELETE CASCADE ON UPDATE CASCADE ); --- END OF DYNAMIC TASK TABLE-- \ No newline at end of file +-- END OF DYNAMIC TASK TABLE-- + +-- DM_TRACCAR_UNSYNCED_DEVICES TABLE -- +CREATE TABLE IF NOT EXISTS DM_TRACCAR_UNSYNCED_DEVICES ( + ID INT NOT NULL AUTO_INCREMENT, + DEVICE_NAME VARCHAR(100) NOT NULL, + IOTS_DEVICE_IDENTIFIER VARCHAR(300) DEFAULT NULL UNIQUE, + TRACCAR_DEVICE_UNIQUE_ID INT NOT NULL, + TRACCAR_USENAME VARCHAR(100) NULL, + STATUS VARCHAR(100) NULL, + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (ID) +); +-- END OF DM_TRACCAR_UNSYNCED_DEVICES TABLE -- diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql index 1c22ba25fc6..d43294bd34e 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -303,6 +303,7 @@ CREATE TABLE DM_POLICY_CORRECTIVE_ACTION ( CORRECTIVE_POLICY_ID INTEGER DEFAULT NULL, POLICY_ID INTEGER NOT NULL, FEATURE_ID INTEGER DEFAULT NULL, + IS_REACTIVE BIT NOT NULL DEFAULT 0, PRIMARY KEY (ID), CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION FOREIGN KEY (POLICY_ID) @@ -753,4 +754,17 @@ CREATE TABLE DYNAMIC_TASK_PROPERTIES ( CONSTRAINT FK_DYNAMIC_TASK_TASK_PROPERTIES FOREIGN KEY (DYNAMIC_TASK_ID) REFERENCES DYNAMIC_TASK (DYNAMIC_TASK_ID) ON DELETE CASCADE ON UPDATE CASCADE ); --- END OF DYNAMIC TASK TABLE-- \ No newline at end of file +-- END OF DYNAMIC TASK TABLE-- + +-- DM_TRACCAR_UNSYNCED_DEVICES TABLE -- +CREATE TABLE IF NOT EXISTS DM_TRACCAR_UNSYNCED_DEVICES ( + ID INT NOT NULL IDENTITY(1,1), + DEVICE_NAME VARCHAR(100) NOT NULL, + IOTS_DEVICE_IDENTIFIER VARCHAR(300) NULL UNIQUE, + TRACCAR_DEVICE_UNIQUE_ID INT NOT NULL, + TRACCAR_USENAME VARCHAR(100) NULL, + STATUS VARCHAR(100) NULL, + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (ID) +); +-- END OF DM_TRACCAR_UNSYNCED_DEVICES TABLE -- diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql index 17c7460c97e..4981e158705 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -851,3 +851,16 @@ CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES ( DYNAMIC_TASK (DYNAMIC_TASK_ID) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB; -- END OF DYNAMIC TASK TABLE-- + +-- DM_TRACCAR_UNSYNCED_DEVICES TABLE -- +CREATE TABLE IF NOT EXISTS DM_TRACCAR_UNSYNCED_DEVICES ( + ID INT NOT NULL AUTO_INCREMENT, + DEVICE_NAME VARCHAR(100) NOT NULL, + IOTS_DEVICE_IDENTIFIER VARCHAR(300) DEFAULT NULL UNIQUE, + TRACCAR_DEVICE_UNIQUE_ID INT NOT NULL, + TRACCAR_USENAME VARCHAR(100) NULL, + STATUS VARCHAR(100) NULL, + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (ID) +); +-- END OF DM_TRACCAR_UNSYNCED_DEVICES TABLE -- diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql index a5d37255488..10554077ab6 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -1119,3 +1119,16 @@ CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES ( DYNAMIC_TASK (DYNAMIC_TASK_ID) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB; -- END OF DYNAMIC TASK TABLE-- + +-- DM_TRACCAR_UNSYNCED_DEVICES TABLE -- +CREATE TABLE DM_TRACCAR_UNSYNCED_DEVICES ( + ID NUMBER(10) NOT NULL, + DEVICE_NAME VARCHAR2(100) NOT NULL, + IOTS_DEVICE_IDENTIFIER VARCHAR2(300) UNIQUE, + TRACCAR_DEVICE_UNIQUE_ID NUMBER(10) NOT NULL, + TRACCAR_USENAME VARCHAR2(100), + STATUS VARCHAR2(100), + TENANT_ID NUMBER(10) DEFAULT 0, + CONSTRAINT DM_TRACCAR_UNSYNCED_DEVICES_PK PRIMARY KEY (ID) +); +-- END OF DM_TRACCAR_UNSYNCED_DEVICES TABLE -- diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 731f086c616..dca570ebf05 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -772,3 +772,16 @@ CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES ( DYNAMIC_TASK (DYNAMIC_TASK_ID) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB; -- END OF DYNAMIC TASK TABLE-- + +-- DM_TRACCAR_UNSYNCED_DEVICES TABLE -- +CREATE TABLE IF NOT EXISTS DM_TRACCAR_UNSYNCED_DEVICES ( + ID SERIAL NOT NULL, + DEVICE_NAME VARCHAR(100) NOT NULL, + IOTS_DEVICE_IDENTIFIER VARCHAR(300) UNIQUE, + TRACCAR_DEVICE_UNIQUE_ID INT NOT NULL, + TRACCAR_USENAME VARCHAR(100), + STATUS VARCHAR(100), + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (ID) +); +-- END OF DM_TRACCAR_UNSYNCED_DEVICES TABLE -- diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml index 0185636c8e7..2128ddce783 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml @@ -4,7 +4,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml index 7f7ae962052..463215e1734 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml index baec3856805..63b3a3229c8 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/pom.xml b/features/device-mgt/pom.xml index 62a22489dd9..11f50bc7d7f 100644 --- a/features/device-mgt/pom.xml +++ b/features/device-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml b/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml index 0c4f1f09b68..31a16abe9ce 100644 --- a/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml +++ b/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt heart-beat-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/heartbeat-management/pom.xml b/features/heartbeat-management/pom.xml index 9268f032b3d..38eb878036d 100644 --- a/features/heartbeat-management/pom.xml +++ b/features/heartbeat-management/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml b/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml index 8fcbd20f074..2425ea317f1 100644 --- a/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml +++ b/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt jwt-client-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/jwt-client/pom.xml b/features/jwt-client/pom.xml index 70a1ee67416..7dafdc71354 100644 --- a/features/jwt-client/pom.xml +++ b/features/jwt-client/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/features/logger/io.entgra.notification.logger.feature/pom.xml b/features/logger/io.entgra.notification.logger.feature/pom.xml index c9630369bc3..d897352777a 100644 --- a/features/logger/io.entgra.notification.logger.feature/pom.xml +++ b/features/logger/io.entgra.notification.logger.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt logger-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/logger/pom.xml b/features/logger/pom.xml index ab41d67cf8d..fbfdbc7656a 100644 --- a/features/logger/pom.xml +++ b/features/logger/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml b/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml index 491b2810c61..c08fc4052be 100644 --- a/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml +++ b/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt policy-mgt-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/policy-mgt/pom.xml b/features/policy-mgt/pom.xml index 97c4cc4e61d..c36d7e00249 100644 --- a/features/policy-mgt/pom.xml +++ b/features/policy-mgt/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/features/task-mgt/io.entgra.task.mgt.feature/pom.xml b/features/task-mgt/io.entgra.task.mgt.feature/pom.xml index ff0531217c3..16bc2d57232 100755 --- a/features/task-mgt/io.entgra.task.mgt.feature/pom.xml +++ b/features/task-mgt/io.entgra.task.mgt.feature/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../../pom.xml diff --git a/features/task-mgt/pom.xml b/features/task-mgt/pom.xml index df640d0bec4..3678b617ad0 100755 --- a/features/task-mgt/pom.xml +++ b/features/task-mgt/pom.xml @@ -21,7 +21,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/pom.xml b/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/pom.xml index 7e9f22200cd..b05bb2be06a 100644 --- a/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/pom.xml +++ b/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt email-sender-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-verify.vm b/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-verify.vm index 858503fd8a4..449418e58fb 100644 --- a/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-verify.vm +++ b/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-verify.vm @@ -36,8 +36,9 @@ Hi $first-name,

- Congratulations!!! Thank you for registering with Entgra cloud. Please click and log in to the - following link to complete your registration with us. Click here. + Congratulations!!! Thank you for registering with Entgra. Please click on the + following link to complete your registration with us. Click here.

diff --git a/features/transport-mgt/email-sender/pom.xml b/features/transport-mgt/email-sender/pom.xml index f44ae495cf6..8e790a71228 100644 --- a/features/transport-mgt/email-sender/pom.xml +++ b/features/transport-mgt/email-sender/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt transport-mgt-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/transport-mgt/pom.xml b/features/transport-mgt/pom.xml index 98a183d6a0e..c80b5988944 100644 --- a/features/transport-mgt/pom.xml +++ b/features/transport-mgt/pom.xml @@ -3,7 +3,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api.feature/pom.xml b/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api.feature/pom.xml index 1035de452f2..512ca7a4c33 100644 --- a/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api.feature/pom.xml +++ b/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.server.feature/pom.xml b/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.server.feature/pom.xml index a8020865a17..8d6c87d7362 100644 --- a/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.server.feature/pom.xml +++ b/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/transport-mgt/sms-handler/pom.xml b/features/transport-mgt/sms-handler/pom.xml index c2b954db0b0..e9039888d31 100644 --- a/features/transport-mgt/sms-handler/pom.xml +++ b/features/transport-mgt/sms-handler/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt transport-mgt-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/ui-request-interceptor/io.entgra.ui.request.interceptor.feature/pom.xml b/features/ui-request-interceptor/io.entgra.ui.request.interceptor.feature/pom.xml index fc9c879a41f..1bd46be14b6 100644 --- a/features/ui-request-interceptor/io.entgra.ui.request.interceptor.feature/pom.xml +++ b/features/ui-request-interceptor/io.entgra.ui.request.interceptor.feature/pom.xml @@ -21,7 +21,7 @@ ui-request-interceptor-feature io.entgra.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT 4.0.0 diff --git a/features/ui-request-interceptor/pom.xml b/features/ui-request-interceptor/pom.xml index bd9a7bd03b6..8a01acd528b 100644 --- a/features/ui-request-interceptor/pom.xml +++ b/features/ui-request-interceptor/pom.xml @@ -21,7 +21,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml index 4909d5c93e0..218e08e58ea 100644 --- a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml +++ b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt webapp-authenticator-framework-feature - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml diff --git a/features/webapp-authenticator-framework/pom.xml b/features/webapp-authenticator-framework/pom.xml index 474a36cc23c..bade36ba10c 100644 --- a/features/webapp-authenticator-framework/pom.xml +++ b/features/webapp-authenticator-framework/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT ../../pom.xml diff --git a/pom.xml b/pom.xml index 985eb5c4d80..2851e5865f0 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt pom - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT WSO2 Carbon - Device Management - Parent http://wso2.org WSO2 Connected Device Manager Components @@ -2101,7 +2101,7 @@ 1.2.11.wso2v10 - 5.0.22-SNAPSHOT + 5.0.25-SNAPSHOT 4.7.35