Search in sources :

Example 61 with AbstractDataStorage

use of com.epam.pipeline.entity.datastorage.AbstractDataStorage in project cloud-pipeline by epam.

the class DataStorageMapper method map.

@Override
public XContentBuilder map(final EntityContainer<DataStorageDoc> doc) {
    try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
        AbstractDataStorage storage = doc.getEntity().getStorage();
        jsonBuilder.startObject().field(DOC_TYPE_FIELD, documentType.name()).field("id", storage.getId()).field("parentId", storage.getParentFolderId()).field("name", storage.getName()).field("path", storage.getPath()).field("createdDate", parseDataToString(storage.getCreatedDate())).field("description", storage.getDescription()).field("storageType", storage.getType()).field("awsRegion", doc.getEntity().getRegionName());
        StoragePolicy storagePolicy = storage.getStoragePolicy();
        if (storagePolicy != null) {
            jsonBuilder.field("storagePolicyBackupDuration", storagePolicy.getBackupDuration()).field("storagePolicyLongTermStorageDuration", storagePolicy.getLongTermStorageDuration()).field("storagePolicyShortTermStorageDuration", storagePolicy.getShortTermStorageDuration()).field("storagePolicyVersioningEnabled", storagePolicy.getVersioningEnabled());
        }
        buildUserContent(doc.getOwner(), jsonBuilder);
        buildMetadata(doc.getMetadata(), jsonBuilder);
        buildPermissions(doc.getPermissions(), jsonBuilder);
        jsonBuilder.endObject();
        return jsonBuilder;
    } catch (IOException e) {
        throw new IllegalArgumentException("An error occurred while creating document: ", e);
    }
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) StoragePolicy(com.epam.pipeline.entity.datastorage.StoragePolicy) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 62 with AbstractDataStorage

use of com.epam.pipeline.entity.datastorage.AbstractDataStorage in project cloud-pipeline by epam.

the class DataStorageLoader method fetchEntity.

@Override
protected DataStorageDoc fetchEntity(final Long id) {
    AbstractDataStorage dataStorage = getApiClient().loadDataStorage(id);
    List<AwsRegion> awsRegions = getApiClient().loadAllRegions();
    DataStorageDoc.DataStorageDocBuilder docBuilder = DataStorageDoc.builder().storage(dataStorage);
    if (dataStorage instanceof S3bucketDataStorage) {
        S3bucketDataStorage bucket = (S3bucketDataStorage) dataStorage;
        docBuilder.regionName(Optional.ofNullable(bucket.getRegionId()).flatMap(regionId -> awsRegions.stream().filter(region -> region.getId().equals(bucket.getRegionId())).findFirst().map(AwsRegion::getAwsRegionName)).orElse(StringUtils.EMPTY));
    }
    return docBuilder.build();
}
Also used : AbstractCloudPipelineEntityLoader(com.epam.pipeline.elasticsearchagent.service.impl.converter.AbstractCloudPipelineEntityLoader) List(java.util.List) DataStorageDoc(com.epam.pipeline.elasticsearchagent.model.DataStorageDoc) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.S3bucketDataStorage) CloudPipelineAPIClient(com.epam.pipeline.elasticsearchagent.service.impl.CloudPipelineAPIClient) AclClass(com.epam.pipeline.entity.security.acl.AclClass) Optional(java.util.Optional) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) AwsRegion(com.epam.pipeline.entity.region.AwsRegion) StringUtils(org.apache.commons.lang3.StringUtils) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) AwsRegion(com.epam.pipeline.entity.region.AwsRegion) DataStorageDoc(com.epam.pipeline.elasticsearchagent.model.DataStorageDoc) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.S3bucketDataStorage)

Aggregations

AbstractDataStorage (com.epam.pipeline.entity.datastorage.AbstractDataStorage)62 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)22 Test (org.junit.Test)22 Transactional (org.springframework.transaction.annotation.Transactional)18 Folder (com.epam.pipeline.entity.pipeline.Folder)13 DataStorageVO (com.epam.pipeline.controller.vo.DataStorageVO)11 ArrayList (java.util.ArrayList)7 List (java.util.List)6 EntityVO (com.epam.pipeline.controller.vo.EntityVO)5 StoragePolicy (com.epam.pipeline.entity.datastorage.StoragePolicy)5 Service (org.springframework.stereotype.Service)5 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)4 UpdateDataStorageItemVO (com.epam.pipeline.controller.vo.data.storage.UpdateDataStorageItemVO)3 DataStorageDownloadFileUrl (com.epam.pipeline.entity.datastorage.DataStorageDownloadFileUrl)3 DataStorageException (com.epam.pipeline.entity.datastorage.DataStorageException)3 DataStorageFile (com.epam.pipeline.entity.datastorage.DataStorageFile)3 DataStorageLink (com.epam.pipeline.entity.pipeline.run.parameter.DataStorageLink)3 ObjectCreatorUtils.constructDataStorageVO (com.epam.pipeline.manager.ObjectCreatorUtils.constructDataStorageVO)3 IOException (java.io.IOException)3 MessageConstants (com.epam.pipeline.common.MessageConstants)2