Search in sources :

Example 1 with StorageUnitStatusChangeEvent

use of org.finra.herd.model.api.xml.StorageUnitStatusChangeEvent in project herd by FINRAOS.

the class BusinessObjectDataServiceGetBusinessObjectDataTest method testGetBusinessObjectDataIncludeStorageUnitStatusHistory.

@Test
public void testGetBusinessObjectDataIncludeStorageUnitStatusHistory() {
    // Create a business object data key.
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION);
    // Create a business object data storage unit key.
    BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey = new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME);
    // Create a storage unit entity.
    StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, businessObjectDataKey, StorageUnitStatusEntity.DISABLED);
    // Execute a storage unit status change.
    businessObjectDataStorageUnitStatusService.updateBusinessObjectDataStorageUnitStatus(businessObjectDataStorageUnitKey, new BusinessObjectDataStorageUnitStatusUpdateRequest(StorageUnitStatusEntity.ENABLED));
    // Retrieve the business object data with enabled include storage unit status history flag.
    BusinessObjectData resultBusinessObjectData = businessObjectDataService.getBusinessObjectData(businessObjectDataKey, PARTITION_KEY, NO_BDATA_STATUS, NO_INCLUDE_BUSINESS_OBJECT_DATA_STATUS_HISTORY, INCLUDE_STORAGE_UNIT_STATUS_HISTORY);
    // Build the expected response object. The storage unit history record is expected to have system username for the createdBy auditable field.
    BusinessObjectData expectedBusinessObjectData = new BusinessObjectData(storageUnitEntity.getBusinessObjectData().getId(), BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BDATA_STATUS, Arrays.asList(new StorageUnit(new Storage(STORAGE_NAME, StoragePlatformEntity.S3, null), NO_STORAGE_DIRECTORY, null, StorageUnitStatusEntity.ENABLED, Arrays.asList(new StorageUnitStatusChangeEvent(StorageUnitStatusEntity.ENABLED, HerdDateUtils.getXMLGregorianCalendarValue(IterableUtils.get(storageUnitEntity.getHistoricalStatuses(), 0).getCreatedOn()), HerdDaoSecurityHelper.SYSTEM_USER)), NO_STORAGE_POLICY_TRANSITION_FAILED_ATTEMPTS, NO_RESTORE_EXPIRATION_ON)), NO_ATTRIBUTES, NO_BUSINESS_OBJECT_DATA_PARENTS, NO_BUSINESS_OBJECT_DATA_CHILDREN, NO_BUSINESS_OBJECT_DATA_STATUS_HISTORY);
    // Validate the returned response object.
    assertEquals(expectedBusinessObjectData, resultBusinessObjectData);
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) StorageUnitStatusChangeEvent(org.finra.herd.model.api.xml.StorageUnitStatusChangeEvent) Storage(org.finra.herd.model.api.xml.Storage) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) StorageUnit(org.finra.herd.model.api.xml.StorageUnit) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectDataStorageUnitStatusUpdateRequest(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitStatusUpdateRequest) Test(org.junit.Test)

Example 2 with StorageUnitStatusChangeEvent

use of org.finra.herd.model.api.xml.StorageUnitStatusChangeEvent 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;
}
Also used : StorageUnitStatusChangeEvent(org.finra.herd.model.api.xml.StorageUnitStatusChangeEvent) StorageUnitStatusHistoryEntity(org.finra.herd.model.jpa.StorageUnitStatusHistoryEntity) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) Attribute(org.finra.herd.model.api.xml.Attribute) StorageAttributeEntity(org.finra.herd.model.jpa.StorageAttributeEntity) ArrayList(java.util.ArrayList) StorageUnit(org.finra.herd.model.api.xml.StorageUnit) StorageEntity(org.finra.herd.model.jpa.StorageEntity) StorageDirectory(org.finra.herd.model.api.xml.StorageDirectory) Storage(org.finra.herd.model.api.xml.Storage) StorageFileEntity(org.finra.herd.model.jpa.StorageFileEntity) StorageFile(org.finra.herd.model.api.xml.StorageFile)

Example 3 with StorageUnitStatusChangeEvent

use of org.finra.herd.model.api.xml.StorageUnitStatusChangeEvent in project herd by FINRAOS.

the class GetBusinessObjectDataTest method testGetBusinessObjectDataIncludeStorageUnitStatusHistory.

@Test
public void testGetBusinessObjectDataIncludeStorageUnitStatusHistory() throws Exception {
    // Create a business object data key.
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION);
    // Create a business object data storage unit key.
    BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey = new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME);
    // Create a storage unit entity.
    StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, businessObjectDataKey, StorageUnitStatusEntity.DISABLED);
    // Execute a storage unit status change.
    businessObjectDataStorageUnitStatusService.updateBusinessObjectDataStorageUnitStatus(businessObjectDataStorageUnitKey, new BusinessObjectDataStorageUnitStatusUpdateRequest(StorageUnitStatusEntity.ENABLED));
    List<FieldExtension> fieldExtensionList = new ArrayList<>();
    fieldExtensionList.add(buildFieldExtension("namespace", "${namespace}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectDefinitionName", "${businessObjectDefinitionName}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectFormatUsage", "${businessObjectFormatUsage}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectFormatFileType", "${businessObjectFormatFileType}"));
    fieldExtensionList.add(buildFieldExtension("partitionValue", "${partitionValue}"));
    fieldExtensionList.add(buildFieldExtension("subPartitionValues", "${subPartitionValues}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectFormatVersion", "${businessObjectFormatVersion}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectDataVersion", "${businessObjectDataVersion}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectDataStatus", "${businessObjectDataStatus}"));
    fieldExtensionList.add(buildFieldExtension("includeBusinessObjectDataStatusHistory", "${includeBusinessObjectDataStatusHistory}"));
    fieldExtensionList.add(buildFieldExtension("includeStorageUnitStatusHistory", "${includeStorageUnitStatusHistory}"));
    List<Parameter> parameters = new ArrayList<>();
    parameters.add(buildParameter("namespace", BDEF_NAMESPACE));
    parameters.add(buildParameter("businessObjectDefinitionName", BDEF_NAME));
    parameters.add(buildParameter("businessObjectFormatUsage", FORMAT_USAGE_CODE));
    parameters.add(buildParameter("businessObjectFormatFileType", FORMAT_FILE_TYPE_CODE));
    parameters.add(buildParameter("partitionValue", PARTITION_VALUE));
    parameters.add(buildParameter("subPartitionValues", herdStringHelper.buildStringWithDefaultDelimiter(SUBPARTITION_VALUES)));
    parameters.add(buildParameter("businessObjectFormatVersion", FORMAT_VERSION.toString()));
    parameters.add(buildParameter("businessObjectDataVersion", DATA_VERSION.toString()));
    parameters.add(buildParameter("businessObjectDataStatus", BusinessObjectDataStatusEntity.VALID));
    parameters.add(buildParameter("includeBusinessObjectDataStatusHistory", NO_INCLUDE_BUSINESS_OBJECT_DATA_STATUS_HISTORY.toString()));
    parameters.add(buildParameter("includeStorageUnitStatusHistory", INCLUDE_STORAGE_UNIT_STATUS_HISTORY.toString()));
    // Build the expected response object. The storage unit history record is expected to have system username for the createdBy auditable field.
    BusinessObjectData expectedBusinessObjectData = new BusinessObjectData(storageUnitEntity.getBusinessObjectData().getId(), BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BDATA_STATUS, Arrays.asList(new StorageUnit(new Storage(STORAGE_NAME, StoragePlatformEntity.S3, null), NO_STORAGE_DIRECTORY, null, StorageUnitStatusEntity.ENABLED, Arrays.asList(new StorageUnitStatusChangeEvent(StorageUnitStatusEntity.ENABLED, HerdDateUtils.getXMLGregorianCalendarValue(IterableUtils.get(storageUnitEntity.getHistoricalStatuses(), 0).getCreatedOn()), HerdDaoSecurityHelper.SYSTEM_USER)), NO_STORAGE_POLICY_TRANSITION_FAILED_ATTEMPTS, NO_RESTORE_EXPIRATION_ON)), NO_ATTRIBUTES, NO_BUSINESS_OBJECT_DATA_PARENTS, NO_BUSINESS_OBJECT_DATA_CHILDREN, NO_BUSINESS_OBJECT_DATA_STATUS_HISTORY);
    // Run the activiti task and validate the returned response object.
    Map<String, Object> variableValuesToValidate = new HashMap<>();
    variableValuesToValidate.put(GetBusinessObjectDataStatus.VARIABLE_JSON_RESPONSE, jsonHelper.objectToJson(expectedBusinessObjectData));
    testActivitiServiceTaskSuccess(GetBusinessObjectData.class.getCanonicalName(), fieldExtensionList, parameters, variableValuesToValidate);
}
Also used : StorageUnitStatusChangeEvent(org.finra.herd.model.api.xml.StorageUnitStatusChangeEvent) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StorageUnit(org.finra.herd.model.api.xml.StorageUnit) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) Storage(org.finra.herd.model.api.xml.Storage) FieldExtension(org.activiti.bpmn.model.FieldExtension) Parameter(org.finra.herd.model.api.xml.Parameter) BusinessObjectDataStorageUnitStatusUpdateRequest(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitStatusUpdateRequest) Test(org.junit.Test)

Aggregations

Storage (org.finra.herd.model.api.xml.Storage)3 StorageUnit (org.finra.herd.model.api.xml.StorageUnit)3 StorageUnitStatusChangeEvent (org.finra.herd.model.api.xml.StorageUnitStatusChangeEvent)3 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)3 ArrayList (java.util.ArrayList)2 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)2 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)2 BusinessObjectDataStorageUnitKey (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey)2 BusinessObjectDataStorageUnitStatusUpdateRequest (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitStatusUpdateRequest)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 FieldExtension (org.activiti.bpmn.model.FieldExtension)1 Attribute (org.finra.herd.model.api.xml.Attribute)1 Parameter (org.finra.herd.model.api.xml.Parameter)1 StorageDirectory (org.finra.herd.model.api.xml.StorageDirectory)1 StorageFile (org.finra.herd.model.api.xml.StorageFile)1 StorageAttributeEntity (org.finra.herd.model.jpa.StorageAttributeEntity)1 StorageEntity (org.finra.herd.model.jpa.StorageEntity)1 StorageFileEntity (org.finra.herd.model.jpa.StorageFileEntity)1 StorageUnitStatusHistoryEntity (org.finra.herd.model.jpa.StorageUnitStatusHistoryEntity)1