Search in sources :

Example 6 with FolderWithMetadata

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

the class FolderManagerGetProjectTest method getProjectShouldFailIfProjectNotFound.

@Test
public void getProjectShouldFailIfProjectNotFound() {
    Mockito.when(entityManager.load(Matchers.any(AclClass.class), Matchers.any(Long.class))).thenReturn(folder3);
    folder2 = initFolderWithMetadata(folder2, 2L, "folder2", folder1.getId(), data);
    FolderWithMetadata project = folderManager.getProject(folder3.getId(), AclClass.FOLDER);
    assertNull(project);
}
Also used : AclClass(com.epam.pipeline.entity.security.acl.AclClass) FolderWithMetadata(com.epam.pipeline.entity.metadata.FolderWithMetadata) FolderManagerTest.initFolderWithMetadata(com.epam.pipeline.manager.pipeline.FolderManagerTest.initFolderWithMetadata) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test)

Example 7 with FolderWithMetadata

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

the class FolderManagerTest method testGetProjectFolderFromProjectTree.

@Test
public void testGetProjectFolderFromProjectTree() {
    Map<String, PipeConfValue> data = new HashMap<>();
    data.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
    Map<String, PipeConfValue> dataWithIndicator = new HashMap<>();
    dataWithIndicator.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, PROJECT_INDICATOR_VALUE));
    FolderWithMetadata folder = initFolderWithMetadata(new FolderWithMetadata(), 1L, "folder", null, data);
    FolderWithMetadata folder1 = initFolderWithMetadata(new FolderWithMetadata(), 2L, "folder1", folder.getId(), dataWithIndicator);
    FolderWithMetadata folder2 = initFolderWithMetadata(new FolderWithMetadata(), 3L, "folder2", folder1.getId(), data);
    Map<Long, FolderWithMetadata> folders = new HashMap<>();
    folders.put(folder.getId(), folder);
    folders.put(folder1.getId(), folder1);
    folders.put(folder2.getId(), folder2);
    Set<Pair<String, String>> indicators = new HashSet<>();
    indicators.add(new ImmutablePair<>(DATA_KEY_1, PROJECT_INDICATOR_VALUE));
    // case: single indicator
    Folder actualFolder = folderManager.getProjectFolder(folders, folder2.getId(), indicators);
    assertEquals(folder1.getId(), actualFolder.getId());
    assertEquals(folder1.getName(), actualFolder.getName());
    assertEquals(folder1.getParentId(), actualFolder.getParentId());
    assertEquals(folder1.getOwner(), actualFolder.getOwner());
    // case: several indicators
    indicators.add(new ImmutablePair<>(PROJECT_INDICATOR_VALUE, DATA_KEY_1));
    dataWithIndicator = new HashMap<>();
    dataWithIndicator.put(PROJECT_INDICATOR_VALUE, new PipeConfValue(DATA_TYPE_1, DATA_KEY_1));
    folder2.setData(dataWithIndicator);
    folders.put(folder2.getId(), folder2);
    actualFolder = folderManager.getProjectFolder(folders, folder2.getId(), indicators);
    assertEquals(folder2.getId(), actualFolder.getId());
    assertEquals(folder2.getName(), actualFolder.getName());
    assertEquals(folder2.getParentId(), actualFolder.getParentId());
    assertEquals(folder2.getOwner(), actualFolder.getOwner());
    // case: no matches (null parent)
    folder1.setData(data);
    folder2.setData(data);
    folders.put(folder1.getId(), folder1);
    folders.put(folder2.getId(), folder2);
    actualFolder = folderManager.getProjectFolder(folders, folder2.getId(), indicators);
    assertNull(actualFolder);
    // case: no matches (no null parent)
    folders.remove(folder.getId());
    actualFolder = folderManager.getProjectFolder(folders, folder2.getId(), indicators);
    assertNull(actualFolder);
}
Also used : HashMap(java.util.HashMap) PasswordGenerator.generateRandomString(com.epam.pipeline.utils.PasswordGenerator.generateRandomString) Folder(com.epam.pipeline.entity.pipeline.Folder) FolderWithMetadata(com.epam.pipeline.entity.metadata.FolderWithMetadata) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) HashSet(java.util.HashSet) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test)

Example 8 with FolderWithMetadata

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

the class FolderManager method loadAllProjects.

public Folder loadAllProjects() {
    Folder root = new Folder();
    Set<Pair<String, String>> indicator = parseProjectIndicator();
    Map<String, PipeConfValue> projectAttributes = indicator.stream().collect(Collectors.toMap(Pair::getLeft, pair -> new PipeConfValue(null, pair.getRight())));
    if (MapUtils.isEmpty(projectAttributes)) {
        return root;
    }
    List<Folder> projects = folderDao.loadAllProjects(projectAttributes).stream().filter(folder -> {
        if (folder instanceof FolderWithMetadata) {
            FolderWithMetadata folderWithMetadata = (FolderWithMetadata) folder;
            Map<String, PipeConfValue> attributes = folderWithMetadata.getData();
            return containsProjectIndicator(indicator, attributes);
        }
        return false;
    }).collect(Collectors.toList());
    root.setChildFolders(projects);
    return root;
}
Also used : MetadataEntry(com.epam.pipeline.entity.metadata.MetadataEntry) Arrays(java.util.Arrays) MessageConstants(com.epam.pipeline.common.MessageConstants) AbstractHierarchicalEntity(com.epam.pipeline.entity.AbstractHierarchicalEntity) LoggerFactory(org.slf4j.LoggerFactory) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) Autowired(org.springframework.beans.factory.annotation.Autowired) MetadataEntryMapper(com.epam.pipeline.mapper.MetadataEntryMapper) Function(java.util.function.Function) ArrayList(java.util.ArrayList) MetadataManager(com.epam.pipeline.manager.metadata.MetadataManager) Value(org.springframework.beans.factory.annotation.Value) Folder(com.epam.pipeline.entity.pipeline.Folder) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) MessageHelper(com.epam.pipeline.common.MessageHelper) Pair(org.apache.commons.lang3.tuple.Pair) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) Map(java.util.Map) FolderWithMetadata(com.epam.pipeline.entity.metadata.FolderWithMetadata) GrantPermissionManager(com.epam.pipeline.manager.security.GrantPermissionManager) AbstractRunConfigurationMapper(com.epam.pipeline.mapper.AbstractRunConfigurationMapper) FolderDao(com.epam.pipeline.dao.pipeline.FolderDao) EntityManager(com.epam.pipeline.manager.EntityManager) MapUtils(org.apache.commons.collections4.MapUtils) BaseEntity(com.epam.pipeline.entity.BaseEntity) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) Logger(org.slf4j.Logger) Set(java.util.Set) AbstractDataStorageMapper(com.epam.pipeline.mapper.AbstractDataStorageMapper) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) PasswordGenerator.generateRandomString(com.epam.pipeline.utils.PasswordGenerator.generateRandomString) Collectors(java.util.stream.Collectors) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) RunConfiguration(com.epam.pipeline.entity.configuration.RunConfiguration) List(java.util.List) MetadataEntityManager(com.epam.pipeline.manager.metadata.MetadataEntityManager) AclClass(com.epam.pipeline.entity.security.acl.AclClass) RunConfigurationManager(com.epam.pipeline.manager.configuration.RunConfigurationManager) Collections(java.util.Collections) DataStorageManager(com.epam.pipeline.manager.datastorage.DataStorageManager) EntityVO(com.epam.pipeline.controller.vo.EntityVO) Transactional(org.springframework.transaction.annotation.Transactional) StringUtils(org.springframework.util.StringUtils) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) PasswordGenerator.generateRandomString(com.epam.pipeline.utils.PasswordGenerator.generateRandomString) Folder(com.epam.pipeline.entity.pipeline.Folder) Map(java.util.Map) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) FolderWithMetadata(com.epam.pipeline.entity.metadata.FolderWithMetadata)

Example 9 with FolderWithMetadata

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

the class FolderManager method getProject.

public FolderWithMetadata getProject(Long entityId, AclClass entityClass) {
    validateAclClass(entityClass);
    Set<Pair<String, String>> projectIndicators = parseProjectIndicator();
    if (CollectionUtils.isEmpty(projectIndicators)) {
        throw new IllegalArgumentException("Can not detect project: project indicator not found.");
    }
    AbstractSecuredEntity entity = entityManager.load(entityClass, entityId);
    AbstractSecuredEntity folderToStartSearch = entity.getAclClass().equals(AclClass.FOLDER) ? entity : entity.getParent();
    if (folderToStartSearch == null) {
        LOGGER.debug("Current entity doesn't have a Folder parent");
        return null;
    }
    if (!folderToStartSearch.getAclClass().equals(AclClass.FOLDER)) {
        throw new IllegalArgumentException("Parent must be a FOLDER.");
    }
    Map<Long, FolderWithMetadata> folders = convertListToMap(folderDao.loadParentFolders(folderToStartSearch.getId()));
    return getProjectFolder(folders, folderToStartSearch.getId(), projectIndicators);
}
Also used : AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) FolderWithMetadata(com.epam.pipeline.entity.metadata.FolderWithMetadata)

Example 10 with FolderWithMetadata

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

the class FolderManager method getProjectFolder.

FolderWithMetadata getProjectFolder(Map<Long, FolderWithMetadata> folders, Long id, Set<Pair<String, String>> projectIndicators) {
    FolderWithMetadata folder = folders.get(id);
    if (folder == null) {
        return null;
    }
    Map<String, PipeConfValue> metadata = folder.getData();
    if (MapUtils.isEmpty(metadata)) {
        LOGGER.debug("Can not detect project folder: metadata not found.");
        return continueSearch(folders, projectIndicators, folder);
    }
    if (containsProjectIndicator(projectIndicators, metadata)) {
        return folder;
    }
    return continueSearch(folders, projectIndicators, folder);
}
Also used : PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) PasswordGenerator.generateRandomString(com.epam.pipeline.utils.PasswordGenerator.generateRandomString) FolderWithMetadata(com.epam.pipeline.entity.metadata.FolderWithMetadata)

Aggregations

FolderWithMetadata (com.epam.pipeline.entity.metadata.FolderWithMetadata)12 PipeConfValue (com.epam.pipeline.entity.metadata.PipeConfValue)5 AclClass (com.epam.pipeline.entity.security.acl.AclClass)5 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)4 Folder (com.epam.pipeline.entity.pipeline.Folder)4 Test (org.junit.Test)4 BaseEntity (com.epam.pipeline.entity.BaseEntity)3 MetadataEntityManager (com.epam.pipeline.manager.metadata.MetadataEntityManager)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 MessageConstants (com.epam.pipeline.common.MessageConstants)2 MessageHelper (com.epam.pipeline.common.MessageHelper)2 EntityVO (com.epam.pipeline.controller.vo.EntityVO)2 AbstractSecuredEntity (com.epam.pipeline.entity.AbstractSecuredEntity)2 PipelineConfiguration (com.epam.pipeline.entity.configuration.PipelineConfiguration)2 MetadataEntry (com.epam.pipeline.entity.metadata.MetadataEntry)2 PipelineStart (com.epam.pipeline.entity.pipeline.run.PipelineStart)2 FolderManagerTest.initFolderWithMetadata (com.epam.pipeline.manager.pipeline.FolderManagerTest.initFolderWithMetadata)2