Search in sources :

Example 26 with Project

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

the class ModifyProjectHandler method doExecute.

@Override
protected ProjectMapper doExecute() {
    final Project projectBeforeUpdate = this.projectService.get(this.id);
    final ModifyProjectParams params = modifyProjectParams(projectBeforeUpdate);
    final Project project = this.projectService.modify(params);
    Locale projectLanguage;
    if (this.language != null) {
        projectLanguage = ApplyProjectLanguageCommand.create().projectName(this.id).language(this.language).contentService(this.contentService).build().execute();
    } else {
        projectLanguage = GetProjectLanguageCommand.create().projectName(this.id).contentService(this.contentService).build().execute();
    }
    final Boolean isPublic = GetProjectReadAccessCommand.create().projectName(this.id).contentService(this.contentService).build().execute();
    final ProjectPermissions projectPermissions = this.projectService.getPermissions(this.id);
    return ProjectMapper.create().setProject(project).setLanguage(projectLanguage).setProjectPermissions(projectPermissions).setIsPublic(isPublic).build();
}
Also used : Locale(java.util.Locale) Project(com.enonic.xp.project.Project) ModifyProjectParams(com.enonic.xp.project.ModifyProjectParams) ProjectPermissions(com.enonic.xp.project.ProjectPermissions)

Example 27 with Project

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

the class BaseProjectHandlerTest method mockProject.

protected void mockProject() {
    final Map<ProjectName, Project> projects = new HashMap<>();
    when(this.projectService.create(any(CreateProjectParams.class))).thenAnswer(mock -> {
        final Project project = createProject((CreateProjectParams) mock.getArguments()[0]);
        Mockito.when(projectService.get(project.getName())).thenReturn(project);
        Mockito.when(projectService.delete(project.getName())).thenReturn(true);
        projects.put(project.getName(), project);
        return project;
    });
    when(this.projectService.modify(any(ModifyProjectParams.class))).thenAnswer(mock -> {
        final Project project = createProject((ModifyProjectParams) mock.getArguments()[0]);
        Mockito.when(projectService.get(project.getName())).thenReturn(project);
        projects.put(project.getName(), project);
        return project;
    });
    when(this.projectService.list()).thenAnswer(mock -> Projects.create().addAll(projects.values()).build());
    when(this.projectService.getPermissions(any(ProjectName.class))).thenReturn(ProjectPermissions.create().build());
    when(this.projectService.modifyPermissions(any(ProjectName.class), any(ProjectPermissions.class))).thenAnswer(mock -> {
        final ProjectName projectName = (ProjectName) mock.getArguments()[0];
        final ProjectPermissions projectPermissions = (ProjectPermissions) mock.getArguments()[1];
        Mockito.when(projectService.getPermissions(projectName)).thenReturn(projectPermissions);
        return projectPermissions;
    });
}
Also used : Project(com.enonic.xp.project.Project) ModifyProjectParams(com.enonic.xp.project.ModifyProjectParams) ProjectName(com.enonic.xp.project.ProjectName) HashMap(java.util.HashMap) ProjectPermissions(com.enonic.xp.project.ProjectPermissions) CreateProjectParams(com.enonic.xp.project.CreateProjectParams)

Example 28 with Project

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

the class CreateProjectHandler method doExecute.

@Override
protected ProjectMapper doExecute() {
    final CreateProjectParams params = createProjectParams();
    final Project project = this.projectService.create(params);
    final Locale modifiedLanguage = this.language != null ? ApplyProjectLanguageCommand.create().projectName(this.id).language(this.language).contentService(this.contentService).build().execute() : null;
    final ProjectPermissions modifiedPermissions = this.permissions != null ? this.projectService.modifyPermissions(this.id, this.permissions) : ProjectPermissions.create().build();
    return ProjectMapper.create().setProject(project).setLanguage(modifiedLanguage).setProjectPermissions(modifiedPermissions).setIsPublic(isPublic).build();
}
Also used : Locale(java.util.Locale) Project(com.enonic.xp.project.Project) ProjectPermissions(com.enonic.xp.project.ProjectPermissions) CreateProjectParams(com.enonic.xp.project.CreateProjectParams)

Example 29 with Project

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

the class GetProjectHandler method doExecute.

@Override
protected ProjectMapper doExecute() {
    final Project project = this.projectService.get(this.id);
    if (project == null) {
        return null;
    }
    final ProjectPermissions projectPermissions = !ProjectConstants.DEFAULT_PROJECT_NAME.equals(project.getName()) ? this.projectService.getPermissions(project.getName()) : null;
    final Boolean readAccess = !ProjectConstants.DEFAULT_PROJECT_NAME.equals(project.getName()) ? GetProjectReadAccessCommand.create().contentService(this.contentService).projectName(project.getName()).build().execute() : null;
    final Locale language = GetProjectLanguageCommand.create().projectName(this.id).contentService(this.contentService).build().execute();
    return ProjectMapper.create().setProject(project).setLanguage(language).setProjectPermissions(projectPermissions).setIsPublic(readAccess).build();
}
Also used : Locale(java.util.Locale) Project(com.enonic.xp.project.Project) ProjectPermissions(com.enonic.xp.project.ProjectPermissions)

Example 30 with Project

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

the class ProjectsSyncTask method sortProjects.

private List<Project> sortProjects(final Projects projects) {
    final List<Project> result = new ArrayList<>();
    final Queue<Project> queue = new ArrayDeque<>(projects.getList());
    ProjectName currentParent = null;
    int currentParentCounter = 0;
    int loopSize = queue.size();
    while (!queue.isEmpty()) {
        if (loopSize == 0) {
            if (currentParentCounter < result.size()) {
                currentParent = result.get(currentParentCounter).getName();
                currentParentCounter++;
            } else {
                // projects with invalid parent in queue
                currentParent = queue.peek().getParent();
            }
            loopSize = queue.size();
        }
        loopSize--;
        final Project current = queue.poll();
        if (Objects.equals(current.getParent(), currentParent)) {
            result.add(current);
        } else {
            queue.offer(current);
        }
    }
    return result;
}
Also used : Project(com.enonic.xp.project.Project) ProjectName(com.enonic.xp.project.ProjectName) ArrayList(java.util.ArrayList) ArrayDeque(java.util.ArrayDeque)

Aggregations

Project (com.enonic.xp.project.Project)31 Test (org.junit.jupiter.api.Test)19 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)18 ProjectName (com.enonic.xp.project.ProjectName)9 ProjectPermissions (com.enonic.xp.project.ProjectPermissions)9 RepositoryId (com.enonic.xp.repository.RepositoryId)9 CreateProjectParams (com.enonic.xp.project.CreateProjectParams)7 ModifyProjectParams (com.enonic.xp.project.ModifyProjectParams)7 Repository (com.enonic.xp.repository.Repository)7 Context (com.enonic.xp.context.Context)6 ContextBuilder (com.enonic.xp.context.ContextBuilder)6 ProjectGraph (com.enonic.xp.project.ProjectGraph)6 RoleKeys (com.enonic.xp.security.RoleKeys)6 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)6 ByteSource (com.google.common.io.ByteSource)6 IOException (java.io.IOException)6 UncheckedIOException (java.io.UncheckedIOException)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)5