Search in sources :

Example 1 with BusinessObjectDataStatusHistoryEntity

use of org.finra.herd.model.jpa.BusinessObjectDataStatusHistoryEntity in project herd by FINRAOS.

the class BusinessObjectDataDaoHelper method updateBusinessObjectDataStatus.

/**
 * Update the business object data status.
 *
 * @param businessObjectDataEntity the business object data entity
 * @param status the status
 */
public void updateBusinessObjectDataStatus(BusinessObjectDataEntity businessObjectDataEntity, String status) {
    // Retrieve and ensure the status is valid.
    BusinessObjectDataStatusEntity businessObjectDataStatusEntity = businessObjectDataStatusDaoHelper.getBusinessObjectDataStatusEntity(status);
    // Save the current status value.
    String oldStatus = businessObjectDataEntity.getStatus().getCode();
    // Update the entity with the new values.
    businessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
    // Add an entry to the business object data status history table
    BusinessObjectDataStatusHistoryEntity businessObjectDataStatusHistoryEntity = new BusinessObjectDataStatusHistoryEntity();
    businessObjectDataEntity.getHistoricalStatuses().add(businessObjectDataStatusHistoryEntity);
    businessObjectDataStatusHistoryEntity.setBusinessObjectData(businessObjectDataEntity);
    businessObjectDataStatusHistoryEntity.setStatus(businessObjectDataStatusEntity);
    // Persist the entity.
    businessObjectDataDao.saveAndRefresh(businessObjectDataEntity);
    // Sent a business object data status change notification.
    messageNotificationEventService.processBusinessObjectDataStatusChangeNotificationEvent(businessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataEntity), businessObjectDataStatusEntity.getCode(), oldStatus);
}
Also used : BusinessObjectDataStatusHistoryEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusHistoryEntity) BusinessObjectDataStatusEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)

Example 2 with BusinessObjectDataStatusHistoryEntity

use of org.finra.herd.model.jpa.BusinessObjectDataStatusHistoryEntity in project herd by FINRAOS.

the class CleanupDestroyedBusinessObjectDataServiceImplTest method testCleanupS3StorageUnit.

@Test
public void testCleanupS3StorageUnit() {
    // Create some data for testing the cleanup
    BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey = createDatabaseEntitiesForCleanupDestroyedBusinessObjectDataTesting();
    // Get a business object data key.
    BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.createBusinessObjectDataKeyFromStorageUnitKey(businessObjectDataStorageUnitKey);
    // Confirm the business object data entity exists.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDao.getBusinessObjectDataByAltKey(businessObjectDataKey);
    assertThat("The business object data entity is null.", businessObjectDataEntity, is(notNullValue()));
    // Confirm the business object data attribute exists.
    BusinessObjectDataAttributeKey businessObjectDataAttributeKey = businessObjectDataAttributeHelper.getBusinessObjectDataAttributeKey(businessObjectDataKey, ATTRIBUTE_NAME);
    assertThat("The business object data attribute key is null.", businessObjectDataAttributeKey, is(notNullValue()));
    assertThat("The business object data entity attributes size is not correct.", businessObjectDataEntity.getAttributes().size(), is(equalTo(1)));
    // Confirm the business object data attribute exists.
    BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = businessObjectDataAttributeDao.getBusinessObjectDataAttributeByKey(businessObjectDataAttributeKey);
    assertThat("The business object data attribute entity is null.", businessObjectDataAttributeEntity, is(notNullValue()));
    // Confirm the storage unity exists.
    StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntityByKey(businessObjectDataStorageUnitKey);
    assertThat("The storage unit entity is null.", storageUnitEntity, is(notNullValue()));
    // Confirm the storage file exists.
    StorageFileEntity storageFileEntity = storageFileDao.getStorageFileByStorageNameAndFilePath(STORAGE_NAME, STORAGE_DIRECTORY_PATH);
    assertThat("The storage file entity is null.", storageFileEntity, is(notNullValue()));
    // Confirm the business object data status history exists.
    Collection<BusinessObjectDataStatusHistoryEntity> businessObjectDataStatusHistoryEntities = businessObjectDataEntity.getHistoricalStatuses();
    assertThat("The business object data status history entities size is not correct.", businessObjectDataStatusHistoryEntities.size(), is(equalTo(1)));
    // Confirm the business object data children
    assertThat("The business object data children size is not correct.", businessObjectDataEntity.getBusinessObjectDataChildren().size(), is(equalTo(1)));
    BusinessObjectDataEntity businessObjectDataEntityChild = businessObjectDataEntity.getBusinessObjectDataChildren().get(0);
    assertThat("The business object data children is not correct.", businessObjectDataEntityChild.getBusinessObjectDataParents().get(0), is(businessObjectDataEntity));
    // Confirm the business object data parents
    assertThat("The business object data parents size is not correct.", businessObjectDataEntity.getBusinessObjectDataParents().size(), is(equalTo(1)));
    assertThat(businessObjectDataEntityChild.getBusinessObjectDataParents().get(0), is(businessObjectDataEntity));
    BusinessObjectDataEntity businessObjectDataEntityParent = businessObjectDataEntity.getBusinessObjectDataParents().get(0);
    assertThat("The business object data parent is not correct.", businessObjectDataEntityParent.getBusinessObjectDataChildren().get(0), is(businessObjectDataEntity));
    // All traces of BData are removed: BData record, Attributes, related Storage Units and Storage Files, Status history, parent-child relationships
    cleanupDestroyedBusinessObjectDataService.cleanupS3StorageUnit(businessObjectDataStorageUnitKey);
    // Verify the business object data has been removed.
    businessObjectDataEntity = businessObjectDataDao.getBusinessObjectDataByAltKey(businessObjectDataKey);
    assertThat("The business object data entity is not null.", businessObjectDataEntity, is(nullValue()));
    // Verify the business object data attribute has been removed.
    businessObjectDataAttributeEntity = businessObjectDataAttributeDao.getBusinessObjectDataAttributeByKey(businessObjectDataAttributeKey);
    assertThat("The business object data attribute entity is not null.", businessObjectDataAttributeEntity, is(nullValue()));
    // Verify the storage unit has been removed.
    storageUnitEntity = storageUnitDao.getStorageUnitByKey(businessObjectDataStorageUnitKey);
    assertThat("The storage unit entity is not null.", storageUnitEntity, is(nullValue()));
    // Verify the storage file has been removed.
    storageFileEntity = storageFileDao.getStorageFileByStorageNameAndFilePath(STORAGE_NAME, STORAGE_DIRECTORY_PATH);
    assertThat("The storage file entity is not null.", storageFileEntity, is(nullValue()));
    // Verify the business object data children parent relationship has been removed
    businessObjectDataEntityChild = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataHelper.createBusinessObjectDataKeyFromEntity(businessObjectDataEntityChild));
    assertThat("The business object data children size is not correct.", businessObjectDataEntityChild.getBusinessObjectDataParents().size(), is(equalTo(0)));
    // // Verify the business object data parent child relationship has been removed
    businessObjectDataEntityParent = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataHelper.createBusinessObjectDataKeyFromEntity(businessObjectDataEntityParent));
    assertThat("The business object data parents size is not correct.", businessObjectDataEntityParent.getBusinessObjectDataChildren().size(), is(equalTo(0)));
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) BusinessObjectDataAttributeEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity) BusinessObjectDataStatusHistoryEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusHistoryEntity) StorageFileEntity(org.finra.herd.model.jpa.StorageFileEntity) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectDataAttributeKey(org.finra.herd.model.api.xml.BusinessObjectDataAttributeKey) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Test(org.junit.Test)

Example 3 with BusinessObjectDataStatusHistoryEntity

use of org.finra.herd.model.jpa.BusinessObjectDataStatusHistoryEntity in project herd by FINRAOS.

the class BusinessObjectDataDaoTestHelper method createBusinessObjectDataEntity.

/**
 * Creates and persists a new business object data entity.
 *
 * @return the newly created business object data entity.
 */
public BusinessObjectDataEntity createBusinessObjectDataEntity(BusinessObjectFormatEntity businessObjectFormatEntity, String businessObjectDataPartitionValue, List<String> businessObjectDataSubPartitionValues, Integer businessObjectDataVersion, Boolean businessObjectDataLatestVersion, BusinessObjectDataStatusEntity businessObjectDataStatusEntity) {
    BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
    businessObjectDataEntity.setVersion(businessObjectDataVersion);
    businessObjectDataEntity.setPartitionValue(businessObjectDataPartitionValue);
    if (businessObjectDataSubPartitionValues != null) {
        businessObjectDataEntity.setPartitionValue2(businessObjectDataSubPartitionValues.size() > 0 ? businessObjectDataSubPartitionValues.get(0) : null);
        businessObjectDataEntity.setPartitionValue3(businessObjectDataSubPartitionValues.size() > 1 ? businessObjectDataSubPartitionValues.get(1) : null);
        businessObjectDataEntity.setPartitionValue4(businessObjectDataSubPartitionValues.size() > 2 ? businessObjectDataSubPartitionValues.get(2) : null);
        businessObjectDataEntity.setPartitionValue5(businessObjectDataSubPartitionValues.size() > 3 ? businessObjectDataSubPartitionValues.get(3) : null);
    }
    businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity);
    businessObjectDataEntity.setLatestVersion(businessObjectDataLatestVersion);
    businessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
    // Add an entry to the business object data status history table.
    BusinessObjectDataStatusHistoryEntity businessObjectDataStatusHistoryEntity = new BusinessObjectDataStatusHistoryEntity();
    businessObjectDataStatusHistoryEntity.setBusinessObjectData(businessObjectDataEntity);
    businessObjectDataStatusHistoryEntity.setStatus(businessObjectDataStatusEntity);
    List<BusinessObjectDataStatusHistoryEntity> businessObjectDataStatusHistoryEntities = new ArrayList<>();
    businessObjectDataStatusHistoryEntities.add(businessObjectDataStatusHistoryEntity);
    businessObjectDataEntity.setHistoricalStatuses(businessObjectDataStatusHistoryEntities);
    return businessObjectDataDao.saveAndRefresh(businessObjectDataEntity);
}
Also used : BusinessObjectDataStatusHistoryEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusHistoryEntity) ArrayList(java.util.ArrayList) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity)

Example 4 with BusinessObjectDataStatusHistoryEntity

use of org.finra.herd.model.jpa.BusinessObjectDataStatusHistoryEntity in project herd by FINRAOS.

the class BusinessObjectDataDaoTestHelper method createBusinessObjectDataEntity.

/**
 * Creates and persists a new business object data entity.
 *
 * @return the newly created business object data entity.
 */
public BusinessObjectDataEntity createBusinessObjectDataEntity(BusinessObjectFormatEntity businessObjectFormatEntity, String businessObjectDataPartitionValue, List<String> businessObjectDataSubPartitionValues, Integer businessObjectDataVersion, Boolean businessObjectDataLatestVersion, BusinessObjectDataStatusEntity businessObjectDataStatusEntity, List<BusinessObjectDataEntity> businessObjectDataParents) {
    BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
    businessObjectDataEntity.setVersion(businessObjectDataVersion);
    businessObjectDataEntity.setPartitionValue(businessObjectDataPartitionValue);
    if (businessObjectDataSubPartitionValues != null) {
        businessObjectDataEntity.setPartitionValue2(businessObjectDataSubPartitionValues.size() > 0 ? businessObjectDataSubPartitionValues.get(0) : null);
        businessObjectDataEntity.setPartitionValue3(businessObjectDataSubPartitionValues.size() > 1 ? businessObjectDataSubPartitionValues.get(1) : null);
        businessObjectDataEntity.setPartitionValue4(businessObjectDataSubPartitionValues.size() > 2 ? businessObjectDataSubPartitionValues.get(2) : null);
        businessObjectDataEntity.setPartitionValue5(businessObjectDataSubPartitionValues.size() > 3 ? businessObjectDataSubPartitionValues.get(3) : null);
    }
    businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity);
    businessObjectDataEntity.setLatestVersion(businessObjectDataLatestVersion);
    businessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
    businessObjectDataEntity.setBusinessObjectDataParents(businessObjectDataParents);
    // Add an entry to the business object data status history table.
    BusinessObjectDataStatusHistoryEntity businessObjectDataStatusHistoryEntity = new BusinessObjectDataStatusHistoryEntity();
    businessObjectDataStatusHistoryEntity.setBusinessObjectData(businessObjectDataEntity);
    businessObjectDataStatusHistoryEntity.setStatus(businessObjectDataStatusEntity);
    List<BusinessObjectDataStatusHistoryEntity> businessObjectDataStatusHistoryEntities = new ArrayList<>();
    businessObjectDataStatusHistoryEntities.add(businessObjectDataStatusHistoryEntity);
    businessObjectDataEntity.setHistoricalStatuses(businessObjectDataStatusHistoryEntities);
    return businessObjectDataDao.saveAndRefresh(businessObjectDataEntity);
}
Also used : BusinessObjectDataStatusHistoryEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusHistoryEntity) ArrayList(java.util.ArrayList) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity)

Example 5 with BusinessObjectDataStatusHistoryEntity

use of org.finra.herd.model.jpa.BusinessObjectDataStatusHistoryEntity in project herd by FINRAOS.

the class BusinessObjectDataDaoHelper method createBusinessObjectData.

/**
 * Creates a new business object data from the request information.
 *
 * @param request the request
 * @param fileSizeRequired specifies if fileSizeBytes value is required or not
 *
 * @return the newly created and persisted business object data
 */
public BusinessObjectData createBusinessObjectData(BusinessObjectDataCreateRequest request, boolean fileSizeRequired) {
    if (StringUtils.isBlank(request.getStatus())) {
        request.setStatus(BusinessObjectDataStatusEntity.VALID);
    } else {
        request.setStatus(request.getStatus().trim());
    }
    // Get the status entity if status is specified else set it to VALID
    BusinessObjectDataStatusEntity businessObjectDataStatusEntity = businessObjectDataStatusDaoHelper.getBusinessObjectDataStatusEntity(request.getStatus());
    // Perform the validation.
    validateBusinessObjectDataCreateRequest(request, fileSizeRequired, businessObjectDataStatusEntity);
    // Get the business object format for the specified parameters and make sure it exists.
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(new BusinessObjectFormatKey(request.getNamespace(), request.getBusinessObjectDefinitionName(), request.getBusinessObjectFormatUsage(), request.getBusinessObjectFormatFileType(), request.getBusinessObjectFormatVersion()));
    attributeDaoHelper.validateAttributesAgainstBusinessObjectDataAttributeDefinitions(request.getAttributes(), businessObjectFormatEntity.getAttributeDefinitions());
    // Ensure the specified partition key matches what's configured within the business object format.
    Assert.isTrue(businessObjectFormatEntity.getPartitionKey().equalsIgnoreCase(request.getPartitionKey()), String.format("Partition key \"%s\" doesn't match configured business object format partition key \"%s\".", request.getPartitionKey(), businessObjectFormatEntity.getPartitionKey()));
    // Get the latest format version for this business object data, if it exists.
    BusinessObjectDataEntity existingBusinessObjectDataEntity = businessObjectDataDao.getBusinessObjectDataByAltKey(new BusinessObjectDataKey(request.getNamespace(), request.getBusinessObjectDefinitionName(), request.getBusinessObjectFormatUsage(), request.getBusinessObjectFormatFileType(), request.getBusinessObjectFormatVersion(), request.getPartitionValue(), request.getSubPartitionValues(), null));
    // Throw an error if this business object data already exists and createNewVersion flag is not set.
    if (existingBusinessObjectDataEntity != null && (!Boolean.TRUE.equals(request.isCreateNewVersion()) || Boolean.TRUE.equals(existingBusinessObjectDataEntity.getStatus().getPreRegistrationStatus()))) {
        throw new AlreadyExistsException("Unable to create business object data because it already exists.");
    }
    // Create a business object data entity from the request information.
    // Please note that simply adding 1 to the latest version without "DB locking" is sufficient here,
    // even for multi-threading, since we are relying on the DB having version as part of the alternate key.
    Integer businessObjectDataVersion = existingBusinessObjectDataEntity == null ? BusinessObjectDataEntity.BUSINESS_OBJECT_DATA_INITIAL_VERSION : existingBusinessObjectDataEntity.getVersion() + 1;
    BusinessObjectDataEntity newVersionBusinessObjectDataEntity = createBusinessObjectDataEntity(request, businessObjectFormatEntity, businessObjectDataVersion, businessObjectDataStatusEntity);
    // Update the existing latest business object data version entity, so it would not be flagged as the latest version anymore.
    if (existingBusinessObjectDataEntity != null) {
        existingBusinessObjectDataEntity.setLatestVersion(Boolean.FALSE);
        businessObjectDataDao.saveAndRefresh(existingBusinessObjectDataEntity);
    }
    // Add an entry to the business object data status history table.
    BusinessObjectDataStatusHistoryEntity businessObjectDataStatusHistoryEntity = new BusinessObjectDataStatusHistoryEntity();
    businessObjectDataStatusHistoryEntity.setBusinessObjectData(newVersionBusinessObjectDataEntity);
    businessObjectDataStatusHistoryEntity.setStatus(businessObjectDataStatusEntity);
    List<BusinessObjectDataStatusHistoryEntity> businessObjectDataStatusHistoryEntities = new ArrayList<>();
    businessObjectDataStatusHistoryEntities.add(businessObjectDataStatusHistoryEntity);
    newVersionBusinessObjectDataEntity.setHistoricalStatuses(businessObjectDataStatusHistoryEntities);
    // Persist the new entity.
    newVersionBusinessObjectDataEntity = businessObjectDataDao.saveAndRefresh(newVersionBusinessObjectDataEntity);
    // Create a status change notification to be sent on create business object data event.
    messageNotificationEventService.processBusinessObjectDataStatusChangeNotificationEvent(businessObjectDataHelper.getBusinessObjectDataKey(newVersionBusinessObjectDataEntity), businessObjectDataStatusEntity.getCode(), null);
    // Create and return the business object data object from the persisted entity.
    return businessObjectDataHelper.createBusinessObjectDataFromEntity(newVersionBusinessObjectDataEntity);
}
Also used : BusinessObjectDataStatusHistoryEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusHistoryEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectDataStatusEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusEntity) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) ArrayList(java.util.ArrayList) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey)

Aggregations

BusinessObjectDataStatusHistoryEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusHistoryEntity)6 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)5 ArrayList (java.util.ArrayList)4 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)3 BusinessObjectDataAttributeEntity (org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity)2 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)2 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)2 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)1 Attribute (org.finra.herd.model.api.xml.Attribute)1 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)1 BusinessObjectDataAttributeKey (org.finra.herd.model.api.xml.BusinessObjectDataAttributeKey)1 BusinessObjectDataStatusChangeEvent (org.finra.herd.model.api.xml.BusinessObjectDataStatusChangeEvent)1 BusinessObjectDataStorageUnitKey (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey)1 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)1 StorageFileEntity (org.finra.herd.model.jpa.StorageFileEntity)1 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)1 Test (org.junit.Test)1