Search in sources :

Example 1 with CreateProjectParams

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

use of com.enonic.xp.project.CreateProjectParams 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)

Aggregations

CreateProjectParams (com.enonic.xp.project.CreateProjectParams)2 Project (com.enonic.xp.project.Project)2 ProjectPermissions (com.enonic.xp.project.ProjectPermissions)2 ModifyProjectParams (com.enonic.xp.project.ModifyProjectParams)1 ProjectName (com.enonic.xp.project.ProjectName)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1