Search in sources :

Example 31 with StorageUnitStatusEntity

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

the class BusinessObjectDataDaoImpl method getBusinessObjectDataEntitiesMatchingStoragePolicies.

@Override
public Map<BusinessObjectDataEntity, StoragePolicyEntity> getBusinessObjectDataEntitiesMatchingStoragePolicies(StoragePolicyPriorityLevel storagePolicyPriorityLevel, List<String> supportedBusinessObjectDataStatuses, int storagePolicyTransitionMaxAllowedAttempts, int startPosition, int maxResult) {
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> criteria = builder.createTupleQuery();
    // The criteria root is the business object data.
    Root<BusinessObjectDataEntity> businessObjectDataEntityRoot = criteria.from(BusinessObjectDataEntity.class);
    Root<StoragePolicyEntity> storagePolicyEntityRoot = criteria.from(StoragePolicyEntity.class);
    // Join to the other tables we can filter on.
    Join<BusinessObjectDataEntity, StorageUnitEntity> storageUnitEntityJoin = businessObjectDataEntityRoot.join(BusinessObjectDataEntity_.storageUnits);
    Join<StorageUnitEntity, StorageUnitStatusEntity> storageUnitStatusEntityJoin = storageUnitEntityJoin.join(StorageUnitEntity_.status);
    Join<BusinessObjectDataEntity, BusinessObjectDataStatusEntity> businessObjectDataStatusEntityJoin = businessObjectDataEntityRoot.join(BusinessObjectDataEntity_.status);
    Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> businessObjectFormatEntityJoin = businessObjectDataEntityRoot.join(BusinessObjectDataEntity_.businessObjectFormat);
    Join<BusinessObjectFormatEntity, FileTypeEntity> fileTypeEntityJoin = businessObjectFormatEntityJoin.join(BusinessObjectFormatEntity_.fileType);
    Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntityJoin = businessObjectFormatEntityJoin.join(BusinessObjectFormatEntity_.businessObjectDefinition);
    Join<StoragePolicyEntity, StoragePolicyTransitionTypeEntity> storagePolicyTransitionTypeEntityJoin = storagePolicyEntityRoot.join(StoragePolicyEntity_.storagePolicyTransitionType);
    Join<StoragePolicyEntity, StoragePolicyStatusEntity> storagePolicyStatusEntityJoin = storagePolicyEntityRoot.join(StoragePolicyEntity_.status);
    // Create main query restrictions based on the specified parameters.
    List<Predicate> mainQueryPredicates = new ArrayList<>();
    // Add a restriction on business object definition.
    mainQueryPredicates.add(storagePolicyPriorityLevel.isBusinessObjectDefinitionIsNull() ? builder.isNull(storagePolicyEntityRoot.get(StoragePolicyEntity_.businessObjectDefinition)) : builder.equal(businessObjectDefinitionEntityJoin, storagePolicyEntityRoot.get(StoragePolicyEntity_.businessObjectDefinition)));
    // Add a restriction on business object format usage.
    mainQueryPredicates.add(storagePolicyPriorityLevel.isUsageIsNull() ? builder.isNull(storagePolicyEntityRoot.get(StoragePolicyEntity_.usage)) : builder.equal(builder.upper(businessObjectFormatEntityJoin.get(BusinessObjectFormatEntity_.usage)), builder.upper(storagePolicyEntityRoot.get(StoragePolicyEntity_.usage))));
    // Add a restriction on business object format file type.
    mainQueryPredicates.add(storagePolicyPriorityLevel.isFileTypeIsNull() ? builder.isNull(storagePolicyEntityRoot.get(StoragePolicyEntity_.fileType)) : builder.equal(fileTypeEntityJoin, storagePolicyEntityRoot.get(StoragePolicyEntity_.fileType)));
    // Add a restriction on storage policy filter storage.
    mainQueryPredicates.add(builder.equal(storageUnitEntityJoin.get(StorageUnitEntity_.storage), storagePolicyEntityRoot.get(StoragePolicyEntity_.storage)));
    // Add a restriction on storage policy latest version flag.
    mainQueryPredicates.add(builder.isTrue(storagePolicyEntityRoot.get(StoragePolicyEntity_.latestVersion)));
    // Add a restriction on storage policy status.
    mainQueryPredicates.add(builder.equal(storagePolicyStatusEntityJoin.get(StoragePolicyStatusEntity_.code), StoragePolicyStatusEntity.ENABLED));
    // Add a restriction on supported business object data statuses.
    mainQueryPredicates.add(businessObjectDataStatusEntityJoin.get(BusinessObjectDataStatusEntity_.code).in(supportedBusinessObjectDataStatuses));
    // Add a restriction as per storage policy transition type.
    mainQueryPredicates.add(builder.and(builder.equal(storagePolicyTransitionTypeEntityJoin.get(StoragePolicyTransitionTypeEntity_.code), StoragePolicyTransitionTypeEntity.GLACIER), builder.or(builder.equal(storageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code), StorageUnitStatusEntity.ENABLED), builder.equal(storageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code), StorageUnitStatusEntity.ARCHIVING))));
    // If specified, add restriction on maximum allowed attempts for a storage policy transition.
    if (storagePolicyTransitionMaxAllowedAttempts > 0) {
        mainQueryPredicates.add(builder.or(builder.isNull(storageUnitEntityJoin.get(StorageUnitEntity_.storagePolicyTransitionFailedAttempts)), builder.lessThan(storageUnitEntityJoin.get(StorageUnitEntity_.storagePolicyTransitionFailedAttempts), storagePolicyTransitionMaxAllowedAttempts)));
    }
    // Order the results by business object data "created on" value.
    Order orderByCreatedOn = builder.asc(businessObjectDataEntityRoot.get(BusinessObjectDataEntity_.createdOn));
    // Add the select clause to the main query.
    criteria.multiselect(businessObjectDataEntityRoot, storagePolicyEntityRoot);
    // Add the where clause to the main query.
    criteria.where(mainQueryPredicates.toArray(new Predicate[] {}));
    // Add the order by clause to the main query.
    criteria.orderBy(orderByCreatedOn);
    // Run the query to get a list of tuples back.
    List<Tuple> tuples = entityManager.createQuery(criteria).setFirstResult(startPosition).setMaxResults(maxResult).getResultList();
    // Populate the result map from the returned tuples (i.e. 1 tuple for each row).
    Map<BusinessObjectDataEntity, StoragePolicyEntity> result = new LinkedHashMap<>();
    for (Tuple tuple : tuples) {
        // Since multiple storage policies can contain identical filters, we add the below check to select each business object data instance only once.
        if (!result.containsKey(tuple.get(businessObjectDataEntityRoot))) {
            result.put(tuple.get(businessObjectDataEntityRoot), tuple.get(storagePolicyEntityRoot));
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) StoragePolicyTransitionTypeEntity(org.finra.herd.model.jpa.StoragePolicyTransitionTypeEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) Predicate(javax.persistence.criteria.Predicate) LinkedHashMap(java.util.LinkedHashMap) StoragePolicyEntity(org.finra.herd.model.jpa.StoragePolicyEntity) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) StoragePolicyStatusEntity(org.finra.herd.model.jpa.StoragePolicyStatusEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) BusinessObjectDataStatusEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusEntity) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) Tuple(javax.persistence.Tuple)

Example 32 with StorageUnitStatusEntity

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

the class BusinessObjectDataDaoHelper method createStorageUnitEntity.

/**
 * Creates a storage unit entity per specified parameters.
 *
 * @param businessObjectDataEntity the business object data entity
 * @param storageEntity the storage entity
 * @param storageDirectory the storage directory
 * @param storageFiles the list of storage files
 * @param isDiscoverStorageFiles specifies if
 *
 * @return the newly created storage unit entity
 */
public StorageUnitEntity createStorageUnitEntity(BusinessObjectDataEntity businessObjectDataEntity, StorageEntity storageEntity, StorageDirectory storageDirectory, List<StorageFile> storageFiles, Boolean isDiscoverStorageFiles) {
    // Get the storage unit status entity for the ENABLED status.
    StorageUnitStatusEntity storageUnitStatusEntity = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(StorageUnitStatusEntity.ENABLED);
    // Set up flags which are used to make flow logic easier.
    boolean isS3StoragePlatform = storageEntity.getStoragePlatform().getName().equals(StoragePlatformEntity.S3);
    boolean isStorageDirectorySpecified = (storageDirectory != null);
    boolean validatePathPrefix = storageHelper.getBooleanStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX), storageEntity, false, true);
    boolean validateFileExistence = storageHelper.getBooleanStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE), storageEntity, false, true);
    boolean validateFileSize = storageHelper.getBooleanStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_FILE_SIZE), storageEntity, false, true);
    // Ensure that file size validation is not enabled without file existence validation.
    if (validateFileSize) {
        Assert.isTrue(validateFileExistence, String.format("Storage \"%s\" has file size validation enabled without file existence validation.", storageEntity.getName()));
    }
    String expectedS3KeyPrefix = null;
    // Retrieve S3 key prefix velocity template storage attribute value and store it in memory.
    // Please note that it is not required, so we pass in a "false" flag.
    String s3KeyPrefixVelocityTemplate = storageHelper.getStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), storageEntity, false);
    if (StringUtils.isNotBlank(s3KeyPrefixVelocityTemplate)) {
        // If the storage has any validation configured, get the expected S3 key prefix.
        expectedS3KeyPrefix = s3KeyPrefixHelper.buildS3KeyPrefix(s3KeyPrefixVelocityTemplate, businessObjectDataEntity.getBusinessObjectFormat(), businessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataEntity), storageEntity.getName());
    }
    if ((validatePathPrefix || validateFileExistence) && isS3StoragePlatform) {
        // If path prefix validation is enabled, validate that S3 key prefix velocity template is configured.
        Assert.isTrue(!validatePathPrefix || StringUtils.isNotBlank(s3KeyPrefixVelocityTemplate), String.format("Storage \"%s\" has enabled path validation without S3 key prefix velocity template configured.", storageEntity.getName()));
    }
    // Process storage directory path if it is specified.
    String directoryPath = null;
    if (isStorageDirectorySpecified) {
        // Get the specified directory path.
        directoryPath = storageDirectory.getDirectoryPath();
        // If the validate path prefix flag is configured for this storage, validate the directory path value.
        if (validatePathPrefix && isS3StoragePlatform) {
            // Ensure the directory path adheres to the S3 naming convention.
            Assert.isTrue(directoryPath.equals(expectedS3KeyPrefix), String.format("Specified directory path \"%s\" does not match the expected S3 key prefix \"%s\".", directoryPath, expectedS3KeyPrefix));
            // Ensure that the directory path is not already registered with another business object data instance.
            StorageUnitEntity alreadyRegisteredStorageUnitEntity = storageUnitDao.getStorageUnitByStorageNameAndDirectoryPath(storageEntity.getName(), directoryPath);
            if (alreadyRegisteredStorageUnitEntity != null) {
                throw new AlreadyExistsException(String.format("Storage directory \"%s\" in \"%s\" storage is already registered by the business object data {%s}.", directoryPath, storageEntity.getName(), businessObjectDataHelper.businessObjectDataEntityAltKeyToString(alreadyRegisteredStorageUnitEntity.getBusinessObjectData())));
            }
        }
    } else if (Boolean.TRUE.equals(businessObjectDataEntity.getStatus().getPreRegistrationStatus())) {
        directoryPath = expectedS3KeyPrefix;
    }
    // Create a storage unit entity.
    StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
    storageUnitEntity.setStorage(storageEntity);
    storageUnitEntity.setBusinessObjectData(businessObjectDataEntity);
    storageUnitDaoHelper.setStorageUnitStatus(storageUnitEntity, storageUnitStatusEntity);
    storageUnitEntity.setDirectoryPath(directoryPath);
    // Discover storage files if storage file discovery is enabled. Otherwise, get the storage files specified in the request, if any.
    List<StorageFile> resultStorageFiles = BooleanUtils.isTrue(isDiscoverStorageFiles) ? discoverStorageFiles(storageEntity, directoryPath) : storageFiles;
    // Create the storage file entities.
    createStorageFileEntitiesFromStorageFiles(resultStorageFiles, storageEntity, BooleanUtils.isTrue(isDiscoverStorageFiles), expectedS3KeyPrefix, storageUnitEntity, directoryPath, validatePathPrefix, validateFileExistence, validateFileSize, isS3StoragePlatform);
    return storageUnitEntity;
}
Also used : AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) StorageFile(org.finra.herd.model.api.xml.StorageFile)

Example 33 with StorageUnitStatusEntity

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

the class BusinessObjectDataInvalidateUnregisteredHelper method registerInvalidBusinessObjectDatas.

/**
 * Registers a business object data specified by the given business object data keys. The registered data will have a single storage unit with a directory
 * with the S3 key prefix of the data key. The registered data will be set to status INVALID. If any registration actually occurs, the specified
 * latestBusinessObjectDataEntity latestVersion will be set to false.
 * <p/>
 * The list of data keys must be in ordered by the data version in ascending order.
 *
 * @param latestBusinessObjectDataEntity the latest data at the time of the registration
 * @param businessObjectDataKeys the list of data to register, ordered by version
 * @param storageEntity the storage to register
 *
 * @return list of {@link BusinessObjectDataEntity} that have been registered
 */
private List<BusinessObjectDataEntity> registerInvalidBusinessObjectDatas(BusinessObjectDataEntity latestBusinessObjectDataEntity, BusinessObjectFormatEntity businessObjectFormatEntity, List<BusinessObjectDataKey> businessObjectDataKeys, StorageEntity storageEntity) {
    List<BusinessObjectDataEntity> createdBusinessObjectDataEntities = new ArrayList<>();
    if (!businessObjectDataKeys.isEmpty()) {
        if (latestBusinessObjectDataEntity != null) {
            // Set the latestVersion flag to false for the latest data. This data should no longer be marked as latest.
            latestBusinessObjectDataEntity.setLatestVersion(false);
        }
        // Get business object data status entity for the UNREGISTERED_STATUS.
        BusinessObjectDataStatusEntity businessObjectDataStatusEntity = businessObjectDataStatusDao.getBusinessObjectDataStatusByCode(UNREGISTERED_STATUS);
        // Get storage unit status entity for the ENABLED status.
        StorageUnitStatusEntity storageUnitStatusEntity = storageUnitStatusDao.getStorageUnitStatusByCode(StorageUnitStatusEntity.ENABLED);
        Iterator<BusinessObjectDataKey> unregisteredBusinessObjectDataKeysIterator = businessObjectDataKeys.iterator();
        while (unregisteredBusinessObjectDataKeysIterator.hasNext()) {
            BusinessObjectDataKey unregisteredBusinessObjectDataKey = unregisteredBusinessObjectDataKeysIterator.next();
            BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
            businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity);
            businessObjectDataEntity.setPartitionValue(unregisteredBusinessObjectDataKey.getPartitionValue());
            businessObjectDataEntity.setPartitionValue2(herdCollectionHelper.safeGet(unregisteredBusinessObjectDataKey.getSubPartitionValues(), 0));
            businessObjectDataEntity.setPartitionValue3(herdCollectionHelper.safeGet(unregisteredBusinessObjectDataKey.getSubPartitionValues(), 1));
            businessObjectDataEntity.setPartitionValue4(herdCollectionHelper.safeGet(unregisteredBusinessObjectDataKey.getSubPartitionValues(), 2));
            businessObjectDataEntity.setPartitionValue5(herdCollectionHelper.safeGet(unregisteredBusinessObjectDataKey.getSubPartitionValues(), 3));
            businessObjectDataEntity.setVersion(unregisteredBusinessObjectDataKey.getBusinessObjectDataVersion());
            List<StorageUnitEntity> storageUnitEntities = new ArrayList<>();
            StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
            storageUnitEntity.setStorage(storageEntity);
            storageUnitEntity.setBusinessObjectData(businessObjectDataEntity);
            String s3KeyPrefix = s3KeyPrefixHelper.buildS3KeyPrefix(storageEntity, businessObjectFormatEntity, unregisteredBusinessObjectDataKey);
            storageUnitEntity.setDirectoryPath(s3KeyPrefix);
            storageUnitEntity.setStatus(storageUnitStatusEntity);
            storageUnitEntities.add(storageUnitEntity);
            businessObjectDataEntity.setStorageUnits(storageUnitEntities);
            businessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
            // Set this data as latest version if this is the end of the loop
            businessObjectDataEntity.setLatestVersion(!unregisteredBusinessObjectDataKeysIterator.hasNext());
            businessObjectDataDao.saveAndRefresh(businessObjectDataEntity);
            createdBusinessObjectDataEntities.add(businessObjectDataEntity);
        }
    }
    return createdBusinessObjectDataEntities;
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectDataStatusEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusEntity) ArrayList(java.util.ArrayList) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey)

Example 34 with StorageUnitStatusEntity

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

the class BusinessObjectDataFinalizeRestoreHelperServiceImpl method completeFinalizeRestoreImpl.

/**
 * Completes the finalize restore operation.
 *
 * @param businessObjectDataRestoreDto the DTO that holds various parameters needed to perform a business object data restore
 */
protected void completeFinalizeRestoreImpl(BusinessObjectDataRestoreDto businessObjectDataRestoreDto) {
    // Retrieve the business object data and ensure it exists.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataRestoreDto.getBusinessObjectDataKey());
    // Retrieve the storage unit and ensure it exists.
    StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(businessObjectDataRestoreDto.getStorageName(), businessObjectDataEntity);
    // Retrieve and ensure the RESTORED storage unit status entity exists.
    StorageUnitStatusEntity newStorageUnitStatusEntity = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(StorageUnitStatusEntity.RESTORED);
    // Save the old storage unit status value.
    String oldStorageUnitStatus = storageUnitEntity.getStatus().getCode();
    // Update the storage unit status to RESTORED.
    String reason = StorageUnitStatusEntity.RESTORED;
    storageUnitDaoHelper.updateStorageUnitStatus(storageUnitEntity, newStorageUnitStatusEntity, reason);
    // Update the new and old storage unit status values in the business object data restore DTO.
    businessObjectDataRestoreDto.setNewStorageUnitStatus(newStorageUnitStatusEntity.getCode());
    businessObjectDataRestoreDto.setOldStorageUnitStatus(oldStorageUnitStatus);
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity)

Example 35 with StorageUnitStatusEntity

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

the class RelationalTableRegistrationHelperServiceImpl method registerRelationalTableImpl.

/**
 * Creates a new relational table registration. The relation table registration includes creation of the following entities: <ul> <li>a business object
 * definition</li> <li>a business object format with the specified schema columns</li> <li>a business object data</li> <li>a storage unit that links
 * together the business object data with the storage specified in the create request</li> </ul>
 *
 * @param relationalTableRegistrationCreateRequest the relational table registration create request
 * @param schemaColumns the list of schema columns
 * @param appendToExistingBusinessObjectDefinition boolean flag that determines if the format should be appended to an existing business object definition
 *
 * @return the information for the newly created business object data
 */
BusinessObjectData registerRelationalTableImpl(RelationalTableRegistrationCreateRequest relationalTableRegistrationCreateRequest, List<SchemaColumn> schemaColumns, Boolean appendToExistingBusinessObjectDefinition) {
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity;
    // else create a new business object definition with the information in the relational table registration create request.
    if (BooleanUtils.isTrue(appendToExistingBusinessObjectDefinition)) {
        // Get the existing business object definition
        businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(new BusinessObjectDefinitionKey(relationalTableRegistrationCreateRequest.getNamespace(), relationalTableRegistrationCreateRequest.getBusinessObjectDefinitionName()));
    } else {
        // Create a business object definition.
        businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.createBusinessObjectDefinitionEntity(new BusinessObjectDefinitionCreateRequest(relationalTableRegistrationCreateRequest.getNamespace(), relationalTableRegistrationCreateRequest.getBusinessObjectDefinitionName(), relationalTableRegistrationCreateRequest.getDataProviderName(), null, relationalTableRegistrationCreateRequest.getBusinessObjectDefinitionDisplayName(), null));
    }
    // Notify the search index that a business object definition is created.
    searchIndexUpdateHelper.modifyBusinessObjectDefinitionInSearchIndex(businessObjectDefinitionEntity, SEARCH_INDEX_UPDATE_TYPE_CREATE);
    // Create a business object format. Store the relational table name as a business object format attribute per attribute name configured in the system.
    BusinessObjectFormatCreateRequest businessObjectFormatCreateRequest = new BusinessObjectFormatCreateRequest();
    businessObjectFormatCreateRequest.setNamespace(relationalTableRegistrationCreateRequest.getNamespace());
    businessObjectFormatCreateRequest.setBusinessObjectDefinitionName(relationalTableRegistrationCreateRequest.getBusinessObjectDefinitionName());
    businessObjectFormatCreateRequest.setBusinessObjectFormatUsage(relationalTableRegistrationCreateRequest.getBusinessObjectFormatUsage());
    businessObjectFormatCreateRequest.setBusinessObjectFormatFileType(FileTypeEntity.RELATIONAL_TABLE_FILE_TYPE);
    businessObjectFormatCreateRequest.setPartitionKey(BusinessObjectDataServiceImpl.NO_PARTITIONING_PARTITION_KEY);
    businessObjectFormatCreateRequest.setAttributes(Arrays.asList(new Attribute(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_FORMAT_ATTRIBUTE_NAME_RELATIONAL_SCHEMA_NAME), relationalTableRegistrationCreateRequest.getRelationalSchemaName()), new Attribute(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_FORMAT_ATTRIBUTE_NAME_RELATIONAL_TABLE_NAME), relationalTableRegistrationCreateRequest.getRelationalTableName())));
    businessObjectFormatCreateRequest.setSchema(new Schema(schemaColumns, null, "", null, null, null));
    BusinessObjectFormat businessObjectFormat = businessObjectFormatService.createBusinessObjectFormat(businessObjectFormatCreateRequest);
    // Retrieve the newly created business object format entity.
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatHelper.getBusinessObjectFormatKey(businessObjectFormat));
    // Get a business object data status entity for the VALID status.
    BusinessObjectDataStatusEntity businessObjectDataStatusEntity = businessObjectDataStatusDaoHelper.getBusinessObjectDataStatusEntity(BusinessObjectDataStatusEntity.VALID);
    // Create a business object data entity.
    BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
    businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity);
    businessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
    businessObjectDataEntity.setVersion(0);
    businessObjectDataEntity.setLatestVersion(true);
    businessObjectDataEntity.setPartitionValue(BusinessObjectDataServiceImpl.NO_PARTITIONING_PARTITION_VALUE);
    // Get a storage unit status entity for the ENABLED status.
    StorageUnitStatusEntity storageUnitStatusEntity = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(StorageUnitStatusEntity.ENABLED);
    // Get the storage.
    StorageEntity storageEntity = storageDaoHelper.getStorageEntity(relationalTableRegistrationCreateRequest.getStorageName());
    // Create a storage unit entity.
    StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
    storageUnitEntity.setStorage(storageEntity);
    storageUnitEntity.setBusinessObjectData(businessObjectDataEntity);
    storageUnitDaoHelper.setStorageUnitStatus(storageUnitEntity, storageUnitStatusEntity);
    businessObjectDataEntity.setStorageUnits(Collections.singletonList(storageUnitEntity));
    // Persist the newly created business object data entity.
    businessObjectDataEntity = businessObjectDataDao.saveAndRefresh(businessObjectDataEntity);
    // Create a status change notification to be sent on create business object data event.
    messageNotificationEventService.processBusinessObjectDataStatusChangeNotificationEvent(businessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataEntity), businessObjectDataStatusEntity.getCode(), null);
    // Create and return business object data information from the newly created business object data entity.
    return businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity);
}
Also used : BusinessObjectFormatCreateRequest(org.finra.herd.model.api.xml.BusinessObjectFormatCreateRequest) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) Attribute(org.finra.herd.model.api.xml.Attribute) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) Schema(org.finra.herd.model.api.xml.Schema) BusinessObjectDataStatusEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusEntity) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectDefinitionCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDefinitionCreateRequest) BusinessObjectFormat(org.finra.herd.model.api.xml.BusinessObjectFormat) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity)

Aggregations

StorageUnitStatusEntity (org.finra.herd.model.jpa.StorageUnitStatusEntity)47 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)35 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)30 StorageEntity (org.finra.herd.model.jpa.StorageEntity)24 Test (org.junit.Test)23 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)18 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)15 ArrayList (java.util.ArrayList)11 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)11 Predicate (javax.persistence.criteria.Predicate)10 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)10 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)10 StoragePlatformEntity (org.finra.herd.model.jpa.StoragePlatformEntity)9 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)8 StorageFile (org.finra.herd.model.api.xml.StorageFile)8 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)8 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)7 InvocationOnMock (org.mockito.invocation.InvocationOnMock)7 Order (javax.persistence.criteria.Order)6 Timestamp (java.sql.Timestamp)5