|
|
@ -18,64 +18,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
package io.entgra.device.mgt.core.device.mgt.core.metadata.mgt;
|
|
|
|
package io.entgra.device.mgt.core.device.mgt.core.metadata.mgt;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.google.common.cache.Cache;
|
|
|
|
|
|
|
|
import com.google.common.cache.CacheBuilder;
|
|
|
|
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.MetadataKeyAlreadyExistsException;
|
|
|
|
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.metadata.mgt.AllowedDeviceStatus;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.AllowedDeviceStatus;
|
|
|
|
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 io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.config.ui.DeviceStatusConfigurations;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.config.ui.DeviceStatusConfigurations;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.config.ui.DeviceStatusItem;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.config.ui.DeviceStatusItem;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.config.ui.UIConfigurationManager;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.config.ui.UIConfigurationManager;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.MetadataDAO;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.internal.DeviceManagementDataHolder;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.MetadataManagementDAOException;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.MetadataManagementDAOFactory;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.util.MetadataConstants;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.util.MetadataConstants;
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
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 java.lang.reflect.Type;
|
|
|
|
import java.lang.reflect.Type;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 static volatile DeviceStatusManagementServiceImpl instance;
|
|
|
|
|
|
|
|
|
|
|
|
public DeviceStatusManagementServiceImpl() {
|
|
|
|
private static final MetadataManagementService metadataManagementService = DeviceManagementDataHolder.getInstance().getMetadataManagementService();
|
|
|
|
this.metadataDAO = MetadataManagementDAOFactory.getMetadataDAO();
|
|
|
|
|
|
|
|
|
|
|
|
private final Gson gson;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Cache<String, List<AllowedDeviceStatus>> cache = CacheBuilder.newBuilder()
|
|
|
|
|
|
|
|
.expireAfterWrite(5, TimeUnit.HOURS)
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private DeviceStatusManagementServiceImpl() {
|
|
|
|
|
|
|
|
this.gson = new Gson();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static synchronized DeviceStatusManagementServiceImpl getInstance() {
|
|
|
|
|
|
|
|
if (instance == null) {
|
|
|
|
|
|
|
|
instance = new DeviceStatusManagementServiceImpl();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void addDefaultDeviceStatusFilterIfNotExist(int tenantId) throws MetadataManagementException {
|
|
|
|
public void addDefaultDeviceStatusFilterIfNotExist() throws MetadataManagementException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
MetadataManagementDAOFactory.beginTransaction();
|
|
|
|
|
|
|
|
if (!metadataDAO.isExist(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY) && !metadataDAO.isExist(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY)) {
|
|
|
|
|
|
|
|
Metadata defaultDeviceStatusMetadata = constructDeviceStatusMetadata(getDefaultDeviceStatus());
|
|
|
|
Metadata defaultDeviceStatusMetadata = constructDeviceStatusMetadata(getDefaultDeviceStatus());
|
|
|
|
Metadata defaultDeviceStatusCheckMetadata = constructDeviceStatusCheckMetadata(getDefaultDeviceStatusCheck());
|
|
|
|
Metadata defaultDeviceStatusCheckMetadata = constructDeviceStatusCheckMetadata(getDefaultDeviceStatusCheck());
|
|
|
|
// Add default device status and device status check metadata entries
|
|
|
|
// Add default device status and device status check metadata entries
|
|
|
|
addMetadataEntry(tenantId, defaultDeviceStatusMetadata, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
|
|
|
addMetadataEntry(defaultDeviceStatusMetadata, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
|
|
|
addMetadataEntry(tenantId, defaultDeviceStatusCheckMetadata, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
|
|
|
|
addMetadataEntry(defaultDeviceStatusCheckMetadata, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
|
|
|
|
}
|
|
|
|
} catch (MetadataKeyAlreadyExistsException e) {
|
|
|
|
MetadataManagementDAOFactory.commitTransaction();
|
|
|
|
log.error("Metadata is already exist.", e);
|
|
|
|
} catch (MetadataManagementDAOException e) {
|
|
|
|
}
|
|
|
|
MetadataManagementDAOFactory.rollbackTransaction();
|
|
|
|
}
|
|
|
|
String msg = "Error occurred while inserting default device status metadata entry.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
/**
|
|
|
|
throw new MetadataManagementException(msg, e);
|
|
|
|
* Adds default device status filters for a given tenant.
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
*
|
|
|
|
String msg = "Error occurred while opening a connection to the data source";
|
|
|
|
* @throws MetadataManagementException if an error occurs while adding the metadata or managing the transaction.
|
|
|
|
log.error(msg, e);
|
|
|
|
*/
|
|
|
|
throw new MetadataManagementException(msg, e);
|
|
|
|
private void addDefaultDeviceStatusFilters() throws MetadataManagementException {
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
MetadataManagementDAOFactory.closeConnection();
|
|
|
|
Metadata defaultDeviceStatusMetadata = constructDeviceStatusMetadata(getDefaultDeviceStatus());
|
|
|
|
|
|
|
|
// Add default device status metadata entries
|
|
|
|
|
|
|
|
addMetadataEntry(defaultDeviceStatusMetadata, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
|
|
|
|
|
|
|
} catch (MetadataKeyAlreadyExistsException e) {
|
|
|
|
|
|
|
|
log.error("Metadata is already exist.", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Adds default device status filter enable or not for a given tenant.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param tenantId the tenant ID for which to add the device status filters.
|
|
|
|
|
|
|
|
* @throws MetadataManagementException if an error occurs while adding the metadata or managing the transaction.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void addDefaultDeviceStatusCheck(int tenantId) throws MetadataManagementException {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Metadata defaultDeviceStatusCheckMetadata = constructDeviceStatusCheckMetadata(getDefaultDeviceStatusCheck());
|
|
|
|
|
|
|
|
// Add default device status check metadata entries
|
|
|
|
|
|
|
|
addMetadataEntry(defaultDeviceStatusCheckMetadata, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
|
|
|
|
|
|
|
|
} catch (MetadataKeyAlreadyExistsException e) {
|
|
|
|
|
|
|
|
log.error("Metadata is already exist.", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -86,196 +121,130 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void updateDefaultDeviceStatusFilters(int tenantId, String deviceType, List<String> deviceStatus) throws MetadataManagementException {
|
|
|
|
public void updateDefaultDeviceStatusFilters(int tenantId, String deviceType, List<String> deviceStatus) throws MetadataManagementException {
|
|
|
|
try {
|
|
|
|
if (StringUtils.isEmpty(deviceType)) {
|
|
|
|
MetadataManagementDAOFactory.beginTransaction();
|
|
|
|
String msg = "Device type must not be empty or null";
|
|
|
|
// Retrieve the current device status metadata
|
|
|
|
log.error(msg);
|
|
|
|
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
|
|
|
throw new IllegalArgumentException(msg);
|
|
|
|
if (metadata != null) {
|
|
|
|
}
|
|
|
|
Gson gson = new Gson();
|
|
|
|
// Retrieve the current device status metadata
|
|
|
|
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {
|
|
|
|
Metadata metadata = metadataManagementService.retrieveMetadata(MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
|
|
|
}.getType();
|
|
|
|
if (metadata != null) {
|
|
|
|
List<AllowedDeviceStatus> currentStatusList = gson.fromJson(metadata.getMetaValue(), listType);
|
|
|
|
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {
|
|
|
|
|
|
|
|
}.getType();
|
|
|
|
// Find the status for the specified deviceType
|
|
|
|
List<AllowedDeviceStatus> currentStatusList = gson.fromJson(metadata.getMetaValue(), listType);
|
|
|
|
for (AllowedDeviceStatus status : currentStatusList) {
|
|
|
|
|
|
|
|
if (status.getType().equalsIgnoreCase(deviceType)) {
|
|
|
|
// Find the status for the specified deviceType
|
|
|
|
// Update the status list for the specified deviceType
|
|
|
|
for (AllowedDeviceStatus status : currentStatusList) {
|
|
|
|
status.setStatus(deviceStatus);
|
|
|
|
if (deviceType.equalsIgnoreCase(status.getType())) {
|
|
|
|
break;
|
|
|
|
// Update the status list for the specified deviceType
|
|
|
|
}
|
|
|
|
status.setStatus(deviceStatus);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
metadata.setMetaValue(gson.toJson(currentStatusList));
|
|
|
|
|
|
|
|
updateMetadataEntry(tenantId, metadata, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MetadataManagementDAOFactory.commitTransaction();
|
|
|
|
metadata.setMetaValue(gson.toJson(currentStatusList));
|
|
|
|
} catch (MetadataManagementDAOException e) {
|
|
|
|
updateMetadataEntry(metadata, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
|
|
|
MetadataManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
|
|
|
String msg = "Error occurred while updating device status metadata entry.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new MetadataManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while opening a connection to the data source";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new MetadataManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
MetadataManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean updateDefaultDeviceStatusCheck(int tenantId, boolean isChecked) throws MetadataManagementException {
|
|
|
|
public boolean updateDefaultDeviceStatusCheck(boolean isChecked) throws MetadataManagementException {
|
|
|
|
boolean success = false;
|
|
|
|
Metadata isDeviceStatusChecked = constructDeviceStatusCheckMetadata(isChecked);
|
|
|
|
try {
|
|
|
|
// Add default device status check metadata entries
|
|
|
|
MetadataManagementDAOFactory.beginTransaction();
|
|
|
|
updateMetadataEntry(isDeviceStatusChecked, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
|
|
|
|
if (metadataDAO.isExist(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY)) {
|
|
|
|
return true;
|
|
|
|
Metadata isDeviceStatusChecked = constructDeviceStatusCheckMetadata(isChecked);
|
|
|
|
|
|
|
|
// Add default device status check metadata entries
|
|
|
|
|
|
|
|
updateMetadataEntry(tenantId, isDeviceStatusChecked, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
|
|
|
|
|
|
|
|
success = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
MetadataManagementDAOFactory.commitTransaction();
|
|
|
|
|
|
|
|
} catch (MetadataManagementDAOException e) {
|
|
|
|
|
|
|
|
MetadataManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
|
|
|
String msg = "Error occurred while updating device status check metadata entry.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new MetadataManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while opening a connection to the data source";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new MetadataManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
MetadataManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<AllowedDeviceStatus> getDeviceStatusFilters(int tenantId) throws MetadataManagementException {
|
|
|
|
public List<AllowedDeviceStatus> getDeviceStatusFilters() throws MetadataManagementException {
|
|
|
|
try {
|
|
|
|
return retrieveAndParseMetadata();
|
|
|
|
MetadataManagementDAOFactory.openConnection();
|
|
|
|
|
|
|
|
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
|
|
|
|
|
|
|
Gson gson = new Gson();
|
|
|
|
|
|
|
|
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {}.getType();
|
|
|
|
|
|
|
|
List<AllowedDeviceStatus> statusList = gson.fromJson(metadata.getMetaValue(), listType);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return statusList;
|
|
|
|
|
|
|
|
} catch (MetadataManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while retrieving device status meta data for tenant:" + tenantId;
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new MetadataManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while opening a connection to the data source";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new MetadataManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
MetadataManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<String> getDeviceStatusFilters(String deviceType, int tenantId) throws MetadataManagementException {
|
|
|
|
public List<String> getDeviceStatusFilters(String deviceType) throws MetadataManagementException {
|
|
|
|
try {
|
|
|
|
List<AllowedDeviceStatus> statusList = retrieveAndParseMetadata();
|
|
|
|
MetadataManagementDAOFactory.openConnection();
|
|
|
|
for (AllowedDeviceStatus status : statusList) {
|
|
|
|
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
|
|
|
if (deviceType.equalsIgnoreCase(status.getType())) {
|
|
|
|
Gson gson = new Gson();
|
|
|
|
return status.getStatus();
|
|
|
|
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {}.getType();
|
|
|
|
|
|
|
|
List<AllowedDeviceStatus> statusList = gson.fromJson(metadata.getMetaValue(), listType);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (AllowedDeviceStatus status : statusList) {
|
|
|
|
|
|
|
|
if (status.getType().equalsIgnoreCase(deviceType)) {
|
|
|
|
|
|
|
|
return status.getStatus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Device type not found in metadata
|
|
|
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
|
|
|
} catch (MetadataManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while retrieving device status meta data for tenant: " + tenantId;
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new MetadataManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while opening a connection to the data source";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new MetadataManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
MetadataManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Device type not found in metadata
|
|
|
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Retrieves and parses the allowed device status metadata for the specified tenant.
|
|
|
|
|
|
|
|
* @return a list of {@link AllowedDeviceStatus} objects parsed from the metadata.
|
|
|
|
|
|
|
|
* @throws MetadataManagementException if an error occurs while retrieving or parsing the metadata.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private List<AllowedDeviceStatus> retrieveAndParseMetadata() throws MetadataManagementException {
|
|
|
|
|
|
|
|
Metadata metadata = metadataManagementService.retrieveMetadata(MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
|
|
|
|
|
|
|
String metaValue;
|
|
|
|
|
|
|
|
if (metadata != null) {
|
|
|
|
|
|
|
|
metaValue = metadata.getMetaValue();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
List<DeviceStatusItem> defaultStatusList = getDefaultDeviceStatus();
|
|
|
|
|
|
|
|
metaValue = gson.toJson(defaultStatusList);
|
|
|
|
|
|
|
|
addDefaultDeviceStatusFilters();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {}.getType();
|
|
|
|
|
|
|
|
return gson.fromJson(metaValue, listType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean getDeviceStatusCheck(int tenantId) throws MetadataManagementException {
|
|
|
|
public boolean getDeviceStatusCheck(int tenantId) throws MetadataManagementException {
|
|
|
|
try {
|
|
|
|
Metadata metadata = metadataManagementService.retrieveMetadata(MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
|
|
|
|
MetadataManagementDAOFactory.openConnection();
|
|
|
|
if (metadata != null) {
|
|
|
|
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
|
|
|
|
return Boolean.parseBoolean(metadata.getMetaValue());
|
|
|
|
String metaValue = metadata.getMetaValue();
|
|
|
|
} else {
|
|
|
|
return Boolean.parseBoolean(metaValue);
|
|
|
|
addDefaultDeviceStatusCheck(tenantId);
|
|
|
|
} catch (MetadataManagementDAOException e) {
|
|
|
|
return getDefaultDeviceStatusCheck();
|
|
|
|
String msg = "Error occurred while retrieving device status check meta data for tenant:" + tenantId;
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new MetadataManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while opening a connection to the data source";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new MetadataManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
MetadataManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean isDeviceStatusValid(String deviceType, String deviceStatus, int tenantId) throws MetadataManagementException {
|
|
|
|
public boolean isDeviceStatusValid(String deviceType, String deviceStatus, int tenantId) throws MetadataManagementException {
|
|
|
|
try {
|
|
|
|
if (StringUtils.isEmpty(deviceType)) {
|
|
|
|
MetadataManagementDAOFactory.openConnection();
|
|
|
|
String msg = "Device type must not be empty or null";
|
|
|
|
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new IllegalArgumentException(msg);
|
|
|
|
Gson gson = new Gson();
|
|
|
|
}
|
|
|
|
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {
|
|
|
|
List<AllowedDeviceStatus> allowedDeviceStatus = cache.getIfPresent(Integer.toString(tenantId));
|
|
|
|
}.getType();
|
|
|
|
if (allowedDeviceStatus == null) {
|
|
|
|
List<AllowedDeviceStatus> statusList = gson.fromJson(metadata.getMetaValue(), listType);
|
|
|
|
allowedDeviceStatus = retrieveAndParseMetadata();
|
|
|
|
|
|
|
|
cache.put(Integer.toString(tenantId), allowedDeviceStatus);
|
|
|
|
for (AllowedDeviceStatus status : statusList) {
|
|
|
|
}
|
|
|
|
if (status.getType().equalsIgnoreCase(deviceType)) {
|
|
|
|
for (AllowedDeviceStatus status : allowedDeviceStatus) {
|
|
|
|
List<String> allowedStatus = status.getStatus();
|
|
|
|
if (deviceType.equalsIgnoreCase(status.getType())) {
|
|
|
|
return allowedStatus.contains(deviceStatus);
|
|
|
|
List<String> allowedStatus = status.getStatus();
|
|
|
|
}
|
|
|
|
return allowedStatus.contains(deviceStatus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false; // Device type not found in metadata
|
|
|
|
|
|
|
|
} catch (MetadataManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while retrieving device status meta data for tenant: " + tenantId;
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new MetadataManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while opening a connection to the data source";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new MetadataManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
MetadataManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false; // Device type not found in metadata
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void addMetadataEntry(int tenantId, Metadata metadata, String key) throws MetadataManagementDAOException {
|
|
|
|
private void addMetadataEntry(Metadata metadata, String key) throws MetadataManagementException, MetadataKeyAlreadyExistsException {
|
|
|
|
metadataDAO.addMetadata(tenantId, metadata);
|
|
|
|
metadata.setMetaKey(key);
|
|
|
|
|
|
|
|
metadataManagementService.createMetadata(metadata);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug(key + " metadata entry has been inserted successfully");
|
|
|
|
log.debug(key + " metadata entry has been inserted successfully");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void updateMetadataEntry(int tenantId, Metadata metadata, String key) throws MetadataManagementDAOException {
|
|
|
|
private void updateMetadataEntry(Metadata metadata, String key) throws MetadataManagementException {
|
|
|
|
metadataDAO.updateMetadata(tenantId, metadata);
|
|
|
|
metadata.setMetaKey(key);
|
|
|
|
|
|
|
|
metadataManagementService.updateMetadata(metadata);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug(key + " metadata entry has been updated successfully");
|
|
|
|
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();
|
|
|
|
metadata.setMetaKey(MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
|
|
|
metadata.setMetaKey(MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
|
|
|
metadata.setMetaValue(deviceStatusItemsJsonString);
|
|
|
|
metadata.setMetaValue(deviceStatusItemsJsonString);
|
|
|
|
|
|
|
|
|
|
|
|
return metadata;
|
|
|
|
return metadata;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -285,10 +254,16 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
|
|
|
|
Metadata metadata = new Metadata();
|
|
|
|
Metadata metadata = new Metadata();
|
|
|
|
metadata.setMetaKey(MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
|
|
|
|
metadata.setMetaKey(MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
|
|
|
|
metadata.setMetaValue(String.valueOf(deviceStatusCheck));
|
|
|
|
metadata.setMetaValue(String.valueOf(deviceStatusCheck));
|
|
|
|
|
|
|
|
|
|
|
|
return metadata;
|
|
|
|
return metadata;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Retrieves the default device status items.
|
|
|
|
|
|
|
|
* This method fetches the device status configurations from the UI configuration manager.
|
|
|
|
|
|
|
|
* If the configurations are available, it returns the list of device status items.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return a list of {@code DeviceStatusItem} objects representing the default device statuses.
|
|
|
|
|
|
|
|
*/
|
|
|
|
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<>();
|
|
|
@ -301,10 +276,16 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
|
|
|
|
log.debug("DeviceStatusConfigurations is null.");
|
|
|
|
log.debug("DeviceStatusConfigurations is null.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return deviceStatusItems;
|
|
|
|
return deviceStatusItems;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Retrieves the default device status check flag.
|
|
|
|
|
|
|
|
* This method fetches the device status configurations from the UI configuration manager.
|
|
|
|
|
|
|
|
* If the configurations are available, it returns the device status check flag.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return a boolean value indicating the default device status check flag.
|
|
|
|
|
|
|
|
*/
|
|
|
|
private boolean getDefaultDeviceStatusCheck() {
|
|
|
|
private boolean getDefaultDeviceStatusCheck() {
|
|
|
|
DeviceStatusConfigurations deviceStatusConfigurations = UIConfigurationManager.getInstance().getUIConfig().getDeviceStatusConfigurations();
|
|
|
|
DeviceStatusConfigurations deviceStatusConfigurations = UIConfigurationManager.getInstance().getUIConfig().getDeviceStatusConfigurations();
|
|
|
|
boolean deviceStatusCheck = false;
|
|
|
|
boolean deviceStatusCheck = false;
|
|
|
|
Add Java Doc comment.