Search in sources :

Example 1 with S3KeyPrefixInformation

use of org.finra.herd.model.api.xml.S3KeyPrefixInformation 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 2 with S3KeyPrefixInformation

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

the class DataBridgeWebClientTest method testGetS3KeyPrefix.

/**
 * Calls getS3KeyPrefix() method and makes assertions.
 *
 * @param namespace the namespace
 * @param subPartitionValues the list of sub-partition values
 * @param businessObjectDataVersion the version of the business object data, may be null
 * @param useSsl specifies whether to use SSL or not
 *
 * @throws Exception
 */
private void testGetS3KeyPrefix(String namespace, List<String> subPartitionValues, Integer businessObjectDataVersion, String storageName, boolean useSsl) throws Exception {
    dataBridgeWebClient.regServerAccessParamsDto.setUseSsl(useSsl);
    DataBridgeBaseManifestDto manifest = getUploaderInputManifestDto();
    manifest.setNamespace(namespace);
    manifest.setSubPartitionValues(subPartitionValues);
    manifest.setStorageName(storageName);
    Boolean createNewVersion = false;
    S3KeyPrefixInformation s3KeyPrefix = dataBridgeWebClient.getS3KeyPrefix(manifest, businessObjectDataVersion, createNewVersion);
    assertNotNull("s3KeyPrefix is null", s3KeyPrefix);
}
Also used : S3KeyPrefixInformation(org.finra.herd.model.api.xml.S3KeyPrefixInformation) DataBridgeBaseManifestDto(org.finra.herd.model.dto.DataBridgeBaseManifestDto)

Example 3 with S3KeyPrefixInformation

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

the class DownloaderWebClientTest method testGetS3KeyPrefix.

@Test
public void testGetS3KeyPrefix() throws Exception {
    // Upload and register business object data parents.
    uploadAndRegisterTestDataParents(downloaderWebClient);
    // Upload and register the initial version if of the test business object data.
    uploadTestDataFilesToS3(S3_TEST_PATH_V0);
    final UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto();
    executeWithoutLogging(DataBridgeWebClient.class, new Command() {

        @Override
        public void execute() throws Exception {
            BusinessObjectData businessObjectData = downloaderWebClient.preRegisterBusinessObjectData(uploaderInputManifestDto, StorageEntity.MANAGED_STORAGE, false);
            BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.getBusinessObjectDataKey(businessObjectData);
            downloaderWebClient.addStorageFiles(businessObjectDataKey, uploaderInputManifestDto, getTestS3FileTransferRequestParamsDto(S3_TEST_PATH_V0 + "/"), StorageEntity.MANAGED_STORAGE);
            downloaderWebClient.updateBusinessObjectDataStatus(businessObjectDataKey, BusinessObjectDataStatusEntity.VALID);
        }
    });
    // Get S3 key prefix.
    BusinessObjectData businessObjectData = toBusinessObjectData(uploaderInputManifestDto);
    S3KeyPrefixInformation resultS3KeyPrefixInformation = downloaderWebClient.getS3KeyPrefix(businessObjectData);
    // Validate the results.
    assertNotNull(resultS3KeyPrefixInformation);
    assertEquals(S3_SIMPLE_TEST_PATH, resultS3KeyPrefixInformation.getS3KeyPrefix());
}
Also used : UploaderInputManifestDto(org.finra.herd.model.dto.UploaderInputManifestDto) Command(org.finra.herd.core.Command) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) S3KeyPrefixInformation(org.finra.herd.model.api.xml.S3KeyPrefixInformation) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with S3KeyPrefixInformation

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

the class MockHttpClientOperationsImpl method buildGetS3KeyPrefixResponse.

/**
 * Builds a Get S3 Key Prefix response.
 *
 * @param response the response.
 * @param uri the URI of the incoming request.
 *
 * @throws JAXBException if a JAXB error occurred.
 */
private void buildGetS3KeyPrefixResponse(MockCloseableHttpResponse response, URI uri) throws JAXBException {
    Pattern pattern = Pattern.compile("/herd-app/rest/businessObjectData(/namespaces/(?<namespace>.*?))?" + "/businessObjectDefinitionNames/(?<businessObjectDefinitionName>.*?)/businessObjectFormatUsages/(?<businessObjectFormatUsage>.*?)" + "/businessObjectFormatFileTypes/(?<businessObjectFormatFileType>.*?)/businessObjectFormatVersions/(?<businessObjectFormatVersion>.*?)" + "/s3KeyPrefix");
    Matcher matcher = pattern.matcher(uri.getPath());
    if (matcher.find()) {
        S3KeyPrefixInformation s3KeyPrefixInformation = new S3KeyPrefixInformation();
        String namespace = getGroup(matcher, "namespace");
        namespace = namespace == null ? "testNamespace" : namespace;
        String businessObjectFormatUsage = getGroup(matcher, "businessObjectFormatUsage");
        String businessObjectFormatType = getGroup(matcher, "businessObjectFormatFileType");
        String businessObjectDefinitionName = getGroup(matcher, "businessObjectDefinitionName");
        String businessObjectFormatVersion = getGroup(matcher, "businessObjectFormatVersion");
        s3KeyPrefixInformation.setS3KeyPrefix(namespace.toLowerCase().replace('_', '-') + "/exchange-a/" + businessObjectFormatUsage.toLowerCase().replace('_', '-') + "/" + businessObjectFormatType.toLowerCase().replace('_', '-') + "/" + businessObjectDefinitionName.toLowerCase().replace('_', '-') + "/frmt-v" + businessObjectFormatVersion + "/data-v0/process-date=2014-01-31");
        response.setEntity(getHttpEntity(s3KeyPrefixInformation));
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) S3KeyPrefixInformation(org.finra.herd.model.api.xml.S3KeyPrefixInformation)

Example 5 with S3KeyPrefixInformation

use of org.finra.herd.model.api.xml.S3KeyPrefixInformation 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)

Aggregations

S3KeyPrefixInformation (org.finra.herd.model.api.xml.S3KeyPrefixInformation)20 Test (org.junit.Test)13 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)12 SchemaColumn (org.finra.herd.model.api.xml.SchemaColumn)8 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)5 File (java.io.File)4 Storage (org.finra.herd.model.api.xml.Storage)4 StorageUnit (org.finra.herd.model.api.xml.StorageUnit)4 DownloaderInputManifestDto (org.finra.herd.model.dto.DownloaderInputManifestDto)4 IOException (java.io.IOException)3 Path (java.nio.file.Path)3 AwsCredential (org.finra.herd.model.api.xml.AwsCredential)3 RegServerAccessParamsDto (org.finra.herd.model.dto.RegServerAccessParamsDto)3 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)3 S3FileTransferResultsDto (org.finra.herd.model.dto.S3FileTransferResultsDto)3 S3Service (org.finra.herd.service.S3Service)3 BusinessObjectDataHelper (org.finra.herd.service.helper.BusinessObjectDataHelper)3 StorageFileHelper (org.finra.herd.service.helper.StorageFileHelper)3 StorageHelper (org.finra.herd.service.helper.StorageHelper)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3