use of org.finra.herd.model.jpa.StorageUnitStatusHistoryEntity in project herd by FINRAOS.
the class StorageUnitDaoHelper method updateStorageUnitStatus.
/**
* Updates storage unit status value for a storage unit. This method also updates the storage unit status history and generates a storage unit status
* change notification event as per system configuration.
*
* @param storageUnitEntity the storage unit entity
* @param storageUnitStatusEntity the new storage unit status entity
* @param reason the reason for the update
*/
public void updateStorageUnitStatus(StorageUnitEntity storageUnitEntity, StorageUnitStatusEntity storageUnitStatusEntity, String reason) {
// Save the current status value.
String oldStatus = storageUnitEntity.getStatus().getCode();
// Update the entity with the new values.
storageUnitEntity.setStatus(storageUnitStatusEntity);
// Add an entry to the storage unit status history table.
StorageUnitStatusHistoryEntity storageUnitStatusHistoryEntity = new StorageUnitStatusHistoryEntity();
storageUnitEntity.getHistoricalStatuses().add(storageUnitStatusHistoryEntity);
storageUnitStatusHistoryEntity.setStorageUnit(storageUnitEntity);
storageUnitStatusHistoryEntity.setStatus(storageUnitStatusEntity);
storageUnitStatusHistoryEntity.setReason(reason);
// Persist the entity.
storageUnitDao.saveAndRefresh(storageUnitEntity);
// Send a storage unit status change notification as per system configuration.
messageNotificationEventService.processStorageUnitStatusChangeNotificationEvent(businessObjectDataHelper.getBusinessObjectDataKey(storageUnitEntity.getBusinessObjectData()), storageUnitEntity.getStorage().getName(), storageUnitStatusEntity.getCode(), oldStatus);
}
use of org.finra.herd.model.jpa.StorageUnitStatusHistoryEntity in project herd by FINRAOS.
the class StorageUnitHelper method createStorageUnitsFromEntities.
/**
* Creates a list of storage units from the list of storage unit entities.
*
* @param storageUnitEntities the storage unit entities.
* @param includeStorageUnitStatusHistory specifies to include storage unit status history for each storage unit in the response
*
* @return the list of storage units.
*/
public List<StorageUnit> createStorageUnitsFromEntities(Collection<StorageUnitEntity> storageUnitEntities, Boolean includeStorageUnitStatusHistory) {
List<StorageUnit> storageUnits = new ArrayList<>();
for (StorageUnitEntity storageUnitEntity : storageUnitEntities) {
StorageUnit storageUnit = new StorageUnit();
storageUnits.add(storageUnit);
Storage storage = new Storage();
storageUnit.setStorage(storage);
StorageEntity storageEntity = storageUnitEntity.getStorage();
storage.setName(storageEntity.getName());
storage.setStoragePlatformName(storageEntity.getStoragePlatform().getName());
// Add the storage attributes.
if (!CollectionUtils.isEmpty(storageEntity.getAttributes())) {
List<Attribute> storageAttributes = new ArrayList<>();
storage.setAttributes(storageAttributes);
for (StorageAttributeEntity storageAttributeEntity : storageEntity.getAttributes()) {
Attribute attribute = new Attribute();
storageAttributes.add(attribute);
attribute.setName(storageAttributeEntity.getName());
attribute.setValue(storageAttributeEntity.getValue());
}
}
// Add the storage directory.
if (storageUnitEntity.getDirectoryPath() != null) {
StorageDirectory storageDirectory = new StorageDirectory();
storageUnit.setStorageDirectory(storageDirectory);
storageDirectory.setDirectoryPath(storageUnitEntity.getDirectoryPath());
}
// Add the storage files.
if (!storageUnitEntity.getStorageFiles().isEmpty()) {
List<StorageFile> storageFiles = new ArrayList<>();
storageUnit.setStorageFiles(storageFiles);
for (StorageFileEntity storageFileEntity : storageUnitEntity.getStorageFiles()) {
storageFiles.add(storageFileHelper.createStorageFileFromEntity(storageFileEntity));
}
}
// Set the storage unit status.
storageUnit.setStorageUnitStatus(storageUnitEntity.getStatus().getCode());
// If specified, add storage unit status history.
if (BooleanUtils.isTrue(includeStorageUnitStatusHistory)) {
List<StorageUnitStatusChangeEvent> storageUnitStatusChangeEvents = new ArrayList<>();
storageUnit.setStorageUnitStatusHistory(storageUnitStatusChangeEvents);
for (StorageUnitStatusHistoryEntity storageUnitStatusHistoryEntity : storageUnitEntity.getHistoricalStatuses()) {
storageUnitStatusChangeEvents.add(new StorageUnitStatusChangeEvent(storageUnitStatusHistoryEntity.getStatus().getCode(), HerdDateUtils.getXMLGregorianCalendarValue(storageUnitStatusHistoryEntity.getCreatedOn()), storageUnitStatusHistoryEntity.getCreatedBy()));
}
}
// Set the number of failed attempts to execute a storage policy transition.
storageUnit.setStoragePolicyTransitionFailedAttempts(storageUnitEntity.getStoragePolicyTransitionFailedAttempts());
if (storageUnitEntity.getRestoreExpirationOn() != null) {
storageUnit.setRestoreExpirationOn(HerdDateUtils.getXMLGregorianCalendarValue(storageUnitEntity.getRestoreExpirationOn()));
}
}
return storageUnits;
}
Aggregations