Search in sources :

Example 1 with Folder

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

the class MetadataManager method loadEntitiesMetadataFromFolder.

public List<MetadataEntryWithIssuesCount> loadEntitiesMetadataFromFolder(Long parentFolderId) {
    List<EntityVO> entities = new ArrayList<>();
    Folder folder;
    if (parentFolderId == null) {
        folder = folderManager.loadTree();
    } else {
        folder = folderManager.load(parentFolderId);
        entities.add(new EntityVO(parentFolderId, AclClass.FOLDER));
    }
    if (!CollectionUtils.isEmpty(folder.getPipelines())) {
        folder.getPipelines().forEach(pipeline -> entities.add(new EntityVO(pipeline.getId(), AclClass.PIPELINE)));
    }
    if (!CollectionUtils.isEmpty(folder.getConfigurations())) {
        folder.getConfigurations().forEach(configuration -> entities.add(new EntityVO(configuration.getId(), AclClass.CONFIGURATION)));
    }
    if (!CollectionUtils.isEmpty(folder.getStorages())) {
        folder.getStorages().forEach(storage -> entities.add(new EntityVO(storage.getId(), AclClass.DATA_STORAGE)));
    }
    if (!CollectionUtils.isEmpty(folder.getChildren())) {
        folder.getChildren().forEach(childFolder -> entities.add(new EntityVO(childFolder.getId(), AclClass.FOLDER)));
    }
    if (CollectionUtils.isEmpty(entities)) {
        return Collections.emptyList();
    }
    return metadataDao.loadMetadataItemsWithIssues(entities);
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) ArrayList(java.util.ArrayList) Folder(com.epam.pipeline.entity.pipeline.Folder)

Example 2 with Folder

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

the class FolderCrudManager method delete.

/**
 * Deletes a folder specified by ID. Folder may be deleted only if it doesn't have
 * any children from specified list: pipeline, folder, storage, configuration.
 * If some {@link com.epam.pipeline.entity.metadata.MetadataEntity} instances exist in Folder,
 * they will deleted before actual deletion of the folder
 * @param id of {@link Folder} to delete
 * @return deleted {@link Folder} instance
 */
@Transactional(propagation = Propagation.REQUIRED)
public Folder delete(final Long id) {
    Folder folder = load(id);
    checkChildrenNotPresent(folder.getChildFolders(), folder.getName(), "folders");
    checkChildrenNotPresent(folder.getPipelines(), folder.getName(), "pipelines");
    checkChildrenNotPresent(folder.getStorages(), folder.getName(), "storages");
    checkChildrenNotPresent(folder.getConfigurations(), folder.getName(), "configurations");
    if (MapUtils.isNotEmpty(folder.getMetadata())) {
        LOGGER.debug("Clearing metadata before folder deletion");
        metadataEntityManager.deleteMetadataFromFolder(id);
    }
    folderDao.deleteFolder(id);
    return folder;
}
Also used : Folder(com.epam.pipeline.entity.pipeline.Folder) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Folder

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

the class FolderCrudManager method update.

/**
 * Updates a {@link Folder} specified by id. Method checks name uniqueness and
 * recursive dependencies.
 * @param folder to update
 * @return updated {@link Folder}
 */
@Transactional(propagation = Propagation.REQUIRED)
public Folder update(final Folder folder) {
    Folder dbFolder = load(folder.getId());
    if (StringUtils.hasText(folder.getName())) {
        dbFolder.setName(validateName(folder.getName()));
    }
    Long parentId = folder.getParentId();
    Assert.isNull(loadByNameAndParentId(folder.getName(), parentId), messageHelper.getMessage(MessageConstants.ERROR_FOLDER_NAME_EXISTS, folder.getName(), parentId));
    if (parentId != null) {
        Assert.isTrue(!dbFolder.getId().equals(parentId), messageHelper.getMessage(MessageConstants.ERROR_FOLDER_RECURSIVE_DEPENDENCY, folder.getId(), parentId));
        boolean recursiveDependency = checkChildrenFolders(folder, parentId);
        Assert.isTrue(!recursiveDependency, messageHelper.getMessage(MessageConstants.ERROR_FOLDER_RECURSIVE_DEPENDENCY, folder.getId(), parentId));
        dbFolder.setParent(load(parentId));
    }
    dbFolder.setParentId(folder.getParentId());
    folderDao.updateFolder(dbFolder);
    return dbFolder;
}
Also used : Folder(com.epam.pipeline.entity.pipeline.Folder) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Folder

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

the class FolderManager method lockFolder.

/**
 * Prohibits any changes to a folder
 * Sets NO_WRITE & NO_EXECUTE permissions for an entity and all it's children
 * @param id specifies entity
 * @return
 */
@Transactional(propagation = Propagation.REQUIRED)
public Folder lockFolder(Long id) {
    Folder folder = crudManager.load(id);
    updateTreeLocks(folder, true);
    permissionManager.lockEntity(folder);
    return crudManager.load(id);
}
Also used : Folder(com.epam.pipeline.entity.pipeline.Folder) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Folder

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

the class FolderManager method createCloneFolder.

private Folder createCloneFolder(Folder folderToClone, Long parentId) {
    Long sourceFolderId = folderToClone.getId();
    folderToClone.setParentId(parentId);
    Folder clonedFolder = crudManager.create(folderToClone);
    if (!CollectionUtils.isEmpty(folderToClone.getStorages())) {
        folderToClone.getStorages().forEach(storage -> {
            storage.setParentFolderId(clonedFolder.getId());
            dataStorageManager.create(dataStorageMapper.toDataStorageVO(storage), true, true, false);
        });
    }
    if (!CollectionUtils.isEmpty(folderToClone.getConfigurations())) {
        folderToClone.getConfigurations().forEach(runConfiguration -> {
            runConfiguration.setParent(clonedFolder);
            configurationManager.create(runConfigurationMapper.toRunConfigurationVO(runConfiguration));
        });
    }
    MetadataEntry metadataEntry = metadataManager.loadMetadataItem(sourceFolderId, AclClass.FOLDER);
    if (metadataEntry != null && !MapUtils.isEmpty(metadataEntry.getData())) {
        metadataEntry.setEntity(new EntityVO(clonedFolder.getId(), AclClass.FOLDER));
        metadataManager.updateMetadataItem(metadataEntryMapper.toMetadataVO(metadataEntry));
    }
    metadataEntityManager.insertCopiesOfExistentMetadataEntities(sourceFolderId, clonedFolder.getId());
    if (!CollectionUtils.isEmpty(folderToClone.getChildFolders())) {
        folderToClone.getChildFolders().forEach(child -> createCloneFolder(child, clonedFolder.getId()));
    }
    return clonedFolder;
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) MetadataEntry(com.epam.pipeline.entity.metadata.MetadataEntry) Folder(com.epam.pipeline.entity.pipeline.Folder)

Aggregations

Folder (com.epam.pipeline.entity.pipeline.Folder)102 Transactional (org.springframework.transaction.annotation.Transactional)53 Test (org.junit.Test)52 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)48 EntityVO (com.epam.pipeline.controller.vo.EntityVO)14 AbstractDataStorage (com.epam.pipeline.entity.datastorage.AbstractDataStorage)14 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)14 MetadataClass (com.epam.pipeline.entity.metadata.MetadataClass)13 RunConfiguration (com.epam.pipeline.entity.configuration.RunConfiguration)11 MetadataEntity (com.epam.pipeline.entity.metadata.MetadataEntity)11 PipeConfValue (com.epam.pipeline.entity.metadata.PipeConfValue)10 AclClass (com.epam.pipeline.entity.security.acl.AclClass)10 Autowired (org.springframework.beans.factory.annotation.Autowired)8 Propagation (org.springframework.transaction.annotation.Propagation)8 MetadataEntityVO (com.epam.pipeline.controller.vo.metadata.MetadataEntityVO)7 PasswordGenerator.generateRandomString (com.epam.pipeline.utils.PasswordGenerator.generateRandomString)6 FolderWithMetadata (com.epam.pipeline.entity.metadata.FolderWithMetadata)5 DataStorageVO (com.epam.pipeline.controller.vo.DataStorageVO)4 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)4 Collectors (java.util.stream.Collectors)4