Search in sources :

Example 71 with BusinessObjectData

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

the class BusinessObjectDataHelperTest method getStorageUnitByStorageNameStorageUnitNoExists.

@Test
public void getStorageUnitByStorageNameStorageUnitNoExists() {
    String testStorageName = "I_DO_NOT_EXIST";
    // Try to get a non-existing storage unit.
    try {
        businessObjectDataHelper.getStorageUnitByStorageName(new BusinessObjectData(INTEGER_VALUE, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.VALID, NO_STORAGE_UNITS, NO_ATTRIBUTES, NO_BUSINESS_OBJECT_DATA_PARENTS, NO_BUSINESS_OBJECT_DATA_CHILDREN, NO_BUSINESS_OBJECT_DATA_STATUS_HISTORY), testStorageName);
        fail("Should throw a IllegalStateException when storage unit does not exist.");
    } catch (IllegalStateException e) {
        assertEquals(String.format("Business object data has no storage unit with storage name \"%s\".", testStorageName), e.getMessage());
    }
}
Also used : BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 72 with BusinessObjectData

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

the class GetBusinessObjectDataTest method test_NoSubPartitions_NoFormatVersion_NoDataVersion_SubPartitionValuesAsEmptyString.

@Test
public void test_NoSubPartitions_NoFormatVersion_NoDataVersion_SubPartitionValuesAsEmptyString() throws Exception {
    // Create a business object data key without sub-partition values.
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION);
    // Create a business object data entity.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectDataKey, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.VALID);
    List<FieldExtension> fieldExtensionList = new ArrayList<>();
    fieldExtensionList.add(buildFieldExtension("namespace", "${namespace}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectDefinitionName", "${businessObjectDefinitionName}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectFormatUsage", "${businessObjectFormatUsage}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectFormatFileType", "${businessObjectFormatFileType}"));
    fieldExtensionList.add(buildFieldExtension("partitionValue", "${partitionValue}"));
    fieldExtensionList.add(buildFieldExtension("subPartitionValues", "${subPartitionValues}"));
    List<Parameter> parameters = new ArrayList<>();
    parameters.add(buildParameter("namespace", BDEF_NAMESPACE));
    parameters.add(buildParameter("businessObjectDefinitionName", BDEF_NAME));
    parameters.add(buildParameter("businessObjectFormatUsage", FORMAT_USAGE_CODE));
    parameters.add(buildParameter("businessObjectFormatFileType", FORMAT_FILE_TYPE_CODE));
    parameters.add(buildParameter("partitionValue", PARTITION_VALUE));
    parameters.add(buildParameter("subPartitionValues", EMPTY_STRING));
    // Build the expected response object.
    BusinessObjectData expectedBusinessObjectData = new BusinessObjectData(businessObjectDataEntity.getId(), BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.VALID, NO_STORAGE_UNITS, NO_ATTRIBUTES, NO_BUSINESS_OBJECT_DATA_PARENTS, NO_BUSINESS_OBJECT_DATA_CHILDREN, NO_BUSINESS_OBJECT_DATA_STATUS_HISTORY);
    // Run the activiti task and validate the returned response object.
    Map<String, Object> variableValuesToValidate = new HashMap<>();
    variableValuesToValidate.put(GetBusinessObjectDataStatus.VARIABLE_JSON_RESPONSE, jsonHelper.objectToJson(expectedBusinessObjectData));
    testActivitiServiceTaskSuccess(GetBusinessObjectData.class.getCanonicalName(), fieldExtensionList, parameters, variableValuesToValidate);
}
Also used : BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) FieldExtension(org.activiti.bpmn.model.FieldExtension) Parameter(org.finra.herd.model.api.xml.Parameter) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) Test(org.junit.Test)

Example 73 with BusinessObjectData

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

the class GetBusinessObjectDataTest method test_WithSubPartitions_NoFormatVersion_NoDataVersion_WithSubPartitionDelimiterEscapeValue.

@Test
public void test_WithSubPartitions_NoFormatVersion_NoDataVersion_WithSubPartitionDelimiterEscapeValue() throws Exception {
    // Information that will be used for both set up data and input data
    String dataProviderName = randomString();
    String namespace = randomString();
    String businessObjectDefinitionName = randomString();
    String fileTypeCode = randomString();
    Integer businessObjectFormatVersion = 0;
    String partitionKey = randomString();
    String businessObjectFormatUsage = randomString();
    String[] partitionValues = { randomString() + DELIMITER, randomString() + DELIMITER, randomString() + DELIMITER, randomString() + DELIMITER, randomString() + DELIMITER };
    Integer businessObjectDataVersion = 0;
    // Set up database
    setupDatabase(namespace, dataProviderName, businessObjectDefinitionName, fileTypeCode, businessObjectFormatUsage, businessObjectFormatVersion, businessObjectDataVersion, partitionKey, partitionValues);
    String subPartitionValues = buildDelimitedSubPartitionValues(partitionValues);
    String partitionValue = partitionValues[0];
    Map<String, Object> variables = executeJob(namespace, businessObjectDefinitionName, businessObjectFormatUsage, fileTypeCode, partitionKey, partitionValue, subPartitionValues, null, null);
    // Validate status
    String serviceTaskStatus = (String) variables.get(getServiceTaskVariableName(ActivitiRuntimeHelper.VARIABLE_STATUS));
    assertEquals(ActivitiRuntimeHelper.TASK_STATUS_SUCCESS, serviceTaskStatus);
    // Validate JSON response
    String jsonResponse = (String) variables.get(getServiceTaskVariableName(VARIABLE_JSON_RESPONSE));
    ObjectMapper om = new ObjectMapper();
    BusinessObjectData businessObjectData = om.readValue(jsonResponse.getBytes(), BusinessObjectData.class);
    assertEquals(namespace, businessObjectData.getNamespace());
    assertEquals(businessObjectDefinitionName, businessObjectData.getBusinessObjectDefinitionName());
    assertEquals(businessObjectFormatUsage, businessObjectData.getBusinessObjectFormatUsage());
    assertEquals(fileTypeCode, businessObjectData.getBusinessObjectFormatFileType());
    assertEquals(businessObjectFormatVersion.intValue(), businessObjectData.getBusinessObjectFormatVersion());
    assertEquals(partitionKey, businessObjectData.getPartitionKey());
    assertEquals(partitionValue, businessObjectData.getPartitionValue());
    assertNotNull(businessObjectData.getSubPartitionValues());
    assertEquals(4, businessObjectData.getSubPartitionValues().size());
    assertEquals(partitionValues[1], businessObjectData.getSubPartitionValues().get(0));
    assertEquals(partitionValues[2], businessObjectData.getSubPartitionValues().get(1));
    assertEquals(partitionValues[3], businessObjectData.getSubPartitionValues().get(2));
    assertEquals(partitionValues[4], businessObjectData.getSubPartitionValues().get(3));
    assertEquals(businessObjectDataVersion.intValue(), businessObjectData.getVersion());
    assertEquals(true, businessObjectData.isLatestVersion());
    assertEquals(1, businessObjectData.getStorageUnits().size());
    assertEquals(0, businessObjectData.getAttributes().size());
    assertEquals(0, businessObjectData.getBusinessObjectDataParents().size());
    assertEquals(0, businessObjectData.getBusinessObjectDataChildren().size());
}
Also used : BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 74 with BusinessObjectData

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

the class BusinessObjectDataRestController method createBusinessObjectData.

/**
 * Creates (i.e. registers) business object data. You may pre-register business object data by setting the status to one of the pre-registration statuses
 * (UPLOADING, PENDING_VALID, and PROCESSING). <p> Requires WRITE permission on namespace </p>
 *
 * @param businessObjectDataCreateRequest the information needed to create the business object data
 *
 * @return the created business object data
 */
@RequestMapping(value = "/businessObjectData", method = RequestMethod.POST, consumes = { "application/xml", "application/json" })
@Secured(SecurityFunctions.FN_BUSINESS_OBJECT_DATA_POST)
public BusinessObjectData createBusinessObjectData(@RequestBody BusinessObjectDataCreateRequest businessObjectDataCreateRequest) {
    BusinessObjectData businessObjectData = businessObjectDataService.createBusinessObjectData(businessObjectDataCreateRequest);
    // TODO This should be enhanced such that the notification events are captured by probably as an advice, and these calls are not specified everywhere
    // in the code.
    // The calls to notifications is being done in REST layer so that the event transaction (e.g. in this case: create business object data) is committed
    // and the event data is available for when notification is processed.
    // With proposed designed, when we go to event publish mode(e.g. create a database record for the event that will be picked up by notification
    // processing engine), We would want the event transaction to also rollback if event publishing failed. These calls will be moved to service layer.
    // Trigger notifications.
    businessObjectDataDaoHelper.triggerNotificationsForCreateBusinessObjectData(businessObjectData);
    return businessObjectData;
}
Also used : BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) Secured(org.springframework.security.access.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 75 with BusinessObjectData

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

the class BusinessObjectDataDaoTest method testBusinessObjectDataSearchWithPartitionValueRangeFiltersNegative.

@Test
public void testBusinessObjectDataSearchWithPartitionValueRangeFiltersNegative() {
    BusinessObjectDataEntity businessObjectDataEntity = createBusinessObjectEntityForPartitionValueFilterTest();
    String namespace = businessObjectDataEntity.getBusinessObjectFormat().getBusinessObjectDefinition().getNamespace().getCode();
    String bDefName = businessObjectDataEntity.getBusinessObjectFormat().getBusinessObjectDefinition().getName();
    String usage = businessObjectDataEntity.getBusinessObjectFormat().getUsage();
    String fileTypeCode = businessObjectDataEntity.getBusinessObjectFormat().getFileType().getCode();
    int formatVerion = businessObjectDataEntity.getBusinessObjectFormat().getBusinessObjectFormatVersion();
    BusinessObjectDataSearchKey businessObjectDataSearchKey = new BusinessObjectDataSearchKey();
    List<PartitionValueFilter> partitionValueFilters = new ArrayList<>();
    PartitionValueFilter partitionValueFilter = new PartitionValueFilter();
    partitionValueFilters.add(partitionValueFilter);
    partitionValueFilter.setPartitionKey(PARTITION_KEY + "6");
    PartitionValueRange partitionValueRange = new PartitionValueRange();
    partitionValueRange.setStartPartitionValue(PARTITION_VALUE);
    partitionValueRange.setEndPartitionValue(PARTITION_VALUE + "1");
    partitionValueFilter.setPartitionValueRange(partitionValueRange);
    businessObjectDataSearchKey.setPartitionValueFilters(partitionValueFilters);
    businessObjectDataSearchKey.setNamespace(namespace);
    businessObjectDataSearchKey.setBusinessObjectDefinitionName(bDefName);
    businessObjectDataSearchKey.setBusinessObjectFormatUsage(usage);
    businessObjectDataSearchKey.setBusinessObjectFormatFileType(fileTypeCode);
    businessObjectDataSearchKey.setBusinessObjectFormatVersion(formatVerion);
    List<BusinessObjectData> result = businessObjectDataDao.searchBusinessObjectData(businessObjectDataSearchKey, DEFAULT_PAGE_NUMBER, DEFAULT_PAGE_SIZE);
    assertEquals(0, result.size());
}
Also used : PartitionValueRange(org.finra.herd.model.api.xml.PartitionValueRange) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) ArrayList(java.util.ArrayList) BusinessObjectDataSearchKey(org.finra.herd.model.api.xml.BusinessObjectDataSearchKey) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) PartitionValueFilter(org.finra.herd.model.api.xml.PartitionValueFilter) Test(org.junit.Test)

Aggregations

BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)150 Test (org.junit.Test)121 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)64 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)57 ArrayList (java.util.ArrayList)39 BusinessObjectDataSearchKey (org.finra.herd.model.api.xml.BusinessObjectDataSearchKey)29 StorageUnit (org.finra.herd.model.api.xml.StorageUnit)25 BusinessObjectDataCreateRequest (org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest)19 Storage (org.finra.herd.model.api.xml.Storage)19 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)16 Attribute (org.finra.herd.model.api.xml.Attribute)15 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)14 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)12 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)11 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)9 AttributeValueFilter (org.finra.herd.model.api.xml.AttributeValueFilter)8 UploaderInputManifestDto (org.finra.herd.model.dto.UploaderInputManifestDto)8 IOException (java.io.IOException)7 BusinessObjectDataRetryStoragePolicyTransitionRequest (org.finra.herd.model.api.xml.BusinessObjectDataRetryStoragePolicyTransitionRequest)7 BusinessObjectDataSearchRequest (org.finra.herd.model.api.xml.BusinessObjectDataSearchRequest)7