Search in sources :

Example 56 with OrganizationalUnit

use of org.guvnor.structure.organizationalunit.OrganizationalUnit in project kie-wb-common by kiegroup.

the class DefExplorerQueryServiceImpl method resolveOrganizationalUnits.

/**
 * Resolves the organizational units accessible by current user.
 */
private Set<OrganizationalUnit> resolveOrganizationalUnits() {
    final Collection<OrganizationalUnit> organizationalUnits = organizationalUnitService.getOrganizationalUnits();
    final Set<OrganizationalUnit> authorizedOrganizationalUnits = new HashSet<>();
    for (OrganizationalUnit organizationalUnit : organizationalUnits) {
        if (authorizationManager.authorize(organizationalUnit, identity)) {
            authorizedOrganizationalUnits.add(organizationalUnit);
        }
    }
    return authorizedOrganizationalUnits;
}
Also used : OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) HashSet(java.util.HashSet)

Example 57 with OrganizationalUnit

use of org.guvnor.structure.organizationalunit.OrganizationalUnit in project kie-wb-common by kiegroup.

the class SocialEventModuleConstraintTest method setUp.

@Before
public void setUp() throws Exception {
    Collection<OrganizationalUnit> ous = new ArrayList<OrganizationalUnit>();
    final OrganizationalUnitImpl ou = new OrganizationalUnitImpl("ouname", "owner", "groupid");
    final OrganizationalUnitImpl ouSpy = spy(ou);
    Collection<Repository> repositories = new ArrayList<Repository>();
    repository = new GitRepository("repo", new Space("space"));
    repositories.add(repository);
    ous.add(ouSpy);
    when(ouSpy.getRepositories()).thenReturn(repositories);
    when(organizationalUnitService.getOrganizationalUnits()).thenReturn(ous);
    when(authorizationManager.authorize(ou, user)).thenReturn(true);
    when(authorizationManager.authorize(repository, user)).thenReturn(true);
    when(userCDIContextHelper.getUser()).thenReturn(user);
    when(userCDIContextHelper.thereIsALoggedUserInScope()).thenReturn(true);
    socialEventModuleConstraint = createSocialEventModuleConstraint();
}
Also used : Space(org.uberfire.spaces.Space) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ArrayList(java.util.ArrayList) OrganizationalUnitImpl(org.guvnor.structure.organizationalunit.impl.OrganizationalUnitImpl) Before(org.junit.Before)

Example 58 with OrganizationalUnit

use of org.guvnor.structure.organizationalunit.OrganizationalUnit in project kie-wb-common by kiegroup.

the class SourceServiceImpl method getRepositories.

@Override
public Collection<String> getRepositories(final String organizationalUnit) {
    checkNotNull("organizationalUnit", organizationalUnit);
    OrganizationalUnit ou = organizationalUnitService.getOrganizationalUnit(organizationalUnit);
    if (ou == null) {
        return new ArrayList<>();
    } else {
        return organizationalUnitService.getOrganizationalUnit(organizationalUnit).getRepositories().stream().filter(repository -> authorizationManager.authorize(repository, identity)).map(Repository::getAlias).collect(Collectors.toList());
    }
}
Also used : OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ArrayList(java.util.ArrayList)

Example 59 with OrganizationalUnit

use of org.guvnor.structure.organizationalunit.OrganizationalUnit in project kie-wb-common by kiegroup.

the class SourceServiceImplTest method testGetRepositories.

@Test
public void testGetRepositories() {
    List<Repository> repositories = mockRepositories("RepoName.", REPOSITORIES_SIZE);
    OrganizationalUnit organizationalUnit = mock(OrganizationalUnit.class);
    when(organizationalUnit.getName()).thenReturn(OU_NAME);
    // the organizational unit not exists.
    when(organizationalUnitService.getOrganizationalUnit(OU_NAME)).thenReturn(null);
    Collection<String> result = service.getRepositories(OU_NAME);
    // nothing is returned.
    assertTrue(result.isEmpty());
    // there organizational unit exists, but no repository is authorized.
    when(organizationalUnitService.getOrganizationalUnit(OU_NAME)).thenReturn(organizationalUnit);
    when(organizationalUnit.getRepositories()).thenReturn(repositories);
    result = service.getRepositories(OU_NAME);
    // nothing is returned since there are no authorized repository.
    assertTrue(result.isEmpty());
    // finally we authorize some repositories. Take some arbitrary indexes.
    List<Integer> authorizedIndexes = new ArrayList<>();
    List<String> authorizedNames = new ArrayList<>();
    authorizedIndexes.add(1);
    authorizedIndexes.add(4);
    authorizedIndexes.add(6);
    authorizedIndexes.forEach(index -> {
        when(authorizationManager.authorize(repositories.get(index), identity)).thenReturn(true);
        authorizedNames.add(repositories.get(index).getAlias());
    });
    result = service.getRepositories(OU_NAME);
    assertEquals(authorizedNames, result);
}
Also used : Repository(org.guvnor.structure.repositories.Repository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 60 with OrganizationalUnit

use of org.guvnor.structure.organizationalunit.OrganizationalUnit in project kie-wb-common by kiegroup.

the class SourceServiceImplTest method mockOrganizationalUnits.

private List<OrganizationalUnit> mockOrganizationalUnits(String suffix, int count) {
    List<OrganizationalUnit> result = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        OrganizationalUnit ou = mock(OrganizationalUnit.class);
        when(ou.getName()).thenReturn(suffix + i);
        result.add(ou);
    }
    return result;
}
Also used : OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ArrayList(java.util.ArrayList)

Aggregations

OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)60 Test (org.junit.Test)33 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)19 ArrayList (java.util.ArrayList)18 Repository (org.guvnor.structure.repositories.Repository)17 ExampleOrganizationalUnit (org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit)13 Module (org.guvnor.common.services.project.model.Module)11 POM (org.guvnor.common.services.project.model.POM)10 Branch (org.guvnor.structure.repositories.Branch)10 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)10 WorkspaceProjectContextChangeEvent (org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent)9 Before (org.junit.Before)8 Path (org.uberfire.backend.vfs.Path)7 OrganizationalUnitImpl (org.guvnor.structure.organizationalunit.impl.OrganizationalUnitImpl)6 ExampleProject (org.kie.workbench.common.screens.examples.model.ExampleProject)6 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)5 NewProjectEvent (org.guvnor.common.services.project.events.NewProjectEvent)3 RemoteCallback (org.jboss.errai.common.client.api.RemoteCallback)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Command (org.uberfire.mvp.Command)3