use of org.finra.herd.model.api.xml.BusinessObjectData in project herd by FINRAOS.
the class BusinessObjectDataDaoImpl method getQueryResultListFromEntityList.
/**
* Gets a query result list from an entity list.
*
* @param entityArray entity array from query
* @param attributeValueList attribute value list
*
* @return the list of business object data
*/
private List<BusinessObjectData> getQueryResultListFromEntityList(List<BusinessObjectDataEntity> entityArray, List<AttributeValueFilter> attributeValueList) {
List<BusinessObjectData> businessObjectDataList = new ArrayList<>();
Set<Integer> businessObjectIdSet = new HashSet<>();
for (BusinessObjectDataEntity dataEntity : entityArray) {
// need to skip the same data entity
if (businessObjectIdSet.contains(dataEntity.getId())) {
continue;
}
BusinessObjectData businessObjectData = new BusinessObjectData();
businessObjectIdSet.add(dataEntity.getId());
businessObjectData.setId(dataEntity.getId());
businessObjectData.setPartitionValue(dataEntity.getPartitionValue());
businessObjectData.setVersion(dataEntity.getVersion());
businessObjectData.setLatestVersion(dataEntity.getLatestVersion());
BusinessObjectFormatEntity formatEntity = dataEntity.getBusinessObjectFormat();
businessObjectData.setNamespace(formatEntity.getBusinessObjectDefinition().getNamespace().getCode());
businessObjectData.setBusinessObjectDefinitionName(formatEntity.getBusinessObjectDefinition().getName());
businessObjectData.setBusinessObjectFormatUsage(formatEntity.getUsage());
businessObjectData.setBusinessObjectFormatFileType(formatEntity.getFileType().getCode());
businessObjectData.setBusinessObjectFormatVersion(formatEntity.getBusinessObjectFormatVersion());
businessObjectData.setPartitionKey(formatEntity.getPartitionKey());
businessObjectData.setStatus(dataEntity.getStatus().getCode());
List<String> subpartitions = new ArrayList<>();
if (dataEntity.getPartitionValue2() != null) {
subpartitions.add(dataEntity.getPartitionValue2());
}
if (dataEntity.getPartitionValue3() != null) {
subpartitions.add(dataEntity.getPartitionValue3());
}
if (dataEntity.getPartitionValue4() != null) {
subpartitions.add(dataEntity.getPartitionValue4());
}
if (dataEntity.getPartitionValue5() != null) {
subpartitions.add(dataEntity.getPartitionValue5());
}
if (subpartitions.size() > 0) {
businessObjectData.setSubPartitionValues(subpartitions);
}
// add attribute name and values in the request to the response
if (attributeValueList != null && !attributeValueList.isEmpty()) {
Collection<BusinessObjectDataAttributeEntity> dataAttributeCollection = dataEntity.getAttributes();
List<Attribute> attributeList = new ArrayList<>();
for (BusinessObjectDataAttributeEntity attributeEntity : dataAttributeCollection) {
Attribute attribute = new Attribute(attributeEntity.getName(), attributeEntity.getValue());
if (shouldIncludeAttributeInResponse(attributeEntity, attributeValueList) && !attributeList.contains(attribute)) {
attributeList.add(attribute);
}
}
businessObjectData.setAttributes(attributeList);
}
businessObjectDataList.add(businessObjectData);
}
return businessObjectDataList;
}
use of org.finra.herd.model.api.xml.BusinessObjectData in project herd by FINRAOS.
the class BusinessObjectDataServiceCreateBusinessObjectDataTest method testCreateBusinessObjectData.
@Test
public void testCreateBusinessObjectData() {
// Create an initial version of the business object data.
BusinessObjectDataCreateRequest businessObjectDataCreateRequest = businessObjectDataServiceTestHelper.getNewBusinessObjectDataCreateRequest();
BusinessObjectData resultBusinessObjectData = businessObjectDataService.createBusinessObjectData(businessObjectDataCreateRequest);
// Verify the results.
businessObjectDataServiceTestHelper.validateBusinessObjectData(businessObjectDataCreateRequest, INITIAL_DATA_VERSION, true, resultBusinessObjectData);
}
use of org.finra.herd.model.api.xml.BusinessObjectData in project herd by FINRAOS.
the class BusinessObjectDataServiceCreateBusinessObjectDataTest method testCreateBusinessObjectDataInitialDataVersionExists.
@Test
public void testCreateBusinessObjectDataInitialDataVersionExists() {
// Create relative database entities including the initial version of the business object data.
businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE, INITIAL_DATA_VERSION, true, BDATA_STATUS);
storageDaoTestHelper.createStorageEntity(STORAGE_NAME);
// Build a list of storage files.
List<StorageFile> storageFiles = businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, SORTED_LOCAL_FILES);
// Build a new business object data create request.
BusinessObjectDataCreateRequest request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BDATA_STATUS, STORAGE_NAME, testS3KeyPrefix, storageFiles);
// Try to create the second version of the business object data (version 1) with createNewVersion flag set to null and to false.
for (Boolean createNewVersionFlag : new Boolean[] { null, Boolean.FALSE }) {
request.setCreateNewVersion(createNewVersionFlag);
try {
businessObjectDataService.createBusinessObjectData(request);
fail(String.format("Should throw an IllegalArgumentException when the initial data version exists and createNewVersion flag is set to \"%s\".", createNewVersionFlag));
} catch (AlreadyExistsException e) {
assertEquals("Unable to create business object data because it already exists.", e.getMessage());
}
}
// Try to create the second version of the business object data with createNewVersion flag set to true.
request.setCreateNewVersion(true);
BusinessObjectData resultBusinessObjectData = businessObjectDataService.createBusinessObjectData(request);
// Validate the results for the second version if the business object data.
businessObjectDataServiceTestHelper.validateBusinessObjectData(request, SECOND_DATA_VERSION, true, resultBusinessObjectData);
// Confirm that the initial version of the business object data now does not have the latestFlag set.
BusinessObjectDataEntity initialVersionBusinessObjectDataEntity = businessObjectDataDao.getBusinessObjectDataByAltKey(new BusinessObjectDataKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, INITIAL_DATA_VERSION));
assertEquals(false, initialVersionBusinessObjectDataEntity.getLatestVersion());
}
use of org.finra.herd.model.api.xml.BusinessObjectData in project herd by FINRAOS.
the class BusinessObjectDataServiceCreateBusinessObjectDataTest method testCreateBusinessObjectDataNoStorageDirectory.
@Test
public void testCreateBusinessObjectDataNoStorageDirectory() {
// Create an initial version of the business object data without specifying a storage directory.
BusinessObjectDataCreateRequest request = businessObjectDataServiceTestHelper.getNewBusinessObjectDataCreateRequest();
request.getStorageUnits().get(0).setStorageDirectory(null);
BusinessObjectData resultBusinessObjectData = businessObjectDataService.createBusinessObjectData(request);
// Verify the results.
businessObjectDataServiceTestHelper.validateBusinessObjectData(request, INITIAL_DATA_VERSION, true, resultBusinessObjectData);
}
use of org.finra.herd.model.api.xml.BusinessObjectData in project herd by FINRAOS.
the class BusinessObjectDataServiceCreateBusinessObjectDataTest method testCreateBusinessObjectDataS3ManagedBucketExtraFilesInS3.
@Test
public void testCreateBusinessObjectDataS3ManagedBucketExtraFilesInS3() throws Exception {
// Create relative database entities.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, FORMAT_DESCRIPTION, false, PARTITION_KEY);
businessObjectDataStatusDaoTestHelper.createBusinessObjectDataStatusEntity(BDATA_STATUS);
// Create and upload to S3 managed storage a set of test files including extra
// files not to be listed in the create business object data create request.
List<String> localFiles = new ArrayList<>();
localFiles.addAll(LOCAL_FILES);
localFiles.add(FILE_NAME);
localFiles.add(FILE_NAME_2);
businessObjectDataServiceTestHelper.prepareTestS3Files(testS3KeyPrefix, localTempPath, localFiles);
// Build a new business object data create request.
BusinessObjectDataCreateRequest request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BDATA_STATUS, StorageEntity.MANAGED_STORAGE, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
// Create the business object data.
BusinessObjectData resultBusinessObjectData = businessObjectDataService.createBusinessObjectData(request);
// Verify the results.
businessObjectDataServiceTestHelper.validateBusinessObjectData(businessObjectFormatEntity, PARTITION_VALUE, NO_SUBPARTITION_VALUES, INITIAL_DATA_VERSION, true, BDATA_STATUS, StorageEntity.MANAGED_STORAGE, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, SORTED_LOCAL_FILES), CollectionUtils.isEmpty(request.getAttributes()) ? new ArrayList<>() : request.getAttributes(), resultBusinessObjectData);
}
Aggregations