Search in sources :

Example 11 with BusinessObjectDataKey

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

the class GetBusinessObjectDataStatus method executeImpl.

@Override
public void executeImpl(DelegateExecution execution) throws Exception {
    String namespace = activitiHelper.getExpressionVariableAsString(this.namespace, execution);
    String businessObjectDefinitionName = activitiHelper.getExpressionVariableAsString(this.businessObjectDefinitionName, execution);
    String businessObjectFormatUsage = activitiHelper.getExpressionVariableAsString(this.businessObjectFormatUsage, execution);
    String businessObjectFormatFileType = activitiHelper.getExpressionVariableAsString(this.businessObjectFormatFileType, execution);
    Integer businessObjectFormatVersion = activitiHelper.getExpressionVariableAsInteger(this.businessObjectFormatVersion, execution, "businessObjectFormatVersion", false);
    String partitionValue = activitiHelper.getExpressionVariableAsString(this.partitionValue, execution);
    String subPartitionValuesString = activitiHelper.getExpressionVariableAsString(this.subPartitionValues, execution);
    List<String> subPartitionValues = daoHelper.splitStringWithDefaultDelimiterEscaped(subPartitionValuesString);
    Integer businessObjectDataVersion = activitiHelper.getExpressionVariableAsInteger(this.businessObjectDataVersion, execution, "businessObjectDataVersion", false);
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey();
    businessObjectDataKey.setNamespace(namespace);
    businessObjectDataKey.setBusinessObjectDefinitionName(businessObjectDefinitionName);
    businessObjectDataKey.setBusinessObjectFormatUsage(businessObjectFormatUsage);
    businessObjectDataKey.setBusinessObjectFormatFileType(businessObjectFormatFileType);
    businessObjectDataKey.setBusinessObjectFormatVersion(businessObjectFormatVersion);
    businessObjectDataKey.setPartitionValue(partitionValue);
    businessObjectDataKey.setSubPartitionValues(subPartitionValues);
    businessObjectDataKey.setBusinessObjectDataVersion(businessObjectDataVersion);
    BusinessObjectDataStatusInformation businessObjectDataStatusInformation = businessObjectDataStatusService.getBusinessObjectDataStatus(businessObjectDataKey, null);
    setJsonResponseAsWorkflowVariable(businessObjectDataStatusInformation, execution);
}
Also used : BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectDataStatusInformation(org.finra.herd.model.api.xml.BusinessObjectDataStatusInformation)

Example 12 with BusinessObjectDataKey

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

the class GetS3KeyPrefix method executeImpl.

@Override
public void executeImpl(DelegateExecution execution) throws Exception {
    String namespace = activitiHelper.getExpressionVariableAsString(this.namespace, execution);
    String businessObjectDefinitionName = activitiHelper.getExpressionVariableAsString(this.businessObjectDefinitionName, execution);
    String businessObjectFormatUsage = activitiHelper.getExpressionVariableAsString(this.businessObjectFormatUsage, execution);
    String businessObjectFormatFileType = activitiHelper.getExpressionVariableAsString(this.businessObjectFormatFileType, execution);
    Integer businessObjectFormatVersion = activitiHelper.getExpressionVariableAsInteger(this.businessObjectFormatVersion, execution, "businessObjectFormatVersion", true);
    String partitionKey = activitiHelper.getExpressionVariableAsString(this.partitionKey, execution);
    String partitionValue = activitiHelper.getExpressionVariableAsString(this.partitionValue, execution);
    String subPartitionValuesString = activitiHelper.getExpressionVariableAsString(this.subPartitionValues, execution);
    List<String> subPartitionValues = daoHelper.splitStringWithDefaultDelimiterEscaped(subPartitionValuesString);
    Integer businessObjectDataVersion = activitiHelper.getExpressionVariableAsInteger(this.businessObjectDataVersion, execution, "businessObjectDataVersion", false);
    String storageName = activitiHelper.getExpressionVariableAsString(this.storageName, execution);
    Boolean createNewVersion = activitiHelper.getExpressionVariableAsBoolean(this.createNewVersion, execution, "createNewVersion", false, false);
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey();
    businessObjectDataKey.setNamespace(namespace);
    businessObjectDataKey.setBusinessObjectDefinitionName(businessObjectDefinitionName);
    businessObjectDataKey.setBusinessObjectFormatUsage(businessObjectFormatUsage);
    businessObjectDataKey.setBusinessObjectFormatFileType(businessObjectFormatFileType);
    businessObjectDataKey.setBusinessObjectFormatVersion(businessObjectFormatVersion);
    businessObjectDataKey.setPartitionValue(partitionValue);
    businessObjectDataKey.setSubPartitionValues(subPartitionValues);
    businessObjectDataKey.setBusinessObjectDataVersion(businessObjectDataVersion);
    S3KeyPrefixInformation s3KeyPrefixInformation = storageUnitService.getS3KeyPrefix(businessObjectDataKey, partitionKey, storageName, createNewVersion);
    setTaskWorkflowVariable(execution, VARIABLE_S3_KEY_PREFIX, s3KeyPrefixInformation.getS3KeyPrefix());
}
Also used : S3KeyPrefixInformation(org.finra.herd.model.api.xml.S3KeyPrefixInformation) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey)

Example 13 with BusinessObjectDataKey

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

the class BusinessObjectDataInitiateDestroyHelperServiceImplTest method testValidateBusinessObjectDataInvalidPrimaryPartitionValue.

@Test
public void testValidateBusinessObjectDataInvalidPrimaryPartitionValue() {
    // Create a version-less business object format key.
    BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, NO_FORMAT_VERSION);
    // Create a business object data key.
    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 retention type entity.
    RetentionTypeEntity retentionTypeEntity = new RetentionTypeEntity();
    retentionTypeEntity.setCode(RetentionTypeEntity.PARTITION_VALUE);
    // Create a business object format entity.
    BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity();
    businessObjectFormatEntity.setLatestVersion(true);
    businessObjectFormatEntity.setRetentionType(retentionTypeEntity);
    businessObjectFormatEntity.setRetentionPeriodInDays(RETENTION_PERIOD_DAYS);
    // Create a business object data entity.
    BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
    businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity);
    businessObjectDataEntity.setPartitionValue(PARTITION_VALUE);
    // Mock the external calls.
    when(businessObjectDataHelper.getDateFromString(PARTITION_VALUE)).thenReturn(null);
    when(businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING);
    // Try to call the method under test.
    try {
        businessObjectDataInitiateDestroyHelperServiceImpl.validateBusinessObjectData(businessObjectDataEntity, businessObjectDataKey);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Primary partition value \"%s\" cannot get converted to a valid date. Business object data: {%s}", PARTITION_VALUE, BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage());
    }
    // Verify the external calls.
    verify(businessObjectDataHelper).getDateFromString(PARTITION_VALUE);
    verify(businessObjectDataHelper).businessObjectDataKeyToString(businessObjectDataKey);
    verifyNoMoreInteractionsHelper();
}
Also used : BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) RetentionTypeEntity(org.finra.herd.model.jpa.RetentionTypeEntity) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 14 with BusinessObjectDataKey

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

the class BusinessObjectDataInitiateRestoreHelperServiceImplTest method testExecuteS3SpecificSteps.

@Test
public void testExecuteS3SpecificSteps() {
    // Create a business object data key.
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION);
    // Create a list of storage files to be passed as an input.
    List<StorageFile> storageFiles = Arrays.asList(new StorageFile(S3_KEY, FILE_SIZE, ROW_COUNT));
    // Create a DTO for business object data restore parameters.
    BusinessObjectDataRestoreDto businessObjectDataRestoreDto = new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, S3_KEY_PREFIX, NO_STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS, storageFiles, NO_EXCEPTION);
    // Create an S3 file transfer parameters DTO to access the S3 bucket.
    S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
    // Create an updated version of the S3 file transfer request parameters DTO.
    S3FileTransferRequestParamsDto updatedS3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
    updatedS3FileTransferRequestParamsDto.setS3BucketName(S3_BUCKET_NAME);
    updatedS3FileTransferRequestParamsDto.setS3Endpoint(S3_ENDPOINT);
    updatedS3FileTransferRequestParamsDto.setS3KeyPrefix(S3_KEY_PREFIX + "/");
    // Create a mock S3 object summary for S3 object that does not belong to Glacier storage class.
    S3ObjectSummary glacierS3ObjectSummary = mock(S3ObjectSummary.class);
    when(glacierS3ObjectSummary.getStorageClass()).thenReturn(StorageClass.Glacier.toString());
    // Create a mock S3 object summary for S3 object that does not belong to Glacier storage class.
    S3ObjectSummary standardS3ObjectSummary = mock(S3ObjectSummary.class);
    when(standardS3ObjectSummary.getStorageClass()).thenReturn(StorageClass.Standard.toString());
    // Create a list of S3 files.
    List<S3ObjectSummary> s3Files = Arrays.asList(glacierS3ObjectSummary, standardS3ObjectSummary);
    // Create a list of S3 objects that belong to Glacier storage class.
    List<S3ObjectSummary> glacierS3Files = Arrays.asList(glacierS3ObjectSummary);
    // Create a list of storage files that represent S3 objects of Glacier storage class.
    List<StorageFile> glacierStorageFiles = Arrays.asList(new StorageFile(S3_KEY, FILE_SIZE, ROW_COUNT));
    // Create a list of storage files selected for S3 object tagging.
    List<File> filesSelectedForRestore = Arrays.asList(new File(S3_KEY));
    // Create a final version of DTO for business object data restore parameters.
    S3FileTransferRequestParamsDto finalS3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
    finalS3FileTransferRequestParamsDto.setS3BucketName(S3_BUCKET_NAME);
    finalS3FileTransferRequestParamsDto.setS3Endpoint(S3_ENDPOINT);
    finalS3FileTransferRequestParamsDto.setS3KeyPrefix(S3_KEY_PREFIX + "/");
    finalS3FileTransferRequestParamsDto.setFiles(filesSelectedForRestore);
    // Mock the external calls.
    when(storageHelper.getS3FileTransferRequestParamsDto()).thenReturn(s3FileTransferRequestParamsDto);
    when(s3Service.listDirectory(updatedS3FileTransferRequestParamsDto, true)).thenReturn(s3Files);
    when(storageFileHelper.createStorageFilesFromS3ObjectSummaries(glacierS3Files)).thenReturn(glacierStorageFiles);
    when(storageFileHelper.getFiles(glacierStorageFiles)).thenReturn(filesSelectedForRestore);
    // Call the method under test.
    businessObjectDataInitiateRestoreHelperServiceImpl.executeS3SpecificSteps(businessObjectDataRestoreDto);
    // Verify the external calls.
    verify(storageHelper).getS3FileTransferRequestParamsDto();
    verify(s3Service).listDirectory(any(S3FileTransferRequestParamsDto.class), eq(true));
    verify(storageFileHelper).validateRegisteredS3Files(storageFiles, s3Files, STORAGE_NAME, businessObjectDataKey);
    verify(storageFileHelper).createStorageFilesFromS3ObjectSummaries(glacierS3Files);
    verify(storageFileHelper).getFiles(glacierStorageFiles);
    verify(s3Service).restoreObjects(finalS3FileTransferRequestParamsDto, 36135);
    verifyNoMoreInteractionsHelper();
}
Also used : S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) StorageFile(org.finra.herd.model.api.xml.StorageFile) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectDataRestoreDto(org.finra.herd.model.dto.BusinessObjectDataRestoreDto) File(java.io.File) StorageFile(org.finra.herd.model.api.xml.StorageFile) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 15 with BusinessObjectDataKey

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

the class BusinessObjectDataStorageUnitServiceImplTest method testCreateBusinessObjectDataStorageUnit.

@Test
public void testCreateBusinessObjectDataStorageUnit() {
    // Create a business object data key.
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION);
    // Create a business object data storage unit key.
    BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey = new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME);
    // Create a storage unit directory.
    StorageDirectory storageDirectory = new StorageDirectory(STORAGE_DIRECTORY_PATH);
    // Create a list of storage files.
    List<StorageFile> storageFiles = Arrays.asList(new StorageFile(FILE_NAME, FILE_SIZE, ROW_COUNT), new StorageFile(FILE_NAME_2, FILE_SIZE_2, ROW_COUNT_2));
    // Create a business object data storage unit request.
    BusinessObjectDataStorageUnitCreateRequest request = new BusinessObjectDataStorageUnitCreateRequest(businessObjectDataStorageUnitKey, storageDirectory, storageFiles, NO_DISCOVER_STORAGE_FILES);
    // Create a business object data entity.
    BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
    businessObjectDataEntity.setId(ID);
    // Create a storage entity.
    StorageEntity storageEntity = new StorageEntity();
    storageEntity.setName(STORAGE_NAME);
    // Create a list of storage file entities.
    List<StorageFileEntity> storageFileEntities = Arrays.asList(new StorageFileEntity(), new StorageFileEntity());
    // Create a storage unit entity.
    StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
    storageUnitEntity.setBusinessObjectData(businessObjectDataEntity);
    storageUnitEntity.setStorage(storageEntity);
    storageUnitEntity.setDirectoryPath(STORAGE_DIRECTORY_PATH);
    storageUnitEntity.setStorageFiles(storageFileEntities);
    // Create an expected business object data storage unit response.
    BusinessObjectDataStorageUnitCreateResponse expectedResponse = new BusinessObjectDataStorageUnitCreateResponse(businessObjectDataStorageUnitKey, storageDirectory, storageFiles);
    // Mock the external calls.
    when(storageUnitHelper.getBusinessObjectDataKey(businessObjectDataStorageUnitKey)).thenReturn(businessObjectDataKey);
    when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey)).thenReturn(businessObjectDataEntity);
    when(storageDaoHelper.getStorageEntity(STORAGE_NAME)).thenReturn(storageEntity);
    when(businessObjectDataDaoHelper.createStorageUnitEntity(businessObjectDataEntity, storageEntity, storageDirectory, storageFiles, NO_DISCOVER_STORAGE_FILES)).thenReturn(storageUnitEntity);
    when(businessObjectDataHelper.createBusinessObjectDataKeyFromEntity(businessObjectDataEntity)).thenReturn(businessObjectDataKey);
    when(storageUnitHelper.createBusinessObjectDataStorageUnitKey(businessObjectDataKey, STORAGE_NAME)).thenReturn(businessObjectDataStorageUnitKey);
    when(storageFileHelper.createStorageFilesFromEntities(storageFileEntities)).thenReturn(storageFiles);
    // Call the method under test.
    BusinessObjectDataStorageUnitCreateResponse result = businessObjectDataStorageUnitServiceImpl.createBusinessObjectDataStorageUnit(request);
    // Verify the external calls.
    verify(storageUnitHelper).validateBusinessObjectDataStorageUnitKey(businessObjectDataStorageUnitKey);
    verify(storageFileHelper).validateCreateRequestStorageFiles(storageFiles);
    verify(storageUnitHelper).getBusinessObjectDataKey(businessObjectDataStorageUnitKey);
    verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey);
    verify(storageDaoHelper).getStorageEntity(STORAGE_NAME);
    verify(businessObjectDataDaoHelper).createStorageUnitEntity(businessObjectDataEntity, storageEntity, storageDirectory, storageFiles, NO_DISCOVER_STORAGE_FILES);
    verify(businessObjectDataHelper).createBusinessObjectDataKeyFromEntity(businessObjectDataEntity);
    verify(storageUnitHelper).createBusinessObjectDataStorageUnitKey(businessObjectDataKey, STORAGE_NAME);
    verify(storageFileHelper).createStorageFilesFromEntities(storageFileEntities);
    verify(storageUnitDao).saveAndRefresh(storageUnitEntity);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(expectedResponse, result);
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) StorageFileEntity(org.finra.herd.model.jpa.StorageFileEntity) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectDataStorageUnitCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitCreateRequest) BusinessObjectDataStorageUnitCreateResponse(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitCreateResponse) StorageFile(org.finra.herd.model.api.xml.StorageFile) StorageEntity(org.finra.herd.model.jpa.StorageEntity) StorageDirectory(org.finra.herd.model.api.xml.StorageDirectory) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Aggregations

BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)444 Test (org.junit.Test)378 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)138 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)93 ArrayList (java.util.ArrayList)92 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)78 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)62 StoragePolicyKey (org.finra.herd.model.api.xml.StoragePolicyKey)50 HashMap (java.util.HashMap)43 StorageFile (org.finra.herd.model.api.xml.StorageFile)38 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)36 BusinessObjectDataStorageUnitKey (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey)33 Attribute (org.finra.herd.model.api.xml.Attribute)32 NotificationMessageDefinitions (org.finra.herd.model.api.xml.NotificationMessageDefinitions)32 StoragePolicySelection (org.finra.herd.model.dto.StoragePolicySelection)32 ConfigurationEntity (org.finra.herd.model.jpa.ConfigurationEntity)32 NotificationMessageDefinition (org.finra.herd.model.api.xml.NotificationMessageDefinition)30 Parameter (org.finra.herd.model.api.xml.Parameter)30 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)29 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)29