Add Java Doc comments

pull/384/head
Pramila Niroshan 5 months ago
parent eb6186ba28
commit 8de7a00f39

@ -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.MetadataManagementDAOFactory;
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.LogFactory;
import java.lang.reflect.Type;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
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 {
try {
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 {
try {
MetadataManagementDAOFactory.beginTransaction();
@ -137,6 +149,9 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
@Override
public void updateDefaultDeviceStatusFilters(int tenantId, String deviceType, List<String> deviceStatus) throws MetadataManagementException {
try {
if (StringUtils.isEmpty(deviceType)) {
throw new IllegalArgumentException("Device type must not be empty or null");
}
MetadataManagementDAOFactory.beginTransaction();
// Retrieve the current device status metadata
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
for (AllowedDeviceStatus status : currentStatusList) {
if (status.getType().equalsIgnoreCase(deviceType)) {
if (deviceType.equalsIgnoreCase(status.getType())) {
// Update the status list for the specified deviceType
status.setStatus(deviceStatus);
break;
@ -206,7 +221,7 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
public List<String> getDeviceStatusFilters(String deviceType, int tenantId) throws MetadataManagementException {
List<AllowedDeviceStatus> statusList = retrieveAndParseMetadata(tenantId);
for (AllowedDeviceStatus status : statusList) {
if (status.getType().equalsIgnoreCase(deviceType)) {
if (deviceType.equalsIgnoreCase(status.getType())) {
return status.getStatus();
}
}
@ -214,6 +229,12 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
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 {
MetadataManagementService metadataManagementService = new MetadataManagementServiceImpl();
Metadata metadata = metadataManagementService.retrieveMetadata(MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
@ -245,6 +266,9 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
@Override
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();
Metadata metadata = metadataManagementService.retrieveMetadata(MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
String metaValue;
@ -260,7 +284,7 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
List<AllowedDeviceStatus> statusList = gson.fromJson(metaValue, listType);
for (AllowedDeviceStatus status : statusList) {
if (status.getType().equalsIgnoreCase(deviceType)) {
if (deviceType.equalsIgnoreCase(status.getType())) {
List<String> allowedStatus = status.getStatus();
return allowedStatus.contains(deviceStatus);
}
@ -290,7 +314,6 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
Metadata metadata = new Metadata();
metadata.setMetaKey(MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
metadata.setMetaValue(deviceStatusItemsJsonString);
return metadata;
}
@ -300,7 +323,6 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
Metadata metadata = new Metadata();
metadata.setMetaKey(MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
metadata.setMetaValue(String.valueOf(deviceStatusCheck));
return metadata;
}
@ -316,7 +338,6 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
log.debug("DeviceStatusConfigurations is null.");
}
}
return deviceStatusItems;
}

Loading…
Cancel
Save