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