|
|
@ -34,11 +34,11 @@ import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.MetadataDAO;
|
|
|
|
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.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.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;
|
|
|
@ -83,6 +83,12 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Adds default device status filters 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 addDefaultDeviceStatusFilters(int tenantId) throws MetadataManagementException {
|
|
|
|
private void addDefaultDeviceStatusFilters(int tenantId) throws MetadataManagementException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
MetadataManagementDAOFactory.beginTransaction();
|
|
|
|
MetadataManagementDAOFactory.beginTransaction();
|
|
|
@ -106,6 +112,12 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 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 {
|
|
|
|
private void addDefaultDeviceStatusCheck(int tenantId) throws MetadataManagementException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
MetadataManagementDAOFactory.beginTransaction();
|
|
|
|
MetadataManagementDAOFactory.beginTransaction();
|
|
|
@ -137,6 +149,9 @@ 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 {
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(deviceType)) {
|
|
|
|
|
|
|
|
throw new IllegalArgumentException("Device type must not be empty or null");
|
|
|
|
|
|
|
|
}
|
|
|
|
MetadataManagementDAOFactory.beginTransaction();
|
|
|
|
MetadataManagementDAOFactory.beginTransaction();
|
|
|
|
// 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);
|
|
|
@ -147,7 +162,7 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
|
|
|
|
|
|
|
|
|
|
|
|
// Find the status for the specified deviceType
|
|
|
|
// Find the status for the specified deviceType
|
|
|
|
for (AllowedDeviceStatus status : currentStatusList) {
|
|
|
|
for (AllowedDeviceStatus status : currentStatusList) {
|
|
|
|
if (status.getType().equalsIgnoreCase(deviceType)) {
|
|
|
|
if (deviceType.equalsIgnoreCase(status.getType())) {
|
|
|
|
// Update the status list for the specified deviceType
|
|
|
|
// Update the status list for the specified deviceType
|
|
|
|
status.setStatus(deviceStatus);
|
|
|
|
status.setStatus(deviceStatus);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -206,7 +221,7 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
|
|
|
|
public List<String> getDeviceStatusFilters(String deviceType, int tenantId) throws MetadataManagementException {
|
|
|
|
public List<String> getDeviceStatusFilters(String deviceType, int tenantId) throws MetadataManagementException {
|
|
|
|
List<AllowedDeviceStatus> statusList = retrieveAndParseMetadata(tenantId);
|
|
|
|
List<AllowedDeviceStatus> statusList = retrieveAndParseMetadata(tenantId);
|
|
|
|
for (AllowedDeviceStatus status : statusList) {
|
|
|
|
for (AllowedDeviceStatus status : statusList) {
|
|
|
|
if (status.getType().equalsIgnoreCase(deviceType)) {
|
|
|
|
if (deviceType.equalsIgnoreCase(status.getType())) {
|
|
|
|
return status.getStatus();
|
|
|
|
return status.getStatus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -214,6 +229,12 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
|
|
|
|
return Collections.emptyList();
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Retrieves and parses the allowed device status metadata for the specified tenant.
|
|
|
|
|
|
|
|
* @param tenantId the tenant ID for which to retrieve and parse the metadata.
|
|
|
|
|
|
|
|
* @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(int tenantId) throws MetadataManagementException {
|
|
|
|
private List<AllowedDeviceStatus> retrieveAndParseMetadata(int tenantId) throws MetadataManagementException {
|
|
|
|
MetadataManagementService metadataManagementService = new MetadataManagementServiceImpl();
|
|
|
|
MetadataManagementService metadataManagementService = new MetadataManagementServiceImpl();
|
|
|
|
Metadata metadata = metadataManagementService.retrieveMetadata(MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
|
|
|
Metadata metadata = metadataManagementService.retrieveMetadata(MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
|
|
@ -245,6 +266,9 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean isDeviceStatusValid(String deviceType, String deviceStatus, int tenantId) throws MetadataManagementException {
|
|
|
|
public boolean isDeviceStatusValid(String deviceType, String deviceStatus, int tenantId) throws MetadataManagementException {
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(deviceType)) {
|
|
|
|
|
|
|
|
throw new IllegalArgumentException("Device type must not be empty or null");
|
|
|
|
|
|
|
|
}
|
|
|
|
MetadataManagementService metadataManagementService = new MetadataManagementServiceImpl();
|
|
|
|
MetadataManagementService metadataManagementService = new MetadataManagementServiceImpl();
|
|
|
|
Metadata metadata = metadataManagementService.retrieveMetadata(MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
|
|
|
Metadata metadata = metadataManagementService.retrieveMetadata(MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
|
|
|
String metaValue;
|
|
|
|
String metaValue;
|
|
|
@ -260,7 +284,7 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
|
|
|
|
List<AllowedDeviceStatus> statusList = gson.fromJson(metaValue, listType);
|
|
|
|
List<AllowedDeviceStatus> statusList = gson.fromJson(metaValue, listType);
|
|
|
|
|
|
|
|
|
|
|
|
for (AllowedDeviceStatus status : statusList) {
|
|
|
|
for (AllowedDeviceStatus status : statusList) {
|
|
|
|
if (status.getType().equalsIgnoreCase(deviceType)) {
|
|
|
|
if (deviceType.equalsIgnoreCase(status.getType())) {
|
|
|
|
List<String> allowedStatus = status.getStatus();
|
|
|
|
List<String> allowedStatus = status.getStatus();
|
|
|
|
return allowedStatus.contains(deviceStatus);
|
|
|
|
return allowedStatus.contains(deviceStatus);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -290,7 +314,6 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -300,7 +323,6 @@ 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -316,7 +338,6 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
|
|
|
|
log.debug("DeviceStatusConfigurations is null.");
|
|
|
|
log.debug("DeviceStatusConfigurations is null.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return deviceStatusItems;
|
|
|
|
return deviceStatusItems;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|