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);
}
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);
}
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));
}
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);
}
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);
}
Aggregations