Merge branch 'corrective-sync' into 'master'

Improve metadata API

See merge request entgra/carbon-device-mgt!705
4.x.x
Dharmakeerthi Lasantha 4 years ago
commit 8bf3272333

@ -189,10 +189,6 @@ public interface MetadataService {
description = "Date and time the resource was last modified.\n" + description = "Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."), "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( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. " + message = "Internal Server Error. " +

@ -89,10 +89,6 @@ public class MetadataServiceImpl implements MetadataService {
try { try {
metadata = DeviceMgtAPIUtils.getMetadataManagementService().retrieveMetadata(metaKey); metadata = DeviceMgtAPIUtils.getMetadataManagementService().retrieveMetadata(metaKey);
return Response.status(Response.Status.OK).entity(metadata).build(); 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) { } catch (MetadataManagementException e) {
String msg = "Error occurred while getting the metadata entry for metaKey:" + metaKey; String msg = "Error occurred while getting the metadata entry for metaKey:" + metaKey;
log.error(msg, e); log.error(msg, e);

@ -47,9 +47,8 @@ public interface MetadataManagementService {
* @param metaKey a string to be search against the Metadata.metaKey * @param metaKey a string to be search against the Metadata.metaKey
* @return the Metadata entry for specified Metadata.metaKey * @return the Metadata entry for specified Metadata.metaKey
* @throws MetadataManagementException If a data source related exception occurred * @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. * Get all Metadata entries.

@ -85,20 +85,14 @@ public class MetadataManagementServiceImpl implements MetadataManagementService
} }
@Override @Override
public Metadata retrieveMetadata(String metaKey) throws MetadataManagementException, MetadataKeyNotFoundException { public Metadata retrieveMetadata(String metaKey) throws MetadataManagementException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Retrieving Metadata for metaKey:" + metaKey); log.debug("Retrieving Metadata for metaKey:" + metaKey);
} }
try { try {
MetadataManagementDAOFactory.openConnection(); MetadataManagementDAOFactory.openConnection();
Metadata metadata = metadataDAO.getMetadata( return metadataDAO.getMetadata(
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true), metaKey); 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) { } catch (MetadataManagementDAOException e) {
String msg = "Error occurred while retrieving the metadata entry for metaKey:" + metaKey; String msg = "Error occurred while retrieving the metadata entry for metaKey:" + metaKey;
log.error(msg, e); log.error(msg, e);

@ -872,6 +872,7 @@ public class PolicyManagerImpl implements PolicyManager {
@Override @Override
public List<Policy> getPolicies() throws PolicyManagementException { public List<Policy> getPolicies() throws PolicyManagementException {
List<Policy> policyList; List<Policy> policyList;
List<Profile> profileList; List<Profile> profileList;
try { try {

Loading…
Cancel
Save