use of com.enonic.xp.project.ProjectName in project xp by enonic.
the class ProjectAccessSiteProcessor method processUpdate.
@Override
public ProcessUpdateResult processUpdate(final ProcessUpdateParams params) {
final Site editedSite = (Site) params.getEditedContent();
final SiteConfigs editedSiteConfigs = editedSite.getSiteConfigs();
final Site originalSite = (Site) params.getOriginalContent();
final SiteConfigs originalSiteConfigs = originalSite.getSiteConfigs();
final Context context = ContextAccessor.current();
final AuthenticationInfo authenticationInfo = context.getAuthInfo();
final ProjectName projectName = ProjectName.from(context.getRepositoryId());
if (!Objects.equals(originalSiteConfigs, editedSiteConfigs)) {
if (!ProjectAccessHelper.hasAdminAccess(authenticationInfo)) {
if (ProjectConstants.DEFAULT_PROJECT_NAME.equals(projectName)) {
throw new ProjectAccessRequiredException(authenticationInfo.getUser().getKey());
} else if (!this.projectPermissionsContextManager.hasAnyProjectRole(authenticationInfo, projectName, Set.of(ProjectRole.OWNER))) {
throw new ProjectAccessRequiredException(authenticationInfo.getUser().getKey(), ProjectRole.OWNER);
}
}
}
return null;
}
use of com.enonic.xp.project.ProjectName in project xp by enonic.
the class SyncContentServiceImplTest method testWorkflowInfo.
@Test
public void testWorkflowInfo() throws Exception {
final Content source = sourceContext.callWith(() -> createContent(ContentPath.ROOT));
syncCreated(source.getId());
targetContext.runWith(() -> {
contentService.update(new UpdateContentParams().contentId(source.getId()).editor(edit -> {
edit.workflowInfo = WorkflowInfo.ready();
edit.data = new PropertyTree();
}));
});
syncContentService.resetInheritance(ResetContentInheritParams.create().contentId(source.getId()).inherit(EnumSet.of(ContentInheritType.CONTENT)).projectName(targetProject.getName()).build());
targetContext.runWith(() -> {
final Content changed = contentService.getById(source.getId());
assertTrue(changed.getInherit().contains(ContentInheritType.CONTENT));
assertTrue(changed.getData().hasProperty("stringField"));
});
}
use of com.enonic.xp.project.ProjectName 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<String> repoNames = nodes.stream().map(map -> map.get("repo")).distinct().collect(Collectors.toList());
if (repoNames.size() != 1) {
throw new IllegalArgumentException(repoNames.size() > 1 ? "An event cannot contain nodes from different repositories" : "An event must contain 'repo' property");
}
final ProjectName currentProjectName = ProjectName.from(RepositoryId.from(repoNames.get(0)));
if (currentProjectName == null) {
return;
}
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()));
}
});
}
use of com.enonic.xp.project.ProjectName 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;
});
}
use of com.enonic.xp.project.ProjectName 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;
}
Aggregations