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 b9ec3fb3b87..57c96ba6db1 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
@@ -127,7 +127,6 @@
io.entgra.device.mgt.core
io.entgra.device.mgt.core.apimgt.extension.rest.api
- provided
org.json.wso2
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 6d3ec075c02..ae7f541234e 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
@@ -916,6 +916,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 76f16c34349..2a8e6357cc7 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,7 @@
*/
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;
@@ -481,6 +482,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) {
@@ -488,7 +492,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 00000000000..8a0a2f3bd4d
--- /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/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 7b434274dfe..b610a3e8f45 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
@@ -18,20 +18,20 @@
package io.entgra.device.mgt.core.device.mgt.core.dao;
-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.exceptions.IllegalTransactionStateException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.UnsupportedDatabaseEngineException;
import io.entgra.device.mgt.core.device.mgt.core.config.datasource.DataSourceConfig;
import io.entgra.device.mgt.core.device.mgt.core.config.datasource.JNDILookupDefinition;
-import io.entgra.device.mgt.core.device.mgt.core.dao.impl.*;
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;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -69,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/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 00000000000..8eedceb4d95
--- /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/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 a3981d3d114..0d8219b290d 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.DynamicTaskContext;
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 4962dfd1fdd..a755a5c6b34 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.policy.mgt.common.Criterion;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.DeviceGroupWrapper;
@@ -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 02f82b4eaba..2e7b3aa87fe 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,6 +18,7 @@
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;
@@ -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 82b40b2a68e..19642f162ee 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,6 +18,7 @@
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;
@@ -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 cd812c870c4..26b211e6e2a 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,6 +18,7 @@
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;
@@ -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 66e982e9be7..6e4df5cb15f 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,6 +18,7 @@
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;
@@ -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 b4bbf29b8c6..2521eab3a11 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,7 @@
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;
@@ -335,7 +336,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 4134ca789c6..abecb537125 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
@@ -21,6 +21,7 @@ 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.DynamicTaskContext;
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;
@@ -93,10 +94,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 665a6e5f908..fd5b3b5fdb2 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
@@ -18,6 +18,7 @@
package io.entgra.device.mgt.core.policy.mgt.core.mgt.impl;
+import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -1488,7 +1489,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 00000000000..b0f3a595a59
--- /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 00000000000..9c86577d768
--- /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 00000000000..7ab37b9d7d7
--- /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 31da375945a..242ed90d485 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 e0adcce8860..72acd8222b0 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/mssql.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql
index 07275d894cd..028c24829f2 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
@@ -775,7 +775,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)
);