Example usage for com.amazonaws.services.s3.model Tier fromValue

List of usage examples for com.amazonaws.services.s3.model Tier fromValue

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model Tier fromValue.

Prototype

public static Tier fromValue(String value) 

Source Link

Document

Use this in place of valueOf.

Usage

From source file:org.finra.herd.service.impl.BusinessObjectDataInitiateRestoreHelperServiceImpl.java

License:Apache License

/**
 * Prepares for the business object data initiate a restore request by validating the business object data along with other related database entities. The
 * method also creates and returns a business object data restore DTO.
 *
 * @param businessObjectDataKey the business object data key
 * @param expirationInDays the the time, in days, between when the business object data is restored to the S3 bucket and when it expires
 * @param archiveRetrievalOption the archive retrieval option when restoring an archived object.
 *
 * @return the DTO that holds various parameters needed to perform a business object data restore
 *///  ww w . j av a 2s .c om
protected BusinessObjectDataRestoreDto prepareToInitiateRestoreImpl(BusinessObjectDataKey businessObjectDataKey,
        Integer expirationInDays, String archiveRetrievalOption) {
    // Validate and trim the business object data key.
    businessObjectDataHelper.validateBusinessObjectDataKey(businessObjectDataKey, true, true);

    // If expiration time is not specified, use the configured default value.
    int localExpirationInDays = expirationInDays != null ? expirationInDays
            : herdStringHelper.getConfigurationValueAsInteger(
                    ConfigurationValue.BDATA_RESTORE_EXPIRATION_IN_DAYS_DEFAULT);

    // Validate the expiration time.
    Assert.isTrue(localExpirationInDays > 0, "Expiration in days value must be a positive integer.");

    // Trim the whitespaces
    if (archiveRetrievalOption != null) {
        archiveRetrievalOption = archiveRetrievalOption.trim();
    }

    // Validate the archive retrieval option
    if (StringUtils.isNotEmpty(archiveRetrievalOption)) {
        try {
            Tier.fromValue(archiveRetrievalOption);
        } catch (IllegalArgumentException ex) {
            throw new IllegalArgumentException(String.format(
                    "The archive retrieval option value \"%s\" is invalid. "
                            + "Valid archive retrieval option values are:%s",
                    archiveRetrievalOption,
                    Stream.of(Tier.values()).map(Enum::name).collect(Collectors.toList())));
        }
    }

    // Retrieve the business object data and ensure it exists.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper
            .getBusinessObjectDataEntity(businessObjectDataKey);

    // Retrieve and validate a Glacier storage unit for this business object data.
    StorageUnitEntity storageUnitEntity = getStorageUnit(businessObjectDataEntity);

    // Get the storage name.
    String storageName = storageUnitEntity.getStorage().getName();

    // Validate that S3 storage has S3 bucket name configured.
    // Please note that since S3 bucket name attribute value is required we pass a "true" flag.
    String s3BucketName = storageHelper.getStorageAttributeValueByName(
            configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME),
            storageUnitEntity.getStorage(), true);

    // Get storage specific S3 key prefix for this business object data.
    String s3KeyPrefix = s3KeyPrefixHelper.buildS3KeyPrefix(storageUnitEntity.getStorage(),
            businessObjectDataEntity.getBusinessObjectFormat(), businessObjectDataKey);

    // Retrieve and validate storage files registered with the storage unit.
    List<StorageFile> storageFiles = storageFileHelper.getAndValidateStorageFiles(storageUnitEntity,
            s3KeyPrefix, storageName, businessObjectDataKey);

    // Validate that this storage does not have any other registered storage files that
    // start with the S3 key prefix, but belong to other business object data instances.
    storageFileDaoHelper.validateStorageFilesCount(storageName, businessObjectDataKey, s3KeyPrefix,
            storageFiles.size());

    // Set the expiration time for the restored storage unit.
    Timestamp currentTime = new Timestamp(System.currentTimeMillis());
    storageUnitEntity.setRestoreExpirationOn(HerdDateUtils.addDays(currentTime, localExpirationInDays));

    // Retrieve and ensure the RESTORING storage unit status entity exists.
    StorageUnitStatusEntity newStorageUnitStatusEntity = storageUnitStatusDaoHelper
            .getStorageUnitStatusEntity(StorageUnitStatusEntity.RESTORING);

    // Save the old storage unit status value.
    String oldOriginStorageUnitStatus = storageUnitEntity.getStatus().getCode();

    // Update the S3 storage unit status to RESTORING.
    storageUnitDaoHelper.updateStorageUnitStatus(storageUnitEntity, newStorageUnitStatusEntity,
            StorageUnitStatusEntity.RESTORING);

    // Build the business object data restore parameters DTO.
    BusinessObjectDataRestoreDto businessObjectDataRestoreDto = new BusinessObjectDataRestoreDto();
    businessObjectDataRestoreDto.setBusinessObjectDataKey(
            businessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataEntity));
    businessObjectDataRestoreDto.setStorageName(storageName);
    businessObjectDataRestoreDto.setS3Endpoint(configurationHelper.getProperty(ConfigurationValue.S3_ENDPOINT));
    businessObjectDataRestoreDto.setS3BucketName(s3BucketName);
    businessObjectDataRestoreDto.setS3KeyPrefix(s3KeyPrefix);
    businessObjectDataRestoreDto.setStorageFiles(storageFiles);
    businessObjectDataRestoreDto.setArchiveRetrievalOption(archiveRetrievalOption);
    businessObjectDataRestoreDto.setNewStorageUnitStatus(newStorageUnitStatusEntity.getCode());
    businessObjectDataRestoreDto.setOldStorageUnitStatus(oldOriginStorageUnitStatus);

    // Return the parameters DTO.
    return businessObjectDataRestoreDto;
}