Search in sources :

Example 51 with Folder

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

the class FolderEventService method updateEventsWithChildrenAndIssues.

@Override
public void updateEventsWithChildrenAndIssues(Long id) {
    String folderType = EventObjectType.FOLDER.name().toLowerCase();
    eventManager.addUpdateEvent(folderType, id);
    eventManager.addUpdateEventsForIssues(id, AclClass.FOLDER);
    Folder folder = folderManager.load(id);
    ListUtils.emptyIfNull(folder.getChildFolders()).forEach(childFolder -> updateEventsWithChildrenAndIssues(childFolder.getId()));
    ListUtils.emptyIfNull(folder.getPipelines()).forEach(pipeline -> pipelineEventService.updateEventsWithChildrenAndIssues(pipeline.getId()));
    ListUtils.emptyIfNull(folder.getStorages()).forEach(storage -> dataStorageEventService.updateEventsWithChildrenAndIssues(storage.getId()));
    ListUtils.emptyIfNull(folder.getConfigurations()).forEach(runConfiguration -> configurationEventService.updateEventsWithChildrenAndIssues(runConfiguration.getId()));
    folder.getMetadata().keySet().forEach(metadataClass -> ListUtils.emptyIfNull(metadataEntityManager.loadMetadataEntityByClassNameAndFolderId(id, metadataClass)).forEach(metadataEntity -> metadataEntityEventService.updateEventsWithChildrenAndIssues(metadataEntity.getId())));
}
Also used : Folder(com.epam.pipeline.entity.pipeline.Folder) Service(org.springframework.stereotype.Service) MetadataEntityManager(com.epam.pipeline.manager.metadata.MetadataEntityManager) ListUtils(org.apache.commons.collections4.ListUtils) RequiredArgsConstructor(lombok.RequiredArgsConstructor) AclClass(com.epam.pipeline.entity.security.acl.AclClass) FolderCrudManager(com.epam.pipeline.manager.pipeline.FolderCrudManager) Folder(com.epam.pipeline.entity.pipeline.Folder)

Example 52 with Folder

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

the class MetadataUploadManager method readFile.

private MetadataParsingResult readFile(Long parentId, MultipartFile file) {
    try {
        final Folder parent = folderManager.load(parentId);
        String delimiter = MetadataParsingUtils.getDelimiterFromFileExtension(file.getOriginalFilename());
        byte[] inputData = file.getBytes();
        MetadataHeader header = new MetadataEntityHeaderParser(delimiter).readHeader(ByteSource.wrap(inputData).openStream());
        validateTypes(header, parentId);
        MetadataClass metadataClass = getOrCreateClass(header.getClassName());
        return new MetadataEntityReader(delimiter, parent, metadataClass).readData(ByteSource.wrap(inputData).openStream(), header.getFields());
    } catch (IOException e) {
        throw new MetadataReadingException(e.getMessage(), e);
    }
}
Also used : MetadataEntityReader(com.epam.pipeline.manager.metadata.parser.MetadataEntityReader) MetadataClass(com.epam.pipeline.entity.metadata.MetadataClass) MetadataReadingException(com.epam.pipeline.exception.MetadataReadingException) MetadataHeader(com.epam.pipeline.manager.metadata.parser.MetadataHeader) IOException(java.io.IOException) Folder(com.epam.pipeline.entity.pipeline.Folder) MetadataEntityHeaderParser(com.epam.pipeline.manager.metadata.parser.MetadataEntityHeaderParser)

Example 53 with Folder

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

the class FolderCrudManager method loadByNameOrId.

/**
 * Tries to find a {@link Folder} entity by some pathOrIdentifier.
 * If identifier is a number, it is interpreted as ID and will be loaded from DB by primary key.
 * Otherwise pathOrIdentifier is interpreted as full path to folder like:
 *      /root/parent/folder-name
 * and method will try to resolve folder hierarchy from this path.
 * @param pathOrIdentifier specifies folder to look for
 * @return {@link Folder} entity if present
 * @throws IllegalArgumentException if {@link Folder} pathOrIdentifier not found
 */
@Override
public Folder loadByNameOrId(String pathOrIdentifier) {
    Folder folder = null;
    String path = pathOrIdentifier;
    try {
        folder = folderDao.loadFolder(Long.parseLong(path));
    } catch (NumberFormatException e) {
        LOGGER.trace(e.getMessage(), e);
    }
    if (folder == null) {
        Long parentId = null;
        if (path.startsWith("/")) {
            path = path.substring(1);
        }
        if (path.endsWith("/")) {
            path = path.substring(0, path.length() - 1);
        }
        String[] pathComponents = path.split("/");
        for (String name : pathComponents) {
            folder = loadByNameAndParentId(name, parentId);
            if (folder == null) {
                break;
            } else {
                parentId = folder.getId();
            }
        }
    }
    Assert.notNull(folder, messageHelper.getMessage(MessageConstants.ERROR_FOLDER_NOT_FOUND, path));
    folder.setHasMetadata(this.metadataManager.hasMetadata(new EntityVO(folder.getId(), AclClass.FOLDER)));
    return folder;
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) Folder(com.epam.pipeline.entity.pipeline.Folder)

Example 54 with Folder

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

the class FolderCrudManager method load.

/**
 * Loads {@link Folder} specified by id parameter
 * @param id to find
 * @return {@link Folder} entity if present
 * @throws IllegalArgumentException if {@link Folder} id not found
 */
@Override
public Folder load(Long id) {
    Folder folder = folderDao.loadFolder(id);
    Assert.notNull(folder, messageHelper.getMessage(MessageConstants.ERROR_FOLDER_NOT_FOUND, id));
    folder.setHasMetadata(metadataManager.hasMetadata(new EntityVO(id, AclClass.FOLDER)));
    return folder;
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) Folder(com.epam.pipeline.entity.pipeline.Folder)

Example 55 with Folder

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

the class FolderCrudManager method changeOwner.

/**
 * Assigns a specified user as a new owner of a folder
 * @param id of {@link Folder} entity
 * @param owner new owner of an enitity
 * @return updated {@link Folder}
 */
@Override
@Transactional(propagation = Propagation.REQUIRED)
public AbstractSecuredEntity changeOwner(Long id, String owner) {
    final Folder folder = load(id);
    folder.setOwner(owner);
    folderDao.updateFolder(folder);
    return folder;
}
Also used : Folder(com.epam.pipeline.entity.pipeline.Folder) Transactional(org.springframework.transaction.annotation.Transactional)

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