@Override public Boolean thereIsAProjectInTheWorkbench() { return !projectService.getAllWorkspaceProjects().isEmpty(); }
@Override public Boolean hasProjects(final OrganizationalUnit organizationalUnit) { return !projectService.getAllWorkspaceProjects(organizationalUnit).isEmpty(); }
@Override public Collection<WorkspaceProject> searchByName(final String pattern, final int maxItems, final boolean caseSensitive) { final List<WorkspaceProject> result = new ArrayList<>(); for (final WorkspaceProject workspaceProject : workspaceProjectService.getAllWorkspaceProjects()) { final String name = workspaceProject.getName(); if (caseSensitive ? name.contains(pattern) : name.toLowerCase().contains(pattern.toLowerCase())) { result.add(workspaceProject); } if (maxItems == result.size()) { break; } } return result; } }
@Override public Collection<WorkspaceProject> searchByName(final String pattern, final int maxItems, final boolean caseSensitive) { final List<WorkspaceProject> result = new ArrayList<>(); for (final WorkspaceProject workspaceProject : workspaceProjectService.getAllWorkspaceProjects()) { final String name = workspaceProject.getName(); if (caseSensitive ? name.contains(pattern) : name.toLowerCase().contains(pattern.toLowerCase())) { result.add(workspaceProject); } if (maxItems == result.size()) { break; } } return result; } }
@GET @Produces(MediaType.APPLICATION_JSON) @Path("/spaces/{spaceName}/projects") @RolesAllowed({REST_ROLE, REST_PROJECT_ROLE}) public Collection<ProjectResponse> getProjects(@PathParam("spaceName") String spaceName) { logger.info("-----getProjects--- , spaceName: {}", spaceName); org.guvnor.structure.organizationalunit.OrganizationalUnit organizationalUnit = organizationalUnitService.getOrganizationalUnit(spaceName); assertObjectExists(organizationalUnit, "space", spaceName); final Collection<WorkspaceProject> projects = workspaceProjectService.getAllWorkspaceProjects(organizationalUnit); final List<ProjectResponse> projectRequests = new ArrayList<ProjectResponse>(projects.size()); for (WorkspaceProject project : projects) { projectRequests.add(getProjectResponse(project)); } return projectRequests; }
@Override public LibraryInfo getLibraryInfo(final OrganizationalUnit organizationalUnit) { final Collection<WorkspaceProject> projects = projectService.getAllWorkspaceProjects(organizationalUnit).stream() .filter(p -> userCanReadProject(p)) .collect(Collectors.toList()); projects.stream().forEach(p -> { if (p.getMainModule() != null) { p.getMainModule().setNumberOfAssets(getNumberOfAssets(p)); } }); return new LibraryInfo(projects); }
@Test public void getAllProjects() throws Exception { final Collection<WorkspaceProject> allWorkspaceProjects = workspaceProjectService.getAllWorkspaceProjects(); assertEquals(3, allWorkspaceProjects.size()); }
@Test public void getAllProjects() throws Exception { final Collection<WorkspaceProject> allWorkspaceProjects = workspaceProjectService.getAllWorkspaceProjects(); assertEquals(3, allWorkspaceProjects.size()); }
@Test public void noProjects() throws Exception { final OrganizationalUnit organizationalUnit = mock(OrganizationalUnit.class); doReturn("myOU").when(organizationalUnit).getName(); doReturn(organizationalUnit).when(organizationalUnitService).getOrganizationalUnit("myOU"); assertTrue(workspaceProjectService.getAllWorkspaceProjects(organizationalUnit).isEmpty()); }
@Test public void thereIsAModuleInTheWorkbenchTest() { Set<WorkspaceProject> projects = new HashSet<>(); projects.add(new WorkspaceProject(ou1, repo1, new Branch("master", mock(Path.class)), mock(Module.class))); doReturn(projects).when(projectService).getAllWorkspaceProjects(); final Boolean thereIsAModuleInTheWorkbench = libraryService.thereIsAProjectInTheWorkbench(); assertTrue(thereIsAModuleInTheWorkbench); verify(projectService, times(1)).getAllWorkspaceProjects(); }
@Test public void noProjects() throws Exception { final OrganizationalUnit organizationalUnit = mock(OrganizationalUnit.class); doReturn("myOU").when(organizationalUnit).getName(); doReturn(organizationalUnit).when(organizationalUnitService).getOrganizationalUnit("myOU"); assertTrue(workspaceProjectService.getAllWorkspaceProjects(organizationalUnit).isEmpty()); }
@Test public void hasProjectsTest() { final Path path = mockPath("file://the_project"); final WorkspaceProject project = mock(WorkspaceProject.class); when(project.getRootPath()).thenReturn(path); doReturn(true).when(ioService).exists(any()); final Set<WorkspaceProject> projects = new HashSet<>(); projects.add(project); doReturn(projects).when(projectService).getAllWorkspaceProjects(ou1); assertTrue(libraryService.hasProjects(ou1)); }
@Test public void thereIsNotAModuleInTheWorkbenchTest() { final Boolean thereIsAModuleInTheWorkbench = libraryService.thereIsAProjectInTheWorkbench(); assertFalse(thereIsAModuleInTheWorkbench); verify(projectService, times(1)).getAllWorkspaceProjects(); }
private Space getSpace(OrganizationalUnit ou) { final Space space = new Space(); space.setName(ou.getName()); space.setOwner(ou.getOwner()); space.setDefaultGroupId(ou.getDefaultGroupId()); final List<ProjectResponse> repoNames = new ArrayList<>(); for (WorkspaceProject workspaceProject : workspaceProjectService.getAllWorkspaceProjects(ou)) { repoNames.add(getProjectResponse(workspaceProject)); } space.setProjects(repoNames); return space; }
@Test public void getAllProjectsForOU2() throws Exception { final Collection<WorkspaceProject> allWorkspaceProjects = workspaceProjectService.getAllWorkspaceProjects(ou2); assertContains(repository3, allWorkspaceProjects); assertEquals(1, allWorkspaceProjects.size()); }
@Before public void setUp() throws Exception { when(itemA.getName()).thenReturn("Item A"); when(itemB.getName()).thenReturn("Item B"); final Repository repository = mock(Repository.class); final Path repositoryRoot = mock(Path.class); when(repository.getDefaultBranch()).thenReturn(Optional.of(new Branch("master", repositoryRoot))); when(workspaceProjectService.getAllWorkspaceProjects()).thenReturn(new HashSet() {{ add(itemA); add(itemB); }}); searchService = new WorkspaceProjectSearchServiceImpl(workspaceProjectService); }
@Before public void setUp() throws Exception { when(itemA.getName()).thenReturn("Item A"); when(itemB.getName()).thenReturn("Item B"); final Repository repository = mock(Repository.class); final Path repositoryRoot = mock(Path.class); when(repository.getDefaultBranch()).thenReturn(Optional.of(new Branch("master", repositoryRoot))); when(workspaceProjectService.getAllWorkspaceProjects()).thenReturn(new HashSet() {{ add(itemA); add(itemB); }}); searchService = new WorkspaceProjectSearchServiceImpl(workspaceProjectService); }
@Test public void getAllProjectsForOU2() throws Exception { final Collection<WorkspaceProject> allWorkspaceProjects = workspaceProjectService.getAllWorkspaceProjects(ou2); assertContains(repository3, allWorkspaceProjects); assertEquals(1, allWorkspaceProjects.size()); }
@Test public void getAllProjectsForOU1() throws Exception { final Collection<WorkspaceProject> allWorkspaceProjects = workspaceProjectService.getAllWorkspaceProjects(ou1); assertContains(repository1, allWorkspaceProjects); assertContains(repository2, allWorkspaceProjects); assertEquals(2, allWorkspaceProjects.size()); }
@Test public void getAllProjectsForOU1() throws Exception { final Collection<WorkspaceProject> allWorkspaceProjects = workspaceProjectService.getAllWorkspaceProjects(ou1); assertContains(repository1, allWorkspaceProjects); assertContains(repository2, allWorkspaceProjects); assertEquals(2, allWorkspaceProjects.size()); }