use of com.epam.pipeline.entity.datastorage.AbstractDataStorage in project cloud-pipeline by epam.
the class DataStorageManager method createDataStorageFile.
public DataStorageFile createDataStorageFile(final Long dataStorageId, String folder, final String name, byte[] contents) throws DataStorageException {
AbstractDataStorage dataStorage = load(dataStorageId);
String path = getRelativePath(folder, name, dataStorage);
return storageProviderManager.createFile(dataStorage, path, contents);
}
use of com.epam.pipeline.entity.datastorage.AbstractDataStorage in project cloud-pipeline by epam.
the class DataStorageManager method getDataStorageItems.
public DataStorageListing getDataStorageItems(final Long dataStorageId, final String path, Boolean showVersion, Integer pageSize, String marker) {
AbstractDataStorage dataStorage = load(dataStorageId);
if (showVersion) {
Assert.isTrue(dataStorage.isVersioningEnabled(), messageHelper.getMessage(MessageConstants.ERROR_DATASTORAGE_VERSIONING_REQUIRED, dataStorage.getName()));
}
Assert.isTrue(pageSize == null || pageSize > 0, messageHelper.getMessage(MessageConstants.ERROR_PAGE_SIZE));
return storageProviderManager.getItems(dataStorage, path, showVersion, pageSize, marker);
}
use of com.epam.pipeline.entity.datastorage.AbstractDataStorage in project cloud-pipeline by epam.
the class DataStorageManager method updateDataStorageObject.
private AbstractDataStorage updateDataStorageObject(AbstractDataStorage dataStorage, DataStorageVO dataStorageVO) {
if (!StringUtils.isEmpty(dataStorageVO.getName())) {
String name = dataStorageVO.getName().trim();
dataStorageVO.setName(name);
if (!dataStorage.getName().equals(name)) {
AbstractDataStorage loadedStorage = dataStorageDao.loadDataStorageByNameOrPath(name, name);
// lets check if path is equal to name and allow it
if (loadedStorage != null && !loadedStorage.getPath().equals(name)) {
throw new IllegalArgumentException(messageHelper.getMessage(MessageConstants.ERROR_DATASTORAGE_ALREADY_EXIST, name, name));
}
}
dataStorage.setName(dataStorageVO.getName());
}
dataStorage.setParentFolderId(dataStorageVO.getParentFolderId());
if (dataStorageVO.getParentFolderId() != null) {
dataStorage.setParent(folderManager.load(dataStorageVO.getParentFolderId()));
}
String newDescription = dataStorageVO.getDescription();
if (newDescription != null) {
dataStorage.setDescription(newDescription);
}
dataStorage.setMountPoint(dataStorageVO.getMountPoint());
dataStorage.setMountOptions(dataStorageVO.getMountOptions());
if (StringUtils.isBlank(dataStorage.getMountOptions())) {
dataStorage.setMountOptions(storageProviderManager.getStorageProvider(dataStorage).getDefaultMountOptions());
}
return dataStorage;
}
use of com.epam.pipeline.entity.datastorage.AbstractDataStorage in project cloud-pipeline by epam.
the class DataStorageManager method loadByNameOrId.
public AbstractDataStorage loadByNameOrId(final String identifier) {
AbstractDataStorage dataStorage = null;
if (NumberUtils.isDigits(identifier)) {
dataStorage = dataStorageDao.loadDataStorage(Long.parseLong(identifier));
}
if (dataStorage == null) {
String pathWithName = identifier;
if (pathWithName.startsWith("/")) {
pathWithName = pathWithName.substring(1);
}
if (pathWithName.endsWith("/")) {
pathWithName = pathWithName.substring(0, pathWithName.length() - 1);
}
String[] pathParts = pathWithName.split("/");
String dataStorageName = pathParts[pathParts.length - 1];
Long parentFolderId = null;
if (pathParts.length > 1) {
Folder parentFolder = folderManager.loadByNameOrId(String.join("/", Arrays.asList(pathParts).subList(0, pathParts.length - 1)));
if (parentFolder != null) {
parentFolderId = parentFolder.getId();
}
}
if (parentFolderId != null) {
dataStorage = dataStorageDao.loadDataStorageByNameAndParentId(dataStorageName, parentFolderId);
} else {
dataStorage = dataStorageDao.loadDataStorageByNameOrPath(dataStorageName, dataStorageName);
}
}
Assert.notNull(dataStorage, messageHelper.getMessage(MessageConstants.ERROR_DATASTORAGE_NOT_FOUND, identifier));
dataStorage.setHasMetadata(metadataManager.hasMetadata(new EntityVO(dataStorage.getId(), AclClass.DATA_STORAGE)));
return dataStorage;
}
use of com.epam.pipeline.entity.datastorage.AbstractDataStorage in project cloud-pipeline by epam.
the class DataStorageManager method load.
@Override
public AbstractDataStorage load(final Long id) {
AbstractDataStorage dbDataStorage = dataStorageDao.loadDataStorage(id);
Assert.notNull(dbDataStorage, messageHelper.getMessage(MessageConstants.ERROR_DATASTORAGE_NOT_FOUND, id));
dbDataStorage.setHasMetadata(this.metadataManager.hasMetadata(new EntityVO(id, AclClass.DATA_STORAGE)));
return dbDataStorage;
}
Aggregations