Search in sources :

Example 6 with StorageUnitCreateRequest

use of org.finra.herd.model.api.xml.StorageUnitCreateRequest in project herd by FINRAOS.

the class BusinessObjectDataServiceCreateBusinessObjectDataTest method testCreateBusinessObjectDataPreRegistrationAssertDirectoryPathNotRequiredWhenStatusIsPreRegistrationAndDirectoryIsSetInResponse.

@Test
public void testCreateBusinessObjectDataPreRegistrationAssertDirectoryPathNotRequiredWhenStatusIsPreRegistrationAndDirectoryIsSetInResponse() {
    StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(STORAGE_NAME);
    storageEntity.getAttributes().add(storageDaoTestHelper.createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), "foo"));
    // Create an initial version of the business object data.
    BusinessObjectDataCreateRequest businessObjectDataCreateRequest = businessObjectDataServiceTestHelper.getNewBusinessObjectDataCreateRequest();
    businessObjectDataCreateRequest.setSubPartitionValues(null);
    businessObjectDataCreateRequest.setStatus("UPLOADING");
    businessObjectDataCreateRequest.setStorageUnits(Arrays.asList(new StorageUnitCreateRequest(STORAGE_NAME, null, null, null)));
    BusinessObjectData businessObjectData = businessObjectDataService.createBusinessObjectData(businessObjectDataCreateRequest);
    assertEquals("foo", businessObjectData.getStorageUnits().get(0).getStorageDirectory().getDirectoryPath());
}
Also used : BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) BusinessObjectDataCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest) StorageEntity(org.finra.herd.model.jpa.StorageEntity) StorageUnitCreateRequest(org.finra.herd.model.api.xml.StorageUnitCreateRequest) Test(org.junit.Test)

Example 7 with StorageUnitCreateRequest

use of org.finra.herd.model.api.xml.StorageUnitCreateRequest in project herd by FINRAOS.

the class BusinessObjectDataServiceGetBusinessObjectDataTest method testGetBusinessObjectDataUsingCreateRequest.

@Test
public void testGetBusinessObjectDataUsingCreateRequest() {
    BusinessObjectDataCreateRequest request = businessObjectDataServiceTestHelper.getNewBusinessObjectDataCreateRequest();
    StorageUnitCreateRequest storageUnit = request.getStorageUnits().get(0);
    // Create the business object data.
    businessObjectDataService.createBusinessObjectData(request);
    // Retrieve the business object data.
    BusinessObjectData businessObjectData = businessObjectDataService.getBusinessObjectData(new BusinessObjectDataKey(request.getNamespace(), request.getBusinessObjectDefinitionName(), request.getBusinessObjectFormatUsage(), request.getBusinessObjectFormatFileType(), request.getBusinessObjectFormatVersion(), request.getPartitionValue(), request.getSubPartitionValues(), INITIAL_DATA_VERSION), request.getPartitionKey(), NO_BDATA_STATUS, NO_INCLUDE_BUSINESS_OBJECT_DATA_STATUS_HISTORY, NO_INCLUDE_STORAGE_UNIT_STATUS_HISTORY);
    // Verify the results.
    assertNotNull(businessObjectData);
    assertNotNull(businessObjectData.getId());
    assertTrue(businessObjectData.getBusinessObjectDefinitionName().equals(request.getBusinessObjectDefinitionName()));
    assertTrue(businessObjectData.getBusinessObjectFormatUsage().equals(request.getBusinessObjectFormatUsage()));
    assertTrue(businessObjectData.getBusinessObjectFormatFileType().equals(request.getBusinessObjectFormatFileType()));
    assertTrue(businessObjectData.getBusinessObjectFormatVersion() == request.getBusinessObjectFormatVersion());
    assertTrue(businessObjectData.getPartitionValue().equals(request.getPartitionValue()));
    assertTrue(businessObjectData.getSubPartitionValues().equals(request.getSubPartitionValues()));
    assertTrue(businessObjectData.getVersion() == INITIAL_DATA_VERSION);
    assertTrue(businessObjectData.isLatestVersion());
    List<StorageUnit> storageUnits = businessObjectData.getStorageUnits();
    assertTrue(storageUnits.size() == 1);
    StorageUnit resultStorageUnit = storageUnits.get(0);
    assertTrue(resultStorageUnit.getStorage().getName().equals(storageUnit.getStorageName()));
    // Check if result storage directory path matches to the directory path from the request.
    assertEquals(storageUnit.getStorageDirectory(), resultStorageUnit.getStorageDirectory());
    // Check if result list of storage files matches to the list from the create request.
    businessObjectDataServiceTestHelper.validateStorageFiles(resultStorageUnit.getStorageFiles(), storageUnit.getStorageFiles());
    // Check if result list of attributes matches to the list from the create request.
    businessObjectDefinitionServiceTestHelper.validateAttributes(request.getAttributes(), businessObjectData.getAttributes());
    // Validate the parents.
    assertTrue(businessObjectData.getBusinessObjectDataParents().size() == 2);
    Collections.sort(request.getBusinessObjectDataParents(), new BusinessObjectDataKeyComparator());
    assertEquals(request.getBusinessObjectDataParents(), businessObjectData.getBusinessObjectDataParents());
    // Ensure no children exist since the entity is new.
    assertTrue(businessObjectData.getBusinessObjectDataChildren().size() == 0);
    // Get one of the parents.
    BusinessObjectDataKey businessObjectDataParentKey = request.getBusinessObjectDataParents().get(0);
    // Retrieve the business object data for the parent.
    BusinessObjectData businessObjectDataParent = businessObjectDataService.getBusinessObjectData(new BusinessObjectDataKey(businessObjectDataParentKey.getNamespace(), businessObjectDataParentKey.getBusinessObjectDefinitionName(), businessObjectDataParentKey.getBusinessObjectFormatUsage(), businessObjectDataParentKey.getBusinessObjectFormatFileType(), businessObjectDataParentKey.getBusinessObjectFormatVersion(), businessObjectDataParentKey.getPartitionValue(), businessObjectDataParentKey.getSubPartitionValues(), businessObjectDataParentKey.getBusinessObjectDataVersion()), request.getPartitionKey(), NO_BDATA_STATUS, NO_INCLUDE_BUSINESS_OBJECT_DATA_STATUS_HISTORY, NO_INCLUDE_STORAGE_UNIT_STATUS_HISTORY);
    // Ensure that the parent contains a single child record and that it is equal to our original business object data we created.
    assertTrue(businessObjectDataParent.getBusinessObjectDataChildren().size() == 1);
    assertEquals(businessObjectDataHelper.createBusinessObjectDataKey(businessObjectData), businessObjectDataParent.getBusinessObjectDataChildren().get(0));
}
Also used : BusinessObjectDataKeyComparator(org.finra.herd.service.helper.BusinessObjectDataKeyComparator) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) BusinessObjectDataCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest) StorageUnit(org.finra.herd.model.api.xml.StorageUnit) StorageUnitCreateRequest(org.finra.herd.model.api.xml.StorageUnitCreateRequest) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Test(org.junit.Test)

Example 8 with StorageUnitCreateRequest

use of org.finra.herd.model.api.xml.StorageUnitCreateRequest in project herd by FINRAOS.

the class BusinessObjectDataServiceTestHelper method getNewBusinessObjectDataCreateRequest.

/**
 * Gets a newly created business object data create request.
 *
 * @param includeAttributes If true, attribute definitions and attributes will be included. Otherwise, not.
 *
 * @return the business object create request.
 */
public BusinessObjectDataCreateRequest getNewBusinessObjectDataCreateRequest(boolean includeAttributes) {
    // Crete a test business object format (and associated data).
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(includeAttributes);
    StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity();
    // Create a request to create business object data.
    BusinessObjectDataCreateRequest businessObjectDataCreateRequest = new BusinessObjectDataCreateRequest();
    businessObjectDataCreateRequest.setNamespace(businessObjectFormatEntity.getBusinessObjectDefinition().getNamespace().getCode());
    businessObjectDataCreateRequest.setBusinessObjectDefinitionName(businessObjectFormatEntity.getBusinessObjectDefinition().getName());
    businessObjectDataCreateRequest.setBusinessObjectFormatUsage(businessObjectFormatEntity.getUsage());
    businessObjectDataCreateRequest.setBusinessObjectFormatFileType(businessObjectFormatEntity.getFileType().getCode());
    businessObjectDataCreateRequest.setBusinessObjectFormatVersion(businessObjectFormatEntity.getBusinessObjectFormatVersion());
    businessObjectDataCreateRequest.setPartitionKey(businessObjectFormatEntity.getPartitionKey());
    businessObjectDataCreateRequest.setPartitionValue(AbstractServiceTest.PARTITION_VALUE);
    businessObjectDataCreateRequest.setSubPartitionValues(AbstractServiceTest.SUBPARTITION_VALUES);
    List<StorageUnitCreateRequest> storageUnits = new ArrayList<>();
    businessObjectDataCreateRequest.setStorageUnits(storageUnits);
    StorageUnitCreateRequest storageUnit = new StorageUnitCreateRequest();
    storageUnits.add(storageUnit);
    storageUnit.setStorageName(storageEntity.getName());
    StorageDirectory storageDirectory = new StorageDirectory();
    storageUnit.setStorageDirectory(storageDirectory);
    storageDirectory.setDirectoryPath("Folder");
    List<StorageFile> storageFiles = new ArrayList<>();
    storageUnit.setStorageFiles(storageFiles);
    StorageFile storageFile1 = new StorageFile();
    storageFiles.add(storageFile1);
    storageFile1.setFilePath("Folder/file1.gz");
    storageFile1.setFileSizeBytes(0L);
    storageFile1.setRowCount(0L);
    StorageFile storageFile2 = new StorageFile();
    storageFiles.add(storageFile2);
    storageFile2.setFilePath("Folder/file2.gz");
    storageFile2.setFileSizeBytes(2999L);
    storageFile2.setRowCount(1000L);
    StorageFile storageFile3 = new StorageFile();
    storageFiles.add(storageFile3);
    storageFile3.setFilePath("Folder/file3.gz");
    storageFile3.setFileSizeBytes(Long.MAX_VALUE);
    storageFile3.setRowCount(Long.MAX_VALUE);
    if (includeAttributes) {
        businessObjectDataCreateRequest.setAttributes(businessObjectDefinitionServiceTestHelper.getNewAttributes());
    }
    List<BusinessObjectDataKey> businessObjectDataParents = new ArrayList<>();
    businessObjectDataCreateRequest.setBusinessObjectDataParents(businessObjectDataParents);
    // Create 2 parents.
    for (int i = 0; i < 2; i++) {
        BusinessObjectDataEntity parentBusinessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity();
        BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey();
        businessObjectDataKey.setNamespace(parentBusinessObjectDataEntity.getBusinessObjectFormat().getBusinessObjectDefinition().getNamespace().getCode());
        businessObjectDataKey.setBusinessObjectDefinitionName(parentBusinessObjectDataEntity.getBusinessObjectFormat().getBusinessObjectDefinition().getName());
        businessObjectDataKey.setBusinessObjectFormatUsage(parentBusinessObjectDataEntity.getBusinessObjectFormat().getUsage());
        businessObjectDataKey.setBusinessObjectFormatFileType(parentBusinessObjectDataEntity.getBusinessObjectFormat().getFileType().getCode());
        businessObjectDataKey.setBusinessObjectFormatVersion(parentBusinessObjectDataEntity.getBusinessObjectFormat().getBusinessObjectFormatVersion());
        businessObjectDataKey.setPartitionValue(parentBusinessObjectDataEntity.getPartitionValue());
        businessObjectDataKey.setBusinessObjectDataVersion(parentBusinessObjectDataEntity.getVersion());
        businessObjectDataKey.setSubPartitionValues(businessObjectDataHelper.getSubPartitionValues(parentBusinessObjectDataEntity));
        businessObjectDataParents.add(businessObjectDataKey);
    }
    return businessObjectDataCreateRequest;
}
Also used : BusinessObjectDataCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest) ArrayList(java.util.ArrayList) StorageEntity(org.finra.herd.model.jpa.StorageEntity) StorageDirectory(org.finra.herd.model.api.xml.StorageDirectory) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) StorageFile(org.finra.herd.model.api.xml.StorageFile) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) StorageUnitCreateRequest(org.finra.herd.model.api.xml.StorageUnitCreateRequest) BusinessObjectDataStorageUnitCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitCreateRequest)

Example 9 with StorageUnitCreateRequest

use of org.finra.herd.model.api.xml.StorageUnitCreateRequest in project herd by FINRAOS.

the class BusinessObjectDataServiceTestHelper method createBusinessObjectDataCreateRequest.

/**
 * Returns a newly created business object data create request.
 *
 * @param namespaceCode the namespace code
 * @param businessObjectDefinitionName the business object definition name
 * @param businessObjectFormatUsage the business object format usage
 * @param businessObjectFormatFileType the business object format file type
 * @param businessObjectFormatVersion the business object format version
 * @param partitionKey the partition key
 * @param partitionValue the partition value
 * @param storageName the storage name
 * @param storageDirectoryPath the storage directory path
 * @param storageFiles the list of storage files
 *
 * @return the business object create request
 */
public BusinessObjectDataCreateRequest createBusinessObjectDataCreateRequest(String namespaceCode, String businessObjectDefinitionName, String businessObjectFormatUsage, String businessObjectFormatFileType, Integer businessObjectFormatVersion, String partitionKey, String partitionValue, String businessObjectDataStatusCode, String storageName, String storageDirectoryPath, List<StorageFile> storageFiles) {
    // Create a business object data create request.
    BusinessObjectDataCreateRequest businessObjectDataCreateRequest = new BusinessObjectDataCreateRequest();
    businessObjectDataCreateRequest.setNamespace(namespaceCode);
    businessObjectDataCreateRequest.setBusinessObjectDefinitionName(businessObjectDefinitionName);
    businessObjectDataCreateRequest.setBusinessObjectFormatUsage(businessObjectFormatUsage);
    businessObjectDataCreateRequest.setBusinessObjectFormatFileType(businessObjectFormatFileType);
    businessObjectDataCreateRequest.setBusinessObjectFormatVersion(businessObjectFormatVersion);
    businessObjectDataCreateRequest.setPartitionKey(partitionKey);
    businessObjectDataCreateRequest.setPartitionValue(partitionValue);
    businessObjectDataCreateRequest.setStatus(businessObjectDataStatusCode);
    List<StorageUnitCreateRequest> storageUnits = new ArrayList<>();
    businessObjectDataCreateRequest.setStorageUnits(storageUnits);
    StorageUnitCreateRequest storageUnit = new StorageUnitCreateRequest();
    storageUnits.add(storageUnit);
    storageUnit.setStorageName(storageName);
    if (storageDirectoryPath != null) {
        StorageDirectory storageDirectory = new StorageDirectory();
        storageUnit.setStorageDirectory(storageDirectory);
        storageDirectory.setDirectoryPath(storageDirectoryPath);
    }
    storageUnit.setStorageFiles(storageFiles);
    return businessObjectDataCreateRequest;
}
Also used : BusinessObjectDataCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest) ArrayList(java.util.ArrayList) StorageDirectory(org.finra.herd.model.api.xml.StorageDirectory) StorageUnitCreateRequest(org.finra.herd.model.api.xml.StorageUnitCreateRequest) BusinessObjectDataStorageUnitCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitCreateRequest)

Example 10 with StorageUnitCreateRequest

use of org.finra.herd.model.api.xml.StorageUnitCreateRequest in project herd by FINRAOS.

the class BusinessObjectDataServiceTestHelper method validateBusinessObjectData.

/**
 * Validates business object data against specified arguments and expected (hard coded) test values.
 *
 * @param request the business object data create request
 * @param expectedBusinessObjectDataVersion the expected business object data version
 * @param expectedLatestVersion the expected business
 * @param actualBusinessObjectData the business object data availability object instance to be validated
 */
public void validateBusinessObjectData(BusinessObjectDataCreateRequest request, Integer expectedBusinessObjectDataVersion, Boolean expectedLatestVersion, BusinessObjectData actualBusinessObjectData) {
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(new BusinessObjectFormatKey(org.apache.commons.lang3.StringUtils.isNotBlank(request.getNamespace()) ? request.getNamespace() : AbstractServiceTest.NAMESPACE, request.getBusinessObjectDefinitionName(), request.getBusinessObjectFormatUsage(), request.getBusinessObjectFormatFileType(), request.getBusinessObjectFormatVersion()));
    List<String> expectedSubPartitionValues = CollectionUtils.isEmpty(request.getSubPartitionValues()) ? new ArrayList<>() : request.getSubPartitionValues();
    String expectedStatusCode = org.apache.commons.lang3.StringUtils.isNotBlank(request.getStatus()) ? request.getStatus() : BusinessObjectDataStatusEntity.VALID;
    StorageUnitCreateRequest storageUnitCreateRequest = request.getStorageUnits().get(0);
    StorageEntity storageEntity = storageDao.getStorageByName(storageUnitCreateRequest.getStorageName());
    String expectedStorageDirectoryPath = storageUnitCreateRequest.getStorageDirectory() != null ? storageUnitCreateRequest.getStorageDirectory().getDirectoryPath() : null;
    List<StorageFile> expectedStorageFiles = CollectionUtils.isEmpty(storageUnitCreateRequest.getStorageFiles()) ? null : storageUnitCreateRequest.getStorageFiles();
    List<Attribute> expectedAttributes = CollectionUtils.isEmpty(request.getAttributes()) ? new ArrayList<>() : request.getAttributes();
    validateBusinessObjectData(businessObjectFormatEntity, request.getPartitionValue(), expectedSubPartitionValues, expectedBusinessObjectDataVersion, expectedLatestVersion, expectedStatusCode, storageEntity.getName(), expectedStorageDirectoryPath, expectedStorageFiles, expectedAttributes, actualBusinessObjectData);
}
Also used : Attribute(org.finra.herd.model.api.xml.Attribute) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) StorageFile(org.finra.herd.model.api.xml.StorageFile) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) StorageUnitCreateRequest(org.finra.herd.model.api.xml.StorageUnitCreateRequest) BusinessObjectDataStorageUnitCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitCreateRequest)

Aggregations

StorageUnitCreateRequest (org.finra.herd.model.api.xml.StorageUnitCreateRequest)17 BusinessObjectDataCreateRequest (org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest)14 Test (org.junit.Test)10 StorageDirectory (org.finra.herd.model.api.xml.StorageDirectory)9 StorageFile (org.finra.herd.model.api.xml.StorageFile)6 ArrayList (java.util.ArrayList)5 Attribute (org.finra.herd.model.api.xml.Attribute)5 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)5 StorageEntity (org.finra.herd.model.jpa.StorageEntity)4 BusinessObjectDataStorageUnitCreateRequest (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitCreateRequest)3 StorageUnit (org.finra.herd.model.api.xml.StorageUnit)3 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)2 Storage (org.finra.herd.model.api.xml.Storage)2 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 StringWriter (java.io.StringWriter)1 URI (java.net.URI)1 Map (java.util.Map)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1