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);
}
}
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();
}
Aggregations