|
|
@ -50,8 +50,11 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
|
|
|
|
|
|
|
|
|
|
|
|
private final MetadataDAO metadataDAO;
|
|
|
|
private final MetadataDAO metadataDAO;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Gson gson;
|
|
|
|
|
|
|
|
|
|
|
|
public DeviceStatusManagementServiceImpl() {
|
|
|
|
public DeviceStatusManagementServiceImpl() {
|
|
|
|
this.metadataDAO = MetadataManagementDAOFactory.getMetadataDAO();
|
|
|
|
this.metadataDAO = MetadataManagementDAOFactory.getMetadataDAO();
|
|
|
|
|
|
|
|
this.gson = new Gson();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -138,7 +141,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);
|
|
|
@ -198,54 +200,37 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<AllowedDeviceStatus> getDeviceStatusFilters(int tenantId) throws MetadataManagementException {
|
|
|
|
public List<AllowedDeviceStatus> getDeviceStatusFilters(int tenantId) throws MetadataManagementException {
|
|
|
|
try {
|
|
|
|
return retrieveAndParseMetadata(tenantId);
|
|
|
|
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 {
|
|
|
|
|
|
|
|
List<AllowedDeviceStatus> statusList = retrieveAndParseMetadata(tenantId);
|
|
|
|
|
|
|
|
for (AllowedDeviceStatus status : statusList) {
|
|
|
|
|
|
|
|
if (status.getType().equalsIgnoreCase(deviceType)) {
|
|
|
|
|
|
|
|
return status.getStatus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Device type not found in metadata
|
|
|
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<String> getDeviceStatusFilters(String deviceType, 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);
|
|
|
|
Gson gson = new Gson();
|
|
|
|
|
|
|
|
String metaValue;
|
|
|
|
String metaValue;
|
|
|
|
if (metadata != null) {
|
|
|
|
if (metadata != null) {
|
|
|
|
metaValue = metadata.getMetaValue();
|
|
|
|
metaValue = metadata.getMetaValue();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
List<DeviceStatusItem> statusList = getDefaultDeviceStatus();
|
|
|
|
List<DeviceStatusItem> defaultStatusList = getDefaultDeviceStatus();
|
|
|
|
metaValue = gson.toJson(statusList);
|
|
|
|
metaValue = gson.toJson(defaultStatusList);
|
|
|
|
addDefaultDeviceStatusFilters(tenantId);
|
|
|
|
addDefaultDeviceStatusFilters(tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {
|
|
|
|
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {}.getType();
|
|
|
|
}.getType();
|
|
|
|
return gson.fromJson(metaValue, listType);
|
|
|
|
List<AllowedDeviceStatus> statusList = gson.fromJson(metaValue, listType);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (AllowedDeviceStatus status : statusList) {
|
|
|
|
|
|
|
|
if (status.getType().equalsIgnoreCase(deviceType)) {
|
|
|
|
|
|
|
|
return status.getStatus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Device type not found in metadata
|
|
|
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean getDeviceStatusCheck(int tenantId) throws MetadataManagementException {
|
|
|
|
public boolean getDeviceStatusCheck(int tenantId) throws MetadataManagementException {
|
|
|
|
MetadataManagementService metadataManagementService = new MetadataManagementServiceImpl();
|
|
|
|
MetadataManagementService metadataManagementService = new MetadataManagementServiceImpl();
|
|
|
@ -263,7 +248,6 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
|
|
|
|
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;
|
|
|
|
Gson gson = new Gson();
|
|
|
|
|
|
|
|
if (metadata != null) {
|
|
|
|
if (metadata != null) {
|
|
|
|
metaValue = metadata.getMetaValue();
|
|
|
|
metaValue = metadata.getMetaValue();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|