use of org.finra.herd.model.api.xml.BusinessObjectDefinition in project herd by FINRAOS.
the class RetentionExpirationExporterControllerTest method testGetBusinessObjectDefinitionDisplayName.
@Test
public void testGetBusinessObjectDefinitionDisplayName() {
// Create a business object definition name without a display name.
BusinessObjectDefinition businessObjectDefinition = new BusinessObjectDefinition();
businessObjectDefinition.setBusinessObjectDefinitionName(BUSINESS_OBJECT_DEFINITION_NAME);
// Get a business object defintion display name and validate that it defaults to the business objetct definition name.
assertEquals(BUSINESS_OBJECT_DEFINITION_NAME, retentionExpirationExporterController.getBusinessObjectDefinitionDisplayName(businessObjectDefinition));
// Set business object definition display name for the test business object definition.
businessObjectDefinition.setDisplayName(BUSINESS_OBJECT_DEFINITION_DISPLAY_NAME);
// Get and validate business object definition display name.
assertEquals(BUSINESS_OBJECT_DEFINITION_DISPLAY_NAME, retentionExpirationExporterController.getBusinessObjectDefinitionDisplayName(businessObjectDefinition));
}
use of org.finra.herd.model.api.xml.BusinessObjectDefinition in project herd by FINRAOS.
the class BusinessObjectDefinitionServiceImpl method indexSearchBusinessObjectDefinitions.
@Override
public BusinessObjectDefinitionIndexSearchResponse indexSearchBusinessObjectDefinitions(BusinessObjectDefinitionIndexSearchRequest searchRequest, Set<String> fieldsRequested) {
// Get the configured values for index name and document type
final String indexName = searchIndexDaoHelper.getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
// Validate the business object definition search fields
validateSearchResponseFields(fieldsRequested);
// Create a new object to hold the search index response
ElasticsearchResponseDto elasticsearchResponseDto;
Set<String> facetFields = new HashSet<>();
if (CollectionUtils.isNotEmpty(searchRequest.getFacetFields())) {
facetFields.addAll(validateFacetFields(new HashSet<>(searchRequest.getFacetFields())));
}
// If the request contains search filters
if (CollectionUtils.isNotEmpty(searchRequest.getBusinessObjectDefinitionSearchFilters())) {
// Validate the search request.
validateBusinessObjectDefinitionIndexSearchRequest(searchRequest);
List<Map<SearchFilterType, List<TagEntity>>> tagEntitiesPerSearchFilter = new ArrayList<>();
// Iterate through all search filters and extract tag keys
for (BusinessObjectDefinitionSearchFilter searchFilter : searchRequest.getBusinessObjectDefinitionSearchFilters()) {
List<TagEntity> tagEntities = new ArrayList<>();
Map<SearchFilterType, List<TagEntity>> searchFilterTypeListMap = new HashMap<>();
if (BooleanUtils.isTrue(searchFilter.isIsExclusionSearchFilter())) {
searchFilterTypeListMap.put(SearchFilterType.EXCLUSION_SEARCH_FILTER, tagEntities);
validateExclusionSearchFilter(searchFilter);
} else {
searchFilterTypeListMap.put(SearchFilterType.INCLUSION_SEARCH_FILTER, tagEntities);
}
for (BusinessObjectDefinitionSearchKey searchKey : searchFilter.getBusinessObjectDefinitionSearchKeys()) {
// Get the actual tag entity from its key.
// TODO: bulk fetch tags and their children from the search index after we start indexing tags
TagEntity tagEntity = tagDaoHelper.getTagEntity(searchKey.getTagKey());
tagEntities.add(tagEntity);
// If includeTagHierarchy is true, get list of children tag entities down the hierarchy of the specified tag.
if (BooleanUtils.isTrue(searchKey.isIncludeTagHierarchy())) {
tagEntities.addAll(tagDaoHelper.getTagChildrenEntities(tagEntity));
}
}
// Collect all tag entities and their children (if included) into separate lists
tagEntitiesPerSearchFilter.add(searchFilterTypeListMap);
}
// Use the tag type entities lists to search in the search index for business object definitions
elasticsearchResponseDto = businessObjectDefinitionIndexSearchDao.searchBusinessObjectDefinitionsByTags(indexName, documentType, tagEntitiesPerSearchFilter, facetFields);
} else {
// Else get all of the business object definitions
elasticsearchResponseDto = businessObjectDefinitionIndexSearchDao.findAllBusinessObjectDefinitions(indexName, documentType, facetFields);
}
// Create a list to hold the business object definitions that will be returned as part of the search response
List<BusinessObjectDefinition> businessObjectDefinitions = new ArrayList<>();
// Retrieve all unique business object definition entities and construct a list of business object definitions based on the requested fields.
if (elasticsearchResponseDto.getBusinessObjectDefinitionIndexSearchResponseDtos() != null) {
for (BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto : ImmutableSet.copyOf(elasticsearchResponseDto.getBusinessObjectDefinitionIndexSearchResponseDtos())) {
// Convert the business object definition entity to a business object definition and
// add it to the list of business object definitions that will be
// returned as a part of the search response
businessObjectDefinitions.add(createBusinessObjectDefinitionFromDto(businessObjectDefinitionIndexSearchResponseDto, fieldsRequested));
}
}
List<Facet> tagTypeFacets = null;
if (CollectionUtils.isNotEmpty(searchRequest.getFacetFields()) && elasticsearchResponseDto.getTagTypeIndexSearchResponseDtos() != null) {
tagTypeFacets = new ArrayList<>();
// construct a list of facet information
for (TagTypeIndexSearchResponseDto tagTypeIndexSearchResponseDto : elasticsearchResponseDto.getTagTypeIndexSearchResponseDtos()) {
List<Facet> tagFacets = new ArrayList<>();
for (TagIndexSearchResponseDto tagIndexSearchResponseDto : tagTypeIndexSearchResponseDto.getTagIndexSearchResponseDtos()) {
Facet tagFacet = new Facet(tagIndexSearchResponseDto.getTagDisplayName(), tagIndexSearchResponseDto.getCount(), FacetTypeEnum.TAG.value(), tagIndexSearchResponseDto.getTagCode(), null);
tagFacets.add(tagFacet);
}
tagTypeFacets.add(new Facet(tagTypeIndexSearchResponseDto.getDisplayName(), null, FacetTypeEnum.TAG_TYPE.value(), tagTypeIndexSearchResponseDto.getCode(), tagFacets));
}
}
// Construct business object search response.
BusinessObjectDefinitionIndexSearchResponse searchResponse = new BusinessObjectDefinitionIndexSearchResponse();
searchResponse.setBusinessObjectDefinitions(businessObjectDefinitions);
searchResponse.setFacets(tagTypeFacets);
return searchResponse;
}
use of org.finra.herd.model.api.xml.BusinessObjectDefinition in project herd by FINRAOS.
the class BusinessObjectDefinitionServiceImpl method searchBusinessObjectDefinitions.
@Override
public BusinessObjectDefinitionSearchResponse searchBusinessObjectDefinitions(BusinessObjectDefinitionSearchRequest request, Set<String> fields) {
// Validate the business object definition search fields.
validateSearchResponseFields(fields);
List<TagEntity> tagEntities = new ArrayList<>();
if (!CollectionUtils.isEmpty(request.getBusinessObjectDefinitionSearchFilters())) {
// Validate the search request.
validateBusinessObjectDefinitionSearchRequest(request);
BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKey = request.getBusinessObjectDefinitionSearchFilters().get(0).getBusinessObjectDefinitionSearchKeys().get(0);
TagEntity tagEntity = tagDaoHelper.getTagEntity(businessObjectDefinitionSearchKey.getTagKey());
// If includeTagHierarchy is true, get list of children tag entities down the hierarchy of the specified tag.
tagEntities.add(tagEntity);
if (BooleanUtils.isTrue(businessObjectDefinitionSearchKey.isIncludeTagHierarchy())) {
tagEntities.addAll(tagDaoHelper.getTagChildrenEntities(tagEntity));
}
}
// Construct business object search response.
BusinessObjectDefinitionSearchResponse searchResponse = new BusinessObjectDefinitionSearchResponse();
List<BusinessObjectDefinition> businessObjectDefinitions = new ArrayList<>();
searchResponse.setBusinessObjectDefinitions(businessObjectDefinitions);
// Retrieve all unique business object definition entities and construct a list of business object definitions based on the requested fields.
for (BusinessObjectDefinitionEntity businessObjectDefinition : ImmutableSet.copyOf(businessObjectDefinitionDao.getBusinessObjectDefinitions(tagEntities))) {
businessObjectDefinitions.add(createBusinessObjectDefinitionFromEntity(businessObjectDefinition, fields));
}
return searchResponse;
}
use of org.finra.herd.model.api.xml.BusinessObjectDefinition in project herd by FINRAOS.
the class BusinessObjectDefinitionServiceImpl method createBusinessObjectDefinitionFromEntity.
/**
* Creates a business object definition from the persisted entity.
*
* @param businessObjectDefinitionEntity the business object definition entity
*
* @return the business object definition
*/
private BusinessObjectDefinition createBusinessObjectDefinitionFromEntity(BusinessObjectDefinitionEntity businessObjectDefinitionEntity, Boolean includeBusinessObjectDefinitionUpdateHistory) {
// Create a business object definition.
BusinessObjectDefinition businessObjectDefinition = new BusinessObjectDefinition();
businessObjectDefinition.setId(businessObjectDefinitionEntity.getId());
businessObjectDefinition.setNamespace(businessObjectDefinitionEntity.getNamespace().getCode());
businessObjectDefinition.setBusinessObjectDefinitionName(businessObjectDefinitionEntity.getName());
businessObjectDefinition.setDescription(businessObjectDefinitionEntity.getDescription());
businessObjectDefinition.setDataProviderName(businessObjectDefinitionEntity.getDataProvider().getName());
businessObjectDefinition.setDisplayName(businessObjectDefinitionEntity.getDisplayName());
// Add attributes.
List<Attribute> attributes = new ArrayList<>();
businessObjectDefinition.setAttributes(attributes);
for (BusinessObjectDefinitionAttributeEntity attributeEntity : businessObjectDefinitionEntity.getAttributes()) {
attributes.add(new Attribute(attributeEntity.getName(), attributeEntity.getValue()));
}
if (businessObjectDefinitionEntity.getDescriptiveBusinessObjectFormat() != null) {
BusinessObjectFormatEntity descriptiveFormatEntity = businessObjectDefinitionEntity.getDescriptiveBusinessObjectFormat();
DescriptiveBusinessObjectFormat descriptiveBusinessObjectFormat = new DescriptiveBusinessObjectFormat();
businessObjectDefinition.setDescriptiveBusinessObjectFormat(descriptiveBusinessObjectFormat);
descriptiveBusinessObjectFormat.setBusinessObjectFormatUsage(descriptiveFormatEntity.getUsage());
descriptiveBusinessObjectFormat.setBusinessObjectFormatFileType(descriptiveFormatEntity.getFileType().getCode());
descriptiveBusinessObjectFormat.setBusinessObjectFormatVersion(descriptiveFormatEntity.getBusinessObjectFormatVersion());
}
// Add sample data files.
List<SampleDataFile> sampleDataFiles = new ArrayList<>();
businessObjectDefinition.setSampleDataFiles(sampleDataFiles);
for (BusinessObjectDefinitionSampleDataFileEntity sampleDataFileEntity : businessObjectDefinitionEntity.getSampleDataFiles()) {
sampleDataFiles.add(new SampleDataFile(sampleDataFileEntity.getDirectoryPath(), sampleDataFileEntity.getFileName()));
}
// Add auditable fields.
businessObjectDefinition.setCreatedByUserId(businessObjectDefinitionEntity.getCreatedBy());
businessObjectDefinition.setLastUpdatedByUserId(businessObjectDefinitionEntity.getUpdatedBy());
businessObjectDefinition.setLastUpdatedOn(HerdDateUtils.getXMLGregorianCalendarValue(businessObjectDefinitionEntity.getUpdatedOn()));
// Add change events.
final List<BusinessObjectDefinitionChangeEvent> businessObjectDefinitionChangeEvents = new ArrayList<>();
if (BooleanUtils.isTrue(includeBusinessObjectDefinitionUpdateHistory)) {
businessObjectDefinitionEntity.getChangeEvents().forEach(businessObjectDefinitionChangeEventEntity -> {
DescriptiveBusinessObjectFormatUpdateRequest descriptiveBusinessObjectFormatUpdateRequest = null;
if (businessObjectDefinitionChangeEventEntity.getFileType() != null) {
descriptiveBusinessObjectFormatUpdateRequest = new DescriptiveBusinessObjectFormatUpdateRequest(businessObjectDefinitionChangeEventEntity.getUsage(), businessObjectDefinitionChangeEventEntity.getFileType());
}
businessObjectDefinitionChangeEvents.add(new BusinessObjectDefinitionChangeEvent(businessObjectDefinitionChangeEventEntity.getDisplayName(), businessObjectDefinitionChangeEventEntity.getDescription(), descriptiveBusinessObjectFormatUpdateRequest, HerdDateUtils.getXMLGregorianCalendarValue(businessObjectDefinitionChangeEventEntity.getCreatedOn()), businessObjectDefinitionChangeEventEntity.getCreatedBy()));
});
}
businessObjectDefinition.setBusinessObjectDefinitionChangeEvents(businessObjectDefinitionChangeEvents);
return businessObjectDefinition;
}
use of org.finra.herd.model.api.xml.BusinessObjectDefinition in project herd by FINRAOS.
the class BusinessObjectDefinitionServiceTest method testCreateBusinessObjectDefinitionUpperCaseParameters.
@Test
public void testCreateBusinessObjectDefinitionUpperCaseParameters() {
// Create and persist database entities required for testing using lower case values.
businessObjectDefinitionServiceTestHelper.createDatabaseEntitiesForBusinessObjectDefinitionTesting(NAMESPACE.toLowerCase(), DATA_PROVIDER_NAME.toLowerCase());
// Create a business object definition using upper case input parameters.
BusinessObjectDefinition resultBusinessObjectDefinition = businessObjectDefinitionService.createBusinessObjectDefinition(new BusinessObjectDefinitionCreateRequest(NAMESPACE.toUpperCase(), BDEF_NAME.toUpperCase(), DATA_PROVIDER_NAME.toUpperCase(), BDEF_DESCRIPTION.toUpperCase(), BDEF_DISPLAY_NAME.toUpperCase(), Arrays.asList(new Attribute(ATTRIBUTE_NAME_1_MIXED_CASE.toUpperCase(), ATTRIBUTE_VALUE_1.toUpperCase()))));
// Get the business object definition entity.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME));
assertNotNull(businessObjectDefinitionEntity);
// Validate the returned object.
assertEquals(new BusinessObjectDefinition(resultBusinessObjectDefinition.getId(), NAMESPACE.toLowerCase(), BDEF_NAME.toUpperCase(), DATA_PROVIDER_NAME.toLowerCase(), BDEF_DESCRIPTION.toUpperCase(), NO_BDEF_SHORT_DESCRIPTION, BDEF_DISPLAY_NAME.toUpperCase(), Arrays.asList(new Attribute(ATTRIBUTE_NAME_1_MIXED_CASE.toUpperCase(), ATTRIBUTE_VALUE_1.toUpperCase())), NO_DESCRIPTIVE_BUSINESS_OBJECT_FORMAT, NO_SAMPLE_DATA_FILES, businessObjectDefinitionEntity.getCreatedBy(), businessObjectDefinitionEntity.getUpdatedBy(), HerdDateUtils.getXMLGregorianCalendarValue(businessObjectDefinitionEntity.getUpdatedOn()), NO_BUSINESS_OBJECT_DEFINITION_CHANGE_EVENTS), resultBusinessObjectDefinition);
}
Aggregations