diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/pom.xml
index c8011c08f3..5bbb149f5a 100644
--- a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/pom.xml
+++ b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/pom.xml
@@ -22,7 +22,7 @@
io.entgra.device.mgt.core
grafana-mgt
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/api/GrafanaAPIProxyService.java b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/api/GrafanaAPIProxyService.java
index 18fb6201af..5bdf335d30 100644
--- a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/api/GrafanaAPIProxyService.java
+++ b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/api/GrafanaAPIProxyService.java
@@ -107,6 +107,23 @@ public interface GrafanaAPIProxyService {
)
Response frontendMetrics(JsonObject body, @Context HttpHeaders headers, @Context UriInfo requestUriInfo);
+ @POST
+ @Produces(MediaType.APPLICATION_JSON)
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Path("/user/auth-tokens/rotate")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = "POST",
+ value = "Rotate authentication tokens",
+ tags = "Analytics",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = SCOPE, value = "grafana:api:view")
+ })
+ }
+ )
+ Response rotateAuthToken(JsonObject body, @Context HttpHeaders headers, @Context UriInfo requestUriInfo);
+
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/dashboards/uid/{uid}")
@@ -123,6 +140,22 @@ public interface GrafanaAPIProxyService {
)
Response getDashboard(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) throws ClassNotFoundException;
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/folders/{uid}")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = "GET",
+ value = "Grafana dashboard folder information",
+ tags = "Analytics",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = SCOPE, value = "grafana:api:view")
+ })
+ }
+ )
+ Response getFolders(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) throws ClassNotFoundException;
+
@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@@ -140,6 +173,23 @@ public interface GrafanaAPIProxyService {
)
Response getAnnotations(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) throws ClassNotFoundException;
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Path("/prometheus/grafana/api/v1/rules")
+ @ApiOperation(
+ produces = MediaType.APPLICATION_JSON,
+ httpMethod = "GET",
+ value = "Accessing Grafana Prometheus rule information",
+ tags = "Analytics",
+ extensions = {
+ @Extension(properties = {
+ @ExtensionProperty(name = SCOPE, value = "grafana:api:view")
+ })
+ }
+ )
+ Response prometheusRuleInfo(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) throws ClassNotFoundException;
+
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/alerts/states-for-dashboard")
diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/api/impl/GrafanaAPIProxyServiceImpl.java b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/api/impl/GrafanaAPIProxyServiceImpl.java
index 8ed6fe1ca1..92eed32c74 100644
--- a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/api/impl/GrafanaAPIProxyServiceImpl.java
+++ b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/api/impl/GrafanaAPIProxyServiceImpl.java
@@ -26,6 +26,8 @@ import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api.impl.util.Grafa
import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api.impl.util.GrafanaRequestHandlerUtil;
import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.common.exception.GrafanaManagementException;
import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.bean.GrafanaPanelIdentifier;
+import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.config.GrafanaConfiguration;
+import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.config.GrafanaConfigurationManager;
import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.exception.MaliciousQueryAttempt;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -56,9 +58,13 @@ public class GrafanaAPIProxyServiceImpl implements GrafanaAPIProxyService {
@Override
public Response queryDatasource(JsonObject body, @Context HttpHeaders headers, @Context UriInfo requestUriInfo) {
try {
+ GrafanaConfiguration configuration = GrafanaConfigurationManager.getInstance().getGrafanaConfiguration();
GrafanaPanelIdentifier panelIdentifier = GrafanaRequestHandlerUtil.getPanelIdentifier(headers);
- GrafanaMgtAPIUtils.getGrafanaQueryService().buildSafeQuery(body, panelIdentifier.getDashboardId(),
- panelIdentifier.getPanelId(), requestUriInfo.getRequestUri());
+ boolean queryValidationConfig = configuration.getValidationConfig().getDSQueryValidation();
+ if (queryValidationConfig) {
+ GrafanaMgtAPIUtils.getGrafanaQueryService().buildSafeQuery(body, panelIdentifier.getDashboardId(),
+ panelIdentifier.getPanelId(), requestUriInfo.getRequestUri());
+ }
return GrafanaRequestHandlerUtil.proxyPassPostRequest(body, requestUriInfo, panelIdentifier.getOrgId());
} catch (MaliciousQueryAttempt e) {
return Response.status(Response.Status.BAD_REQUEST).entity(
@@ -83,6 +89,15 @@ public class GrafanaAPIProxyServiceImpl implements GrafanaAPIProxyService {
return proxyPassPostRequest(body, headers, requestUriInfo);
}
+ @POST
+ @Produces(MediaType.APPLICATION_JSON)
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Path("/user/auth-tokens/rotate")
+ @Override
+ public Response rotateAuthToken(JsonObject body, @Context HttpHeaders headers, @Context UriInfo requestUriInfo) {
+ return proxyPassPostRequest(body, headers, requestUriInfo);
+ }
+
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/dashboards/uid/{uid}")
@@ -91,6 +106,14 @@ public class GrafanaAPIProxyServiceImpl implements GrafanaAPIProxyService {
return proxyPassGetRequest(headers, requestUriInfo);
}
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/folders/{uid}")
+ @Override
+ public Response getFolders(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) {
+ return proxyPassGetRequest(headers, requestUriInfo);
+ }
+
@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@@ -99,6 +122,16 @@ public class GrafanaAPIProxyServiceImpl implements GrafanaAPIProxyService {
public Response getAnnotations(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) {
return proxyPassGetRequest(headers, requestUriInfo);
}
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Path("/prometheus/grafana/api/v1/rules")
+ @Override
+ public Response prometheusRuleInfo(@Context HttpHeaders headers, @Context UriInfo requestUriInfo) {
+ return proxyPassGetRequest(headers, requestUriInfo);
+ }
+
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/alerts/states-for-dashboard")
diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/api/impl/util/GrafanaRequestHandlerUtil.java b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/api/impl/util/GrafanaRequestHandlerUtil.java
index d81a6d4d26..e94b3ccf53 100644
--- a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/api/impl/util/GrafanaRequestHandlerUtil.java
+++ b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/api/impl/util/GrafanaRequestHandlerUtil.java
@@ -22,6 +22,8 @@ import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api.bean.ErrorRespo
import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api.exception.RefererNotValid;
import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.common.exception.GrafanaManagementException;
import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.bean.GrafanaPanelIdentifier;
+import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.config.GrafanaConfiguration;
+import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.config.GrafanaConfigurationManager;
import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.exception.GrafanaEnvVariablesNotDefined;
import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.util.GrafanaConstants;
import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.util.GrafanaUtil;
@@ -120,19 +122,23 @@ public class GrafanaRequestHandlerUtil {
return path;
}
- public static GrafanaPanelIdentifier getPanelIdentifier(HttpHeaders headers) throws RefererNotValid {
+ public static GrafanaPanelIdentifier getPanelIdentifier(HttpHeaders headers) throws RefererNotValid, GrafanaManagementException {
String referer = headers.getHeaderString(GrafanaConstants.REFERER_HEADER);
- if(referer == null) {
+ if (referer == null) {
String errMsg = "Request does not contain Referer header";
log.error(errMsg);
throw new RefererNotValid(errMsg);
}
+ GrafanaConfiguration configuration = GrafanaConfigurationManager.getInstance().getGrafanaConfiguration();
+ boolean dashboardIntegrationConfig = configuration.getValidationConfig().getDashboardIntegration();
GrafanaPanelIdentifier panelIdentifier = GrafanaUtil.getPanelIdentifierFromReferer(referer);
- if(panelIdentifier.getDashboardId() == null ||
- panelIdentifier.getPanelId() == null || panelIdentifier.getOrgId() == null) {
- String errMsg = "Referer must contain dashboardId, panelId and orgId";
- log.error(errMsg);
- throw new RefererNotValid(errMsg);
+ if (!dashboardIntegrationConfig) {
+ if (panelIdentifier.getDashboardId() == null ||
+ panelIdentifier.getPanelId() == null || panelIdentifier.getOrgId() == null) {
+ String errMsg = "Referer must contain dashboardId, panelId, and orgId";
+ log.error(errMsg);
+ throw new RefererNotValid(errMsg);
+ }
}
return panelIdentifier;
}
diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.common/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.common/pom.xml
index ad2b76aea8..fe168409c7 100644
--- a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.common/pom.xml
+++ b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.common/pom.xml
@@ -22,7 +22,7 @@
io.entgra.device.mgt.core
grafana-mgt
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core/pom.xml
index 2d708f2e34..e1d23b0dd4 100644
--- a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core/pom.xml
+++ b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core/pom.xml
@@ -22,7 +22,7 @@
io.entgra.device.mgt.core
grafana-mgt
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/core/config/GrafanaConfiguration.java b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/core/config/GrafanaConfiguration.java
index bf2cbce90f..137dc86025 100644
--- a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/core/config/GrafanaConfiguration.java
+++ b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/core/config/GrafanaConfiguration.java
@@ -19,6 +19,7 @@
package io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.config;
import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.config.xml.bean.CacheConfiguration;
+import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.config.xml.bean.ValidationConfig;
import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.config.xml.bean.User;
import javax.xml.bind.annotation.XmlElement;
@@ -30,6 +31,7 @@ import java.util.List;
public class GrafanaConfiguration {
private User adminUser;
+ private ValidationConfig validationConfig;
private List caches;
@XmlElement(name = "AdminUser")
@@ -37,6 +39,15 @@ public class GrafanaConfiguration {
return adminUser;
}
+ @XmlElement(name = "ValidationConfig")
+ public ValidationConfig getValidationConfig() {
+ return validationConfig;
+ }
+
+ public void setValidationConfig(ValidationConfig validationConfig) {
+ this.validationConfig = validationConfig;
+ }
+
public void setAdminUser(User user) {
this.adminUser = user;
}
diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/core/config/xml/bean/ValidationConfig.java b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/core/config/xml/bean/ValidationConfig.java
new file mode 100644
index 0000000000..b15955bbe2
--- /dev/null
+++ b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/core/config/xml/bean/ValidationConfig.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.config.xml.bean;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "ValidationConfig")
+public class ValidationConfig {
+ private boolean dsQueryValidation;
+ private boolean dashboardIntegration;
+
+ @XmlElement(name = "DSQueryValidation")
+ public boolean getDSQueryValidation() {
+ return dsQueryValidation;
+ }
+
+ public void setDSQueryValidation(boolean dsQueryValidation) {
+ this.dsQueryValidation = dsQueryValidation;
+ }
+
+ @XmlElement(name = "DashboardIntegration")
+ public boolean getDashboardIntegration() {
+ return dashboardIntegration;
+ }
+
+ public void setDashboardIntegration(boolean dashboardIntegration) {
+ this.dashboardIntegration = dashboardIntegration;
+ }
+}
diff --git a/components/analytics-mgt/grafana-mgt/pom.xml b/components/analytics-mgt/grafana-mgt/pom.xml
index 1687efce72..456834371f 100644
--- a/components/analytics-mgt/grafana-mgt/pom.xml
+++ b/components/analytics-mgt/grafana-mgt/pom.xml
@@ -22,7 +22,7 @@
io.entgra.device.mgt.core
analytics-mgt
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/analytics-mgt/pom.xml b/components/analytics-mgt/pom.xml
index 00d4c90659..7de259bada 100644
--- a/components/analytics-mgt/pom.xml
+++ b/components/analytics-mgt/pom.xml
@@ -21,7 +21,7 @@
io.entgra.device.mgt.core.parent
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-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 062250c578..0644c29899 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
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
4.0.0
diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.annotations/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.annotations/pom.xml
index e3f137438d..5386164088 100644
--- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.annotations/pom.xml
+++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.annotations/pom.xml
@@ -22,7 +22,7 @@
apimgt-extensions
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension.api/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension.api/pom.xml
index fb993c89e1..0431e96880 100644
--- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension.api/pom.xml
+++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension.api/pom.xml
@@ -21,7 +21,7 @@
apimgt-extensions
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/pom.xml
index 9715d49004..b0af3744db 100644
--- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/pom.xml
+++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/pom.xml
@@ -22,7 +22,7 @@
apimgt-extensions
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml
index 153009c3e8..ef2bb81d86 100644
--- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml
+++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml
@@ -22,7 +22,7 @@
apimgt-extensions
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java
index 8db730cc7b..e322ae0307 100644
--- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java
+++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java
@@ -120,7 +120,9 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else if (HttpStatus.SC_NOT_FOUND == response.code()) {
String msg = "Shared scope key not found : " + key;
- log.info(msg);
+ if (log.isDebugEnabled()) {
+ log.debug(msg);
+ }
return false;
} else {
String msg = "Response : " + response.code() + response.body();
diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension.api/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension.api/pom.xml
index 3a0bbffa59..ebc4285259 100644
--- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension.api/pom.xml
+++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension.api/pom.xml
@@ -21,7 +21,7 @@
apimgt-extensions
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
4.0.0
diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension/pom.xml
index 9d9fc52a3c..1b31e53d33 100644
--- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension/pom.xml
+++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension/pom.xml
@@ -21,7 +21,7 @@
apimgt-extensions
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/pom.xml
index 10bfbf4145..1f8b3b7809 100644
--- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/pom.xml
+++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/pom.xml
@@ -22,7 +22,7 @@
apimgt-extensions
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
@@ -205,7 +205,9 @@
org.wso2.carbon.utils;version="4.6",
org.wso2.carbon.utils.multitenancy;version="4.6",
org.apache.commons.lang,
- org.json
+ org.json,
+ io.entgra.device.mgt.core.device.mgt.common.permission.mgt,
+ io.entgra.device.mgt.core.device.mgt.core.permission.mgt
jsr311-api;scope=compile|runtime;inline=false
diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java
index e9a58e556c..cab16f8482 100644
--- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java
+++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java
@@ -46,6 +46,7 @@ import io.entgra.device.mgt.core.device.mgt.core.config.DeviceManagementConfig;
import io.entgra.device.mgt.core.device.mgt.core.config.permission.DefaultPermission;
import io.entgra.device.mgt.core.device.mgt.core.config.permission.DefaultPermissions;
import io.entgra.device.mgt.core.device.mgt.core.config.permission.ScopeMapping;
+import io.entgra.device.mgt.core.device.mgt.core.permission.mgt.PermissionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -68,6 +69,8 @@ import org.wso2.carbon.user.core.tenant.TenantSearchResult;
import org.wso2.carbon.utils.CarbonUtils;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
+import io.entgra.device.mgt.core.device.mgt.core.permission.mgt.PermissionUtils;
+import io.entgra.device.mgt.core.device.mgt.common.permission.mgt.PermissionManagementException;
import java.io.BufferedReader;
import java.io.File;
@@ -610,9 +613,17 @@ public class APIPublisherServiceImpl implements APIPublisherService {
if (publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, scope.getName())) {
publisherRESTAPIServices.updateSharedScope(apiApplicationKey, accessTokenInfo, scope);
+ // todo: permission changed in update path, is not handled yet.
} else {
- // todo: come to this level means, that scope is removed from API, but haven't removed from the scope-role-permission-mappings list
- log.warn(scope.getName() + " not available as shared scope");
+ // This scope doesn't have an api attached.
+ log.warn(scope.getName() + " not available as shared, add as new scope");
+ publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
+ // add permission if not exist
+ try {
+ PermissionUtils.putPermission(permission);
+ } catch(PermissionManagementException e) {
+ log.error("Error when adding permission ", e);
+ }
}
}
for (String role : rolePermissions.keySet()) {
diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherStartupHandler.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherStartupHandler.java
index e039259b92..d218238dc1 100644
--- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherStartupHandler.java
+++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherStartupHandler.java
@@ -18,12 +18,24 @@
package io.entgra.device.mgt.core.apimgt.webapp.publisher;
+import com.google.gson.Gson;
+import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants;
+import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataKeyAlreadyExistsException;
+import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
+import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
+import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService;
+import io.entgra.device.mgt.core.device.mgt.core.config.DeviceConfigurationManager;
+import io.entgra.device.mgt.core.device.mgt.core.config.DeviceManagementConfig;
+import io.entgra.device.mgt.core.device.mgt.core.config.permission.DefaultPermission;
+import io.entgra.device.mgt.core.device.mgt.core.config.permission.DefaultPermissions;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import io.entgra.device.mgt.core.apimgt.webapp.publisher.exception.APIManagerPublisherException;
import io.entgra.device.mgt.core.apimgt.webapp.publisher.internal.APIPublisherDataHolder;
import org.wso2.carbon.core.ServerStartupObserver;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Stack;
public class APIPublisherStartupHandler implements ServerStartupObserver {
@@ -34,6 +46,7 @@ public class APIPublisherStartupHandler implements ServerStartupObserver {
private static final int MAX_RETRY_COUNT = 5;
private static Stack failedAPIsStack = new Stack<>();
private static Stack currentAPIsStack;
+ private static final Gson gson = new Gson();
private APIPublisherService publisher;
@@ -91,6 +104,8 @@ public class APIPublisherStartupHandler implements ServerStartupObserver {
log.error("failed to update scope role mapping.", e);
}
+ updateScopeMetadataEntryWithDefaultScopes();
+
// execute after api publishing
for (PostApiPublishingObsever observer : APIPublisherDataHolder.getInstance().getPostApiPublishingObseverList()) {
if (log.isDebugEnabled()) {
@@ -116,4 +131,39 @@ public class APIPublisherStartupHandler implements ServerStartupObserver {
}
}
+ /**
+ * Update permission scope mapping entry with default scopes if perm-scope-mapping entry exists, otherwise this function
+ * will create that entry and update the value with default permissions.
+ */
+ private void updateScopeMetadataEntryWithDefaultScopes() {
+ MetadataManagementService metadataManagementService = APIPublisherDataHolder.getInstance().getMetadataManagementService();
+ try {
+ DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
+ DefaultPermissions defaultPermissions = deviceManagementConfig.getDefaultPermissions();
+ Metadata permScopeMapping = metadataManagementService.retrieveMetadata(Constants.PERM_SCOPE_MAPPING_META_KEY);
+ Map permScopeMap = (permScopeMapping != null) ? gson.fromJson(permScopeMapping.getMetaValue(), HashMap.class) :
+ new HashMap<>();
+ for (DefaultPermission defaultPermission : defaultPermissions.getDefaultPermissions()) {
+ permScopeMap.putIfAbsent(defaultPermission.getName(),
+ defaultPermission.getScopeMapping().getKey());
+ }
+
+ APIPublisherDataHolder.getInstance().setPermScopeMapping(permScopeMap);
+ if (permScopeMapping != null) {
+ permScopeMapping.setMetaValue(gson.toJson(permScopeMap));
+ metadataManagementService.updateMetadata(permScopeMapping);
+ return;
+ }
+
+ permScopeMapping = new Metadata();
+ permScopeMapping.setMetaKey(Constants.PERM_SCOPE_MAPPING_META_KEY);
+ permScopeMapping.setMetaValue(gson.toJson(permScopeMap));
+ metadataManagementService.createMetadata(permScopeMapping);
+ } catch (MetadataManagementException e) {
+ log.error("Error encountered while updating permission scope mapping metadata with default scopes");
+ } catch (MetadataKeyAlreadyExistsException e) {
+ log.error("Metadata entry already exists for " + Constants.PERM_SCOPE_MAPPING_META_KEY);
+ }
+ }
+
}
diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java
index bbd2fd952e..737f734d07 100644
--- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java
+++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java
@@ -22,10 +22,6 @@ import io.entgra.device.mgt.core.apimgt.webapp.publisher.dto.ApiScope;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService;
-import io.entgra.device.mgt.core.device.mgt.core.config.DeviceConfigurationManager;
-import io.entgra.device.mgt.core.device.mgt.core.config.DeviceManagementConfig;
-import io.entgra.device.mgt.core.device.mgt.core.config.permission.DefaultPermission;
-import io.entgra.device.mgt.core.device.mgt.core.config.permission.DefaultPermissions;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener;
@@ -131,19 +127,13 @@ public class APIPublisherLifecycleListener implements LifecycleListener {
Metadata existingMetaData = metadataManagementService.retrieveMetadata("perm-scope" +
"-mapping");
+
if (existingMetaData != null) {
existingMetaData.setMetaValue(new Gson().toJson(permScopeMap));
metadataManagementService.updateMetadata(existingMetaData);
} else {
Metadata newMetaData = new Metadata();
newMetaData.setMetaKey("perm-scope-mapping");
-
- DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
- DefaultPermissions defaultPermissions = deviceManagementConfig.getDefaultPermissions();
-
- for (DefaultPermission defaultPermission : defaultPermissions.getDefaultPermissions()) {
- permScopeMap.put(defaultPermission.getName(), defaultPermission.getScopeMapping().getKey());
- }
newMetaData.setMetaValue(new Gson().toJson(permScopeMap));
metadataManagementService.createMetadata(newMetaData);
}
diff --git a/components/apimgt-extensions/pom.xml b/components/apimgt-extensions/pom.xml
index 8120dc4f6a..a95c177917 100644
--- a/components/apimgt-extensions/pom.xml
+++ b/components/apimgt-extensions/pom.xml
@@ -22,7 +22,7 @@
io.entgra.device.mgt.core
io.entgra.device.mgt.core.parent
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../../pom.xml
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/pom.xml b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/pom.xml
index ffb8a053df..81c0147a52 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/pom.xml
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/pom.xml
@@ -21,7 +21,7 @@
io.entgra.device.mgt.core
application-mgt
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/ApplicationArtifact.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/ApplicationArtifact.java
index 371d022ec9..cbec13d3d3 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/ApplicationArtifact.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/ApplicationArtifact.java
@@ -25,16 +25,52 @@ public class ApplicationArtifact {
private String installerName;
private InputStream installerStream;
+ private String installerPath;
private String bannerName;
private InputStream bannerStream;
+ private String bannerPath;
private String iconName;
private InputStream iconStream;
+ private String iconPath;
private Map screenshots;
+ private Map screenshotPaths;
+
+ public String getInstallerPath() {
+ return installerPath;
+ }
+
+ public void setInstallerPath(String installerPath) {
+ this.installerPath = installerPath;
+ }
+
+ public String getBannerPath() {
+ return bannerPath;
+ }
+
+ public void setBannerPath(String bannerPath) {
+ this.bannerPath = bannerPath;
+ }
+
+ public String getIconPath() {
+ return iconPath;
+ }
+
+ public void setIconPath(String iconPath) {
+ this.iconPath = iconPath;
+ }
+
+ public Map getScreenshotPaths() {
+ return screenshotPaths;
+ }
+
+ public void setScreenshotPaths(Map screenshotPaths) {
+ this.screenshotPaths = screenshotPaths;
+ }
public String getInstallerName() {
return installerName;
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/CategorizedSubscriptionResult.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/CategorizedSubscriptionResult.java
new file mode 100644
index 0000000000..e685284b77
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/CategorizedSubscriptionResult.java
@@ -0,0 +1,217 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CategorizedSubscriptionResult {
+ private List installedDevices;
+ private int installedDevicesCount;
+ private List pendingDevices;
+ private int pendingDevicesCount;
+ private List errorDevices;
+ private int errorDevicesCount;
+ private List newDevices;
+ private int newDevicesCount;
+ private List subscribedDevices;
+ private int subscribedDevicesCount;
+
+ public CategorizedSubscriptionResult(List installedDevices,
+ List pendingDevices,
+ List errorDevices) {
+ this.installedDevices = installedDevices;
+ this.pendingDevices = pendingDevices;
+ this.errorDevices = errorDevices;
+ this.newDevices = null;
+ this.subscribedDevices = null;
+ }
+
+ public CategorizedSubscriptionResult(List installedDevices,
+ List pendingDevices,
+ List errorDevices,
+ List newDevices) {
+ this.installedDevices = installedDevices;
+ this.pendingDevices = pendingDevices;
+ this.errorDevices = errorDevices;
+ this.newDevices = newDevices;
+ this.subscribedDevices = null;
+ }
+
+ public CategorizedSubscriptionResult(List installedDevices,
+ List pendingDevices,
+ List errorDevices,
+ List newDevices,
+ List subscribedDevices) {
+ this.installedDevices = installedDevices;
+ this.pendingDevices = pendingDevices;
+ this.errorDevices = errorDevices;
+ this.newDevices = newDevices;
+ this.subscribedDevices = subscribedDevices;
+ }
+
+ public CategorizedSubscriptionResult(List installedDevices,
+ List pendingDevices,
+ List errorDevices,
+ List newDevices,
+ int installedDevicesCount,
+ int pendingDevicesCount,
+ int errorDevicesCount,
+ int newDevicesCount
+ ) {
+ this.installedDevices = installedDevices;
+ this.pendingDevices = pendingDevices;
+ this.errorDevices = errorDevices;
+ this.newDevices = newDevices;
+ this.subscribedDevices = null;
+ this.installedDevicesCount = installedDevicesCount;
+ this.pendingDevicesCount = pendingDevicesCount;
+ this.errorDevicesCount = errorDevicesCount;
+ this.newDevicesCount = newDevicesCount;
+ this.subscribedDevicesCount = 0;
+ }
+
+ public CategorizedSubscriptionResult(List installedDevices,
+ List pendingDevices,
+ List errorDevices,
+ List newDevices,
+ List subscribedDevices, int installedDevicesCount,
+ int pendingDevicesCount,
+ int errorDevicesCount,
+ int newDevicesCount,
+ int subscribedDevicesCount) {
+ this.installedDevices = installedDevices;
+ this.pendingDevices = pendingDevices;
+ this.errorDevices = errorDevices;
+ this.newDevices = newDevices;
+ this.subscribedDevices = subscribedDevices;
+ this.installedDevicesCount = installedDevicesCount;
+ this.pendingDevicesCount = pendingDevicesCount;
+ this.errorDevicesCount = errorDevicesCount;
+ this.newDevicesCount = newDevicesCount;
+ this.subscribedDevicesCount = subscribedDevicesCount;
+ }
+
+ public CategorizedSubscriptionResult(List devices, String tabActionStatus) {
+ switch (tabActionStatus) {
+ case "COMPLETED":
+ this.installedDevices = devices;
+ break;
+ case "PENDING":
+ this.pendingDevices = devices;
+ break;
+ case "ERROR":
+ this.errorDevices = devices;
+ break;
+ case "NEW":
+ this.newDevices = devices;
+ break;
+ case "SUBSCRIBED":
+ this.subscribedDevices = devices;
+ break;
+ default:
+ this.installedDevices = new ArrayList<>();
+ this.pendingDevices = new ArrayList<>();
+ this.errorDevices = new ArrayList<>();
+ this.newDevices = new ArrayList<>();
+ this.subscribedDevices = new ArrayList<>();
+ break;
+ }
+ }
+
+ public List getInstalledDevices() {
+ return installedDevices;
+ }
+
+ public void setInstalledDevices(List installedDevices) {
+ this.installedDevices = installedDevices;
+ }
+
+ public List getPendingDevices() {
+ return pendingDevices;
+ }
+
+ public void setPendingDevices(List pendingDevices) {
+ this.pendingDevices = pendingDevices;
+ }
+
+ public List getErrorDevices() {
+ return errorDevices;
+ }
+
+ public void setErrorDevices(List errorDevices) {
+ this.errorDevices = errorDevices;
+ }
+
+ public List getNewDevices() {
+ return newDevices;
+ }
+
+ public void setNewDevices(List newDevices) {
+ this.newDevices = newDevices;
+ }
+
+ public List getSubscribedDevices() {
+ return subscribedDevices;
+ }
+
+ public void setSubscribedDevices(List subscribedDevices) {
+ this.subscribedDevices = subscribedDevices;
+ }
+
+ public int getInstalledDevicesCount() {
+ return installedDevicesCount;
+ }
+
+ public void setInstalledDevicesCount(int installedDevicesCount) {
+ this.installedDevicesCount = installedDevicesCount;
+ }
+
+ public int getPendingDevicesCount() {
+ return pendingDevicesCount;
+ }
+
+ public void setPendingDevicesCount(int pendingDevicesCount) {
+ this.pendingDevicesCount = pendingDevicesCount;
+ }
+
+ public int getErrorDevicesCount() {
+ return errorDevicesCount;
+ }
+
+ public void setErrorDevicesCount(int errorDevicesCount) {
+ this.errorDevicesCount = errorDevicesCount;
+ }
+
+ public int getNewDevicesCount() {
+ return newDevicesCount;
+ }
+
+ public void setNewDevicesCount(int newDevicesCount) {
+ this.newDevicesCount = newDevicesCount;
+ }
+
+ public int getSubscribedDevicesCount() {
+ return subscribedDevicesCount;
+ }
+
+ public void setSubscribedDevicesCount(int subscribedDevicesCount) {
+ this.subscribedDevicesCount = subscribedDevicesCount;
+ }
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/DeviceSubscription.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/DeviceSubscription.java
new file mode 100644
index 0000000000..16e1d7553f
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/DeviceSubscription.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common;
+
+import java.sql.Timestamp;
+
+public class DeviceSubscription {
+ private int deviceId;
+ private int subscriptionId;
+ private String deviceName;
+ private String deviceIdentifier;
+ private String deviceStatus;
+ private String deviceOwner;
+ private String deviceType;
+ private String ownershipType;
+ private Timestamp dateOfLastUpdate;
+ private SubscriptionData subscriptionData;
+
+ public int getSubscriptionId() {
+ return subscriptionId;
+ }
+
+ public void setSubscriptionId(int subscriptionId) {
+ this.subscriptionId = subscriptionId;
+ }
+
+ public int getDeviceId() {
+ return deviceId;
+ }
+
+ public void setDeviceId(int deviceId) {
+ this.deviceId = deviceId;
+ }
+
+ public String getDeviceName() {
+ return deviceName;
+ }
+
+ public void setDeviceName(String deviceName) {
+ this.deviceName = deviceName;
+ }
+
+ public String getDeviceIdentifier() {
+ return deviceIdentifier;
+ }
+
+ public void setDeviceIdentifier(String deviceIdentifier) {
+ this.deviceIdentifier = deviceIdentifier;
+ }
+
+ public String getDeviceStatus() {
+ return deviceStatus;
+ }
+
+ public void setDeviceStatus(String deviceStatus) {
+ this.deviceStatus = deviceStatus;
+ }
+
+ public String getDeviceOwner() {
+ return deviceOwner;
+ }
+
+ public void setDeviceOwner(String deviceOwner) {
+ this.deviceOwner = deviceOwner;
+ }
+
+ public String getDeviceType() {
+ return deviceType;
+ }
+
+ public void setDeviceType(String deviceType) {
+ this.deviceType = deviceType;
+ }
+
+ public String getOwnershipType() {
+ return ownershipType;
+ }
+
+ public void setOwnershipType(String ownershipType) {
+ this.ownershipType = ownershipType;
+ }
+
+ public Timestamp getDateOfLastUpdate() {
+ return dateOfLastUpdate;
+ }
+
+ public void setDateOfLastUpdate(Timestamp dateOfLastUpdate) {
+ this.dateOfLastUpdate = dateOfLastUpdate;
+ }
+
+ public SubscriptionData getSubscriptionData() {
+ return subscriptionData;
+ }
+
+ public void setSubscriptionData(SubscriptionData subscriptionData) {
+ this.subscriptionData = subscriptionData;
+ }
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/DeviceSubscriptionData.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/DeviceSubscriptionData.java
index 55f2ec9edc..b77b2ba599 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/DeviceSubscriptionData.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/DeviceSubscriptionData.java
@@ -26,12 +26,22 @@ public class DeviceSubscriptionData {
private int subId;
private String action;
- private long actionTriggeredTimestamp;
+ private Timestamp actionTriggeredTimestamp;
+ private String actionTriggeredFrom;
private String actionTriggeredBy;
private String actionType;
private String status;
private Device device;
private String currentInstalledVersion;
+ private int deviceId;
+ private String deviceOwner;
+ private String deviceStatus;
+ private boolean unsubscribed;
+ private String unsubscribedBy;
+ private Timestamp unsubscribedTimestamp;
+ private String deviceName;
+ private String deviceIdentifier;
+ private String type;
public String getAction() {
return action;
@@ -41,14 +51,6 @@ public class DeviceSubscriptionData {
this.action = action;
}
- public long getActionTriggeredTimestamp() {
- return actionTriggeredTimestamp;
- }
-
- public void setActionTriggeredTimestamp(long actionTriggeredTimestamp) {
- this.actionTriggeredTimestamp = actionTriggeredTimestamp;
- }
-
public String getActionTriggeredBy() {
return actionTriggeredBy;
}
@@ -81,9 +83,13 @@ public class DeviceSubscriptionData {
this.device = device;
}
- public String getCurrentInstalledVersion() { return currentInstalledVersion; }
+ public String getCurrentInstalledVersion() {
+ return currentInstalledVersion;
+ }
- public void setCurrentInstalledVersion(String currentInstalledVersion) { this.currentInstalledVersion = currentInstalledVersion; }
+ public void setCurrentInstalledVersion(String currentInstalledVersion) {
+ this.currentInstalledVersion = currentInstalledVersion;
+ }
public int getSubId() {
return subId;
@@ -92,4 +98,92 @@ public class DeviceSubscriptionData {
public void setSubId(int subId) {
this.subId = subId;
}
+
+ public int getDeviceId() {
+ return deviceId;
+ }
+
+ public void setDeviceId(int deviceId) {
+ this.deviceId = deviceId;
+ }
+
+ public String getActionTriggeredFrom() {
+ return actionTriggeredFrom;
+ }
+
+ public void setActionTriggeredFrom(String actionTriggeredFrom) {
+ this.actionTriggeredFrom = actionTriggeredFrom;
+ }
+
+ public Timestamp getActionTriggeredTimestamp() {
+ return actionTriggeredTimestamp;
+ }
+
+ public void setActionTriggeredTimestamp(Timestamp actionTriggeredTimestamp) {
+ this.actionTriggeredTimestamp = actionTriggeredTimestamp;
+ }
+
+ public String getDeviceOwner() {
+ return deviceOwner;
+ }
+
+ public void setDeviceOwner(String deviceOwner) {
+ this.deviceOwner = deviceOwner;
+ }
+
+ public String getDeviceStatus() {
+ return deviceStatus;
+ }
+
+ public void setDeviceStatus(String deviceStatus) {
+ this.deviceStatus = deviceStatus;
+ }
+
+ public boolean isUnsubscribed() {
+ return unsubscribed;
+ }
+
+ public void setUnsubscribed(boolean unsubscribed) {
+ this.unsubscribed = unsubscribed;
+ }
+
+ public String getUnsubscribedBy() {
+ return unsubscribedBy;
+ }
+
+ public void setUnsubscribedBy(String unsubscribedBy) {
+ this.unsubscribedBy = unsubscribedBy;
+ }
+
+ public Timestamp getUnsubscribedTimestamp() {
+ return unsubscribedTimestamp;
+ }
+
+ public void setUnsubscribedTimestamp(Timestamp unsubscribedTimestamp) {
+ this.unsubscribedTimestamp = unsubscribedTimestamp;
+ }
+
+ public String getDeviceName() {
+ return deviceName;
+ }
+
+ public void setDeviceName(String deviceName) {
+ this.deviceName = deviceName;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getDeviceIdentifier() {
+ return deviceIdentifier;
+ }
+
+ public void setDeviceIdentifier(String deviceIdentifier) {
+ this.deviceIdentifier = deviceIdentifier;
+ }
}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/DeviceSubscriptionFilterCriteria.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/DeviceSubscriptionFilterCriteria.java
new file mode 100644
index 0000000000..298a5221eb
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/DeviceSubscriptionFilterCriteria.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common;
+
+public class DeviceSubscriptionFilterCriteria {
+ private String name;
+ private String owner;
+ private String deviceStatus;
+ private String filteringDeviceSubscriptionStatus; // COMPLETE, PENDING ...
+ private String triggeredBy;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getOwner() {
+ return owner;
+ }
+
+ public void setOwner(String owner) {
+ this.owner = owner;
+ }
+
+ public String getDeviceStatus() {
+ return deviceStatus;
+ }
+
+ public void setDeviceStatus(String deviceStatus) {
+ this.deviceStatus = deviceStatus;
+ }
+
+ public String getFilteringDeviceSubscriptionStatus() {
+ return filteringDeviceSubscriptionStatus;
+ }
+
+ public void setFilteringDeviceSubscriptionStatus(String filteringDeviceSubscriptionStatus) {
+ this.filteringDeviceSubscriptionStatus = filteringDeviceSubscriptionStatus;
+ }
+
+ public String getTriggeredBy() {
+ return triggeredBy;
+ }
+
+ public void setTriggeredBy(String triggeredBy) {
+ this.triggeredBy = triggeredBy;
+ }
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/Filter.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/Filter.java
index 272e9ba8a3..88f7e90a0a 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/Filter.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/Filter.java
@@ -118,6 +118,11 @@ public class Filter {
*/
private boolean isNotRetired;
+ /**
+ * To check whether web applications should be returned
+ */
+ private boolean withWebApps;
+
public int getLimit() {
return limit;
}
@@ -221,4 +226,12 @@ public class Filter {
public void setNotRetired(boolean notRetired) {
isNotRetired = notRetired;
}
+
+ public boolean isWithWebApps() {
+ return withWebApps;
+ }
+
+ public void setWithWebApps(boolean withWebApps) {
+ this.withWebApps = withWebApps;
+ }
}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/SubscriptionData.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/SubscriptionData.java
new file mode 100644
index 0000000000..cef9a12508
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/SubscriptionData.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common;
+
+import java.sql.Timestamp;
+
+public class SubscriptionData {
+ private String deviceSubscriptionStatus;
+ private String triggeredBy;
+ private String subscriptionType;
+ private Timestamp triggeredAt;
+ private int subscriptionId;
+
+ public String getDeviceSubscriptionStatus() {
+ return deviceSubscriptionStatus;
+ }
+
+ public void setDeviceSubscriptionStatus(String deviceSubscriptionStatus) {
+ this.deviceSubscriptionStatus = deviceSubscriptionStatus;
+ }
+
+ public String getTriggeredBy() {
+ return triggeredBy;
+ }
+
+ public void setTriggeredBy(String triggeredBy) {
+ this.triggeredBy = triggeredBy;
+ }
+
+ public String getSubscriptionType() {
+ return subscriptionType;
+ }
+
+ public void setSubscriptionType(String subscriptionType) {
+ this.subscriptionType = subscriptionType;
+ }
+
+ public Timestamp getTriggeredAt() {
+ return triggeredAt;
+ }
+
+ public void setTriggeredAt(Timestamp triggeredAt) {
+ this.triggeredAt = triggeredAt;
+ }
+
+ public int getSubscriptionId() {
+ return subscriptionId;
+ }
+
+ public void setSubscriptionId(int subscriptionId) {
+ this.subscriptionId = subscriptionId;
+ }
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/SubscriptionEntity.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/SubscriptionEntity.java
new file mode 100644
index 0000000000..40c1b2f4a7
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/SubscriptionEntity.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common;
+
+import java.sql.Timestamp;
+
+public class SubscriptionEntity {
+ private String identity;
+ private String subscribedBy;
+ private Timestamp subscribedTimestamp;
+ private boolean unsubscribed;
+ private String unsubscribedBy;
+ private Timestamp unsubscribedTimestamp;
+ private int applicationReleaseId;
+
+ public String getIdentity() {
+ return identity;
+ }
+
+ public void setIdentity(String identity) {
+ this.identity = identity;
+ }
+
+ public String getSubscribedBy() {
+ return subscribedBy;
+ }
+
+ public void setSubscribedBy(String subscribedBy) {
+ this.subscribedBy = subscribedBy;
+ }
+
+ public Timestamp getSubscribedTimestamp() {
+ return subscribedTimestamp;
+ }
+
+ public void setSubscribedTimestamp(Timestamp subscribedTimestamp) {
+ this.subscribedTimestamp = subscribedTimestamp;
+ }
+
+ public boolean getUnsubscribed() {
+ return unsubscribed;
+ }
+
+ public void setUnsubscribed(boolean unsubscribed) {
+ this.unsubscribed = unsubscribed;
+ }
+
+ public String getUnsubscribedBy() {
+ return unsubscribedBy;
+ }
+
+ public void setUnsubscribedBy(String unsubscribedBy) {
+ this.unsubscribedBy = unsubscribedBy;
+ }
+
+ public Timestamp getUnsubscribedTimestamp() {
+ return unsubscribedTimestamp;
+ }
+
+ public void setUnsubscribedTimestamp(Timestamp unsubscribedTimestamp) {
+ this.unsubscribedTimestamp = unsubscribedTimestamp;
+ }
+
+ public int getApplicationReleaseId() {
+ return applicationReleaseId;
+ }
+
+ public void setApplicationReleaseId(int applicationReleaseId) {
+ this.applicationReleaseId = applicationReleaseId;
+ }
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/SubscriptionInfo.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/SubscriptionInfo.java
new file mode 100644
index 0000000000..6af03aa61a
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/SubscriptionInfo.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common;
+
+public class SubscriptionInfo {
+ private String applicationUUID;
+ private String subscriptionType;
+ private String deviceSubscriptionStatus;
+ private String identifier;
+ private String subscriptionStatus;
+ private DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria;
+
+ public String getApplicationUUID() {
+ return applicationUUID;
+ }
+
+ public void setApplicationUUID(String applicationUUID) {
+ this.applicationUUID = applicationUUID;
+ }
+
+ public String getSubscriptionType() {
+ return subscriptionType;
+ }
+
+ public void setSubscriptionType(String subscriptionType) {
+ this.subscriptionType = subscriptionType;
+ }
+
+ public String getDeviceSubscriptionStatus() {
+ return deviceSubscriptionStatus;
+ }
+
+ public void setDeviceSubscriptionStatus(String deviceSubscriptionStatus) {
+ this.deviceSubscriptionStatus = deviceSubscriptionStatus;
+ }
+
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ public void setIdentifier(String identifier) {
+ this.identifier = identifier;
+ }
+
+ public String getSubscriptionStatus() {
+ return subscriptionStatus;
+ }
+
+ public void setSubscriptionStatus(String subscriptionStatus) {
+ this.subscriptionStatus = subscriptionStatus;
+ }
+
+ public DeviceSubscriptionFilterCriteria getDeviceSubscriptionFilterCriteria() {
+ return deviceSubscriptionFilterCriteria;
+ }
+
+ public void setDeviceSubscriptionFilterCriteria(DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria) {
+ this.deviceSubscriptionFilterCriteria = deviceSubscriptionFilterCriteria;
+ }
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/SubscriptionMetadata.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/SubscriptionMetadata.java
new file mode 100644
index 0000000000..bd487dfea4
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/SubscriptionMetadata.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class SubscriptionMetadata {
+ public static final String SUBSCRIPTION_STATUS_UNSUBSCRIBED = "unsubscribed";
+ public static final class DeviceSubscriptionStatus {
+ public static final String NEW = "NEW";
+ public static final String PENDING = "PENDING";
+ public static final String COMPLETED = "COMPLETED";
+ public static final String ERROR = "ERROR";
+ public static final String INVALID = "INVALID";
+ public static final String UNAUTHORIZED = "UNAUTHORIZED";
+ public static final String IN_PROGRESS = "IN_PROGRESS";
+ public static final String REPEATED = "REPEATED";
+ }
+
+ public static final class SubscriptionTypes {
+ public static final String ROLE = "role";
+ public static final String DEVICE = "device";
+ public static final String GROUP = "group";
+ public static final String USER = "user";
+ }
+
+ public static final class DBSubscriptionStatus {
+ public static final List COMPLETED_STATUS_LIST =
+ Collections.singletonList(DeviceSubscriptionStatus.COMPLETED);
+ public static final List ERROR_STATUS_LIST =
+ Arrays.asList(DeviceSubscriptionStatus.ERROR, DeviceSubscriptionStatus.INVALID, DeviceSubscriptionStatus.UNAUTHORIZED);
+ public static final List PENDING_STATUS_LIST =
+ Arrays.asList(DeviceSubscriptionStatus.PENDING, DeviceSubscriptionStatus.IN_PROGRESS, DeviceSubscriptionStatus.REPEATED);
+ }
+
+ public static Map> deviceSubscriptionStatusToDBSubscriptionStatusMap;
+ static {
+ Map> statusMap = new HashMap<>();
+ statusMap.put(DeviceSubscriptionStatus.COMPLETED, DBSubscriptionStatus.COMPLETED_STATUS_LIST);
+ statusMap.put(DeviceSubscriptionStatus.PENDING, DBSubscriptionStatus.PENDING_STATUS_LIST);
+ statusMap.put(DeviceSubscriptionStatus.IN_PROGRESS, Collections.singletonList(DeviceSubscriptionStatus.IN_PROGRESS));
+ statusMap.put(DeviceSubscriptionStatus.REPEATED, Collections.singletonList(DeviceSubscriptionStatus.REPEATED));
+ statusMap.put(DeviceSubscriptionStatus.ERROR, DBSubscriptionStatus.ERROR_STATUS_LIST);
+ statusMap.put(DeviceSubscriptionStatus.INVALID,Collections.singletonList(DeviceSubscriptionStatus.INVALID));
+ statusMap.put(DeviceSubscriptionStatus.UNAUTHORIZED,Collections.singletonList(DeviceSubscriptionStatus.UNAUTHORIZED));
+ deviceSubscriptionStatusToDBSubscriptionStatusMap = Collections.unmodifiableMap(statusMap);
+ }
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/SubscriptionResponse.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/SubscriptionResponse.java
new file mode 100644
index 0000000000..aeaeba70be
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/SubscriptionResponse.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common;
+
+import java.util.List;
+
+public class SubscriptionResponse {
+ private String applicationUUID;
+ private int count;
+ private List> data;
+
+ public SubscriptionResponse(String applicationUUID, int count, List> data) {
+ this.applicationUUID = applicationUUID;
+ this.count = count;
+ this.data = data;
+ }
+
+ public SubscriptionResponse(String applicationUUID, List> data) {
+ this.applicationUUID = applicationUUID;
+ this.data = data;
+ }
+
+ public String getApplicationUUID() {
+ return applicationUUID;
+ }
+
+ public void setApplicationUUID(String applicationUUID) {
+ this.applicationUUID = applicationUUID;
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+ public void setCount(int count) {
+ this.count = count;
+ }
+
+ public List> getData() {
+ return data;
+ }
+
+ public void setData(List> data) {
+ this.data = data;
+ }
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/SubscriptionStatistics.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/SubscriptionStatistics.java
new file mode 100644
index 0000000000..80a10e98c5
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/SubscriptionStatistics.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common;
+
+public class SubscriptionStatistics {
+ private float completedPercentage;
+ private float failedPercentage;
+ private float pendingPercentage;
+ private float newDevicesPercentage;
+
+ public SubscriptionStatistics() {}
+ public SubscriptionStatistics(float completedPercentage, float failedPercentage, float pendingPercentage,
+ float newDevicesPercentage) {
+ this.completedPercentage = completedPercentage;
+ this.failedPercentage = failedPercentage;
+ this.pendingPercentage = pendingPercentage;
+ this.newDevicesPercentage = newDevicesPercentage;
+ }
+
+ public float getCompletedPercentage() {
+ return completedPercentage;
+ }
+
+ public void setCompletedPercentage(float completedPercentage) {
+ this.completedPercentage = completedPercentage;
+ }
+
+ public float getFailedPercentage() {
+ return failedPercentage;
+ }
+
+ public void setFailedPercentage(float failedPercentage) {
+ this.failedPercentage = failedPercentage;
+ }
+
+ public float getPendingPercentage() {
+ return pendingPercentage;
+ }
+
+ public void setPendingPercentage(float pendingPercentage) {
+ this.pendingPercentage = pendingPercentage;
+ }
+
+ public float getNewDevicesPercentage() {
+ return newDevicesPercentage;
+ }
+
+ public void setNewDevicesPercentage(float newDevicesPercentage) {
+ this.newDevicesPercentage = newDevicesPercentage;
+ }
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/CategorizedSubscriptionCountsDTO.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/CategorizedSubscriptionCountsDTO.java
new file mode 100644
index 0000000000..2ee5bb3cb0
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/CategorizedSubscriptionCountsDTO.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common.dto;
+
+public class CategorizedSubscriptionCountsDTO {
+ private String subscriptionType;
+ private int subscriptionCount;
+ private int unsubscriptionCount;
+
+ public CategorizedSubscriptionCountsDTO(String subscriptionType, int subscriptionCount, int unsubscriptionCount) {
+ this.subscriptionType = subscriptionType;
+ this.subscriptionCount = subscriptionCount;
+ this.unsubscriptionCount = unsubscriptionCount;
+ }
+
+ public String getSubscriptionType() {
+ return subscriptionType;
+ }
+
+ public void setSubscriptionType(String subscriptionType) {
+ this.subscriptionType = subscriptionType;
+ }
+
+ public int getSubscriptionCount() {
+ return subscriptionCount;
+ }
+
+ public void setSubscriptionCount(int subscriptionCount) {
+ this.subscriptionCount = subscriptionCount;
+ }
+
+ public int getUnsubscriptionCount() {
+ return unsubscriptionCount;
+ }
+
+ public void setUnsubscriptionCount(int unsubscriptionCount) {
+ this.unsubscriptionCount = unsubscriptionCount;
+ }
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/DeviceOperationDTO.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/DeviceOperationDTO.java
new file mode 100644
index 0000000000..75699431a2
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/DeviceOperationDTO.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common.dto;
+
+import io.entgra.device.mgt.core.device.mgt.core.dto.OperationResponseDTO;
+
+import java.sql.Timestamp;
+import java.util.List;
+
+public class DeviceOperationDTO {
+ private int deviceId;
+ private String uuid;
+ private String status;
+ private int operationId;
+ private String actionTriggeredFrom;
+ private Timestamp actionTriggeredAt;
+ private int appReleaseId;
+ private String operationCode;
+ private Object operationDetails;
+ private Object operationProperties;
+ private List operationResponses;
+
+ public int getDeviceId() {
+ return deviceId;
+ }
+
+ public void setDeviceId(int deviceId) {
+ this.deviceId = deviceId;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public int getOperationId() {
+ return operationId;
+ }
+
+ public void setOperationId(int operationId) {
+ this.operationId = operationId;
+ }
+
+ public String getActionTriggeredFrom() {
+ return actionTriggeredFrom;
+ }
+
+ public void setActionTriggeredFrom(String actionTriggeredFrom) {
+ this.actionTriggeredFrom = actionTriggeredFrom;
+ }
+
+ public Timestamp getActionTriggeredAt() {
+ return actionTriggeredAt;
+ }
+
+ public void setActionTriggeredAt(Timestamp actionTriggeredAt) {
+ this.actionTriggeredAt = actionTriggeredAt;
+ }
+
+ public int getAppReleaseId() {
+ return appReleaseId;
+ }
+
+ public void setAppReleaseId(int appReleaseId) {
+ this.appReleaseId = appReleaseId;
+ }
+
+ public String getOperationCode() {
+ return operationCode;
+ }
+
+ public void setOperationCode(String operationCode) {
+ this.operationCode = operationCode;
+ }
+
+ public Object getOperationDetails() {
+ return operationDetails;
+ }
+
+ public void setOperationDetails(Object operationDetails) {
+ this.operationDetails = operationDetails;
+ }
+
+ public Object getOperationProperties() {
+ return operationProperties;
+ }
+
+ public void setOperationProperties(Object operationProperties) {
+ this.operationProperties = operationProperties;
+ }
+
+ public List getOperationResponses() {
+ return operationResponses;
+ }
+
+ public void setOperationResponses(List operationResponses) {
+ this.operationResponses = operationResponses;
+ }
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/DeviceSubscriptionDTO.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/DeviceSubscriptionDTO.java
index 9a30ec07c2..aa4f221ca3 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/DeviceSubscriptionDTO.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/DeviceSubscriptionDTO.java
@@ -19,6 +19,7 @@
package io.entgra.device.mgt.core.application.mgt.common.dto;
import java.sql.Timestamp;
+import java.util.Objects;
public class DeviceSubscriptionDTO {
@@ -31,44 +32,120 @@ public class DeviceSubscriptionDTO {
private String actionTriggeredFrom;
private String status;
private int deviceId;
+ private int appReleaseId;
+ private String appUuid;
- public int getId() { return id; }
+ public DeviceSubscriptionDTO() {
- public void setId(int id) { this.id = id; }
+ }
- public String getSubscribedBy() { return subscribedBy; }
+ public DeviceSubscriptionDTO(int deviceId) {
+ this.deviceId = deviceId;
+ }
- public void setSubscribedBy(String subscribedBy) { this.subscribedBy = subscribedBy; }
+ public DeviceSubscriptionDTO(int deviceId, String status) {
+ this.deviceId = deviceId;
+ this.status = status;
+ }
- public Timestamp getSubscribedTimestamp() { return subscribedTimestamp; }
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getSubscribedBy() {
+ return subscribedBy;
+ }
+
+ public void setSubscribedBy(String subscribedBy) {
+ this.subscribedBy = subscribedBy;
+ }
+
+ public Timestamp getSubscribedTimestamp() {
+ return subscribedTimestamp;
+ }
public void setSubscribedTimestamp(Timestamp subscribedTimestamp) {
this.subscribedTimestamp = subscribedTimestamp;
}
- public boolean isUnsubscribed() { return isUnsubscribed; }
+ public boolean isUnsubscribed() {
+ return isUnsubscribed;
+ }
- public void setUnsubscribed(boolean unsubscribed) { isUnsubscribed = unsubscribed; }
+ public void setUnsubscribed(boolean unsubscribed) {
+ isUnsubscribed = unsubscribed;
+ }
- public String getUnsubscribedBy() { return unsubscribedBy; }
+ public String getUnsubscribedBy() {
+ return unsubscribedBy;
+ }
- public void setUnsubscribedBy(String unsubscribedBy) { this.unsubscribedBy = unsubscribedBy; }
+ public void setUnsubscribedBy(String unsubscribedBy) {
+ this.unsubscribedBy = unsubscribedBy;
+ }
- public Timestamp getUnsubscribedTimestamp() { return unsubscribedTimestamp; }
+ public Timestamp getUnsubscribedTimestamp() {
+ return unsubscribedTimestamp;
+ }
public void setUnsubscribedTimestamp(Timestamp unsubscribedTimestamp) {
this.unsubscribedTimestamp = unsubscribedTimestamp;
}
- public String getActionTriggeredFrom() { return actionTriggeredFrom; }
+ public String getActionTriggeredFrom() {
+ return actionTriggeredFrom;
+ }
- public void setActionTriggeredFrom(String actionTriggeredFrom) { this.actionTriggeredFrom = actionTriggeredFrom; }
+ public void setActionTriggeredFrom(String actionTriggeredFrom) {
+ this.actionTriggeredFrom = actionTriggeredFrom;
+ }
- public String getStatus() { return status; }
+ public String getStatus() {
+ return status;
+ }
- public void setStatus(String status) { this.status = status; }
+ public void setStatus(String status) {
+ this.status = status;
+ }
- public int getDeviceId() { return deviceId; }
+ public int getDeviceId() {
+ return deviceId;
+ }
- public void setDeviceId(int deviceId) { this.deviceId = deviceId; }
+ public void setDeviceId(int deviceId) {
+ this.deviceId = deviceId;
+ }
+
+ public int getAppReleaseId() {
+ return appReleaseId;
+ }
+
+ public void setAppReleaseId(int appReleaseId) {
+ this.appReleaseId = appReleaseId;
+ }
+
+ public String getAppUuid() {
+ return appUuid;
+ }
+
+ public void setAppUuid(String appUuid) {
+ this.appUuid = appUuid;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ DeviceSubscriptionDTO that = (DeviceSubscriptionDTO) o;
+ return deviceId == that.deviceId;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(deviceId);
+ }
}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/DeviceSubscriptionResponseDTO.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/DeviceSubscriptionResponseDTO.java
new file mode 100644
index 0000000000..5d132bfd37
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/DeviceSubscriptionResponseDTO.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common.dto;
+
+import io.entgra.device.mgt.core.application.mgt.common.CategorizedSubscriptionResult;
+
+import java.util.Map;
+
+public class DeviceSubscriptionResponseDTO {
+ private int deviceCount;
+ private Map statusPercentages;
+ private CategorizedSubscriptionResult devices;
+
+ public DeviceSubscriptionResponseDTO(int deviceCount, Map statusPercentages,
+ CategorizedSubscriptionResult devices) {
+ this.deviceCount = deviceCount;
+ this.statusPercentages = statusPercentages;
+ this.devices = devices;
+ }
+
+ public int getDeviceCount() {
+ return deviceCount;
+ }
+
+ public void setDeviceCount(int deviceCount) {
+ this.deviceCount = deviceCount;
+ }
+
+ public Map getStatusPercentages() {
+ return statusPercentages;
+ }
+
+ public void setStatusPercentages(Map statusPercentages) {
+ this.statusPercentages = statusPercentages;
+ }
+
+ public CategorizedSubscriptionResult getDevices() {
+ return devices;
+ }
+
+ public void setDevices(CategorizedSubscriptionResult devices) {
+ this.devices = devices;
+ }
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/GroupSubscriptionDTO.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/GroupSubscriptionDTO.java
index 3d9e6dfd2c..76a7b39d2d 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/GroupSubscriptionDTO.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/GroupSubscriptionDTO.java
@@ -22,6 +22,7 @@ import java.sql.Timestamp;
public class GroupSubscriptionDTO {
private int id;
+ private String groupName;
private String subscribedBy;
private Timestamp subscribedTimestamp;
private boolean isUnsubscribed;
@@ -29,6 +30,7 @@ public class GroupSubscriptionDTO {
private Timestamp unsubscribedTimestamp;
private String subscribedFrom;
private int groupdId;
+ private int appReleaseId;
public int getId() { return id; }
@@ -61,4 +63,20 @@ public class GroupSubscriptionDTO {
public int getGroupdId() { return groupdId; }
public void setGroupdId(int groupdId) { this.groupdId = groupdId; }
+
+ public String getGroupName() {
+ return groupName;
+ }
+
+ public void setGroupName(String groupName) {
+ this.groupName = groupName;
+ }
+
+ public int getAppReleaseId() {
+ return appReleaseId;
+ }
+
+ public void setAppReleaseId(int appReleaseId) {
+ this.appReleaseId = appReleaseId;
+ }
}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/RoleSubscriptionDTO.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/RoleSubscriptionDTO.java
index 869ed1fd6d..b8139181de 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/RoleSubscriptionDTO.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/RoleSubscriptionDTO.java
@@ -18,51 +18,115 @@
package io.entgra.device.mgt.core.application.mgt.common.dto;
+import io.entgra.device.mgt.core.application.mgt.common.CategorizedSubscriptionResult;
+
import java.sql.Timestamp;
+import java.util.Map;
public class RoleSubscriptionDTO {
- private int id;
private String subscribedBy;
private Timestamp subscribedTimestamp;
private boolean isUnsubscribed;
+ private boolean unsubscribed;
private String unsubscribedBy;
private Timestamp unsubscribedTimestamp;
private String subscribedFrom;
private String roleName;
+ private int appReleaseId;
+ private int deviceCount;
+ private Map statusPercentages;
+ private CategorizedSubscriptionResult devices;
- public int getId() { return id; }
+ public String getSubscribedBy() {
+ return subscribedBy;
+ }
- public void setId(int id) { this.id = id; }
+ public void setSubscribedBy(String subscribedBy) {
+ this.subscribedBy = subscribedBy;
+ }
- public String getSubscribedBy() { return subscribedBy; }
-
- public void setSubscribedBy(String subscribedBy) { this.subscribedBy = subscribedBy; }
-
- public Timestamp getSubscribedTimestamp() { return subscribedTimestamp; }
+ public Timestamp getSubscribedTimestamp() {
+ return subscribedTimestamp;
+ }
public void setSubscribedTimestamp(Timestamp subscribedTimestamp) {
this.subscribedTimestamp = subscribedTimestamp;
}
- public boolean isUnsubscribed() { return isUnsubscribed; }
+ public boolean getUnsubscribed() {
+ return unsubscribed;
+ }
- public void setUnsubscribed(boolean unsubscribed) { isUnsubscribed = unsubscribed; }
+ public void setUnsubscribed(boolean unsubscribed) {
+ this.unsubscribed = unsubscribed;
+ }
- public String getUnsubscribedBy() { return unsubscribedBy; }
+ public boolean isUnsubscribed() {
+ return isUnsubscribed;
+ }
- public void setUnsubscribedBy(String unsubscribedBy) { this.unsubscribedBy = unsubscribedBy; }
+ public String getUnsubscribedBy() {
+ return unsubscribedBy;
+ }
- public Timestamp getUnsubscribedTimestamp() { return unsubscribedTimestamp; }
+ public void setUnsubscribedBy(String unsubscribedBy) {
+ this.unsubscribedBy = unsubscribedBy;
+ }
+
+ public Timestamp getUnsubscribedTimestamp() {
+ return unsubscribedTimestamp;
+ }
public void setUnsubscribedTimestamp(Timestamp unsubscribedTimestamp) {
this.unsubscribedTimestamp = unsubscribedTimestamp;
}
- public String getSubscribedFrom() { return subscribedFrom; }
+ public String getSubscribedFrom() {
+ return subscribedFrom;
+ }
- public void setSubscribedFrom(String subscribedFrom) { this.subscribedFrom = subscribedFrom; }
+ public void setSubscribedFrom(String subscribedFrom) {
+ this.subscribedFrom = subscribedFrom;
+ }
- public String getRoleName() { return roleName; }
+ public String getRoleName() {
+ return roleName;
+ }
+
+ public void setRoleName(String roleName) {
+ this.roleName = roleName;
+ }
+
+ public int getAppReleaseId() {
+ return appReleaseId;
+ }
+
+ public void setAppReleaseId(int appReleaseId) {
+ this.appReleaseId = appReleaseId;
+ }
+
+ public int getDeviceCount() {
+ return deviceCount;
+ }
+
+ public void setDeviceCount(int deviceCount) {
+ this.deviceCount = deviceCount;
+ }
+
+ public Map getStatusPercentages() {
+ return statusPercentages;
+ }
+
+ public void setStatusPercentages(Map statusPercentages) {
+ this.statusPercentages = statusPercentages;
+ }
+
+ public CategorizedSubscriptionResult getDevices() {
+ return devices;
+ }
+
+ public void setDevices(CategorizedSubscriptionResult devices) {
+ this.devices = devices;
+ }
- public void setRoleName(String roleName) { this.roleName = roleName; }
}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/SubscriptionResponseDTO.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/SubscriptionResponseDTO.java
new file mode 100644
index 0000000000..03967ec94d
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/SubscriptionResponseDTO.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common.dto;
+
+import java.util.List;
+
+public class SubscriptionResponseDTO {
+
+ private String UUID;
+ private List subscriptions;
+ private List DevicesOperations;
+
+ public String getUUID() {
+ return UUID;
+ }
+
+ public void setUUID(String UUID) {
+ this.UUID = UUID;
+ }
+
+ public List getDevicesOperations() {
+ return DevicesOperations;
+ }
+
+ public void setDevicesOperations(List devicesOperations) {
+ DevicesOperations = devicesOperations;
+ }
+
+ public List getSubscriptions() {
+ return subscriptions;
+ }
+
+ public void setSubscriptions(List subscriptions) {
+ this.subscriptions = subscriptions;
+ }
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/SubscriptionStatisticDTO.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/SubscriptionStatisticDTO.java
new file mode 100644
index 0000000000..c50e47a5ac
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/SubscriptionStatisticDTO.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common.dto;
+
+public class SubscriptionStatisticDTO {
+ private int completedDeviceCount = 0;
+ private int pendingDevicesCount = 0;
+ private int failedDevicesCount = 0;
+
+ public void addToComplete(int count) {
+ completedDeviceCount += count;
+ }
+
+ public void addToPending(int count) {
+ pendingDevicesCount += count;
+ }
+
+ public void addToFailed(int count) {
+ failedDevicesCount += count ;
+ }
+
+ public int getCompletedDeviceCount() {
+ return completedDeviceCount;
+ }
+
+ public void setCompletedDeviceCount(int completedDeviceCount) {
+ this.completedDeviceCount = completedDeviceCount;
+ }
+
+ public int getPendingDevicesCount() {
+ return pendingDevicesCount;
+ }
+
+ public void setPendingDevicesCount(int pendingDevicesCount) {
+ this.pendingDevicesCount = pendingDevicesCount;
+ }
+
+ public int getFailedDevicesCount() {
+ return failedDevicesCount;
+ }
+
+ public void setFailedDevicesCount(int failedDevicesCount) {
+ this.failedDevicesCount = failedDevicesCount;
+ }
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/SubscriptionsDTO.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/SubscriptionsDTO.java
new file mode 100644
index 0000000000..cb127696e3
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/dto/SubscriptionsDTO.java
@@ -0,0 +1,162 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.common.dto;
+
+import io.entgra.device.mgt.core.application.mgt.common.CategorizedSubscriptionResult;
+
+import java.sql.Timestamp;
+import java.util.Map;
+
+public class SubscriptionsDTO {
+ private int id;
+ private String owner;
+ private String name;
+ private String subscribedBy;
+ private Timestamp subscribedTimestamp;
+ private boolean unsubscribed;
+ private String unsubscribedBy;
+ private Timestamp unsubscribedTimestamp;
+ private String subscribedFrom;
+ private int appReleaseId;
+ private int deviceCount;
+ private String deviceOwner;
+ private String deviceStatus;
+ private Map statusPercentages;
+ private CategorizedSubscriptionResult devices;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getOwner() {
+ return owner;
+ }
+
+ public void setOwner(String owner) {
+ this.owner = owner;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getSubscribedBy() {
+ return subscribedBy;
+ }
+
+ public void setSubscribedBy(String subscribedBy) {
+ this.subscribedBy = subscribedBy;
+ }
+
+ public Timestamp getSubscribedTimestamp() {
+ return subscribedTimestamp;
+ }
+
+ public void setSubscribedTimestamp(Timestamp subscribedTimestamp) {
+ this.subscribedTimestamp = subscribedTimestamp;
+ }
+
+ public String getUnsubscribedBy() {
+ return unsubscribedBy;
+ }
+
+ public void setUnsubscribedBy(String unsubscribedBy) {
+ this.unsubscribedBy = unsubscribedBy;
+ }
+
+ public Timestamp getUnsubscribedTimestamp() {
+ return unsubscribedTimestamp;
+ }
+
+ public void setUnsubscribedTimestamp(Timestamp unsubscribedTimestamp) {
+ this.unsubscribedTimestamp = unsubscribedTimestamp;
+ }
+
+ public String getSubscribedFrom() {
+ return subscribedFrom;
+ }
+
+ public void setSubscribedFrom(String subscribedFrom) {
+ this.subscribedFrom = subscribedFrom;
+ }
+
+ public int getAppReleaseId() {
+ return appReleaseId;
+ }
+
+ public void setAppReleaseId(int appReleaseId) {
+ this.appReleaseId = appReleaseId;
+ }
+
+ public int getDeviceCount() {
+ return deviceCount;
+ }
+
+ public void setDeviceCount(int deviceCount) {
+ this.deviceCount = deviceCount;
+ }
+
+ public String getDeviceOwner() {
+ return deviceOwner;
+ }
+
+ public void setDeviceOwner(String deviceOwner) {
+ this.deviceOwner = deviceOwner;
+ }
+
+ public String getDeviceStatus() {
+ return deviceStatus;
+ }
+
+ public void setDeviceStatus(String deviceStatus) {
+ this.deviceStatus = deviceStatus;
+ }
+
+ public Map getStatusPercentages() {
+ return statusPercentages;
+ }
+
+ public void setStatusPercentages(Map statusPercentages) {
+ this.statusPercentages = statusPercentages;
+ }
+
+ public CategorizedSubscriptionResult getDevices() {
+ return devices;
+ }
+
+ public void setDevices(CategorizedSubscriptionResult devices) {
+ this.devices = devices;
+ }
+
+ public boolean getUnsubscribed() {
+ return unsubscribed;
+ }
+
+ public void setUnsubscribed(boolean unsubscribed) {
+ this.unsubscribed = unsubscribed;
+ }
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/ApplicationManager.java
index 4a1be2ea1e..7e13353980 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/ApplicationManager.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/ApplicationManager.java
@@ -546,5 +546,20 @@ public interface ApplicationManager {
* @throws ApplicationManagementException thrown if an error occurs when deleting data
*/
void deleteApplicationDataOfTenant(int tenantId) throws ApplicationManagementException;
+
+ /**
+ * Delete all application related data of a tenant by tenant Domain
+ *
+ * @param tenantDomain Domain of the Tenant
+ * @throws ApplicationManagementException thrown if an error occurs when deleting data
+ */
void deleteApplicationDataByTenantDomain(String tenantDomain) throws ApplicationManagementException;
+
+ /**
+ * Delete all Application artifacts related to a tenant by Tenant Domain
+ *
+ * @param tenantDomain Domain of the Tenant
+ * @throws ApplicationManagementException thrown if an error occurs when deleting app folders
+ */
+ void deleteApplicationArtifactsByTenantDomain(String tenantDomain) throws ApplicationManagementException;
}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/ApplicationStorageManager.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/ApplicationStorageManager.java
index 698c57f55a..bab015e97e 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/ApplicationStorageManager.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/ApplicationStorageManager.java
@@ -140,4 +140,14 @@ public interface ApplicationStorageManager {
* @throws ApplicationStorageManagementException thrown if
*/
void deleteAppFolderOfTenant(int tenantId) throws ApplicationStorageManagementException;
+
+ /**
+ * Get absolute path of a file describe by hashVal, folder, file name and tenantId
+ * @param hashVal Hash value of the application release.
+ * @param folderName Folder name file resides.
+ * @param fileName File name of the file.
+ * @param tenantId Tenant ID
+ * @return Absolute path
+ */
+ String getAbsolutePathOfFile(String hashVal, String folderName, String fileName, int tenantId);
}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/SubscriptionManager.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/SubscriptionManager.java
index e06a17cb9b..1e70f1b9d6 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/SubscriptionManager.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/SubscriptionManager.java
@@ -18,11 +18,23 @@
package io.entgra.device.mgt.core.application.mgt.common.services;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationInstallResponse;
+import io.entgra.device.mgt.core.application.mgt.common.CategorizedSubscriptionResult;
+import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscription;
+import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionData;
import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionEntity;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionResponse;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionStatistics;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionType;
+import io.entgra.device.mgt.core.application.mgt.common.dto.CategorizedSubscriptionCountsDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ScheduledSubscriptionDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionsDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceOperationDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionResponseDTO;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.device.mgt.core.application.mgt.common.exception.SubscriptionManagementException;
-import io.entgra.device.mgt.core.application.mgt.common.SubscriptionType;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
@@ -194,7 +206,7 @@ public interface SubscriptionManager {
* application release for given UUID, if an error occurred while getting device details of subscribed device ids,
* if an error occurred while getting subscription details of given application release UUID.
*/
- PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus, String action, String installedVersion)
+ CategorizedSubscriptionResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus, String action, String installedVersion)
throws ApplicationManagementException;
/***
@@ -217,4 +229,57 @@ public interface SubscriptionManager {
* @throws {@link SubscriptionManagementException} Exception of the subscription management
*/
Activity getOperationAppDetails(String id) throws SubscriptionManagementException;
+
+ /**
+ * Get subscription data describes by {@link SubscriptionInfo} entity
+ * @param subscriptionInfo {@link SubscriptionInfo}
+ * @param limit Limit value
+ * @param offset Offset value
+ * @return {@link SubscriptionResponse}
+ * @throws ApplicationManagementException Throws when error encountered while getting subscription data
+ */
+ SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
+ throws ApplicationManagementException;
+
+ /**
+ * Get status based subscription data describes by {@link SubscriptionInfo} entity
+ * @param subscriptionInfo {@link SubscriptionInfo}
+ * @param limit Limit value
+ * @param offset Offset value
+ * @return {@link SubscriptionResponse}
+ * @throws ApplicationManagementException Throws when error encountered while getting subscription data
+ */
+ SubscriptionResponse getStatusBaseSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
+ throws ApplicationManagementException;
+
+ /**
+ * Get subscription statistics related data describes by the {@link SubscriptionInfo}
+ * @param subscriptionInfo {@link SubscriptionInfo}
+ * @return {@link SubscriptionStatistics}
+ * @throws ApplicationManagementException Throws when error encountered while getting statistics
+ */
+ SubscriptionStatistics getStatistics(SubscriptionInfo subscriptionInfo) throws ApplicationManagementException;
+
+ /**
+ * This method is responsible for retrieving device subscription details related to the given UUID.
+ *
+ * @param deviceId the deviceId of the device that need to get operation details.
+ * @param uuid the UUID of the application release.
+ * @return {@link DeviceOperationDTO} which contains the details of device subscriptions.
+ * @throws SubscriptionManagementException if there is an error while fetching the details.
+ */
+ List getSubscriptionOperationsByUUIDAndDeviceID(int deviceId, String uuid)
+ throws ApplicationManagementException;
+
+ /**
+ * This method is responsible for retrieving device counts details related to the given UUID.
+ *
+ * @param uuid the UUID of the application release.
+ * @return {@link List} which contains counts of subscriptions
+ and unsubscription for each subscription type.
+ * @throws SubscriptionManagementException if there is an error while fetching the details.
+ */
+ List getSubscriptionCountsByUUID(String uuid)
+ throws ApplicationManagementException;
+
}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/pom.xml b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/pom.xml
index ed00b9b0f9..e275391342 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/pom.xml
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/pom.xml
@@ -21,7 +21,7 @@
io.entgra.device.mgt.core
application-mgt
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
@@ -81,6 +81,7 @@
com.dd.*,
io.entgra.device.mgt.core.identity.jwt.client.extension.*,
io.entgra.device.mgt.core.apimgt.application.extension.*,
+ io.entgra.device.mgt.core.tenant.mgt.common.*,
org.apache.commons.httpclient,
org.apache.commons.httpclient.methods,
org.apache.commons.validator.routines
@@ -389,6 +390,10 @@
org.wso2.carbon.tenant.mgt
compile
+
+ io.entgra.device.mgt.core
+ io.entgra.device.mgt.core.tenant.mgt.common
+
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/SubscriptionDAO.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/SubscriptionDAO.java
index 3213db3484..c35c4a5251 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/SubscriptionDAO.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/SubscriptionDAO.java
@@ -18,8 +18,13 @@
package io.entgra.device.mgt.core.application.mgt.core.dao;
import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus;
-import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.GroupSubscriptionDTO;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionEntity;
+import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionStatisticDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionsDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceOperationDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ScheduledSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.exception.SubscriptionManagementException;
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
@@ -312,4 +317,227 @@ public interface SubscriptionDAO {
* @throws ApplicationManagementDAOException thrown if an error occurs while deleting data
*/
void deleteScheduledSubscriptionByTenant(int tenantId) throws ApplicationManagementDAOException;
+
+ /**
+ * This method is used to get the details of group subscriptions related to a appReleaseId.
+ *
+ * @param appReleaseId the appReleaseId of the application release.
+ * @param unsubscribe the Status of the subscription.
+ * @param tenantId id of the current tenant.
+ * @param offset the offset for the data set
+ * @param limit the limit for the data set
+ * @return {@link GroupSubscriptionDTO} which contains the details of group subscriptions.
+ * @throws ApplicationManagementDAOException if connection establishment fails.
+ */
+ List getGroupsSubscriptionDetailsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, int offset, int limit)
+ throws ApplicationManagementDAOException;
+
+ /**
+ * This method is used to get the details of user subscriptions related to a appReleaseId.
+ *
+ * @param appReleaseId the appReleaseId of the application release.
+ * @param unsubscribe the Status of the subscription.
+ * @param tenantId id of the current tenant.
+ * @param offset the offset for the data set
+ * @param limit the limit for the data set
+ * @return {@link SubscriptionsDTO} which contains the details of subscriptions.
+ * @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
+ */
+ List getUserSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId,
+ int offset, int limit) throws ApplicationManagementDAOException;
+
+ /**
+ * This method is used to get the details of role subscriptions related to a appReleaseId.
+ *
+ * @param appReleaseId the appReleaseId of the application release.
+ * @param unsubscribe the Status of the subscription.
+ * @param tenantId id of the current tenant.
+ * @param offset the offset for the data set
+ * @param limit the limit for the data set
+ * @return {@link SubscriptionsDTO} which contains the details of subscriptions.
+ * @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
+ */
+ List getRoleSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, int offset, int limit)
+ throws ApplicationManagementDAOException;
+
+ /**
+ * This method is used to get the details of device subscriptions related to a appReleaseId.
+ *
+ * @param appReleaseId the appReleaseId of the application release.
+ * @param unsubscribe the Status of the subscription.
+ * @param tenantId id of the current tenant.
+ * @param offset the offset for the data set
+ * @param limit the limit for the data set
+ * @return {@link DeviceSubscriptionDTO} which contains the details of device subscriptions.
+ * @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
+ */
+ List getDeviceSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, int offset, int limit)
+ throws ApplicationManagementDAOException;
+
+ /**
+ * This method is used to get the details of device subscriptions related to a UUID.
+ *
+ * @param appReleaseId the appReleaseId of the application release.
+ * @param deviceId the deviceId of the device that need to get operation details.
+ * @param tenantId id of the current tenant.
+ * @return {@link DeviceOperationDTO} which contains the details of device subscriptions.
+ * @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
+ */
+ List getSubscriptionOperationsByAppReleaseIDAndDeviceID(int appReleaseId, int deviceId, int tenantId)
+ throws ApplicationManagementDAOException;
+
+ /**
+ * This method is used to get the details of device subscriptions related to a UUID.
+ *
+ * @param appReleaseId the appReleaseId of the application release.
+ * @param unsubscribe the Status of the subscription.
+ * @param tenantId id of the current tenant.
+ * @param actionStatus Status of the action
+ * @param actionType type of the action
+ * @param actionTriggeredBy subscribed by
+ * @param deviceIds deviceIds deviceIds to retrieve data.
+ * @return {@link DeviceOperationDTO} which contains the details of device subscriptions.
+ * @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
+ */
+ List getSubscriptionDetailsByDeviceIds(int appReleaseId, boolean unsubscribe, int tenantId,
+ List deviceIds, List actionStatus, String actionType,
+ String actionTriggeredBy, int limit, int offset) throws ApplicationManagementDAOException;
+ int getDeviceSubscriptionCount(int appReleaseId, boolean unsubscribe, int tenantId,
+ List deviceIds, List actionStatus, String actionType,
+ String actionTriggeredBy) throws ApplicationManagementDAOException;
+
+ /**
+ * This method is used to get the details of device subscriptions related to a UUID.
+ *
+ * @param appReleaseId the appReleaseId of the application release.
+ * @param unsubscribe the Status of the subscription.
+ * @param tenantId id of the current tenant.
+ * @param actionStatus Status of the action
+ * @param actionType type of the action
+ * @param actionTriggeredBy subscribed by
+ * @param offset the offset for the data set
+ * @param limit the limit for the data set
+ * @return {@link DeviceOperationDTO} which contains the details of device subscriptions.
+ * @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
+ */
+ List getAllSubscriptionsDetails(int appReleaseId, boolean unsubscribe, int tenantId, List actionStatus, String actionType,
+ String actionTriggeredBy, int offset, int limit) throws ApplicationManagementDAOException;
+
+ int getAllSubscriptionsCount(int appReleaseId, boolean unsubscribe, int tenantId,
+ List actionStatus, String actionType, String actionTriggeredBy)
+ throws ApplicationManagementDAOException;
+
+ /**
+ * This method is used to get the counts of all subscription types related to a UUID.
+ *
+ * @param appReleaseId the appReleaseId of the application release.
+ * @param tenantId id of the current tenant.
+ * @return {@link int} which contains the count of the subscription type
+ * @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
+ */
+ int getAllSubscriptionCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException;
+
+ /**
+ * This method is used to get the counts of all unsubscription types related to a UUID.
+ *
+ * @param appReleaseId the UUID of the application release.
+ * @param tenantId id of the current tenant.
+ * @return {@link int} which contains the count of the subscription type
+ * @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
+ */
+ int getAllUnsubscriptionCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException;
+
+ /**
+ * This method is used to get the counts of device subscriptions related to a UUID.
+ *
+ * @param appReleaseId the UUID of the application release.
+ * @param tenantId id of the current tenant.
+ * @return {@link int} which contains the count of the subscription type
+ * @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
+ */
+ int getDeviceSubscriptionCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException;
+
+ /**
+ * This method is used to get the counts of device unsubscription related to a UUID.
+ *
+ * @param appReleaseId the UUID of the application release.
+ * @param tenantId id of the current tenant.
+ * @return {@link int} which contains the count of the subscription type
+ * @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
+ */
+ int getDeviceUnsubscriptionCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException;
+
+ /**
+ * This method is used to get the counts of group subscriptions related to a UUID.
+ *
+ * @param appReleaseId the UUID of the application release.
+ * @param tenantId id of the current tenant.
+ * @return {@link int} which contains the count of the subscription type
+ * @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
+ */
+ int getGroupSubscriptionCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException;
+
+ /**
+ * This method is used to get the counts of group unsubscription related to a UUID.
+ *
+ * @param appReleaseId the UUID of the application release.
+ * @param tenantId id of the current tenant.
+ * @return {@link int} which contains the count of the subscription type
+ * @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
+ */
+ int getGroupUnsubscriptionCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException;
+
+ /**
+ * This method is used to get the counts of role subscriptions related to a UUID.
+ *
+ * @param appReleaseId the UUID of the application release.
+ * @param tenantId id of the current tenant.
+ * @return {@link int} which contains the count of the subscription type
+ * @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
+ */
+ int getRoleSubscriptionCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException;
+
+ /**
+ * This method is used to get the counts of role unsubscription related to a UUID.
+ *
+ * @param appReleaseId the UUID of the application release.
+ * @param tenantId id of the current tenant.
+ * @return {@link int} which contains the count of the subscription type
+ * @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
+ */
+ int getRoleUnsubscriptionCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException;
+
+ /**
+ * This method is used to get the counts of user subscriptions related to a UUID.
+ *
+ * @param appReleaseId the UUID of the application release.
+ * @param tenantId id of the current tenant.
+ * @return {@link int} which contains the count of the subscription type
+ * @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
+ */
+ int getUserSubscriptionCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException;
+
+ /**
+ * This method is used to get the counts of user unsubscription related to a UUID.
+ *
+ * @param appReleaseId the UUID of the application release.
+ * @param tenantId id of the current tenant.
+ * @return {@link int} which contains the count of the subscription type
+ * @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
+ */
+ int getUserUnsubscriptionCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException;
+
+ SubscriptionStatisticDTO getSubscriptionStatistic(List deviceIds, boolean isUnsubscribed,
+ int tenantId, int appReleaseId) throws ApplicationManagementDAOException;
+ /**
+ * This method is used to get the counts of devices related to a UUID.
+ *
+ * @param appReleaseId the UUID of the application release.
+ * @param tenantId id of the current tenant.
+ * @param actionStatus categorized status.
+ * @param actionTriggeredFrom type of the action.
+ * @return {@link int} which contains the count of the subscription type
+ * @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
+ */
+ int countSubscriptionsByStatus(int appReleaseId, int tenantId, String actionStatus, String actionTriggeredFrom) throws ApplicationManagementDAOException;
}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java
index 7c71880fa6..86b7407378 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java
@@ -178,7 +178,11 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
sql += "AND AP_APP_RELEASE.CURRENT_STATE = ? ";
}
if (deviceTypeId != -1) {
- sql += "AND AP_APP.DEVICE_TYPE_ID = ? ";
+ sql += "AND (AP_APP.DEVICE_TYPE_ID = ? ";
+ if (filter.isWithWebApps()) {
+ sql += "OR AP_APP.DEVICE_TYPE_ID = 0 ";
+ }
+ sql += ") ";
}
if (filter.isNotRetired()) {
sql += "AND AP_APP.STATUS != 'RETIRED' ";
@@ -309,7 +313,11 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
sql += " AND AP_APP_RELEASE.CURRENT_STATE = ?";
}
if (deviceTypeId != -1) {
- sql += " AND AP_APP.DEVICE_TYPE_ID = ?";
+ sql += " AND (AP_APP.DEVICE_TYPE_ID = ? ";
+ if (filter.isWithWebApps()) {
+ sql += "OR AP_APP.DEVICE_TYPE_ID = 0 ";
+ }
+ sql += ") ";
}
if (filter.isNotRetired()) {
sql += " AND AP_APP.STATUS != 'RETIRED'";
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java
index 79e7b76660..c80e10d064 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java
@@ -17,11 +17,19 @@
*/
package io.entgra.device.mgt.core.application.mgt.core.dao.impl.subscription;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionMetadata;
+import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceOperationDTO;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionEntity;
+import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionStatisticDTO;
import io.entgra.device.mgt.core.application.mgt.core.dao.SubscriptionDAO;
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.AbstractDAOImpl;
import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException;
import io.entgra.device.mgt.core.application.mgt.core.util.DAOUtil;
+import io.entgra.device.mgt.core.application.mgt.core.util.HelperUtil;
+import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
+import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Activity;
+import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus;
@@ -40,10 +48,13 @@ import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.StringJoiner;
+import java.util.stream.Collectors;
public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements SubscriptionDAO {
private static final Log log = LogFactory.getLog(GenericSubscriptionDAOImpl.class);
@@ -1445,13 +1456,13 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
+ "AR.PACKAGE_NAME, "
+ "AR.VERSION, "
+ "DS.SUBSCRIBED_BY, "
- + "DS.STATUS, "
+ "DS.ACTION_TRIGGERED_FROM "
+ "FROM AP_APP_SUB_OP_MAPPING SOP "
+ "JOIN AP_DEVICE_SUBSCRIPTION DS ON SOP.AP_DEVICE_SUBSCRIPTION_ID = DS.ID "
+ "JOIN AP_APP_RELEASE AR ON DS.AP_APP_RELEASE_ID = AR.ID "
+ "JOIN AP_APP AP ON AP.ID = AR.AP_APP_ID "
- + " WHERE SOP.OPERATION_ID = ? AND SOP.TENANT_ID = ?";
+ + "WHERE SOP.OPERATION_ID = ? AND SOP.TENANT_ID = ? "
+ + "LIMIT 1";
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
@@ -1635,4 +1646,1280 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
throw new ApplicationManagementDAOException(msg, e);
}
}
+
+ @Override
+ public List getGroupsSubscriptionDetailsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, int offset, int limit)
+ throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Request received in DAO Layer to get groups related to the given AppReleaseID.");
+ }
+ try {
+ Connection conn = this.getDBConnection();
+ List subscriptionEntities = new ArrayList<>();
+
+ String subscriptionStatusTime = unsubscribe ? "GS.UNSUBSCRIBED_TIMESTAMP" : "GS.SUBSCRIBED_TIMESTAMP";
+ String sql = "SELECT GS.GROUP_NAME, " +
+ "GS.SUBSCRIBED_BY, " +
+ "GS.SUBSCRIBED_TIMESTAMP, " +
+ "GS.UNSUBSCRIBED, " +
+ "GS.UNSUBSCRIBED_BY, " +
+ "GS.UNSUBSCRIBED_TIMESTAMP, " +
+ "GS.AP_APP_RELEASE_ID " +
+ "FROM AP_GROUP_SUBSCRIPTION GS " +
+ "WHERE GS.AP_APP_RELEASE_ID = ? " +
+ "AND GS.UNSUBSCRIBED = ? " +
+ "AND GS.TENANT_ID = ? " +
+ "ORDER BY " + subscriptionStatusTime + " DESC ";
+
+ // Append limit and offset only if limit is not -1
+ if (limit != -1) {
+ sql = sql + " LIMIT ? OFFSET ?";
+ }
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setInt(1, appReleaseId);
+ ps.setBoolean(2, unsubscribe);
+ ps.setInt(3, tenantId);
+
+ // Set limit and offset parameters only if limit is not -1
+ if (limit != -1) {
+ ps.setInt(4, limit);
+ ps.setInt(5, offset);
+ }
+
+ try (ResultSet rs = ps.executeQuery()) {
+ SubscriptionEntity subscriptionEntity;
+ while (rs.next()) {
+ subscriptionEntity = new SubscriptionEntity();
+ subscriptionEntity.setIdentity(rs.getString("GROUP_NAME"));
+ subscriptionEntity.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
+ subscriptionEntity.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_TIMESTAMP"));
+ subscriptionEntity.setUnsubscribed(rs.getBoolean("UNSUBSCRIBED"));
+ subscriptionEntity.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
+ subscriptionEntity.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_TIMESTAMP"));
+ subscriptionEntity.setApplicationReleaseId(rs.getInt("AP_APP_RELEASE_ID"));
+
+ subscriptionEntities.add(subscriptionEntity);
+ }
+ }
+ return subscriptionEntities;
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection to get groups for the given UUID.";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ } catch (SQLException e) {
+ String msg = "SQL Error occurred while getting groups for the given UUID.";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public List getUserSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId,
+ int offset, int limit) throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Request received in DAO Layer to get user subscriptions related to the given UUID.");
+ }
+ try {
+ Connection conn = this.getDBConnection();
+ List subscriptionEntities = new ArrayList<>();
+
+ String subscriptionStatusTime = unsubscribe ? "US.UNSUBSCRIBED_TIMESTAMP" : "US.SUBSCRIBED_TIMESTAMP";
+ String sql = "SELECT US.USER_NAME, " +
+ "US.SUBSCRIBED_BY, " +
+ "US.SUBSCRIBED_TIMESTAMP, " +
+ "US.UNSUBSCRIBED, " +
+ "US.UNSUBSCRIBED_BY, " +
+ "US.UNSUBSCRIBED_TIMESTAMP, " +
+ "US.AP_APP_RELEASE_ID " +
+ "FROM AP_USER_SUBSCRIPTION US " +
+ "WHERE US.AP_APP_RELEASE_ID = ? " +
+ "AND US.UNSUBSCRIBED = ? " +
+ "AND US.TENANT_ID = ? " +
+ "ORDER BY " + subscriptionStatusTime + " DESC " +
+ "LIMIT ? OFFSET ?";
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setInt(1, appReleaseId);
+ ps.setBoolean(2, unsubscribe);
+ ps.setInt(3, tenantId);
+ ps.setInt(4, limit);
+ ps.setInt(5, offset);
+ try (ResultSet rs = ps.executeQuery()) {
+ SubscriptionEntity subscriptionEntity;
+ while (rs.next()) {
+ subscriptionEntity = new SubscriptionEntity();
+ subscriptionEntity.setIdentity(rs.getString("USER_NAME"));
+ subscriptionEntity.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
+ subscriptionEntity.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_TIMESTAMP"));
+ subscriptionEntity.setUnsubscribed(rs.getBoolean("UNSUBSCRIBED"));
+ subscriptionEntity.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
+ subscriptionEntity.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_TIMESTAMP"));
+ subscriptionEntity.setApplicationReleaseId(rs.getInt("AP_APP_RELEASE_ID"));
+
+ subscriptionEntities.add(subscriptionEntity);
+ }
+ }
+ return subscriptionEntities;
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection to get user subscriptions for the given UUID.";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ } catch (SQLException e) {
+ String msg = "SQL Error occurred while getting user subscriptions for the given UUID.";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public List getRoleSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, int offset,
+ int limit) throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Request received in DAO Layer to get role subscriptions related to the given AppReleaseID.");
+ }
+ try {
+ Connection conn = this.getDBConnection();
+ List subscriptionEntities = new ArrayList<>();
+
+ String subscriptionStatusTime = unsubscribe ? "ARS.UNSUBSCRIBED_TIMESTAMP" : "ARS.SUBSCRIBED_TIMESTAMP";
+ String sql = "SELECT ARS.ROLE_NAME, " +
+ "ARS.SUBSCRIBED_BY, " +
+ "ARS.SUBSCRIBED_TIMESTAMP, " +
+ "ARS.UNSUBSCRIBED, " +
+ "ARS.UNSUBSCRIBED_BY, " +
+ "ARS.UNSUBSCRIBED_TIMESTAMP, " +
+ "ARS.AP_APP_RELEASE_ID " +
+ "FROM AP_ROLE_SUBSCRIPTION ARS " +
+ "WHERE ARS.AP_APP_RELEASE_ID = ? " +
+ "AND ARS.UNSUBSCRIBED = ? " +
+ "AND ARS.TENANT_ID = ? " +
+ "ORDER BY " + subscriptionStatusTime + " DESC " +
+ "LIMIT ? OFFSET ?";
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setInt(1, appReleaseId);
+ ps.setBoolean(2, unsubscribe);
+ ps.setInt(3, tenantId);
+ ps.setInt(4, limit);
+ ps.setInt(5, offset);
+ try (ResultSet rs = ps.executeQuery()) {
+ SubscriptionEntity subscriptionEntity;
+ while (rs.next()) {
+ subscriptionEntity = new SubscriptionEntity();
+ subscriptionEntity.setIdentity(rs.getString("ROLE_NAME"));
+ subscriptionEntity.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
+ subscriptionEntity.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_TIMESTAMP"));
+ subscriptionEntity.setUnsubscribed(rs.getBoolean("UNSUBSCRIBED"));
+ subscriptionEntity.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
+ subscriptionEntity.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_TIMESTAMP"));
+ subscriptionEntity.setApplicationReleaseId(rs.getInt("AP_APP_RELEASE_ID"));
+
+ subscriptionEntities.add(subscriptionEntity);
+ }
+ }
+ return subscriptionEntities;
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection to get role subscriptions for the given UUID.";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ } catch (SQLException e) {
+ String msg = "SQL Error occurred while getting role subscriptions for the given UUID.";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public List getDeviceSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, int offset, int limit)
+ throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Request received in DAO Layer to get device subscriptions related to the given AppReleaseID.");
+ }
+ try {
+ Connection conn = this.getDBConnection();
+ List deviceSubscriptions = new ArrayList<>();
+
+ String subscriptionStatusTime = unsubscribe ? "DS.UNSUBSCRIBED_TIMESTAMP" : "DS.SUBSCRIBED_TIMESTAMP";
+ String sql = "SELECT DS.DM_DEVICE_ID, " +
+ "DS.SUBSCRIBED_BY, " +
+ "DS.SUBSCRIBED_TIMESTAMP, " +
+ "DS.STATUS, " +
+ "DS.UNSUBSCRIBED, " +
+ "DS.UNSUBSCRIBED_BY, " +
+ "DS.UNSUBSCRIBED_TIMESTAMP, " +
+ "DS.AP_APP_RELEASE_ID " +
+ "FROM AP_DEVICE_SUBSCRIPTION DS " +
+ "WHERE DS.AP_APP_RELEASE_ID = ? " +
+ "AND DS.UNSUBSCRIBED = ? " +
+ "AND DS.TENANT_ID = ? " +
+ "AND DS.ACTION_TRIGGERED_FROM = 'DEVICE' " +
+ "ORDER BY " + subscriptionStatusTime + " DESC " +
+ "LIMIT ? OFFSET ?";
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setInt(1, appReleaseId);
+ ps.setBoolean(2, unsubscribe);
+ ps.setInt(3, tenantId);
+ ps.setInt(4, limit);
+ ps.setInt(5, offset);
+ try (ResultSet rs = ps.executeQuery()) {
+ DeviceSubscriptionDTO deviceSubscription;
+ while (rs.next()) {
+ deviceSubscription = new DeviceSubscriptionDTO();
+ deviceSubscription.setDeviceId(rs.getInt("DM_DEVICE_ID"));
+ deviceSubscription.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
+ deviceSubscription.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_TIMESTAMP"));
+ deviceSubscription.setStatus(rs.getString("STATUS"));
+ deviceSubscription.setUnsubscribed(rs.getBoolean("UNSUBSCRIBED"));
+ deviceSubscription.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
+ deviceSubscription.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_TIMESTAMP"));
+ deviceSubscription.setAppReleaseId(rs.getInt("AP_APP_RELEASE_ID"));
+
+ deviceSubscriptions.add(deviceSubscription);
+ }
+ }
+ return deviceSubscriptions;
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection to get device subscriptions for the given UUID.";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ } catch (SQLException e) {
+ String msg = "SQL Error occurred while getting device subscriptions for the given UUID.";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public List getSubscriptionOperationsByAppReleaseIDAndDeviceID(
+ int appReleaseId, int deviceId, int tenantId) throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Request received in DAO Layer to get device subscriptions related to the given AppReleaseID and DeviceID.");
+ }
+ try {
+ Connection conn = this.getDBConnection();
+ List deviceSubscriptions = new ArrayList<>();
+ String sql = "SELECT " +
+ " ads.DM_DEVICE_ID, " +
+ " aasom.OPERATION_ID, " +
+ " ads.STATUS, " +
+ " ads.ACTION_TRIGGERED_FROM, " +
+ " ads.SUBSCRIBED_TIMESTAMP AS ACTION_TRIGGERED_AT, " +
+ " ads.AP_APP_RELEASE_ID " +
+ "FROM AP_APP_SUB_OP_MAPPING aasom " +
+ "JOIN AP_DEVICE_SUBSCRIPTION ads " +
+ "ON aasom.AP_DEVICE_SUBSCRIPTION_ID = ads.ID " +
+ "WHERE ads.AP_APP_RELEASE_ID = ? " +
+ "AND ads.DM_DEVICE_ID = ? " +
+ "AND ads.TENANT_ID = ? " +
+ "ORDER BY aasom.OPERATION_ID DESC " +
+ "LIMIT 1";
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setInt(1, appReleaseId);
+ ps.setInt(2, deviceId);
+ ps.setInt(3, tenantId);
+ try (ResultSet rs = ps.executeQuery()) {
+ DeviceOperationDTO deviceSubscription;
+ while (rs.next()) {
+ deviceSubscription = new DeviceOperationDTO();
+ deviceSubscription.setDeviceId(rs.getInt("DM_DEVICE_ID"));
+ deviceSubscription.setStatus(rs.getString("STATUS"));
+ deviceSubscription.setOperationId(rs.getInt("OPERATION_ID"));
+ deviceSubscription.setActionTriggeredFrom(rs.getString("ACTION_TRIGGERED_FROM"));
+ deviceSubscription.setActionTriggeredAt(rs.getTimestamp("ACTION_TRIGGERED_AT"));
+ deviceSubscription.setAppReleaseId(rs.getInt("AP_APP_RELEASE_ID"));
+
+ deviceSubscriptions.add(deviceSubscription);
+ }
+ }
+ }
+ return deviceSubscriptions;
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection to get device subscriptions for the given AppReleaseID and DeviceID.";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ } catch (SQLException e) {
+ String msg = "SQL Error occurred while getting device subscriptions for the given AppReleaseID and DeviceID.";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ // passed the required list for the action status
+ @Override
+ public List getSubscriptionDetailsByDeviceIds(int appReleaseId, boolean unsubscribe, int tenantId,
+ List deviceIds, List actionStatus, String actionType,
+ String actionTriggeredBy, int limit, int offset) throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Getting device subscriptions for the application release id " + appReleaseId
+ + " and device ids " + deviceIds + " from the database");
+ }
+
+ if (deviceIds == null || deviceIds.isEmpty()) {
+ return Collections.emptyList();
+ }
+
+ try {
+ Connection conn = this.getDBConnection();
+ String subscriptionStatusTime = unsubscribe ? "DS.UNSUBSCRIBED_TIMESTAMP" : "DS.SUBSCRIBED_TIMESTAMP";
+ StringBuilder sql = new StringBuilder("SELECT "
+ + "DS.ID AS ID, "
+ + "DS.SUBSCRIBED_BY AS SUBSCRIBED_BY, "
+ + "DS.SUBSCRIBED_TIMESTAMP AS SUBSCRIBED_AT, "
+ + "DS.UNSUBSCRIBED AS IS_UNSUBSCRIBED, "
+ + "DS.UNSUBSCRIBED_BY AS UNSUBSCRIBED_BY, "
+ + "DS.UNSUBSCRIBED_TIMESTAMP AS UNSUBSCRIBED_AT, "
+ + "DS.ACTION_TRIGGERED_FROM AS ACTION_TRIGGERED_FROM, "
+ + "DS.STATUS AS STATUS, "
+ + "DS.DM_DEVICE_ID AS DEVICE_ID "
+ + "FROM AP_DEVICE_SUBSCRIPTION DS "
+ + "WHERE DS.AP_APP_RELEASE_ID = ? "
+ + "AND DS.UNSUBSCRIBED = ? "
+ + "AND DS.TENANT_ID = ? "
+ + "AND DS.DM_DEVICE_ID IN ("
+ + deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ") ");
+
+ if (actionStatus != null && !actionStatus.isEmpty()) {
+ sql.append(" AND DS.STATUS IN (").
+ append(actionStatus.stream().map(status -> "?").collect(Collectors.joining(","))).append(") ");
+ }
+ if (actionType != null && !actionType.isEmpty()) {
+ sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
+ }
+ if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
+ sql.append(" AND DS.SUBSCRIBED_BY LIKE ? ");
+ }
+
+ sql.append("ORDER BY ").append(subscriptionStatusTime).
+ append(" DESC ");
+
+ if (offset >= 0 && limit >= 0) {
+ sql.append("LIMIT ? OFFSET ?");
+ }
+
+ try (PreparedStatement ps = conn.prepareStatement(sql.toString())) {
+ int paramIdx = 1;
+ ps.setInt(paramIdx++, appReleaseId);
+ ps.setBoolean(paramIdx++, unsubscribe);
+ ps.setInt(paramIdx++, tenantId);
+ for (Integer deviceId : deviceIds) {
+ ps.setInt(paramIdx++, deviceId);
+ }
+
+ if (actionStatus != null && !actionStatus.isEmpty()) {
+ for (String status : actionStatus) {
+ ps.setString(paramIdx++, status);
+ }
+ }
+
+ if (actionType != null && !actionType.isEmpty()) {
+ ps.setString(paramIdx++, actionType);
+ }
+
+ if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
+ ps.setString(paramIdx++, "%" + actionTriggeredBy + "%");
+ }
+
+ if (offset >= 0 && limit >= 0) {
+ ps.setInt(paramIdx++, limit);
+ ps.setInt(paramIdx, offset);
+ }
+
+ try (ResultSet rs = ps.executeQuery()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Successfully retrieved device subscriptions for application release id "
+ + appReleaseId + " and device ids " + deviceIds);
+ }
+ List subscriptions = new ArrayList<>();
+ while (rs.next()) {
+ DeviceSubscriptionDTO subscription = new DeviceSubscriptionDTO();
+ subscription.setId(rs.getInt("ID"));
+ subscription.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
+ subscription.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_AT"));
+ subscription.setUnsubscribed(rs.getBoolean("IS_UNSUBSCRIBED"));
+ subscription.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
+ subscription.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_AT"));
+ subscription.setActionTriggeredFrom(rs.getString("ACTION_TRIGGERED_FROM"));
+ subscription.setStatus(rs.getString("STATUS"));
+ subscription.setDeviceId(rs.getInt("DEVICE_ID"));
+ subscriptions.add(subscription);
+ }
+ return subscriptions;
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while running SQL to get device subscription data for application ID: " + appReleaseId
+ + " and device ids: " + deviceIds + ".";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection for getting device subscriptions for "
+ + "application Id: " + appReleaseId + " and device ids: " + deviceIds + ".";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+
+ }
+
+ @Override
+ public int getDeviceSubscriptionCount(int appReleaseId, boolean unsubscribe, int tenantId,
+ List deviceIds, List actionStatus, String actionType,
+ String actionTriggeredBy) throws ApplicationManagementDAOException {
+ int deviceCount = 0;
+
+ if (deviceIds == null || deviceIds.isEmpty()) return deviceCount;
+
+ try {
+ Connection conn = this.getDBConnection();
+ StringBuilder sql = new StringBuilder("SELECT COUNT(DISTINCT DS.DM_DEVICE_ID) AS COUNT "
+ + "FROM AP_DEVICE_SUBSCRIPTION DS "
+ + "WHERE DS.AP_APP_RELEASE_ID = ? "
+ + "AND DS.UNSUBSCRIBED = ? "
+ + "AND DS.TENANT_ID = ? "
+ + "AND DS.DM_DEVICE_ID IN ("
+ + deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ") ");
+
+ if (actionStatus != null && !actionStatus.isEmpty()) {
+ sql.append(" AND DS.STATUS IN (").
+ append(actionStatus.stream().map(status -> "?").collect(Collectors.joining(","))).append(") ");
+ }
+
+ if (actionType != null && !actionType.isEmpty()) {
+ sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
+ }
+ if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
+ sql.append(" AND DS.SUBSCRIBED_BY LIKE ?");
+ }
+
+ try (PreparedStatement ps = conn.prepareStatement(sql.toString())) {
+ int paramIdx = 1;
+ ps.setInt(paramIdx++, appReleaseId);
+ ps.setBoolean(paramIdx++, unsubscribe);
+ ps.setInt(paramIdx++, tenantId);
+ for (Integer deviceId : deviceIds) {
+ ps.setInt(paramIdx++, deviceId);
+ }
+
+ if (actionStatus != null && !actionStatus.isEmpty()) {
+ for (String status : actionStatus) {
+ ps.setString(paramIdx++, status);
+ }
+ }
+
+ if (actionType != null && !actionType.isEmpty()) {
+ ps.setString(paramIdx++, actionType);
+ }
+
+ if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
+ ps.setString(paramIdx, "%" + actionTriggeredBy + "%");
+ }
+
+ try (ResultSet rs = ps.executeQuery()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Successfully retrieved device subscriptions for application release id "
+ + appReleaseId + " and device ids " + deviceIds);
+ }
+ if (rs.next()) {
+ deviceCount = rs.getInt("COUNT");
+ }
+ return deviceCount;
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while running SQL to get device subscription data for application ID: " + appReleaseId
+ + " and device ids: " + deviceIds + ".";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection for getting device subscriptions for "
+ + "application Id: " + appReleaseId + " and device ids: " + deviceIds + ".";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+// @Override
+// public List getSubscriptionDetailsByDeviceIds(int appReleaseId, boolean unsubscribe, int tenantId,
+// List deviceIds, String actionStatus, String actionType,
+// String actionTriggeredBy, String tabActionStatus) throws ApplicationManagementDAOException {
+// if (log.isDebugEnabled()) {
+// log.debug("Getting device subscriptions for the application release id " + appReleaseId
+// + " and device ids " + deviceIds + " from the database");
+// }
+// try {
+// Connection conn = this.getDBConnection();
+// String subscriptionStatusTime = unsubscribe ? "DS.UNSUBSCRIBED_TIMESTAMP" : "DS.SUBSCRIBED_TIMESTAMP";
+// StringBuilder sql = new StringBuilder("SELECT "
+// + "DS.ID AS ID, "
+// + "DS.SUBSCRIBED_BY AS SUBSCRIBED_BY, "
+// + "DS.SUBSCRIBED_TIMESTAMP AS SUBSCRIBED_AT, "
+// + "DS.UNSUBSCRIBED AS IS_UNSUBSCRIBED, "
+// + "DS.UNSUBSCRIBED_BY AS UNSUBSCRIBED_BY, "
+// + "DS.UNSUBSCRIBED_TIMESTAMP AS UNSUBSCRIBED_AT, "
+// + "DS.ACTION_TRIGGERED_FROM AS ACTION_TRIGGERED_FROM, "
+// + "DS.STATUS AS STATUS, "
+// + "DS.DM_DEVICE_ID AS DEVICE_ID "
+// + "FROM AP_DEVICE_SUBSCRIPTION DS "
+// + "WHERE DS.AP_APP_RELEASE_ID = ? AND DS.UNSUBSCRIBED = ? AND DS.TENANT_ID = ? AND DS.DM_DEVICE_ID IN (" +
+// deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ") ");
+//
+// if (actionStatus != null && !actionStatus.isEmpty()) {
+// sql.append(" AND DS.STATUS = ? ");
+// }
+// if (actionType != null && !actionType.isEmpty()) {
+// sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
+// }
+// if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
+// sql.append(" AND DS.SUBSCRIBED_BY LIKE ? ");
+// }
+//
+// sql.append("ORDER BY ").append(subscriptionStatusTime).append(" DESC");
+//
+// try (PreparedStatement ps = conn.prepareStatement(sql.toString())) {
+// int paramIdx = 1;
+// ps.setInt(paramIdx++, appReleaseId);
+// ps.setBoolean(paramIdx++, unsubscribe);
+// ps.setInt(paramIdx++, tenantId);
+// for (int i = 0; i < deviceIds.size(); i++) {
+// ps.setInt(paramIdx++, deviceIds.get(i));
+// }
+//
+// if (actionStatus != null && !actionStatus.isEmpty()) {
+// ps.setString(paramIdx++, actionStatus);
+// }
+// if (actionType != null && !actionType.isEmpty()) {
+// ps.setString(paramIdx++, actionType);
+// }
+// if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
+// ps.setString(paramIdx++, "%" + actionTriggeredBy + "%");
+// }
+//
+// try (ResultSet rs = ps.executeQuery()) {
+// if (log.isDebugEnabled()) {
+// log.debug("Successfully retrieved device subscriptions for application release id "
+// + appReleaseId + " and device ids " + deviceIds);
+// }
+// List subscriptions = new ArrayList<>();
+// while (rs.next()) {
+// DeviceSubscriptionDTO subscription = new DeviceSubscriptionDTO();
+// subscription.setId(rs.getInt("ID"));
+// subscription.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
+// subscription.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_AT"));
+// subscription.setUnsubscribed(rs.getBoolean("IS_UNSUBSCRIBED"));
+// subscription.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
+// subscription.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_AT"));
+// subscription.setActionTriggeredFrom(rs.getString("ACTION_TRIGGERED_FROM"));
+// subscription.setStatus(rs.getString("STATUS"));
+// subscription.setDeviceId(rs.getInt("DEVICE_ID"));
+// subscriptions.add(subscription);
+// }
+// return subscriptions;
+// }
+// } catch (SQLException e) {
+// String msg = "Error occurred while running SQL to get device subscription data for application ID: " + appReleaseId
+// + " and device ids: " + deviceIds + ".";
+// log.error(msg, e);
+// throw new ApplicationManagementDAOException(msg, e);
+// }
+// } catch (DBConnectionException e) {
+// String msg = "Error occurred while obtaining the DB connection for getting device subscriptions for "
+// + "application Id: " + appReleaseId + " and device ids: " + deviceIds + ".";
+// log.error(msg, e);
+// throw new ApplicationManagementDAOException(msg, e);
+// }
+//
+// }
+
+ @Override
+ public List getAllSubscriptionsDetails(int appReleaseId, boolean unsubscribe, int tenantId,
+ List actionStatus, String actionType, String actionTriggeredBy,
+ int offset, int limit) throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Getting device subscriptions for the application release id " + appReleaseId
+ + " from the database");
+ }
+
+ String subscriptionStatusTime = unsubscribe ? "DS.UNSUBSCRIBED_TIMESTAMP" : "DS.SUBSCRIBED_TIMESTAMP";
+ String actionTriggeredColumn = unsubscribe ? "DS.UNSUBSCRIBED_BY" : "DS.SUBSCRIBED_BY";
+ StringBuilder sql = new StringBuilder("SELECT "
+ + "DS.ID AS ID, "
+ + "DS.SUBSCRIBED_BY AS SUBSCRIBED_BY, "
+ + "DS.SUBSCRIBED_TIMESTAMP AS SUBSCRIBED_AT, "
+ + "DS.UNSUBSCRIBED AS IS_UNSUBSCRIBED, "
+ + "DS.UNSUBSCRIBED_BY AS UNSUBSCRIBED_BY, "
+ + "DS.UNSUBSCRIBED_TIMESTAMP AS UNSUBSCRIBED_AT, "
+ + "DS.ACTION_TRIGGERED_FROM AS ACTION_TRIGGERED_FROM, "
+ + "DS.STATUS AS STATUS, "
+ + "DS.DM_DEVICE_ID AS DEVICE_ID "
+ + "FROM AP_DEVICE_SUBSCRIPTION DS "
+ + "WHERE DS.AP_APP_RELEASE_ID = ? "
+ + "AND DS.UNSUBSCRIBED = ? "
+ + "AND DS.TENANT_ID = ? ");
+
+ if (actionStatus != null && !actionStatus.isEmpty()) {
+ sql.append(" AND DS.STATUS IN (").
+ append(actionStatus.stream().map(status -> "?").collect(Collectors.joining(","))).append(") ");
+ }
+
+ if (actionType != null && !actionType.isEmpty()) {
+ sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
+ }
+ if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
+ sql.append(" AND ").append(actionTriggeredColumn).append(" LIKE ? ");
+ }
+
+ sql.append("ORDER BY ").append(subscriptionStatusTime).append(" DESC ");
+
+ if (limit >= 0 && offset >= 0) {
+ sql.append("LIMIT ? OFFSET ?");
+ }
+
+ try {
+ Connection conn = this.getDBConnection();
+ try (PreparedStatement ps = conn.prepareStatement(sql.toString())) {
+ int paramIdx = 1;
+ ps.setInt(paramIdx++, appReleaseId);
+ ps.setBoolean(paramIdx++, unsubscribe);
+ ps.setInt(paramIdx++, tenantId);
+
+ if (actionStatus != null && !actionStatus.isEmpty()) {
+ for (String status : actionStatus) {
+ ps.setString(paramIdx++, status);
+ }
+ }
+
+ if (actionType != null && !actionType.isEmpty()) {
+ ps.setString(paramIdx++, actionType);
+ }
+
+ if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
+ ps.setString(paramIdx++, "%" + actionTriggeredBy + "%");
+ }
+
+ if (limit >= 0 && offset >= 0) {
+ ps.setInt(paramIdx++, limit);
+ ps.setInt(paramIdx, offset);
+ }
+
+ try (ResultSet rs = ps.executeQuery()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Successfully retrieved device subscriptions for application release id "
+ + appReleaseId);
+ }
+ List deviceSubscriptions = new ArrayList<>();
+
+ while (rs.next()) {
+ DeviceSubscriptionDTO subscription = new DeviceSubscriptionDTO();
+ subscription.setId(rs.getInt("ID"));
+ subscription.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
+ subscription.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_AT"));
+ subscription.setUnsubscribed(rs.getBoolean("IS_UNSUBSCRIBED"));
+ subscription.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
+ subscription.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_AT"));
+ subscription.setActionTriggeredFrom(rs.getString("ACTION_TRIGGERED_FROM"));
+ subscription.setStatus(rs.getString("STATUS"));
+ subscription.setDeviceId(rs.getInt("DEVICE_ID"));
+
+ deviceSubscriptions.add(subscription);
+ }
+ return deviceSubscriptions;
+ }
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection for getting device subscription for "
+ + "application Id: " + appReleaseId + ".";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ } catch (SQLException e) {
+ String msg = "Error occurred while running SQL to get device subscription data for application ID: " + appReleaseId;
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public int getAllSubscriptionsCount(int appReleaseId, boolean unsubscribe, int tenantId,
+ List actionStatus, String actionType, String actionTriggeredBy)
+ throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Getting device subscriptions for the application release id " + appReleaseId
+ + " from the database");
+ }
+ String actionTriggeredColumn = unsubscribe ? "DS.UNSUBSCRIBED_BY" : "DS.SUBSCRIBED_BY";
+ StringBuilder sql = new StringBuilder("SELECT COUNT(DISTINCT DS.DM_DEVICE_ID) AS COUNT "
+ + "FROM AP_DEVICE_SUBSCRIPTION DS "
+ + "WHERE DS.AP_APP_RELEASE_ID = ? "
+ + "AND DS.UNSUBSCRIBED = ? "
+ + "AND DS.TENANT_ID = ? ");
+
+ if (actionStatus != null && !actionStatus.isEmpty()) {
+ sql.append(" AND DS.STATUS IN (").
+ append(actionStatus.stream().map(status -> "?").collect(Collectors.joining(","))).append(") ");
+ }
+ if (actionType != null && !actionType.isEmpty()) {
+ sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
+ }
+ if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
+ sql.append(" AND ").append(actionTriggeredColumn).append(" LIKE ?");
+ }
+ try {
+ Connection conn = this.getDBConnection();
+ try (PreparedStatement ps = conn.prepareStatement(sql.toString())) {
+ int paramIdx = 1;
+ ps.setInt(paramIdx++, appReleaseId);
+ ps.setBoolean(paramIdx++, unsubscribe);
+ ps.setInt(paramIdx++, tenantId);
+
+ if (actionStatus != null && !actionStatus.isEmpty()) {
+ for (String status : actionStatus) {
+ ps.setString(paramIdx++, status);
+ }
+ }
+ if (actionType != null && !actionType.isEmpty()) {
+ ps.setString(paramIdx++, actionType);
+ }
+ if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
+ ps.setString(paramIdx++, "%" + actionTriggeredBy + "%");
+ }
+ try (ResultSet rs = ps.executeQuery()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Successfully retrieved device subscriptions for application release id "
+ + appReleaseId);
+ }
+ return rs.next() ? rs.getInt("COUNT") : 0;
+ }
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection for getting device subscription for "
+ + "application Id: " + appReleaseId + ".";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ } catch (SQLException e) {
+ String msg = "Error occurred while running SQL to get device subscription data for application ID: " + appReleaseId;
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public int getAllSubscriptionCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Getting all subscriptions count for the application appReleaseId " + appReleaseId + " from the database");
+ }
+ List allowingDeviceStatuses = new ArrayList<>();
+ allowingDeviceStatuses.add(EnrolmentInfo.Status.ACTIVE.toString());
+ allowingDeviceStatuses.add(EnrolmentInfo.Status.INACTIVE.toString());
+ allowingDeviceStatuses.add(EnrolmentInfo.Status.UNREACHABLE.toString());
+
+ DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
+ try {
+ Connection conn = this.getDBConnection();
+ List deviceIds = deviceManagementProviderService.getDeviceIdsByStatus(allowingDeviceStatuses);
+ if (deviceIds.isEmpty()) {
+ return 0;
+ }
+ StringBuilder idList = new StringBuilder();
+ for (int i = 0; i < deviceIds.size(); i++) {
+ idList.append("?");
+ if (i < deviceIds.size() - 1) {
+ idList.append(",");
+ }
+ }
+ String sql = "SELECT COUNT(*) AS count " +
+ "FROM AP_DEVICE_SUBSCRIPTION " +
+ "WHERE AP_APP_RELEASE_ID = ? " +
+ "AND TENANT_ID = ? " +
+ "AND UNSUBSCRIBED = FALSE " +
+ "AND DM_DEVICE_ID IN (" + idList.toString() + ")";
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setInt(1, appReleaseId);
+ ps.setInt(2, tenantId);
+ for (int i = 0; i < deviceIds.size(); i++) {
+ ps.setInt(3 + i, deviceIds.get(i));
+ }
+
+ try (ResultSet rs = ps.executeQuery()) {
+ if (rs.next()) {
+ return rs.getInt("count");
+ }
+ return 0;
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while running SQL to get all subscriptions count for application appReleaseId: "
+ + appReleaseId;
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ } catch (DBConnectionException | DeviceManagementException e) {
+ String msg = "Error occurred while obtaining the DB connection for getting all subscriptions count for appReleaseId: "
+ + appReleaseId + ".";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public int getAllUnsubscriptionCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Getting all unsubscription count for the application appReleaseId " + appReleaseId + " from the database");
+ }
+ List allowingDeviceStatuses = new ArrayList<>();
+ allowingDeviceStatuses.add(EnrolmentInfo.Status.ACTIVE.toString());
+ allowingDeviceStatuses.add(EnrolmentInfo.Status.INACTIVE.toString());
+ allowingDeviceStatuses.add(EnrolmentInfo.Status.UNREACHABLE.toString());
+
+ DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
+ try {
+ Connection conn = this.getDBConnection();
+ List deviceIds = deviceManagementProviderService.getDeviceIdsByStatus(allowingDeviceStatuses);
+ if (deviceIds.isEmpty()) {
+ return 0;
+ }
+ StringBuilder idList = new StringBuilder();
+ for (int i = 0; i < deviceIds.size(); i++) {
+ idList.append("?");
+ if (i < deviceIds.size() - 1) {
+ idList.append(",");
+ }
+ }
+ String sql = "SELECT COUNT(*) AS count " +
+ "FROM AP_DEVICE_SUBSCRIPTION " +
+ "WHERE AP_APP_RELEASE_ID = ? " +
+ "AND TENANT_ID = ? " +
+ "AND UNSUBSCRIBED = TRUE " +
+ "AND DM_DEVICE_ID IN (" + idList.toString() + ")";
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setInt(1, appReleaseId);
+ ps.setInt(2, tenantId);
+ for (int i = 0; i < deviceIds.size(); i++) {
+ ps.setInt(3 + i, deviceIds.get(i));
+ }
+
+ try (ResultSet rs = ps.executeQuery()) {
+ if (rs.next()) {
+ return rs.getInt("count");
+ }
+ return 0;
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while running SQL to get all unsubscription count for application appReleaseId: "
+ + appReleaseId;
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ } catch (DBConnectionException | DeviceManagementException e) {
+ String msg = "Error occurred while obtaining the DB connection for getting all unsubscription count for appReleaseId: "
+ + appReleaseId + ".";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public int getDeviceSubscriptionCount(int appReleaseId, int tenantId)
+ throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Getting device subscriptions count for the application appReleaseId " + appReleaseId
+ + " from the database");
+ }
+ try {
+ Connection conn = this.getDBConnection();
+ String sql = "SELECT COUNT(*) AS count " +
+ "FROM AP_DEVICE_SUBSCRIPTION " +
+ "WHERE AP_APP_RELEASE_ID = ? " +
+ "AND TENANT_ID = ? " +
+ "AND UNSUBSCRIBED = FALSE " +
+ "AND ACTION_TRIGGERED_FROM = 'DEVICE'";
+
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setInt(1, appReleaseId);
+ ps.setInt(2, tenantId);
+
+ try (ResultSet rs = ps.executeQuery()) {
+ if (rs.next()) {
+ return rs.getInt("count");
+ }
+ return 0;
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while running SQL to get device subscriptions count for application appReleaseId: "
+ + appReleaseId;
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection for getting device subscriptions count for appReleaseId: "
+ + appReleaseId + ".";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public int getDeviceUnsubscriptionCount(int appReleaseId, int tenantId)
+ throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Getting device unsubscriptions count for the application appReleaseId " + appReleaseId
+ + " from the database");
+ }
+ try {
+ Connection conn = this.getDBConnection();
+ String sql = "SELECT COUNT(*) AS count " +
+ "FROM AP_DEVICE_SUBSCRIPTION " +
+ "WHERE AP_APP_RELEASE_ID = ? " +
+ "AND TENANT_ID = ? " +
+ "AND UNSUBSCRIBED = TRUE " +
+ "AND ACTION_TRIGGERED_FROM = 'DEVICE'";
+
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setInt(1, appReleaseId);
+ ps.setInt(2, tenantId);
+
+ try (ResultSet rs = ps.executeQuery()) {
+ if (rs.next()) {
+ return rs.getInt("count");
+ }
+ return 0;
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while running SQL to get device unsubscription count for application appReleaseId: "
+ + appReleaseId;
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection for getting device unsubscription count for appReleaseId: "
+ + appReleaseId + ".";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public int getGroupSubscriptionCount(int appReleaseId, int tenantId)
+ throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Getting group subscriptions count for the application appReleaseId " + appReleaseId
+ + " from the database");
+ }
+ try {
+ Connection conn = this.getDBConnection();
+ String sql = "SELECT COUNT(*) AS count " +
+ "FROM AP_GROUP_SUBSCRIPTION " +
+ "WHERE AP_APP_RELEASE_ID = ? " +
+ "AND TENANT_ID = ? " +
+ "AND UNSUBSCRIBED = FALSE";
+
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setInt(1, appReleaseId);
+ ps.setInt(2, tenantId);
+
+ try (ResultSet rs = ps.executeQuery()) {
+ if (rs.next()) {
+ return rs.getInt("count");
+ }
+ return 0;
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while running SQL to get group subscriptions count for application appReleaseId: "
+ + appReleaseId;
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection for getting group subscriptions count for appReleaseId: "
+ + appReleaseId + ".";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public int getGroupUnsubscriptionCount(int appReleaseId, int tenantId)
+ throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Getting group unsubscriptions count for the application appReleaseId " + appReleaseId
+ + " from the database");
+ }
+ try {
+ Connection conn = this.getDBConnection();
+ String sql = "SELECT COUNT(*) AS count " +
+ "FROM AP_GROUP_SUBSCRIPTION " +
+ "WHERE AP_APP_RELEASE_ID = ? " +
+ "AND TENANT_ID = ? " +
+ "AND UNSUBSCRIBED = TRUE";
+
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setInt(1, appReleaseId);
+ ps.setInt(2, tenantId);
+
+ try (ResultSet rs = ps.executeQuery()) {
+ if (rs.next()) {
+ return rs.getInt("count");
+ }
+ return 0;
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while running SQL to get group unsubscription count for application appReleaseId: "
+ + appReleaseId;
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection for getting group unsubscription count for appReleaseId: "
+ + appReleaseId + ".";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public int getRoleSubscriptionCount(int appReleaseId, int tenantId)
+ throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Getting role subscriptions count for the application appReleaseId " + appReleaseId
+ + " from the database");
+ }
+ try {
+ Connection conn = this.getDBConnection();
+ String sql = "SELECT COUNT(*) AS count " +
+ "FROM AP_ROLE_SUBSCRIPTION " +
+ "WHERE AP_APP_RELEASE_ID = ? " +
+ "AND TENANT_ID = ? " +
+ "AND UNSUBSCRIBED = FALSE";
+
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setInt(1, appReleaseId);
+ ps.setInt(2, tenantId);
+
+ try (ResultSet rs = ps.executeQuery()) {
+ if (rs.next()) {
+ return rs.getInt("count");
+ }
+ return 0;
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while running SQL to get role subscriptions count for application appReleaseId: "
+ + appReleaseId;
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection for getting role subscriptions count for appReleaseId: "
+ + appReleaseId + ".";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public int getRoleUnsubscriptionCount(int appReleaseId, int tenantId)
+ throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Getting role unsubscription count for the application appReleaseId " + appReleaseId
+ + " from the database");
+ }
+ try {
+ Connection conn = this.getDBConnection();
+ String sql = "SELECT COUNT(*) AS count " +
+ "FROM AP_ROLE_SUBSCRIPTION " +
+ "WHERE AP_APP_RELEASE_ID = ? " +
+ "AND TENANT_ID = ? " +
+ "AND UNSUBSCRIBED = TRUE";
+
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setInt(1, appReleaseId);
+ ps.setInt(2, tenantId);
+
+ try (ResultSet rs = ps.executeQuery()) {
+ if (rs.next()) {
+ return rs.getInt("count");
+ }
+ return 0;
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while running SQL to get role unsubscription count for application appReleaseId: "
+ + appReleaseId;
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection for getting role unsubscription count for appReleaseId: "
+ + appReleaseId + ".";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public int getUserSubscriptionCount(int appReleaseId, int tenantId)
+ throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Getting user subscriptions count for the application appReleaseId " + appReleaseId
+ + " from the database");
+ }
+ try {
+ Connection conn = this.getDBConnection();
+ String sql = "SELECT COUNT(*) AS count " +
+ "FROM AP_USER_SUBSCRIPTION " +
+ "WHERE AP_APP_RELEASE_ID = ? " +
+ "AND TENANT_ID = ? " +
+ "AND UNSUBSCRIBED = FALSE";
+
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setInt(1, appReleaseId);
+ ps.setInt(2, tenantId);
+
+ try (ResultSet rs = ps.executeQuery()) {
+ if (rs.next()) {
+ return rs.getInt("count");
+ }
+ return 0;
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while running SQL to get user subscriptions count for application appReleaseId: "
+ + appReleaseId;
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection for getting user subscriptions count for appReleaseId: "
+ + appReleaseId + ".";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public int getUserUnsubscriptionCount(int appReleaseId, int tenantId)
+ throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Getting user unsubscription count for the application appReleaseId " + appReleaseId
+ + " from the database");
+ }
+ try {
+ Connection conn = this.getDBConnection();
+ String sql = "SELECT COUNT(*) AS count " +
+ "FROM AP_USER_SUBSCRIPTION " +
+ "WHERE AP_APP_RELEASE_ID = ? " +
+ "AND TENANT_ID = ? " +
+ "AND UNSUBSCRIBED = TRUE";
+
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setInt(1, appReleaseId);
+ ps.setInt(2, tenantId);
+
+ try (ResultSet rs = ps.executeQuery()) {
+ if (rs.next()) {
+ return rs.getInt("count");
+ }
+ return 0;
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while running SQL to get user unsubscription count for application appReleaseId: "
+ + appReleaseId;
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection for getting user unsubscription count for appReleaseId: "
+ + appReleaseId + ".";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public SubscriptionStatisticDTO getSubscriptionStatistic(List deviceIds, boolean isUnsubscribed, int tenantId, int appReleaseId)
+ throws ApplicationManagementDAOException {
+ SubscriptionStatisticDTO subscriptionStatisticDTO = new SubscriptionStatisticDTO();
+ if (deviceIds == null || deviceIds.isEmpty()) return subscriptionStatisticDTO;
+
+ try {
+ Connection connection = getDBConnection();
+ String sql = "SELECT COUNT(DISTINCT ID) AS COUNT, " +
+ "STATUS FROM AP_DEVICE_SUBSCRIPTION " +
+ "WHERE TENANT_ID = ? " +
+ "AND AP_APP_RELEASE_ID = ? " +
+ "AND UNSUBSCRIBED = ? " +
+ "AND DM_DEVICE_ID IN (" +
+ deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ") " +
+ "GROUP BY (STATUS)";
+
+ try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
+ int idx = 1;
+
+ preparedStatement.setInt(idx++, tenantId);
+ preparedStatement.setInt(idx++, appReleaseId);
+ preparedStatement.setBoolean(idx++, isUnsubscribed);
+ for (Integer deviceId : deviceIds) {
+ preparedStatement.setInt(idx++, deviceId);
+ }
+
+ try (ResultSet resultSet = preparedStatement.executeQuery()) {
+ while (resultSet.next()) {
+ // add the error and in progress
+ int count = resultSet.getInt("COUNT");
+ String status = resultSet.getString("STATUS");
+
+ if (SubscriptionMetadata.DBSubscriptionStatus.COMPLETED_STATUS_LIST.contains(status)) {
+ subscriptionStatisticDTO.addToComplete(count);
+ }
+
+ if (SubscriptionMetadata.DBSubscriptionStatus.PENDING_STATUS_LIST.contains(status)) {
+ subscriptionStatisticDTO.addToPending(count);
+ }
+ if (SubscriptionMetadata.DBSubscriptionStatus.ERROR_STATUS_LIST.contains(status)) {
+ subscriptionStatisticDTO.addToFailed(count);
+ }
+ }
+ }
+ }
+ return subscriptionStatisticDTO;
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection for getting subscription statistics";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ } catch (SQLException e) {
+ String msg = "Error occurred while running SQL for getting subscription statistics";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ public int countSubscriptionsByStatus(int appReleaseId, int tenantId, String actionStatus, String actionTriggeredFrom) throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Request received in DAO Layer to count device subscriptions by status and actionTriggeredFrom for the given AppReleaseID.");
+ }
+ try {
+ Connection conn = this.getDBConnection();
+ String sql = "SELECT COUNT(*) FROM AP_DEVICE_SUBSCRIPTION " +
+ "WHERE AP_APP_RELEASE_ID = ? " +
+ "AND TENANT_ID = ? " +
+ "AND STATUS = ?" +
+ " AND ACTION_TRIGGERED_FROM = ?";
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setInt(1, appReleaseId);
+ ps.setInt(2, tenantId);
+ ps.setString(3, actionStatus);
+ ps.setString(4, actionTriggeredFrom);
+ try (ResultSet rs = ps.executeQuery()) {
+ if (rs.next()) {
+ return rs.getInt(1);
+ }
+ }
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection to count device subscriptions by status and action trigger.";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ } catch (SQLException e) {
+ String msg = "SQL Error occurred while counting device subscriptions by status and action trigger.";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ return 0;
+ }
+
}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/OracleSubscriptionDAOImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/OracleSubscriptionDAOImpl.java
index 9181b9b4de..71bd17bbc9 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/OracleSubscriptionDAOImpl.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/OracleSubscriptionDAOImpl.java
@@ -18,6 +18,8 @@
package io.entgra.device.mgt.core.application.mgt.core.dao.impl.subscription;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionEntity;
+import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import io.entgra.device.mgt.core.application.mgt.common.exception.DBConnectionException;
@@ -28,7 +30,9 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
+import java.util.stream.Collectors;
/**
* This handles Application subscribing operations which are specific to Oracle.
@@ -157,4 +161,379 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
throw new ApplicationManagementDAOException(msg, e);
}
}
+
+ // passed the required list for the action status
+ @Override
+ public List getSubscriptionDetailsByDeviceIds(int appReleaseId, boolean unsubscribe, int tenantId,
+ List deviceIds, List actionStatus, String actionType,
+ String actionTriggeredBy, int limit, int offset) throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Getting device subscriptions for the application release id " + appReleaseId
+ + " and device ids " + deviceIds + " from the database");
+ }
+ if (deviceIds == null || deviceIds.isEmpty()) {
+ return Collections.emptyList();
+ }
+ try {
+ Connection conn = this.getDBConnection();
+ String subscriptionStatusTime = unsubscribe ? "DS.UNSUBSCRIBED_TIMESTAMP" : "DS.SUBSCRIBED_TIMESTAMP";
+ StringBuilder sql = new StringBuilder("SELECT "
+ + "DS.ID AS ID, "
+ + "DS.SUBSCRIBED_BY AS SUBSCRIBED_BY, "
+ + "DS.SUBSCRIBED_TIMESTAMP AS SUBSCRIBED_AT, "
+ + "DS.UNSUBSCRIBED AS IS_UNSUBSCRIBED, "
+ + "DS.UNSUBSCRIBED_BY AS UNSUBSCRIBED_BY, "
+ + "DS.UNSUBSCRIBED_TIMESTAMP AS UNSUBSCRIBED_AT, "
+ + "DS.ACTION_TRIGGERED_FROM AS ACTION_TRIGGERED_FROM, "
+ + "DS.STATUS AS STATUS, "
+ + "DS.DM_DEVICE_ID AS DEVICE_ID "
+ + "FROM AP_DEVICE_SUBSCRIPTION DS "
+ + "WHERE DS.AP_APP_RELEASE_ID = ? "
+ + "AND DS.UNSUBSCRIBED = ? "
+ + "AND DS.TENANT_ID = ? "
+ + "AND DS.DM_DEVICE_ID IN ("
+ + deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ") ");
+ if (actionStatus != null && !actionStatus.isEmpty()) {
+ sql.append(" AND DS.STATUS IN (").
+ append(actionStatus.stream().map(status -> "?").collect(Collectors.joining(","))).append(") ");
+ }
+ if (actionType != null && !actionType.isEmpty()) {
+ sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
+ }
+ if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
+ sql.append(" AND DS.SUBSCRIBED_BY LIKE ? ");
+ }
+ sql.append("ORDER BY ").append(subscriptionStatusTime).
+ append(" DESC ");
+ if (offset >= 0 && limit >= 0) {
+ sql.append("OFFSET ? ROWS FETCH NEXT ? ROWS ONLY");
+ }
+ try (PreparedStatement ps = conn.prepareStatement(sql.toString())) {
+ int paramIdx = 1;
+ ps.setInt(paramIdx++, appReleaseId);
+ ps.setBoolean(paramIdx++, unsubscribe);
+ ps.setInt(paramIdx++, tenantId);
+ for (Integer deviceId : deviceIds) {
+ ps.setInt(paramIdx++, deviceId);
+ }
+ if (actionStatus != null && !actionStatus.isEmpty()) {
+ for (String status : actionStatus) {
+ ps.setString(paramIdx++, status);
+ }
+ }
+ if (actionType != null && !actionType.isEmpty()) {
+ ps.setString(paramIdx++, actionType);
+ }
+ if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
+ ps.setString(paramIdx++, "%" + actionTriggeredBy + "%");
+ }
+ if (offset >= 0 && limit >= 0) {
+ ps.setInt(paramIdx++, offset);
+ ps.setInt(paramIdx, limit);
+ }
+ try (ResultSet rs = ps.executeQuery()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Successfully retrieved device subscriptions for application release id "
+ + appReleaseId + " and device ids " + deviceIds);
+ }
+ List subscriptions = new ArrayList<>();
+ while (rs.next()) {
+ DeviceSubscriptionDTO subscription = new DeviceSubscriptionDTO();
+ subscription.setId(rs.getInt("ID"));
+ subscription.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
+ subscription.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_AT"));
+ subscription.setUnsubscribed(rs.getBoolean("IS_UNSUBSCRIBED"));
+ subscription.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
+ subscription.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_AT"));
+ subscription.setActionTriggeredFrom(rs.getString("ACTION_TRIGGERED_FROM"));
+ subscription.setStatus(rs.getString("STATUS"));
+ subscription.setDeviceId(rs.getInt("DEVICE_ID"));
+ subscriptions.add(subscription);
+ }
+ return subscriptions;
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while running SQL to get device subscription data for application ID: " + appReleaseId
+ + " and device ids: " + deviceIds + ".";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection for getting device subscriptions for "
+ + "application Id: " + appReleaseId + " and device ids: " + deviceIds + ".";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public List getRoleSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, int offset,
+ int limit) throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Request received in DAO Layer to get role subscriptions related to the given AppReleaseID.");
+ }
+ try {
+ Connection conn = this.getDBConnection();
+ List subscriptionEntities = new ArrayList<>();
+
+ String subscriptionStatusTime = unsubscribe ? "ARS.UNSUBSCRIBED_TIMESTAMP" : "ARS.SUBSCRIBED_TIMESTAMP";
+ String sql = "SELECT ARS.ROLE_NAME, " +
+ "ARS.SUBSCRIBED_BY, " +
+ "ARS.SUBSCRIBED_TIMESTAMP, " +
+ "ARS.UNSUBSCRIBED, " +
+ "ARS.UNSUBSCRIBED_BY, " +
+ "ARS.UNSUBSCRIBED_TIMESTAMP, " +
+ "ARS.AP_APP_RELEASE_ID " +
+ "FROM AP_ROLE_SUBSCRIPTION ARS " +
+ "WHERE ARS.AP_APP_RELEASE_ID = ? " +
+ "AND ARS.UNSUBSCRIBED = ? " +
+ "AND ARS.TENANT_ID = ? " +
+ "ORDER BY " + subscriptionStatusTime + " DESC " +
+ "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
+
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setInt(1, appReleaseId);
+ ps.setBoolean(2, unsubscribe);
+ ps.setInt(3, tenantId);
+ ps.setInt(4, offset);
+ ps.setInt(5, limit);
+ try (ResultSet rs = ps.executeQuery()) {
+ SubscriptionEntity subscriptionEntity;
+ while (rs.next()) {
+ subscriptionEntity = new SubscriptionEntity();
+ subscriptionEntity.setIdentity(rs.getString("ROLE_NAME"));
+ subscriptionEntity.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
+ subscriptionEntity.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_TIMESTAMP"));
+ subscriptionEntity.setUnsubscribed(rs.getBoolean("UNSUBSCRIBED"));
+ subscriptionEntity.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
+ subscriptionEntity.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_TIMESTAMP"));
+ subscriptionEntity.setApplicationReleaseId(rs.getInt("AP_APP_RELEASE_ID"));
+
+ subscriptionEntities.add(subscriptionEntity);
+ }
+ }
+ return subscriptionEntities;
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection to get role subscriptions for the given UUID.";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ } catch (SQLException e) {
+ String msg = "SQL Error occurred while getting role subscriptions for the given UUID.";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public List getUserSubscriptionsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId,
+ int offset, int limit) throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Request received in DAO Layer to get user subscriptions related to the given UUID.");
+ }
+ try {
+ Connection conn = this.getDBConnection();
+ List subscriptionEntities = new ArrayList<>();
+
+ String subscriptionStatusTime = unsubscribe ? "US.UNSUBSCRIBED_TIMESTAMP" : "US.SUBSCRIBED_TIMESTAMP";
+ String sql = "SELECT US.USER_NAME, " +
+ "US.SUBSCRIBED_BY, " +
+ "US.SUBSCRIBED_TIMESTAMP, " +
+ "US.UNSUBSCRIBED, " +
+ "US.UNSUBSCRIBED_BY, " +
+ "US.UNSUBSCRIBED_TIMESTAMP, " +
+ "US.AP_APP_RELEASE_ID " +
+ "FROM AP_USER_SUBSCRIPTION US " +
+ "WHERE US.AP_APP_RELEASE_ID = ? " +
+ "AND US.UNSUBSCRIBED = ? " +
+ "AND US.TENANT_ID = ? " +
+ "ORDER BY " + subscriptionStatusTime + " DESC " +
+ "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
+
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setInt(1, appReleaseId);
+ ps.setBoolean(2, unsubscribe);
+ ps.setInt(3, tenantId);
+ ps.setInt(4, offset);
+ ps.setInt(5, limit);
+ try (ResultSet rs = ps.executeQuery()) {
+ SubscriptionEntity subscriptionEntity;
+ while (rs.next()) {
+ subscriptionEntity = new SubscriptionEntity();
+ subscriptionEntity.setIdentity(rs.getString("USER_NAME"));
+ subscriptionEntity.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
+ subscriptionEntity.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_TIMESTAMP"));
+ subscriptionEntity.setUnsubscribed(rs.getBoolean("UNSUBSCRIBED"));
+ subscriptionEntity.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
+ subscriptionEntity.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_TIMESTAMP"));
+ subscriptionEntity.setApplicationReleaseId(rs.getInt("AP_APP_RELEASE_ID"));
+
+ subscriptionEntities.add(subscriptionEntity);
+ }
+ }
+ return subscriptionEntities;
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection to get user subscriptions for the given UUID.";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ } catch (SQLException e) {
+ String msg = "SQL Error occurred while getting user subscriptions for the given UUID.";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public List getGroupsSubscriptionDetailsByAppReleaseID(int appReleaseId, boolean unsubscribe, int tenantId, int offset, int limit)
+ throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Request received in DAO Layer to get groups related to the given AppReleaseID.");
+ }
+ try {
+ Connection conn = this.getDBConnection();
+ List subscriptionEntities = new ArrayList<>();
+
+ String subscriptionStatusTime = unsubscribe ? "GS.UNSUBSCRIBED_TIMESTAMP" : "GS.SUBSCRIBED_TIMESTAMP";
+ String sql = "SELECT GS.GROUP_NAME, " +
+ "GS.SUBSCRIBED_BY, " +
+ "GS.SUBSCRIBED_TIMESTAMP, " +
+ "GS.UNSUBSCRIBED, " +
+ "GS.UNSUBSCRIBED_BY, " +
+ "GS.UNSUBSCRIBED_TIMESTAMP, " +
+ "GS.AP_APP_RELEASE_ID " +
+ "FROM AP_GROUP_SUBSCRIPTION GS " +
+ "WHERE GS.AP_APP_RELEASE_ID = ? " +
+ "AND GS.UNSUBSCRIBED = ? AND GS.TENANT_ID = ? " +
+ "ORDER BY " + subscriptionStatusTime + " DESC " +
+ "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
+
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {
+ ps.setInt(1, appReleaseId);
+ ps.setBoolean(2, unsubscribe);
+ ps.setInt(3, tenantId);
+ ps.setInt(4, offset);
+ ps.setInt(5, limit);
+
+ try (ResultSet rs = ps.executeQuery()) {
+ SubscriptionEntity subscriptionEntity;
+ while (rs.next()) {
+ subscriptionEntity = new SubscriptionEntity();
+ subscriptionEntity.setIdentity(rs.getString("GROUP_NAME"));
+ subscriptionEntity.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
+ subscriptionEntity.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_TIMESTAMP"));
+ subscriptionEntity.setUnsubscribed(rs.getBoolean("UNSUBSCRIBED"));
+ subscriptionEntity.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
+ subscriptionEntity.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_TIMESTAMP"));
+ subscriptionEntity.setApplicationReleaseId(rs.getInt("AP_APP_RELEASE_ID"));
+
+ subscriptionEntities.add(subscriptionEntity);
+ }
+ }
+ return subscriptionEntities;
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection to get groups for the given UUID.";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ } catch (SQLException e) {
+ String msg = "SQL Error occurred while getting groups for the given UUID.";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public List getAllSubscriptionsDetails(int appReleaseId, boolean unsubscribe, int tenantId,
+ List actionStatus, String actionType, String actionTriggeredBy,
+ int offset, int limit) throws ApplicationManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Getting device subscriptions for the application release id " + appReleaseId + " from the database");
+ }
+ String subscriptionStatusTime = unsubscribe ? "DS.UNSUBSCRIBED_TIMESTAMP" : "DS.SUBSCRIBED_TIMESTAMP";
+ String actionTriggeredColumn = unsubscribe ? "DS.UNSUBSCRIBED_BY" : "DS.SUBSCRIBED_BY";
+ StringBuilder sql = new StringBuilder("SELECT "
+ + "DS.ID AS ID, "
+ + "DS.SUBSCRIBED_BY AS SUBSCRIBED_BY, "
+ + "DS.SUBSCRIBED_TIMESTAMP AS SUBSCRIBED_AT, "
+ + "DS.UNSUBSCRIBED AS IS_UNSUBSCRIBED, "
+ + "DS.UNSUBSCRIBED_BY AS UNSUBSCRIBED_BY, "
+ + "DS.UNSUBSCRIBED_TIMESTAMP AS UNSUBSCRIBED_AT, "
+ + "DS.ACTION_TRIGGERED_FROM AS ACTION_TRIGGERED_FROM, "
+ + "DS.STATUS AS STATUS, "
+ + "DS.DM_DEVICE_ID AS DEVICE_ID "
+ + "FROM AP_DEVICE_SUBSCRIPTION DS "
+ + "WHERE DS.AP_APP_RELEASE_ID = ? "
+ + "AND DS.UNSUBSCRIBED = ? "
+ + "AND DS.TENANT_ID = ? ");
+ if (actionStatus != null && !actionStatus.isEmpty()) {
+ sql.append(" AND DS.STATUS IN (")
+ .append(actionStatus.stream().map(status -> "?").collect(Collectors.joining(","))).append(") ");
+ }
+ if (actionType != null && !actionType.isEmpty()) {
+ sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
+ }
+ if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
+ sql.append(" AND ").append(actionTriggeredColumn).append(" LIKE ? ");
+ }
+ sql.append("ORDER BY ").append(subscriptionStatusTime).append(" DESC ");
+ if (limit >= 0 && offset >= 0) {
+ sql.append("OFFSET ? ROWS FETCH NEXT ? ROWS ONLY");
+ }
+ try {
+ Connection conn = this.getDBConnection();
+ try (PreparedStatement ps = conn.prepareStatement(sql.toString())) {
+ int paramIdx = 1;
+ ps.setInt(paramIdx++, appReleaseId);
+ ps.setBoolean(paramIdx++, unsubscribe);
+ ps.setInt(paramIdx++, tenantId);
+ if (actionStatus != null && !actionStatus.isEmpty()) {
+ for (String status : actionStatus) {
+ ps.setString(paramIdx++, status);
+ }
+ }
+ if (actionType != null && !actionType.isEmpty()) {
+ ps.setString(paramIdx++, actionType);
+ }
+ if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
+ ps.setString(paramIdx++, "%" + actionTriggeredBy + "%");
+ }
+ if (limit >= 0 && offset >= 0) {
+ ps.setInt(paramIdx++, offset);
+ ps.setInt(paramIdx, limit);
+ }
+ try (ResultSet rs = ps.executeQuery()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Successfully retrieved device subscriptions for application release id "
+ + appReleaseId);
+ }
+ List deviceSubscriptions = new ArrayList<>();
+ while (rs.next()) {
+ DeviceSubscriptionDTO subscription = new DeviceSubscriptionDTO();
+ subscription.setId(rs.getInt("ID"));
+ subscription.setSubscribedBy(rs.getString("SUBSCRIBED_BY"));
+ subscription.setSubscribedTimestamp(rs.getTimestamp("SUBSCRIBED_AT"));
+ subscription.setUnsubscribed(rs.getBoolean("IS_UNSUBSCRIBED"));
+ subscription.setUnsubscribedBy(rs.getString("UNSUBSCRIBED_BY"));
+ subscription.setUnsubscribedTimestamp(rs.getTimestamp("UNSUBSCRIBED_AT"));
+ subscription.setActionTriggeredFrom(rs.getString("ACTION_TRIGGERED_FROM"));
+ subscription.setStatus(rs.getString("STATUS"));
+ subscription.setDeviceId(rs.getInt("DEVICE_ID"));
+
+ deviceSubscriptions.add(subscription);
+ }
+ return deviceSubscriptions;
+ }
+ }
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while obtaining the DB connection for getting device subscription for application Id: "
+ + appReleaseId + ".";
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ } catch (SQLException e) {
+ String msg = "Error occurred while running SQL to get device subscription data for application ID: " + appReleaseId;
+ log.error(msg, e);
+ throw new ApplicationManagementDAOException(msg, e);
+ }
+ }
}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/ApplicationManagerImpl.java
index efb55e60cb..2e8233f9dc 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/ApplicationManagerImpl.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/ApplicationManagerImpl.java
@@ -30,6 +30,7 @@ import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.App;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
+import io.entgra.device.mgt.core.tenant.mgt.common.exception.TenantMgtException;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringEscapeUtils;
@@ -96,17 +97,19 @@ import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementEx
import io.entgra.device.mgt.core.device.mgt.core.dto.DeviceType;
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
-import org.wso2.carbon.stratos.common.beans.TenantInfoBean;
-import org.wso2.carbon.tenant.mgt.services.TenantMgtAdminService;
import org.wso2.carbon.user.api.UserRealm;
import org.wso2.carbon.user.api.UserStoreException;
import javax.ws.rs.core.Response;
+import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -723,24 +726,29 @@ public class ApplicationManagerImpl implements ApplicationManager {
* @throws ResourceManagementException if error occurred while uploading
*/
private ApplicationReleaseDTO uploadCustomAppReleaseArtifacts(ApplicationReleaseDTO releaseDTO, ApplicationArtifact applicationArtifact,
- String deviceType)
+ String deviceType)
throws ResourceManagementException, ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
- byte[] content = getByteContentOfApp(applicationArtifact);
- String md5OfApp = generateMD5OfApp(applicationArtifact, content);
- validateReleaseBinaryFileHash(md5OfApp);
- releaseDTO.setUuid(UUID.randomUUID().toString());
- releaseDTO.setAppHashValue(md5OfApp);
- releaseDTO.setInstallerName(applicationArtifact.getInstallerName());
+ try {
+ String md5OfApp = applicationStorageManager.
+ getMD5(Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())));
+ validateReleaseBinaryFileHash(md5OfApp);
+ releaseDTO.setUuid(UUID.randomUUID().toString());
+ releaseDTO.setAppHashValue(md5OfApp);
+ releaseDTO.setInstallerName(applicationArtifact.getInstallerName());
- try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
applicationStorageManager.uploadReleaseArtifact(releaseDTO, deviceType,
- binaryDuplicate, tenantId);
+ Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())), tenantId);
} catch (IOException e) {
String msg = "Error occurred when uploading release artifact into the server";
log.error(msg);
throw new ApplicationManagementException(msg, e);
+ } catch (StorageManagementException e) {
+ String msg = "Error occurred while md5sum value retrieving process: application UUID "
+ + releaseDTO.getUuid();
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
}
return addImageArtifacts(releaseDTO, applicationArtifact, tenantId);
}
@@ -769,6 +777,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
return Constants.GOOGLE_PLAY_STORE_URL;
} else if (DeviceTypes.IOS.toString().equalsIgnoreCase(deviceType)) {
return Constants.APPLE_STORE_URL;
+ } else if (DeviceTypes.WINDOWS.toString().equalsIgnoreCase(deviceType)) {
+ return Constants.MICROSOFT_STORE_URL;
} else {
throw new IllegalArgumentException("No such device with the name " + deviceType);
}
@@ -856,82 +866,77 @@ public class ApplicationManagerImpl implements ApplicationManager {
String uuid = UUID.randomUUID().toString();
applicationReleaseDTO.setUuid(uuid);
-
// The application executable artifacts such as apks are uploaded.
try {
- byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
applicationReleaseDTO.setInstallerName(applicationArtifact.getInstallerName());
- try (ByteArrayInputStream binary = new ByteArrayInputStream(content)) {
- if (!DeviceTypes.WINDOWS.toString().equalsIgnoreCase(deviceType)) {
- ApplicationInstaller applicationInstaller = applicationStorageManager
- .getAppInstallerData(binary, deviceType);
- applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
- applicationReleaseDTO.setPackageName(applicationInstaller.getPackageName());
- } else {
- String windowsInstallerName = applicationArtifact.getInstallerName();
- String extension = windowsInstallerName.substring(windowsInstallerName.lastIndexOf(".") + 1);
- if (!extension.equalsIgnoreCase(Constants.MSI) &&
- !extension.equalsIgnoreCase(Constants.APPX)) {
- String msg = "Application Type doesn't match with supporting application types of " +
- deviceType + "platform which are APPX and MSI";
- log.error(msg);
- throw new BadRequestException(msg);
- }
- }
-
- String packageName = applicationReleaseDTO.getPackageName();
- try {
- ConnectionManagerUtil.openDBConnection();
- if (!isNewRelease && applicationReleaseDAO
- .isActiveReleaseExisitForPackageName(packageName, tenantId,
- lifecycleStateManager.getEndState())) {
- String msg = "Application release is already exist for the package name: " + packageName
- + ". Either you can delete all application releases for package " + packageName + " or "
- + "you can add this app release as an new application release, under the existing "
- + "application.";
- log.error(msg);
- throw new ApplicationManagementException(msg);
- }
- String md5OfApp = applicationStorageManager.getMD5(new ByteArrayInputStream(content));
- if (md5OfApp == null) {
- String msg = "Error occurred while md5sum value retrieving process: application UUID "
- + applicationReleaseDTO.getUuid();
- log.error(msg);
- throw new ApplicationStorageManagementException(msg);
- }
- if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
- String msg =
- "Application release exists for the uploaded binary file. Device Type: " + deviceType;
- log.error(msg);
- throw new BadRequestException(msg);
- }
- applicationReleaseDTO.setAppHashValue(md5OfApp);
-
- try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
- applicationStorageManager
- .uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate, tenantId);
- }
- } catch (StorageManagementException e) {
- String msg = "Error occurred while md5sum value retrieving process: application UUID "
- + applicationReleaseDTO.getUuid();
- log.error(msg, e);
- throw new ApplicationStorageManagementException(msg, e);
- } catch (DBConnectionException e) {
- String msg = "Error occurred when getting database connection for verifying app release data.";
- log.error(msg, e);
- throw new ApplicationManagementException(msg, e);
- } catch (ApplicationManagementDAOException e) {
- String msg =
- "Error occurred when executing the query for verifying application release existence for "
- + "the package.";
- log.error(msg, e);
- throw new ApplicationManagementException(msg, e);
- } finally {
- ConnectionManagerUtil.closeDBConnection();
+ if (!DeviceTypes.WINDOWS.toString().equalsIgnoreCase(deviceType)) {
+ ApplicationInstaller applicationInstaller = applicationStorageManager
+ .getAppInstallerData(Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())), deviceType);
+ applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
+ applicationReleaseDTO.setPackageName(applicationInstaller.getPackageName());
+ } else {
+ String windowsInstallerName = applicationArtifact.getInstallerName();
+ String extension = windowsInstallerName.substring(windowsInstallerName.lastIndexOf(".") + 1);
+ if (!extension.equalsIgnoreCase(Constants.MSI) &&
+ !extension.equalsIgnoreCase(Constants.APPX)) {
+ String msg = "Application Type doesn't match with supporting application types of " +
+ deviceType + "platform which are APPX and MSI";
+ log.error(msg);
+ throw new BadRequestException(msg);
}
}
+
+ String packageName = applicationReleaseDTO.getPackageName();
+ try {
+ ConnectionManagerUtil.openDBConnection();
+ if (!isNewRelease && applicationReleaseDAO
+ .isActiveReleaseExisitForPackageName(packageName, tenantId,
+ lifecycleStateManager.getEndState())) {
+ String msg = "Application release is already exist for the package name: " + packageName
+ + ". Either you can delete all application releases for package " + packageName + " or "
+ + "you can add this app release as an new application release, under the existing "
+ + "application.";
+ log.error(msg);
+ throw new ApplicationManagementException(msg);
+ }
+ String md5OfApp = applicationStorageManager.
+ getMD5(Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())));
+ if (md5OfApp == null) {
+ String msg = "Error occurred while md5sum value retrieving process: application UUID "
+ + applicationReleaseDTO.getUuid();
+ log.error(msg);
+ throw new ApplicationStorageManagementException(msg);
+ }
+ if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
+ String msg =
+ "Application release exists for the uploaded binary file. Device Type: " + deviceType;
+ log.error(msg);
+ throw new BadRequestException(msg);
+ }
+ applicationReleaseDTO.setAppHashValue(md5OfApp);
+ applicationStorageManager
+ .uploadReleaseArtifact(applicationReleaseDTO, deviceType,
+ Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())), tenantId);
+ } catch (StorageManagementException e) {
+ String msg = "Error occurred while md5sum value retrieving process: application UUID "
+ + applicationReleaseDTO.getUuid();
+ log.error(msg, e);
+ throw new ApplicationStorageManagementException(msg, e);
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred when getting database connection for verifying app release data.";
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } catch (ApplicationManagementDAOException e) {
+ String msg =
+ "Error occurred when executing the query for verifying application release existence for "
+ + "the package.";
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } finally {
+ ConnectionManagerUtil.closeDBConnection();
+ }
} catch (IOException e) {
- String msg = "Error occurred when getting byte array of binary file. Installer name: " + applicationArtifact
+ String msg = "Error occurred when getting file input stream. Installer name: " + applicationArtifact
.getInstallerName();
log.error(msg, e);
throw new ApplicationStorageManagementException(msg, e);
@@ -957,73 +962,64 @@ public class ApplicationManagerImpl implements ApplicationManager {
// The application executable artifacts such as apks are uploaded.
try {
- byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
+ String md5OfApp = applicationStorageManager.getMD5(Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())));
+ if (md5OfApp == null) {
+ String msg = "Error occurred while retrieving md5sum value from the binary file for application "
+ + "release UUID " + applicationReleaseDTO.getUuid();
+ log.error(msg);
+ throw new ApplicationStorageManagementException(msg);
+ }
- try (ByteArrayInputStream binaryClone = new ByteArrayInputStream(content)) {
- String md5OfApp = applicationStorageManager.getMD5(binaryClone);
+ if (!applicationReleaseDTO.getAppHashValue().equals(md5OfApp)) {
+ applicationReleaseDTO.setInstallerName(applicationArtifact.getInstallerName());
+ ApplicationInstaller applicationInstaller = applicationStorageManager
+ .getAppInstallerData(Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())), deviceType);
+ String packageName = applicationInstaller.getPackageName();
- if (md5OfApp == null) {
- String msg = "Error occurred while retrieving md5sum value from the binary file for application "
- + "release UUID " + applicationReleaseDTO.getUuid();
- log.error(msg);
- throw new ApplicationStorageManagementException(msg);
- }
- if (!applicationReleaseDTO.getAppHashValue().equals(md5OfApp)) {
- applicationReleaseDTO.setInstallerName(applicationArtifact.getInstallerName());
-
- try (ByteArrayInputStream binary = new ByteArrayInputStream(content)) {
- ApplicationInstaller applicationInstaller = applicationStorageManager
- .getAppInstallerData(binary, deviceType);
- String packageName = applicationInstaller.getPackageName();
-
- try {
- ConnectionManagerUtil.getDBConnection();
- if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
- String msg = "Same binary file is in the server. Hence you can't add same file into the "
- + "server. Device Type: " + deviceType + " and package name: " + packageName;
- log.error(msg);
- throw new BadRequestException(msg);
- }
- if (applicationReleaseDTO.getPackageName() == null){
- String msg = "Found null value for application release package name for application "
- + "release which has UUID: " + applicationReleaseDTO.getUuid();
- log.error(msg);
- throw new ApplicationManagementException(msg);
- }
- if (!applicationReleaseDTO.getPackageName().equals(packageName)){
- String msg = "Package name of the new artifact does not match with the package name of "
- + "the exiting application release. Package name of the existing app release "
- + applicationReleaseDTO.getPackageName() + " and package name of the new "
- + "application release " + packageName;
- log.error(msg);
- throw new BadRequestException(msg);
- }
-
- applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
- applicationReleaseDTO.setPackageName(packageName);
- String deletingAppHashValue = applicationReleaseDTO.getAppHashValue();
- applicationReleaseDTO.setAppHashValue(md5OfApp);
- try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
- applicationStorageManager
- .uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate,
- tenantId);
- applicationStorageManager.copyImageArtifactsAndDeleteInstaller(deletingAppHashValue,
- applicationReleaseDTO, tenantId);
- }
- } catch (DBConnectionException e) {
- String msg = "Error occurred when getting database connection for verifying application "
- + "release existing for new app hash value.";
- log.error(msg, e);
- throw new ApplicationManagementException(msg, e);
- } catch (ApplicationManagementDAOException e) {
- String msg = "Error occurred when executing the query for verifying application release "
- + "existence for the new app hash value.";
- log.error(msg, e);
- throw new ApplicationManagementException(msg, e);
- } finally {
- ConnectionManagerUtil.closeDBConnection();
- }
+ try {
+ ConnectionManagerUtil.getDBConnection();
+ if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
+ String msg = "Same binary file is in the server. Hence you can't add same file into the "
+ + "server. Device Type: " + deviceType + " and package name: " + packageName;
+ log.error(msg);
+ throw new BadRequestException(msg);
}
+ if (applicationReleaseDTO.getPackageName() == null) {
+ String msg = "Found null value for application release package name for application "
+ + "release which has UUID: " + applicationReleaseDTO.getUuid();
+ log.error(msg);
+ throw new ApplicationManagementException(msg);
+ }
+ if (!applicationReleaseDTO.getPackageName().equals(packageName)) {
+ String msg = "Package name of the new artifact does not match with the package name of "
+ + "the exiting application release. Package name of the existing app release "
+ + applicationReleaseDTO.getPackageName() + " and package name of the new "
+ + "application release " + packageName;
+ log.error(msg);
+ throw new BadRequestException(msg);
+ }
+
+ applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
+ applicationReleaseDTO.setPackageName(packageName);
+ String deletingAppHashValue = applicationReleaseDTO.getAppHashValue();
+ applicationReleaseDTO.setAppHashValue(md5OfApp);
+ applicationStorageManager.uploadReleaseArtifact(applicationReleaseDTO, deviceType,
+ Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())),
+ tenantId);
+ applicationStorageManager.copyImageArtifactsAndDeleteInstaller(deletingAppHashValue,
+ applicationReleaseDTO, tenantId);
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred when getting database connection for verifying application "
+ + "release existing for new app hash value.";
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } catch (ApplicationManagementDAOException e) {
+ String msg = "Error occurred when executing the query for verifying application release "
+ + "existence for the new app hash value.";
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } finally {
+ ConnectionManagerUtil.closeDBConnection();
}
}
} catch (StorageManagementException e) {
@@ -1032,7 +1028,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg, e);
throw new ApplicationStorageManagementException(msg, e);
} catch (IOException e) {
- String msg = "Error occurred when getting byte array of binary file. Installer name: " + applicationArtifact
+ String msg = "Error occurred when getting file input stream. Installer name: " + applicationArtifact
.getInstallerName();
log.error(msg, e);
throw new ApplicationStorageManagementException(msg, e);
@@ -3607,52 +3603,49 @@ public class ApplicationManagerImpl implements ApplicationManager {
DeviceType deviceTypeObj = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
// The application executable artifacts such as deb are uploaded.
try {
- byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
- try (ByteArrayInputStream binaryClone = new ByteArrayInputStream(content)) {
- String md5OfApp = applicationStorageManager.getMD5(binaryClone);
- if (md5OfApp == null) {
- String msg = "Error occurred while retrieving md5sum value from the binary file for "
- + "application release UUID " + applicationReleaseDTO.get().getUuid();
- log.error(msg);
- throw new ApplicationStorageManagementException(msg);
- }
- if (!applicationReleaseDTO.get().getAppHashValue().equals(md5OfApp)) {
- try {
- ConnectionManagerUtil.getDBConnection();
- if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
- String msg =
- "Same binary file is in the server. Hence you can't add same file into the "
- + "server. Device Type: " + deviceTypeObj.getName()
- + " and package name: " + applicationDTO.getApplicationReleaseDTOs()
- .get(0).getPackageName();
- log.error(msg);
- throw new BadRequestException(msg);
- }
+ String md5OfApp = applicationStorageManager.getMD5(
+ Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())));
+ if (md5OfApp == null) {
+ String msg = "Error occurred while retrieving md5sum value from the binary file for "
+ + "application release UUID " + applicationReleaseDTO.get().getUuid();
+ log.error(msg);
+ throw new ApplicationStorageManagementException(msg);
+ }
- applicationReleaseDTO.get().setInstallerName(applicationArtifact.getInstallerName());
- String deletingAppHashValue = applicationReleaseDTO.get().getAppHashValue();
- applicationReleaseDTO.get().setAppHashValue(md5OfApp);
- try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
- applicationStorageManager
- .uploadReleaseArtifact(applicationReleaseDTO.get(), deviceTypeObj.getName(),
- binaryDuplicate, tenantId);
- applicationStorageManager.copyImageArtifactsAndDeleteInstaller(deletingAppHashValue,
- applicationReleaseDTO.get(), tenantId);
- }
- } catch (DBConnectionException e) {
- String msg = "Error occurred when getting database connection for verifying application"
- + " release existing for new app hash value.";
- log.error(msg, e);
- throw new ApplicationManagementException(msg, e);
- } catch (ApplicationManagementDAOException e) {
+ if (!applicationReleaseDTO.get().getAppHashValue().equals(md5OfApp)) {
+ try {
+ ConnectionManagerUtil.getDBConnection();
+ if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
String msg =
- "Error occurred when executing the query for verifying application release "
- + "existence for the new app hash value.";
- log.error(msg, e);
- throw new ApplicationManagementException(msg, e);
- } finally {
- ConnectionManagerUtil.closeDBConnection();
+ "Same binary file is in the server. Hence you can't add same file into the "
+ + "server. Device Type: " + deviceTypeObj.getName()
+ + " and package name: " + applicationDTO.getApplicationReleaseDTOs()
+ .get(0).getPackageName();
+ log.error(msg);
+ throw new BadRequestException(msg);
}
+
+ applicationReleaseDTO.get().setInstallerName(applicationArtifact.getInstallerName());
+ String deletingAppHashValue = applicationReleaseDTO.get().getAppHashValue();
+ applicationReleaseDTO.get().setAppHashValue(md5OfApp);
+ applicationStorageManager.
+ uploadReleaseArtifact(applicationReleaseDTO.get(), deviceTypeObj.getName(),
+ Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())), tenantId);
+ applicationStorageManager.copyImageArtifactsAndDeleteInstaller(deletingAppHashValue,
+ applicationReleaseDTO.get(), tenantId);
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred when getting database connection for verifying application"
+ + " release existing for new app hash value.";
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } catch (ApplicationManagementDAOException e) {
+ String msg =
+ "Error occurred when executing the query for verifying application release "
+ + "existence for the new app hash value.";
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } finally {
+ ConnectionManagerUtil.closeDBConnection();
}
}
} catch (StorageManagementException e) {
@@ -4424,7 +4417,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
spApplicationDAO.deleteSPApplicationMappingByTenant(tenantId);
spApplicationDAO.deleteIdentityServerByTenant(tenantId);
applicationDAO.deleteApplicationsByTenant(tenantId);
- APIUtil.getApplicationStorageManager().deleteAppFolderOfTenant(tenantId);
ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) {
@@ -4449,12 +4441,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
+ " of tenant ID: " + tenantId ;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
- } catch (ApplicationStorageManagementException e) {
- ConnectionManagerUtil.rollbackDBTransaction();
- String msg = "Error occurred while deleting App folder of tenant"
- + " of tenant ID: " + tenantId ;
- log.error(msg, e);
- throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
@@ -4463,19 +4449,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
@Override
public void deleteApplicationDataByTenantDomain(String tenantDomain) throws ApplicationManagementException {
int tenantId;
- try{
- TenantMgtAdminService tenantMgtAdminService = new TenantMgtAdminService();
- TenantInfoBean tenantInfoBean = tenantMgtAdminService.getTenant(tenantDomain);
- tenantId = tenantInfoBean.getTenantId();
-
- } catch (Exception e) {
- String msg = "Error getting tenant ID from domain: "
- + tenantDomain;
- log.error(msg, e);
- throw new ApplicationManagementException(msg, e);
- }
-
try {
+ tenantId = DataHolder.getInstance().getTenantManagerAdminService().getTenantId(tenantDomain);
+
ConnectionManagerUtil.beginDBTransaction();
vppApplicationDAO.deleteAssociationByTenant(tenantId);
@@ -4499,40 +4475,54 @@ public class ApplicationManagerImpl implements ApplicationManager {
spApplicationDAO.deleteSPApplicationMappingByTenant(tenantId);
spApplicationDAO.deleteIdentityServerByTenant(tenantId);
applicationDAO.deleteApplicationsByTenant(tenantId);
- APIUtil.getApplicationStorageManager().deleteAppFolderOfTenant(tenantId);
ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) {
- String msg = "Error occurred while observing the database connection to delete applications for tenant with ID: "
- + tenantId;
+ String msg = "Error occurred while observing the database connection to delete applications for tenant with " +
+ "domain: " + tenantDomain;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
- String msg = "Database access error is occurred when getting applications for tenant with ID: " + tenantId;
+ String msg = "Database access error is occurred when getting applications for tenant with domain: "
+ + tenantDomain;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (LifeCycleManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred while deleting life-cycle state data of application releases of the tenant"
- + " of ID: " + tenantId ;
+ + " of domain: " + tenantDomain ;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ReviewManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred while deleting reviews of application releases of the applications"
- + " of tenant ID: " + tenantId ;
+ + " of tenant of domain: " + tenantDomain ;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
- } catch (ApplicationStorageManagementException e) {
- ConnectionManagerUtil.rollbackDBTransaction();
- String msg = "Error occurred while deleting App folder of tenant"
- + " of tenant ID: " + tenantId ;
+ } catch (Exception e) {
+ String msg = "Error getting tenant ID from domain: "
+ + tenantDomain;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
- } finally {
- ConnectionManagerUtil.closeDBConnection();
}
+ }
+ @Override
+ public void deleteApplicationArtifactsByTenantDomain(String tenantDomain) throws ApplicationManagementException {
+ int tenantId;
+ try {
+ tenantId = DataHolder.getInstance().getTenantManagerAdminService().getTenantId(tenantDomain);
+ DataHolder.getInstance().getApplicationStorageManager().deleteAppFolderOfTenant(tenantId);
+ } catch (ApplicationStorageManagementException e) {
+ String msg = "Error deleting app artifacts of tenant of domain: " + tenantDomain ;
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } catch (TenantMgtException e) {
+ String msg = "Error getting tenant ID from domain: "
+ + tenantDomain + " when trying to delete application artifacts of tenant";
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ }
}
}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/ApplicationStorageManagerImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/ApplicationStorageManagerImpl.java
index 158361232c..ad1906ede1 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/ApplicationStorageManagerImpl.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/ApplicationStorageManagerImpl.java
@@ -37,6 +37,7 @@ import io.entgra.device.mgt.core.device.mgt.core.common.exception.StorageManagem
import io.entgra.device.mgt.core.device.mgt.core.common.util.StorageManagementUtil;
import java.io.*;
+import java.nio.file.Paths;
import java.util.List;
import static io.entgra.device.mgt.core.device.mgt.core.common.util.StorageManagementUtil.saveFile;
@@ -155,13 +156,12 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
public void uploadReleaseArtifact(ApplicationReleaseDTO applicationReleaseDTO,
String deviceType, InputStream binaryFile, int tenantId) throws ResourceManagementException {
try {
- byte [] content = IOUtils.toByteArray(binaryFile);
String artifactDirectoryPath =
storagePath + tenantId + File.separator + applicationReleaseDTO.getAppHashValue() + File.separator
+ Constants.APP_ARTIFACT;
StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath);
String artifactPath = artifactDirectoryPath + File.separator + applicationReleaseDTO.getInstallerName();
- saveFile(new ByteArrayInputStream(content), artifactPath);
+ saveFile(binaryFile, artifactPath);
} catch (IOException e) {
String msg = "IO Exception while saving the release artifacts in the server for the application UUID "
+ applicationReleaseDTO.getUuid();
@@ -324,4 +324,12 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
}
}
}
+
+ @Override
+ public String getAbsolutePathOfFile(String hashVal, String folderName, String fileName, int tenantId) {
+ String filePath =
+ storagePath + tenantId + File.separator + hashVal + File.separator + folderName + File.separator
+ + fileName;
+ return Paths.get(filePath).toAbsolutePath().toString();
+ }
}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/FileTransferServiceImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/FileTransferServiceImpl.java
index 52789308fd..8af3324c67 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/FileTransferServiceImpl.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/FileTransferServiceImpl.java
@@ -31,6 +31,7 @@ import io.entgra.device.mgt.core.device.mgt.common.exceptions.NotFoundException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.FileSystems;
@@ -103,8 +104,13 @@ public class FileTransferServiceImpl implements FileTransferService {
@Override
public boolean isExistsOnLocal(URL downloadUrl) throws FileTransferServiceException {
try {
- return FileTransferServiceHelperUtil.resolve(downloadUrl) != null;
- } catch (FileTransferServiceHelperUtilException e) {
+ FileDescriptor fileDescriptor = FileTransferServiceHelperUtil.resolve(downloadUrl);
+ if (fileDescriptor != null && fileDescriptor.getFile() != null) {
+ fileDescriptor.getFile().close();
+ return true;
+ }
+ return false;
+ } catch (FileTransferServiceHelperUtilException | IOException e) {
String msg = "Error occurred while checking the existence of artifact on the local environment";
log.error(msg, e);
throw new FileTransferServiceException(msg, e);
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/SubscriptionManagerImpl.java
index 931c45ddcf..49552ea153 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/SubscriptionManagerImpl.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/SubscriptionManagerImpl.java
@@ -19,17 +19,42 @@
package io.entgra.device.mgt.core.application.mgt.core.impl;
import com.google.gson.Gson;
+import io.entgra.device.mgt.core.application.mgt.common.ApplicationInstallResponse;
+import io.entgra.device.mgt.core.application.mgt.common.ApplicationSubscriptionInfo;
+import io.entgra.device.mgt.core.application.mgt.common.ApplicationType;
+import io.entgra.device.mgt.core.application.mgt.common.CategorizedSubscriptionResult;
+import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionData;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionResponse;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionStatistics;
+import io.entgra.device.mgt.core.application.mgt.common.dto.CategorizedSubscriptionCountsDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceOperationDTO;
+import io.entgra.device.mgt.core.application.mgt.common.DeviceTypes;
+import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus;
+import io.entgra.device.mgt.core.application.mgt.common.SubAction;
+import io.entgra.device.mgt.core.application.mgt.common.SubscribingDeviceIdHolder;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionType;
+import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.ScheduledSubscriptionDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationPolicyDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssetDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
import io.entgra.device.mgt.core.application.mgt.common.services.VPPApplicationManager;
+import io.entgra.device.mgt.core.application.mgt.core.dao.ApplicationReleaseDAO;
import io.entgra.device.mgt.core.application.mgt.core.dao.VppApplicationDAO;
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
+import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.SubscriptionManagementServiceProvider;
+import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.service.SubscriptionManagementHelperService;
+import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
+import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants;
import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException;
+import io.entgra.device.mgt.core.device.mgt.core.dto.OperationDTO;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.AppInstallLogContext;
import io.entgra.device.mgt.core.notification.logger.impl.EntgraAppInstallLoggerImpl;
-import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpResponse;
@@ -45,20 +70,6 @@ import org.json.JSONObject;
import io.entgra.device.mgt.core.apimgt.application.extension.dto.ApiApplicationKey;
import io.entgra.device.mgt.core.apimgt.application.extension.exception.APIManagerException;
import org.wso2.carbon.context.PrivilegedCarbonContext;
-import io.entgra.device.mgt.core.application.mgt.common.ApplicationInstallResponse;
-import io.entgra.device.mgt.core.application.mgt.common.ApplicationSubscriptionInfo;
-import io.entgra.device.mgt.core.application.mgt.common.ApplicationType;
-import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionData;
-import io.entgra.device.mgt.core.application.mgt.common.DeviceTypes;
-import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus;
-import io.entgra.device.mgt.core.application.mgt.common.SubAction;
-import io.entgra.device.mgt.core.application.mgt.common.SubscriptionType;
-import io.entgra.device.mgt.core.application.mgt.common.SubscribingDeviceIdHolder;
-import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
-import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationPolicyDTO;
-import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO;
-import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
-import io.entgra.device.mgt.core.application.mgt.common.dto.ScheduledSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.device.mgt.core.application.mgt.common.exception.DBConnectionException;
import io.entgra.device.mgt.core.application.mgt.common.exception.LifecycleManagementException;
@@ -131,12 +142,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
private SubscriptionDAO subscriptionDAO;
private ApplicationDAO applicationDAO;
private VppApplicationDAO vppApplicationDAO;
+ private ApplicationReleaseDAO applicationReleaseDAO;
private LifecycleStateManager lifecycleStateManager;
public SubscriptionManagerImpl() {
this.lifecycleStateManager = DataHolder.getInstance().getLifecycleStateManager();
this.subscriptionDAO = ApplicationManagementDAOFactory.getSubscriptionDAO();
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
+ this.applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO();
this.vppApplicationDAO = ApplicationManagementDAOFactory.getVppApplicationDAO();
}
@@ -1505,16 +1518,19 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
@Override
- public PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus,
- String action, String installedVersion) throws ApplicationManagementException {
+ public CategorizedSubscriptionResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus,
+ String action, String installedVersion) throws ApplicationManagementException {
int limitValue = request.getRowCount();
int offsetValue = request.getStartIndex();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
- DeviceManagementProviderService deviceManagementProviderService = HelperUtil
- .getDeviceManagementProviderService();
+ DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
+ List installedDevices = new ArrayList<>();
+ List pendingDevices = new ArrayList<>();
+ List errorDevices = new ArrayList<>();
+
if (offsetValue < 0 || limitValue <= 0) {
- String msg = "Found incompatible values for offset and limit. Hence please check the request and resend. "
- + "Offset " + offsetValue + " limit " + limitValue;
+ String msg = "Found incompatible values for offset and limit. Hence please check the request and resend. " +
+ "Offset " + offsetValue + " limit " + limitValue;
log.error(msg);
throw new BadRequestException(msg);
}
@@ -1532,31 +1548,26 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List deviceSubscriptionDTOS = subscriptionDAO
.getDeviceSubscriptions(applicationReleaseId, tenantId, actionStatus, action);
if (deviceSubscriptionDTOS.isEmpty()) {
- PaginationResult paginationResult = new PaginationResult();
- paginationResult.setData(new ArrayList<>());
- paginationResult.setRecordsFiltered(0);
- paginationResult.setRecordsTotal(0);
- return paginationResult;
+ return new CategorizedSubscriptionResult(new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
}
List deviceIdList = deviceSubscriptionDTOS.stream().map(DeviceSubscriptionDTO::getDeviceId)
.collect(Collectors.toList());
- Map currentVersionsMap = subscriptionDAO.getCurrentInstalledAppVersion(applicationDTO.getId(),deviceIdList, installedVersion);
+ Map currentVersionsMap =
+ subscriptionDAO.getCurrentInstalledAppVersion(applicationDTO.getId(), deviceIdList, installedVersion);
try {
- //pass the device id list to device manager service method
- PaginationResult paginationResult = deviceManagementProviderService.getAppSubscribedDevices
- (request, deviceIdList);
- List deviceSubscriptionDataList = new ArrayList<>();
+ // Pass the device id list to device manager service method
+ PaginationResult paginationResult = deviceManagementProviderService.getAppSubscribedDevices(request, deviceIdList);
if (!paginationResult.getData().isEmpty()) {
List devices = (List) paginationResult.getData();
for (Device device : devices) {
- if(installedVersion != null && !installedVersion.isEmpty() && !currentVersionsMap.containsKey(device.getId())){
+ if (installedVersion != null && !installedVersion.isEmpty() && !currentVersionsMap.containsKey(device.getId())) {
continue;
}
DeviceSubscriptionData deviceSubscriptionData = new DeviceSubscriptionData();
- if(currentVersionsMap.containsKey(device.getId())){
+ if (currentVersionsMap.containsKey(device.getId())) {
deviceSubscriptionData.setCurrentInstalledVersion(currentVersionsMap.get(device.getId()));
- }else{
+ } else {
deviceSubscriptionData.setCurrentInstalledVersion("-");
}
for (DeviceSubscriptionDTO subscription : deviceSubscriptionDTOS) {
@@ -1565,39 +1576,51 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (subscription.isUnsubscribed()) {
deviceSubscriptionData.setAction(Constants.UNSUBSCRIBED);
deviceSubscriptionData.setActionTriggeredBy(subscription.getUnsubscribedBy());
- deviceSubscriptionData
- .setActionTriggeredTimestamp(subscription.getUnsubscribedTimestamp().getTime() / 1000);
+ deviceSubscriptionData.setActionTriggeredTimestamp(subscription.getUnsubscribedTimestamp());
} else {
deviceSubscriptionData.setAction(Constants.SUBSCRIBED);
deviceSubscriptionData.setActionTriggeredBy(subscription.getSubscribedBy());
- deviceSubscriptionData
- .setActionTriggeredTimestamp(subscription.getSubscribedTimestamp().getTime() / 1000);
+ deviceSubscriptionData.setActionTriggeredTimestamp(subscription.getSubscribedTimestamp());
}
deviceSubscriptionData.setActionType(subscription.getActionTriggeredFrom());
deviceSubscriptionData.setStatus(subscription.getStatus());
deviceSubscriptionData.setSubId(subscription.getId());
- deviceSubscriptionDataList.add(deviceSubscriptionData);
+
+ // Categorize the subscription data based on its status
+ switch (subscription.getStatus()) {
+ case "COMPLETED":
+ installedDevices.add(deviceSubscriptionData);
+ break;
+ case "ERROR":
+ case "INVALID":
+ case "UNAUTHORIZED":
+ errorDevices.add(deviceSubscriptionData);
+ break;
+ case "IN_PROGRESS":
+ case "PENDING":
+ case "REPEATED":
+ pendingDevices.add(deviceSubscriptionData);
+ break;
+ }
break;
}
}
}
}
- paginationResult.setData(deviceSubscriptionDataList);
- return paginationResult;
+ return new CategorizedSubscriptionResult(installedDevices, pendingDevices, errorDevices);
} catch (DeviceManagementException e) {
- String msg = "service error occurred while getting device data from the device management service. "
- + "Device ids " + deviceIdList;
+ String msg = "Service error occurred while getting device data from the device management service. " +
+ "Device ids " + deviceIdList;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
} catch (ApplicationManagementDAOException e) {
- String msg =
- "Error occurred when getting application release data for application release UUID: " + appUUID;
+ String msg = "Error occurred when getting application release data for application release UUID: " + appUUID;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) {
- String msg = "DB Connection error occurred while trying to get subscription data of application which has "
- + "application release UUID " + appUUID;
+ String msg = "DB Connection error occurred while trying to get subscription data of application which has " +
+ "application release UUID " + appUUID;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
@@ -1675,4 +1698,148 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
}
+ /**
+ * Get subscription data describes by {@link SubscriptionInfo} entity
+ * @param subscriptionInfo {@link SubscriptionInfo}
+ * @param limit Limit value
+ * @param offset Offset value
+ * @return {@link SubscriptionResponse}
+ * @throws ApplicationManagementException Throws when error encountered while getting subscription data
+ */
+ @Override
+ public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
+ throws ApplicationManagementException {
+ SubscriptionManagementHelperService subscriptionManagementHelperService =
+ SubscriptionManagementServiceProvider.getInstance().getSubscriptionManagementHelperService(subscriptionInfo);
+ return subscriptionManagementHelperService.getSubscriptions(subscriptionInfo, limit, offset);
+ }
+
+ /**
+ * Get status based subscription data describes by {@link SubscriptionInfo} entity
+ * @param subscriptionInfo {@link SubscriptionInfo}
+ * @param limit Limit value
+ * @param offset Offset value
+ * @return {@link SubscriptionResponse}
+ * @throws ApplicationManagementException Throws when error encountered while getting subscription data
+ */
+ @Override
+ public SubscriptionResponse getStatusBaseSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
+ throws ApplicationManagementException {
+ SubscriptionManagementHelperService subscriptionManagementHelperService =
+ SubscriptionManagementServiceProvider.getInstance().getSubscriptionManagementHelperService(subscriptionInfo);
+ return subscriptionManagementHelperService.getStatusBaseSubscriptions(subscriptionInfo, limit, offset);
+ }
+
+ /**
+ * Get subscription statistics related data describes by the {@link SubscriptionInfo}
+ * @param subscriptionInfo {@link SubscriptionInfo}
+ * @return {@link SubscriptionStatistics}
+ * @throws ApplicationManagementException Throws when error encountered while getting statistics
+ */
+ @Override
+ public SubscriptionStatistics getStatistics(SubscriptionInfo subscriptionInfo) throws ApplicationManagementException {
+ return SubscriptionManagementServiceProvider.getInstance().getSubscriptionManagementHelperService(subscriptionInfo).
+ getSubscriptionStatistics(subscriptionInfo);
+ }
+
+ @Override
+ public List getSubscriptionOperationsByUUIDAndDeviceID(int deviceId, String uuid)
+ throws ApplicationManagementException {
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
+ if (uuid == null || uuid.isEmpty()) {
+ throw new IllegalArgumentException("UUID cannot be null or empty.");
+ }
+ try {
+ ConnectionManagerUtil.openDBConnection();
+
+ ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO.getReleaseByUUID(uuid, tenantId);
+ if (applicationReleaseDTO == null) {
+ String msg = "Couldn't find an application release for application release UUID: " + uuid;
+ log.error(msg);
+ throw new NotFoundException(msg);
+ }
+ int appReleaseId = applicationReleaseDTO.getId();
+
+ DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
+ List deviceSubscriptions =
+ subscriptionDAO.getSubscriptionOperationsByAppReleaseIDAndDeviceID(appReleaseId, deviceId, tenantId);
+ for (DeviceOperationDTO deviceSubscription : deviceSubscriptions) {
+ Integer operationId = deviceSubscription.getOperationId();
+ if (operationId != null) {
+ OperationDTO operationDetails = deviceManagementProviderService.getOperationDetailsById(operationId);
+ if (operationDetails != null) {
+ deviceSubscription.setOperationCode(operationDetails.getOperationCode());
+ deviceSubscription.setOperationDetails(operationDetails.getOperationDetails());
+ deviceSubscription.setOperationProperties(operationDetails.getOperationProperties());
+ deviceSubscription.setOperationResponses(operationDetails.getOperationResponses());
+ }
+ }
+ }
+ return deviceSubscriptions;
+ } catch (ApplicationManagementDAOException e) {
+ String msg = "Error occurred while retrieving device subscriptions for UUID: " + uuid;
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while retrieving the database connection";
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } catch (OperationManagementException e) {
+ throw new RuntimeException(e);
+ } finally {
+ ConnectionManagerUtil.closeDBConnection();
+ }
+ }
+
+ @Override
+ public List getSubscriptionCountsByUUID(String uuid)
+ throws ApplicationManagementException {
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
+ if (uuid == null || uuid.isEmpty()) {
+ throw new IllegalArgumentException("UUID cannot be null or empty.");
+ }
+
+ try {
+ ConnectionManagerUtil.openDBConnection();
+
+ ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO.getReleaseByUUID(uuid, tenantId);
+ if (applicationReleaseDTO == null) {
+ String msg = "Couldn't find an application release for application release UUID: " + uuid;
+ log.error(msg);
+ throw new NotFoundException(msg);
+ }
+ int appReleaseId = applicationReleaseDTO.getId();
+
+ List subscriptionCounts = new ArrayList<>();
+
+ subscriptionCounts.add(new CategorizedSubscriptionCountsDTO(
+ "Device",
+ subscriptionDAO.getAllSubscriptionCount(appReleaseId, tenantId),
+ subscriptionDAO.getAllUnsubscriptionCount(appReleaseId, tenantId)));
+ subscriptionCounts.add(new CategorizedSubscriptionCountsDTO(
+ "Group",
+ subscriptionDAO.getGroupSubscriptionCount(appReleaseId, tenantId),
+ subscriptionDAO.getGroupUnsubscriptionCount(appReleaseId, tenantId)));
+ subscriptionCounts.add(new CategorizedSubscriptionCountsDTO(
+ "Role",
+ subscriptionDAO.getRoleSubscriptionCount(appReleaseId, tenantId),
+ subscriptionDAO.getRoleUnsubscriptionCount(appReleaseId, tenantId)));
+ subscriptionCounts.add(new CategorizedSubscriptionCountsDTO(
+ "User",
+ subscriptionDAO.getUserSubscriptionCount(appReleaseId, tenantId),
+ subscriptionDAO.getUserUnsubscriptionCount(appReleaseId, tenantId)));
+
+ return subscriptionCounts;
+ } catch (ApplicationManagementDAOException e) {
+ String msg = "Error occurred while retrieving subscriptions counts for UUID: " + uuid;
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } catch (DBConnectionException e) {
+ String msg = "Error occurred while retrieving the database connection";
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } finally {
+ ConnectionManagerUtil.closeDBConnection();
+ }
+ }
}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/internal/ApplicationManagementServiceComponent.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/internal/ApplicationManagementServiceComponent.java
index 20cd9febbc..d1b8ff8288 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/internal/ApplicationManagementServiceComponent.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/internal/ApplicationManagementServiceComponent.java
@@ -33,7 +33,9 @@ import io.entgra.device.mgt.core.application.mgt.core.impl.FileTransferServiceIm
import io.entgra.device.mgt.core.application.mgt.core.lifecycle.LifecycleStateManager;
import io.entgra.device.mgt.core.application.mgt.core.task.ScheduledAppSubscriptionTaskManager;
import io.entgra.device.mgt.core.application.mgt.core.util.ApplicationManagementUtil;
+import io.entgra.device.mgt.core.device.mgt.core.internal.DeviceManagementDataHolder;
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
+import io.entgra.device.mgt.core.tenant.mgt.common.spi.TenantManagerAdminService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext;
@@ -71,6 +73,12 @@ import java.util.List;
* policy="dynamic"
* bind="setTaskService"
* unbind="unsetTaskService"
+ * @scr.reference name="io.entgra.device.mgt.core.tenant.manager"
+ * interface="io.entgra.device.mgt.core.tenant.mgt.common.spi.TenantManagerAdminService"
+ * cardinality="0..1"
+ * policy="dynamic"
+ * bind="setTenantManagementAdminService"
+ * unbind="unsetTenantManagementAdminService"
*/
@SuppressWarnings("unused")
public class ApplicationManagementServiceComponent {
@@ -196,4 +204,20 @@ public class ApplicationManagementServiceComponent {
}
DataHolder.getInstance().setTaskService(null);
}
+
+ @SuppressWarnings("unused")
+ protected void setTenantManagementAdminService(TenantManagerAdminService tenantManagerAdminService) {
+ if (log.isDebugEnabled()) {
+ log.debug("Setting Tenant management admin Service");
+ }
+ DataHolder.getInstance().setTenantManagerAdminService(tenantManagerAdminService);
+ }
+
+ @SuppressWarnings("unused")
+ protected void unsetTenantManagementAdminService(TenantManagerAdminService tenantManagerAdminService) {
+ if (log.isDebugEnabled()) {
+ log.debug("Un setting Tenant management admin service");
+ }
+ DataHolder.getInstance().setTenantManagerAdminService(null);
+ }
}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/internal/DataHolder.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/internal/DataHolder.java
index 80416dcd59..c67db70fb6 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/internal/DataHolder.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/internal/DataHolder.java
@@ -27,6 +27,8 @@ import io.entgra.device.mgt.core.application.mgt.common.services.SubscriptionMan
import io.entgra.device.mgt.core.application.mgt.common.services.VPPApplicationManager;
import io.entgra.device.mgt.core.application.mgt.core.lifecycle.LifecycleStateManager;
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
+import io.entgra.device.mgt.core.tenant.mgt.common.spi.TenantManagerAdminService;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.ntask.core.service.TaskService;
import org.wso2.carbon.user.core.service.RealmService;
@@ -57,6 +59,7 @@ public class DataHolder {
private TaskService taskService;
private FileTransferService fileTransferService;
+ private TenantManagerAdminService tenantManagerAdminService;
private static final DataHolder applicationMgtDataHolder = new DataHolder();
@@ -163,4 +166,12 @@ public class DataHolder {
public void setFileTransferService(FileTransferService fileTransferService) {
this.fileTransferService = fileTransferService;
}
+
+ public TenantManagerAdminService getTenantManagerAdminService() {
+ return tenantManagerAdminService;
+ }
+
+ public void setTenantManagerAdminService(TenantManagerAdminService tenantManagerAdminService) {
+ this.tenantManagerAdminService = tenantManagerAdminService;
+ }
}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/ApplicationManagementUtil.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/ApplicationManagementUtil.java
index 846777c794..6374aadb13 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/ApplicationManagementUtil.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/ApplicationManagementUtil.java
@@ -181,6 +181,7 @@ public class ApplicationManagementUtil {
fileDescriptor = FileDownloaderServiceProvider.getFileDownloaderService(artifactLinkUrl).download(artifactLinkUrl);
applicationArtifact.setInstallerName(fileDescriptor.getFullQualifiedName());
applicationArtifact.setInstallerStream(fileDescriptor.getFile());
+ applicationArtifact.setInstallerPath(fileDescriptor.getAbsolutePath());
}
if (iconLink != null) {
@@ -188,6 +189,7 @@ public class ApplicationManagementUtil {
fileDescriptor = FileDownloaderServiceProvider.getFileDownloaderService(iconLinkUrl).download(iconLinkUrl);
applicationArtifact.setIconName(fileDescriptor.getFullQualifiedName());
applicationArtifact.setIconStream(fileDescriptor.getFile());
+ applicationArtifact.setIconPath(fileDescriptor.getAbsolutePath());
}
if (bannerLink != null) {
@@ -195,10 +197,12 @@ public class ApplicationManagementUtil {
fileDescriptor = FileDownloaderServiceProvider.getFileDownloaderService(bannerLinkUrl).download(bannerLinkUrl);
applicationArtifact.setBannerName(fileDescriptor.getFullQualifiedName());
applicationArtifact.setBannerStream(fileDescriptor.getFile());
+ applicationArtifact.setBannerPath(fileDescriptor.getAbsolutePath());
}
if (screenshotLinks != null) {
Map screenshotData = new TreeMap<>();
+ Map screenshotPaths = new TreeMap<>();
// This is to handle cases in which multiple screenshots have the same name
Map screenshotNameCount = new HashMap<>();
URL screenshotLinkUrl;
@@ -209,6 +213,7 @@ public class ApplicationManagementUtil {
screenshotNameCount.put(screenshotName, screenshotNameCount.getOrDefault(screenshotName, 0) + 1);
screenshotName = FileUtil.generateDuplicateFileName(screenshotName, screenshotNameCount.get(screenshotName));
screenshotData.put(screenshotName, fileDescriptor.getFile());
+ screenshotPaths.put(screenshotName, fileDescriptor.getAbsolutePath());
}
applicationArtifact.setScreenshots(screenshotData);
}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/Constants.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/Constants.java
index b5b5fd5154..0b22db0668 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/Constants.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/Constants.java
@@ -74,6 +74,7 @@ public class Constants {
public static final String IS_USER_ABLE_TO_VIEW_ALL_ROLES = "isUserAbleToViewAllRoles";
public static final String GOOGLE_PLAY_STORE_URL = "https://play.google.com/store/apps/details?id=";
public static final String APPLE_STORE_URL = "https://itunes.apple.com/country/app/app-name/id";
+ public static final String MICROSOFT_STORE_URL = "https://apps.microsoft.com/detail/";
public static final String GOOGLE_PLAY_SYNCED_APP = "GooglePlaySyncedApp";
// Subscription task related constants
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/DAOUtil.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/DAOUtil.java
index 2177c6ad13..6b06a7aa62 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/DAOUtil.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/DAOUtil.java
@@ -383,7 +383,6 @@ public class DAOUtil {
activity.setAppType(rs.getString("TYPE"));
activity.setUsername(rs.getString("SUBSCRIBED_BY"));
activity.setPackageName(rs.getString("PACKAGE_NAME"));
- activity.setStatus(rs.getString("STATUS"));
activity.setVersion(rs.getString("VERSION"));
activity.setTriggeredBy(rs.getString("ACTION_TRIGGERED_FROM"));
activities.add(activity);
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/FileTransferServiceHelperUtil.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/FileTransferServiceHelperUtil.java
index 570998ebef..856faf4944 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/FileTransferServiceHelperUtil.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/FileTransferServiceHelperUtil.java
@@ -23,7 +23,9 @@ import com.google.gson.Gson;
import io.entgra.device.mgt.core.application.mgt.common.ChunkDescriptor;
import io.entgra.device.mgt.core.application.mgt.common.FileDescriptor;
import io.entgra.device.mgt.core.application.mgt.common.FileMetaEntry;
+import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationStorageManagementException;
import io.entgra.device.mgt.core.application.mgt.core.exception.FileTransferServiceHelperUtilException;
+import io.entgra.device.mgt.core.application.mgt.core.internal.DataHolder;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.NotFoundException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -175,6 +177,12 @@ public class FileTransferServiceHelperUtil {
}
String []urlPathSegments = downloadUrl.getPath().split("/");
+
+ FileDescriptor fileDescriptorResolvedFromRelease = resolve(urlPathSegments);
+ if (fileDescriptorResolvedFromRelease != null) {
+ return fileDescriptorResolvedFromRelease;
+ }
+
if (urlPathSegments.length < 2) {
if (log.isDebugEnabled()) {
log.debug("URL patch segments contain less than 2 segments");
@@ -234,4 +242,54 @@ public class FileTransferServiceHelperUtil {
throw new FileTransferServiceHelperUtilException("Error encountered while creating artifact file", e);
}
}
+
+ private static FileDescriptor resolve(String []urlSegments) throws FileTransferServiceHelperUtilException {
+ // check the possibility of url is pointing to a file resides in the default storage path
+ if (urlSegments.length < 4) {
+ if (log.isDebugEnabled()) {
+ log.debug("URL path segments contain less than 4 segments");
+ }
+ return null;
+ }
+
+ int tenantId;
+ try {
+ tenantId = Integer.parseInt(urlSegments[urlSegments.length - 4]);
+ } catch (NumberFormatException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("URL isn't pointing to a file resides in the default storage path");
+ }
+ return null;
+ }
+
+ String fileName = urlSegments[urlSegments.length - 1];
+ String folderName = urlSegments[urlSegments.length - 2];
+ String appHash = urlSegments[urlSegments.length - 3];
+
+ try {
+ InputStream fileStream = DataHolder.getInstance().
+ getApplicationStorageManager().getFileStream(appHash, folderName, fileName, tenantId);
+ if (fileStream == null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Could not found the file " + fileName);
+ }
+ return null;
+ }
+
+ String []fileNameSegments = fileName.split("\\.(?=[^.]+$)");
+ if (fileNameSegments.length < 2) {
+ throw new FileTransferServiceHelperUtilException("Invalid full qualified name encountered :" + fileName);
+ }
+ FileDescriptor fileDescriptor = new FileDescriptor();
+ fileDescriptor.setFile(fileStream);
+ fileDescriptor.setFullQualifiedName(fileName);
+ fileDescriptor.setExtension(fileNameSegments[fileNameSegments.length - 1]);
+ fileDescriptor.setFileName(fileNameSegments[fileNameSegments.length - 2]);
+ fileDescriptor.setAbsolutePath(DataHolder.getInstance().
+ getApplicationStorageManager().getAbsolutePathOfFile(appHash, folderName, fileName, tenantId));
+ return fileDescriptor;
+ } catch (ApplicationStorageManagementException e) {
+ throw new FileTransferServiceHelperUtilException("Error encountered while getting file input stream", e);
+ }
+ }
}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/SubscriptionManagementHelperUtil.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/SubscriptionManagementHelperUtil.java
new file mode 100644
index 0000000000..0fbc32b986
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/SubscriptionManagementHelperUtil.java
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt;
+
+import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscription;
+import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionFilterCriteria;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionData;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionMetadata;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionStatistics;
+import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionStatisticDTO;
+import io.entgra.device.mgt.core.application.mgt.core.util.HelperUtil;
+import io.entgra.device.mgt.core.device.mgt.common.Device;
+import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
+import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
+
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class SubscriptionManagementHelperUtil {
+
+ /**
+ * Retrieves device subscription data based on the provided filters.
+ *
+ * @param deviceSubscriptionDTOS List of DeviceSubscriptionDTO objects.
+ * @param deviceSubscriptionFilterCriteria Filter criteria for device subscription.
+ * @param isUnsubscribed Boolean indicating whether to filter unsubscribed devices.
+ * @param deviceTypeId Device type ID.
+ * @param limit Limit for pagination.
+ * @param offset Offset for pagination.
+ * @return List of DeviceSubscription objects.
+ * @throws DeviceManagementException If an error occurs during device management.
+ */
+ public static List getDeviceSubscriptionData(List deviceSubscriptionDTOS,
+ DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria,
+ boolean isUnsubscribed, int deviceTypeId, int limit, int offset)
+ throws DeviceManagementException {
+ List deviceIds = deviceSubscriptionDTOS.stream().map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
+ PaginationRequest paginationRequest = new PaginationRequest(offset, limit);
+ paginationRequest.setDeviceName(deviceSubscriptionFilterCriteria.getName());
+ paginationRequest.setDeviceStatus(deviceSubscriptionFilterCriteria.getDeviceStatus());
+ paginationRequest.setOwner(deviceSubscriptionFilterCriteria.getOwner());
+ paginationRequest.setDeviceTypeId(deviceTypeId);
+ List devices = HelperUtil.getDeviceManagementProviderService().getDevicesByDeviceIds(paginationRequest, deviceIds);
+ return populateDeviceData(deviceSubscriptionDTOS, devices, isUnsubscribed);
+ }
+
+ /**
+ * Retrieves the total count of device subscriptions based on the provided filters.
+ *
+ * @param deviceSubscriptionDTOS List of DeviceSubscriptionDTO objects.
+ * @param deviceSubscriptionFilterCriteria Filter criteria for device subscription.
+ * @param deviceTypeId Device type ID.
+ * @return int Total count of device subscriptions.
+ * @throws DeviceManagementException If an error occurs during device management.
+ */
+ public static int getTotalDeviceSubscriptionCount(List deviceSubscriptionDTOS,
+ DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria, int deviceTypeId)
+ throws DeviceManagementException {
+ List deviceIds = deviceSubscriptionDTOS.stream().map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
+ PaginationRequest paginationRequest = new PaginationRequest(-1, -1);
+ paginationRequest.setDeviceName(deviceSubscriptionFilterCriteria.getName());
+ paginationRequest.setDeviceStatus(deviceSubscriptionFilterCriteria.getDeviceStatus());
+ paginationRequest.setOwner(deviceSubscriptionFilterCriteria.getOwner());
+ paginationRequest.setDeviceTypeId(deviceTypeId);
+ return HelperUtil.getDeviceManagementProviderService().getDeviceCountByDeviceIds(paginationRequest, deviceIds);
+ }
+
+ /**
+ * Populates device subscription data based on the provided devices and subscription DTOs.
+ *
+ * @param deviceSubscriptionDTOS List of DeviceSubscriptionDTO objects.
+ * @param devices List of Device objects.
+ * @param isUnsubscribed Boolean indicating whether to filter unsubscribed devices.
+ * @return List of DeviceSubscription objects.
+ */
+ private static List populateDeviceData(List deviceSubscriptionDTOS,
+ List devices, boolean isUnsubscribed) {
+ List deviceSubscriptions = new ArrayList<>();
+ for (Device device : devices) {
+ int idx = deviceSubscriptionDTOS.indexOf(new DeviceSubscriptionDTO(device.getId()));
+ if (idx >= 0) {
+ DeviceSubscriptionDTO deviceSubscriptionDTO = deviceSubscriptionDTOS.get(idx);
+ DeviceSubscription deviceSubscription = new DeviceSubscription();
+ deviceSubscription.setDeviceId(device.getId());
+ deviceSubscription.setDeviceIdentifier(device.getDeviceIdentifier());
+ deviceSubscription.setDeviceOwner(device.getEnrolmentInfo().getOwner());
+ deviceSubscription.setDeviceType(device.getType());
+ deviceSubscription.setDeviceName(device.getName());
+ deviceSubscription.setDeviceStatus(device.getEnrolmentInfo().getStatus().name());
+ deviceSubscription.setOwnershipType(device.getEnrolmentInfo().getOwnership().name());
+ deviceSubscription.setDateOfLastUpdate(new Timestamp(device.getEnrolmentInfo().getDateOfLastUpdate()));
+ SubscriptionData subscriptionData = getSubscriptionData(isUnsubscribed, deviceSubscriptionDTO);
+ deviceSubscription.setSubscriptionData(subscriptionData);
+ deviceSubscriptions.add(deviceSubscription);
+ }
+ }
+ return deviceSubscriptions;
+ }
+
+ /**
+ * Creates a SubscriptionData object based on the provided subscription DTO.
+ *
+ * @param isUnsubscribed Boolean indicating whether to filter unsubscribed devices.
+ * @param deviceSubscriptionDTO DeviceSubscriptionDTO object.
+ * @return SubscriptionData object.
+ */
+ private static SubscriptionData getSubscriptionData(boolean isUnsubscribed, DeviceSubscriptionDTO deviceSubscriptionDTO) {
+ SubscriptionData subscriptionData = new SubscriptionData();
+ subscriptionData.setTriggeredBy(isUnsubscribed ? deviceSubscriptionDTO.getUnsubscribedBy() :
+ deviceSubscriptionDTO.getSubscribedBy());
+ subscriptionData.setTriggeredAt(deviceSubscriptionDTO.getSubscribedTimestamp());
+ subscriptionData.setDeviceSubscriptionStatus(deviceSubscriptionDTO.getStatus());
+ subscriptionData.setSubscriptionType(deviceSubscriptionDTO.getActionTriggeredFrom());
+ subscriptionData.setSubscriptionId(deviceSubscriptionDTO.getId());
+ return subscriptionData;
+ }
+
+ /**
+ * Retrieves the device subscription status based on the provided subscription info.
+ *
+ * @param subscriptionInfo SubscriptionInfo object.
+ * @return Device subscription status.
+ */
+ public static String getDeviceSubscriptionStatus(SubscriptionInfo subscriptionInfo) {
+ return getDeviceSubscriptionStatus(subscriptionInfo.getDeviceSubscriptionFilterCriteria().
+ getFilteringDeviceSubscriptionStatus(), subscriptionInfo.getDeviceSubscriptionStatus());
+ }
+
+ /**
+ * Retrieves the device subscription status based on the provided filter and status.
+ *
+ * @param deviceSubscriptionStatusFilter Filtered device subscription status.
+ * @param deviceSubscriptionStatus Device subscription status.
+ * @return Device subscription status.
+ */
+ public static String getDeviceSubscriptionStatus(String deviceSubscriptionStatusFilter, String deviceSubscriptionStatus) {
+ return (deviceSubscriptionStatusFilter != null && !deviceSubscriptionStatusFilter.isEmpty()) ?
+ deviceSubscriptionStatusFilter : deviceSubscriptionStatus;
+ }
+
+ /**
+ * Retrieves subscription statistics based on the provided subscription statistics DTO and device count.
+ *
+ * @param subscriptionStatisticDTO SubscriptionStatisticDTO object.
+ * @param allDeviceCount Total count of all devices.
+ * @return SubscriptionStatistics object.
+ */
+ public static SubscriptionStatistics getSubscriptionStatistics(SubscriptionStatisticDTO subscriptionStatisticDTO, int allDeviceCount) {
+ SubscriptionStatistics subscriptionStatistics = new SubscriptionStatistics();
+ subscriptionStatistics.setCompletedPercentage(
+ getPercentage(subscriptionStatisticDTO.getCompletedDeviceCount(), allDeviceCount));
+ subscriptionStatistics.setPendingPercentage(
+ getPercentage(subscriptionStatisticDTO.getPendingDevicesCount(), allDeviceCount));
+ subscriptionStatistics.setFailedPercentage(
+ getPercentage(subscriptionStatisticDTO.getFailedDevicesCount(), allDeviceCount));
+ subscriptionStatistics.setNewDevicesPercentage(getPercentage((allDeviceCount -
+ subscriptionStatisticDTO.getCompletedDeviceCount() -
+ subscriptionStatisticDTO.getPendingDevicesCount() -
+ subscriptionStatisticDTO.getFailedDevicesCount()), allDeviceCount));
+ return subscriptionStatistics;
+ }
+
+ /**
+ * Calculates the percentages.
+ *
+ * @param numerator Numerator value.
+ * @param denominator Denominator value.
+ * @return Calculated percentage.
+ */
+ public static float getPercentage(int numerator, int denominator) {
+ if (denominator <= 0) {
+ return 0.0f;
+ }
+ return ((float) numerator / (float) denominator) * 100;
+ }
+
+ /**
+ * Retrieves database subscription statuses based on the provided device subscription status.
+ *
+ * @param deviceSubscriptionStatus Device subscription status.
+ * @return List of database subscription statuses.
+ */
+ public static List getDBSubscriptionStatus(String deviceSubscriptionStatus) {
+ return SubscriptionMetadata.deviceSubscriptionStatusToDBSubscriptionStatusMap.get(deviceSubscriptionStatus);
+ }
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/SubscriptionManagementServiceProvider.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/SubscriptionManagementServiceProvider.java
new file mode 100644
index 0000000000..1f13a8a5fa
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/SubscriptionManagementServiceProvider.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt;
+
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionMetadata;
+import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.impl.DeviceBasedSubscriptionManagementHelperServiceImpl;
+import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.impl.GroupBasedSubscriptionManagementHelperServiceImpl;
+import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.impl.RoleBasedSubscriptionManagementHelperServiceImpl;
+import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.impl.UserBasedSubscriptionManagementHelperServiceImpl;
+import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.service.SubscriptionManagementHelperService;
+
+import java.util.Objects;
+
+public class SubscriptionManagementServiceProvider {
+ private SubscriptionManagementServiceProvider() {
+ }
+
+ public static SubscriptionManagementServiceProvider getInstance() {
+ return SubscriptionManagementProviderServiceHolder.INSTANCE;
+ }
+
+ /**
+ * Retrieves the appropriate SubscriptionManagementHelperService based on the provided SubscriptionInfo.
+ *
+ * @param subscriptionInfo SubscriptionInfo object containing the subscription type.
+ * @return SubscriptionManagementHelperService implementation based on the subscription type.
+ */
+ public SubscriptionManagementHelperService getSubscriptionManagementHelperService(SubscriptionInfo subscriptionInfo) {
+ return getSubscriptionManagementHelperService(subscriptionInfo.getSubscriptionType());
+ }
+
+ /**
+ * Retrieves the appropriate SubscriptionManagementHelperService based on the subscription type.
+ *
+ * @param subscriptionType Type of the subscription.
+ * @return SubscriptionManagementHelperService implementation based on the subscription type.
+ */
+ private SubscriptionManagementHelperService getSubscriptionManagementHelperService(String subscriptionType) {
+ if (Objects.equals(subscriptionType, SubscriptionMetadata.SubscriptionTypes.ROLE))
+ return RoleBasedSubscriptionManagementHelperServiceImpl.getInstance();
+ if (Objects.equals(subscriptionType, SubscriptionMetadata.SubscriptionTypes.GROUP))
+ return GroupBasedSubscriptionManagementHelperServiceImpl.getInstance();
+ if (Objects.equals(subscriptionType, SubscriptionMetadata.SubscriptionTypes.USER))
+ return UserBasedSubscriptionManagementHelperServiceImpl.getInstance();
+ if (Objects.equals(subscriptionType, SubscriptionMetadata.SubscriptionTypes.DEVICE))
+ return DeviceBasedSubscriptionManagementHelperServiceImpl.getInstance();
+ throw new UnsupportedOperationException("Subscription type: " + subscriptionType + " not supports");
+ }
+
+ private static class SubscriptionManagementProviderServiceHolder {
+ private static final SubscriptionManagementServiceProvider INSTANCE = new SubscriptionManagementServiceProvider();
+ }
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/DeviceBasedSubscriptionManagementHelperServiceImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/DeviceBasedSubscriptionManagementHelperServiceImpl.java
new file mode 100644
index 0000000000..88e78e82cd
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/DeviceBasedSubscriptionManagementHelperServiceImpl.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.impl;
+
+import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscription;
+import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionFilterCriteria;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionMetadata;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionResponse;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionStatistics;
+import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
+import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
+import io.entgra.device.mgt.core.application.mgt.common.exception.DBConnectionException;
+import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
+import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
+import io.entgra.device.mgt.core.application.mgt.core.util.ConnectionManagerUtil;
+import io.entgra.device.mgt.core.application.mgt.core.util.HelperUtil;
+import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.SubscriptionManagementHelperUtil;
+import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.service.SubscriptionManagementHelperService;
+import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
+import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+public class DeviceBasedSubscriptionManagementHelperServiceImpl implements SubscriptionManagementHelperService {
+ private static final Log log = LogFactory.getLog(DeviceBasedSubscriptionManagementHelperServiceImpl.class);
+
+ private DeviceBasedSubscriptionManagementHelperServiceImpl() {
+ }
+
+ public static DeviceBasedSubscriptionManagementHelperServiceImpl getInstance() {
+ return DeviceBasedSubscriptionManagementHelperServiceImpl.DeviceBasedSubscriptionManagementHelperServiceImplHolder.INSTANCE;
+ }
+
+ @Override
+ public SubscriptionResponse getStatusBaseSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
+ throws ApplicationManagementException {
+ final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
+ List deviceSubscriptionDTOS;
+ int deviceCount = 0;
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+
+ try {
+ ConnectionManagerUtil.openDBConnection();
+ ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.
+ getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId);
+ if (applicationReleaseDTO == null) {
+ String msg = "Couldn't find an application release for application release UUID: " +
+ subscriptionInfo.getApplicationUUID();
+ log.error(msg);
+ throw new NotFoundException(msg);
+ }
+
+ ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(subscriptionInfo.getApplicationUUID(), tenantId);
+ if (applicationDTO == null) {
+ String msg = "Application not found for the release UUID: " + subscriptionInfo.getApplicationUUID();
+ log.error(msg);
+ throw new NotFoundException(msg);
+ }
+
+ String deviceSubscriptionStatus = SubscriptionManagementHelperUtil.getDeviceSubscriptionStatus(subscriptionInfo);
+ DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria = subscriptionInfo.getDeviceSubscriptionFilterCriteria();
+ DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
+ List dbSubscriptionStatus = SubscriptionManagementHelperUtil.getDBSubscriptionStatus(subscriptionInfo.getDeviceSubscriptionStatus());
+
+ if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) {
+ deviceSubscriptionDTOS = subscriptionDAO.getAllSubscriptionsDetails(applicationReleaseDTO.
+ getId(), isUnsubscribe, tenantId, null, null,
+ deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
+
+ List deviceIdsOfSubscription = deviceSubscriptionDTOS.stream().
+ map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
+
+ List newDeviceIds = deviceManagementProviderService.getDevicesNotInGivenIdList(deviceIdsOfSubscription);
+
+ deviceSubscriptionDTOS = newDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList());
+ } else {
+ deviceSubscriptionDTOS = subscriptionDAO.getAllSubscriptionsDetails(applicationReleaseDTO.
+ getId(), isUnsubscribe, tenantId, dbSubscriptionStatus, null,
+ deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
+ }
+ deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS,
+ subscriptionInfo.getDeviceSubscriptionFilterCriteria(), applicationDTO.getDeviceTypeId());
+
+ List deviceSubscriptions = SubscriptionManagementHelperUtil.getDeviceSubscriptionData(deviceSubscriptionDTOS,
+ subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, applicationDTO.getDeviceTypeId(), limit, offset);
+ return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), deviceCount, deviceSubscriptions);
+ } catch (DeviceManagementException e) {
+ String msg = "Error encountered while getting device details";
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } catch (ApplicationManagementDAOException | DBConnectionException e) {
+ String msg = "Error encountered while connecting to the database";
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } finally {
+ ConnectionManagerUtil.closeDBConnection();
+ }
+ }
+
+ @Override
+ public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
+ throws ApplicationManagementException {
+ return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), Collections.emptyList());
+ }
+
+ @Override
+ public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo)
+ throws ApplicationManagementException {
+ return null;
+ }
+
+ private static class DeviceBasedSubscriptionManagementHelperServiceImplHolder {
+ private static final DeviceBasedSubscriptionManagementHelperServiceImpl INSTANCE
+ = new DeviceBasedSubscriptionManagementHelperServiceImpl();
+ }
+
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/GroupBasedSubscriptionManagementHelperServiceImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/GroupBasedSubscriptionManagementHelperServiceImpl.java
new file mode 100644
index 0000000000..16834bf2a1
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/GroupBasedSubscriptionManagementHelperServiceImpl.java
@@ -0,0 +1,220 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.impl;
+
+import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscription;
+import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionFilterCriteria;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionEntity;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionMetadata;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionResponse;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionStatistics;
+import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionStatisticDTO;
+import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
+import io.entgra.device.mgt.core.application.mgt.common.exception.DBConnectionException;
+import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
+import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
+import io.entgra.device.mgt.core.application.mgt.core.util.ConnectionManagerUtil;
+import io.entgra.device.mgt.core.application.mgt.core.util.HelperUtil;
+import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.SubscriptionManagementHelperUtil;
+import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.service.SubscriptionManagementHelperService;
+import io.entgra.device.mgt.core.device.mgt.common.Device;
+import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
+import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException;
+import io.entgra.device.mgt.core.device.mgt.core.dto.GroupDetailsDTO;
+import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
+import io.entgra.device.mgt.core.device.mgt.core.service.GroupManagementProviderService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+public class GroupBasedSubscriptionManagementHelperServiceImpl implements SubscriptionManagementHelperService {
+ private static final Log log = LogFactory.getLog(GroupBasedSubscriptionManagementHelperServiceImpl.class);
+
+ private GroupBasedSubscriptionManagementHelperServiceImpl() {
+ }
+
+ public static GroupBasedSubscriptionManagementHelperServiceImpl getInstance() {
+ return GroupBasedSubscriptionManagementHelperServiceImplHolder.INSTANCE;
+ }
+
+ @Override
+ public SubscriptionResponse getStatusBaseSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
+ throws ApplicationManagementException {
+
+ final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
+ List deviceSubscriptionDTOS;
+ int deviceCount = 0;
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+
+ try {
+ ConnectionManagerUtil.openDBConnection();
+ ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.
+ getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId);
+
+ if (applicationReleaseDTO == null) {
+ String msg = "Couldn't find an application release for application release UUID: " +
+ subscriptionInfo.getApplicationUUID();
+ log.error(msg);
+ throw new NotFoundException(msg);
+ }
+
+ ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(subscriptionInfo.getApplicationUUID(), tenantId);
+ if (applicationDTO == null) {
+ String msg = "Application not found for the release UUID: " + subscriptionInfo.getApplicationUUID();
+ log.error(msg);
+ throw new NotFoundException(msg);
+ }
+
+ String deviceSubscriptionStatus = SubscriptionManagementHelperUtil.getDeviceSubscriptionStatus(subscriptionInfo);
+ DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria = subscriptionInfo.getDeviceSubscriptionFilterCriteria();
+ DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
+
+ GroupManagementProviderService groupManagementProviderService = HelperUtil.getGroupManagementProviderService();
+ GroupDetailsDTO groupDetailsDTO;
+ List dbSubscriptionStatus = SubscriptionManagementHelperUtil.getDBSubscriptionStatus(subscriptionInfo.getDeviceSubscriptionStatus());
+
+ if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) {
+ List allDeviceIdsOwnByGroup = groupManagementProviderService.getGroupDetailsWithDevices(subscriptionInfo.getIdentifier(),
+ applicationDTO.getDeviceTypeId(), deviceSubscriptionFilterCriteria.getOwner(), deviceSubscriptionFilterCriteria.getName(),
+ deviceSubscriptionFilterCriteria.getDeviceStatus(), -1, -1).getDeviceIds();
+
+ deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
+ isUnsubscribe, tenantId, allDeviceIdsOwnByGroup, null,
+ null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
+
+ List deviceIdsOfSubscription = deviceSubscriptionDTOS.stream().
+ map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
+
+ for (Integer deviceId : deviceIdsOfSubscription) {
+ allDeviceIdsOwnByGroup.remove(deviceId);
+ }
+
+ List newDeviceIds = deviceManagementProviderService.getDevicesInGivenIdList(allDeviceIdsOwnByGroup);
+ deviceSubscriptionDTOS = newDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList());
+ } else {
+ groupDetailsDTO = groupManagementProviderService.getGroupDetailsWithDevices(subscriptionInfo.getIdentifier(),
+ applicationDTO.getDeviceTypeId(), deviceSubscriptionFilterCriteria.getOwner(), deviceSubscriptionFilterCriteria.getName(),
+ deviceSubscriptionFilterCriteria.getDeviceStatus(), offset, limit);
+ List paginatedDeviceIdsOwnByGroup = groupDetailsDTO.getDeviceIds();
+
+ deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
+ isUnsubscribe, tenantId, paginatedDeviceIdsOwnByGroup, dbSubscriptionStatus,
+ null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
+
+ }
+ deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS,
+ subscriptionInfo.getDeviceSubscriptionFilterCriteria(), applicationDTO.getDeviceTypeId());
+
+ List deviceSubscriptions = SubscriptionManagementHelperUtil.getDeviceSubscriptionData(deviceSubscriptionDTOS,
+ subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, applicationDTO.getDeviceTypeId(), limit, offset);
+ return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), deviceCount, deviceSubscriptions);
+ } catch (GroupManagementException e) {
+ String msg = "Error encountered while retrieving group details for group: " + subscriptionInfo.getIdentifier();
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } catch (ApplicationManagementDAOException | DBConnectionException e) {
+ String msg = "Error encountered while connecting to the database";
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } catch (DeviceManagementException e) {
+ throw new RuntimeException(e);
+ } finally {
+ ConnectionManagerUtil.closeDBConnection();
+ }
+
+ }
+
+ @Override
+ public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
+ throws ApplicationManagementException {
+ final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
+ final int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ try {
+ ConnectionManagerUtil.openDBConnection();
+ ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.
+ getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId);
+ if (applicationReleaseDTO == null) {
+ String msg = "Couldn't find an application release for application release UUID: " +
+ subscriptionInfo.getApplicationUUID();
+ log.error(msg);
+ throw new NotFoundException(msg);
+ }
+ List subscriptionEntities = subscriptionDAO.
+ getGroupsSubscriptionDetailsByAppReleaseID(applicationReleaseDTO.getId(), isUnsubscribe, tenantId, offset, limit);
+ int subscriptionCount = isUnsubscribe ? subscriptionDAO.getGroupUnsubscriptionCount(applicationReleaseDTO.getId(), tenantId) :
+ subscriptionDAO.getGroupSubscriptionCount(applicationReleaseDTO.getId(), tenantId);
+ return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), subscriptionCount, subscriptionEntities);
+ } catch (DBConnectionException | ApplicationManagementDAOException e) {
+ String msg = "Error encountered while connecting to the database";
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } finally {
+ ConnectionManagerUtil.closeDBConnection();
+ }
+ }
+
+ @Override
+ public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo)
+ throws ApplicationManagementException {
+ final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ try {
+ ConnectionManagerUtil.openDBConnection();
+ ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.
+ getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId);
+ if (applicationReleaseDTO == null) {
+ String msg = "Couldn't find an application release for application release UUID: " +
+ subscriptionInfo.getApplicationUUID();
+ log.error(msg);
+ throw new NotFoundException(msg);
+ }
+ List devices = HelperUtil.getGroupManagementProviderService().
+ getAllDevicesOfGroup(subscriptionInfo.getIdentifier(), false);
+ List deviceIdsOwnByGroup = devices.stream().map(Device::getId).collect(Collectors.toList());
+ SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO.
+ getSubscriptionStatistic(deviceIdsOwnByGroup, isUnsubscribe, tenantId, applicationReleaseDTO.getId());
+ int allDeviceCount = HelperUtil.getGroupManagementProviderService().getDeviceCount(subscriptionInfo.getIdentifier());
+ return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount);
+ } catch (ApplicationManagementDAOException e) {
+ String msg = "Error encountered while getting subscription statistics for group: " + subscriptionInfo.getIdentifier();
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } catch (GroupManagementException e) {
+ String msg = "Error encountered while getting device subscription for group: " + subscriptionInfo.getIdentifier();
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } finally {
+ ConnectionManagerUtil.closeDBConnection();
+ }
+ }
+
+ private static class GroupBasedSubscriptionManagementHelperServiceImplHolder {
+ private static final GroupBasedSubscriptionManagementHelperServiceImpl INSTANCE
+ = new GroupBasedSubscriptionManagementHelperServiceImpl();
+ }
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/RoleBasedSubscriptionManagementHelperServiceImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/RoleBasedSubscriptionManagementHelperServiceImpl.java
new file mode 100644
index 0000000000..b667198fd5
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/RoleBasedSubscriptionManagementHelperServiceImpl.java
@@ -0,0 +1,227 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.impl;
+
+import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscription;
+import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionFilterCriteria;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionEntity;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionMetadata;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionResponse;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionStatistics;
+import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionStatisticDTO;
+import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
+import io.entgra.device.mgt.core.application.mgt.common.exception.DBConnectionException;
+import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
+import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
+import io.entgra.device.mgt.core.application.mgt.core.internal.DataHolder;
+import io.entgra.device.mgt.core.application.mgt.core.util.ConnectionManagerUtil;
+import io.entgra.device.mgt.core.application.mgt.core.util.HelperUtil;
+import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.SubscriptionManagementHelperUtil;
+import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.service.SubscriptionManagementHelperService;
+import io.entgra.device.mgt.core.device.mgt.common.Device;
+import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
+import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
+import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
+import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.user.api.UserStoreException;
+import org.wso2.carbon.user.api.UserStoreManager;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+public class RoleBasedSubscriptionManagementHelperServiceImpl implements SubscriptionManagementHelperService {
+ private static final Log log = LogFactory.getLog(RoleBasedSubscriptionManagementHelperServiceImpl.class);
+
+ private RoleBasedSubscriptionManagementHelperServiceImpl() {
+ }
+
+ public static RoleBasedSubscriptionManagementHelperServiceImpl getInstance() {
+ return RoleBasedSubscriptionManagementHelperServiceImplHolder.INSTANCE;
+ }
+
+ @Override
+ public SubscriptionResponse getStatusBaseSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
+ throws ApplicationManagementException {
+ final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
+ List deviceSubscriptionDTOS;
+ int deviceCount = 0;
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+
+ try {
+ ConnectionManagerUtil.openDBConnection();
+ List deviceIdsOwnByRole = getDeviceIdsOwnByRole(subscriptionInfo.getIdentifier(), tenantId);
+
+ ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.
+ getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId);
+ if (applicationReleaseDTO == null) {
+ String msg = "Couldn't find an application release for application release UUID: " +
+ subscriptionInfo.getApplicationUUID();
+ log.error(msg);
+ throw new NotFoundException(msg);
+ }
+
+ ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(subscriptionInfo.getApplicationUUID(), tenantId);
+ if (applicationDTO == null) {
+ String msg = "Application not found for the release UUID: " + subscriptionInfo.getApplicationUUID();
+ log.error(msg);
+ throw new NotFoundException(msg);
+ }
+
+ String deviceSubscriptionStatus = SubscriptionManagementHelperUtil.getDeviceSubscriptionStatus(subscriptionInfo);
+ DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria = subscriptionInfo.getDeviceSubscriptionFilterCriteria();
+ DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
+ List dbSubscriptionStatus = SubscriptionManagementHelperUtil.getDBSubscriptionStatus(subscriptionInfo.getDeviceSubscriptionStatus());
+
+ if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) {
+ deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
+ isUnsubscribe, tenantId, deviceIdsOwnByRole, null,
+ null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
+
+ List deviceIdsOfSubscription = deviceSubscriptionDTOS.stream().
+ map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
+
+ for (Integer deviceId : deviceIdsOfSubscription) {
+ deviceIdsOwnByRole.remove(deviceId);
+ }
+
+ List newDeviceIds = deviceManagementProviderService.getDevicesInGivenIdList(deviceIdsOwnByRole);
+ deviceSubscriptionDTOS = newDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList());
+ } else {
+ deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
+ isUnsubscribe, tenantId, deviceIdsOwnByRole, dbSubscriptionStatus,
+ subscriptionInfo.getSubscriptionType(), deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
+ }
+ deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS,
+ subscriptionInfo.getDeviceSubscriptionFilterCriteria(), applicationDTO.getDeviceTypeId());
+
+ List deviceSubscriptions = SubscriptionManagementHelperUtil.
+ getDeviceSubscriptionData(deviceSubscriptionDTOS,
+ subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, applicationDTO.getDeviceTypeId(), limit, offset);
+ return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), deviceCount, deviceSubscriptions);
+
+ } catch (UserStoreException e) {
+ String msg = "Error encountered while getting the user management store for tenant id " + tenantId;
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } catch (DeviceManagementException e) {
+ String msg = "Error encountered while getting device details";
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } catch (ApplicationManagementDAOException | DBConnectionException e) {
+ String msg = "Error encountered while connecting to the database";
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } finally {
+ ConnectionManagerUtil.closeDBConnection();
+ }
+ }
+
+ @Override
+ public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
+ throws ApplicationManagementException {
+ final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
+ final int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ try {
+ ConnectionManagerUtil.openDBConnection();
+ ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.
+ getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId);
+ if (applicationReleaseDTO == null) {
+ String msg = "Couldn't find an application release for application release UUID: " +
+ subscriptionInfo.getApplicationUUID();
+ log.error(msg);
+ throw new NotFoundException(msg);
+ }
+ List subscriptionEntities = subscriptionDAO.
+ getRoleSubscriptionsByAppReleaseID(applicationReleaseDTO.getId(), isUnsubscribe, tenantId, offset, limit);
+ int subscriptionCount = isUnsubscribe ? subscriptionDAO.getRoleUnsubscriptionCount(applicationReleaseDTO.getId(), tenantId) :
+ subscriptionDAO.getRoleSubscriptionCount(applicationReleaseDTO.getId(), tenantId);
+ return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), subscriptionCount, subscriptionEntities);
+ } catch (DBConnectionException | ApplicationManagementDAOException e) {
+ String msg = "Error encountered while connecting to the database";
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } finally {
+ ConnectionManagerUtil.closeDBConnection();
+ }
+ }
+
+ @Override
+ public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo) throws ApplicationManagementException {
+ final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ try {
+ ConnectionManagerUtil.openDBConnection();
+ ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.
+ getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId);
+ if (applicationReleaseDTO == null) {
+ String msg = "Couldn't find an application release for application release UUID: " +
+ subscriptionInfo.getApplicationUUID();
+ log.error(msg);
+ throw new NotFoundException(msg);
+ }
+ List deviceIdsOwnByRole = getDeviceIdsOwnByRole(subscriptionInfo.getIdentifier(), tenantId);
+ SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO.
+ getSubscriptionStatistic(deviceIdsOwnByRole, isUnsubscribe, tenantId, applicationReleaseDTO.getId());
+ int allDeviceCount = deviceIdsOwnByRole.size();
+ return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount);
+ } catch (DeviceManagementException | ApplicationManagementDAOException | UserStoreException e) {
+ String msg = "Error encountered while getting subscription statistics for role: " + subscriptionInfo.getIdentifier();
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } finally {
+ ConnectionManagerUtil.closeDBConnection();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private List getDeviceIdsOwnByRole(String roleName, int tenantId) throws UserStoreException, DeviceManagementException {
+ UserStoreManager userStoreManager = DataHolder.getInstance().getRealmService().
+ getTenantUserRealm(tenantId).getUserStoreManager();
+ String[] usersWithRole =
+ userStoreManager.getUserListOfRole(roleName);
+ List deviceListOwnByRole = new ArrayList<>();
+ for (String user : usersWithRole) {
+ PaginationRequest paginationRequest = new PaginationRequest(-1, -1);
+ paginationRequest.setOwner(user);
+ paginationRequest.setStatusList(Arrays.asList("ACTIVE", "INACTIVE", "UNREACHABLE"));
+ PaginationResult ownDeviceIds = HelperUtil.getDeviceManagementProviderService().
+ getAllDevicesIdList(paginationRequest);
+ if (ownDeviceIds.getData() != null) {
+ deviceListOwnByRole.addAll((List) ownDeviceIds.getData());
+ }
+ }
+ return deviceListOwnByRole.stream().map(Device::getId).collect(Collectors.toList());
+ }
+
+ private static class RoleBasedSubscriptionManagementHelperServiceImplHolder {
+ private static final RoleBasedSubscriptionManagementHelperServiceImpl INSTANCE
+ = new RoleBasedSubscriptionManagementHelperServiceImpl();
+ }
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/UserBasedSubscriptionManagementHelperServiceImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/UserBasedSubscriptionManagementHelperServiceImpl.java
new file mode 100644
index 0000000000..b8978b1c7a
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/impl/UserBasedSubscriptionManagementHelperServiceImpl.java
@@ -0,0 +1,212 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.impl;
+
+import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscription;
+import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionFilterCriteria;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionEntity;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionMetadata;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionResponse;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionStatistics;
+import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
+import io.entgra.device.mgt.core.application.mgt.common.dto.SubscriptionStatisticDTO;
+import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
+import io.entgra.device.mgt.core.application.mgt.common.exception.DBConnectionException;
+import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
+import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
+import io.entgra.device.mgt.core.application.mgt.core.util.ConnectionManagerUtil;
+import io.entgra.device.mgt.core.application.mgt.core.util.HelperUtil;
+import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.SubscriptionManagementHelperUtil;
+import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.service.SubscriptionManagementHelperService;
+import io.entgra.device.mgt.core.device.mgt.common.Device;
+import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
+import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
+import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
+import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+public class UserBasedSubscriptionManagementHelperServiceImpl implements SubscriptionManagementHelperService {
+ private static final Log log = LogFactory.getLog(UserBasedSubscriptionManagementHelperServiceImpl.class);
+
+ private UserBasedSubscriptionManagementHelperServiceImpl() {
+ }
+
+ public static UserBasedSubscriptionManagementHelperServiceImpl getInstance() {
+ return UserBasedSubscriptionManagementHelperServiceImpl.UserBasedSubscriptionManagementHelperServiceImplHolder.INSTANCE;
+ }
+
+ @Override
+ public SubscriptionResponse getStatusBaseSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
+ throws ApplicationManagementException {
+ final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
+ List deviceSubscriptionDTOS;
+ int deviceCount = 0;
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+
+ try {
+ ConnectionManagerUtil.openDBConnection();
+ List deviceIdsOwnByUser = getDeviceIdsOwnByUser(subscriptionInfo.getIdentifier());
+
+ ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.
+ getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId);
+ if (applicationReleaseDTO == null) {
+ String msg = "Couldn't find an application release for application release UUID: " +
+ subscriptionInfo.getApplicationUUID();
+ log.error(msg);
+ throw new NotFoundException(msg);
+ }
+
+ ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(subscriptionInfo.getApplicationUUID(), tenantId);
+ if (applicationDTO == null) {
+ String msg = "Application not found for the release UUID: " + subscriptionInfo.getApplicationUUID();
+ log.error(msg);
+ throw new NotFoundException(msg);
+ }
+
+ String deviceSubscriptionStatus = SubscriptionManagementHelperUtil.getDeviceSubscriptionStatus(subscriptionInfo);
+ DeviceSubscriptionFilterCriteria deviceSubscriptionFilterCriteria = subscriptionInfo.getDeviceSubscriptionFilterCriteria();
+ DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
+ List dbSubscriptionStatus = SubscriptionManagementHelperUtil.getDBSubscriptionStatus(subscriptionInfo.getDeviceSubscriptionStatus());
+
+ if (Objects.equals(SubscriptionMetadata.DeviceSubscriptionStatus.NEW, deviceSubscriptionStatus)) {
+ deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
+ isUnsubscribe, tenantId, deviceIdsOwnByUser, null,
+ null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
+
+ List deviceIdsOfSubscription = deviceSubscriptionDTOS.stream().
+ map(DeviceSubscriptionDTO::getDeviceId).collect(Collectors.toList());
+
+ for (Integer deviceId : deviceIdsOfSubscription) {
+ deviceIdsOwnByUser.remove(deviceId);
+ }
+ List newDeviceIds = deviceManagementProviderService.getDevicesInGivenIdList(deviceIdsOwnByUser);
+ deviceSubscriptionDTOS = newDeviceIds.stream().map(DeviceSubscriptionDTO::new).collect(Collectors.toList());
+
+ } else {
+ deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
+ isUnsubscribe, tenantId, deviceIdsOwnByUser, dbSubscriptionStatus,
+ null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
+ }
+ deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS,
+ subscriptionInfo.getDeviceSubscriptionFilterCriteria(), applicationDTO.getDeviceTypeId());
+
+ List deviceSubscriptions = SubscriptionManagementHelperUtil.getDeviceSubscriptionData(deviceSubscriptionDTOS,
+ subscriptionInfo.getDeviceSubscriptionFilterCriteria(), isUnsubscribe, applicationDTO.getDeviceTypeId(), limit, offset);
+ return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), deviceCount, deviceSubscriptions);
+ } catch (DeviceManagementException e) {
+ String msg = "Error encountered while getting device details";
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } catch (ApplicationManagementDAOException | DBConnectionException e) {
+ String msg = "Error encountered while connecting to the database";
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } finally {
+ ConnectionManagerUtil.closeDBConnection();
+ }
+ }
+
+ @Override
+ public SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
+ throws ApplicationManagementException {
+ final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
+ final int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ try {
+ ConnectionManagerUtil.openDBConnection();
+ ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.
+ getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId);
+ if (applicationReleaseDTO == null) {
+ String msg = "Couldn't find an application release for application release UUID: " +
+ subscriptionInfo.getApplicationUUID();
+ log.error(msg);
+ throw new NotFoundException(msg);
+ }
+ List subscriptionEntities = subscriptionDAO.
+ getUserSubscriptionsByAppReleaseID(applicationReleaseDTO.getId(), isUnsubscribe, tenantId, offset, limit);
+ int subscriptionCount = isUnsubscribe ? subscriptionDAO.getUserUnsubscriptionCount(applicationReleaseDTO.getId(), tenantId) :
+ subscriptionDAO.getUserSubscriptionCount(applicationReleaseDTO.getId(), tenantId);
+ return new SubscriptionResponse(subscriptionInfo.getApplicationUUID(), subscriptionCount, subscriptionEntities);
+ } catch (DBConnectionException | ApplicationManagementDAOException e) {
+ String msg = "Error encountered while connecting to the database";
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } finally {
+ ConnectionManagerUtil.closeDBConnection();
+ }
+ }
+
+ @Override
+ public SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo) throws ApplicationManagementException {
+ final boolean isUnsubscribe = Objects.equals(SubscriptionMetadata.SUBSCRIPTION_STATUS_UNSUBSCRIBED, subscriptionInfo.getSubscriptionStatus());
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ try {
+ ConnectionManagerUtil.openDBConnection();
+ ApplicationReleaseDTO applicationReleaseDTO = applicationReleaseDAO.
+ getReleaseByUUID(subscriptionInfo.getApplicationUUID(), tenantId);
+ if (applicationReleaseDTO == null) {
+ String msg = "Couldn't find an application release for application release UUID: " +
+ subscriptionInfo.getApplicationUUID();
+ log.error(msg);
+ throw new NotFoundException(msg);
+ }
+ List deviceIdsOwnByUser = getDeviceIdsOwnByUser(subscriptionInfo.getIdentifier());
+ SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO.
+ getSubscriptionStatistic(deviceIdsOwnByUser, isUnsubscribe, tenantId, applicationReleaseDTO.getId());
+ int allDeviceCount = deviceIdsOwnByUser.size();
+ return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount);
+ } catch (DeviceManagementException | ApplicationManagementDAOException e) {
+ String msg = "Error encountered while getting subscription statistics for user: " + subscriptionInfo.getIdentifier();
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } finally {
+ ConnectionManagerUtil.closeDBConnection();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private List getDeviceIdsOwnByUser(String username) throws DeviceManagementException {
+ List deviceListOwnByUser = new ArrayList<>();
+ PaginationRequest paginationRequest = new PaginationRequest(-1, -1);
+ paginationRequest.setOwner(username);
+ paginationRequest.setStatusList(Arrays.asList("ACTIVE", "INACTIVE", "UNREACHABLE"));
+ PaginationResult ownDeviceIds = HelperUtil.getDeviceManagementProviderService().
+ getAllDevicesIdList(paginationRequest);
+ if (ownDeviceIds.getData() != null) {
+ deviceListOwnByUser.addAll((List) ownDeviceIds.getData());
+ }
+ return deviceListOwnByUser.stream().map(Device::getId).collect(Collectors.toList());
+ }
+
+ private static class UserBasedSubscriptionManagementHelperServiceImplHolder {
+ private static final UserBasedSubscriptionManagementHelperServiceImpl INSTANCE
+ = new UserBasedSubscriptionManagementHelperServiceImpl();
+ }
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/service/SubscriptionManagementHelperService.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/service/SubscriptionManagementHelperService.java
new file mode 100644
index 0000000000..f869e282dd
--- /dev/null
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/subscription/mgt/service/SubscriptionManagementHelperService.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.service;
+
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionInfo;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionResponse;
+import io.entgra.device.mgt.core.application.mgt.common.SubscriptionStatistics;
+import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
+import io.entgra.device.mgt.core.application.mgt.core.dao.ApplicationDAO;
+import io.entgra.device.mgt.core.application.mgt.core.dao.ApplicationReleaseDAO;
+import io.entgra.device.mgt.core.application.mgt.core.dao.SubscriptionDAO;
+import io.entgra.device.mgt.core.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
+
+public interface SubscriptionManagementHelperService {
+ SubscriptionDAO subscriptionDAO = ApplicationManagementDAOFactory.getSubscriptionDAO();
+ ApplicationDAO applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
+ ApplicationReleaseDAO applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO();
+
+ SubscriptionResponse getStatusBaseSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
+ throws ApplicationManagementException;
+
+ SubscriptionResponse getSubscriptions(SubscriptionInfo subscriptionInfo, int limit, int offset)
+ throws ApplicationManagementException;
+
+ SubscriptionStatistics getSubscriptionStatistics(SubscriptionInfo subscriptionInfo)
+ throws ApplicationManagementException;
+}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/test/java/io/entgra/device/mgt/core/application/mgt/core/BaseTestCase.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/test/java/io/entgra/device/mgt/core/application/mgt/core/BaseTestCase.java
index 9243cb8930..7251a0d19e 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/test/java/io/entgra/device/mgt/core/application/mgt/core/BaseTestCase.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/test/java/io/entgra/device/mgt/core/application/mgt/core/BaseTestCase.java
@@ -37,6 +37,7 @@ import io.entgra.device.mgt.core.device.mgt.core.config.DeviceConfigurationManag
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOFactory;
import io.entgra.device.mgt.core.device.mgt.core.internal.DeviceManagementDataHolder;
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.MetadataManagementDAOFactory;
+import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import org.wso2.carbon.registry.core.config.RegistryContext;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.registry.core.internal.RegistryDataHolder;
@@ -96,6 +97,7 @@ public abstract class BaseTestCase {
ConnectionManagerUtil.init(dataSource);
DeviceManagementDAOFactory.init(dataSource);
MetadataManagementDAOFactory.init(dataSource);
+ OperationManagementDAOFactory.init(dataSource);
// PolicyManagementDAOFactory.init(dataSource);
// OperationManagementDAOFactory.init(dataSource);
// GroupManagementDAOFactory.init(dataSource);
diff --git a/components/application-mgt/pom.xml b/components/application-mgt/pom.xml
index 360dad0a6c..b130f15b05 100644
--- a/components/application-mgt/pom.xml
+++ b/components/application-mgt/pom.xml
@@ -22,7 +22,7 @@
io.entgra.device.mgt.core
io.entgra.device.mgt.core.parent
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../../pom.xml
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.admin.api/pom.xml b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.admin.api/pom.xml
index 254c6ad535..7f89c759df 100644
--- a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.admin.api/pom.xml
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.admin.api/pom.xml
@@ -22,7 +22,7 @@
io.entgra.device.mgt.core
cea-mgt
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/pom.xml b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/pom.xml
index 2e6e9efc5b..dc4dd90442 100644
--- a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/pom.xml
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.common/pom.xml
@@ -23,7 +23,7 @@
io.entgra.device.mgt.core
cea-mgt
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/pom.xml b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/pom.xml
index ec906b7507..84853ec469 100644
--- a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/pom.xml
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.core/pom.xml
@@ -22,7 +22,7 @@
io.entgra.device.mgt.core
cea-mgt
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/pom.xml b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/pom.xml
index 09822882ff..4521458fed 100644
--- a/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/pom.xml
+++ b/components/cea-mgt/io.entgra.device.mgt.core.cea.mgt.enforce/pom.xml
@@ -22,7 +22,7 @@
io.entgra.device.mgt.core
cea-mgt
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/cea-mgt/pom.xml b/components/cea-mgt/pom.xml
index 665b30df0c..78b391bd6b 100644
--- a/components/cea-mgt/pom.xml
+++ b/components/cea-mgt/pom.xml
@@ -22,7 +22,7 @@
io.entgra.device.mgt.core
io.entgra.device.mgt.core.parent
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../../pom.xml
diff --git a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.api/pom.xml b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.api/pom.xml
index 29bef57226..f4a992e2af 100644
--- a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.api/pom.xml
+++ b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.api/pom.xml
@@ -22,7 +22,7 @@
certificate-mgt
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.cert.admin.api/pom.xml b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.cert.admin.api/pom.xml
index 03b8374637..d2cf1432e2 100644
--- a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.cert.admin.api/pom.xml
+++ b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.cert.admin.api/pom.xml
@@ -22,7 +22,7 @@
certificate-mgt
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/pom.xml b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/pom.xml
index 53c8057109..5259d27170 100644
--- a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/pom.xml
+++ b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/pom.xml
@@ -21,7 +21,7 @@
io.entgra.device.mgt.core
certificate-mgt
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/certificate-mgt/pom.xml b/components/certificate-mgt/pom.xml
index 62ba9f87aa..6716687cc1 100644
--- a/components/certificate-mgt/pom.xml
+++ b/components/certificate-mgt/pom.xml
@@ -22,7 +22,7 @@
io.entgra.device.mgt.core
io.entgra.device.mgt.core.parent
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../../pom.xml
diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.defaultrole.manager/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.defaultrole.manager/pom.xml
index 07e7b949c5..0c52cb5756 100644
--- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.defaultrole.manager/pom.xml
+++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.defaultrole.manager/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/pom.xml
index 55aea2d343..be028cf924 100644
--- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/pom.xml
+++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/pom.xml
index 92cbacef55..b5101280a2 100644
--- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/pom.xml
+++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql
index 13ac69dfc6..29d1a225b2 100644
--- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql
+++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql
@@ -329,7 +329,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED
DEVICE_ID INT NOT NULL,
ENROLMENT_ID INT(11) NOT NULL,
POLICY_ID INT NOT NULL,
- POLICY_CONTENT BLOB NULL,
+ POLICY_CONTENT TEXT NULL,
TENANT_ID INT NOT NULL,
APPLIED TINYINT(1) NULL,
CREATED_TIME TIMESTAMP NULL,
diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/resources/sql/h2.sql b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/resources/sql/h2.sql
index a842fdf2ab..f998695f58 100644
--- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/resources/sql/h2.sql
+++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.organization/src/test/resources/sql/h2.sql
@@ -336,7 +336,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED (
DEVICE_ID INT NOT NULL ,
ENROLMENT_ID INT(11) NOT NULL,
POLICY_ID INT NOT NULL ,
- POLICY_CONTENT BLOB NULL ,
+ POLICY_CONTENT TEXT NULL ,
TENANT_ID INT NOT NULL,
APPLIED TINYINT(1) NULL ,
CREATED_TIME TIMESTAMP NULL ,
diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.type.deployer/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.type.deployer/pom.xml
index cce520cc68..888c00a4d4 100644
--- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.type.deployer/pom.xml
+++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.type.deployer/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.logger/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.logger/pom.xml
index 34427cb7de..700cca153c 100644
--- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.logger/pom.xml
+++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.logger/pom.xml
@@ -21,7 +21,7 @@
device-mgt-extensions
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.pull.notification/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.pull.notification/pom.xml
index 90e4d05ed7..338198eab8 100644
--- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.pull.notification/pom.xml
+++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.pull.notification/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm/pom.xml
index ffb529ef29..a36ec650b6 100644
--- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm/pom.xml
+++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
@@ -111,6 +111,50 @@
org.wso2.carbon.analytics-common
org.wso2.carbon.event.output.adapter.core
+
+ org.wso2.orbit.com.google.http-client
+ google-http-client
+
+
+ org.wso2.orbit.com.google.auth-library-oauth2-http
+ google-auth-library-oauth2-http
+
+
+ org.wso2.orbit.io.opencensus
+ opencensus
+
+
+ io.opencensus
+ opencensus-api
+
+
+ io.opencensus
+ opencensus-contrib-http-util
+
+
+ org.wso2.orbit.io.grpc
+ grpc-context
+
+
+ com.google.http-client
+ google-http-client-gson
+
+
+ com.google.guava
+ failureaccess
+
+
+ com.google.guava
+ guava
+
+
+ org.wso2.carbon
+ org.wso2.carbon.utils
+
+
+ com.squareup.okhttp3
+ okhttp
+
@@ -137,12 +181,27 @@
com.google.gson,
org.osgi.framework.*;version="${imp.package.version.osgi.framework}",
org.osgi.service.*;version="${imp.package.version.osgi.service}",
+ org.wso2.carbon.utils.*,
io.entgra.device.mgt.core.device.mgt.common.operation.mgt,
io.entgra.device.mgt.core.device.mgt.common.push.notification,
org.apache.commons.logging,
io.entgra.device.mgt.core.device.mgt.common.*,
- io.entgra.device.mgt.core.device.mgt.core.service
+ io.entgra.device.mgt.core.device.mgt.core.service,
+ io.entgra.device.mgt.core.device.mgt.core.config.*,
+ io.entgra.device.mgt.core.device.mgt.core.config.push.notification.*,
+ io.entgra.device.mgt.core.device.mgt.extensions.logger.spi,
+ io.entgra.device.mgt.core.notification.logger.*,
+ com.google.auth.oauth2.*
+
+ google-auth-library-oauth2-http;scope=compile|runtime,
+ google-http-client;scope=compile|runtime,
+ grpc-context;scope=compile|runtime,
+ guava;scope=compile|runtime,
+ opencensus;scope=compile|runtime,
+ failureaccess;scope=compile|runtime
+
+ true
diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/push/notification/provider/fcm/FCMBasedPushNotificationProvider.java b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/push/notification/provider/fcm/FCMBasedPushNotificationProvider.java
index 1dbbacd720..2f849a4366 100644
--- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/push/notification/provider/fcm/FCMBasedPushNotificationProvider.java
+++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/push/notification/provider/fcm/FCMBasedPushNotificationProvider.java
@@ -32,7 +32,9 @@ public class FCMBasedPushNotificationProvider implements PushNotificationProvide
@Override
public NotificationStrategy getNotificationStrategy(PushNotificationConfig config) {
- return new FCMNotificationStrategy(config);
+ FCMNotificationStrategy fcmNotificationStrategy = new FCMNotificationStrategy(config);
+ fcmNotificationStrategy.init();
+ return fcmNotificationStrategy;
}
}
diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/push/notification/provider/fcm/FCMNotificationStrategy.java b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/push/notification/provider/fcm/FCMNotificationStrategy.java
index c6100aa418..66ee2ebb00 100644
--- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/push/notification/provider/fcm/FCMNotificationStrategy.java
+++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/push/notification/provider/fcm/FCMNotificationStrategy.java
@@ -17,9 +17,11 @@
*/
package io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm;
-import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
-import com.google.gson.JsonPrimitive;
+import io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm.util.FCMUtil;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import okhttp3.Response;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import io.entgra.device.mgt.core.device.mgt.common.Device;
@@ -39,14 +41,13 @@ import java.util.List;
public class FCMNotificationStrategy implements NotificationStrategy {
private static final Log log = LogFactory.getLog(FCMNotificationStrategy.class);
-
private static final String NOTIFIER_TYPE_FCM = "FCM";
private static final String FCM_TOKEN = "FCM_TOKEN";
- private static final String FCM_ENDPOINT = "https://fcm.googleapis.com/fcm/send";
private static final String FCM_API_KEY = "fcmAPIKey";
- private static final int TIME_TO_LIVE = 2419199; // 1 second less that 28 days
+ private static final int TIME_TO_LIVE = 2419199; // 1 second less than 28 days
private static final int HTTP_STATUS_CODE_OK = 200;
private final PushNotificationConfig config;
+ private static final String FCM_ENDPOINT_KEY = "FCM_SERVER_ENDPOINT";
public FCMNotificationStrategy(PushNotificationConfig config) {
this.config = config;
@@ -64,12 +65,14 @@ public class FCMNotificationStrategy implements NotificationStrategy {
Device device = FCMDataHolder.getInstance().getDeviceManagementProviderService()
.getDeviceWithTypeProperties(ctx.getDeviceId());
if(device.getProperties() != null && getFCMToken(device.getProperties()) != null) {
- this.sendWakeUpCall(ctx.getOperation().getCode(), device);
+ FCMUtil.getInstance().getDefaultApplication().refresh();
+ sendWakeUpCall(FCMUtil.getInstance().getDefaultApplication().getAccessToken().getTokenValue(),
+ getFCMToken(device.getProperties()));
}
} else {
if (log.isDebugEnabled()) {
log.debug("Not using FCM notifier as notifier type is set to " + config.getType() +
- " in Platform Configurations.");
+ " in Platform Configurations.");
}
}
} catch (DeviceManagementException e) {
@@ -79,6 +82,58 @@ public class FCMNotificationStrategy implements NotificationStrategy {
}
}
+
+ /**
+ * Send FCM message to the FCM server to initiate the push notification
+ * @param accessToken Access token to authenticate with the FCM server
+ * @param registrationId Registration ID of the device
+ * @throws IOException If an error occurs while sending the request
+ * @throws PushNotificationExecutionFailedException If an error occurs while sending the push notification
+ */
+ private void sendWakeUpCall(String accessToken, String registrationId) throws IOException,
+ PushNotificationExecutionFailedException {
+ String fcmServerEndpoint = FCMUtil.getInstance().getContextMetadataProperties()
+ .getProperty(FCM_ENDPOINT_KEY);
+ if(fcmServerEndpoint == null) {
+ String msg = "Encountered configuration issue. " + FCM_ENDPOINT_KEY + " is not defined";
+ log.error(msg);
+ throw new PushNotificationExecutionFailedException(msg);
+ }
+
+ RequestBody fcmRequest = getFCMRequest(registrationId);
+ Request request = new Request.Builder()
+ .url(fcmServerEndpoint)
+ .post(fcmRequest)
+ .addHeader("Authorization", "Bearer " + accessToken)
+ .build();
+ try (Response response = FCMUtil.getInstance().getHttpClient().newCall(request).execute()) {
+ if (log.isDebugEnabled()) {
+ log.debug("FCM message sent to the FCM server. Response code: " + response.code()
+ + " Response message : " + response.message());
+ }
+ if(!response.isSuccessful()) {
+ String msg = "Response Status: " + response.code() + ", Response Message: " + response.message();
+ log.error(msg);
+ throw new IOException(msg);
+ }
+ }
+ }
+
+ /**
+ * Get the FCM request as a JSON string
+ * @param registrationId Registration ID of the device
+ * @return FCM request as a JSON string
+ */
+ private static RequestBody getFCMRequest(String registrationId) {
+ JsonObject messageObject = new JsonObject();
+ messageObject.addProperty("token", registrationId);
+
+ JsonObject fcmRequest = new JsonObject();
+ fcmRequest.add("message", messageObject);
+
+ return RequestBody.create(fcmRequest.toString(), okhttp3.MediaType.parse("application/json"));
+ }
+
@Override
public NotificationContext buildContext() {
return null;
@@ -89,61 +144,6 @@ public class FCMNotificationStrategy implements NotificationStrategy {
}
- private void sendWakeUpCall(String message, Device device) throws IOException,
- PushNotificationExecutionFailedException {
- if (device.getProperties() != null) {
- OutputStream os = null;
- byte[] bytes = getFCMRequest(message, getFCMToken(device.getProperties())).getBytes();
-
- HttpURLConnection conn = null;
- try {
- conn = (HttpURLConnection) new URL(FCM_ENDPOINT).openConnection();
- conn.setRequestProperty("Content-Type", "application/json");
- conn.setRequestProperty("Authorization", "key=" + config.getProperty(FCM_API_KEY));
- conn.setRequestMethod("POST");
- conn.setDoOutput(true);
- os = conn.getOutputStream();
- os.write(bytes);
- } finally {
- if (os != null) {
- os.close();
- }
- if (conn != null) {
- conn.disconnect();
- }
- }
- int status = conn.getResponseCode();
- if (log.isDebugEnabled()) {
- log.debug("Result code: " + status + ", Message: " + conn.getResponseMessage());
- }
- if (status != HTTP_STATUS_CODE_OK) {
- throw new PushNotificationExecutionFailedException("Push notification sending failed with the HTTP " +
- "error code '" + status + "'");
- }
- }
- }
-
- private static String getFCMRequest(String message, String registrationId) {
- JsonObject fcmRequest = new JsonObject();
- fcmRequest.addProperty("delay_while_idle", false);
- fcmRequest.addProperty("time_to_live", TIME_TO_LIVE);
- fcmRequest.addProperty("priority", "high");
-
- //Add message to FCM request
- JsonObject data = new JsonObject();
- if (message != null && !message.isEmpty()) {
- data.addProperty("data", message);
- fcmRequest.add("data", data);
- }
-
- //Set device reg-id
- JsonArray regIds = new JsonArray();
- regIds.add(new JsonPrimitive(registrationId));
-
- fcmRequest.add("registration_ids", regIds);
- return fcmRequest.toString();
- }
-
private static String getFCMToken(List properties) {
String fcmToken = null;
for (Device.Property property : properties) {
@@ -159,5 +159,4 @@ public class FCMNotificationStrategy implements NotificationStrategy {
public PushNotificationConfig getConfig() {
return config;
}
-
}
diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/push/notification/provider/fcm/util/FCMUtil.java b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/push/notification/provider/fcm/util/FCMUtil.java
new file mode 100644
index 0000000000..e3d15d8974
--- /dev/null
+++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm/src/main/java/io/entgra/device/mgt/core/device/mgt/extensions/push/notification/provider/fcm/util/FCMUtil.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm.util;
+
+import com.google.auth.oauth2.GoogleCredentials;
+import io.entgra.device.mgt.core.device.mgt.core.config.DeviceConfigurationManager;
+import io.entgra.device.mgt.core.device.mgt.core.config.push.notification.ContextMetadata;
+import io.entgra.device.mgt.core.device.mgt.core.config.push.notification.PushNotificationConfiguration;
+import io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm.FCMNotificationStrategy;
+import okhttp3.ConnectionPool;
+import okhttp3.OkHttpClient;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.utils.CarbonUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+public class FCMUtil {
+
+ private static final Log log = LogFactory.getLog(FCMUtil.class);
+ private static volatile FCMUtil instance;
+ private static GoogleCredentials defaultApplication;
+ private static final String FCM_SERVICE_ACCOUNT_PATH = CarbonUtils.getCarbonHome() + File.separator +
+ "repository" + File.separator + "resources" + File.separator + "service-account.json";
+ private static final String[] FCM_SCOPES = { "https://www.googleapis.com/auth/firebase.messaging" };
+ private Properties contextMetadataProperties;
+ private static ConnectionPool connectionPool;
+ private static OkHttpClient client;
+
+ private FCMUtil() {
+ initContextConfigs();
+ initDefaultOAuthApplication();
+ initPooledConnection();
+ }
+
+ /**
+ * Initialize the connection pool for the OkHttpClient instance.
+ */
+ private void initPooledConnection() {
+ connectionPool = new ConnectionPool(25, 1, TimeUnit.MINUTES);
+ client = new OkHttpClient.Builder().connectionPool(connectionPool).build();
+ }
+
+ /**
+ * Get the Pooled OkHttpClient instance
+ * @return OkHttpClient instance
+ */
+ public OkHttpClient getHttpClient() {
+ return client;
+ }
+
+ private void initDefaultOAuthApplication() {
+ if (defaultApplication == null) {
+ Path serviceAccountPath = Paths.get(FCM_SERVICE_ACCOUNT_PATH);
+ try {
+ defaultApplication = GoogleCredentials.
+ fromStream(Files.newInputStream(serviceAccountPath)).
+ createScoped(FCM_SCOPES);
+ } catch (IOException e) {
+ String msg = "Fail to initialize default OAuth application for FCM communication";
+ log.error(msg);
+ throw new IllegalStateException(msg, e);
+ }
+ }
+ }
+
+ /**
+ * Initialize the context metadata properties from the cdm-config.xml. This file includes the fcm server URL
+ * to be invoked when sending the wakeup call to the device.
+ */
+ private void initContextConfigs() {
+ PushNotificationConfiguration pushNotificationConfiguration = DeviceConfigurationManager.getInstance().
+ getDeviceManagementConfig().getPushNotificationConfiguration();
+ List contextMetadata = pushNotificationConfiguration.getContextMetadata();
+ Properties properties = new Properties();
+ if (contextMetadata != null) {
+ for (ContextMetadata metadata : contextMetadata) {
+ properties.setProperty(metadata.getKey(), metadata.getValue());
+ }
+ }
+ contextMetadataProperties = properties;
+ }
+
+ /**
+ * Get the instance of FCMUtil. FCMUtil is a singleton class which should not be
+ * instantiating more than once. Instantiating the class requires to read the service account file from
+ * the filesystem and instantiation of the GoogleCredentials object which are costly operations.
+ * @return FCMUtil instance
+ */
+ public static FCMUtil getInstance() {
+ if (instance == null) {
+ synchronized (FCMUtil.class) {
+ if (instance == null) {
+ instance = new FCMUtil();
+ }
+ }
+ }
+ return instance;
+ }
+
+ public GoogleCredentials getDefaultApplication() {
+ return defaultApplication;
+ }
+
+ public Properties getContextMetadataProperties() {
+ return contextMetadataProperties;
+ }
+}
diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.http/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.http/pom.xml
index 8909230131..53d4fbab79 100644
--- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.http/pom.xml
+++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.http/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.mqtt/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.mqtt/pom.xml
index 167b1dcc67..2b9a09a282 100644
--- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.mqtt/pom.xml
+++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.mqtt/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.xmpp/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.xmpp/pom.xml
index 6546e5d8f2..c0de48044f 100644
--- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.xmpp/pom.xml
+++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.xmpp/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.stateengine/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.stateengine/pom.xml
index efe179f503..27a70b464e 100644
--- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.stateengine/pom.xml
+++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.stateengine/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper/pom.xml
index 4c0f550469..8cd558dda0 100644
--- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper/pom.xml
+++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper/pom.xml
@@ -22,7 +22,7 @@
device-mgt-extensions
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt-extensions/pom.xml b/components/device-mgt-extensions/pom.xml
index 5912b6f830..5e906f2c8e 100644
--- a/components/device-mgt-extensions/pom.xml
+++ b/components/device-mgt-extensions/pom.xml
@@ -22,7 +22,7 @@
io.entgra.device.mgt.core.parent
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../../pom.xml
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/pom.xml b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/pom.xml
index d975ad3715..a84a45a8d2 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/pom.xml
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/pom.xml
@@ -22,7 +22,7 @@
device-mgt
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/beans/ApplicationUninstallation.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/beans/ApplicationUninstallation.java
index f78d15966e..eee5f06c49 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/beans/ApplicationUninstallation.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/beans/ApplicationUninstallation.java
@@ -18,6 +18,7 @@
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans;
+import com.google.gson.Gson;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@@ -113,4 +114,8 @@ public class ApplicationUninstallation {
public void setType(String type) {
this.type = type;
}
+
+ public String toJson() {
+ return new Gson().toJson(this);
+ }
}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/DeviceManagementService.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/DeviceManagementService.java
index f1e464a0d9..5c41168bcb 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/DeviceManagementService.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/DeviceManagementService.java
@@ -165,6 +165,13 @@ import java.util.Map;
roles = {"Internal/devicemgt-user"},
permissions = {"/device-mgt/devices/change-status"}
),
+ @Scope(
+ name = "Update status of a given operation",
+ description = "Updates the status of a given operation of a given device",
+ key = "dm:devices:ops:status:update",
+ roles = {"Internal/devicemgt-user"},
+ permissions = {"/device-mgt/devices/operations/status-update"}
+ ),
@Scope(
name = "Enroll Device",
description = "Register a device",
@@ -303,6 +310,12 @@ public interface DeviceManagementService {
required = false)
@QueryParam("groupId")
int groupId,
+ @ApiParam(
+ name = "excludeGroupId",
+ value = "Id of the group that needs to get the devices that are not belong.",
+ required = false)
+ @QueryParam("excludeGroupId")
+ int excludeGroupId,
@ApiParam(
name = "since",
value = "Checks if the requested variant was created since the specified date-time.\n" +
@@ -2714,12 +2727,12 @@ public interface DeviceManagementService {
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT",
- value = "Update status of a given opeation",
+ value = "Update status of a given operation",
notes = "Updates the status of a given operation of a given device in Entgra IoT Server.",
tags = "Device Management",
extensions = {
@Extension(properties = {
- @ExtensionProperty(name = Constants.SCOPE, value = "dm:devices:ops:view")
+ @ExtensionProperty(name = Constants.SCOPE, value = "dm:devices:ops:status:update")
})
}
)
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/PolicyManagementService.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/PolicyManagementService.java
index 8cce7e92b3..4abcf68617 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/PolicyManagementService.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/PolicyManagementService.java
@@ -934,6 +934,12 @@ public interface PolicyManagementService {
required = false)
@QueryParam("status")
String status,
+ @ApiParam(
+ name = "deviceType",
+ value = "The device type of the policy that needs filtering.",
+ required = false)
+ @QueryParam("deviceType")
+ String deviceType,
@ApiParam(
name = "If-Modified-Since",
value = "Checks if the requested variant was modified, since the specified date-time. \n" +
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/admin/UserManagementAdminService.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/admin/UserManagementAdminService.java
index 5d324aeb02..08b51ac9c4 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/admin/UserManagementAdminService.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/admin/UserManagementAdminService.java
@@ -298,8 +298,13 @@ public interface UserManagementAdminService {
name = "tenantDomain",
value = "The domain of the tenant to be deleted.",
required = true)
-
@PathParam("tenantDomain")
- String tenantDomain);
-
+ String tenantDomain,
+ @ApiParam(
+ name = "deleteAppArtifacts",
+ value = "Flag to indicate whether to delete application artifacts.",
+ required = false)
+ @QueryParam("deleteAppArtifacts")
+ @DefaultValue("false")
+ boolean deleteAppArtifacts);
}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/ActivityProviderServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/ActivityProviderServiceImpl.java
index a4148f07a8..bcfdb69aac 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/ActivityProviderServiceImpl.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/ActivityProviderServiceImpl.java
@@ -175,7 +175,6 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
activity.setUsername(appActivity.getUsername());
activity.setPackageName(appActivity.getPackageName());
activity.setAppName(appActivity.getAppName());
- activity.setStatus(appActivity.getStatus());
activity.setAppType(appActivity.getAppType());
activity.setVersion(appActivity.getVersion());
activity.setTriggeredBy(appActivity.getTriggeredBy());
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImpl.java
index 58259e19c8..88cfe125ca 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImpl.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImpl.java
@@ -19,7 +19,6 @@
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.gson.Gson;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationInstallResponse;
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionType;
import io.entgra.device.mgt.core.application.mgt.common.exception.SubscriptionManagementException;
@@ -44,6 +43,7 @@ import org.wso2.carbon.context.PrivilegedCarbonContext;
import io.entgra.device.mgt.core.device.mgt.common.*;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.Application;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.ApplicationManagementException;
+import io.entgra.device.mgt.core.device.mgt.common.app.mgt.MobileAppTypes;
import io.entgra.device.mgt.core.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import io.entgra.device.mgt.core.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceData;
@@ -147,6 +147,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@QueryParam("customProperty") String customProperty,
@QueryParam("status") List status,
@QueryParam("groupId") int groupId,
+ @QueryParam("excludeGroupId") int excludeGroupId,
@QueryParam("since") String since,
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("requireDeviceInfo") boolean requireDeviceInfo,
@@ -209,7 +210,22 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
request.setStatusList(status);
}
}
- // this is the user who initiates the request
+
+ if (excludeGroupId != 0) {
+ request.setGroupId(excludeGroupId);
+
+ if (user != null && !user.isEmpty()) {
+ request.setOwner(MultitenantUtils.getTenantAwareUsername(user));
+ } else if (userPattern != null && !userPattern.isEmpty()) {
+ request.setOwnerPattern(userPattern);
+ }
+
+ result = dms.getDevicesNotInGroup(request, requireDeviceInfo);
+ devices.setList((List) result.getData());
+ devices.setCount(result.getRecordsTotal());
+ return Response.status(Response.Status.OK).entity(devices).build();
+ }
+
String authorizedUser = CarbonContext.getThreadLocalCarbonContext().getUsername();
if (groupId != 0) {
@@ -541,22 +557,49 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@Path("/type/{deviceType}/id/{deviceId}/rename")
public Response renameDevice(Device device, @PathParam("deviceType") String deviceType,
@PathParam("deviceId") String deviceId) {
+ if (device == null) {
+ String msg = "Required values are not set to rename device";
+ log.error(msg);
+ return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
+ }
+ if (StringUtils.isEmpty(device.getName())) {
+ String msg = "Device name is not set to rename device";
+ log.error(msg);
+ return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
+ }
DeviceManagementProviderService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceManagementService();
try {
- Device persistedDevice = deviceManagementProviderService.getDevice(new DeviceIdentifier
- (deviceId, deviceType), true);
- persistedDevice.setName(device.getName());
- System.out.println("This is rename device");
- boolean responseOfmodifyEnrollment = deviceManagementProviderService.modifyEnrollment(persistedDevice);
- boolean responseOfDeviceNameChanged = deviceManagementProviderService.sendDeviceNameChangedNotification(
- persistedDevice);
- boolean response = responseOfmodifyEnrollment && responseOfDeviceNameChanged;
-
- return Response.status(Response.Status.CREATED).entity(response).build();
- } catch (DeviceManagementException e) {
- String msg = "Error encountered while updating requested device of type : " + deviceType ;
+ Device updatedDevice = deviceManagementProviderService.updateDeviceName(device, deviceType, deviceId);
+ if (updatedDevice != null) {
+ boolean notificationResponse = deviceManagementProviderService.sendDeviceNameChangedNotification(updatedDevice);
+ if (notificationResponse) {
+ return Response.status(Response.Status.CREATED).entity(updatedDevice).build();
+ } else {
+ String msg = "Device updated successfully, but failed to send notification.";
+ log.warn(msg);
+ return Response.status(Response.Status.CREATED).entity(updatedDevice).header("Warning", msg).build();
+ }
+ } else {
+ String msg = "Device update failed for device of type : " + deviceType;
+ log.error(msg);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
+ }
+ } catch (BadRequestException e) {
+ String msg = "Bad request: " + e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
+ } catch (DeviceNotFoundException e) {
+ String msg = "Device not found: " + e.getMessage();
+ log.error(msg, e);
+ return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
+ } catch (DeviceManagementException e) {
+ String msg = "Error encountered while updating requested device of type : " + deviceType;
+ log.error(msg, e);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
+ } catch (ConflictException e) {
+ String msg = "Conflict encountered while updating requested device of type : " + deviceType;
+ log.error(msg, e);
+ return Response.status(Response.Status.CONFLICT).entity(msg).build();
}
}
@@ -1069,7 +1112,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@QueryParam("version") String version,
@QueryParam("user") String user) {
List deviceIdentifiers = new ArrayList<>();
- Operation operation = new Operation();
try {
RequestValidationUtil.validateDeviceIdentifier(type, id);
Device device = DeviceMgtAPIUtils.getDeviceManagementService().getDevice(id, false);
@@ -1090,11 +1132,12 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
//if the applications not installed via entgra store
} else {
if (Constants.ANDROID.equals(type)) {
- ApplicationUninstallation applicationUninstallation = new ApplicationUninstallation(packageName, "PUBLIC", name, platform, version, user);
- Gson gson = new Gson();
+ ApplicationUninstallation applicationUninstallation = new ApplicationUninstallation(packageName,
+ MobileAppTypes.PUBLIC.toString(), name, platform, version, user);
+ ProfileOperation operation = new ProfileOperation();
operation.setCode(MDMAppConstants.AndroidConstants.UNMANAGED_APP_UNINSTALL);
operation.setType(Operation.Type.PROFILE);
- operation.setPayLoad(gson.toJson(applicationUninstallation));
+ operation.setPayLoad(applicationUninstallation.toJson());
DeviceManagementProviderService deviceManagementProviderService = HelperUtil
.getDeviceManagementProviderService();
Activity activity = deviceManagementProviderService.addOperation(
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GroupManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GroupManagementServiceImpl.java
index fc8f080b07..e8c56680b1 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GroupManagementServiceImpl.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GroupManagementServiceImpl.java
@@ -273,7 +273,7 @@ public class GroupManagementServiceImpl implements GroupManagementService {
);
return Response.status(Response.Status.OK).build();
} catch (GroupManagementException e) {
- String msg = "Error occurred while adding new group.";
+ String msg = "Error occurred while updating group. ";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (GroupNotExistException e) {
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/PolicyManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/PolicyManagementServiceImpl.java
index 311b4292a7..d882018073 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/PolicyManagementServiceImpl.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/PolicyManagementServiceImpl.java
@@ -488,6 +488,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
@QueryParam("name") String name,
@QueryParam("type") String type,
@QueryParam("status") String status,
+ @QueryParam("deviceType") String deviceType,
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("offset") int offset,
@QueryParam("limit") int limit) {
@@ -505,6 +506,9 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
if (status != null){
request.setStatus(status);
}
+ if (deviceType != null) {
+ request.setDeviceType(deviceType);
+ }
try {
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
policies = policyAdministratorPoint.getPolicyList(request);
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/admin/UserManagementAdminServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/admin/UserManagementAdminServiceImpl.java
index d4f34d8e4a..91ed3f6d42 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/admin/UserManagementAdminServiceImpl.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/admin/UserManagementAdminServiceImpl.java
@@ -19,6 +19,7 @@ package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.admin;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
+import io.entgra.device.mgt.core.tenant.mgt.common.exception.TenantMgtException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
@@ -29,9 +30,6 @@ import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.CredentialManagementR
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.context.CarbonContext;
-import org.wso2.carbon.stratos.common.exception.StratosException;
-import org.wso2.carbon.tenant.mgt.services.TenantMgtAdminService;
-import org.wso2.carbon.user.api.UserStoreException;
import javax.validation.constraints.Size;
import javax.ws.rs.*;
@@ -91,7 +89,7 @@ public class UserManagementAdminServiceImpl implements UserManagementAdminServic
@DELETE
@Path("/domain/{tenantDomain}")
@Override
- public Response deleteTenantByDomain(@PathParam("tenantDomain") String tenantDomain) {
+ public Response deleteTenantByDomain(@PathParam("tenantDomain") String tenantDomain, @QueryParam("deleteAppArtifacts") boolean deleteAppArtifacts) {
try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
if (tenantId != MultitenantConstants.SUPER_TENANT_ID){
@@ -99,15 +97,20 @@ public class UserManagementAdminServiceImpl implements UserManagementAdminServic
log.error(msg);
return Response.status(Response.Status.UNAUTHORIZED).entity(msg).build();
} else {
+ if (deleteAppArtifacts) {
+ DeviceMgtAPIUtils.getApplicationManager().deleteApplicationArtifactsByTenantDomain(tenantDomain);
+ }
DeviceMgtAPIUtils.getApplicationManager().deleteApplicationDataByTenantDomain(tenantDomain);
DeviceMgtAPIUtils.getDeviceManagementService().deleteDeviceDataByTenantDomain(tenantDomain);
- TenantMgtAdminService tenantMgtAdminService = new TenantMgtAdminService();
- tenantMgtAdminService.deleteTenant(tenantDomain);
+ DeviceMgtAPIUtils.getTenantManagerAdminService().deleteTenant(tenantDomain);
String msg = "Tenant Deletion process has been initiated for tenant:" + tenantDomain;
+ if (log.isDebugEnabled()) {
+ log.debug(msg);
+ }
return Response.status(Response.Status.OK).entity(msg).build();
}
- } catch (StratosException | UserStoreException e) {
+ } catch (TenantMgtException e) {
String msg = "Error deleting tenant: " + tenantDomain;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/util/RequestValidationUtil.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/util/RequestValidationUtil.java
index 71d875a6b9..ab66e75d1c 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/util/RequestValidationUtil.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/util/RequestValidationUtil.java
@@ -23,6 +23,8 @@ import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpStatus;
+import org.json.JSONArray;
+import org.json.JSONObject;
import io.entgra.device.mgt.core.device.mgt.common.Base64File;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.Feature;
@@ -821,6 +823,30 @@ public class RequestValidationUtil {
new ErrorResponse.ErrorResponseBuilder()
.setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
}
+ if (metadata.getMetaKey().equals("PER_DEVICE_COST")) {
+ String metaValue = metadata.getMetaValue();
+ JSONArray jsonArray = new JSONArray(metaValue);
+
+ for (int i = 0; i < jsonArray.length(); i++) {
+ JSONObject jsonObject = jsonArray.getJSONObject(i);
+ if (jsonObject.has("cost")) {
+ Object costObj = jsonObject.get("cost");
+ if (costObj == JSONObject.NULL || (costObj instanceof Number && ((Number) costObj).doubleValue() < 0)) {
+ String msg = "Billing cost cannot be a minus value or null.";
+ log.error(msg);
+ throw new InputValidationException(
+ new ErrorResponse.ErrorResponseBuilder()
+ .setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
+ }
+ } else {
+ String msg = "Billing cost is missing.";
+ log.error(msg);
+ throw new InputValidationException(
+ new ErrorResponse.ErrorResponseBuilder()
+ .setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
+ }
+ }
+ }
if (metadata.getMetaValue() == null) {
String msg = "Request parameter metaValue should be non empty.";
log.error(msg);
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/util/DeviceMgtAPIUtils.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/util/DeviceMgtAPIUtils.java
index 885d521389..5451572519 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/util/DeviceMgtAPIUtils.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/util/DeviceMgtAPIUtils.java
@@ -24,6 +24,7 @@ import io.entgra.device.mgt.core.application.mgt.common.services.SubscriptionMan
import io.entgra.device.mgt.core.device.mgt.common.authorization.GroupAccessAuthorizationService;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService;
import io.entgra.device.mgt.core.device.mgt.core.permission.mgt.PermissionManagerServiceImpl;
+import io.entgra.device.mgt.core.tenant.mgt.common.spi.TenantManagerAdminService;
import org.apache.axis2.AxisFault;
import org.apache.axis2.client.Options;
import org.apache.axis2.java.security.SSLProtocolSocketFactory;
@@ -163,6 +164,7 @@ public class DeviceMgtAPIUtils {
private static volatile ApplicationManager applicationManager;
private static volatile APIPublisherService apiPublisher;
+ private static volatile TenantManagerAdminService tenantManagerAdminService;
static {
String keyStorePassword = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Password");
@@ -1243,4 +1245,21 @@ public class DeviceMgtAPIUtils {
}
return isPermitted;
}
+
+ public static TenantManagerAdminService getTenantManagerAdminService(){
+ if(tenantManagerAdminService == null) {
+ synchronized (DeviceMgtAPIUtils.class) {
+ if (tenantManagerAdminService == null) {
+ tenantManagerAdminService = (TenantManagerAdminService) PrivilegedCarbonContext.getThreadLocalCarbonContext().
+ getOSGiService(TenantManagerAdminService.class, null);
+ if (tenantManagerAdminService == null) {
+ String msg = "Tenant Manager Admin Service is null";
+ log.error(msg);
+ throw new IllegalStateException(msg);
+ }
+ }
+ }
+ }
+ return tenantManagerAdminService;
+ }
}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/test/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImplTest.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/test/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImplTest.java
index 63bb401d61..b66773e84d 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/test/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImplTest.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/test/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImplTest.java
@@ -157,7 +157,7 @@ public class DeviceManagementServiceImplTest {
.toReturn(this.deviceAccessAuthorizationService);
Response response = this.deviceManagementService
.getDevices(TEST_DEVICE_NAME, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
- null, null, DEFAULT_STATUS_LIST, 1, null, null, false,
+ null, null, DEFAULT_STATUS_LIST, 1, 0, null, null, false,
10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
}
@@ -177,22 +177,22 @@ public class DeviceManagementServiceImplTest {
Response response = this.deviceManagementService
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
- null,null, DEFAULT_STATUS_LIST, 1, null, null, false,
+ null,null, DEFAULT_STATUS_LIST, 1, 0, null, null, false,
10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
response = this.deviceManagementService
.getDevices(TEST_DEVICE_NAME, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, null, DEFAULT_OWNERSHIP,
- null, null, DEFAULT_STATUS_LIST, 1, null, null, false,
+ null, null, DEFAULT_STATUS_LIST, 1, 0, null, null, false,
10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
response = this.deviceManagementService
.getDevices(TEST_DEVICE_NAME, TEST_DEVICE_TYPE, null, null, null, DEFAULT_OWNERSHIP,
- null, null, DEFAULT_STATUS_LIST, 1, null, null, false,
+ null, null, DEFAULT_STATUS_LIST, 1, 0, null, null, false,
10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
response = this.deviceManagementService
.getDevices(TEST_DEVICE_NAME, TEST_DEVICE_TYPE, null, null, null, DEFAULT_OWNERSHIP,
- null, null, DEFAULT_STATUS_LIST, 1, null, null, true,
+ null, null, DEFAULT_STATUS_LIST, 1, 0, null, null, true,
10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
}
@@ -307,7 +307,7 @@ public class DeviceManagementServiceImplTest {
Mockito.when(deviceAccessAuthorizationService.isDeviceAdminUser()).thenReturn(true);
deviceManagementService.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null,
DEFAULT_ROLE, DEFAULT_OWNERSHIP, null,null, DEFAULT_STATUS_LIST, 1,
- null, null, false, 10, 5);
+ 0, null, null, false, 10, 5);
}
@Test(description = "Testing get devices when user is the device admin")
@@ -326,11 +326,11 @@ public class DeviceManagementServiceImplTest {
Response response = this.deviceManagementService
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP
- , null, null, DEFAULT_STATUS_LIST, 1, null, null, false, 10, 5);
+ , null, null, DEFAULT_STATUS_LIST, 1, 0, null, null, false, 10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
response = this.deviceManagementService
.getDevices(null, TEST_DEVICE_TYPE, null, DEFAULT_USERNAME, DEFAULT_ROLE, DEFAULT_OWNERSHIP
- , null, null, DEFAULT_STATUS_LIST, 1, null, null, false, 10, 5);
+ , null, null, DEFAULT_STATUS_LIST, 1, 0, null, null, false, 10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
}
@@ -352,7 +352,7 @@ public class DeviceManagementServiceImplTest {
Response response = this.deviceManagementService
.getDevices(null, TEST_DEVICE_TYPE, "newuser", null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
- null, null, DEFAULT_STATUS_LIST, 0, null, null, false,
+ null, null, DEFAULT_STATUS_LIST, 0, 0, null, null, false,
10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode());
Mockito.reset(this.deviceAccessAuthorizationService);
@@ -374,17 +374,17 @@ public class DeviceManagementServiceImplTest {
Response response = this.deviceManagementService
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
- null, null, DEFAULT_STATUS_LIST, 0, null, ifModifiedSince, false,
+ null, null, DEFAULT_STATUS_LIST, 0, 0, null, ifModifiedSince, false,
10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.NOT_MODIFIED.getStatusCode());
response = this.deviceManagementService
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
- null, null, DEFAULT_STATUS_LIST, 0, null, ifModifiedSince, true,
+ null, null, DEFAULT_STATUS_LIST, 0, 0, null, ifModifiedSince, true,
10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.NOT_MODIFIED.getStatusCode());
response = this.deviceManagementService
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
- null, null, DEFAULT_STATUS_LIST, 0, null, "ErrorModifiedSince",
+ null, null, DEFAULT_STATUS_LIST, 0, 0, null, "ErrorModifiedSince",
false, 10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
}
@@ -405,17 +405,17 @@ public class DeviceManagementServiceImplTest {
Response response = this.deviceManagementService
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
- null, null,DEFAULT_STATUS_LIST, 0, since, null, false,
+ null, null,DEFAULT_STATUS_LIST, 0, 0, since, null, false,
10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
response = this.deviceManagementService
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
- null, null,DEFAULT_STATUS_LIST, 0, since, null, true,
+ null, null,DEFAULT_STATUS_LIST, 0, 0, since, null, true,
10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
response = this.deviceManagementService
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
- null, null,DEFAULT_STATUS_LIST, 0, "ErrorSince", null, false,
+ null, null,DEFAULT_STATUS_LIST, 0, 0, "ErrorSince", null, false,
10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
}
@@ -438,7 +438,7 @@ public class DeviceManagementServiceImplTest {
Response response = this.deviceManagementService
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
- null, null, DEFAULT_STATUS_LIST, 1, null, null, false,
+ null, null, DEFAULT_STATUS_LIST, 1, 0, null, null, false,
10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
Mockito.reset(this.deviceManagementProviderService);
@@ -461,7 +461,7 @@ public class DeviceManagementServiceImplTest {
Response response = this.deviceManagementService
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
- null, null, DEFAULT_STATUS_LIST, 1, null, null, false,
+ null, null, DEFAULT_STATUS_LIST, 1, 0, null, null, false,
10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
Mockito.reset(this.deviceAccessAuthorizationService);
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/pom.xml b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/pom.xml
index a472beedad..98859c7087 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/pom.xml
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/pom.xml
@@ -21,7 +21,7 @@
device-mgt
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/Device.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/Device.java
index b75f557077..2819364327 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/Device.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/Device.java
@@ -97,6 +97,10 @@ public class Device implements Serializable {
public Device() {
}
+ public Device(int id) {
+ this.id = id;
+ }
+
public Device(String name, String type, String description, String deviceId, EnrolmentInfo enrolmentInfo,
List features, List properties) {
this.name = name;
@@ -268,7 +272,9 @@ public class Device implements Serializable {
Device device = (Device) o;
- return getDeviceIdentifier().equals(device.getDeviceIdentifier());
+ if (getDeviceIdentifier().equals(device.getDeviceIdentifier())) return true;
+
+ return getId() == device.getId();
}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/MDMAppConstants.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/MDMAppConstants.java
index da042f8d93..da1714ede0 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/MDMAppConstants.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/MDMAppConstants.java
@@ -58,6 +58,10 @@ public class MDMAppConstants {
}
public static final String INSTALL_ENTERPRISE_APPLICATION = "INSTALL_ENTERPRISE_APPLICATION";
public static final String UNINSTALL_ENTERPRISE_APPLICATION = "UNINSTALL_ENTERPRISE_APPLICATION";
+ public static final String INSTALL_STORE_APPLICATION = "INSTALL_STORE_APPLICATION";
+ public static final String UNINSTALL_STORE_APPLICATION = "UNINSTALL_STORE_APPLICATION";
+ public static final String INSTALL_WEB_CLIP_APPLICATION = "INSTALL_WEB_CLIP";
+ public static final String UNINSTALL_WEB_CLIP_APPLICATION = "UNINSTALL_WEB_CLIP";
//App type constants related to window device type
public static final String MSI = "MSI";
public static final String APPX = "APPX";
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/PaginationRequest.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/PaginationRequest.java
index c0783fe18f..c4e01eb282 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/PaginationRequest.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/PaginationRequest.java
@@ -41,11 +41,20 @@ public class PaginationRequest {
private Date since;
private String filter;
private String serialNumber;
+ private String groupName;
+ private String roleName;
+ private String userName;
+ private String deviceStatus;
+ private String tabActionStatus;
+ private String actionStatus;
+ private String actionType;
+ private String actionTriggeredBy;
private Map customProperty = new HashMap<>();
private Map property = new HashMap<>();
private List statusList = new ArrayList<>();
private OperationLogFilters operationLogFilters = new OperationLogFilters();
private List sortColumn = new ArrayList<>();
+ private int deviceTypeId;
public OperationLogFilters getOperationLogFilters() {
return operationLogFilters;
}
@@ -220,4 +229,76 @@ public class PaginationRequest {
+ this.ownership + "' Status '" + this.statusList + "' owner '" + this.owner + "' groupId: " + this.groupId
+ " start index: " + this.startIndex + ", SortColumns: " + this.sortColumn;
}
+
+ public String getDeviceStatus() {
+ return deviceStatus;
+ }
+
+ public void setDeviceStatus(String deviceStatus) {
+ this.deviceStatus = deviceStatus;
+ }
+
+ public String getActionStatus() {
+ return actionStatus;
+ }
+
+ public void setActionStatus(String actionStatus) {
+ this.actionStatus = actionStatus;
+ }
+
+ public String getActionType() {
+ return actionType;
+ }
+
+ public void setActionType(String actionType) {
+ this.actionType = actionType;
+ }
+
+ public String getActionTriggeredBy() {
+ return actionTriggeredBy;
+ }
+
+ public void setActionTriggeredBy(String actionTriggeredBy) {
+ this.actionTriggeredBy = actionTriggeredBy;
+ }
+
+ public String getGroupName() {
+ return groupName;
+ }
+
+ public void setGroupName(String groupName) {
+ this.groupName = groupName;
+ }
+
+ public String getRoleName() {
+ return roleName;
+ }
+
+ public void setRoleName(String roleName) {
+ this.roleName = roleName;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getTabActionStatus() {
+ return tabActionStatus;
+ }
+
+ public void setTabActionStatus(String tabActionStatus) {
+ this.tabActionStatus = tabActionStatus;
+ }
+
+ public int getDeviceTypeId() {
+ return deviceTypeId;
+ }
+
+ public void setDeviceTypeId(int deviceTypeId) {
+ this.deviceTypeId = deviceTypeId;
+ }
}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/PolicyPaginationRequest.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/PolicyPaginationRequest.java
index 8a0a2f3bd4..ddbc3a51a7 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/PolicyPaginationRequest.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/PolicyPaginationRequest.java
@@ -24,6 +24,7 @@ public class PolicyPaginationRequest {
private String name;
private String type;
private String status;
+ private String deviceType;
public PolicyPaginationRequest(int start, int rowCount) {
this.startIndex = start;
@@ -70,6 +71,14 @@ public class PolicyPaginationRequest {
this.status = status;
}
+ public String getDeviceType() {
+ return deviceType;
+ }
+
+ public void setDeviceType(String deviceType) {
+ this.deviceType = deviceType;
+ }
+
@Override
public String toString() {
return "Group Name '" + this.name + "' num of rows: " + this.rowCount + " start index: " + this.startIndex;
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/app/mgt/windows/AppStoreApplication.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/app/mgt/windows/AppStoreApplication.java
new file mode 100644
index 0000000000..85a6cbd9a1
--- /dev/null
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/app/mgt/windows/AppStoreApplication.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.device.mgt.common.app.mgt.windows;
+
+import com.google.gson.Gson;
+import java.io.Serializable;
+
+public class AppStoreApplication implements Serializable {
+
+ private String type;
+ private String packageIdentifier;
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getPackageIdentifier() {
+ return packageIdentifier;
+ }
+
+ public void setPackageIdentifier(String packageIdentifier) {
+ this.packageIdentifier = packageIdentifier;
+ }
+
+ public String toJSON() {
+ Gson gson = new Gson();
+ return gson.toJson(this);
+ }
+}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/app/mgt/windows/WebClipApplication.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/app/mgt/windows/WebClipApplication.java
new file mode 100644
index 0000000000..be4feae54e
--- /dev/null
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/app/mgt/windows/WebClipApplication.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.device.mgt.common.app.mgt.windows;
+import com.google.gson.Gson;
+
+import java.util.Properties;
+
+public class WebClipApplication {
+
+ private String url;
+ private String name;
+ private String icon;
+ private String type;
+ private Properties properties;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getIcon() {
+ return icon;
+ }
+
+ public void setIcon(String icon) {
+ this.icon = icon;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public Properties getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Properties properties) {
+ this.properties = properties;
+ }
+
+ public String toJSON() {
+ Gson gson = new Gson();
+ return gson.toJson(this);
+ }
+}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/exceptions/ConflictException.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/exceptions/ConflictException.java
new file mode 100644
index 0000000000..5dec1fc431
--- /dev/null
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/exceptions/ConflictException.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2018 - 2024, 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 io.entgra.device.mgt.core.device.mgt.common.exceptions;
+
+public class ConflictException extends Exception {
+
+ private static final long serialVersionUID = -4998775497944307646L;
+
+ public ConflictException(String message) {
+ super(message);
+ }
+
+ public ConflictException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
\ No newline at end of file
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.config.api/pom.xml b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.config.api/pom.xml
index 115bdc04a6..05f6beeeba 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.config.api/pom.xml
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.config.api/pom.xml
@@ -22,7 +22,7 @@
device-mgt
io.entgra.device.mgt.core
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/pom.xml b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/pom.xml
index fe7df106e3..fdd6b0c25b 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/pom.xml
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/pom.xml
@@ -22,7 +22,7 @@
io.entgra.device.mgt.core
device-mgt
- 5.0.42-SNAPSHOT
+ 5.2.4-SNAPSHOT
../pom.xml
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/common/util/StorageManagementUtil.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/common/util/StorageManagementUtil.java
index 979a514db5..bf37d0bab6 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/common/util/StorageManagementUtil.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/common/util/StorageManagementUtil.java
@@ -23,6 +23,8 @@ import org.apache.commons.logging.LogFactory;
import io.entgra.device.mgt.core.device.mgt.common.Base64File;
import io.entgra.device.mgt.core.device.mgt.core.common.exception.StorageManagementException;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -31,6 +33,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
+import java.nio.file.Paths;
/**
* This is a util class that handles Storage Management related tasks.
@@ -87,13 +90,14 @@ public class StorageManagementUtil {
* @param path Path the file need to be saved in.
*/
public static void saveFile(InputStream inputStream, String path) throws IOException {
- try (OutputStream outStream = new FileOutputStream(new File(path))) {
- byte[] buffer = new byte[inputStream.available()];
- if (inputStream.read(buffer) != -1) {
- outStream.write(buffer);
+ try (BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(Files.newOutputStream(Paths.get(path)));
+ BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream)) {
+ byte []buffer = new byte[8192];
+ int n;
+ while ((n = bufferedInputStream.read(buffer)) != -1) {
+ bufferedOutputStream.write(buffer, 0, n);
}
- } finally {
- inputStream.close();
+ bufferedOutputStream.flush();
}
}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/config/push/notification/ContextMetadata.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/config/push/notification/ContextMetadata.java
new file mode 100644
index 0000000000..a5ead67f0a
--- /dev/null
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/config/push/notification/ContextMetadata.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2018 - 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 io.entgra.device.mgt.core.device.mgt.core.config.push.notification;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlValue;
+
+@XmlRootElement(name = "ContextMetadata")
+public class ContextMetadata {
+ private String key;
+ private String value;
+
+ @XmlAttribute(name = "key")
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ @XmlValue
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/config/push/notification/PushNotificationConfiguration.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/config/push/notification/PushNotificationConfiguration.java
index 90c6639cb1..0d64e45cdd 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/config/push/notification/PushNotificationConfiguration.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/config/push/notification/PushNotificationConfiguration.java
@@ -33,6 +33,7 @@ public class PushNotificationConfiguration {
private int schedulerTaskInitialDelay;
private boolean schedulerTaskEnabled;
private List pushNotificationProviders;
+ private List contextMetadata;
@XmlElement(name = "SchedulerBatchSize", required = true)
public int getSchedulerBatchSize() {
@@ -79,4 +80,14 @@ public class PushNotificationConfiguration {
public void setPushNotificationProviders(List pushNotificationProviders) {
this.pushNotificationProviders = pushNotificationProviders;
}
+
+ @XmlElementWrapper(name = "ProviderContextMetadata")
+ @XmlElement(name = "ContextMetadata", required = true)
+ public List getContextMetadata() {
+ return contextMetadata;
+ }
+
+ public void setContextMetadata(List contextMetadata) {
+ this.contextMetadata = contextMetadata;
+ }
}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/DeviceDAO.java
index 731bb11d59..5189068242 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/DeviceDAO.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/DeviceDAO.java
@@ -18,6 +18,7 @@
package io.entgra.device.mgt.core.device.mgt.core.dao;
+import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
import org.apache.commons.collections.map.SingletonMap;
import io.entgra.device.mgt.core.device.mgt.common.*;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo.Status;
@@ -844,4 +845,48 @@ public interface DeviceDAO {
List getAgentVersions(int tenantId) throws DeviceManagementDAOException;
List getDevicesEnrolledSince(Date since) throws DeviceManagementDAOException;
List getDevicesEnrolledPriorTo(Date priorTo) throws DeviceManagementDAOException;
+
+ /**
+ * This method is used to search for devices that are not in a specific group.
+ *
+ * @param request PaginationRequest object holding the data for pagination
+ * @param tenantId tenant id.
+ * @return returns paginated list of devices.
+ * @throws DeviceManagementDAOException
+ */
+ List searchDevicesNotInGroup(PaginationRequest request, int tenantId) throws DeviceManagementDAOException;
+
+ /**
+ * This method is used to get device count that are not within a specific group.
+ *
+ * @param request PaginationRequest object holding the data for pagination
+ * @param tenantId tenant id
+ * @return Device count
+ * @throws DeviceManagementDAOException
+ */
+ int getCountOfDevicesNotInGroup(PaginationRequest request, int tenantId) throws DeviceManagementDAOException;
+
+ List getDevicesNotInGivenIdList(List deviceIds, int tenantId)
+ throws DeviceManagementDAOException;
+
+ List getDevicesInGivenIdList(List deviceIds, int tenantId)
+ throws DeviceManagementDAOException;
+
+ int getDeviceCountNotInGivenIdList(List deviceIds, int tenantId)
+ throws DeviceManagementDAOException;
+
+ List getDevicesByDeviceIds(PaginationRequest paginationRequest, List deviceIds, int tenantId)
+ throws DeviceManagementDAOException;
+
+ int getDeviceCountByDeviceIds(PaginationRequest paginationRequest, List deviceIds, int tenantId)
+ throws DeviceManagementDAOException;
+
+ /**
+ * This method is used to get device count that are not within a specific group.
+ *
+ * @param statuses Device statuses to be filtered
+ * @return deviceIds
+ * @throws DeviceManagementException
+ */
+ List getDeviceIdsByStatus(List statuses) throws DeviceManagementException;
}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/EnrollmentDAO.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/EnrollmentDAO.java
index e42d5c1524..70b791db7b 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/EnrollmentDAO.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/EnrollmentDAO.java
@@ -21,9 +21,12 @@ import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo.Status;
+import io.entgra.device.mgt.core.device.mgt.core.dto.DeviceDetailsDTO;
+import io.entgra.device.mgt.core.device.mgt.core.dto.OwnerWithDeviceDTO;
import java.sql.Timestamp;
import java.util.List;
+import java.util.Map;
public interface EnrollmentDAO {
@@ -94,5 +97,46 @@ public interface EnrollmentDAO {
*/
boolean addDeviceStatus(int enrolmentId, EnrolmentInfo.Status status) throws DeviceManagementDAOException;
+ /**
+ * Retrieves owners and the list of device IDs related to an owner.
+ *
+ * @param owner the owner whose device IDs need to be retrieved
+ * @param allowingDeviceStatuses statuses of devices need to be retrieved
+ * @param tenantId the ID of the tenant
+ * @param deviceOwner owner of the device
+ * @param deviceName name of the device
+ * @param deviceStatus status of the device
+ * @return {@link OwnerWithDeviceDTO} which contains a list of devices related to a user
+ * @throws DeviceManagementDAOException if an error occurs while fetching the data
+ */
+ OwnerWithDeviceDTO getOwnersWithDevices(String owner, List allowingDeviceStatuses, int tenantId, int deviceTypeId,
+ String deviceOwner, String deviceName, String deviceStatus) throws DeviceManagementDAOException;
+ /**
+ * Retrieves a list of device IDs with owners and device status.
+ *
+ * @param deviceId the deviceId of the device which user need to be retrieved
+ * @param tenantId the ID of the tenant
+ * @param deviceOwner owner of the device
+ * @param deviceName name of the device
+ * @param deviceStatus status of the device
+ * @return {@link OwnerWithDeviceDTO} which contains a list of devices
+ * @throws DeviceManagementDAOException if an error occurs while fetching the data
+ */
+ OwnerWithDeviceDTO getOwnerWithDeviceByDeviceId(int deviceId, int tenantId, String deviceOwner, String deviceName, String deviceStatus)
+ throws DeviceManagementDAOException;
+
+ /**
+ * Retrieves owners and the list of device IDs with device status.
+ *
+ * @param tenantId the ID of the tenant
+ * @param allowingDeviceStatuses the allowed device statuses of devices
+ * @param deviceTypeId the device type id
+ * @param deviceOwner owner of the device
+ * @param deviceStatus status of the device
+ * @return {@link OwnerWithDeviceDTO} which contains a list of devices related to a user
+ * @throws DeviceManagementDAOException if an error occurs while fetching the data
+ */
+ List getDevicesByTenantId(int tenantId, List allowingDeviceStatuses, int deviceTypeId, String deviceOwner,
+ String deviceStatus) throws DeviceManagementDAOException;
}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/GroupDAO.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/GroupDAO.java
index b3c4321df3..5da24ad91d 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/GroupDAO.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/GroupDAO.java
@@ -21,9 +21,9 @@ package io.entgra.device.mgt.core.device.mgt.core.dao;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.GroupPaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
-import io.entgra.device.mgt.core.device.mgt.common.exceptions.ReportManagementException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupRoleWrapper;
+import io.entgra.device.mgt.core.device.mgt.core.dto.GroupDetailsDTO;
import java.util.List;
import java.util.Map;
@@ -469,4 +469,24 @@ public interface GroupDAO {
List groupNames)
throws GroupManagementDAOException;
+ /**
+ * Get group details and list of device IDs related to the group.
+ *
+ * @param groupName Group name
+ * @param allowingDeviceStatuses the statuses of devices
+ * @param deviceTypeId the device type id
+ * @param tenantId Tenant ID
+ * @param deviceOwner owner of the device
+ * @param deviceName name of the device
+ * @param deviceStatus status of the device
+ * @param offset the offset for the data set
+ * @param limit the limit for the data set
+ * @return {@link GroupDetailsDTO} which containing group details and a list of device IDs
+ * @throws GroupManagementDAOException if an error occurs while retrieving the group details and devices
+ */
+ GroupDetailsDTO getGroupDetailsWithDevices(String groupName, List allowingDeviceStatuses, int deviceTypeId,
+ int tenantId, String deviceOwner, String deviceName, String deviceStatus, int offset, int limit)
+ throws GroupManagementDAOException;
+
+ int getDeviceCount(String groupName, int tenantId) throws GroupManagementDAOException;
}
\ No newline at end of file
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java
index 7ab1cdb6e3..3b8aa18647 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java
@@ -18,6 +18,7 @@
package io.entgra.device.mgt.core.device.mgt.core.dao.impl;
+import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
import org.apache.commons.collections.map.SingletonMap;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.LogFactory;
@@ -54,6 +55,7 @@ import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
import java.util.Random;
+import java.util.stream.Collectors;
public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
@@ -176,7 +178,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
+ "d.DESCRIPTION, "
+ "d.NAME, "
+ "d.LAST_UPDATED_TIMESTAMP "
- + "FROM DM_DEVICE d"
+ + "FROM DM_DEVICE d WHERE "
+ "d.DEVICE_IDENTIFICATION = ? AND "
+ "d.TENANT_ID = ?";
@@ -197,7 +199,6 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
int paramIndx = 1;
- stmt.setString(paramIndx++, deviceData.getDeviceIdentifier().getType());
stmt.setString(paramIndx++, deviceData.getDeviceIdentifier().getId());
stmt.setInt(paramIndx++, tenantId);
if (deviceData.getLastModifiedDate() != null) {
@@ -964,12 +965,12 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
+ "d.NAME AS DEVICE_NAME, "
+ "d.DEVICE_IDENTIFICATION, "
+ "d.LAST_UPDATED_TIMESTAMP, "
- + "e.DEVICE_TYPE "
+ + "e1.DEVICE_TYPE "
+ "FROM "
+ "DM_DEVICE d, "
+ "(SELECT "
+ "e.OWNER, "
- + "e.DEVICE_TYPE "
+ + "e.DEVICE_TYPE, "
+ "e.OWNERSHIP, "
+ "e.ID AS ENROLMENT_ID, "
+ "e.DEVICE_ID, "
@@ -983,7 +984,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
+ "e.TENANT_ID = ? AND "
+ "LOWER(e.OWNER) = LOWER(?) AND "
+ "e.STATUS IN (",
- ")) e1 ORDER BY e1.DATE_OF_LAST_UPDATE DESC");
+ ")) e1 WHERE d.ID = e1.DEVICE_ID ORDER BY e1.DATE_OF_LAST_UPDATE DESC");
deviceStatuses.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();
@@ -1037,12 +1038,12 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
"(SELECT gd.DEVICE_ID, " +
"gd.DESCRIPTION, " +
"gd.NAME, " +
- "gd.DEVICE_IDENTIFICATION, " +
+ "gd.DEVICE_IDENTIFICATION " +
"FROM " +
"(SELECT d.ID AS DEVICE_ID, " +
"d.DESCRIPTION, " +
"d.NAME, " +
- "d.DEVICE_IDENTIFICATION, " +
+ "d.DEVICE_IDENTIFICATION " +
"FROM DM_DEVICE d, " +
"(SELECT dgm.DEVICE_ID " +
"FROM DM_DEVICE_GROUP_MAP dgm " +
@@ -1717,7 +1718,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.LAST_UPDATED_TIMESTAMP, " +
"e.DEVICE_TYPE, e.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, " +
"e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT, e.ENROLMENT_ID FROM " +
- "(SELECT e.ID, e.DEVICE_ID, e.DEVICE_TYPE, e.OWNER, " +
+ "(SELECT e.ID, e.DEVICE_ID, e.DEVICE_TYPE, e.DEVICE_IDENTIFICATION, e.OWNER, " +
"e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, e.ID AS " +
"ENROLMENT_ID FROM DM_ENROLMENT e WHERE TENANT_ID = ? AND STATUS = ?) e, " +
"DM_DEVICE d WHERE d.ID = e.DEVICE_ID AND d.TENANT_ID = ?";
@@ -2366,7 +2367,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
"e.device_id," +
"e.status, " +
"e.date_of_last_update, " +
- "e.date_of_enrolment " +
+ "e.date_of_enrolment, " +
"e.DEVICE_TYPE " +
"FROM dm_enrolment e " +
"INNER JOIN " +
@@ -2376,7 +2377,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
"KEY_FIELD = 'encryptionEnabled' " +
"AND VALUE_FIELD = ?) AS di " +
"ON di.DEVICE_ID = e.DEVICE_ID " +
- "WHERE e.tenant_id = ?) e1, " +
+ "WHERE e.tenant_id = ?) e1 " +
"WHERE d.id = e1.device_id " +
"ORDER BY e1.date_of_last_update DESC " +
"LIMIT ? OFFSET ?";
@@ -2410,7 +2411,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
try {
Connection conn = getConnection();
String sql =
- "SELECT COUNT(DEVICE_ID) " +
+ "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT " +
"FROM DM_DEVICE_INFO " +
"WHERE KEY_FIELD = 'encryptionEnabled' " +
"AND VALUE_FIELD = ?";
@@ -2418,7 +2419,6 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setBoolean(1, isEncrypted);
- ps.setInt(2, tenantId);
try (ResultSet rs = ps.executeQuery()) {
return rs.next() ? rs.getInt("DEVICE_COUNT") : 0;
@@ -3192,4 +3192,332 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
public abstract void refactorDeviceStatus (Connection conn, List validDevices)
throws DeviceManagementDAOException;
+ @Override
+ public int getCountOfDevicesNotInGroup(PaginationRequest request, int tenantId) throws DeviceManagementDAOException {
+ int deviceCount = 0;
+ int groupId = request.getGroupId();
+ String deviceType = request.getDeviceType();
+ boolean isDeviceTypeProvided = false;
+ String deviceName = request.getDeviceName();
+ boolean isDeviceNameProvided = false;
+ String owner = request.getOwner();
+ boolean isOwnerProvided = false;
+ String ownerPattern = request.getOwnerPattern();
+ boolean isOwnerPatternProvided = false;
+ String ownership = request.getOwnership();
+ boolean isOwnershipProvided = false;
+ List statusList = request.getStatusList();
+ boolean isStatusProvided = false;
+ Date since = request.getSince();
+ boolean isSinceProvided = false;
+
+ try {
+ Connection conn = getConnection();
+ String sql = "SELECT COUNT(d1.DEVICE_ID) AS DEVICE_COUNT " +
+ "FROM DM_ENROLMENT e, " +
+ "(SELECT gd.ID AS DEVICE_ID, " +
+ "gd.DESCRIPTION, " +
+ "gd.NAME, " +
+ "gd.DEVICE_IDENTIFICATION " +
+ "FROM DM_DEVICE gd " +
+ "WHERE gd.ID NOT IN (SELECT dgm.DEVICE_ID " +
+ "FROM DM_DEVICE_GROUP_MAP dgm " +
+ "WHERE dgm.GROUP_ID = ?) " +
+ "AND gd.TENANT_ID = ?";
+
+ if (deviceName != null && !deviceName.isEmpty()) {
+ sql += " AND gd.NAME LIKE ?";
+ isDeviceNameProvided = true;
+ }
+ sql += " AND 1=1";
+
+ if (since != null) {
+ sql += " AND gd.LAST_UPDATED_TIMESTAMP > ?";
+ isSinceProvided = true;
+ }
+ sql += " ) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND e.TENANT_ID = ?";
+
+ if (deviceType != null && !deviceType.isEmpty()) {
+ sql += " AND e.DEVICE_TYPE = ?";
+ isDeviceTypeProvided = true;
+ }
+
+ if (ownership != null && !ownership.isEmpty()) {
+ sql += " AND e.OWNERSHIP = ?";
+ isOwnershipProvided = true;
+ }
+
+ if (owner != null && !owner.isEmpty()) {
+ sql += " AND e.OWNER = ?";
+ isOwnerProvided = true;
+ } else if (ownerPattern != null && !ownerPattern.isEmpty()) {
+ sql += " AND e.OWNER LIKE ?";
+ isOwnerPatternProvided = true;
+ }
+ if (statusList != null && !statusList.isEmpty()) {
+ sql += buildStatusQuery(statusList);
+ isStatusProvided = true;
+ }
+
+ try (PreparedStatement stmt = conn.prepareStatement(sql)) {
+ int paramIdx = 1;
+ stmt.setInt(paramIdx++, groupId);
+ stmt.setInt(paramIdx++, tenantId);
+ if (isDeviceNameProvided) {
+ stmt.setString(paramIdx++, "%" + deviceName + "%");
+ }
+ if (isSinceProvided) {
+ stmt.setTimestamp(paramIdx++, new Timestamp(since.getTime()));
+ }
+ stmt.setInt(paramIdx++, tenantId);
+ if (isDeviceTypeProvided) {
+ stmt.setString(paramIdx++, deviceType);
+ }
+ if (isOwnershipProvided) {
+ stmt.setString(paramIdx++, ownership);
+ }
+ if (isOwnerProvided) {
+ stmt.setString(paramIdx++, owner);
+ } else if (isOwnerPatternProvided) {
+ stmt.setString(paramIdx++, ownerPattern + "%");
+ }
+ if (isStatusProvided) {
+ for (String status : statusList) {
+ stmt.setString(paramIdx++, status);
+ }
+ }
+
+ try (ResultSet rs = stmt.executeQuery()) {
+ if (rs.next()) {
+ deviceCount = rs.getInt("DEVICE_COUNT");
+ }
+ return deviceCount;
+ }
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while retrieving count of devices not in group: " + groupId;
+ log.error(msg, e);
+ throw new DeviceManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public List getDevicesNotInGivenIdList(List deviceIds, int tenantId)
+ throws DeviceManagementDAOException {
+ List filteredDeviceIds = new ArrayList<>();
+ try {
+ Connection connection = getConnection();
+ String sql = "SELECT ID AS DEVICE_ID FROM DM_DEVICE WHERE TENANT_ID = ?";
+
+ if (deviceIds != null && !deviceIds.isEmpty()) {
+ sql += " AND ID NOT IN ( " + deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ")";
+ }
+
+ try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
+ int paraIdx = 1;
+ preparedStatement.setInt(paraIdx++, tenantId);
+
+ if (deviceIds != null && !deviceIds.isEmpty()) {
+ for (Integer deviceId : deviceIds) {
+ preparedStatement.setInt(paraIdx++, deviceId);
+ }
+ }
+
+ try (ResultSet resultSet = preparedStatement.executeQuery()) {
+ while (resultSet.next()) {
+ filteredDeviceIds.add(resultSet.getInt("DEVICE_ID"));
+ }
+ }
+ return filteredDeviceIds;
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while retrieving device ids not in: " + filteredDeviceIds;
+ log.error(msg, e);
+ throw new DeviceManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public List getDevicesInGivenIdList(List deviceIds, int tenantId)
+ throws DeviceManagementDAOException {
+ List filteredDeviceIds = new ArrayList<>();
+ if (deviceIds == null || deviceIds.isEmpty()) return filteredDeviceIds;
+
+ String deviceIdStringList = deviceIds.stream().map(id -> "?").collect(Collectors.joining(","));
+ try {
+ Connection connection = getConnection();
+ String sql = "SELECT ID AS DEVICE_ID " +
+ "FROM DM_DEVICE " +
+ "WHERE ID IN (" + deviceIdStringList + ") " +
+ "AND TENANT_ID = ? ";
+ try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
+ int paraIdx = 1;
+ for (Integer deviceId : deviceIds) {
+ preparedStatement.setInt(paraIdx++, deviceId);
+ }
+
+ preparedStatement.setInt(paraIdx, tenantId);
+ try (ResultSet resultSet = preparedStatement.executeQuery()) {
+ while (resultSet.next()) {
+ filteredDeviceIds.add(resultSet.getInt("DEVICE_ID"));
+ }
+ }
+ return filteredDeviceIds;
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while retrieving device ids in: " + filteredDeviceIds;
+ log.error(msg, e);
+ throw new DeviceManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public int getDeviceCountNotInGivenIdList(List deviceIds, int tenantId)
+ throws DeviceManagementDAOException {
+ int deviceCount = 0;
+ try {
+ Connection connection = getConnection();
+ String sql = "SELECT COUNT(ID) AS COUNT " +
+ "FROM DM_DEVICE " +
+ "WHERE TENANT_ID = ?";
+
+ if (deviceIds != null && !deviceIds.isEmpty()) {
+ sql += " AND ID NOT IN ( " + deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ")";
+ }
+
+ try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
+ int paraIdx = 1;
+ preparedStatement.setInt(paraIdx++, tenantId);
+
+ if (deviceIds != null && !deviceIds.isEmpty()) {
+ for (Integer deviceId : deviceIds) {
+ preparedStatement.setInt(paraIdx++, deviceId);
+ }
+ }
+
+ try (ResultSet resultSet = preparedStatement.executeQuery()) {
+ if (resultSet.next()) {
+ deviceCount = resultSet.getInt("COUNT");
+ }
+ }
+ return deviceCount;
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while retrieving device count";
+ log.error(msg, e);
+ throw new DeviceManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public int getDeviceCountByDeviceIds(PaginationRequest paginationRequest, List deviceIds, int tenantId)
+ throws DeviceManagementDAOException {
+ int deviceCount = 0;
+ if (deviceIds == null || deviceIds.isEmpty()) return deviceCount;
+
+ String deviceIdStringList = deviceIds.stream().map(id -> "?").collect(Collectors.joining(","));
+ boolean isOwnerProvided = false;
+ boolean isDeviceStatusProvided = false;
+ boolean isDeviceNameProvided = false;
+ boolean isDeviceTypeIdProvided = false;
+ try {
+ Connection connection = getConnection();
+ String sql = "SELECT COUNT(DISTINCT e.DEVICE_ID) AS COUNT " +
+ "FROM DM_DEVICE d " +
+ "INNER JOIN DM_ENROLMENT e " +
+ "ON d.ID = e.DEVICE_ID " +
+ "WHERE e.TENANT_ID = ? " +
+ "AND e.DEVICE_ID IN (" + deviceIdStringList+ ") " +
+ "AND e.STATUS NOT IN ('DELETED', 'REMOVED')";
+
+ if (paginationRequest.getOwner() != null) {
+ sql = sql + " AND e.OWNER LIKE ?";
+ isOwnerProvided = true;
+ }
+
+ if (paginationRequest.getDeviceStatus() != null) {
+ sql = sql + " AND e.STATUS = ?";
+ isDeviceStatusProvided = true;
+ }
+
+ if (paginationRequest.getDeviceName() != null) {
+ sql = sql + " AND d.NAME LIKE ?";
+ isDeviceNameProvided = true;
+ }
+
+ if (paginationRequest.getDeviceTypeId() > 0) {
+ sql = sql + " AND d.DEVICE_TYPE_ID = ?";
+ isDeviceTypeIdProvided = true;
+ }
+
+ try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
+ int parameterIdx = 1;
+ preparedStatement.setInt(parameterIdx++, tenantId);
+
+ for (Integer deviceId : deviceIds) {
+ preparedStatement.setInt(parameterIdx++, deviceId);
+ }
+
+ if (isOwnerProvided) {
+ preparedStatement.setString(parameterIdx++, "%" + paginationRequest.getOwner() + "%");
+ }
+ if (isDeviceStatusProvided) {
+ preparedStatement.setString(parameterIdx++, paginationRequest.getDeviceStatus());
+ }
+ if (isDeviceNameProvided) {
+ preparedStatement.setString(parameterIdx++, "%" + paginationRequest.getDeviceName() + "%");
+ }
+ if (isDeviceTypeIdProvided) {
+ preparedStatement.setInt(parameterIdx, paginationRequest.getDeviceTypeId());
+ }
+
+ try(ResultSet resultSet = preparedStatement.executeQuery()) {
+ if (resultSet.next()) {
+ deviceCount = resultSet.getInt("COUNT");
+ }
+ }
+ }
+ return deviceCount;
+ } catch (SQLException e) {
+ String msg = "Error occurred while retrieving device count for device ids in: " + deviceIds;
+ log.error(msg, e);
+ throw new DeviceManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public List getDeviceIdsByStatus(List statuses) throws DeviceManagementException {
+ StringBuilder deviceFilters = new StringBuilder();
+ for (int i = 0; i < statuses.size(); i++) {
+ deviceFilters.append("?");
+ if (i < statuses.size() - 1) {
+ deviceFilters.append(",");
+ }
+ }
+
+ try {
+ Connection conn = getConnection();
+ String sql = "SELECT DEVICE_ID " +
+ "FROM DM_ENROLMENT " +
+ "WHERE STATUS IN (" + deviceFilters.toString() + ")";
+
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {
+ for (int i = 0; i < statuses.size(); i++) {
+ ps.setString(i + 1, statuses.get(i));
+ }
+
+ try (ResultSet rs = ps.executeQuery()) {
+ List deviceIds = new ArrayList<>();
+ while (rs.next()) {
+ deviceIds.add(rs.getInt("DEVICE_ID"));
+ }
+ return deviceIds;
+ }
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while running SQL to get device IDs by status.";
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
+ }
+ }
}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractEnrollmentDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractEnrollmentDAOImpl.java
index 8bde335227..091716bfe7 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractEnrollmentDAOImpl.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractEnrollmentDAOImpl.java
@@ -18,6 +18,9 @@
package io.entgra.device.mgt.core.device.mgt.core.dao.impl;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
+import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.util.OperationDAOUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.DeviceManagementConstants;
@@ -26,6 +29,8 @@ import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOExceptio
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOFactory;
import io.entgra.device.mgt.core.device.mgt.core.dao.EnrollmentDAO;
import io.entgra.device.mgt.core.device.mgt.core.dao.util.DeviceManagementDAOUtil;
+import io.entgra.device.mgt.core.device.mgt.core.dto.OwnerWithDeviceDTO;
+import io.entgra.device.mgt.core.device.mgt.core.dto.DeviceDetailsDTO;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -33,11 +38,12 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
-import java.util.ArrayList;
import java.util.Date;
import java.util.List;
+import java.util.ArrayList;
public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
+ private static final Log log = LogFactory.getLog(AbstractEnrollmentDAOImpl.class);
@Override
public EnrolmentInfo addEnrollment(int deviceId, DeviceIdentifier deviceIdentifier, EnrolmentInfo enrolmentInfo,
@@ -557,4 +563,307 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
return enrolmentInfo;
}
+ @Override
+ public OwnerWithDeviceDTO getOwnersWithDevices(String owner, List allowingDeviceStatuses, int tenantId,
+ int deviceTypeId, String deviceOwner, String deviceName,
+ String deviceStatus) throws DeviceManagementDAOException {
+ Connection conn = null;
+ OwnerWithDeviceDTO ownerDetails = new OwnerWithDeviceDTO();
+ List deviceIds = new ArrayList<>();
+ int deviceCount = 0;
+
+ StringBuilder deviceFilters = new StringBuilder();
+ for (int i = 0; i < allowingDeviceStatuses.size(); i++) {
+ deviceFilters.append("?");
+ if (i < allowingDeviceStatuses.size() - 1) {
+ deviceFilters.append(",");
+ }
+ }
+
+ StringBuilder sql = new StringBuilder(
+ "SELECT e.DEVICE_ID, " +
+ "e.OWNER, " +
+ "e.STATUS AS DEVICE_STATUS, " +
+ "d.NAME AS DEVICE_NAME, " +
+ "e.DEVICE_TYPE AS DEVICE_TYPE, " +
+ "e.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION " +
+ "FROM DM_ENROLMENT e " +
+ "JOIN DM_DEVICE d ON e.DEVICE_ID = d.ID " +
+ "WHERE e.OWNER = ? AND e.TENANT_ID = ? AND e.STATUS IN (" + deviceFilters + ")");
+
+ if (deviceTypeId != 0) {
+ sql.append(" AND d.DEVICE_TYPE_ID = ?");
+ }
+ if (deviceOwner != null && !deviceOwner.isEmpty()) {
+ sql.append(" AND e.OWNER LIKE ?");
+ }
+ if (deviceName != null && !deviceName.isEmpty()) {
+ sql.append(" AND d.NAME LIKE ?");
+ }
+ if (deviceStatus != null && !deviceStatus.isEmpty()) {
+ sql.append(" AND e.STATUS = ?");
+ }
+
+ try {
+ conn = this.getConnection();
+ try (PreparedStatement stmt = conn.prepareStatement(sql.toString())) {
+ int index = 1;
+ stmt.setString(index++, owner);
+ stmt.setInt(index++, tenantId);
+ for (String status : allowingDeviceStatuses) {
+ stmt.setString(index++, status);
+ }
+ if (deviceTypeId != 0) {
+ stmt.setInt(index++, deviceTypeId);
+ }
+
+ if (deviceOwner != null && !deviceOwner.isEmpty()) {
+ stmt.setString(index++, "%" + deviceOwner + "%");
+ }
+ if (deviceName != null && !deviceName.isEmpty()) {
+ stmt.setString(index++, "%" + deviceName + "%");
+ }
+ if (deviceStatus != null && !deviceStatus.isEmpty()) {
+ stmt.setString(index++, deviceStatus);
+ }
+
+ try (ResultSet rs = stmt.executeQuery()) {
+ while (rs.next()) {
+ deviceIds.add(rs.getInt("DEVICE_ID"));
+ deviceCount++;
+ }
+ }
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while retrieving owners and device IDs for owner: " + owner;
+ log.error(msg, e);
+ throw new DeviceManagementDAOException(msg, e);
+ }
+ ownerDetails.setUserName(deviceOwner);
+ ownerDetails.setDeviceIds(deviceIds);
+ ownerDetails.setDeviceCount(deviceCount);
+ return ownerDetails;
+ }
+
+// @Override
+// public OwnerWithDeviceDTO getOwnersWithDevices(String owner, List allowingDeviceStatuses, int tenantId,
+// int deviceTypeId, String deviceOwner, String deviceName,
+// String deviceStatus) throws DeviceManagementDAOException {
+// Connection conn = null;
+// OwnerWithDeviceDTO ownerDetails = new OwnerWithDeviceDTO();
+// List deviceIds = new ArrayList<>();
+// int deviceCount = 0;
+//
+// StringBuilder deviceFilters = new StringBuilder();
+// for (int i = 0; i < allowingDeviceStatuses.size(); i++) {
+// deviceFilters.append("?");
+// if (i < allowingDeviceStatuses.size() - 1) {
+// deviceFilters.append(",");
+// }
+// }
+//
+// StringBuilder sql = new StringBuilder(
+// "SELECT e.DEVICE_ID, " +
+// "e.OWNER, " +
+// "e.STATUS AS DEVICE_STATUS, " +
+// "d.NAME AS DEVICE_NAME, " +
+// "e.DEVICE_TYPE AS DEVICE_TYPE, " +
+// "e.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION " +
+// "FROM DM_ENROLMENT e " +
+// "JOIN DM_DEVICE d ON e.DEVICE_ID = d.ID " +
+// "WHERE e.OWNER = ? AND e.TENANT_ID = ? AND d.DEVICE_TYPE_ID = ? AND e.STATUS IN (" + deviceFilters + ")");
+//
+// if (deviceOwner != null && !deviceOwner.isEmpty()) {
+// sql.append(" AND e.OWNER LIKE ?");
+// }
+// if (deviceName != null && !deviceName.isEmpty()) {
+// sql.append(" AND d.NAME LIKE ?");
+// }
+// if (deviceStatus != null && !deviceStatus.isEmpty()) {
+// sql.append(" AND e.STATUS = ?");
+// }
+//
+// try {
+// conn = this.getConnection();
+// try (PreparedStatement stmt = conn.prepareStatement(sql.toString())) {
+// int index = 1;
+// stmt.setString(index++, owner);
+// stmt.setInt(index++, tenantId);
+// stmt.setInt(index++, deviceTypeId);
+// for (String status : allowingDeviceStatuses) {
+// stmt.setString(index++, status);
+// }
+//
+// if (deviceOwner != null && !deviceOwner.isEmpty()) {
+// stmt.setString(index++, "%" + deviceOwner + "%");
+// }
+// if (deviceName != null && !deviceName.isEmpty()) {
+// stmt.setString(index++, "%" + deviceName + "%");
+// }
+// if (deviceStatus != null && !deviceStatus.isEmpty()) {
+// stmt.setString(index++, deviceStatus);
+// }
+//
+// try (ResultSet rs = stmt.executeQuery()) {
+// while (rs.next()) {
+// if (ownerDetails.getUserName() == null) {
+// ownerDetails.setUserName(rs.getString("OWNER"));
+// }
+// ownerDetails.setDeviceStatus(rs.getString("DEVICE_STATUS"));
+// ownerDetails.setDeviceNames(rs.getString("DEVICE_NAME"));
+// ownerDetails.setDeviceTypes(rs.getString("DEVICE_TYPE"));
+// ownerDetails.setDeviceIdentifiers(rs.getString("DEVICE_IDENTIFICATION"));
+// deviceIds.add(rs.getInt("DEVICE_ID"));
+// deviceCount++;
+// }
+// }
+// }
+// } catch (SQLException e) {
+// String msg = "Error occurred while retrieving owners and device IDs for owner: " + owner;
+// log.error(msg, e);
+// throw new DeviceManagementDAOException(msg, e);
+// }
+// ownerDetails.setDeviceIds(deviceIds);
+// ownerDetails.setDeviceCount(deviceCount);
+// return ownerDetails;
+// }
+
+ @Override
+ public OwnerWithDeviceDTO getOwnerWithDeviceByDeviceId(int deviceId, int tenantId, String deviceOwner, String deviceName,
+ String deviceStatus) throws DeviceManagementDAOException {
+ OwnerWithDeviceDTO deviceOwnerWithStatus = new OwnerWithDeviceDTO();
+ Connection conn = null;
+ List deviceIds = new ArrayList<>();
+
+ StringBuilder sql = new StringBuilder(
+ "SELECT e.DEVICE_ID, " +
+ "e.OWNER, " +
+ "e.STATUS AS DEVICE_STATUS, " +
+ "d.NAME AS DEVICE_NAME, " +
+ "e.DEVICE_TYPE, " +
+ "e.DEVICE_IDENTIFICATION " +
+ "FROM DM_ENROLMENT e " +
+ "JOIN DM_DEVICE d ON e.DEVICE_ID = d.ID " +
+ "WHERE e.DEVICE_ID = ? AND e.TENANT_ID = ?");
+
+ if (deviceOwner != null && !deviceOwner.isEmpty()) {
+ sql.append(" AND e.OWNER LIKE ?");
+ }
+ if (deviceName != null && !deviceName.isEmpty()) {
+ sql.append(" AND d.NAME LIKE ?");
+ }
+ if (deviceStatus != null && !deviceStatus.isEmpty()) {
+ sql.append(" AND e.STATUS = ?");
+ }
+
+ try {
+ conn = this.getConnection();
+ try (PreparedStatement stmt = conn.prepareStatement(sql.toString())) {
+ int paramIndex = 1;
+ stmt.setInt(paramIndex++, deviceId);
+ stmt.setInt(paramIndex++, tenantId);
+
+ // Set filter parameters if provided
+ if (deviceOwner != null && !deviceOwner.isEmpty()) {
+ stmt.setString(paramIndex++, "%" + deviceOwner + "%");
+ }
+ if (deviceName != null && !deviceName.isEmpty()) {
+ stmt.setString(paramIndex++, "%" + deviceName + "%");
+ }
+ if (deviceStatus != null && !deviceStatus.isEmpty()) {
+ stmt.setString(paramIndex++, deviceStatus);
+ }
+
+ try (ResultSet rs = stmt.executeQuery()) {
+ if (rs.next()) {
+ deviceOwnerWithStatus.setUserName(rs.getString("OWNER"));
+ deviceOwnerWithStatus.setDeviceStatus(rs.getString("DEVICE_STATUS"));
+ deviceIds.add(rs.getInt("DEVICE_ID"));
+ deviceOwnerWithStatus.setDeviceIds(deviceIds);
+ deviceOwnerWithStatus.setDeviceNames(rs.getString("DEVICE_NAME"));
+ deviceOwnerWithStatus.setDeviceTypes(rs.getString("DEVICE_TYPE"));
+ deviceOwnerWithStatus.setDeviceIdentifiers(rs.getString("DEVICE_IDENTIFICATION"));
+ }
+ }
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while retrieving owner and status for device ID: " + deviceId;
+ log.error(msg, e);
+ throw new DeviceManagementDAOException(msg, e);
+ }
+ return deviceOwnerWithStatus;
+ }
+
+ @Override
+ public List getDevicesByTenantId(int tenantId, List allowingDeviceStatuses, int deviceTypeId,
+ String deviceOwner, String deviceStatus) throws DeviceManagementDAOException {
+ List devices = new ArrayList<>();
+ if (allowingDeviceStatuses.isEmpty()) {
+ return devices;
+ }
+
+ StringBuilder deviceFilters = new StringBuilder();
+ for (int i = 0; i < allowingDeviceStatuses.size(); i++) {
+ deviceFilters.append("?");
+ if (i < allowingDeviceStatuses.size() - 1) {
+ deviceFilters.append(",");
+ }
+ }
+
+ StringBuilder sql = new StringBuilder("SELECT e.DEVICE_ID, e.OWNER, e.STATUS, e.DEVICE_TYPE, e.DEVICE_IDENTIFICATION " +
+ "FROM DM_ENROLMENT e " +
+ "JOIN DM_DEVICE d ON e.DEVICE_ID = d.ID " +
+ "WHERE e.TENANT_ID = ? AND e.STATUS IN (" + deviceFilters.toString() + ")");
+
+ if (deviceTypeId != 0) {
+ sql.append(" AND d.DEVICE_TYPE_ID = ?");
+ }
+ if (deviceOwner != null && !deviceOwner.isEmpty()) {
+ sql.append(" AND e.OWNER LIKE ?");
+ }
+ if (deviceStatus != null && !deviceStatus.isEmpty()) {
+ sql.append(" AND e.STATUS = ?");
+ }
+
+ Connection conn = null;
+
+ try {
+ conn = this.getConnection();
+ try (PreparedStatement stmt = conn.prepareStatement(sql.toString())) {
+ int index = 1;
+ stmt.setInt(index++, tenantId);
+ for (String status : allowingDeviceStatuses) {
+ stmt.setString(index++, status);
+ }
+ if (deviceTypeId != 0) {
+ stmt.setInt(index++, deviceTypeId);
+ }
+
+ if (deviceOwner != null && !deviceOwner.isEmpty()) {
+ stmt.setString(index++, "%" + deviceOwner + "%");
+ }
+ if (deviceStatus != null && !deviceStatus.isEmpty()) {
+ stmt.setString(index++, deviceStatus);
+ }
+
+ try (ResultSet rs = stmt.executeQuery()) {
+ while (rs.next()) {
+ DeviceDetailsDTO device = new DeviceDetailsDTO();
+ device.setDeviceId(rs.getInt("DEVICE_ID"));
+ device.setOwner(rs.getString("OWNER"));
+ device.setStatus(rs.getString("STATUS"));
+ device.setType(rs.getString("DEVICE_TYPE"));
+ device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION"));
+ devices.add(device);
+ }
+ }
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while retrieving devices for tenant ID: " + tenantId;
+ log.error(msg, e);
+ throw new DeviceManagementDAOException(msg, e);
+ }
+ return devices;
+ }
+
}
diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java
index 374c1ca0aa..518919add1 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java
@@ -26,6 +26,7 @@ import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.GroupPaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup;
+import io.entgra.device.mgt.core.device.mgt.core.dto.GroupDetailsDTO;
import io.entgra.device.mgt.core.device.mgt.core.dao.GroupDAO;
import io.entgra.device.mgt.core.device.mgt.core.dao.GroupManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.dao.GroupManagementDAOFactory;
@@ -164,7 +165,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
}
} catch (SQLException e) {
String msg = "Error occurred while retrieving groups of groups IDs " + deviceGroupIds.toString()
- + " in tenant: " + tenantId;
+ + " in tenant: " + tenantId;
log.error(msg);
throw new GroupManagementDAOException(msg, e);
}
@@ -184,7 +185,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
for (int i = 0; i < deviceGroupIdsCount; i++) {
sql += (deviceGroupIdsCount - 1 != i) ? "?," : "?";
}
- sql += ")";
+ sql += ")";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
int paramIndex = 1;
stmt.setInt(paramIndex++, tenantId);
@@ -202,7 +203,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
}
} catch (SQLException e) {
String msg = "Error occurred while retrieving groups of groups IDs " + deviceGroupIds
- + " in tenant: " + tenantId;
+ + " in tenant: " + tenantId;
log.error(msg);
throw new GroupManagementDAOException(msg, e);
}
@@ -227,7 +228,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
sql += " AND OWNER LIKE ?";
}
if (StringUtils.isNotBlank(request.getParentPath())) {
- if(isWithParentPath){
+ if (isWithParentPath) {
sql += " AND PARENT_PATH LIKE ?";
}
}
@@ -250,7 +251,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
stmt.setString(paramIndex++, request.getOwner() + "%");
}
if (StringUtils.isNotBlank(request.getParentPath())) {
- if(isWithParentPath){
+ if (isWithParentPath) {
stmt.setString(paramIndex++, request.getParentPath());
}
}
@@ -271,7 +272,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
}
} catch (SQLException e) {
String msg = "Error occurred while retrieving groups of groups IDs " + deviceGroupIds.toString()
- + " in tenant: " + tenantId;
+ + " in tenant: " + tenantId;
log.error(msg);
throw new GroupManagementDAOException(msg, e);
}
@@ -484,7 +485,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
Connection conn = GroupManagementDAOFactory.getConnection();
String sql = "UPDATE DM_GROUP SET DESCRIPTION = ?, GROUP_NAME = ?, OWNER = ?, STATUS = ?, "
+ "PARENT_PATH = ?, PARENT_GROUP_ID = ? WHERE ID = ? AND TENANT_ID = ?";
- try (PreparedStatement stmt = conn.prepareStatement(sql)){
+ try (PreparedStatement stmt = conn.prepareStatement(sql)) {
for (DeviceGroup deviceGroup : deviceGroups) {
stmt.setString(1, deviceGroup.getDescription());
stmt.setString(2, deviceGroup.getName());
@@ -609,6 +610,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
throw new GroupManagementDAOException(msg, e);
}
}
+
@Override
public void deleteGroups(List groupIds, int tenantId) throws GroupManagementDAOException {
try {
@@ -1166,7 +1168,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
if (StringUtils.isNotBlank(parentPath)) {
sql += " AND g.PARENT_PATH = ? ";
}
- sql += "GROUP BY g.ID";
+ sql += "GROUP BY g.ID";
stmt = conn.prepareStatement(sql);
int index = 0;
while (index++ < rolesCount) {
@@ -1279,11 +1281,11 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
return devices;
}
Connection conn = GroupManagementDAOFactory.getConnection();
- StringJoiner joiner = new StringJoiner(",","SELECT "
+ StringJoiner joiner = new StringJoiner(",", "SELECT "
+ "d1.DEVICE_ID, "
+ "d1.DESCRIPTION, "
- + "e.DEVICE_NAME, "
- + "d1.DEVICE_TYPE, "
+ + "d1.NAME AS DEVICE_NAME, "
+ + "e.DEVICE_TYPE, "
+ "d1.DEVICE_IDENTIFICATION, "
+ "d1.LAST_UPDATED_TIMESTAMP, "
+ "e.OWNER, "
@@ -1343,8 +1345,8 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
String sql = "SELECT "
+ "d1.DEVICE_ID, "
+ "d1.DESCRIPTION, "
- + "e.DEVICE_NAME, "
- + "d1.DEVICE_TYPE, "
+ + "d1.NAME AS DEVICE_NAME, "
+ + "e.DEVICE_TYPE, "
+ "d1.DEVICE_IDENTIFICATION, "
+ "d1.LAST_UPDATED_TIMESTAMP, "
+ "e.OWNER, "
@@ -1437,4 +1439,149 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
}
return groupUnassignedDeviceList;
}
+
+ @Override
+ public GroupDetailsDTO getGroupDetailsWithDevices(String groupName, List allowedStatuses, int deviceTypeId, int tenantId,
+ String deviceOwner, String deviceName, String deviceStatus, int offset, int limit)
+ throws GroupManagementDAOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Request received in DAO Layer to get group details and device IDs for group: " + groupName);
+ }
+ GroupDetailsDTO groupDetails = new GroupDetailsDTO();
+ List deviceIds = new ArrayList<>();
+ Map deviceOwners = new HashMap<>();
+ Map