From eccb39d6f48789a837da543ef31cf03623404dbe Mon Sep 17 00:00:00 2001 From: Shamalka Navod Date: Mon, 7 Dec 2020 20:15:18 +0000 Subject: [PATCH] Improve metadata API --- .../device/mgt/jaxrs/service/api/MetadataService.java | 4 ---- .../mgt/jaxrs/service/impl/MetadataServiceImpl.java | 4 ---- .../common/metadata/mgt/MetadataManagementService.java | 3 +-- .../metadata/mgt/MetadataManagementServiceImpl.java | 10 ++-------- .../policy/mgt/core/mgt/impl/PolicyManagerImpl.java | 1 + 5 files changed, 4 insertions(+), 18 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/MetadataService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/MetadataService.java index c9a1b268e88..3a22364ed56 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/MetadataService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/MetadataService.java @@ -189,10 +189,6 @@ public interface MetadataService { description = "Date and time the resource was last modified.\n" + "Used by caches, or in conditional requests."), }), - @ApiResponse( - code = 404, - message = "Not Found. \n The requested metadata entry is not found.", - response = ErrorResponse.class), @ApiResponse( code = 500, message = "Internal Server Error. " + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/MetadataServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/MetadataServiceImpl.java index 8609c01fbe1..5a484bfa0c3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/MetadataServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/MetadataServiceImpl.java @@ -89,10 +89,6 @@ public class MetadataServiceImpl implements MetadataService { try { metadata = DeviceMgtAPIUtils.getMetadataManagementService().retrieveMetadata(metaKey); return Response.status(Response.Status.OK).entity(metadata).build(); - } catch (MetadataKeyNotFoundException e) { - String msg = "Metadata entry metaKey:" + metaKey + " is not found."; - log.error(msg, e); - return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (MetadataManagementException e) { String msg = "Error occurred while getting the metadata entry for metaKey:" + metaKey; log.error(msg, e); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/metadata/mgt/MetadataManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/metadata/mgt/MetadataManagementService.java index 65b02e3af5b..060492f6203 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/metadata/mgt/MetadataManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/metadata/mgt/MetadataManagementService.java @@ -47,9 +47,8 @@ public interface MetadataManagementService { * @param metaKey a string to be search against the Metadata.metaKey * @return the Metadata entry for specified Metadata.metaKey * @throws MetadataManagementException If a data source related exception occurred - * @throws MetadataKeyNotFoundException If the provided Metadata.metaKey not found */ - Metadata retrieveMetadata(String metaKey) throws MetadataManagementException, MetadataKeyNotFoundException; + Metadata retrieveMetadata(String metaKey) throws MetadataManagementException; /** * Get all Metadata entries. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/MetadataManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/MetadataManagementServiceImpl.java index 813bd47db36..7d7fd1d7c01 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/MetadataManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/MetadataManagementServiceImpl.java @@ -85,20 +85,14 @@ public class MetadataManagementServiceImpl implements MetadataManagementService } @Override - public Metadata retrieveMetadata(String metaKey) throws MetadataManagementException, MetadataKeyNotFoundException { + public Metadata retrieveMetadata(String metaKey) throws MetadataManagementException { if (log.isDebugEnabled()) { log.debug("Retrieving Metadata for metaKey:" + metaKey); } try { MetadataManagementDAOFactory.openConnection(); - Metadata metadata = metadataDAO.getMetadata( + return metadataDAO.getMetadata( PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true), metaKey); - if (metadata == null) { - String msg = "Specified Metadata entry has not found. {metaKey:" + metaKey + "}"; - log.error(msg); - throw new MetadataKeyNotFoundException(msg); - } - return metadata; } catch (MetadataManagementDAOException e) { String msg = "Error occurred while retrieving the metadata entry for metaKey:" + metaKey; log.error(msg, e); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java index 6a614fb37ed..0db7f676e51 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java @@ -872,6 +872,7 @@ public class PolicyManagerImpl implements PolicyManager { @Override public List getPolicies() throws PolicyManagementException { + List policyList; List profileList; try {