DtoConverter { public ProjectDescriptor toDescriptorDto2(Project project, UriBuilder serviceUriBuilder, UriBuilder baseUriBuilder, ProjectTypeRegistry ptRegistry, String wsId) throws InvalidValueException { final EnvironmentContext environmentContext = EnvironmentContext.getCurrent(); final DtoFactory dtoFactory = DtoFactory.getInstance(); final ProjectDescriptor dto = dtoFactory.createDto(ProjectDescriptor.class); final String name = project.getName(); final String path = project.getPath(); String wsName = fetchWorkspaceName(wsId, baseUriBuilder, dto.getProblems()); dto.withWorkspaceId(wsId) .withWorkspaceName(wsName) .withName(name) .withPath(path); ProjectConfig config = null; try { config = project.getConfig(); } catch (ServerException | ValueStorageException | ProjectTypeConstraintException e) { dto.getProblems().add(createProjectProblem(dtoFactory, e)); dto.withType(BaseProjectType.ID); } if (config != null) { dto.withDescription(config.getDescription()); String typeId = config.getTypeId(); dto.withType(typeId) .withTypeName(ptRegistry.getProjectType(typeId).getDisplayName()); dto.withMixins(config.getMixinTypes()); final Map<String, AttributeValue> attributes = config.getAttributes(); final Map<String, List<String>> attributesMap = new LinkedHashMap<>(attributes.size()); if (!attributes.isEmpty()) { for (String attrName : attributes.keySet()) { attributesMap.put(attrName, attributes.get(attrName).getList()); } } dto.withAttributes(attributesMap); final Builders builders = config.getBuilders(); if (builders != null) { dto.withBuilders(toDto(dtoFactory, builders)); } final Runners runners = config.getRunners(); if (runners != null) { dto.withRunners(toDto(dtoFactory, runners)); } } final User currentUser = environmentContext.getUser(); List<AccessControlEntry> acl = null; try { acl = project.getPermissions(); } catch (ServerException e) { dto.getProblems().add(createProjectProblem(dtoFactory, e)); } if (acl != null) { final List<String> permissions = new LinkedList<>(); if (acl.isEmpty()) { permissions.add("all"); } else { for (AccessControlEntry accessControlEntry : acl) { final Principal principal = accessControlEntry.getPrincipal(); if ((Principal.Type.USER == principal.getType() && currentUser.getId().equals(principal.getName())) || (Principal.Type.USER == principal.getType() && "any".equals(principal.getName())) || (Principal.Type.GROUP == principal.getType() && currentUser.isMemberOf(principal.getName()))) { permissions.addAll(accessControlEntry.getPermissions()); } } } dto.withPermissions(permissions); } try { dto.withCreationDate(project.getCreationDate()); } catch (ServerException e) { dto.getProblems().add(createProjectProblem(dtoFactory, e)); } try { dto.withModificationDate(project.getModificationDate()); } catch (ServerException e) { dto.getProblems().add(createProjectProblem(dtoFactory, e)); } try { dto.withContentRoot(project.getContentRoot()); } catch (ServerException e) { dto.getProblems().add(createProjectProblem(dtoFactory, e)); } try { dto.withVisibility(project.getVisibility()); } catch (ServerException e) { dto.getProblems().add(createProjectProblem(dtoFactory, e)); } if (serviceUriBuilder != null) { dto.withBaseUrl(serviceUriBuilder.clone().path(ProjectService.class, "getProject").build(wsId, path.substring(1)).toString()) .withLinks(generateProjectLinks(project, serviceUriBuilder)); if (wsName != null) { dto.withIdeUrl(serviceUriBuilder.clone().replacePath("ws").path(wsName).path(path).build().toString()); } } return dto; }  ProjectTemplateDescription fromDto(ProjectTemplateDescriptor dto); ProjectTemplateDescriptor toDto(ProjectTemplateDescription templateDescription); ProjectConfig fromDto2(ProjectUpdate dto, ProjectTypeRegistry typeRegistry); ProjectConfig toProjectConfig(ProjectModule dto, ProjectTypeRegistry typeRegistry); Builders fromDto(BuildersDescriptor dto); Runners fromDto(RunnersDescriptor dto); ProjectTypeDefinition toTypeDescriptor2(ProjectType projectType); ProjectTemplateDescriptor toTemplateDescriptor(ProjectTemplateDescription projectTemplate, String projectType); ProjectImporterDescriptor toImporterDescriptor(ProjectImporter importer); ItemReference toItemReferenceDto(FileEntry file, UriBuilder uriBuilder); ItemReference toItemReferenceDto(FolderEntry folder, UriBuilder uriBuilder); ProjectDescriptor toDescriptorDto2(Project project,
                                                     UriBuilder serviceUriBuilder,
                                                     UriBuilder baseUriBuilder,
                                                     ProjectTypeRegistry ptRegistry,
                                                     String wsId); BuildersDescriptor toDto(Builders builders); RunnersDescriptor toDto(Runners runners); ProjectReference toReferenceDto2(Project project,
                                                   UriBuilder uriBuilder,
                                                   UriBuilder baseUriBuilder);  }
@Test public void toProjectsDescriptorUserPermissionID() throws Exception { String userId = "florentID"; String userName = "florent"; List<String> permissions = Arrays.asList("read", "write"); Project project = mock(Project.class); AccessControlEntry accessControlEntry = mock(AccessControlEntry.class); List<AccessControlEntry> acl = Arrays.asList(accessControlEntry); doReturn(acl).when(project).getPermissions(); Principal principal = mock(Principal.class); doReturn(principal).when(accessControlEntry).getPrincipal(); doReturn(permissions).when(accessControlEntry).getPermissions(); doReturn(Principal.Type.USER).when(principal).getType(); doReturn(userId).when(principal).getName(); EnvironmentContext customEnvironment = mock(EnvironmentContext.class); User user = mock(User.class); doReturn(user).when(customEnvironment).getUser(); doReturn(userId).when(user).getId(); doReturn(userName).when(user).getName(); EnvironmentContext old = EnvironmentContext.getCurrent(); ProjectDescriptor projectDescriptor; try { EnvironmentContext.setCurrent(customEnvironment); projectDescriptor = new DtoConverter().toDescriptorDto2(project, null, new UriBuilderImpl(), null, "workspace"); } finally { EnvironmentContext.setCurrent(old); } Assert.assertNotNull(projectDescriptor); Assert.assertEquals(permissions, projectDescriptor.getPermissions()); }