use of com.enonic.xp.project.ProjectNotFoundException 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.ProjectNotFoundException in project xp by enonic.
the class ProjectContentEventListener method doHandleContentEvent.
private void doHandleContentEvent(final List<Map<String, String>> nodes, final String type) {
createAdminContext().runWith(() -> {
final Branch branch = Branch.from(nodes.stream().findAny().orElseThrow(() -> new IllegalArgumentException("nodes cannot be empty")).get("branch"));
if (!ContentConstants.BRANCH_DRAFT.equals(branch)) {
return;
}
final List<ContentId> contentIds = nodes.stream().map(map -> ContentId.from(map.get("id"))).collect(Collectors.toList());
final List<ProjectName> projectNames = nodes.stream().map(map -> map.get("repo")).distinct().map(repo -> ProjectName.from(RepositoryId.from(repo))).collect(Collectors.toList());
if (projectNames.size() != 1) {
throw new IllegalArgumentException(projectNames.size() > 1 ? "An event cannot contain nodes from different repositories" : "An event must contain 'repo' property");
}
final ProjectName currentProjectName = projectNames.get(0);
final Project sourceProject = this.projectService.list().stream().filter(project -> currentProjectName.equals(project.getName())).findAny().orElseThrow(() -> new ProjectNotFoundException(currentProjectName));
this.projectService.list().stream().filter(project -> currentProjectName.equals(project.getParent())).forEach(targetProject -> {
final ContentEventsSyncParams.Builder paramsBuilder = ContentEventsSyncParams.create().addContentIds(contentIds).sourceProject(sourceProject.getName()).targetProject(targetProject.getName());
switch(type) {
case "node.created":
case "node.duplicated":
paramsBuilder.syncEventType(ContentSyncEventType.CREATED);
break;
case "node.updated":
case "node.pushed":
paramsBuilder.syncEventType(ContentSyncEventType.UPDATED);
break;
case "node.manualOrderUpdated":
paramsBuilder.syncEventType(ContentSyncEventType.MANUAL_ORDER_UPDATED);
break;
case "node.sorted":
paramsBuilder.syncEventType(ContentSyncEventType.SORTED);
break;
case "node.renamed":
paramsBuilder.syncEventType(ContentSyncEventType.RENAMED);
break;
case "node.moved":
paramsBuilder.syncEventType(ContentSyncEventType.MOVED);
break;
case "node.deleted":
paramsBuilder.syncEventType(ContentSyncEventType.DELETED);
break;
default:
LOG.debug("Ignoring node type: {}", type);
break;
}
final ContentEventsSyncParams params = paramsBuilder.build();
if (params.getSyncType() != null) {
contentSynchronizer.sync(params);
}
});
if (sourceProject.getParent() != null && "node.deleted".equals(type)) {
this.projectService.list().stream().filter(project -> project.getName().equals(sourceProject.getParent())).forEach(parentProject -> contentSynchronizer.sync(ContentSyncParams.create().addContentIds(contentIds).sourceProject(parentProject.getName()).targetProject(sourceProject.getName()).build()));
}
});
}
Aggregations