Search in sources :

Example 16 with Contributor

use of org.uberfire.security.Contributor in project kie-wb-common by kiegroup.

the class TemporaryNiogitService method importProjects.

public void importProjects(Path actualTarget) {
    OrganizationalUnit ou = ouService.createOrganizationalUnit(OU_NAME, "org.migration", Collections.emptyList(), Collections.singletonList(new Contributor(OU_OWNER, ContributorType.OWNER)));
    String repositoryURL = actualTarget.toUri().toString();
    RepositoryEnvironmentConfigurations configurations = new RepositoryEnvironmentConfigurations();
    Map<String, Object> configMap = configurations.getConfigurationMap();
    configMap.put(EnvironmentParameters.AVOID_INDEX, Boolean.TRUE);
    configMap.put("origin", repositoryURL);
    Repository repo = repoService.createRepository(ou, GitRepository.SCHEME.toString(), TMP_REPO_ALIAS, configurations);
    WorkspaceProject project = projectService.resolveProject(repo);
    migrationService.migrate(project);
    repoService.removeRepository(ou.getSpace(), TMP_REPO_ALIAS);
}
Also used : Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) RepositoryEnvironmentConfigurations(org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Contributor(org.uberfire.security.Contributor)

Example 17 with Contributor

use of org.uberfire.security.Contributor in project kie-wb-common by kiegroup.

the class ConfigGroupToSpaceInfoConverter method extractContributors.

private Collection<Contributor> extractContributors(final ConfigGroup configGroup) {
    final List<Contributor> contributors = new ArrayList<>();
    boolean oldConfigGroup = false;
    final String oldOwner = configGroup.getConfigItemValue(OWNER);
    if (oldOwner != null) {
        oldConfigGroup = true;
        contributors.add(new Contributor(oldOwner, ContributorType.OWNER));
    }
    ConfigItem<List<String>> oldContributors = configGroup.getConfigItem(CONTRIBUTORS);
    if (oldContributors != null) {
        oldConfigGroup = true;
        for (String userName : oldContributors.getValue()) {
            if (!userName.equals(oldOwner)) {
                contributors.add(new Contributor(userName, ContributorType.CONTRIBUTOR));
            }
        }
    }
    if (!oldConfigGroup) {
        ConfigItem<List<Contributor>> newContributorsConfigItem = configGroup.getConfigItem(SPACE_CONTRIBUTORS);
        contributors.addAll(newContributorsConfigItem.getValue());
    }
    return contributors;
}
Also used : ArrayList(java.util.ArrayList) Contributor(org.uberfire.security.Contributor) ArrayList(java.util.ArrayList) List(java.util.List)

Example 18 with Contributor

use of org.uberfire.security.Contributor in project kie-wb-common by kiegroup.

the class LibraryServiceImplTest method createProjectTest.

@Test
public void createProjectTest() {
    final List<Contributor> spaceContributors = new ArrayList<>();
    spaceContributors.add(new Contributor("user1", ContributorType.OWNER));
    spaceContributors.add(new Contributor("user2", ContributorType.ADMIN));
    spaceContributors.add(new Contributor("admin", ContributorType.CONTRIBUTOR));
    final OrganizationalUnit organizationalUnit = mock(OrganizationalUnit.class);
    doReturn("ou").when(organizationalUnit).getName();
    doReturn("org.ou").when(organizationalUnit).getDefaultGroupId();
    doReturn(spaceContributors).when(organizationalUnit).getContributors();
    doReturn(organizationalUnit).when(ouService).getOrganizationalUnit("ou");
    doReturn(Optional.empty()).when(archetypeService).getBaseKieTemplateRepository();
    final POM pom = mock(POM.class);
    libraryService.createProject(organizationalUnit, pom, DeploymentMode.VALIDATED);
    verify(ouService, never()).updateOrganizationalUnit(anyString(), anyString(), anyList());
    final List<Contributor> projectContributors = new ArrayList<>();
    projectContributors.add(new Contributor("user1", ContributorType.OWNER));
    projectContributors.add(new Contributor("user2", ContributorType.ADMIN));
    projectContributors.add(new Contributor("admin", ContributorType.OWNER));
    verify(projectService).newProject(organizationalUnit, pom, DeploymentMode.VALIDATED, projectContributors, null, null);
}
Also used : OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ArrayList(java.util.ArrayList) Contributor(org.uberfire.security.Contributor) POM(org.guvnor.common.services.project.model.POM) Test(org.junit.Test)

Example 19 with Contributor

use of org.uberfire.security.Contributor in project kie-wb-common by kiegroup.

the class LibraryServiceImplTest method createProjectFromTemplateTest.

@Test
public void createProjectFromTemplateTest() {
    final List<Contributor> spaceContributors = new ArrayList<>();
    spaceContributors.add(new Contributor("user1", ContributorType.OWNER));
    spaceContributors.add(new Contributor("user2", ContributorType.ADMIN));
    spaceContributors.add(new Contributor("admin", ContributorType.CONTRIBUTOR));
    final OrganizationalUnit organizationalUnit = mock(OrganizationalUnit.class);
    doReturn("ou").when(organizationalUnit).getName();
    doReturn("org.ou").when(organizationalUnit).getDefaultGroupId();
    doReturn(spaceContributors).when(organizationalUnit).getContributors();
    doReturn(organizationalUnit).when(ouService).getOrganizationalUnit("ou");
    final String templateId = "my-template";
    final Repository templateRepository = mock(Repository.class);
    doReturn(templateRepository).when(archetypeService).getTemplateRepository(templateId);
    final POM pom = mock(POM.class);
    libraryService.createProject(organizationalUnit, pom, DeploymentMode.VALIDATED, templateId);
    verify(ouService, never()).updateOrganizationalUnit(anyString(), anyString(), anyList());
    final List<Contributor> projectContributors = new ArrayList<>();
    projectContributors.add(new Contributor("user1", ContributorType.OWNER));
    projectContributors.add(new Contributor("user2", ContributorType.ADMIN));
    projectContributors.add(new Contributor("admin", ContributorType.OWNER));
    verify(projectService).newProject(organizationalUnit, pom, DeploymentMode.VALIDATED, projectContributors, templateRepository, null);
}
Also used : ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) Repository(org.guvnor.structure.repositories.Repository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ArrayList(java.util.ArrayList) Contributor(org.uberfire.security.Contributor) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) POM(org.guvnor.common.services.project.model.POM) Test(org.junit.Test)

Example 20 with Contributor

use of org.uberfire.security.Contributor in project kie-wb-common by kiegroup.

the class LibraryServiceImplTest method createProjectWithUserThatIsNotASpaceContributorTest.

@Test
public void createProjectWithUserThatIsNotASpaceContributorTest() {
    final List<Contributor> spaceContributors = new ArrayList<>();
    spaceContributors.add(new Contributor("user1", ContributorType.OWNER));
    spaceContributors.add(new Contributor("user2", ContributorType.ADMIN));
    spaceContributors.add(new Contributor("user3", ContributorType.CONTRIBUTOR));
    final OrganizationalUnit organizationalUnit = mock(OrganizationalUnit.class);
    doReturn("ou").when(organizationalUnit).getName();
    doReturn("org.ou").when(organizationalUnit).getDefaultGroupId();
    doReturn(spaceContributors).when(organizationalUnit).getContributors();
    doReturn(organizationalUnit).when(ouService).getOrganizationalUnit("ou");
    doReturn(Optional.empty()).when(archetypeService).getBaseKieTemplateRepository();
    final POM pom = mock(POM.class);
    libraryService.createProject(organizationalUnit, pom, DeploymentMode.VALIDATED);
    final List<Contributor> updatedSpaceContributors = new ArrayList<>();
    updatedSpaceContributors.add(new Contributor("user1", ContributorType.OWNER));
    updatedSpaceContributors.add(new Contributor("user2", ContributorType.ADMIN));
    updatedSpaceContributors.add(new Contributor("user3", ContributorType.CONTRIBUTOR));
    updatedSpaceContributors.add(new Contributor("admin", ContributorType.CONTRIBUTOR));
    verify(ouService).updateOrganizationalUnit(anyString(), anyString(), eq(updatedSpaceContributors));
    final List<Contributor> projectContributors = new ArrayList<>();
    projectContributors.add(new Contributor("user1", ContributorType.OWNER));
    projectContributors.add(new Contributor("user2", ContributorType.ADMIN));
    projectContributors.add(new Contributor("user3", ContributorType.CONTRIBUTOR));
    projectContributors.add(new Contributor("admin", ContributorType.OWNER));
    verify(projectService).newProject(organizationalUnit, pom, DeploymentMode.VALIDATED, projectContributors, null, null);
}
Also used : OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ArrayList(java.util.ArrayList) Contributor(org.uberfire.security.Contributor) POM(org.guvnor.common.services.project.model.POM) Test(org.junit.Test)

Aggregations

Contributor (org.uberfire.security.Contributor)31 ArrayList (java.util.ArrayList)25 Test (org.junit.Test)22 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)11 Repository (org.guvnor.structure.repositories.Repository)8 POM (org.guvnor.common.services.project.model.POM)6 Consumer (java.util.function.Consumer)4 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)4 List (java.util.List)3 Branch (org.guvnor.structure.repositories.Branch)3 Before (org.junit.Before)3 Collections (java.util.Collections)2 Map (java.util.Map)2 Module (org.guvnor.common.services.project.model.Module)2 BranchPermissions (org.guvnor.structure.organizationalunit.config.BranchPermissions)2 UnauthorizedException (org.jboss.errai.security.shared.exception.UnauthorizedException)2 Archetype (org.kie.workbench.common.screens.archetype.mgmt.shared.model.Archetype)2 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)2 LibraryPreferences (org.kie.workbench.common.screens.library.api.preferences.LibraryPreferences)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2