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);
}
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);
}
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;
}
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);
}
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);
}
Aggregations