From bb5f779c26e0a8c9bf184e1a1faa62af07702e22 Mon Sep 17 00:00:00 2001 From: Kavindya Sathsarani Date: Tue, 4 Oct 2022 09:37:45 +0000 Subject: [PATCH] Add a searchable input for App Restriction Settings policy --- .../service/api/DeviceManagementService.java | 9 +- .../impl/DeviceManagementServiceImpl.java | 6 +- .../mgt/common/policy/mgt/ui/Column.java | 10 ++ .../device/mgt/common/policy/mgt/ui/Item.java | 10 ++ .../mgt/common/policy/mgt/ui/SearchInput.java | 108 ++++++++++++++++++ .../mgt/core/dao/impl/ApplicationDAOImpl.java | 20 +++- 6 files changed, 156 insertions(+), 7 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/ui/SearchInput.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java index dc0a3c034ed..1594a307c02 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java @@ -2623,7 +2623,9 @@ public interface DeviceManagementService { @GET @Path("/{deviceType}/applications") + @Produces(MediaType.APPLICATION_JSON) @ApiOperation( + consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, httpMethod = "GET", value = "Getting Details of Applications", @@ -2681,7 +2683,12 @@ public interface DeviceManagementService { value = "Provide how many device details you require from the starting pagination index/offset.", defaultValue = "10") @QueryParam("limit") - int limit); + int limit, + @ApiParam( + name = "appName", + value = "App name to be searched") + @QueryParam("appName") + String appName); @GET @Path("/application/{packageName}/versions") diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index 71646f98cd5..ccbf8aafed6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -131,6 +131,7 @@ import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import javax.validation.Valid; +import javax.ws.rs.Consumes; import javax.validation.constraints.Size; import javax.ws.rs.DELETE; import javax.ws.rs.DefaultValue; @@ -1605,16 +1606,19 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { @GET @Override + @Consumes("application/json") @Path("/{deviceType}/applications") public Response getApplications( @PathParam("deviceType") String deviceType, @DefaultValue("0") @QueryParam("offset") int offset, @DefaultValue("10") - @QueryParam("limit") int limit) { + @QueryParam("limit") int limit, + @QueryParam("appName") String appName) { PaginationRequest request = new PaginationRequest(offset, limit); ApplicationList applicationList = new ApplicationList(); request.setDeviceType(deviceType); + request.setFilter(appName); try { PaginationResult paginationResult = DeviceMgtAPIUtils .getDeviceManagementService() diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/ui/Column.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/ui/Column.java index 275db772821..23c49a46f5d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/ui/Column.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/ui/Column.java @@ -32,6 +32,7 @@ public class Column { private Input input; private Upload upload; private Checkbox checkbox; + private SearchInput searchInput; private boolean isRequired; private String tooltip; private String docLink; @@ -100,6 +101,15 @@ public class Column { this.checkbox = checkbox; } + @XmlElement(name = "SearchInput") + public SearchInput getSearchInput() { + return searchInput; + } + + public void setSearchInput(SearchInput searchInput) { + this.searchInput = searchInput; + } + @XmlElement(name = "RequiredItem") public boolean isRequired() { return isRequired; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/ui/Item.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/ui/Item.java index aac25bc0d20..0c5d5481429 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/ui/Item.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/ui/Item.java @@ -45,6 +45,7 @@ public class Item { private APITable apiTable; private Text text; private InputList inputList; + private SearchInput searchInput; private String nullableValue; private String divider; private boolean isHidden; @@ -212,6 +213,15 @@ public class Item { this.inputList = inputList; } + @XmlElement(name = "SearchInput") + public SearchInput getSearchInput() { + return searchInput; + } + + public void setSearchInput(SearchInput searchInput) { + this.searchInput = searchInput; + } + @XmlElement(name = "NullableValue") public String getNullableValue() { return nullableValue; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/ui/SearchInput.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/ui/SearchInput.java new file mode 100644 index 00000000000..7736937369e --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/ui/SearchInput.java @@ -0,0 +1,108 @@ +/* Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.common.policy.mgt.ui; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.List; + +@XmlRootElement(name = "SearchInput") +public class SearchInput { + + private String valueType; + private String placeholderValue; + private String apiUrl; + private String defineValueKey; + private String displayValueKey; + private String arrayPath; + private String paramValue; + private String iteratorKeyValue; + + @XmlElement(name = "Url") + public String getApiUrl() { + return apiUrl; + } + + public void setApiUrl(String apiUrl) { + this.apiUrl = apiUrl; + } + + @XmlElement(name = "DefineValueKey") + public String getDefineValueKey() { + return defineValueKey; + } + + public void setDefineValueKey(String defineValueKey) { + this.defineValueKey = defineValueKey; + } + + @XmlElement(name = "DisplayValueKey") + public String getDisplayValueKey() { + return displayValueKey; + } + + public void setDisplayValueKey(String displayValueKey) { + this.displayValueKey = displayValueKey; + } + + @XmlElement(name = "ArrayPath") + public String getArrayPath() { + return arrayPath; + } + + public void setArrayPath(String arrayPath) { + this.arrayPath = arrayPath; + } + + @XmlElement(name = "ValueType", required = true) + public String getValueType() { + return valueType; + } + + public void setValueType(String valueType) { + this.valueType = valueType; + } + + @XmlElement(name = "Placeholder") + public String getPlaceholderValue() { + return placeholderValue; + } + + public void setPlaceholderValue(String placeholderValue) { + this.placeholderValue = placeholderValue; + } + + @XmlElement(name = "ParamValue") + public String getParamValue() { + return paramValue; + } + + public void setParamValue(String paramValue) { + this.paramValue = paramValue; + } + + @XmlElement(name = "IteratorKeyValue") + public String getIteratorKeyValue() { + return iteratorKeyValue; + } + + public void setIteratorKeyValue(String iteratorKeyValue) { + this.iteratorKeyValue = iteratorKeyValue; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationDAOImpl.java index 5a89b613be4..23d2148f1b1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationDAOImpl.java @@ -292,14 +292,24 @@ public class ApplicationDAOImpl implements ApplicationDAO { "WHERE A.NAME = DM_APPLICATION.NAME " + "AND A.ID < DM_APPLICATION.ID) " + "AND PLATFORM = ? " + - "AND TENANT_ID = ? LIMIT ? OFFSET ?"; + "AND TENANT_ID = ?"; try { + String filter = request.getFilter(); + if (filter != null) { + sql = sql + "AND NAME LIKE ?"; + } + sql = sql + "LIMIT ? OFFSET ?"; Connection conn = this.getConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { - stmt.setString(1, request.getDeviceType()); - stmt.setInt(2, tenantId); - stmt.setInt(3, request.getRowCount()); - stmt.setInt(4, request.getStartIndex()); + int paramIdx = 1; + stmt.setString(paramIdx++, request.getDeviceType()); + stmt.setInt(paramIdx++, tenantId); + if (filter != null){ + stmt.setString(paramIdx++, filter); + } + stmt.setInt(paramIdx++, request.getRowCount()); + stmt.setInt(paramIdx, request.getStartIndex()); + try (ResultSet rs = stmt.executeQuery()) { while (rs.next()) { application = loadApplication(rs);