Search in sources :

Example 41 with Repository

use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.

the class DefExplorerQueryServiceImpl method resolveModules.

/**
 * Resolves all the modules accessible by current user in the given branch name.
 */
private Map<String, Module> resolveModules(final Map<String, Repository> repositories, final String branchName) {
    final Map<String, Module> authorizedModules = new HashMap<>();
    for (final Repository repository : repositories.values()) {
        if (containsBranch(repository.getBranches(), branchName)) {
            final Module module = projectService.resolveProject(repository).getMainModule();
            authorizedModules.put(module.getModuleName(), module);
        }
    }
    return authorizedModules;
}
Also used : Repository(org.guvnor.structure.repositories.Repository) HashMap(java.util.HashMap) Module(org.guvnor.common.services.project.model.Module)

Example 42 with Repository

use of org.guvnor.structure.repositories.Repository 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 43 with Repository

use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.

the class SocialEventModuleConstraintTest method hasNoRestrictionsTest.

@Test
public void hasNoRestrictionsTest() throws Exception {
    final WorkspaceProject project = mock(WorkspaceProject.class);
    Repository repository = mock(Repository.class);
    doReturn(repository).when(project).getRepository();
    when(authorizationManager.authorize(repository, user)).thenReturn(true);
    eventProject = project;
    final SocialActivitiesEvent vfsEvent = new SocialActivitiesEvent(socialUser, "type", new Date());
    final SocialActivitiesEvent moduleEvent = new SocialActivitiesEvent(socialUser, OrganizationalUnitEventType.NEW_ORGANIZATIONAL_UNIT, new Date()).withLink("otherName", "otherName", SocialActivitiesEvent.LINK_TYPE.CUSTOM);
    socialEventModuleConstraint.init();
    assertFalse(socialEventModuleConstraint.hasRestrictions(vfsEvent));
    assertFalse(socialEventModuleConstraint.hasRestrictions(moduleEvent));
}
Also used : Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) SocialActivitiesEvent(org.ext.uberfire.social.activities.model.SocialActivitiesEvent) Date(java.util.Date) Test(org.junit.Test)

Example 44 with Repository

use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.

the class ModuleSaverTest method runProjecCreationTest.

protected void runProjecCreationTest(final POM pom) throws IOException {
    final Repository repository = mock(Repository.class);
    final String baseURL = "/";
    final File test = File.createTempFile("test", Long.toString(System.nanoTime()));
    final Path repositoryRootPath = paths.convert(fs.getPath(test.toURI()));
    when(repository.getDefaultBranch()).thenReturn(Optional.of(new Branch("master", repositoryRootPath)));
    when(pomService.load(any(Path.class))).thenReturn(pom);
    final ArrayList<String> directories = new ArrayList<String>();
    when(resourceResolver.simpleModuleInstance(any(org.uberfire.java.nio.file.Path.class))).thenReturn(mock(KieModule.class));
    final KieModule kieModule = new KieModule();
    kieModule.setPom(pom);
    when(resourceResolver.resolveModule(any(Path.class))).thenReturn(kieModule);
    stub(ioService.createDirectory(any(org.uberfire.java.nio.file.Path.class))).toAnswer(new Answer<org.uberfire.java.nio.file.Path>() {

        @Override
        public org.uberfire.java.nio.file.Path answer(final InvocationOnMock invocationOnMock) throws Throwable {
            org.uberfire.java.nio.file.Path path = (org.uberfire.java.nio.file.Path) invocationOnMock.getArguments()[0];
            directories.add(path.toString());
            return null;
        }
    });
    Module module = saver.save(repositoryRootPath, pom, baseURL);
    assertEquals(4, directories.size());
    assertTrue(directories.add("src/main/java"));
    assertTrue(directories.add("src/main/resources"));
    assertTrue(directories.add("src/test/resources"));
    assertTrue(directories.add("src/main/java"));
    assertEquals(pom, module.getPom());
}
Also used : Path(org.uberfire.backend.vfs.Path) ArrayList(java.util.ArrayList) Repository(org.guvnor.structure.repositories.Repository) Branch(org.guvnor.structure.repositories.Branch) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Module(org.guvnor.common.services.project.model.Module) KieModule(org.kie.workbench.common.services.shared.project.KieModule) File(java.io.File) KieModule(org.kie.workbench.common.services.shared.project.KieModule)

Example 45 with Repository

use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.

the class ModuleServiceImplNewModuleTest method testNewModuleCreationClashingGAVForced.

@Test()
public void testNewModuleCreationClashingGAVForced() throws URISyntaxException {
    final Repository repository = mock(Repository.class);
    final Path masterBranchRoot = mock(Path.class);
    doReturn(Optional.of(new Branch("master", masterBranchRoot))).when(repository).getDefaultBranch();
    final POM pom = new POM();
    final String baseURL = "/";
    final KieModule expected = new KieModule();
    when(moduleRepositoryResolver.getRepositoriesResolvingArtifact(eq(pom.getGav()))).thenReturn(new HashSet<MavenRepositoryMetadata>() {

        {
            add(new MavenRepositoryMetadata("id", "url", MavenRepositorySource.SETTINGS));
        }
    });
    when(saver.save(masterBranchRoot, pom, baseURL)).thenReturn(expected);
    try {
        moduleService.newModule(masterBranchRoot, pom, baseURL, DeploymentMode.FORCED);
    } catch (GAVAlreadyExistsException e) {
        fail("Unexpected exception thrown: " + e.getMessage());
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) Repository(org.guvnor.structure.repositories.Repository) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) Branch(org.guvnor.structure.repositories.Branch) KieModule(org.kie.workbench.common.services.shared.project.KieModule) POM(org.guvnor.common.services.project.model.POM) Test(org.junit.Test)

Aggregations

Repository (org.guvnor.structure.repositories.Repository)51 Test (org.junit.Test)25 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)21 Branch (org.guvnor.structure.repositories.Branch)21 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)20 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)15 Module (org.guvnor.common.services.project.model.Module)14 ArrayList (java.util.ArrayList)13 Path (org.uberfire.backend.vfs.Path)13 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)10 POM (org.guvnor.common.services.project.model.POM)7 KieModule (org.kie.workbench.common.services.shared.project.KieModule)7 ExampleOrganizationalUnit (org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit)5 HashMap (java.util.HashMap)4 MavenRepositoryMetadata (org.guvnor.common.services.project.model.MavenRepositoryMetadata)4 Before (org.junit.Before)4 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)3 RepositoryEnvironmentConfigurations (org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations)3 ConfigGroup (org.guvnor.structure.server.config.ConfigGroup)3 Space (org.uberfire.spaces.Space)3