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