Search in sources :

Example 36 with AbstractDataStorage

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);
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage)

Example 37 with AbstractDataStorage

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);
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage)

Example 38 with AbstractDataStorage

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;
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage)

Example 39 with AbstractDataStorage

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;
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) Folder(com.epam.pipeline.entity.pipeline.Folder) DataStorageFolder(com.epam.pipeline.entity.datastorage.DataStorageFolder)

Example 40 with AbstractDataStorage

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;
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage)

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