Search in sources :

Example 11 with StorageUnitCreateRequest

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

the class DataBridgeWebClient method preRegisterBusinessObjectData.

/**
 * Pre-registers business object data with the registration server.
 *
 * @param manifest the uploader input manifest file
 * @param storageName the storage name
 * @param createNewVersion if not set, only initial version of the business object data is allowed to be created
 *
 * @return the business object data returned by the registration server.
 * @throws IOException if an I/O error was encountered.
 * @throws JAXBException if a JAXB error was encountered.
 * @throws URISyntaxException if a URI syntax error was encountered.
 */
@SuppressFBWarnings(value = "VA_FORMAT_STRING_USES_NEWLINE", justification = "We will use the standard carriage return character.")
public BusinessObjectData preRegisterBusinessObjectData(UploaderInputManifestDto manifest, String storageName, Boolean createNewVersion) throws IOException, JAXBException, URISyntaxException {
    LOGGER.info("Pre-registering business object data with the registration server...");
    BusinessObjectDataCreateRequest request = new BusinessObjectDataCreateRequest();
    request.setNamespace(manifest.getNamespace());
    request.setBusinessObjectDefinitionName(manifest.getBusinessObjectDefinitionName());
    request.setBusinessObjectFormatUsage(manifest.getBusinessObjectFormatUsage());
    request.setBusinessObjectFormatFileType(manifest.getBusinessObjectFormatFileType());
    request.setBusinessObjectFormatVersion(Integer.parseInt(manifest.getBusinessObjectFormatVersion()));
    request.setPartitionKey(manifest.getPartitionKey());
    request.setPartitionValue(manifest.getPartitionValue());
    request.setSubPartitionValues(manifest.getSubPartitionValues());
    request.setCreateNewVersion(createNewVersion);
    request.setStatus(BusinessObjectDataStatusEntity.UPLOADING);
    List<StorageUnitCreateRequest> storageUnits = new ArrayList<>();
    request.setStorageUnits(storageUnits);
    StorageUnitCreateRequest storageUnit = new StorageUnitCreateRequest();
    storageUnits.add(storageUnit);
    storageUnit.setStorageName(storageName);
    // Add business object data attributes, if any.
    if (manifest.getAttributes() != null) {
        List<Attribute> attributes = new ArrayList<>();
        request.setAttributes(attributes);
        for (Map.Entry<String, String> entry : manifest.getAttributes().entrySet()) {
            Attribute attribute = new Attribute();
            attributes.add(attribute);
            attribute.setName(entry.getKey());
            attribute.setValue(entry.getValue());
        }
    }
    // Add business object data parents, if any.
    request.setBusinessObjectDataParents(manifest.getBusinessObjectDataParents());
    // Create a JAXB context and marshaller
    JAXBContext requestContext = JAXBContext.newInstance(BusinessObjectDataCreateRequest.class);
    Marshaller requestMarshaller = requestContext.createMarshaller();
    requestMarshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.name());
    requestMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    StringWriter sw = new StringWriter();
    requestMarshaller.marshal(request, sw);
    BusinessObjectData businessObjectData;
    try (CloseableHttpClient client = httpClientOperations.createHttpClient()) {
        URI uri = new URIBuilder().setScheme(getUriScheme()).setHost(regServerAccessParamsDto.getRegServerHost()).setPort(regServerAccessParamsDto.getRegServerPort()).setPath(HERD_APP_REST_URI_PREFIX + "/businessObjectData").build();
        HttpPost post = new HttpPost(uri);
        post.addHeader("Content-Type", DEFAULT_CONTENT_TYPE);
        post.addHeader("Accepts", DEFAULT_ACCEPT);
        // If SSL is enabled, set the client authentication header.
        if (regServerAccessParamsDto.isUseSsl()) {
            post.addHeader(getAuthorizationHeader());
        }
        post.setEntity(new StringEntity(sw.toString()));
        LOGGER.info(String.format("    HTTP POST URI: %s", post.getURI().toString()));
        LOGGER.info(String.format("    HTTP POST Headers: %s", Arrays.toString(post.getAllHeaders())));
        LOGGER.info(String.format("    HTTP POST Entity Content:%n%s", sw.toString()));
        businessObjectData = getBusinessObjectData(httpClientOperations.execute(client, post), "register business object data with the registration server");
    }
    LOGGER.info(String.format("Successfully pre-registered business object data with the registration server. businessObjectDataId=%s", businessObjectData.getId()));
    return businessObjectData;
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) Marshaller(javax.xml.bind.Marshaller) Attribute(org.finra.herd.model.api.xml.Attribute) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) BusinessObjectDataCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest) ArrayList(java.util.ArrayList) JAXBContext(javax.xml.bind.JAXBContext) URI(java.net.URI) URIBuilder(org.apache.http.client.utils.URIBuilder) StringEntity(org.apache.http.entity.StringEntity) StringWriter(java.io.StringWriter) StorageUnitCreateRequest(org.finra.herd.model.api.xml.StorageUnitCreateRequest) Map(java.util.Map) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 12 with StorageUnitCreateRequest

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

the class BusinessObjectDataHelper method createBusinessObjectDataCreateRequest.

/**
 * Validates the upload single initiation request. This method also trims the request parameters.
 *
 * @param businessObjectFormatEntity the business object format entity
 * @param uuid the UUID
 * @param businessObjectDataStatus the status of the business object data
 * @param attributes the list of attributes
 * @param storageEntity the storage entity
 * @param storageDirectoryPath the storage directory path
 * @param storageFilePath the storage file path
 * @param storageFileSizeBytes the storage file size in bytes
 * @param storageFileRowCount the storage file row count
 *
 * @return the business object data create request.
 */
public BusinessObjectDataCreateRequest createBusinessObjectDataCreateRequest(BusinessObjectFormatEntity businessObjectFormatEntity, String uuid, String businessObjectDataStatus, List<Attribute> attributes, StorageEntity storageEntity, String storageDirectoryPath, String storageFilePath, Long storageFileSizeBytes, Long storageFileRowCount) {
    BusinessObjectDataCreateRequest request = new BusinessObjectDataCreateRequest();
    // Set the values required for the business object data partition key.
    request.setNamespace(businessObjectFormatEntity.getBusinessObjectDefinition().getNamespace().getCode());
    request.setBusinessObjectDefinitionName(businessObjectFormatEntity.getBusinessObjectDefinition().getName());
    request.setBusinessObjectFormatUsage(businessObjectFormatEntity.getUsage());
    request.setBusinessObjectFormatFileType(businessObjectFormatEntity.getFileType().getCode());
    request.setBusinessObjectFormatVersion(businessObjectFormatEntity.getBusinessObjectFormatVersion());
    request.setPartitionKey(businessObjectFormatEntity.getPartitionKey());
    request.setPartitionValue(uuid);
    // Set the business object data status.
    request.setStatus(businessObjectDataStatus);
    // Add a storage unit.
    StorageUnitCreateRequest storageUnitCreateRequest = new StorageUnitCreateRequest();
    request.setStorageUnits(Arrays.asList(storageUnitCreateRequest));
    storageUnitCreateRequest.setStorageName(storageEntity.getName());
    storageUnitCreateRequest.setStorageDirectory(new StorageDirectory(storageDirectoryPath));
    storageUnitCreateRequest.setStorageFiles(Arrays.asList(new StorageFile(storageFilePath, storageFileSizeBytes, storageFileRowCount)));
    // Set the attributes if any are specified.
    request.setAttributes(attributes);
    // Since we are using UUID as our partition value, set the flag to only allow business object data initial version creation.
    request.setCreateNewVersion(false);
    return request;
}
Also used : BusinessObjectDataCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest) StorageFile(org.finra.herd.model.api.xml.StorageFile) StorageDirectory(org.finra.herd.model.api.xml.StorageDirectory) StorageUnitCreateRequest(org.finra.herd.model.api.xml.StorageUnitCreateRequest)

Example 13 with StorageUnitCreateRequest

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

the class BusinessObjectDataServiceCreateBusinessObjectDataTest method testCreateBusinessObjectDataDiscoverStorageFiles.

@Test
public void testCreateBusinessObjectDataDiscoverStorageFiles() throws Exception {
    // Create a business object format entity.
    businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, FORMAT_DESCRIPTION, LATEST_VERSION_FLAG_SET, PARTITION_KEY);
    // Create a business object data status entity.
    businessObjectDataStatusDaoTestHelper.createBusinessObjectDataStatusEntity(BDATA_STATUS);
    // Create and upload to S3 managed storage a set of test files.
    businessObjectDataServiceTestHelper.prepareTestS3Files(testS3KeyPrefix, localTempPath, LOCAL_FILES);
    // Build a new business object data create request with enabled discovery of storage files.
    BusinessObjectDataCreateRequest request = new BusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, NO_SUBPARTITION_VALUES, BDATA_STATUS, Arrays.asList(new StorageUnitCreateRequest(StorageEntity.MANAGED_STORAGE, new StorageDirectory(testS3KeyPrefix), NO_STORAGE_FILES, DISCOVER_STORAGE_FILES)), NO_ATTRIBUTES, NO_BUSINESS_OBJECT_DATA_PARENTS, NO_CREATE_NEW_VERSION);
    // Create the business object data.
    BusinessObjectData resultBusinessObjectData = businessObjectDataService.createBusinessObjectData(request);
    // Verify the results.
    assertEquals(new BusinessObjectData(resultBusinessObjectData.getId(), NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, NO_SUBPARTITION_VALUES, INITIAL_DATA_VERSION, LATEST_VERSION_FLAG_SET, BDATA_STATUS, Arrays.asList(new StorageUnit(new Storage(StorageEntity.MANAGED_STORAGE, StoragePlatformEntity.S3, Arrays.asList(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), storageDaoTestHelper.getS3ManagedBucketName()), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), S3_KEY_PREFIX_VELOCITY_TEMPLATE), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE), Boolean.TRUE.toString()), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_FILE_SIZE), Boolean.TRUE.toString()), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX), Boolean.TRUE.toString()))), new StorageDirectory(testS3KeyPrefix), businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, SORTED_LOCAL_FILES, false), StorageUnitStatusEntity.ENABLED, NO_STORAGE_UNIT_STATUS_HISTORY, NO_STORAGE_POLICY_TRANSITION_FAILED_ATTEMPTS, NO_RESTORE_EXPIRATION_ON)), NO_ATTRIBUTES, NO_BUSINESS_OBJECT_DATA_PARENTS, NO_BUSINESS_OBJECT_DATA_CHILDREN, NO_BUSINESS_OBJECT_DATA_STATUS_HISTORY), resultBusinessObjectData);
}
Also used : Storage(org.finra.herd.model.api.xml.Storage) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) Attribute(org.finra.herd.model.api.xml.Attribute) BusinessObjectDataCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest) StorageUnit(org.finra.herd.model.api.xml.StorageUnit) StorageDirectory(org.finra.herd.model.api.xml.StorageDirectory) StorageUnitCreateRequest(org.finra.herd.model.api.xml.StorageUnitCreateRequest) Test(org.junit.Test)

Example 14 with StorageUnitCreateRequest

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

the class BusinessObjectDataServiceCreateBusinessObjectDataTest method testCreateBusinessObjectDataMissingRequiredParameters.

@Test
public void testCreateBusinessObjectDataMissingRequiredParameters() {
    // Create relative database entities.
    businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, FORMAT_DESCRIPTION, true, PARTITION_KEY);
    storageDaoTestHelper.createStorageEntity(STORAGE_NAME);
    BusinessObjectDataCreateRequest request;
    List<StorageFile> storageFiles;
    // Try to create a business object data instance when business object definition name is not specified.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BLANK_TEXT, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when business object definition name is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A business object definition name must be specified.", e.getMessage());
    }
    // Try to create a business object data instance when business object format usage is not specified.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, BLANK_TEXT, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when business object format usage is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A business object format usage must be specified.", e.getMessage());
    }
    // Try to create a business object data instance when business object format file type is not specified.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, BLANK_TEXT, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when business object format file type is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A business object format file type must be specified.", e.getMessage());
    }
    // Try to create a business object data instance when business object format version is not specified.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, null, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when business object format version is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A business object format version must be specified.", e.getMessage());
    }
    // Try to create a business object data instance when business object format partition key is not specified.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, BLANK_TEXT, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when business object format partition key is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A partition key must be specified.", e.getMessage());
    }
    // Try to create a business object data instance when partition value is not specified.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, BLANK_TEXT, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when partition value is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A partition value must be specified.", e.getMessage());
    }
    // Try to create a business object data instance when request contains no storage units element.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    request.setStorageUnits(null);
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when when request contains no storage units element.");
    } catch (IllegalArgumentException e) {
        assertEquals("At least one storage unit must be specified.", e.getMessage());
    }
    // Try to create a business object data instance when no storage units are specified.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    request.setStorageUnits(new ArrayList<StorageUnitCreateRequest>());
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when when no storage units are specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("At least one storage unit must be specified.", e.getMessage());
    }
    // Try to create a business object data instance when request contains an empty storage unit element.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    List<StorageUnitCreateRequest> storageUnits = new ArrayList<>();
    storageUnits.add(null);
    request.setStorageUnits(storageUnits);
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when when no storage units are specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A storage unit can't be null.", e.getMessage());
    }
    // Try to create a business object data instance when storage name is not specified for a storage unit.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    request.getStorageUnits().get(0).setStorageName(BLANK_TEXT);
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when storage name is not specified for a storage unit.");
    } catch (IllegalArgumentException e) {
        assertEquals("A storage name is required for each storage unit.", e.getMessage());
    }
    // Try to create a business object data instance when both storage directory and storage files are not specified.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, null, null);
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when both storage directory and storage files are not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A storage directory or at least one storage file must be specified for each storage unit.", e.getMessage());
    }
    // Try to create a business object data instance when storage directory element is present, but the actual directory path value is not specified.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, BLANK_TEXT, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when storage directory element is present, but the actual directory path value is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A storage directory path must be specified.", e.getMessage());
    }
    // Try to create a business object data instance when storage file element is present, but the actual file path value is not specified.
    storageFiles = businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, Arrays.asList(LOCAL_FILE));
    storageFiles.get(0).setFilePath(BLANK_TEXT);
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, storageFiles);
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when storage file element is present, but the actual file path value is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A file path must be specified.", e.getMessage());
    }
    // Try to create a business object data instance when storage file size is not specified.
    storageFiles = businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, Arrays.asList(LOCAL_FILE));
    storageFiles.get(0).setFileSizeBytes(null);
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, storageFiles);
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when storage file size is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A file size must be specified.", e.getMessage());
    }
}
Also used : BusinessObjectDataCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest) StorageFile(org.finra.herd.model.api.xml.StorageFile) ArrayList(java.util.ArrayList) StorageUnitCreateRequest(org.finra.herd.model.api.xml.StorageUnitCreateRequest) Test(org.junit.Test)

Example 15 with StorageUnitCreateRequest

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

the class BusinessObjectDataServiceCreateBusinessObjectDataTest method testCreateBusinessObjectDataInvalidParameters.

@Test
public void testCreateBusinessObjectDataInvalidParameters() {
    // Try to create a business object data when namespace contains a forward slash character.
    try {
        businessObjectDataService.createBusinessObjectData(new BusinessObjectDataCreateRequest(addSlash(BDEF_NAMESPACE), BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, SUBPARTITION_VALUES, BusinessObjectDataStatusEntity.VALID, Arrays.asList(new StorageUnitCreateRequest(STORAGE_NAME, new StorageDirectory(STORAGE_DIRECTORY_PATH), NO_STORAGE_FILES, NO_DISCOVER_STORAGE_FILES)), NO_ATTRIBUTES, NO_BUSINESS_OBJECT_DATA_PARENTS, NO_CREATE_NEW_VERSION));
        fail("Should throw an IllegalArgumentException when namespace contains a forward slash character.");
    } catch (IllegalArgumentException e) {
        assertEquals("Namespace can not contain a forward slash character.", e.getMessage());
    }
    // Try to create a business object data when business object definition name contains a forward slash character.
    try {
        businessObjectDataService.createBusinessObjectData(new BusinessObjectDataCreateRequest(BDEF_NAMESPACE, addSlash(BDEF_NAME), FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, SUBPARTITION_VALUES, BusinessObjectDataStatusEntity.VALID, Arrays.asList(new StorageUnitCreateRequest(STORAGE_NAME, new StorageDirectory(STORAGE_DIRECTORY_PATH), NO_STORAGE_FILES, NO_DISCOVER_STORAGE_FILES)), NO_ATTRIBUTES, NO_BUSINESS_OBJECT_DATA_PARENTS, NO_CREATE_NEW_VERSION));
        fail("Should throw an IllegalArgumentException when business object definition name contains a forward slash character.");
    } catch (IllegalArgumentException e) {
        assertEquals("Business object definition name can not contain a forward slash character.", e.getMessage());
    }
    // Try to create a business object data when business object format usage contains a forward slash character.
    try {
        businessObjectDataService.createBusinessObjectData(new BusinessObjectDataCreateRequest(BDEF_NAMESPACE, BDEF_NAME, addSlash(FORMAT_USAGE_CODE), FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, SUBPARTITION_VALUES, BusinessObjectDataStatusEntity.VALID, Arrays.asList(new StorageUnitCreateRequest(STORAGE_NAME, new StorageDirectory(STORAGE_DIRECTORY_PATH), NO_STORAGE_FILES, NO_DISCOVER_STORAGE_FILES)), NO_ATTRIBUTES, NO_BUSINESS_OBJECT_DATA_PARENTS, NO_CREATE_NEW_VERSION));
        fail("Should throw an IllegalArgumentException when business object format usage contains a forward slash character.");
    } catch (IllegalArgumentException e) {
        assertEquals("Business object format usage can not contain a forward slash character.", e.getMessage());
    }
    // Try to create a business object data when business object format file type contains a forward slash character.
    try {
        businessObjectDataService.createBusinessObjectData(new BusinessObjectDataCreateRequest(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, addSlash(FORMAT_FILE_TYPE_CODE), FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, SUBPARTITION_VALUES, BusinessObjectDataStatusEntity.VALID, Arrays.asList(new StorageUnitCreateRequest(STORAGE_NAME, new StorageDirectory(STORAGE_DIRECTORY_PATH), NO_STORAGE_FILES, NO_DISCOVER_STORAGE_FILES)), NO_ATTRIBUTES, NO_BUSINESS_OBJECT_DATA_PARENTS, NO_CREATE_NEW_VERSION));
        fail("Should throw an IllegalArgumentException when business object format file type contains a forward slash character.");
    } catch (IllegalArgumentException e) {
        assertEquals("Business object format file type can not contain a forward slash character.", e.getMessage());
    }
    // Try to create a business object data when partition key contains a forward slash character.
    try {
        businessObjectDataService.createBusinessObjectData(new BusinessObjectDataCreateRequest(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, addSlash(PARTITION_KEY), PARTITION_VALUE, SUBPARTITION_VALUES, BusinessObjectDataStatusEntity.VALID, Arrays.asList(new StorageUnitCreateRequest(STORAGE_NAME, new StorageDirectory(STORAGE_DIRECTORY_PATH), NO_STORAGE_FILES, NO_DISCOVER_STORAGE_FILES)), NO_ATTRIBUTES, NO_BUSINESS_OBJECT_DATA_PARENTS, NO_CREATE_NEW_VERSION));
        fail("Should throw an IllegalArgumentException when partition key contains a forward slash character.");
    } catch (IllegalArgumentException e) {
        assertEquals("Partition key can not contain a forward slash character.", e.getMessage());
    }
    // Try to create a business object data when partition value contains a forward slash character.
    try {
        businessObjectDataService.createBusinessObjectData(new BusinessObjectDataCreateRequest(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_KEY, addSlash(PARTITION_VALUE), SUBPARTITION_VALUES, BusinessObjectDataStatusEntity.VALID, Arrays.asList(new StorageUnitCreateRequest(STORAGE_NAME, new StorageDirectory(STORAGE_DIRECTORY_PATH), NO_STORAGE_FILES, NO_DISCOVER_STORAGE_FILES)), NO_ATTRIBUTES, NO_BUSINESS_OBJECT_DATA_PARENTS, NO_CREATE_NEW_VERSION));
        fail("Should throw an IllegalArgumentException when partition value contains a forward slash character.");
    } catch (IllegalArgumentException e) {
        assertEquals("Partition value can not contain a forward slash character.", e.getMessage());
    }
    // Try to create a business object data when a sub-partition value contains a forward slash character.
    try {
        businessObjectDataService.createBusinessObjectData(new BusinessObjectDataCreateRequest(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, Arrays.asList(addSlash(PARTITION_VALUE_2)), BusinessObjectDataStatusEntity.VALID, Arrays.asList(new StorageUnitCreateRequest(STORAGE_NAME, new StorageDirectory(STORAGE_DIRECTORY_PATH), NO_STORAGE_FILES, NO_DISCOVER_STORAGE_FILES)), NO_ATTRIBUTES, NO_BUSINESS_OBJECT_DATA_PARENTS, NO_CREATE_NEW_VERSION));
        fail("Should throw an IllegalArgumentException when sub-partition value contains a forward slash character.");
    } catch (IllegalArgumentException e) {
        assertEquals("Subpartition value can not contain a forward slash character.", e.getMessage());
    }
    // Try to create a business object data when an attribute name contains a forward slash character.
    try {
        businessObjectDataService.createBusinessObjectData(new BusinessObjectDataCreateRequest(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, SUBPARTITION_VALUES, BusinessObjectDataStatusEntity.VALID, Arrays.asList(new StorageUnitCreateRequest(STORAGE_NAME, new StorageDirectory(STORAGE_DIRECTORY_PATH), NO_STORAGE_FILES, NO_DISCOVER_STORAGE_FILES)), Arrays.asList(new Attribute(addSlash(ATTRIBUTE_NAME_1_MIXED_CASE), ATTRIBUTE_VALUE_1)), NO_BUSINESS_OBJECT_DATA_PARENTS, NO_CREATE_NEW_VERSION));
        fail("Should throw an IllegalArgumentException when attribute name contains a forward slash character.");
    } catch (IllegalArgumentException e) {
        assertEquals("Attribute name can not contain a forward slash character.", e.getMessage());
    }
}
Also used : Attribute(org.finra.herd.model.api.xml.Attribute) BusinessObjectDataCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest) StorageDirectory(org.finra.herd.model.api.xml.StorageDirectory) StorageUnitCreateRequest(org.finra.herd.model.api.xml.StorageUnitCreateRequest) Test(org.junit.Test)

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