Search in sources :

Example 1 with Projects

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

the class ProjectsSyncTaskTest method order.

@Test
void order() {
    final Projects projects = Projects.create().addAll(Set.of(createProject("turkey-tr-tr", "turkey-tr"), createProject("enonic-common", null), createProject("corporate", "enonic-common"), createProject("corporate-no", "corporate"), createProject("countries", "enonic-common"), createProject("denmark", "countries"), createProject("without-actual-parent1", "unknown-parent1"), createProject("denmark-de", "denmark"), createProject("sweden", "countries"), createProject("sweden-sw", "sweden"), createProject("sweden-sw-sw", "sweden-sw"), createProject("root1", null), createProject("child1", "root1"), createProject("without-actual-parent2", "unknown-parent2"), createProject("turkey", "countries"), createProject("turkey-tr", "turkey"))).build();
    when(projectService.list()).thenReturn(projects);
    ProjectsSyncTask.create().projectService(projectService).syncContentService(syncContentService).build().run(TaskId.from("taskId"), mock(ProgressReporter.class, withSettings().stubOnly()));
    verify(syncContentService, times(14)).syncProject(paramsCaptor.capture());
    final List<ProjectName> syncProjects = paramsCaptor.getAllValues().stream().map(ProjectSyncParams::getTargetProject).collect(Collectors.toList());
    assertAll(() -> assertThat(syncProjects.indexOf(ProjectName.from("turkey-tr-tr"))).isGreaterThan(syncProjects.indexOf(ProjectName.from("turkey-tr"))), () -> assertThat(syncProjects.indexOf(ProjectName.from("turkey-tr"))).isGreaterThan(syncProjects.indexOf(ProjectName.from("turkey"))), () -> assertThat(syncProjects.indexOf(ProjectName.from("turkey"))).isGreaterThan(syncProjects.indexOf(ProjectName.from("countries"))), () -> assertThat(syncProjects.indexOf(ProjectName.from("corporate-no"))).isGreaterThan(syncProjects.indexOf(ProjectName.from("corporate"))), () -> assertThat(syncProjects.indexOf(ProjectName.from("denmark-de"))).isGreaterThan(syncProjects.indexOf(ProjectName.from("denmark"))), () -> assertThat(syncProjects.indexOf(ProjectName.from("denmark"))).isGreaterThan(syncProjects.indexOf(ProjectName.from("countries"))), () -> assertThat(syncProjects.indexOf(ProjectName.from("sweden-sw-sw"))).isGreaterThan(syncProjects.indexOf(ProjectName.from("sweden-sw"))), () -> assertThat(syncProjects.indexOf(ProjectName.from("sweden-sw"))).isGreaterThan(syncProjects.indexOf(ProjectName.from("sweden"))), () -> assertThat(syncProjects.indexOf(ProjectName.from("sweden"))).isGreaterThan(syncProjects.indexOf(ProjectName.from("countries"))), () -> assertThat(syncProjects.indexOf(ProjectName.from("child1"))).isGreaterThan(syncProjects.indexOf(ProjectName.from("root1"))), () -> assertThat(syncProjects.indexOf(ProjectName.from("without-actual-parent1"))).isGreaterThanOrEqualTo(12), () -> assertThat(syncProjects.indexOf(ProjectName.from("without-actual-parent2"))).isGreaterThanOrEqualTo(12), () -> assertThat(syncProjects).doesNotContain(ProjectName.from("enoic-common"), ProjectName.from("root1")));
}
Also used : ProjectName(com.enonic.xp.project.ProjectName) Projects(com.enonic.xp.project.Projects) ProgressReporter(com.enonic.xp.task.ProgressReporter) Test(org.junit.jupiter.api.Test)

Example 2 with Projects

use of com.enonic.xp.project.Projects 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 3 with Projects

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

the class ProjectServiceImpl method initialize.

public void initialize() {
    adminContext().runWith(() -> {
        final Projects projects = this.doList();
        projects.forEach(project -> doInitRootNodes(CreateProjectParams.create().name(project.getName()).displayName(project.getDisplayName()).description(project.getDescription()).build()));
        if (projects.stream().noneMatch(project -> project.getName().equals(ProjectConstants.DEFAULT_PROJECT.getName()))) {
            doInitRootNodes(CreateProjectParams.create().name(ProjectConstants.DEFAULT_PROJECT.getName()).displayName(ProjectConstants.DEFAULT_PROJECT.getDisplayName()).description(ProjectConstants.DEFAULT_PROJECT.getDescription()).build());
        }
    });
}
Also used : Projects(com.enonic.xp.project.Projects)

Example 4 with Projects

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

the class ProjectServiceImplTest method list_with_content_manager_permissions.

@Test
void list_with_content_manager_permissions() {
    doCreateProjectAsAdmin(ProjectName.from("test-project1"));
    contentManagerContext().runWith(() -> {
        final Projects projects = projectService.list();
        assertEquals(1, projects.getSize());
        assertTrue(projects.stream().anyMatch(project -> project.getName().equals(ProjectName.from(ContentConstants.CONTENT_REPO_ID))));
    });
}
Also used : NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry) BeforeEach(org.junit.jupiter.api.BeforeEach) IdProviderKey(com.enonic.xp.security.IdProviderKey) PrincipalRelationships(com.enonic.xp.security.PrincipalRelationships) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Permission(com.enonic.xp.security.acl.Permission) RepositoryId(com.enonic.xp.repository.RepositoryId) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) ContextBuilder(com.enonic.xp.context.ContextBuilder) Assertions.assertAll(org.junit.jupiter.api.Assertions.assertAll) SystemConstants(com.enonic.xp.security.SystemConstants) ProjectPermissionsContextManagerImpl(com.enonic.xp.core.impl.project.ProjectPermissionsContextManagerImpl) CreateUserParams(com.enonic.xp.security.CreateUserParams) User(com.enonic.xp.security.User) Projects(com.enonic.xp.project.Projects) PrincipalRelationship(com.enonic.xp.security.PrincipalRelationship) Set(java.util.Set) Project(com.enonic.xp.project.Project) AccessControlList(com.enonic.xp.security.acl.AccessControlList) Collectors(java.util.stream.Collectors) CreateProjectParams(com.enonic.xp.project.CreateProjectParams) UncheckedIOException(java.io.UncheckedIOException) Test(org.junit.jupiter.api.Test) List(java.util.List) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest) IndexServiceInternal(com.enonic.xp.repo.impl.index.IndexServiceInternal) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) ProjectServiceImpl(com.enonic.xp.core.impl.project.ProjectServiceImpl) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) Repository(com.enonic.xp.repository.Repository) SecurityServiceImpl(com.enonic.xp.core.impl.security.SecurityServiceImpl) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ContentConstants(com.enonic.xp.content.ContentConstants) Node(com.enonic.xp.node.Node) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ProjectConstants(com.enonic.xp.project.ProjectConstants) ProjectRole(com.enonic.xp.project.ProjectRole) ProjectName(com.enonic.xp.project.ProjectName) ModifyProjectIconParams(com.enonic.xp.project.ModifyProjectIconParams) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) ProjectGraph(com.enonic.xp.project.ProjectGraph) ProjectPermissions(com.enonic.xp.project.ProjectPermissions) InternalContext(com.enonic.xp.repo.impl.InternalContext) PropertySet(com.enonic.xp.data.PropertySet) NodePath(com.enonic.xp.node.NodePath) IOException(java.io.IOException) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Mockito.when(org.mockito.Mockito.when) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Mockito(org.mockito.Mockito) PrincipalKey(com.enonic.xp.security.PrincipalKey) Assertions(org.junit.jupiter.api.Assertions) ProjectAccessException(com.enonic.xp.core.impl.project.ProjectAccessException) ProjectAccessHelper(com.enonic.xp.core.impl.project.ProjectAccessHelper) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) ModifyProjectParams(com.enonic.xp.project.ModifyProjectParams) PrincipalKeys(com.enonic.xp.security.PrincipalKeys) Projects(com.enonic.xp.project.Projects) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 5 with Projects

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

the class ProjectServiceImplTest method list_with_content_admin_permissions.

@Test
void list_with_content_admin_permissions() {
    doCreateProjectAsAdmin(ProjectName.from("test-project1"));
    doCreateProjectAsAdmin(ProjectName.from("test-project2"));
    doCreateProjectAsAdmin(ProjectName.from("test-project3"));
    contentAdminContext().runWith(() -> {
        final Projects projects = projectService.list();
        assertEquals(4, projects.getSize());
        assertTrue(projects.stream().anyMatch(project -> project.getName().equals(ProjectName.from(ContentConstants.CONTENT_REPO_ID))));
    });
}
Also used : NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry) BeforeEach(org.junit.jupiter.api.BeforeEach) IdProviderKey(com.enonic.xp.security.IdProviderKey) PrincipalRelationships(com.enonic.xp.security.PrincipalRelationships) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Permission(com.enonic.xp.security.acl.Permission) RepositoryId(com.enonic.xp.repository.RepositoryId) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) ContextBuilder(com.enonic.xp.context.ContextBuilder) Assertions.assertAll(org.junit.jupiter.api.Assertions.assertAll) SystemConstants(com.enonic.xp.security.SystemConstants) ProjectPermissionsContextManagerImpl(com.enonic.xp.core.impl.project.ProjectPermissionsContextManagerImpl) CreateUserParams(com.enonic.xp.security.CreateUserParams) User(com.enonic.xp.security.User) Projects(com.enonic.xp.project.Projects) PrincipalRelationship(com.enonic.xp.security.PrincipalRelationship) Set(java.util.Set) Project(com.enonic.xp.project.Project) AccessControlList(com.enonic.xp.security.acl.AccessControlList) Collectors(java.util.stream.Collectors) CreateProjectParams(com.enonic.xp.project.CreateProjectParams) UncheckedIOException(java.io.UncheckedIOException) Test(org.junit.jupiter.api.Test) List(java.util.List) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest) IndexServiceInternal(com.enonic.xp.repo.impl.index.IndexServiceInternal) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) ProjectServiceImpl(com.enonic.xp.core.impl.project.ProjectServiceImpl) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) Repository(com.enonic.xp.repository.Repository) SecurityServiceImpl(com.enonic.xp.core.impl.security.SecurityServiceImpl) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ContentConstants(com.enonic.xp.content.ContentConstants) Node(com.enonic.xp.node.Node) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ProjectConstants(com.enonic.xp.project.ProjectConstants) ProjectRole(com.enonic.xp.project.ProjectRole) ProjectName(com.enonic.xp.project.ProjectName) ModifyProjectIconParams(com.enonic.xp.project.ModifyProjectIconParams) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) ProjectGraph(com.enonic.xp.project.ProjectGraph) ProjectPermissions(com.enonic.xp.project.ProjectPermissions) InternalContext(com.enonic.xp.repo.impl.InternalContext) PropertySet(com.enonic.xp.data.PropertySet) NodePath(com.enonic.xp.node.NodePath) IOException(java.io.IOException) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Mockito.when(org.mockito.Mockito.when) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Mockito(org.mockito.Mockito) PrincipalKey(com.enonic.xp.security.PrincipalKey) Assertions(org.junit.jupiter.api.Assertions) ProjectAccessException(com.enonic.xp.core.impl.project.ProjectAccessException) ProjectAccessHelper(com.enonic.xp.core.impl.project.ProjectAccessHelper) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) ModifyProjectParams(com.enonic.xp.project.ModifyProjectParams) PrincipalKeys(com.enonic.xp.security.PrincipalKeys) Projects(com.enonic.xp.project.Projects) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Aggregations

Projects (com.enonic.xp.project.Projects)7 ProjectName (com.enonic.xp.project.ProjectName)5 Test (org.junit.jupiter.api.Test)5 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)4 Context (com.enonic.xp.context.Context)4 ContextBuilder (com.enonic.xp.context.ContextBuilder)4 PropertySet (com.enonic.xp.data.PropertySet)4 PropertyTree (com.enonic.xp.data.PropertyTree)4 CreateProjectParams (com.enonic.xp.project.CreateProjectParams)4 ModifyProjectIconParams (com.enonic.xp.project.ModifyProjectIconParams)4 ModifyProjectParams (com.enonic.xp.project.ModifyProjectParams)4 Project (com.enonic.xp.project.Project)4 ProjectConstants (com.enonic.xp.project.ProjectConstants)4 ProjectGraph (com.enonic.xp.project.ProjectGraph)4 ProjectPermissions (com.enonic.xp.project.ProjectPermissions)4 ProjectRole (com.enonic.xp.project.ProjectRole)4 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)4 Repository (com.enonic.xp.repository.Repository)4 RepositoryId (com.enonic.xp.repository.RepositoryId)4 RoleKeys (com.enonic.xp.security.RoleKeys)4