Search in sources :

Example 1 with ProjectGraph

use of com.enonic.xp.project.ProjectGraph in project xp by enonic.

the class ProjectServiceImpl method graph.

@Override
public ProjectGraph graph(final ProjectName projectName) {
    final ProjectGraph.Builder graph = ProjectGraph.create();
    final Project targetProject;
    try {
        targetProject = this.get(projectName);
        if (targetProject == null) {
            throw new ProjectNotFoundException(projectName);
        }
    } catch (ProjectAccessException e) {
        throw new ProjectNotFoundException(e.getProjectName());
    }
    final Projects projects = adminContext().callWith(this::doList);
    Project project = targetProject;
    final List<Project> parents = new ArrayList<>();
    while (project.getParent() != null) {
        project = getProject(projects, project.getParent());
        parents.add(project);
    }
    Collections.reverse(parents);
    parents.add(targetProject);
    parents.forEach(p -> graph.add(ProjectGraphEntry.create().name(p.getName()).parent(p.getParent()).build()));
    final Queue<Project> children = new ArrayDeque<>();
    children.add(targetProject);
    while (!children.isEmpty()) {
        final Project current = children.poll();
        projects.stream().filter(p -> current.getName().equals(p.getParent())).forEach(p -> {
            children.offer(p);
            graph.add(ProjectGraphEntry.create().name(p.getName()).parent(p.getParent()).build());
        });
    }
    return graph.build();
}
Also used : ArchiveInitializer(com.enonic.xp.core.impl.project.init.ArchiveInitializer) DeleteRepositoryParams(com.enonic.xp.repository.DeleteRepositoryParams) RepositoryService(com.enonic.xp.repository.RepositoryService) LoggerFactory(org.slf4j.LoggerFactory) AttachmentSerializer(com.enonic.xp.attachment.AttachmentSerializer) ImageHelper(com.enonic.xp.image.ImageHelper) IndexService(com.enonic.xp.index.IndexService) BigDecimal(java.math.BigDecimal) RepositoryId(com.enonic.xp.repository.RepositoryId) ContextAccessor(com.enonic.xp.context.ContextAccessor) NodeService(com.enonic.xp.node.NodeService) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) ImageIO(javax.imageio.ImageIO) ContextBuilder(com.enonic.xp.context.ContextBuilder) EnumSet(java.util.EnumSet) SecurityService(com.enonic.xp.security.SecurityService) RoundingMode(java.math.RoundingMode) BinaryReference(com.enonic.xp.util.BinaryReference) ProjectService(com.enonic.xp.project.ProjectService) Projects(com.enonic.xp.project.Projects) BufferedImage(java.awt.image.BufferedImage) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) Project(com.enonic.xp.project.Project) Collectors(java.util.stream.Collectors) CreateProjectParams(com.enonic.xp.project.CreateProjectParams) UpdateRepositoryParams(com.enonic.xp.repository.UpdateRepositoryParams) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) ProjectNotFoundException(com.enonic.xp.project.ProjectNotFoundException) Optional(java.util.Optional) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) Queue(java.util.Queue) Repository(com.enonic.xp.repository.Repository) EventPublisher(com.enonic.xp.event.EventPublisher) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Callable(java.util.concurrent.Callable) Attachment(com.enonic.xp.attachment.Attachment) ProjectConstants(com.enonic.xp.project.ProjectConstants) ProjectGraphEntry(com.enonic.xp.project.ProjectGraphEntry) ArrayList(java.util.ArrayList) IssueInitializer(com.enonic.xp.core.impl.project.init.IssueInitializer) ProjectRole(com.enonic.xp.project.ProjectRole) CreateAttachments(com.enonic.xp.attachment.CreateAttachments) ProjectName(com.enonic.xp.project.ProjectName) ContentInitializer(com.enonic.xp.core.impl.project.init.ContentInitializer) ModifyProjectIconParams(com.enonic.xp.project.ModifyProjectIconParams) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) Logger(org.slf4j.Logger) ProjectGraph(com.enonic.xp.project.ProjectGraph) ProjectPermissions(com.enonic.xp.project.ProjectPermissions) PropertySet(com.enonic.xp.data.PropertySet) IOException(java.io.IOException) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) ModifyProjectParams(com.enonic.xp.project.ModifyProjectParams) InputStream(java.io.InputStream) Project(com.enonic.xp.project.Project) ProjectNotFoundException(com.enonic.xp.project.ProjectNotFoundException) ArrayList(java.util.ArrayList) Projects(com.enonic.xp.project.Projects) ProjectGraph(com.enonic.xp.project.ProjectGraph) ArrayDeque(java.util.ArrayDeque)

Example 2 with ProjectGraph

use of com.enonic.xp.project.ProjectGraph in project xp by enonic.

the class ProjectServiceImplTest method graph.

@Test
void graph() {
    final Project project1 = adminContext().callWith(() -> doCreateProject(ProjectName.from("project1"), null, true, null));
    final Project project2 = adminContext().callWith(() -> doCreateProject(ProjectName.from("project2"), null, true, project1.getName()));
    final Project project3 = adminContext().callWith(() -> doCreateProject(ProjectName.from("project3"), null, true, project2.getName()));
    final Project project4 = adminContext().callWith(() -> doCreateProject(ProjectName.from("project4"), null, true, project2.getName()));
    final Project project5 = adminContext().callWith(() -> doCreateProject(ProjectName.from("project5"), null, true, project4.getName()));
    final ProjectGraph graph1 = adminContext().callWith(() -> projectService.graph(project1.getName()));
    assertEquals(5, graph1.getSize());
    assertThat(graph1.getList()).extracting("name", "parent").containsExactly(tuple(project1.getName(), null), tuple(project2.getName(), project1.getName()), tuple(project4.getName(), project2.getName()), tuple(project3.getName(), project2.getName()), tuple(project5.getName(), project4.getName()));
    final ProjectGraph graph2 = adminContext().callWith(() -> projectService.graph(project4.getName()));
    assertEquals(4, graph2.getSize());
    assertThat(graph2.getList()).extracting("name", "parent").containsExactly(tuple(project1.getName(), null), tuple(project2.getName(), project1.getName()), tuple(project4.getName(), project2.getName()), tuple(project5.getName(), project4.getName()));
}
Also used : Project(com.enonic.xp.project.Project) ProjectGraph(com.enonic.xp.project.ProjectGraph) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Aggregations

Project (com.enonic.xp.project.Project)2 ProjectGraph (com.enonic.xp.project.ProjectGraph)2 Attachment (com.enonic.xp.attachment.Attachment)1 AttachmentSerializer (com.enonic.xp.attachment.AttachmentSerializer)1 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)1 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)1 Context (com.enonic.xp.context.Context)1 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 ArchiveInitializer (com.enonic.xp.core.impl.project.init.ArchiveInitializer)1 ContentInitializer (com.enonic.xp.core.impl.project.init.ContentInitializer)1 IssueInitializer (com.enonic.xp.core.impl.project.init.IssueInitializer)1 PropertySet (com.enonic.xp.data.PropertySet)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 EventPublisher (com.enonic.xp.event.EventPublisher)1 ImageHelper (com.enonic.xp.image.ImageHelper)1 IndexService (com.enonic.xp.index.IndexService)1 BinaryAttachment (com.enonic.xp.node.BinaryAttachment)1 NodeService (com.enonic.xp.node.NodeService)1 CreateProjectParams (com.enonic.xp.project.CreateProjectParams)1