Search in sources :

Example 1 with BusinessObjectDefinitionEntity

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

the class BusinessObjectDefinitionDaoHelper method createBusinessObjectDefinitionEntity.

/**
 * Create Business Object Definition Entity
 * @param request business object definition create request
 * @return Business Object Definition Entity
 */
public BusinessObjectDefinitionEntity createBusinessObjectDefinitionEntity(BusinessObjectDefinitionCreateRequest request) {
    // Perform the validation.
    validateBusinessObjectDefinitionCreateRequest(request);
    // Get the namespace and ensure it exists.
    NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(request.getNamespace());
    // Get the data provider and ensure it exists.
    DataProviderEntity dataProviderEntity = dataProviderDaoHelper.getDataProviderEntity(request.getDataProviderName());
    // Get business object definition key.
    BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(request.getNamespace(), request.getBusinessObjectDefinitionName());
    // Ensure a business object definition with the specified key doesn't already exist.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(businessObjectDefinitionKey);
    if (businessObjectDefinitionEntity != null) {
        throw new AlreadyExistsException(String.format("Unable to create business object definition with name \"%s\" because it already exists for namespace \"%s\".", businessObjectDefinitionKey.getBusinessObjectDefinitionName(), businessObjectDefinitionKey.getNamespace()));
    }
    // Create a new entity.
    businessObjectDefinitionEntity = new BusinessObjectDefinitionEntity();
    businessObjectDefinitionEntity.setNamespace(namespaceEntity);
    businessObjectDefinitionEntity.setName(request.getBusinessObjectDefinitionName());
    businessObjectDefinitionEntity.setDescription(request.getDescription());
    businessObjectDefinitionEntity.setDataProvider(dataProviderEntity);
    businessObjectDefinitionEntity.setDisplayName(request.getDisplayName());
    // Create the attributes if they are specified.
    if (!CollectionUtils.isEmpty(request.getAttributes())) {
        List<BusinessObjectDefinitionAttributeEntity> attributeEntities = new ArrayList<>();
        businessObjectDefinitionEntity.setAttributes(attributeEntities);
        for (Attribute attribute : request.getAttributes()) {
            BusinessObjectDefinitionAttributeEntity attributeEntity = new BusinessObjectDefinitionAttributeEntity();
            attributeEntities.add(attributeEntity);
            attributeEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
            attributeEntity.setName(attribute.getName());
            attributeEntity.setValue(attribute.getValue());
        }
    }
    // Persist the change event entity
    saveBusinessObjectDefinitionChangeEvents(businessObjectDefinitionEntity);
    // Persist and return the new entity.
    return businessObjectDefinitionDao.saveAndRefresh(businessObjectDefinitionEntity);
}
Also used : BusinessObjectDefinitionAttributeEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionAttributeEntity) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) DataProviderEntity(org.finra.herd.model.jpa.DataProviderEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) Attribute(org.finra.herd.model.api.xml.Attribute) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) ArrayList(java.util.ArrayList)

Example 2 with BusinessObjectDefinitionEntity

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

the class BusinessObjectDefinitionHelper method processTagSearchScoreMultiplier.

/**
 * Processes the tags search score multiplier. Multiply all the tags search score.
 *
 * @param businessObjectDefinitionEntity the business object definition entity
 */
public void processTagSearchScoreMultiplier(final BusinessObjectDefinitionEntity businessObjectDefinitionEntity) {
    LOGGER.debug("processTagSearchScoreMultiplier " + businessObjectDefinitionEntity.getId() + " " + businessObjectDefinitionEntity.getBusinessObjectDefinitionTags());
    BigDecimal totalSearchScoreMultiplier = businessObjectDefinitionEntity.getBusinessObjectDefinitionTags().stream().filter(item -> item.getTag().getSearchScoreMultiplier() != null).reduce(BigDecimal.ONE, (bd, item) -> bd.multiply(item.getTag().getSearchScoreMultiplier()), BigDecimal::multiply).setScale(3, RoundingMode.HALF_UP);
    businessObjectDefinitionEntity.setTagSearchScoreMultiplier(totalSearchScoreMultiplier);
}
Also used : Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) BigDecimal(java.math.BigDecimal) List(java.util.List) Component(org.springframework.stereotype.Component) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) QuadConsumer(org.finra.herd.service.functional.QuadConsumer) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) BusinessObjectDefinitionColumnKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionColumnKey) JsonHelper(org.finra.herd.dao.helper.JsonHelper) RoundingMode(java.math.RoundingMode) Assert(org.springframework.util.Assert) BigDecimal(java.math.BigDecimal)

Example 3 with BusinessObjectDefinitionEntity

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

the class JsonHelperTest method testObjectToJsonValidateJsonIgnoreOnExpectedPartitionValues.

@Test
public void testObjectToJsonValidateJsonIgnoreOnExpectedPartitionValues() {
    // Create a business object definition entity.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, NO_ATTRIBUTES);
    // Create a partition key group entity.
    PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDaoTestHelper.createPartitionKeyGroupEntity(PARTITION_KEY_GROUP);
    // Create a list of expected partition values.
    expectedPartitionValueDaoTestHelper.createExpectedPartitionValueEntities(partitionKeyGroupEntity, Arrays.asList(PARTITION_VALUE, PARTITION_VALUE_2, PARTITION_VALUE_3));
    // Create a business object format entity.
    businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(businessObjectDefinitionEntity, FORMAT_USAGE_CODE, fileTypeDaoTestHelper.createFileTypeEntity(FORMAT_FILE_TYPE_CODE, null), FORMAT_VERSION, FORMAT_DESCRIPTION, LATEST_VERSION_FLAG_SET, PARTITION_KEY, partitionKeyGroupEntity, NO_ATTRIBUTES, SCHEMA_DELIMITER_COMMA, SCHEMA_ESCAPE_CHARACTER_BACKSLASH, SCHEMA_NULL_VALUE_BACKSLASH_N, NO_COLUMNS, NO_PARTITION_COLUMNS);
    // Create a JSON object from the business object definition entity.
    String result = jsonHelper.objectToJson(businessObjectDefinitionEntity);
    // Validate the results.
    assertNotNull(result);
    assertTrue(result.contains("partitionKeyGroup"));
    assertFalse(result.contains("expectedPartitionValues"));
    assertFalse(result.contains(PARTITION_VALUE));
    assertFalse(result.contains(PARTITION_VALUE_2));
    assertFalse(result.contains(PARTITION_VALUE_3));
}
Also used : BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) PartitionKeyGroupEntity(org.finra.herd.model.jpa.PartitionKeyGroupEntity) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 4 with BusinessObjectDefinitionEntity

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

the class BusinessObjectDefinitionServiceImpl method updateBusinessObjectDefinitionImpl.

/**
 * Updates a business object definition.
 *
 * @param businessObjectDefinitionKey the business object definition key
 * @param request the business object definition update request
 *
 * @return the updated business object definition
 */
protected BusinessObjectDefinition updateBusinessObjectDefinitionImpl(BusinessObjectDefinitionKey businessObjectDefinitionKey, BusinessObjectDefinitionUpdateRequest request) {
    // Perform validation and trim.
    businessObjectDefinitionHelper.validateBusinessObjectDefinitionKey(businessObjectDefinitionKey);
    validateBusinessObjectDefinitionUpdateRequest(request);
    // Retrieve and ensure that a business object definition already exists with the specified key.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(businessObjectDefinitionKey);
    // Update and persist the entity.
    updateBusinessObjectDefinitionEntity(businessObjectDefinitionEntity, request);
    // Notify the search index that a business object definition must be updated.
    searchIndexUpdateHelper.modifyBusinessObjectDefinitionInSearchIndex(businessObjectDefinitionEntity, SEARCH_INDEX_UPDATE_TYPE_UPDATE);
    // Create and return the business object definition object from the persisted entity.
    return createBusinessObjectDefinitionFromEntity(businessObjectDefinitionEntity, false);
}
Also used : BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)

Example 5 with BusinessObjectDefinitionEntity

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

the class BusinessObjectDefinitionServiceImpl method updateBusinessObjectDefinitionDescriptiveInformationImpl.

/**
 * Updates a business object definition descriptive information.
 *
 * @param businessObjectDefinitionKey the business object definition key
 * @param request the business object definition descriptive information update request
 *
 * @return the updated business object definition
 */
protected BusinessObjectDefinition updateBusinessObjectDefinitionDescriptiveInformationImpl(BusinessObjectDefinitionKey businessObjectDefinitionKey, BusinessObjectDefinitionDescriptiveInformationUpdateRequest request) {
    // Perform validation and trim.
    businessObjectDefinitionHelper.validateBusinessObjectDefinitionKey(businessObjectDefinitionKey);
    validateBusinessObjectDefinitionDescriptiveInformationUpdateRequest(request);
    // Retrieve and ensure that a business object definition already exists with the specified key.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(businessObjectDefinitionKey);
    BusinessObjectFormatEntity businessObjectFormatEntity = null;
    DescriptiveBusinessObjectFormatUpdateRequest descriptiveFormat = request.getDescriptiveBusinessObjectFormat();
    if (descriptiveFormat != null) {
        BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey();
        businessObjectFormatKey.setBusinessObjectDefinitionName(businessObjectDefinitionEntity.getName());
        businessObjectFormatKey.setNamespace(businessObjectDefinitionEntity.getNamespace().getCode());
        businessObjectFormatKey.setBusinessObjectFormatFileType(descriptiveFormat.getBusinessObjectFormatFileType());
        businessObjectFormatKey.setBusinessObjectFormatUsage(descriptiveFormat.getBusinessObjectFormatUsage());
        businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatKey);
    }
    businessObjectDefinitionEntity.setDescriptiveBusinessObjectFormat(businessObjectFormatEntity);
    // Update and persist the entity.
    updateBusinessObjectDefinitionEntityDescriptiveInformation(businessObjectDefinitionEntity, request);
    // Notify the search index that a business object definition must be updated.
    searchIndexUpdateHelper.modifyBusinessObjectDefinitionInSearchIndex(businessObjectDefinitionEntity, SEARCH_INDEX_UPDATE_TYPE_UPDATE);
    // Create and return the business object definition object from the persisted entity.
    return createBusinessObjectDefinitionFromEntity(businessObjectDefinitionEntity, false);
}
Also used : BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) DescriptiveBusinessObjectFormatUpdateRequest(org.finra.herd.model.api.xml.DescriptiveBusinessObjectFormatUpdateRequest) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity)

Aggregations

BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)164 Test (org.junit.Test)78 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)75 ArrayList (java.util.ArrayList)54 BusinessObjectDefinition (org.finra.herd.model.api.xml.BusinessObjectDefinition)40 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)39 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)38 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)33 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)32 Predicate (javax.persistence.criteria.Predicate)31 StorageEntity (org.finra.herd.model.jpa.StorageEntity)23 Attribute (org.finra.herd.model.api.xml.Attribute)19 BusinessObjectDefinitionCreateRequest (org.finra.herd.model.api.xml.BusinessObjectDefinitionCreateRequest)15 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)15 TagEntity (org.finra.herd.model.jpa.TagEntity)15 SearchIndexUpdateDto (org.finra.herd.model.dto.SearchIndexUpdateDto)13 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)12 BusinessObjectDefinitionTagEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity)12 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)12 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)10