Search in sources :

Example 11 with ProjectName

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

the class ProjectServiceImplTest method delete.

@Test
void delete() {
    final ProjectName projectName = ProjectName.from("test-project");
    doCreateProjectAsAdmin(projectName);
    adminContext().runWith(() -> {
        assertNotNull(this.projectService.get(projectName));
        this.projectService.delete(projectName);
        assertNull(this.repositoryService.get(projectName.getRepoId()));
    });
}
Also used : ProjectName(com.enonic.xp.project.ProjectName) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 12 with ProjectName

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

the class ProjectServiceImplTest method delete_without_permissions.

@Test
void delete_without_permissions() {
    final ProjectName projectName = ProjectName.from("test-project");
    doCreateProjectAsAdmin(projectName);
    adminContext().runWith(() -> {
        assertNotNull(this.projectService.get(projectName));
    });
    final RuntimeException ex = Assertions.assertThrows(RuntimeException.class, () -> projectService.delete(projectName));
    assertEquals("Denied [user:system:test-user] user access for [delete] operation", ex.getMessage());
}
Also used : ProjectName(com.enonic.xp.project.ProjectName) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 13 with ProjectName

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

the class ResetContentInheritanceCommand method execute.

void execute() {
    final ProjectName sourceProjectName = fetchSourceProjectName(params.getProjectName());
    validateSourceContentExist(sourceProjectName);
    final Context targetContext = ContextBuilder.from(ContextAccessor.current()).repositoryId(params.getProjectName().getRepoId()).branch(ContentConstants.BRANCH_DRAFT).authInfo(createAdminAuthInfo()).build();
    targetContext.runWith(() -> {
        if (contentService.contentExists(params.getContentId())) {
            final Content targetContent = contentService.getById(params.getContentId());
            final Set<ContentInheritType> typesToReset = params.getInherit().stream().filter(contentInheritType -> !targetContent.getInherit().contains(contentInheritType)).collect(Collectors.toSet());
            if (!typesToReset.isEmpty()) {
                final UpdateContentParams updateParams = new UpdateContentParams().contentId(targetContent.getId()).modifier(targetContent.getModifier()).stopInherit(false).editor(edit -> {
                    edit.inherit = processInherit(edit.inherit, typesToReset);
                    edit.workflowInfo = WorkflowInfo.inProgress();
                });
                contentService.update(updateParams);
                syncContent(targetContent.getId(), sourceProjectName, params.getProjectName());
            }
        }
    });
}
Also used : Context(com.enonic.xp.context.Context) ContentService(com.enonic.xp.content.ContentService) User(com.enonic.xp.security.User) ContentConstants(com.enonic.xp.content.ContentConstants) ProjectService(com.enonic.xp.project.ProjectService) WorkflowInfo(com.enonic.xp.content.WorkflowInfo) ContentInheritType(com.enonic.xp.content.ContentInheritType) Set(java.util.Set) Content(com.enonic.xp.content.Content) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Project(com.enonic.xp.project.Project) Collectors(java.util.stream.Collectors) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) ContentId(com.enonic.xp.content.ContentId) Stream(java.util.stream.Stream) ResetContentInheritParams(com.enonic.xp.content.ResetContentInheritParams) PrincipalKey(com.enonic.xp.security.PrincipalKey) ContextAccessor(com.enonic.xp.context.ContextAccessor) ProjectName(com.enonic.xp.project.ProjectName) RoleKeys(com.enonic.xp.security.RoleKeys) Preconditions(com.google.common.base.Preconditions) Context(com.enonic.xp.context.Context) ContextBuilder(com.enonic.xp.context.ContextBuilder) EnumSet(java.util.EnumSet) ProjectName(com.enonic.xp.project.ProjectName) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) ContentInheritType(com.enonic.xp.content.ContentInheritType)

Example 14 with ProjectName

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

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

the class ProjectServiceImpl method doModify.

private Project doModify(final ModifyProjectParams params) {
    final UpdateRepositoryParams updateParams = UpdateRepositoryParams.create().repositoryId(params.getName().getRepoId()).editor(editableRepository -> modifyProjectData(params, editableRepository.data)).build();
    final Repository updatedRepository = repositoryService.updateRepository(updateParams);
    if (!ProjectConstants.DEFAULT_PROJECT_NAME.equals(params.getName())) {
        UpdateProjectRoleNamesCommand.create().securityService(securityService).projectName(params.getName()).projectDisplayName(params.getDisplayName()).build().execute();
    }
    return Project.from(updatedRepository);
}
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) Repository(com.enonic.xp.repository.Repository) UpdateRepositoryParams(com.enonic.xp.repository.UpdateRepositoryParams)

Aggregations

ProjectName (com.enonic.xp.project.ProjectName)20 Test (org.junit.jupiter.api.Test)13 Project (com.enonic.xp.project.Project)7 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)7 RepositoryId (com.enonic.xp.repository.RepositoryId)6 Context (com.enonic.xp.context.Context)5 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)5 EnumSet (java.util.EnumSet)5 ContentId (com.enonic.xp.content.ContentId)4 ContextAccessor (com.enonic.xp.context.ContextAccessor)4 ContextBuilder (com.enonic.xp.context.ContextBuilder)4 PropertyTree (com.enonic.xp.data.PropertyTree)4 ProjectService (com.enonic.xp.project.ProjectService)4 RoleKeys (com.enonic.xp.security.RoleKeys)4 Collectors (java.util.stream.Collectors)4 Content (com.enonic.xp.content.Content)3 ContentInheritType (com.enonic.xp.content.ContentInheritType)3 ResetContentInheritParams (com.enonic.xp.content.ResetContentInheritParams)3 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)3 WorkflowInfo (com.enonic.xp.content.WorkflowInfo)3