Search in sources :

Example 56 with BusinessObjectDataKey

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

the class UploadDownloadServiceImpl method extendUploadSingleCredentials.

@NamespacePermission(fields = "#namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public UploadSingleCredentialExtensionResponse extendUploadSingleCredentials(String namespace, String businessObjectDefinitionName, String businessObjectFormatUsage, String businessObjectFormatFileType, Integer businessObjectFormatVersion, String partitionValue, Integer businessObjectDataVersion) {
    // Create the business object data key.
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(namespace, businessObjectDefinitionName, businessObjectFormatUsage, businessObjectFormatFileType, businessObjectFormatVersion, partitionValue, null, businessObjectDataVersion);
    // Validate and trim the business object data key.
    businessObjectDataHelper.validateBusinessObjectDataKey(businessObjectDataKey, true, true);
    // Get the business object data for the key.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey);
    // Ensure the status of the business object data is "uploading" in order to extend credentials.
    if (!(businessObjectDataEntity.getStatus().getCode().equals(BusinessObjectDataStatusEntity.UPLOADING))) {
        throw new IllegalArgumentException(String.format(String.format("Business object data {%s} has a status of \"%s\" and must be \"%s\" to extend " + "credentials.", businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey), businessObjectDataEntity.getStatus().getCode(), BusinessObjectDataStatusEntity.UPLOADING)));
    }
    // Get the S3 managed "loading dock" storage entity and make sure it exists.
    StorageEntity storageEntity = storageDaoHelper.getStorageEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE);
    String s3BucketName = storageHelper.getStorageBucketName(storageEntity);
    // Get the storage unit entity for this business object data in the S3 managed "loading dock" storage and make sure it exists.
    StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, businessObjectDataEntity);
    // Validate that the storage unit contains exactly one storage file.
    assertHasOneStorageFile(storageUnitEntity);
    // Get the storage file entity.
    StorageFileEntity storageFileEntity = IterableUtils.get(storageUnitEntity.getStorageFiles(), 0);
    // Get the storage file path.
    String storageFilePath = storageFileEntity.getPath();
    String awsRoleArn = getStorageUploadRoleArn(storageEntity);
    Integer awsRoleDurationSeconds = getStorageUploadSessionDuration(storageEntity);
    String awsKmsKeyId = storageHelper.getStorageKmsKeyId(storageEntity);
    // Get the temporary security credentials to access S3_MANAGED_STORAGE.
    Credentials assumedSessionCredentials = stsDao.getTemporarySecurityCredentials(awsHelper.getAwsParamsDto(), String.valueOf(businessObjectDataEntity.getId()), awsRoleArn, awsRoleDurationSeconds, createUploaderPolicy(s3BucketName, storageFilePath, awsKmsKeyId));
    // Create the response.
    UploadSingleCredentialExtensionResponse response = new UploadSingleCredentialExtensionResponse();
    response.setAwsAccessKey(assumedSessionCredentials.getAccessKeyId());
    response.setAwsSecretKey(assumedSessionCredentials.getSecretAccessKey());
    response.setAwsSessionToken(assumedSessionCredentials.getSessionToken());
    response.setAwsSessionExpirationTime(HerdDateUtils.getXMLGregorianCalendarValue(assumedSessionCredentials.getExpiration()));
    return response;
}
Also used : StorageFileEntity(org.finra.herd.model.jpa.StorageFileEntity) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) UploadSingleCredentialExtensionResponse(org.finra.herd.model.api.xml.UploadSingleCredentialExtensionResponse) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Credentials(com.amazonaws.services.securitytoken.model.Credentials) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 57 with BusinessObjectDataKey

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

the class StorageUnitServiceImpl method getS3KeyPrefixImpl.

/**
 * Gets the S3 key prefix.
 *
 * @param businessObjectDataKey the business object data key
 * @param businessObjectFormatPartitionKey the business object format partition key
 * @param storageName the storage name
 * @param createNewVersion specifies if it is OK to return an S3 key prefix for a new business object data version that is not an initial version. This
 * parameter is ignored, when the business object data version is specified.
 *
 * @return the S3 key prefix
 */
protected S3KeyPrefixInformation getS3KeyPrefixImpl(BusinessObjectDataKey businessObjectDataKey, String businessObjectFormatPartitionKey, String storageName, Boolean createNewVersion) {
    // Validate and trim the business object data key.
    businessObjectDataHelper.validateBusinessObjectDataKey(businessObjectDataKey, true, false);
    // If specified, trim the partition key parameter.
    String businessObjectFormatPartitionKeyLocal = businessObjectFormatPartitionKey;
    if (businessObjectFormatPartitionKeyLocal != null) {
        businessObjectFormatPartitionKeyLocal = businessObjectFormatPartitionKeyLocal.trim();
    }
    // If specified, trim the storage name. Otherwise, default to the configuration option.
    String storageNameLocal = storageName;
    if (StringUtils.isNotBlank(storageNameLocal)) {
        storageNameLocal = storageNameLocal.trim();
    } else {
        storageNameLocal = configurationHelper.getProperty(ConfigurationValue.S3_STORAGE_NAME_DEFAULT);
    }
    // Get the business object format for the specified parameters and make sure it exists.
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(new BusinessObjectFormatKey(businessObjectDataKey.getNamespace(), businessObjectDataKey.getBusinessObjectDefinitionName(), businessObjectDataKey.getBusinessObjectFormatUsage(), businessObjectDataKey.getBusinessObjectFormatFileType(), businessObjectDataKey.getBusinessObjectFormatVersion()));
    // If specified, ensure that partition key matches what's configured within the business object format.
    if (StringUtils.isNotBlank(businessObjectFormatPartitionKeyLocal)) {
        Assert.isTrue(businessObjectFormatEntity.getPartitionKey().equalsIgnoreCase(businessObjectFormatPartitionKeyLocal), "Partition key \"" + businessObjectFormatPartitionKeyLocal + "\" doesn't match configured business object format partition key \"" + businessObjectFormatEntity.getPartitionKey() + "\".");
    }
    // Get and validate the storage along with the relative attributes.
    StorageEntity storageEntity = storageDaoHelper.getStorageEntity(storageNameLocal);
    // If the business object data version is not specified, get the next business object data version value.
    if (businessObjectDataKey.getBusinessObjectDataVersion() == null) {
        // Get the latest data version for this business object data, if it exists.
        BusinessObjectDataEntity latestVersionBusinessObjectDataEntity = businessObjectDataDao.getBusinessObjectDataByAltKey(new BusinessObjectDataKey(businessObjectDataKey.getNamespace(), businessObjectDataKey.getBusinessObjectDefinitionName(), businessObjectDataKey.getBusinessObjectFormatUsage(), businessObjectDataKey.getBusinessObjectFormatFileType(), businessObjectDataKey.getBusinessObjectFormatVersion(), businessObjectDataKey.getPartitionValue(), businessObjectDataKey.getSubPartitionValues(), null));
        // Throw an error if this business object data already exists and createNewVersion flag is not set.
        if (latestVersionBusinessObjectDataEntity != null && !createNewVersion) {
            throw new AlreadyExistsException("Initial version of the business object data already exists.");
        }
        businessObjectDataKey.setBusinessObjectDataVersion(latestVersionBusinessObjectDataEntity == null ? BusinessObjectDataEntity.BUSINESS_OBJECT_DATA_INITIAL_VERSION : latestVersionBusinessObjectDataEntity.getVersion() + 1);
    }
    // Build the S3 key prefix string.
    String s3KeyPrefix = s3KeyPrefixHelper.buildS3KeyPrefix(storageEntity, businessObjectFormatEntity, businessObjectDataKey);
    // Create and return the S3 key prefix.
    S3KeyPrefixInformation s3KeyPrefixInformation = new S3KeyPrefixInformation();
    s3KeyPrefixInformation.setS3KeyPrefix(s3KeyPrefix);
    return s3KeyPrefixInformation;
}
Also used : AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) S3KeyPrefixInformation(org.finra.herd.model.api.xml.S3KeyPrefixInformation) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey)

Example 58 with BusinessObjectDataKey

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

the class BusinessObjectDataAttributeServiceTest method testGetBusinessObjectDataAttributesLowerCaseParameters.

@Test
public void testGetBusinessObjectDataAttributesLowerCaseParameters() {
    // List of test business object data attribute names.
    List<String> testBusinessObjectDataAttributeNames = Arrays.asList(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_NAME_2_MIXED_CASE);
    // Create and persist a business object data attribute entities using upper case values.
    for (String businessObjectDataAttributeName : testBusinessObjectDataAttributeNames) {
        businessObjectDataAttributeDaoTestHelper.createBusinessObjectDataAttributeEntity(NAMESPACE, BDEF_NAME.toUpperCase(), FORMAT_USAGE_CODE.toUpperCase(), FORMAT_FILE_TYPE_CODE.toUpperCase(), FORMAT_VERSION, PARTITION_VALUE.toUpperCase(), convertListToUpperCase(SUBPARTITION_VALUES), DATA_VERSION, businessObjectDataAttributeName.toUpperCase(), ATTRIBUTE_VALUE_1.toUpperCase());
    }
    // Retrieve a list of business object data attribute keys using lower case input parameters (except for case-sensitive partition values).
    BusinessObjectDataAttributeKeys resultBusinessObjectDataAttributeKeys = businessObjectDataAttributeService.getBusinessObjectDataAttributes(new BusinessObjectDataKey(NAMESPACE, BDEF_NAME.toLowerCase(), FORMAT_USAGE_CODE.toLowerCase(), FORMAT_FILE_TYPE_CODE.toLowerCase(), FORMAT_VERSION, PARTITION_VALUE.toUpperCase(), convertListToUpperCase(SUBPARTITION_VALUES), DATA_VERSION));
    // Validate the returned object.
    assertNotNull(resultBusinessObjectDataAttributeKeys);
    assertEquals(testBusinessObjectDataAttributeNames.size(), resultBusinessObjectDataAttributeKeys.getBusinessObjectDataAttributeKeys().size());
    for (int i = 0; i < testBusinessObjectDataAttributeNames.size(); i++) {
        businessObjectDataAttributeServiceTestHelper.validateBusinessObjectDataAttributeKey(NAMESPACE, BDEF_NAME.toUpperCase(), FORMAT_USAGE_CODE.toUpperCase(), FORMAT_FILE_TYPE_CODE.toUpperCase(), FORMAT_VERSION, PARTITION_VALUE.toUpperCase(), convertListToUpperCase(SUBPARTITION_VALUES), DATA_VERSION, testBusinessObjectDataAttributeNames.get(i).toUpperCase(), resultBusinessObjectDataAttributeKeys.getBusinessObjectDataAttributeKeys().get(i));
    }
}
Also used : BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectDataAttributeKeys(org.finra.herd.model.api.xml.BusinessObjectDataAttributeKeys) Test(org.junit.Test)

Example 59 with BusinessObjectDataKey

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

the class BusinessObjectDataAttributeServiceTest method testBusinessObjectDataAttributeServiceMethodsNewTransactionPropagation.

/**
 * This method is to get coverage for the business object data attribute service methods that have an explicit annotation for transaction propagation.
 */
@Test
public void testBusinessObjectDataAttributeServiceMethodsNewTransactionPropagation() {
    // 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 attribute key.
    BusinessObjectDataAttributeKey businessObjectDataAttributeKey = businessObjectDataAttributeHelper.getBusinessObjectDataAttributeKey(businessObjectDataKey, ATTRIBUTE_NAME_1_MIXED_CASE);
    // Try to create a business object data attribute when specified business object format does not exist.
    try {
        businessObjectDataAttributeServiceImpl.createBusinessObjectDataAttribute(new BusinessObjectDataAttributeCreateRequest(businessObjectDataAttributeKey, ATTRIBUTE_VALUE_1));
        fail("Should throw an ObjectNotFoundException when not able to find business object format.");
    } catch (ObjectNotFoundException e) {
        assertEquals(businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatNotFoundErrorMessage(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION), e.getMessage());
    }
    // Try to retrieve a business object data attribute when specified business object data instance does not exist.
    try {
        businessObjectDataAttributeServiceImpl.getBusinessObjectDataAttribute(businessObjectDataAttributeKey);
        fail("Should throw an ObjectNotFoundException when not able to find business object data.");
    } catch (ObjectNotFoundException e) {
        assertEquals(businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataNotFoundErrorMessage(businessObjectDataKey, NO_BDATA_STATUS), e.getMessage());
    }
    // Try to update a business object data attribute when specified business object format does not exist.
    try {
        businessObjectDataAttributeServiceImpl.updateBusinessObjectDataAttribute(businessObjectDataAttributeKey, new BusinessObjectDataAttributeUpdateRequest(ATTRIBUTE_VALUE_2));
        fail("Should throw an ObjectNotFoundException when not able to find business object format.");
    } catch (ObjectNotFoundException e) {
        assertEquals(businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatNotFoundErrorMessage(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION), e.getMessage());
    }
    // Try to delete a business object data attribute when specified business object format does not exist.
    try {
        businessObjectDataAttributeServiceImpl.deleteBusinessObjectDataAttribute(businessObjectDataAttributeKey);
        fail("Should throw an ObjectNotFoundException when not able to find business object format.");
    } catch (ObjectNotFoundException e) {
        assertEquals(businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatNotFoundErrorMessage(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION), e.getMessage());
    }
    // Try to retrieve keys for all business object data attributes for a non-existing business object data.
    try {
        assertTrue(CollectionUtils.isEmpty(businessObjectDataAttributeServiceImpl.getBusinessObjectDataAttributes(businessObjectDataKey).getBusinessObjectDataAttributeKeys()));
        fail("Should throw an ObjectNotFoundException when not able to find business object data.");
    } catch (ObjectNotFoundException e) {
        assertEquals(businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataNotFoundErrorMessage(businessObjectDataKey, NO_BDATA_STATUS), e.getMessage());
    }
}
Also used : BusinessObjectDataAttributeCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataAttributeCreateRequest) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) BusinessObjectDataAttributeUpdateRequest(org.finra.herd.model.api.xml.BusinessObjectDataAttributeUpdateRequest) BusinessObjectDataAttributeKey(org.finra.herd.model.api.xml.BusinessObjectDataAttributeKey) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Test(org.junit.Test)

Example 60 with BusinessObjectDataKey

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

the class BusinessObjectDataAttributeServiceTest method testGetBusinessObjectDataAttributes.

@Test
public void testGetBusinessObjectDataAttributes() {
    // List of test business object data attribute names.
    List<String> testBusinessObjectDataAttributeNames = Arrays.asList(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_NAME_2_MIXED_CASE);
    // Create and persist a business object data attribute entities.
    for (String businessObjectDataAttributeName : testBusinessObjectDataAttributeNames) {
        businessObjectDataAttributeDaoTestHelper.createBusinessObjectDataAttributeEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, businessObjectDataAttributeName, ATTRIBUTE_VALUE_1);
    }
    // Retrieve a list of business object data attribute keys.
    BusinessObjectDataAttributeKeys resultBusinessObjectDataAttributeKeys = businessObjectDataAttributeService.getBusinessObjectDataAttributes(new BusinessObjectDataKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION));
    // Validate the returned object.
    assertNotNull(resultBusinessObjectDataAttributeKeys);
    assertEquals(testBusinessObjectDataAttributeNames.size(), resultBusinessObjectDataAttributeKeys.getBusinessObjectDataAttributeKeys().size());
    for (int i = 0; i < testBusinessObjectDataAttributeNames.size(); i++) {
        businessObjectDataAttributeServiceTestHelper.validateBusinessObjectDataAttributeKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, testBusinessObjectDataAttributeNames.get(i), resultBusinessObjectDataAttributeKeys.getBusinessObjectDataAttributeKeys().get(i));
    }
}
Also used : BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectDataAttributeKeys(org.finra.herd.model.api.xml.BusinessObjectDataAttributeKeys) 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