Merge pull request 'Improve device status management service' (#510) from tcdlpds/device-mgt-core:master into master

Reviewed-on: community/device-mgt-core#510
remotes/1728937285237262521/master
Navod Zoysa 2 months ago
commit 35f02ba7ac

@ -257,14 +257,12 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
MetadataManagementService metadataManagementService = APIApplicationManagerExtensionDataHolder.getInstance().getMetadataManagementService(); MetadataManagementService metadataManagementService = APIApplicationManagerExtensionDataHolder.getInstance().getMetadataManagementService();
metadataManagementService.createMetadata(metaData); metadataManagementService.createMetadata(metaData);
return apiApplicationKey; return apiApplicationKey;
} catch (MetadataManagementException e) { } catch (MetadataKeyAlreadyExistsException e) {
String msg = "Error occurred while creating meta data for meta key: " + applicationName; String msg = "Since meta key:" + applicationName + " already exists, meta data creating process failed.";
log.error(msg, e); log.error(msg, e);
throw new APIManagerException(msg, e); throw new APIManagerException(msg, e);
} catch (MetadataKeyAlreadyExistsException e) { } catch (MetadataManagementException e) {
String msg = String msg = "Error occurred while creating meta data for meta key: " + applicationName;
"Since meta key:" + applicationName + " already exists, meta data creating process " +
"failed.";
log.error(msg, e); log.error(msg, e);
throw new APIManagerException(msg, e); throw new APIManagerException(msg, e);
} catch (BadRequestException e) { } catch (BadRequestException e) {

@ -196,10 +196,10 @@ public class APIPublisherStartupHandler implements ServerStartupObserver {
APIPublisherDataHolder.getInstance().setPermScopeMapping(permScopeMap); APIPublisherDataHolder.getInstance().setPermScopeMapping(permScopeMap);
log.info(Constants.PERM_SCOPE_MAPPING_META_KEY + "entry updated successfully"); log.info(Constants.PERM_SCOPE_MAPPING_META_KEY + "entry updated successfully");
} catch (MetadataManagementException e) {
log.error("Error encountered while updating permission scope mapping metadata with default scopes");
} catch (MetadataKeyAlreadyExistsException e) { } catch (MetadataKeyAlreadyExistsException e) {
log.error("Metadata entry already exists for " + Constants.PERM_SCOPE_MAPPING_META_KEY); log.error("Metadata entry already exists for " + Constants.PERM_SCOPE_MAPPING_META_KEY);
} catch (MetadataManagementException e) {
log.error("Error encountered while updating permission scope mapping metadata with default scopes");
} }
} }
} }

@ -20,13 +20,20 @@ package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.DeviceStatusFilterService; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.DeviceStatusFilterService;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataKeyNotFoundException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException; import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService; import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import javax.ws.rs.*; import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List; import java.util.List;
@ -42,15 +49,14 @@ public class DeviceStatusFilterServiceImpl implements DeviceStatusFilterService
@GET @GET
@Path("/{deviceType}") @Path("/{deviceType}")
public Response getDeviceStatusFilters(@PathParam("deviceType") String deviceType) { public Response getDeviceStatusFilters(@PathParam("deviceType") String deviceType) {
List<String> result;
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try { try {
DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService(); DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService();
result = deviceManagementProviderService.getDeviceStatusFilters(deviceType, tenantId); return Response.status(Response.Status.OK).entity(deviceManagementProviderService
if (result != null) { .getDeviceStatusFilters(deviceType, CarbonContext.getThreadLocalCarbonContext().getTenantId())).build();
return Response.status(Response.Status.OK).entity(result).build(); } catch (MetadataKeyNotFoundException e) {
} String msg = "Couldn't find the device status filter details for device type: " + deviceType;
return Response.status(Response.Status.NO_CONTENT).entity(false).build(); 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 device status filter of the tenant."; String msg = "Error occurred while getting device status filter of the tenant.";
log.error(msg, e); log.error(msg, e);

@ -36,8 +36,6 @@ import org.apache.commons.logging.LogFactory;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.List; import java.util.List;
/** /**
@ -147,21 +145,4 @@ public class MetadataServiceImpl implements MetadataService {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
} }
/**
* Useful to send files as application/octet-stream responses
*/
private Response sendFileStream(byte[] content) throws IOException {
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
Response.ResponseBuilder response = Response
.ok(binaryDuplicate, MediaType.APPLICATION_OCTET_STREAM);
response.status(Response.Status.OK);
response.header("Content-Length", content.length);
return response.build();
} catch (IOException e) {
String msg = "Error occurred while creating input stream from buffer array. ";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
} }

@ -21,7 +21,7 @@ package io.entgra.device.mgt.core.device.mgt.common.exceptions;
/** /**
* Custom exception class to be used in MetadataMgmt related functionalities. * Custom exception class to be used in MetadataMgmt related functionalities.
*/ */
public class MetadataKeyAlreadyExistsException extends Exception { public class MetadataKeyAlreadyExistsException extends MetadataManagementException {
private static final long serialVersionUID = -1814347544027733436L; private static final long serialVersionUID = -1814347544027733436L;
private String errorMessage; private String errorMessage;

@ -21,7 +21,7 @@ package io.entgra.device.mgt.core.device.mgt.common.exceptions;
/** /**
* Custom exception class to be used in MetadataMgmt related functionalities. * Custom exception class to be used in MetadataMgmt related functionalities.
*/ */
public class MetadataKeyNotFoundException extends Exception { public class MetadataKeyNotFoundException extends MetadataManagementException {
private static final long serialVersionUID = 5260831982626354815L; private static final long serialVersionUID = 5260831982626354815L;
private String errorMessage; private String errorMessage;

@ -38,7 +38,7 @@ public interface DeviceStatusManagementService {
* *
* @throws MetadataManagementException if error while resetting default device status * @throws MetadataManagementException if error while resetting default device status
*/ */
void resetToDefaultDeviceStausFilter() throws MetadataManagementException; void resetToDefaultDeviceStatusFilter(int tenantId) throws MetadataManagementException;
/** /**
* This method is useful to update existing allowed device status * This method is useful to update existing allowed device status

@ -346,15 +346,15 @@ public class DeviceManagementServiceComponent {
bundleContext.registerService(WhiteLabelManagementService.class.getName(), whiteLabelManagementService, null); bundleContext.registerService(WhiteLabelManagementService.class.getName(), whiteLabelManagementService, null);
/* Registering DeviceState Filter Service */ /* Registering DeviceState Filter Service */
DeviceStatusManagementService deviceStatusManagemntService = new DeviceStatusManagementServiceImpl(); DeviceStatusManagementService deviceStatusManagementService = new DeviceStatusManagementServiceImpl();
DeviceManagementDataHolder.getInstance().setDeviceStatusManagementService(deviceStatusManagemntService); DeviceManagementDataHolder.getInstance().setDeviceStatusManagementService(deviceStatusManagementService);
try { try {
deviceStatusManagemntService.addDefaultDeviceStatusFilterIfNotExist(tenantId); deviceStatusManagementService.addDefaultDeviceStatusFilterIfNotExist(tenantId);
} catch (Throwable e) { } catch (Throwable e) {
log.error("Error occurred while adding default tenant device status", e); log.error("Error occurred while adding default tenant device status", e);
} }
bundleContext.registerService(DeviceStatusManagementService.class.getName(), deviceStatusManagemntService, null); bundleContext.registerService(DeviceStatusManagementService.class.getName(), deviceStatusManagementService, null);
/* Registering Event Configuration Service */ /* Registering Event Configuration Service */
EventConfigurationProviderService eventConfigurationService = new EventConfigurationProviderServiceImpl(); EventConfigurationProviderService eventConfigurationService = new EventConfigurationProviderServiceImpl();

@ -21,6 +21,7 @@ package io.entgra.device.mgt.core.device.mgt.core.metadata.mgt;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataKeyNotFoundException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException; import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException; import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.AllowedDeviceStatus; import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.AllowedDeviceStatus;
@ -42,12 +43,12 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
public class DeviceStatusManagementServiceImpl implements DeviceStatusManagementService { public class DeviceStatusManagementServiceImpl implements DeviceStatusManagementService {
private static final Log log = LogFactory.getLog(DeviceStatusManagementServiceImpl.class); private static final Log log = LogFactory.getLog(DeviceStatusManagementServiceImpl.class);
private final MetadataDAO metadataDAO; private final MetadataDAO metadataDAO;
private static final Gson gson = new Gson();
public DeviceStatusManagementServiceImpl() { public DeviceStatusManagementServiceImpl() {
this.metadataDAO = MetadataManagementDAOFactory.getMetadataDAO(); this.metadataDAO = MetadataManagementDAOFactory.getMetadataDAO();
@ -57,12 +58,11 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
public void addDefaultDeviceStatusFilterIfNotExist(int tenantId) throws MetadataManagementException { public void addDefaultDeviceStatusFilterIfNotExist(int tenantId) throws MetadataManagementException {
try { try {
MetadataManagementDAOFactory.beginTransaction(); MetadataManagementDAOFactory.beginTransaction();
if (!metadataDAO.isExist(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY) && !metadataDAO.isExist(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY)) { if (!metadataDAO.isExist(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY)) {
Metadata defaultDeviceStatusMetadata = constructDeviceStatusMetadata(getDefaultDeviceStatus()); metadataDAO.addMetadata(tenantId, constructDeviceStatusMetadata(getDefaultDeviceStatus()));
Metadata defaultDeviceStatusCheckMetadata = constructDeviceStatusCheckMetadata(getDefaultDeviceStatusCheck()); }
// Add default device status and device status check metadata entries if (!metadataDAO.isExist(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY)) {
addMetadataEntry(tenantId, defaultDeviceStatusMetadata, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY); metadataDAO.addMetadata(tenantId, constructDeviceStatusCheckMetadata(getDefaultDeviceStatusCheck()));
addMetadataEntry(tenantId, defaultDeviceStatusCheckMetadata, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
} }
MetadataManagementDAOFactory.commitTransaction(); MetadataManagementDAOFactory.commitTransaction();
} catch (MetadataManagementDAOException e) { } catch (MetadataManagementDAOException e) {
@ -80,8 +80,27 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
} }
@Override @Override
public void resetToDefaultDeviceStausFilter() throws MetadataManagementException { public void resetToDefaultDeviceStatusFilter(int tenantId) throws MetadataManagementException {
try {
MetadataManagementDAOFactory.beginTransaction();
Metadata defaultDeviceStatusMetadata = constructDeviceStatusMetadata(getDefaultDeviceStatus());
Metadata defaultDeviceStatusCheckMetadata = constructDeviceStatusCheckMetadata(getDefaultDeviceStatusCheck());
// Add default device status and device status check metadata entries
metadataDAO.addMetadata(tenantId, defaultDeviceStatusMetadata);
metadataDAO.addMetadata(tenantId, defaultDeviceStatusCheckMetadata);
MetadataManagementDAOFactory.commitTransaction();
} catch (MetadataManagementDAOException e) {
MetadataManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while inserting default device status metadata entries.";
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while starting the transaction to reset default device status filters.";
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} finally {
MetadataManagementDAOFactory.closeConnection();
}
} }
@Override @Override
@ -91,7 +110,6 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
// Retrieve the current device status metadata // Retrieve the current device status metadata
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY); Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
if (metadata != null) { if (metadata != null) {
Gson gson = new Gson();
Type listType = new TypeToken<List<AllowedDeviceStatus>>() { Type listType = new TypeToken<List<AllowedDeviceStatus>>() {
}.getType(); }.getType();
List<AllowedDeviceStatus> currentStatusList = gson.fromJson(metadata.getMetaValue(), listType); List<AllowedDeviceStatus> currentStatusList = gson.fromJson(metadata.getMetaValue(), listType);
@ -105,7 +123,7 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
} }
} }
metadata.setMetaValue(gson.toJson(currentStatusList)); metadata.setMetaValue(gson.toJson(currentStatusList));
updateMetadataEntry(tenantId, metadata, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY); metadataDAO.updateMetadata(tenantId, metadata);
} }
MetadataManagementDAOFactory.commitTransaction(); MetadataManagementDAOFactory.commitTransaction();
} catch (MetadataManagementDAOException e) { } catch (MetadataManagementDAOException e) {
@ -124,14 +142,12 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
@Override @Override
public boolean updateDefaultDeviceStatusCheck(int tenantId, boolean isChecked) throws MetadataManagementException { public boolean updateDefaultDeviceStatusCheck(int tenantId, boolean isChecked) throws MetadataManagementException {
boolean success = false;
try { try {
MetadataManagementDAOFactory.beginTransaction(); MetadataManagementDAOFactory.beginTransaction();
if (metadataDAO.isExist(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY)) { if (metadataDAO.isExist(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY)) {
Metadata isDeviceStatusChecked = constructDeviceStatusCheckMetadata(isChecked);
// Add default device status check metadata entries // Add default device status check metadata entries
updateMetadataEntry(tenantId, isDeviceStatusChecked, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY); metadataDAO.updateMetadata(tenantId, constructDeviceStatusCheckMetadata(isChecked));
success = true; return true;
} }
MetadataManagementDAOFactory.commitTransaction(); MetadataManagementDAOFactory.commitTransaction();
} catch (MetadataManagementDAOException e) { } catch (MetadataManagementDAOException e) {
@ -146,7 +162,7 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
} finally { } finally {
MetadataManagementDAOFactory.closeConnection(); MetadataManagementDAOFactory.closeConnection();
} }
return success; return false;
} }
@Override @Override
@ -154,11 +170,15 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
try { try {
MetadataManagementDAOFactory.openConnection(); MetadataManagementDAOFactory.openConnection();
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY); Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
Gson gson = new Gson(); if (metadata == null) {
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {}.getType(); String msg =
List<AllowedDeviceStatus> statusList = gson.fromJson(metadata.getMetaValue(), listType); "Couldn't find the meta data value for meta key: " + MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY;
log.error(msg);
return statusList; throw new MetadataKeyNotFoundException(msg);
}
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {
}.getType();
return gson.fromJson(metadata.getMetaValue(), listType);
} catch (MetadataManagementDAOException e) { } catch (MetadataManagementDAOException e) {
String msg = "Error occurred while retrieving device status meta data for tenant:" + tenantId; String msg = "Error occurred while retrieving device status meta data for tenant:" + tenantId;
log.error(msg, e); log.error(msg, e);
@ -177,8 +197,14 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
try { try {
MetadataManagementDAOFactory.openConnection(); MetadataManagementDAOFactory.openConnection();
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY); Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
Gson gson = new Gson(); if (metadata == null) {
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {}.getType(); String msg = "Couldn't find the meta details of meta Key: "
+ MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY + " and tenant Id: " + tenantId;
log.error(msg);
throw new MetadataKeyNotFoundException(msg);
}
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {
}.getType();
List<AllowedDeviceStatus> statusList = gson.fromJson(metadata.getMetaValue(), listType); List<AllowedDeviceStatus> statusList = gson.fromJson(metadata.getMetaValue(), listType);
for (AllowedDeviceStatus status : statusList) { for (AllowedDeviceStatus status : statusList) {
@ -207,6 +233,12 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
try { try {
MetadataManagementDAOFactory.openConnection(); MetadataManagementDAOFactory.openConnection();
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY); Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
if (metadata == null) {
String msg = "Couldn't find the meta data value for meta key: "
+ MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY + " and tenant Id: " + tenantId;
log.error(msg);
throw new MetadataKeyNotFoundException(msg);
}
String metaValue = metadata.getMetaValue(); String metaValue = metadata.getMetaValue();
return Boolean.parseBoolean(metaValue); return Boolean.parseBoolean(metaValue);
} catch (MetadataManagementDAOException e) { } catch (MetadataManagementDAOException e) {
@ -227,8 +259,13 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
try { try {
MetadataManagementDAOFactory.openConnection(); MetadataManagementDAOFactory.openConnection();
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY); Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
if (metadata == null) {
String msg = "Couldn't find the meta data value for meta key: "
+ MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY + " and tenant Id: " + tenantId;
log.error(msg);
throw new MetadataKeyNotFoundException(msg);
}
Gson gson = new Gson();
Type listType = new TypeToken<List<AllowedDeviceStatus>>() { Type listType = new TypeToken<List<AllowedDeviceStatus>>() {
}.getType(); }.getType();
List<AllowedDeviceStatus> statusList = gson.fromJson(metadata.getMetaValue(), listType); List<AllowedDeviceStatus> statusList = gson.fromJson(metadata.getMetaValue(), listType);
@ -254,22 +291,13 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
} }
} }
private void addMetadataEntry(int tenantId, Metadata metadata, String key) throws MetadataManagementDAOException { /**
metadataDAO.addMetadata(tenantId, metadata); * To construct device status Meta data by using received device status items
if (log.isDebugEnabled()) { *
log.debug(key + " metadata entry has been inserted successfully"); * @param deviceStatusItems {@link List<DeviceStatusItem>}
} * @return {@link Metadata}
} */
private void updateMetadataEntry(int tenantId, Metadata metadata, String key) throws MetadataManagementDAOException {
metadataDAO.updateMetadata(tenantId, metadata);
if (log.isDebugEnabled()) {
log.debug(key + " metadata entry has been updated successfully");
}
}
private Metadata constructDeviceStatusMetadata(List<DeviceStatusItem> deviceStatusItems) { private Metadata constructDeviceStatusMetadata(List<DeviceStatusItem> deviceStatusItems) {
Gson gson = new Gson();
String deviceStatusItemsJsonString = gson.toJson(deviceStatusItems); String deviceStatusItemsJsonString = gson.toJson(deviceStatusItems);
Metadata metadata = new Metadata(); Metadata metadata = new Metadata();
@ -279,6 +307,12 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
return metadata; return metadata;
} }
/**
* To construct device status check Meta data to either enable it or disable it.
*
* @param deviceStatusCheck True or False
* @return {@link Metadata}
*/
private Metadata constructDeviceStatusCheckMetadata(boolean deviceStatusCheck) { private Metadata constructDeviceStatusCheckMetadata(boolean deviceStatusCheck) {
JsonObject jsonObject = new JsonObject(); JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("deviceStatusCheck", String.valueOf(deviceStatusCheck)); jsonObject.addProperty("deviceStatusCheck", String.valueOf(deviceStatusCheck));
@ -289,6 +323,11 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
return metadata; return metadata;
} }
/**
* Get default list of device status items from the configuration.
*
* @return List of device status items
*/
private List<DeviceStatusItem> getDefaultDeviceStatus() { private List<DeviceStatusItem> getDefaultDeviceStatus() {
DeviceStatusConfigurations deviceStatusConfigurations = UIConfigurationManager.getInstance().getUIConfig().getDeviceStatusConfigurations(); DeviceStatusConfigurations deviceStatusConfigurations = UIConfigurationManager.getInstance().getUIConfig().getDeviceStatusConfigurations();
List<DeviceStatusItem> deviceStatusItems = new ArrayList<>(); List<DeviceStatusItem> deviceStatusItems = new ArrayList<>();
@ -305,6 +344,11 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
return deviceStatusItems; return deviceStatusItems;
} }
/**
* Get Default device status check from the configuration.
*
* @return default status check value, it will be either 'True' or 'False'
*/
private boolean getDefaultDeviceStatusCheck() { private boolean getDefaultDeviceStatusCheck() {
DeviceStatusConfigurations deviceStatusConfigurations = UIConfigurationManager.getInstance().getUIConfig().getDeviceStatusConfigurations(); DeviceStatusConfigurations deviceStatusConfigurations = UIConfigurationManager.getInstance().getUIConfig().getDeviceStatusConfigurations();
boolean deviceStatusCheck = false; boolean deviceStatusCheck = false;

@ -107,13 +107,13 @@ public class MetaRepositoryBasedLicenseManager implements LicenseManager {
} else { } else {
metadataManagementService.createMetadata(metadata); metadataManagementService.createMetadata(metadata);
} }
} catch (MetadataManagementException e) { } catch (MetadataKeyAlreadyExistsException e) {
String msg = "Error occurred while saving the licence value in meta data repository"; String msg = "Error occurred while saving the licence key and licence key exist.Licence Key: "
+ licenceKey;
log.error(msg, e); log.error(msg, e);
throw new LicenseManagementException(msg, e); throw new LicenseManagementException(msg, e);
} catch (MetadataKeyAlreadyExistsException e) { } catch (MetadataManagementException e) {
String msg = String msg = "Error occurred while saving the licence value in meta data repository";
"Error occurred while saving the licence key and licence key exist. Licence Key: " + licenceKey;
log.error(msg, e); log.error(msg, e);
throw new LicenseManagementException(msg, e); throw new LicenseManagementException(msg, e);
} }

Loading…
Cancel
Save