Search in sources :

Example 36 with BusinessObjectDataEntity

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

the class BusinessObjectDataServiceImpl method checkBusinessObjectDataAvailabilityImpl.

/**
 * Performs a search and returns a list of business object data key values and relative statuses for a range of requested business object data.
 *
 * @param request the business object data availability request
 * @param skipRequestValidation specifies whether to skip the request validation and trimming
 *
 * @return the business object data availability information
 */
protected BusinessObjectDataAvailability checkBusinessObjectDataAvailabilityImpl(BusinessObjectDataAvailabilityRequest request, boolean skipRequestValidation) {
    // Perform the validation.
    if (!skipRequestValidation) {
        validateBusinessObjectDataAvailabilityRequest(request);
    }
    // Get business object format key from the request.
    BusinessObjectFormatKey businessObjectFormatKey = getBusinessObjectFormatKey(request);
    // Make sure that specified business object format exists.
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatKey);
    // Get the list of storages from the request and validate that specified storages exist.
    List<String> storageNames = getStorageNames(request);
    storageDaoHelper.validateStorageExistence(storageNames);
    // Build partition filters based on the specified partition value filters.
    // Business object data availability works across all storage platform types, so the storage platform type is not specified in the call.
    List<List<String>> partitionFilters = businessObjectDataDaoHelper.buildPartitionFilters(request.getPartitionValueFilters(), request.getPartitionValueFilter(), businessObjectFormatKey, request.getBusinessObjectDataVersion(), storageNames, null, null, businessObjectFormatEntity);
    // Retrieve a list of storage unit entities for the specified partition values. The entities will be sorted by partition value that is identified
    // by partition column position. If a business object data version isn't specified, the latest VALID business object data version is returned.
    // Business object data availability works across all storage platform types, so the storage platform type is not specified in the herdDao call.
    // We want to select only "available" storage units, so we pass "true" for selectOnlyAvailableStorageUnits parameter.
    List<StorageUnitEntity> availableStorageUnitEntities = storageUnitDao.getStorageUnitsByPartitionFiltersAndStorages(businessObjectFormatKey, partitionFilters, request.getBusinessObjectDataVersion(), BusinessObjectDataStatusEntity.VALID, storageNames, null, null, true);
    // Create business object data availability object instance and initialise it with request field values.
    BusinessObjectDataAvailability businessObjectDataAvailability = createBusinessObjectDataAvailability(request);
    // Create "available" and "not available" business object data status lists.
    List<BusinessObjectDataStatus> availableStatuses = new ArrayList<>();
    businessObjectDataAvailability.setAvailableStatuses(availableStatuses);
    List<BusinessObjectDataStatus> notAvailableStatuses = new ArrayList<>();
    businessObjectDataAvailability.setNotAvailableStatuses(notAvailableStatuses);
    // Build a list of matched available partition filters and populate the available statuses list. Please note that each request partition filter
    // might result in multiple available business object data entities. If storage names are not specified, fail on "duplicate" business object data
    // (same business object data instance registered with multiple storages). Otherwise, remove possible "duplicates".
    List<List<String>> matchedAvailablePartitionFilters = new ArrayList<>();
    List<List<String>> availablePartitions = new ArrayList<>();
    Map<BusinessObjectDataEntity, StorageUnitEntity> businessObjectDataToStorageUnitMap = new HashMap<>();
    for (StorageUnitEntity storageUnitEntity : availableStorageUnitEntities) {
        BusinessObjectDataEntity businessObjectDataEntity = storageUnitEntity.getBusinessObjectData();
        if (businessObjectDataToStorageUnitMap.containsKey(businessObjectDataEntity)) {
            // If storage names are not specified, fail on a business object data registered in multiple storages. Otherwise, ignore that storage unit.
            if (CollectionUtils.isEmpty(storageNames)) {
                throw new IllegalArgumentException(String.format("Found business object data registered in more than one storage. " + "Please specify storage(s) in the request to resolve this. Business object data {%s}", businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)));
            }
        } else {
            BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataEntity);
            matchedAvailablePartitionFilters.add(businessObjectDataHelper.getPartitionFilter(businessObjectDataKey, partitionFilters.get(0)));
            availablePartitions.add(businessObjectDataHelper.getPrimaryAndSubPartitionValues(businessObjectDataKey));
            availableStatuses.add(createAvailableBusinessObjectDataStatus(businessObjectDataEntity));
            businessObjectDataToStorageUnitMap.put(businessObjectDataEntity, storageUnitEntity);
        }
    }
    // Check if request specifies to include all registered sub-partitions in the response.
    boolean includeAllRegisteredSubPartitions = request.getBusinessObjectDataVersion() == null && BooleanUtils.isTrue(request.isIncludeAllRegisteredSubPartitions());
    // matched partition filters one more time to discover any non-available registered sub-partitions.
    if (includeAllRegisteredSubPartitions && !CollectionUtils.isEmpty(matchedAvailablePartitionFilters)) {
        addNotAvailableBusinessObjectDataStatuses(notAvailableStatuses, businessObjectFormatKey, matchedAvailablePartitionFilters, availablePartitions, storageNames);
    }
    // Get a list of unmatched partition filters.
    List<List<String>> unmatchedPartitionFilters = new ArrayList<>(partitionFilters);
    unmatchedPartitionFilters.removeAll(matchedAvailablePartitionFilters);
    // We still need to try to retrieve business object data per list of unmatched filters regardless of business object data and/or storage unit statuses.
    // This is done to populate not-available statuses with legitimate reasons.
    // Business object data availability works across all storage platform types, so the storage platform type is not specified in the herdDao call.
    // We want to select any existing storage units regardless of their status, so we pass "false" for selectOnlyAvailableStorageUnits parameter.
    List<StorageUnitEntity> notAvailableStorageUnitEntities = storageUnitDao.getStorageUnitsByPartitionFiltersAndStorages(businessObjectFormatKey, unmatchedPartitionFilters, request.getBusinessObjectDataVersion(), null, storageNames, null, null, false);
    // Populate the not-available statuses list.
    addNotAvailableBusinessObjectDataStatuses(notAvailableStatuses, notAvailableStorageUnitEntities);
    // Build a list of matched "not-available" partition filters.
    // Please note that each request partition filter might result in multiple available business object data entities.
    List<List<String>> matchedNotAvailablePartitionFilters = getPartitionFilters(notAvailableStorageUnitEntities, partitionFilters.get(0));
    // Update the list of unmatched partition filters.
    unmatchedPartitionFilters.removeAll(matchedNotAvailablePartitionFilters);
    // Populate the "not available" statuses per remaining unmatched filters.
    for (List<String> unmatchedPartitionFilter : unmatchedPartitionFilters) {
        notAvailableStatuses.add(createNotAvailableBusinessObjectDataStatus(request, unmatchedPartitionFilter, REASON_NOT_REGISTERED));
    }
    return businessObjectDataAvailability;
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) HashMap(java.util.HashMap) BusinessObjectDataAvailability(org.finra.herd.model.api.xml.BusinessObjectDataAvailability) ArrayList(java.util.ArrayList) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) List(java.util.List) ArrayList(java.util.ArrayList) BusinessObjectDataStatus(org.finra.herd.model.api.xml.BusinessObjectDataStatus) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity)

Example 37 with BusinessObjectDataEntity

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

the class BusinessObjectDataServiceImpl method getBusinessObjectDataVersions.

@NamespacePermission(fields = "#businessObjectDataKey.namespace", permissions = NamespacePermissionEnum.READ)
@Override
public BusinessObjectDataVersions getBusinessObjectDataVersions(BusinessObjectDataKey businessObjectDataKey) {
    // Validate and trim the business object data key.
    businessObjectDataHelper.validateBusinessObjectDataKey(businessObjectDataKey, false, false);
    // Get the business object data versions based on the specified parameters.
    List<BusinessObjectDataEntity> businessObjectDataEntities = businessObjectDataDao.getBusinessObjectDataEntities(businessObjectDataKey);
    // Create the response.
    BusinessObjectDataVersions businessObjectDataVersions = new BusinessObjectDataVersions();
    for (BusinessObjectDataEntity businessObjectDataEntity : businessObjectDataEntities) {
        BusinessObjectDataVersion businessObjectDataVersion = new BusinessObjectDataVersion();
        BusinessObjectDataKey businessObjectDataVersionKey = businessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataEntity);
        businessObjectDataVersion.setBusinessObjectDataKey(businessObjectDataVersionKey);
        businessObjectDataVersion.setStatus(businessObjectDataEntity.getStatus().getCode());
        businessObjectDataVersions.getBusinessObjectDataVersions().add(businessObjectDataVersion);
    }
    return businessObjectDataVersions;
}
Also used : BusinessObjectDataVersion(org.finra.herd.model.api.xml.BusinessObjectDataVersion) BusinessObjectDataVersions(org.finra.herd.model.api.xml.BusinessObjectDataVersions) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 38 with BusinessObjectDataEntity

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

the class BusinessObjectDataServiceImpl method updateBusinessObjectDataAttributes.

@NamespacePermission(fields = "#businessObjectDataKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public BusinessObjectData updateBusinessObjectDataAttributes(BusinessObjectDataKey businessObjectDataKey, BusinessObjectDataAttributesUpdateRequest businessObjectDataAttributesUpdateRequest) {
    // Validate and trim the business object data key.
    businessObjectDataHelper.validateBusinessObjectDataKey(businessObjectDataKey, true, true);
    // Validate the update request.
    Assert.notNull(businessObjectDataAttributesUpdateRequest, "A business object data attributes update request must be specified.");
    Assert.notNull(businessObjectDataAttributesUpdateRequest.getAttributes(), "A list of business object data attributes must be specified.");
    List<Attribute> attributes = businessObjectDataAttributesUpdateRequest.getAttributes();
    // Validate attributes. This is also going to trim the attribute names.
    attributeHelper.validateAttributes(attributes);
    // Retrieve the business object data and ensure it exists.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey);
    // Validate attributes against attribute definitions.
    attributeDaoHelper.validateAttributesAgainstBusinessObjectDataAttributeDefinitions(attributes, businessObjectDataEntity.getBusinessObjectFormat().getAttributeDefinitions());
    // Update the attributes.
    attributeDaoHelper.updateBusinessObjectDataAttributes(businessObjectDataEntity, attributes);
    // Persist and refresh the entity.
    businessObjectDataEntity = businessObjectDataDao.saveAndRefresh(businessObjectDataEntity);
    // Create and return the business object data object from the persisted entity.
    return businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity);
}
Also used : Attribute(org.finra.herd.model.api.xml.Attribute) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 39 with BusinessObjectDataEntity

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

the class BusinessObjectDataStorageUnitServiceImpl method createBusinessObjectDataStorageUnitImpl.

/**
 * Creates new storage unit for a given business object data and storage.
 *
 * @param request the create business object data storage unit create request
 *
 * @return the create business object data storage unit create response
 */
protected BusinessObjectDataStorageUnitCreateResponse createBusinessObjectDataStorageUnitImpl(BusinessObjectDataStorageUnitCreateRequest request) {
    // Validate the request.
    validateBusinessObjectDataStorageUnitCreateRequest(request);
    // Retrieve and validate that business object data exists.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(storageUnitHelper.getBusinessObjectDataKey(request.getBusinessObjectDataStorageUnitKey()));
    // Retrieve and validate that storage exists.
    StorageEntity storageEntity = storageDaoHelper.getStorageEntity(request.getBusinessObjectDataStorageUnitKey().getStorageName());
    // Create a storage unit entity.
    StorageUnitEntity storageUnitEntity = businessObjectDataDaoHelper.createStorageUnitEntity(businessObjectDataEntity, storageEntity, request.getStorageDirectory(), request.getStorageFiles(), request.isDiscoverStorageFiles());
    // Persist the newly created storage unit entity.
    storageUnitDao.saveAndRefresh(storageUnitEntity);
    // Construct and return the response.
    return createBusinessObjectDataStorageUnitCreateResponse(storageUnitEntity);
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity)

Example 40 with BusinessObjectDataEntity

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

the class BusinessObjectDataAttributeServiceImpl method deleteBusinessObjectDataAttributeImpl.

/**
 * Deletes an existing business object data attribute by key.
 *
 * @param businessObjectDataAttributeKey the business object data attribute key
 *
 * @return the business object data attribute information for the attribute that got deleted
 */
protected BusinessObjectDataAttribute deleteBusinessObjectDataAttributeImpl(BusinessObjectDataAttributeKey businessObjectDataAttributeKey) {
    // Validate and trim the key.
    businessObjectDataAttributeHelper.validateBusinessObjectDataAttributeKey(businessObjectDataAttributeKey);
    // Get the business object format and ensure it exists.
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(new BusinessObjectFormatKey(businessObjectDataAttributeKey.getNamespace(), businessObjectDataAttributeKey.getBusinessObjectDefinitionName(), businessObjectDataAttributeKey.getBusinessObjectFormatUsage(), businessObjectDataAttributeKey.getBusinessObjectFormatFileType(), businessObjectDataAttributeKey.getBusinessObjectFormatVersion()));
    // Make sure we are not trying to delete a required attribute.
    if (businessObjectDataAttributeHelper.isBusinessObjectDataAttributeRequired(businessObjectDataAttributeKey.getBusinessObjectDataAttributeName(), businessObjectFormatEntity)) {
        throw new IllegalArgumentException(String.format("Cannot delete \"%s\" attribute since it is a required attribute for business object format {%s}.", businessObjectDataAttributeKey.getBusinessObjectDataAttributeName(), businessObjectFormatHelper.businessObjectFormatEntityAltKeyToString(businessObjectFormatEntity)));
    }
    // Retrieve and ensure that a business object data attribute exists with the specified key.
    BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = businessObjectDataAttributeDaoHelper.getBusinessObjectDataAttributeEntity(businessObjectDataAttributeKey);
    // Delete the business object data attribute.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataAttributeEntity.getBusinessObjectData();
    businessObjectDataEntity.getAttributes().remove(businessObjectDataAttributeEntity);
    businessObjectDataDao.saveAndRefresh(businessObjectDataEntity);
    // Create and return the business object data attribute object from the deleted entity.
    return createBusinessObjectDataAttributeFromEntity(businessObjectDataAttributeEntity);
}
Also used : BusinessObjectDataAttributeEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity)

Aggregations

BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)278 Test (org.junit.Test)184 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)138 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)105 ArrayList (java.util.ArrayList)70 StorageEntity (org.finra.herd.model.jpa.StorageEntity)67 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)63 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)57 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)54 StorageUnitStatusEntity (org.finra.herd.model.jpa.StorageUnitStatusEntity)31 Attribute (org.finra.herd.model.api.xml.Attribute)28 NotificationMessageDefinition (org.finra.herd.model.api.xml.NotificationMessageDefinition)27 NotificationMessageDefinitions (org.finra.herd.model.api.xml.NotificationMessageDefinitions)27 ConfigurationEntity (org.finra.herd.model.jpa.ConfigurationEntity)27 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)25 Predicate (javax.persistence.criteria.Predicate)24 NotificationMessage (org.finra.herd.model.dto.NotificationMessage)24 BusinessObjectDataAttributeEntity (org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity)23 StoragePolicyKey (org.finra.herd.model.api.xml.StoragePolicyKey)21 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)19