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")));
}
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();
}
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());
}
});
}
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))));
});
}
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))));
});
}
Aggregations