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 f8b502236c..c0c72a2f65 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
@@ -123,7 +123,6 @@
io.entgra.device.mgt.core
io.entgra.device.mgt.core.apimgt.extension.rest.api
- provided
org.json.wso2
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 c9297ee7c3..f7655b566b 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
@@ -517,4 +517,12 @@ public interface ApplicationManager {
String getPlistArtifact(String uuid) throws ApplicationManagementException;
List getReleaseByPackageNames(List packageIds) throws ApplicationManagementException;
+
+ /**
+ * @param applicationRelease {@link ApplicationRelease}
+ * @param oldPackageName Old package name of the application
+ * @throws ApplicationManagementException Application management exception
+ */
+ void updateAppIconInfo(ApplicationRelease applicationRelease, String oldPackageName)
+ throws ApplicationManagementException;
}
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 a55ef8cc2c..9a50d0d00a 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
@@ -1243,6 +1243,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
applicationDTO.setId(appId);
applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
+ if (applicationDTO.getType().equals("ENTERPRISE") || applicationDTO.getType().equals("PUBLIC") ) {
+ persistAppIconInfo(applicationReleaseDTO);
+ }
return APIUtil.appDtoToAppResponse(applicationDTO);
}
} catch (LifeCycleManagementDAOException e) {
@@ -1269,6 +1272,30 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
+ /**
+ * Persist application icon information when creating an application
+ *
+ * @param applicationReleaseDTO {@link ApplicationReleaseDTO}
+ * @throws ApplicationManagementException if error occurred while persisting application icon information
+ */
+ private void persistAppIconInfo(ApplicationReleaseDTO applicationReleaseDTO)
+ throws ApplicationManagementException {
+ try {
+ int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
+ String iconPath = APIUtil.createAppIconPath(applicationReleaseDTO, tenantId);
+ DataHolder.getInstance().getDeviceManagementService().saveApplicationIcon(iconPath,
+ String.valueOf(applicationReleaseDTO.getPackageName()), applicationReleaseDTO.getVersion(), tenantId);
+ } catch (ApplicationManagementException e) {
+ String msg = "Error occurred while creating iconPath. Application package name : " + applicationReleaseDTO.getPackageName();
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while saving application icon info. Application package name : " + applicationReleaseDTO.getPackageName();
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ }
+ }
+
@Override
public ApplicationRelease createRelease(ApplicationDTO applicationDTO, ApplicationReleaseDTO applicationReleaseDTO,
ApplicationType type, boolean isPublished)
@@ -1874,6 +1901,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
break;
}
}
+ try {
+ deleteAppIconInfo(applicationDTO);
+ } catch (ApplicationManagementException e) {
+ String msg = "Error occurred while deleting application icon info. Application package name: " + applicationDTO.getPackageName();
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ }
}
@Override
@@ -3978,4 +4012,32 @@ public class ApplicationManagerImpl implements ApplicationManager {
ConnectionManagerUtil.closeDBConnection();
}
}
+
+ @Override
+ public void updateAppIconInfo(ApplicationRelease applicationRelease, String oldPackageName) throws ApplicationManagementException {
+ try {
+ DataHolder.getInstance().getDeviceManagementService().updateApplicationIcon(applicationRelease.getIconPath(),
+ oldPackageName, applicationRelease.getPackageName(), applicationRelease.getVersion());
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while updating application icon info. Application package name: " + oldPackageName;
+ log.error(msg, e);
+ throw new ApplicationManagementException(msg, e);
+ }
+ }
+
+ /**
+ * Delete application icon information when deleting an application
+ *
+ * @param applicationDTO {@link ApplicationDTO}
+ * @throws ApplicationManagementException if error occurred while deleting application icon information
+ */
+ private void deleteAppIconInfo(ApplicationDTO applicationDTO) throws ApplicationManagementException {
+ try {
+ DataHolder.getInstance().getDeviceManagementService().deleteApplicationIcon(applicationDTO.getPackageName());
+ } catch (DeviceManagementException e) {
+ String msg = "Error occurred while deleting application icon info. Application package name: " + applicationDTO.getPackageName();
+ 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/util/APIUtil.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/APIUtil.java
index 27917680e1..4b78b9e1c2 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/APIUtil.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/APIUtil.java
@@ -503,4 +503,18 @@ public class APIUtil {
return mdmConfig.getArtifactDownloadProtocol() + "://" + host + ":" + port
+ artifactDownloadEndpoint + Constants.FORWARD_SLASH;
}
+
+ /**
+ * To create the application icon path.
+ *
+ * @param applicationReleaseDTO {@link ApplicationReleaseDTO}
+ * @param tenantId tenant ID
+ * @return iconPath constructed icon path.
+ */
+ public static String createAppIconPath(ApplicationReleaseDTO applicationReleaseDTO, int tenantId) throws ApplicationManagementException {
+ String basePath = getArtifactDownloadBaseURL() + tenantId + Constants.FORWARD_SLASH + applicationReleaseDTO
+ .getAppHashValue() + Constants.FORWARD_SLASH;
+ String iconPath = basePath + Constants.ICON_ARTIFACT + Constants.FORWARD_SLASH + applicationReleaseDTO.getIconName();
+ return iconPath;
+ }
}
diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.publisher.api/src/main/java/io/entgra/device/mgt/core/application/mgt/publisher/api/impl/ApplicationManagementPublisherAPIImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.publisher.api/src/main/java/io/entgra/device/mgt/core/application/mgt/publisher/api/impl/ApplicationManagementPublisherAPIImpl.java
index 57bd381f71..606e66fd0a 100644
--- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.publisher.api/src/main/java/io/entgra/device/mgt/core/application/mgt/publisher/api/impl/ApplicationManagementPublisherAPIImpl.java
+++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.publisher.api/src/main/java/io/entgra/device/mgt/core/application/mgt/publisher/api/impl/ApplicationManagementPublisherAPIImpl.java
@@ -512,6 +512,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
+ String oldPackageName = applicationManager.getApplicationByUuid(applicationUUID).getPackageName();
+ applicationManager.updateAppIconInfo(applicationRelease, oldPackageName);
return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
@@ -552,6 +554,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
+ String oldPackageName = applicationManager.getApplicationByUuid(applicationUUID).getPackageName();
+ applicationManager.updateAppIconInfo(applicationRelease, oldPackageName);
return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (BadRequestException e) {
String msg = e.getMessage();
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 e11ff4c033..deb3d4c8bb 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
@@ -898,6 +898,24 @@ public interface PolicyManagementService {
response = ErrorResponse.class)
})
Response getPolicyList(
+ @ApiParam(
+ name = "name",
+ value = "The name of the policy that needs filtering.",
+ required = false)
+ @QueryParam("name")
+ String name,
+ @ApiParam(
+ name = "type",
+ value = "The type of the policy that needs filtering.",
+ required = false)
+ @QueryParam("type")
+ String type,
+ @ApiParam(
+ name = "status",
+ value = "The status of the policy that needs filtering.",
+ required = false)
+ @QueryParam("status")
+ String status,
@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/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 11f5a7e505..fb16a529e4 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
@@ -17,6 +17,22 @@
*/
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl;
+import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
+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.DeviceIdentifier;
+import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
+import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
+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.core.internal.DeviceManagementDataHolder;
+import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ErrorResponse;
+import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.PolicyList;
+import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.PolicyWrapper;
+import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.PriorityUpdatedPolicyWrapper;
+import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ProfileFeature;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.*;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.PolicyManagementService;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.util.FilteringUtil;
@@ -477,6 +493,9 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
@Path("/list")
@Override
public Response getPolicyList(
+ @QueryParam("name") String name,
+ @QueryParam("type") String type,
+ @QueryParam("status") String status,
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("offset") int offset,
@QueryParam("limit") int limit) {
@@ -484,7 +503,16 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
List policies;
PolicyList targetPolicies = new PolicyList();
- PaginationRequest request = new PaginationRequest(offset, limit);
+ PolicyPaginationRequest request = new PolicyPaginationRequest(offset, limit);
+ if (name != null){
+ request.setName(name);
+ }
+ if (type != null){
+ request.setType(type);
+ }
+ if (status != null){
+ request.setStatus(status);
+ }
try {
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
policies = policyAdministratorPoint.getPolicyList(request);
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
new file mode 100644
index 0000000000..8a0a2f3bd4
--- /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/PolicyPaginationRequest.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2018 - 2023, Entgra (pvt) Ltd. (https://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;
+
+public class PolicyPaginationRequest {
+ private int startIndex;
+ private int rowCount;
+ private String name;
+ private String type;
+ private String status;
+
+ public PolicyPaginationRequest(int start, int rowCount) {
+ this.startIndex = start;
+ this.rowCount = rowCount;
+ }
+
+ public int getStartIndex() {
+ return startIndex;
+ }
+
+ public void setStartIndex(int startIndex) {
+ this.startIndex = startIndex;
+ }
+
+ public int getRowCount() {
+ return rowCount;
+ }
+
+ public void setRowCount(int rowCount) {
+ this.rowCount = rowCount;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ @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.core/pom.xml b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/pom.xml
index bb971666f9..ae8e99a83d 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
@@ -509,6 +509,18 @@
io.entgra.device.mgt.core.notification.logger
provided
+
+ org.wso2.orbit.javax.xml.bind
+ jaxb-api
+ 2.3.1.wso2v1
+ compile
+
+
+ org.wso2.orbit.javax.xml.bind
+ jaxb-api
+ 2.3.1.wso2v1
+ compile
+
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/ApplicationDAO.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/ApplicationDAO.java
index 3faf61f30b..9aa311ec57 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/ApplicationDAO.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/ApplicationDAO.java
@@ -62,4 +62,55 @@ public interface ApplicationDAO {
* @throws DeviceManagementDAOException If any database error occured
*/
List getAppVersions(int tenantId, String packageName) throws DeviceManagementDAOException;
+
+ /**
+ * This method is used to save application icon information.
+ * @param iconPath Icon path of the application
+ * @param packageName Package name of the application
+ * @param version version of the application
+ * @throws DeviceManagementDAOException If any database error occurred
+ */
+ void saveApplicationIcon(String iconPath, String packageName, String version, int tenantId) throws DeviceManagementDAOException;
+
+ /**
+ * This method is used to check the package existence.
+ * @param packageName Package name of the application
+ * @throws DeviceManagementDAOException If any database error occurred
+ */
+ int getApplicationPackageCount(String packageName) throws DeviceManagementDAOException;
+
+ /**
+ * This method is used to update application icon information.
+ * @param iconPath Icon path of the application
+ * @param oldPackageName Old package name of the application
+ * @param newPackageName New package name of the application
+ * @param version Version of the application
+ * @throws DeviceManagementDAOException If any database error occurred
+ */
+ void updateApplicationIcon(String iconPath, String oldPackageName, String newPackageName, String version) throws DeviceManagementDAOException;
+
+ /**
+ * This method is used to delete application icon information.
+ * @param packageName Package name of the application
+ * @throws DeviceManagementDAOException If any database error occurred
+ */
+ void deleteApplicationIcon(String packageName) throws DeviceManagementDAOException;
+
+ /**
+ * This method is used to get the installed application list of a specific device
+ * @param deviceId ID of the device
+ * @param enrolmentId Enrolment ID of the device
+ * @param tenantId tenant ID
+ * @throws DeviceManagementDAOException If any database error occurred
+ */
+ List getInstalledApplicationListOnDevice(int deviceId, int enrolmentId, int offset, int limit, int tenantId)
+ throws DeviceManagementDAOException;
+
+ /**
+ * This method is used to retrieve the icon info of an installed app in device.
+ * @param applicationIdentifier application identifier.
+ * @return returns the application icon path.
+ * @throws DeviceManagementDAOException
+ */
+ String getIconPath(String applicationIdentifier) 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/EventManagementDAOFactory.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/EventManagementDAOFactory.java
index dc2abfe0d0..b610a3e8f4 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/EventManagementDAOFactory.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/EventManagementDAOFactory.java
@@ -26,6 +26,7 @@ import io.entgra.device.mgt.core.device.mgt.core.config.datasource.DataSourceCon
import io.entgra.device.mgt.core.device.mgt.core.config.datasource.JNDILookupDefinition;
import io.entgra.device.mgt.core.device.mgt.core.dao.impl.event.GenericEventConfigDAOImpl;
import io.entgra.device.mgt.core.device.mgt.core.dao.impl.event.H2EventConfigDAOImpl;
+import io.entgra.device.mgt.core.device.mgt.core.dao.impl.event.SQLServerEventConfigDAOImpl;
import io.entgra.device.mgt.core.device.mgt.core.dao.impl.geofence.GenericGeofenceDAOImpl;
import io.entgra.device.mgt.core.device.mgt.core.dao.impl.geofence.SQLServerGeofenceDAOImpl;
import io.entgra.device.mgt.core.device.mgt.core.dao.util.DeviceManagementDAOUtil;
@@ -68,6 +69,7 @@ public class EventManagementDAOFactory {
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_POSTGRESQL:
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_ORACLE:
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MSSQL:
+ return new SQLServerEventConfigDAOImpl();
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL:
return new GenericEventConfigDAOImpl();
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2:
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/ApplicationDAOImpl.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/ApplicationDAOImpl.java
index 655ee846bf..56ab396c4b 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/ApplicationDAOImpl.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/ApplicationDAOImpl.java
@@ -33,7 +33,9 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.sql.Timestamp;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
import java.util.Properties;
@@ -393,4 +395,178 @@ public class ApplicationDAOImpl implements ApplicationDAO {
return application;
}
+ @Override
+ public void saveApplicationIcon(String iconPath, String packageName, String version, int tenantId)
+ throws DeviceManagementDAOException{
+ Connection conn;
+ String sql = "INSERT INTO DM_APP_ICONS " +
+ "(ICON_PATH, " +
+ "PACKAGE_NAME, " +
+ "VERSION, " +
+ "CREATED_TIMESTAMP, " +
+ "TENANT_ID) " +
+ "VALUES (?, ?, ?, ?, ?)";
+ try {
+ conn = this.getConnection();
+ try (PreparedStatement stmt = conn.prepareStatement(sql)) {
+ stmt.setString(1,iconPath);
+ stmt.setString(2,packageName);
+ stmt.setString(3,version);
+ stmt.setTimestamp(4, new Timestamp(new Date().getTime()));
+ stmt.setInt(5, tenantId);
+ stmt.executeUpdate();
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while saving application icon details";
+ log.error(msg, e);
+ throw new DeviceManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public int getApplicationPackageCount(String packageName) throws DeviceManagementDAOException{
+ Connection conn;
+ String sql = "SELECT " +
+ "COUNT(*) AS APP_PACKAGE_COUNT " +
+ "FROM DM_APP_ICONS " +
+ "WHERE PACKAGE_NAME = ?";
+ try {
+ conn = this.getConnection();
+ try (PreparedStatement stmt = conn.prepareStatement(sql)) {
+ stmt.setString(1, packageName);
+ try (ResultSet rs = stmt.executeQuery()) {
+ if (rs.next()) {
+ return rs.getInt("APP_PACKAGE_COUNT");
+ }
+ return 0;
+ }
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while getting application icon details";
+ log.error(msg, e);
+ throw new DeviceManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public void updateApplicationIcon(String iconPath, String oldPackageName, String newPackageName, String version)
+ throws DeviceManagementDAOException{
+ Connection conn;
+ String sql = "UPDATE DM_APP_ICONS " +
+ "SET " +
+ "ICON_PATH= ?, " +
+ "PACKAGE_NAME = ?, " +
+ "VERSION = ? " +
+ "WHERE PACKAGE_NAME = ?";
+ try {
+ conn = this.getConnection();
+ try (PreparedStatement stmt = conn.prepareStatement(sql)) {
+ stmt.setString(1,iconPath);
+ stmt.setString(2,newPackageName);
+ stmt.setString(3,version);
+ stmt.setString(4,oldPackageName);
+ stmt.executeUpdate();
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while updating application icon details";
+ log.error(msg, e);
+ throw new DeviceManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public void deleteApplicationIcon(String packageName) throws DeviceManagementDAOException {
+ Connection conn;
+ String sql = "DELETE " +
+ "FROM DM_APP_ICONS " +
+ "WHERE PACKAGE_NAME = ?";
+ try {
+ conn = this.getConnection();
+ try (PreparedStatement stmt = conn.prepareStatement(sql)) {
+ stmt.setString(1, packageName);
+ stmt.executeUpdate();
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while deleting application icon details";
+ log.error(msg, e);
+ throw new DeviceManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public String getIconPath(String applicationIdentifier) throws DeviceManagementDAOException{
+ Connection conn;
+ String sql = "SELECT " +
+ "ICON_PATH " +
+ "FROM DM_APP_ICONS " +
+ "WHERE PACKAGE_NAME = ?";
+ String iconPath = null;
+ try {
+ conn = this.getConnection();
+ try (PreparedStatement stmt = conn.prepareStatement(sql)) {
+ stmt.setString(1,applicationIdentifier);
+ try (ResultSet rs = stmt.executeQuery()) {
+ if (rs.next()) {
+ iconPath = rs.getString("ICON_PATH");
+ }
+ return iconPath;
+ }
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while retrieving app icon path of the application";
+ log.error(msg, e);
+ throw new DeviceManagementDAOException(msg, e);
+ }
+ }
+
+ @Override
+ public List getInstalledApplicationListOnDevice(int deviceId, int enrolmentId, int offset, int limit, int tenantId)
+ throws DeviceManagementDAOException {
+ Connection conn;
+ List applicationList = new ArrayList<>();
+ Application application;
+ String sql = "SELECT " +
+ "ID, " +
+ "NAME, " +
+ "APP_IDENTIFIER, " +
+ "PLATFORM, " +
+ "CATEGORY, " +
+ "VERSION, " +
+ "TYPE, " +
+ "LOCATION_URL, " +
+ "IMAGE_URL, " +
+ "APP_PROPERTIES, " +
+ "MEMORY_USAGE, " +
+ "IS_ACTIVE, " +
+ "TENANT_ID " +
+ "FROM DM_APPLICATION " +
+ "WHERE DEVICE_ID = ? AND " +
+ "ENROLMENT_ID = ? AND " +
+ "TENANT_ID = ? " +
+ "LIMIT ? " +
+ "OFFSET ?";
+ try {
+ conn = this.getConnection();
+ try (PreparedStatement stmt = conn.prepareStatement(sql)) {
+ stmt.setInt(1, deviceId);
+ stmt.setInt(2, enrolmentId);
+ stmt.setInt(3, tenantId);
+ stmt.setInt(4, limit);
+ stmt.setInt(5, offset);
+ try (ResultSet rs = stmt.executeQuery()) {
+ while (rs.next()) {
+ application = loadApplication(rs);
+ applicationList.add(application);
+ }
+ }
+ }
+
+ } catch (SQLException e) {
+ String msg = "SQL Error occurred while retrieving the list of Applications " +
+ "installed in device id '" + deviceId;
+ log.error(msg, e);
+ throw new DeviceManagementDAOException(msg, e);
+ }
+ return applicationList;
+ }
}
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/event/SQLServerEventConfigDAOImpl.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/event/SQLServerEventConfigDAOImpl.java
new file mode 100644
index 0000000000..8eedceb4d9
--- /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/dao/impl/event/SQLServerEventConfigDAOImpl.java
@@ -0,0 +1,82 @@
+/*
+ * 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.dao.impl.event;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import io.entgra.device.mgt.core.device.mgt.common.event.config.EventConfig;
+import io.entgra.device.mgt.core.device.mgt.core.dao.EventManagementDAOException;
+import io.entgra.device.mgt.core.device.mgt.core.dao.EventManagementDAOFactory;
+import io.entgra.device.mgt.core.device.mgt.core.dao.impl.AbstractEventConfigDAO;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Calendar;
+
+public class SQLServerEventConfigDAOImpl extends AbstractEventConfigDAO {
+ private static final Log log = LogFactory.getLog(SQLServerEventConfigDAOImpl.class);
+
+ @Override
+ public List storeEventRecords(List eventConfigList, int tenantId) throws EventManagementDAOException {
+ try {
+ Calendar calendar = Calendar.getInstance();
+ Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
+ Connection conn = this.getConnection();
+ String sql = "INSERT INTO DM_DEVICE_EVENT(" +
+ "EVENT_SOURCE, " +
+ "EVENT_LOGIC, " +
+ "ACTIONS, "+
+ "CREATED_TIMESTAMP, " +
+ "TENANT_ID) " +
+ "VALUES (?, ?, ?, ?, ?)";
+ List generatedIds = new ArrayList<>();
+ try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
+ for (EventConfig eventConfig : eventConfigList) {
+ stmt.setString(1, eventConfig.getEventSource());
+ stmt.setString(2, eventConfig.getEventLogic());
+ stmt.setString(3, eventConfig.getActions());
+ stmt.setTimestamp(4, timestamp);
+ stmt.setInt(5, tenantId);
+ stmt.executeUpdate();
+
+ try (ResultSet generatedKeys = stmt.getGeneratedKeys()) {
+ if (generatedKeys.next()) {
+ generatedIds.add(generatedKeys.getInt(1));
+ }
+ }
+ }
+ }
+ return generatedIds;
+ } catch (SQLException e) {
+ String msg = "Error occurred while creating event configurations for the tenant id " + tenantId;
+ log.error(msg, e);
+ throw new EventManagementDAOException(msg, e);
+ }
+ }
+
+ private Connection getConnection() throws SQLException {
+ return EventManagementDAOFactory.getConnection();
+ }
+}
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/geofence/SQLServerGeofenceDAOImpl.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/geofence/SQLServerGeofenceDAOImpl.java
index d26f016898..fa04264286 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/geofence/SQLServerGeofenceDAOImpl.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/geofence/SQLServerGeofenceDAOImpl.java
@@ -18,21 +18,24 @@
package io.entgra.device.mgt.core.device.mgt.core.dao.impl.geofence;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import io.entgra.device.mgt.core.device.mgt.common.DeviceManagementConstants;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.geo.service.GeofenceData;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.dao.EventManagementDAOFactory;
import io.entgra.device.mgt.core.device.mgt.core.dao.impl.AbstractGeofenceDAOImpl;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.context.CarbonContext;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
public class SQLServerGeofenceDAOImpl extends AbstractGeofenceDAOImpl {
private static final Log log = LogFactory.getLog(SQLServerGeofenceDAOImpl.class);
@@ -106,4 +109,61 @@ public class SQLServerGeofenceDAOImpl extends AbstractGeofenceDAOImpl {
}
return geofenceDataList;
}
+
+ @Override
+ public GeofenceData getGeofence(int fenceId, boolean requireGroupData) throws DeviceManagementDAOException {
+ if (!requireGroupData) {
+ return getGeofence(fenceId);
+ }
+ int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
+ try {
+ Connection con = this.getConnection();
+ String sql = "SELECT " +
+ "G.ID AS FENCE_ID, " +
+ "FENCE_NAME, " +
+ "G.DESCRIPTION, " +
+ "LATITUDE, " +
+ "LONGITUDE, " +
+ "RADIUS, " +
+ "GEO_JSON, " +
+ "FENCE_SHAPE, " +
+ "M.GROUP_ID AS GROUP_ID, " +
+ "GR.GROUP_NAME " +
+ "FROM DM_GEOFENCE G, DM_GEOFENCE_GROUP_MAPPING M, DM_GROUP GR " +
+ "WHERE G.ID = M.FENCE_ID " +
+ "AND M.GROUP_ID = GR.ID " +
+ "AND G.ID = ? " +
+ "AND G.TENANT_ID = ?";
+ try (PreparedStatement stmt = con.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)) {
+ stmt.setInt(1, fenceId);
+ stmt.setInt(2, tenantId);
+ try (ResultSet rst = stmt.executeQuery()) {
+ Map groupMap = new HashMap<>();
+ GeofenceData geofenceData = null;
+ while (rst.next()) {
+ groupMap.put(rst.getInt("GROUP_ID"), rst.getString("GROUP_NAME"));
+ }
+ if (!groupMap.isEmpty()) {
+ rst.beforeFirst();
+ rst.next();
+ geofenceData = new GeofenceData();
+ geofenceData.setId(rst.getInt("FENCE_ID"));
+ geofenceData.setFenceName(rst.getString("FENCE_NAME"));
+ geofenceData.setDescription(rst.getString("DESCRIPTION"));
+ geofenceData.setLatitude(rst.getDouble("LATITUDE"));
+ geofenceData.setLongitude(rst.getDouble("LONGITUDE"));
+ geofenceData.setRadius(rst.getFloat("RADIUS"));
+ geofenceData.setGeoJson(rst.getString("GEO_JSON"));
+ geofenceData.setFenceShape(rst.getString("FENCE_SHAPE"));
+ geofenceData.setGroupData(groupMap);
+ }
+ return geofenceData;
+ }
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while retrieving Geo fence data " + fenceId;
+ log.error(msg, e);
+ throw new DeviceManagementDAOException(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/service/DeviceManagementProviderService.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderService.java
index 2e5d1c8f72..1b3d57f171 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderService.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderService.java
@@ -18,6 +18,8 @@
package io.entgra.device.mgt.core.device.mgt.core.service;
+import io.entgra.device.mgt.core.device.mgt.common.app.mgt.Application;
+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.app.mgt.ApplicationManagementException;
import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.*;
@@ -43,6 +45,7 @@ import org.apache.commons.collections.map.SingletonMap;
import java.sql.SQLException;
import java.sql.Timestamp;
+import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -1007,4 +1010,42 @@ public interface DeviceManagementProviderService {
throws DeviceManagementException;
Boolean sendDeviceNameChangedNotification(Device device) throws DeviceManagementException;
+
+ /**
+ * This method is for saving application icon info
+ * @param iconPath Icon path of the application
+ * @param packageName Package name of the application
+ * @param version Version of the application
+ * @param tenantId Tenant ID of the application created user
+ * @throws DeviceManagementException if any service level or DAO level error occurs
+ */
+ void saveApplicationIcon(String iconPath, String packageName, String version, int tenantId)
+ throws DeviceManagementException;
+
+ /**
+ * This method is for updating application icon info
+ * @param iconPath Icon path of the application
+ * @param oldPackageName Old package name of the application
+ * @param newPackageName New package name of the application
+ * @param version Version of the application
+ * @throws DeviceManagementException if any service level or DAO level error occurs
+ */
+ void updateApplicationIcon(String iconPath, String oldPackageName, String newPackageName, String version)
+ throws DeviceManagementException;
+
+ /**
+ * This method is for deleting application icon info
+ * @param packageName Package name of the application
+ * @throws DeviceManagementException if any service level or DAO level error occurs
+ */
+ void deleteApplicationIcon(String packageName) throws DeviceManagementException;
+
+ /**
+ * This method is for getting the installed application list of a device
+ * @param device {@link Device}
+ * @return list of applications {@link Application}
+ * @throws DeviceManagementException if any service level or DAO level error occurs
+ */
+ List getInstalledApplicationsOnDevice(Device device, int offset, int limit)
+ 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/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java
index 1c8c67a3bc..02d6b010eb 100644
--- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java
+++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java
@@ -4844,4 +4844,130 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
throw new DeviceManagementException(msg, e);
}
}
+
+ @Override
+ public void saveApplicationIcon(String iconPath, String packageName, String version, int tenantId) throws DeviceManagementException{
+ try{
+ DeviceManagementDAOFactory.beginTransaction();
+ if(applicationDAO.getApplicationPackageCount(packageName) == 0){
+ applicationDAO.saveApplicationIcon(iconPath, packageName, version, tenantId);
+ }
+ DeviceManagementDAOFactory.commitTransaction();
+ } catch (TransactionManagementException e) {
+ String msg = "Error occurred while initiating transaction";
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
+ } catch (DeviceManagementDAOException e) {
+ DeviceManagementDAOFactory.rollbackTransaction();
+ String msg = "Error occurred while saving app icon. Icon Path: " + iconPath +
+ " Package Name: " + packageName +
+ " Version: " + version +
+ " Tenant Id: " + tenantId;
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
+ } finally {
+ DeviceManagementDAOFactory.closeConnection();
+ }
+ }
+
+ @Override
+ public void updateApplicationIcon(String iconPath, String oldPackageName, String newPackageName, String version)
+ throws DeviceManagementException{
+ try {
+ DeviceManagementDAOFactory.beginTransaction();
+ applicationDAO.updateApplicationIcon(iconPath, oldPackageName, newPackageName, version);
+ DeviceManagementDAOFactory.commitTransaction();
+ } catch (TransactionManagementException e) {
+ String msg = "Error occurred while initiating transaction";
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
+ } catch (DeviceManagementDAOException e) {
+ DeviceManagementDAOFactory.rollbackTransaction();
+ String msg = "Error occurred while updating app icon info." +
+ " Package Name: " + oldPackageName;
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
+ } finally {
+ DeviceManagementDAOFactory.closeConnection();
+ }
+ }
+
+ @Override
+ public void deleteApplicationIcon(String packageName)
+ throws DeviceManagementException {
+ try {
+ DeviceManagementDAOFactory.beginTransaction();
+ applicationDAO.deleteApplicationIcon(packageName);
+ DeviceManagementDAOFactory.commitTransaction();
+ } catch (TransactionManagementException e) {
+ String msg = "Error occurred while initiating transaction";
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
+ } catch (DeviceManagementDAOException e) {
+ DeviceManagementDAOFactory.rollbackTransaction();
+ String msg = "Error occurred while deleting app icon info." +
+ " Package Name: " + packageName ;
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
+ } finally {
+ DeviceManagementDAOFactory.closeConnection();
+ }
+ }
+
+ private List getInstalledAppIconInfo(List applications) throws DeviceManagementException {
+ String iconPath;
+ try {
+ DeviceManagementDAOFactory.openConnection();
+ for (Application app : applications) {
+ iconPath = applicationDAO.getIconPath(app.getApplicationIdentifier());
+ app.setImageUrl(iconPath);
+ }
+ } catch (DeviceManagementDAOException e) {
+ String msg = "Error occurred while retrieving installed app icon info";
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
+ } catch (SQLException e) {
+ String msg = "Error occurred while opening a connection to the data source";
+ log.error(msg);
+ throw new DeviceManagementException(msg, e);
+ } finally {
+ DeviceManagementDAOFactory.closeConnection();
+ }
+ return applications;
+ }
+
+ @Override
+ public List getInstalledApplicationsOnDevice(Device device, int offset, int limit) throws DeviceManagementException {
+ List applications;
+ try {
+ DeviceManagementDAOFactory.openConnection();
+ int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
+ applications = applicationDAO.getInstalledApplicationListOnDevice(device.getId(),
+ device.getEnrolmentInfo().getId(), offset, limit, tenantId);
+ if (applications == null) {
+ String msg = "Couldn't found applications for device identifier '" + device.getId() + "'";
+ log.error(msg);
+ throw new DeviceManagementException(msg);
+ }
+ } catch (DeviceManagementDAOException e) {
+ String msg = "Error occurred while retrieving the application list of android device, " +
+ "which carries the id '" + device.getId() + "'";
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
+ } catch (SQLException e) {
+ String msg = "Error occurred while opening a connection to the data source";
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
+ } finally {
+ DeviceManagementDAOFactory.closeConnection();
+ }
+ List newApplicationList;
+ newApplicationList = this.getInstalledAppIconInfo(applications);
+ if (newApplicationList == null) {
+ String msg = "Error occurred while getting app icon info for device identifier '" + device.getId() + "'";
+ log.error(msg);
+ throw new DeviceManagementException(msg);
+ }
+ return newApplicationList;
+ }
}
diff --git a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.common/src/main/java/io/entgra/device/mgt/core/policy/mgt/common/PolicyAdministratorPoint.java b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.common/src/main/java/io/entgra/device/mgt/core/policy/mgt/common/PolicyAdministratorPoint.java
index d32d328ed7..7101bc6c78 100644
--- a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.common/src/main/java/io/entgra/device/mgt/core/policy/mgt/common/PolicyAdministratorPoint.java
+++ b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.common/src/main/java/io/entgra/device/mgt/core/policy/mgt/common/PolicyAdministratorPoint.java
@@ -20,6 +20,7 @@ package io.entgra.device.mgt.core.policy.mgt.common;
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.PolicyPaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Profile;
@@ -167,10 +168,10 @@ public interface PolicyAdministratorPoint {
/**
* Returns a list of policies filtered by offset and limit
- * @param request {@link PaginationRequest} contains offset and limit
+ * @param request {@link PolicyPaginationRequest} contains offset and limit and filters
* @return {@link List} - list of policies for current tenant
* @throws PolicyManagementException when there is an error while retrieving the policies from database or
* while retrieving device groups
*/
- List getPolicyList(PaginationRequest request) throws PolicyManagementException;
+ List getPolicyList(PolicyPaginationRequest request) throws PolicyManagementException;
}
diff --git a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/dao/PolicyDAO.java b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/dao/PolicyDAO.java
index 86519d7238..f5d7f4c238 100644
--- a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/dao/PolicyDAO.java
+++ b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/dao/PolicyDAO.java
@@ -20,6 +20,7 @@ package io.entgra.device.mgt.core.policy.mgt.core.dao;
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.PolicyPaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.CorrectiveAction;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.DeviceGroupWrapper;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy;
@@ -202,9 +203,9 @@ public interface PolicyDAO {
/**
* This method is used to retrieve policies from the database based on the offset and limit
* sent through the PaginationRequest
- * @param request {@link PaginationRequest} contains offset and limit
+ * @param request {@link PolicyPaginationRequest} contains offset and limit and filters
* @return {@link List} - list of policies for current tenant
* @throws PolicyManagerDAOException when there is an error while retrieving the policies from database
*/
- List getAllPolicies(PaginationRequest request) throws PolicyManagerDAOException;
+ List getAllPolicies(PolicyPaginationRequest request) throws PolicyManagerDAOException;
}
diff --git a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/dao/impl/policy/GenericPolicyDAOImpl.java b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/dao/impl/policy/GenericPolicyDAOImpl.java
index ef26884feb..2e7b3aa87f 100644
--- a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/dao/impl/policy/GenericPolicyDAOImpl.java
+++ b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/dao/impl/policy/GenericPolicyDAOImpl.java
@@ -18,13 +18,14 @@
package io.entgra.device.mgt.core.policy.mgt.core.dao.impl.policy;
+import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
+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.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy;
import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagementDAOFactory;
import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagerDAOException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.context.PrivilegedCarbonContext;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -41,21 +42,57 @@ public class GenericPolicyDAOImpl extends AbstractPolicyDAOImpl {
}
@Override
- public List getAllPolicies(PaginationRequest request) throws PolicyManagerDAOException {
+ public List getAllPolicies(PolicyPaginationRequest request) throws PolicyManagerDAOException {
Connection conn;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ String name = request.getName();
+ String type = request.getType();
+ String status = request.getStatus();
+ int statusValue = 0;
+ boolean isPolicyNameProvided = false;
+ boolean isPolicyTypeProvided = false;
+ boolean isPolicyStatusProvided = false;
try {
conn = this.getConnection();
String query = "SELECT * " +
"FROM DM_POLICY " +
- "WHERE TENANT_ID = ? " +
- "ORDER BY ID LIMIT ?,?";
+ "WHERE TENANT_ID = ? ";
+
+ if (name != null && !name.isEmpty()) {
+ query += "AND NAME LIKE ? " ;
+ isPolicyNameProvided = true;
+ }
+
+ if (type != null && !type.isEmpty()) {
+ query += "AND POLICY_TYPE = ? " ;
+ isPolicyTypeProvided = true;
+ }
+
+ if (status != null && !status.isEmpty()) {
+ if (status.equals("ACTIVE")) {
+ statusValue = 1;
+ }
+ query += "AND ACTIVE = ? " ;
+ isPolicyStatusProvided = true;
+ }
+
+ query += "ORDER BY ID LIMIT ?,?";
try (PreparedStatement stmt = conn.prepareStatement(query)) {
- stmt.setInt(1, tenantId);
- stmt.setInt(2, request.getStartIndex());
- stmt.setInt(3, request.getRowCount());
+ int paramIdx = 1;
+ stmt.setInt(paramIdx++, tenantId);
+ if (isPolicyNameProvided) {
+ stmt.setString(paramIdx++, "%" + name + "%");
+ }
+ if (isPolicyTypeProvided) {
+ stmt.setString(paramIdx++, type);
+ }
+ if (isPolicyStatusProvided) {
+ stmt.setInt(paramIdx++, statusValue);
+ }
+ stmt.setInt(paramIdx++, request.getStartIndex());
+ stmt.setInt(paramIdx++, request.getRowCount());
try (ResultSet resultSet = stmt.executeQuery()) {
return this.extractPolicyListFromDbResult(resultSet, tenantId);
}
diff --git a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/dao/impl/policy/OraclePolicyDAOImpl.java b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/dao/impl/policy/OraclePolicyDAOImpl.java
index ecefc571a7..19642f162e 100644
--- a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/dao/impl/policy/OraclePolicyDAOImpl.java
+++ b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/dao/impl/policy/OraclePolicyDAOImpl.java
@@ -18,13 +18,14 @@
package io.entgra.device.mgt.core.policy.mgt.core.dao.impl.policy;
+import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
+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.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy;
import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagementDAOFactory;
import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagerDAOException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.context.PrivilegedCarbonContext;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -40,21 +41,57 @@ public class OraclePolicyDAOImpl extends AbstractPolicyDAOImpl {
}
@Override
- public List getAllPolicies(PaginationRequest request) throws PolicyManagerDAOException {
+ public List getAllPolicies(PolicyPaginationRequest request) throws PolicyManagerDAOException {
Connection conn;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ String name = request.getName();
+ String type = request.getType();
+ String status = request.getStatus();
+ int statusValue = 0;
+ boolean isPolicyNameProvided = false;
+ boolean isPolicyTypeProvided = false;
+ boolean isPolicyStatusProvided = false;
try {
conn = this.getConnection();
String query = "SELECT * " +
"FROM DM_POLICY " +
- "WHERE TENANT_ID = ? " +
- "ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
+ "WHERE TENANT_ID = ? ";
+
+ if (name != null && !name.isEmpty()) {
+ query += "AND NAME LIKE ? " ;
+ isPolicyNameProvided = true;
+ }
+
+ if (type != null && !type.isEmpty()) {
+ query += "AND POLICY_TYPE = ? " ;
+ isPolicyTypeProvided = true;
+ }
+
+ if (status != null && !status.isEmpty()) {
+ if (status.equals("ACTIVE")) {
+ statusValue = 1;
+ }
+ query += "AND ACTIVE = ? " ;
+ isPolicyStatusProvided = true;
+ }
+
+ query += "ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try (PreparedStatement stmt = conn.prepareStatement(query)) {
- stmt.setInt(1, tenantId);
- stmt.setInt(2, request.getStartIndex());
- stmt.setInt(3, request.getRowCount());
+ int paramIdx = 1;
+ stmt.setInt(paramIdx++, tenantId);
+ if (isPolicyNameProvided) {
+ stmt.setString(paramIdx++, "%" + name + "%");
+ }
+ if (isPolicyTypeProvided) {
+ stmt.setString(paramIdx++, type);
+ }
+ if (isPolicyStatusProvided) {
+ stmt.setInt(paramIdx++, statusValue);
+ }
+ stmt.setInt(paramIdx++, request.getStartIndex());
+ stmt.setInt(paramIdx++, request.getRowCount());
try (ResultSet resultSet = stmt.executeQuery()) {
return this.extractPolicyListFromDbResult(resultSet, tenantId);
}
diff --git a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/dao/impl/policy/PostgreSQLPolicyDAOImpl.java b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/dao/impl/policy/PostgreSQLPolicyDAOImpl.java
index bc6db2baf8..26b211e6e2 100644
--- a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/dao/impl/policy/PostgreSQLPolicyDAOImpl.java
+++ b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/dao/impl/policy/PostgreSQLPolicyDAOImpl.java
@@ -18,13 +18,14 @@
package io.entgra.device.mgt.core.policy.mgt.core.dao.impl.policy;
+import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
+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.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy;
import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagementDAOFactory;
import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagerDAOException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.context.PrivilegedCarbonContext;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -40,21 +41,57 @@ public class PostgreSQLPolicyDAOImpl extends AbstractPolicyDAOImpl {
}
@Override
- public List getAllPolicies(PaginationRequest request) throws PolicyManagerDAOException {
+ public List getAllPolicies(PolicyPaginationRequest request) throws PolicyManagerDAOException {
Connection conn;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ String name = request.getName();
+ String type = request.getType();
+ String status = request.getStatus();
+ int statusValue = 0;
+ boolean isPolicyNameProvided = false;
+ boolean isPolicyTypeProvided = false;
+ boolean isPolicyStatusProvided = false;
try {
conn = this.getConnection();
String query = "SELECT * " +
"FROM DM_POLICY " +
- "WHERE TENANT_ID = ? " +
- "ORDER BY ID LIMIT ? OFFSET ?";
+ "WHERE TENANT_ID = ? ";
+
+ if (name != null && !name.isEmpty()) {
+ query += "AND NAME LIKE ? " ;
+ isPolicyNameProvided = true;
+ }
+
+ if (type != null && !type.isEmpty()) {
+ query += "AND POLICY_TYPE = ? " ;
+ isPolicyTypeProvided = true;
+ }
+
+ if (status != null && !status.isEmpty()) {
+ if (status.equals("ACTIVE")) {
+ statusValue = 1;
+ }
+ query += "AND ACTIVE = ? " ;
+ isPolicyStatusProvided = true;
+ }
+
+ query += "ORDER BY ID LIMIT ? OFFSET ?";
try (PreparedStatement stmt = conn.prepareStatement(query)) {
- stmt.setInt(1, tenantId);
- stmt.setInt(2, request.getRowCount());
- stmt.setInt(3, request.getStartIndex());
+ int paramIdx = 1;
+ stmt.setInt(paramIdx++, tenantId);
+ if (isPolicyNameProvided) {
+ stmt.setString(paramIdx++, "%" + name + "%");
+ }
+ if (isPolicyTypeProvided) {
+ stmt.setString(paramIdx++, type);
+ }
+ if (isPolicyStatusProvided) {
+ stmt.setInt(paramIdx++, statusValue);
+ }
+ stmt.setInt(paramIdx++, request.getStartIndex());
+ stmt.setInt(paramIdx++, request.getRowCount());
try (ResultSet resultSet = stmt.executeQuery()) {
return this.extractPolicyListFromDbResult(resultSet, tenantId);
}
diff --git a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/dao/impl/policy/SQLServerPolicyDAOImpl.java b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/dao/impl/policy/SQLServerPolicyDAOImpl.java
index ee07d33bee..6e4df5cb15 100644
--- a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/dao/impl/policy/SQLServerPolicyDAOImpl.java
+++ b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/dao/impl/policy/SQLServerPolicyDAOImpl.java
@@ -18,13 +18,14 @@
package io.entgra.device.mgt.core.policy.mgt.core.dao.impl.policy;
+import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
+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.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy;
import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagementDAOFactory;
import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagerDAOException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.context.PrivilegedCarbonContext;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -40,20 +41,57 @@ public class SQLServerPolicyDAOImpl extends AbstractPolicyDAOImpl {
}
@Override
- public List getAllPolicies(PaginationRequest request) throws PolicyManagerDAOException {
+ public List getAllPolicies(PolicyPaginationRequest request) throws PolicyManagerDAOException {
Connection conn;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
+ String name = request.getName();
+ String type = request.getType();
+ String status = request.getStatus();
+ int statusValue = 0;
+ boolean isPolicyNameProvided = false;
+ boolean isPolicyTypeProvided = false;
+ boolean isPolicyStatusProvided = false;
try {
conn = this.getConnection();
String query = "SELECT * " +
"FROM DM_POLICY " +
- "WHERE TENANT_ID = ? " +
- "ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
+ "WHERE TENANT_ID = ? ";
+
+ if (name != null && !name.isEmpty()) {
+ query += "AND NAME LIKE ? " ;
+ isPolicyNameProvided = true;
+ }
+
+ if (type != null && !type.isEmpty()) {
+ query += "AND POLICY_TYPE = ? " ;
+ isPolicyTypeProvided = true;
+ }
+
+ if (status != null && !status.isEmpty()) {
+ if (status.equals("ACTIVE")) {
+ statusValue = 1;
+ }
+ query += "AND ACTIVE = ? " ;
+ isPolicyStatusProvided = true;
+ }
+
+ query += "ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
+
try (PreparedStatement stmt = conn.prepareStatement(query)) {
- stmt.setInt(1, tenantId);
- stmt.setInt(2, request.getStartIndex());
- stmt.setInt(3, request.getRowCount());
+ int paramIdx = 1;
+ stmt.setInt(paramIdx++, tenantId);
+ if (isPolicyNameProvided) {
+ stmt.setString(paramIdx++, "%" + name + "%");
+ }
+ if (isPolicyTypeProvided) {
+ stmt.setString(paramIdx++, type);
+ }
+ if (isPolicyStatusProvided) {
+ stmt.setInt(paramIdx++, statusValue);
+ }
+ stmt.setInt(paramIdx++, request.getStartIndex());
+ stmt.setInt(paramIdx++, request.getRowCount());
try (ResultSet resultSet = stmt.executeQuery()) {
return this.extractPolicyListFromDbResult(resultSet, tenantId);
}
diff --git a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/impl/PolicyAdministratorPointImpl.java b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/impl/PolicyAdministratorPointImpl.java
index 962794a930..b07f311ce1 100644
--- a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/impl/PolicyAdministratorPointImpl.java
+++ b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/impl/PolicyAdministratorPointImpl.java
@@ -18,6 +18,10 @@
package io.entgra.device.mgt.core.policy.mgt.core.impl;
+import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
+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.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy;
@@ -336,7 +340,7 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
}
@Override
- public List getPolicyList(PaginationRequest request) throws PolicyManagementException {
+ public List getPolicyList(PolicyPaginationRequest request) throws PolicyManagementException {
return policyManager.getPolicyList(request);
}
}
diff --git a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/mgt/PolicyManager.java b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/mgt/PolicyManager.java
index 8cba36edee..dc066033ce 100644
--- a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/mgt/PolicyManager.java
+++ b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/mgt/PolicyManager.java
@@ -20,6 +20,7 @@ package io.entgra.device.mgt.core.policy.mgt.core.mgt;
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.PaginationRequest;
+import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy;
import io.entgra.device.mgt.core.policy.mgt.common.PolicyManagementException;
import io.entgra.device.mgt.core.policy.mgt.core.mgt.bean.UpdatedPolicyDeviceListBean;
@@ -92,10 +93,10 @@ public interface PolicyManager {
/**
* Returns list of policies with users, roles and groups attached to that policy
- * @param request {@link PaginationRequest} contains offset and limit
+ * @param request {@link PolicyPaginationRequest} contains offset and limit and filters
* @return {@link List} - list of policies for current tenant
* @throws PolicyManagementException when there is an error while retrieving the policies from database or
* while retrieving device groups
*/
- List getPolicyList(PaginationRequest request) throws PolicyManagementException;
+ List getPolicyList(PolicyPaginationRequest request) throws PolicyManagementException;
}
diff --git a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/mgt/impl/PolicyManagerImpl.java b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/mgt/impl/PolicyManagerImpl.java
index 62e3bacc70..5cc0dc35b8 100644
--- a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/mgt/impl/PolicyManagerImpl.java
+++ b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/mgt/impl/PolicyManagerImpl.java
@@ -20,7 +20,7 @@ package io.entgra.device.mgt.core.policy.mgt.core.mgt.impl;
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.PaginationRequest;
+import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.InvalidDeviceException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup;
@@ -1427,7 +1427,7 @@ public class PolicyManagerImpl implements PolicyManager {
* @return
*/
private List getSingleCorrectiveAction
- (List allCorrectiveActions, int policyId) {
+ (List allCorrectiveActions, int policyId) {
List correctiveActionsOfPolicy = new ArrayList<>();
for (CorrectiveAction correctiveAction : allCorrectiveActions) {
if (correctiveAction.getAssociatedGeneralPolicyId() != null &&
@@ -1471,7 +1471,7 @@ public class PolicyManagerImpl implements PolicyManager {
}
@Override
- public List getPolicyList(PaginationRequest request) throws PolicyManagementException {
+ public List getPolicyList(PolicyPaginationRequest request) throws PolicyManagementException {
List policyList;
try {
PolicyManagementDAOFactory.openConnection();
diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/pom.xml b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/pom.xml
new file mode 100644
index 0000000000..b0f3a595a5
--- /dev/null
+++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/pom.xml
@@ -0,0 +1,108 @@
+
+
+
+
+
+
+ io.entgra.device.mgt.core
+ apimgt-extensions-feature
+ 5.0.26-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ io.entgra.device.mgt.core.apimgt.extension.rest.api.feature
+ pom
+ Entgra - API management REST API feature
+ This feature contains an implementation of API manager REST API extension
+ http://entgra.io
+
+
+
+ io.entgra.device.mgt.core
+ io.entgra.device.mgt.core.apimgt.extension.rest.api
+ ${io.entgra.device.mgt.core.version}
+
+
+
+
+
+
+ maven-resources-plugin
+ 2.6
+
+
+ copy-resources
+ generate-resources
+
+ copy-resources
+
+
+ src/main/resources
+
+
+ resources
+
+ build.properties
+ p2.inf
+
+
+
+
+
+
+
+
+ org.wso2.maven
+ carbon-p2-plugin
+ ${carbon.p2.plugin.version}
+
+
+ p2-feature-generation
+ package
+
+ p2-feature-gen
+
+
+ io.entgra.device.mgt.core.apimgt.extension.rest.api
+ ../../../features/etc/feature.properties
+
+
+ org.wso2.carbon.p2.category.type:server
+ org.eclipse.equinox.p2.type.group:false
+
+
+
+
+ io.entgra.device.mgt.core:io.entgra.device.mgt.core.apimgt.extension.rest.api:${io.entgra.device.mgt.core.version}
+
+
+
+ org.wso2.carbon.core.server:${carbon.kernel.version}
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/src/main/resources/build.properties b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/src/main/resources/build.properties
new file mode 100644
index 0000000000..9c86577d76
--- /dev/null
+++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/src/main/resources/build.properties
@@ -0,0 +1 @@
+custom = true
diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/src/main/resources/p2.inf b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/src/main/resources/p2.inf
new file mode 100644
index 0000000000..7ab37b9d7d
--- /dev/null
+++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/src/main/resources/p2.inf
@@ -0,0 +1 @@
+instructions.configure = \
\ No newline at end of file
diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher.feature/pom.xml b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher.feature/pom.xml
index 3bb5d8c5c3..1a2cb3b77e 100644
--- a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher.feature/pom.xml
+++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher.feature/pom.xml
@@ -51,10 +51,6 @@
io.swagger
swagger-annotations
-
- io.entgra.device.mgt.core
- io.entgra.device.mgt.core.apimgt.extension.rest.api
-
@@ -146,9 +142,6 @@
io.swagger:swagger-annotations:${swagger.version}
-
- io.entgra.device.mgt.core:io.entgra.device.mgt.core.apimgt.extension.rest.api:${io.entgra.device.mgt.core.version}
-
org.wso2.carbon.core.server:${carbon.kernel.version}
diff --git a/features/apimgt-extensions/pom.xml b/features/apimgt-extensions/pom.xml
index 64553086cb..9c37daadae 100644
--- a/features/apimgt-extensions/pom.xml
+++ b/features/apimgt-extensions/pom.xml
@@ -38,6 +38,7 @@
io.entgra.device.mgt.core.apimgt.application.extension.feature
io.entgra.device.mgt.core.apimgt.keymgt.extension.feature
io.entgra.device.mgt.core.apimgt.analytics.extension.feature
+ io.entgra.device.mgt.core.apimgt.extension.rest.api.feature
diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql
index 87842e9da6..df3277920d 100644
--- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql
+++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql
@@ -417,6 +417,16 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION (
-- POLICY RELATED TABLES FINISHED --
+CREATE TABLE IF NOT EXISTS DM_APP_ICONS (
+ ID INTEGER AUTO_INCREMENT NOT NULL,
+ ICON_PATH VARCHAR(150) DEFAULT NULL,
+ PACKAGE_NAME VARCHAR(150) NOT NULL,
+ VERSION VARCHAR(50) DEFAULT '1.1.0',
+ CREATED_TIMESTAMP TIMESTAMP NOT NULL,
+ TENANT_ID INTEGER NOT NULL,
+ PRIMARY KEY (ID)
+);
+
-- NOTIFICATION TABLE --
CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
NOTIFICATION_ID INTEGER AUTO_INCREMENT NOT NULL,
diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql
index 07275d894c..c162d41e06 100644
--- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql
+++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql
@@ -462,6 +462,17 @@ CREATE INDEX IDX_DM_APPLICATION ON DM_APPLICATION(DEVICE_ID, ENROLMENT_ID, TENAN
-- POLICY RELATED TABLES FINISHED --
+IF NOT EXISTS (SELECT * SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_APP_ICONS]') AND TYPE IN (N'U'))
+CREATE TABLE DM_APP_ICONS (
+ ID INTEGER IDENTITY(1,1) NOT NULL,
+ ICON_PATH VARCHAR(150) DEFAULT NULL,
+ PACKAGE_NAME VARCHAR(150) NOT NULL,
+ VERSION VARCHAR(50) DEFAULT '1.1.0',
+ CREATED_TIMESTAMP DATETIME2 NOT NULL,
+ TENANT_ID INTEGER NOT NULL,
+ PRIMARY KEY (ID)
+);
+
-- POLICY AND DEVICE GROUP MAPPING --
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_GROUP_POLICY]') AND TYPE IN (N'U'))
CREATE TABLE DM_DEVICE_GROUP_POLICY (
@@ -775,7 +786,7 @@ CREATE TABLE DM_DEVICE_EVENT (
EVENT_SOURCE VARCHAR(100) NOT NULL,
EVENT_LOGIC VARCHAR(100) NOT NULL,
ACTIONS TEXT DEFAULT NULL,
- CREATED_TIMESTAMP TIMESTAMP NOT NULL,
+ CREATED_TIMESTAMP DATETIME2(0) NOT NULL,
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID)
);
diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql
index 0c5a8fb090..6dcc7bec44 100644
--- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql
+++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql
@@ -458,6 +458,16 @@ CREATE INDEX IDX_DM_APPLICATION ON DM_APPLICATION(DEVICE_ID, ENROLMENT_ID, TENAN
-- END OF POLICY RELATED TABLES --
+CREATE TABLE IF NOT EXISTS DM_APP_ICONS (
+ ID INTEGER AUTO_INCREMENT NOT NULL,
+ ICON_PATH VARCHAR(150) DEFAULT NULL,
+ PACKAGE_NAME VARCHAR(150) NOT NULL,
+ VERSION VARCHAR(50) DEFAULT '1.1.0',
+ CREATED_TIMESTAMP TIMESTAMP NOT NULL,
+ TENANT_ID INTEGER NOT NULL,
+ PRIMARY KEY (ID)
+)ENGINE = InnoDB;
+
-- POLICY AND DEVICE GROUP MAPPING --
CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY (
diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql
index 1a0ddb3064..a6f87c9cb6 100644
--- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql
+++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql
@@ -748,6 +748,28 @@ WHEN (NEW.ID IS NULL)
-- POLICY RELATED TABLES FINISHED --
+CREATE TABLE DM_APP_ICONS (
+ ID NUMBER(10) NOT NULL,
+ ICON_PATH VARCHAR2(150) DEFAULT NULL,
+ PACKAGE_NAME VARCHAR2(150) NOT NULL,
+ VERSION VARCHAR2(50) DEFAULT '1.1.0',
+ CREATED_TIMESTAMP TIMESTAMP(0) NOT NULL,
+ TENANT_ID NUMBER(10) NOT NULL,
+ PRIMARY KEY (ID)
+)
+/
+
+-- Generate ID using sequence and trigger
+CREATE SEQUENCE DM_APP_ICONS_seq START WITH 1 INCREMENT BY 1 NOCACHE
+/
+CREATE OR REPLACE TRIGGER DM_APP_ICONS_seq_tr
+BEFORE INSERT ON DM_APP_ICONS FOR EACH ROW
+WHEN (NEW.ID IS NULL)
+ BEGIN
+ SELECT DM_APP_ICONS_seq.NEXTVAL INTO :NEW.ID FROM DUAL;
+ END;
+/
+
-- NOTIFICATION TABLE --
CREATE TABLE DM_NOTIFICATION (
NOTIFICATION_ID NUMBER(10) NOT NULL,
diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql
index 7df9dcc065..8c601111b7 100644
--- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql
+++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql
@@ -490,6 +490,19 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION (
-- END OF POLICY RELATED TABLES --
+CREATE SEQUENCE DM_APP_ICONS_seq;
+
+CREATE TABLE IF NOT EXISTS DM_APP_ICONS (
+ ID INTEGER DEFAULT NEXTVAL ('DM_APP_ICONS_seq') NOT NULL,
+ ICON_PATH VARCHAR(150) DEFAULT NULL,
+ PACKAGE_NAME VARCHAR(150) NOT NULL,
+ VERSION VARCHAR(50) DEFAULT '1.1.0',
+ CREATED_TIMESTAMP TIMESTAMP(0) NOT NULL,
+ TENANT_ID INTEGER NOT NULL,
+ PRIMARY KEY (ID)
+)
+;
+
-- POLICY AND DEVICE GROUP MAPPING --
CREATE SEQUENCE DM_DEVICE_GROUP_POLICY_seq;