Search in sources :

Example 16 with WorkspaceProject

use of org.guvnor.common.services.project.model.WorkspaceProject in project kie-wb-common by kiegroup.

the class ContributorsManagerTest method makeProject.

private WorkspaceProject makeProject(final Repository repository, final OrganizationalUnit organizationalUnit, final String moduleName) throws IOException {
    final Module module = mock(Module.class);
    when(module.getModuleName()).thenReturn(moduleName);
    return new WorkspaceProject(organizationalUnit, repository, new Branch("master", PathFactory.newPath("testFile", "file:///" + moduleName)), module);
}
Also used : WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Branch(org.guvnor.structure.repositories.Branch) Module(org.guvnor.common.services.project.model.Module)

Example 17 with WorkspaceProject

use of org.guvnor.common.services.project.model.WorkspaceProject in project kie-wb-common by kiegroup.

the class ExamplesServiceImpl method setupExamples.

@Override
public WorkspaceProjectContextChangeEvent setupExamples(final ExampleOrganizationalUnit exampleTargetOU, final List<ExampleProject> exampleProjects) {
    PortablePreconditions.checkNotNull("exampleTargetOU", exampleTargetOU);
    PortablePreconditions.checkNotNull("exampleProjects", exampleProjects);
    PortablePreconditions.checkCondition("Must have at least one ExampleProject", exampleProjects.size() > 0);
    // Retrieve or create Organizational Unit
    final String targetOUName = exampleTargetOU.getName();
    final OrganizationalUnit targetOU = getOrganizationalUnit(targetOUName);
    WorkspaceProject firstExampleProject = null;
    for (final ExampleProject exampleProject : exampleProjects) {
        try {
            final Repository targetRepository = repositoryCopier.copy(targetOU, exampleProject.getName(), exampleProject.getRoot());
            // Signal creation of new Project (Creation of OU and Repository, if applicable,
            // are already handled in the corresponding services).
            WorkspaceProject project = projectService.resolveProject(targetRepository);
            project = renameIfNecessary(targetOU, project);
            newProjectEvent.fire(new NewProjectEvent(project));
            // Store first new example project
            if (firstExampleProject == null) {
                firstExampleProject = project;
            }
        } catch (IOException ioe) {
            logger.error("Unable to create Example(s).", ioe);
        }
    }
    return new WorkspaceProjectContextChangeEvent(firstExampleProject, firstExampleProject.getMainModule());
}
Also used : NewProjectEvent(org.guvnor.common.services.project.events.NewProjectEvent) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) IOException(org.uberfire.java.nio.IOException) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) ExampleProject(org.kie.workbench.common.screens.examples.model.ExampleProject)

Example 18 with WorkspaceProject

use of org.guvnor.common.services.project.model.WorkspaceProject in project kie-wb-common by kiegroup.

the class ExamplesServiceImpl method renameIfNecessary.

private WorkspaceProject renameIfNecessary(final OrganizationalUnit ou, final WorkspaceProject project) {
    String name = project.getName();
    Collection<WorkspaceProject> projectsWithSameName = projectService.getAllWorkspaceProjectsByName(ou, name);
    if (projectsWithSameName.size() > 1) {
        name = this.projectService.createFreshProjectName(ou, project.getName());
    }
    if (!name.equals(project.getName())) {
        final Path pomXMLPath = project.getMainModule().getPomXMLPath();
        final ProjectScreenModel model = projectScreenService.load(pomXMLPath);
        model.getPOM().setName(name);
        projectScreenService.save(pomXMLPath, model, "");
        return projectService.resolveProject(pomXMLPath);
    }
    return project;
}
Also used : Path(org.uberfire.backend.vfs.Path) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel)

Example 19 with WorkspaceProject

use of org.guvnor.common.services.project.model.WorkspaceProject in project kie-wb-common by kiegroup.

the class ExamplesServiceImplRepositoryNamesTest method nameIsTaken.

@Test
public void nameIsTaken() {
    String module1 = "module1";
    String module1_1 = "module1 [1]";
    doReturn(mock(Repository.class)).when(repositoryService).getRepositoryFromSpace(any(Space.class), eq(module1));
    WorkspaceProject project1 = mock(WorkspaceProject.class);
    doReturn(module1).when(project1).getName();
    List<WorkspaceProject> projects = new ArrayList<>();
    projects.add(project1);
    projects.add(project1);
    doReturn(projects).when(projectService).getAllWorkspaceProjectsByName(any(), eq(module1));
    doReturn(module1_1).when(projectService).createFreshProjectName(any(), eq(module1));
    service.setupExamples(exampleOrganizationalUnit, exampleProjects);
    verify(projectScreenService).save(any(), modelCapture.capture(), any());
    final ProjectScreenModel model = modelCapture.getValue();
    assertEquals(module1_1, model.getPOM().getName());
}
Also used : Space(org.uberfire.spaces.Space) Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) Test(org.junit.Test)

Example 20 with WorkspaceProject

use of org.guvnor.common.services.project.model.WorkspaceProject in project kie-wb-common by kiegroup.

the class ExamplesServiceImplTest method testSetupExamples_NewOrganizationalUnitNewRepository.

@Test
public void testSetupExamples_NewOrganizationalUnitNewRepository() {
    final ExampleOrganizationalUnit exOU = mock(ExampleOrganizationalUnit.class);
    final ExampleProject exModule = mock(ExampleProject.class);
    doReturn("module").when(exModule).getName();
    final List<ExampleProject> exModules = new ArrayList<ExampleProject>() {

        {
            add(exModule);
        }
    };
    final OrganizationalUnit ou = mock(OrganizationalUnit.class);
    doReturn("ou").when(ou).getName();
    final GitRepository repository = mock(GitRepository.class);
    final Path repositoryRoot = mock(Path.class);
    final Path moduleRoot = mock(Path.class);
    when(exOU.getName()).thenReturn("ou");
    when(exModule.getName()).thenReturn("module");
    when(exModule.getRoot()).thenReturn(moduleRoot);
    when(repository.getDefaultBranch()).thenReturn(Optional.of(new Branch("master", repositoryRoot)));
    when(repositoryRoot.toURI()).thenReturn("default:///");
    when(moduleRoot.toURI()).thenReturn("default:///module");
    when(ouService.getOrganizationalUnit(eq("ou"))).thenReturn(null);
    when(ouService.createOrganizationalUnit(eq("ou"), eq(""), eq(""))).thenReturn(ou);
    when(repositoryCopier.copy(eq(ou), anyString(), eq(moduleRoot))).thenReturn(repository);
    final WorkspaceProject project = spy(new WorkspaceProject());
    doReturn("project").when(project).getName();
    doReturn(project).when(projectService).resolveProject(repository);
    final WorkspaceProjectContextChangeEvent event = service.setupExamples(exOU, exModules);
    assertNull(event.getOrganizationalUnit());
    assertEquals(project, event.getWorkspaceProject());
    verify(ouService, times(1)).createOrganizationalUnit(eq("ou"), eq(""), eq(""));
    verify(repositoryCopier, times(1)).copy(eq(ou), anyString(), eq(moduleRoot));
    verify(newProjectEvent, times(1)).fire(any(NewProjectEvent.class));
}
Also used : Path(org.uberfire.backend.vfs.Path) NewProjectEvent(org.guvnor.common.services.project.events.NewProjectEvent) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) Branch(org.guvnor.structure.repositories.Branch) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ArrayList(java.util.ArrayList) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) ExampleProject(org.kie.workbench.common.screens.examples.model.ExampleProject) Test(org.junit.Test)

Aggregations

WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)67 Test (org.junit.Test)42 Branch (org.guvnor.structure.repositories.Branch)29 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)28 Repository (org.guvnor.structure.repositories.Repository)26 Path (org.uberfire.backend.vfs.Path)26 Module (org.guvnor.common.services.project.model.Module)21 ArrayList (java.util.ArrayList)12 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)12 WorkspaceProjectContextChangeEvent (org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent)10 ExampleOrganizationalUnit (org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit)9 Before (org.junit.Before)8 KieModule (org.kie.workbench.common.services.shared.project.KieModule)7 POM (org.guvnor.common.services.project.model.POM)6 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)5 ProjectAssetsQuery (org.kie.workbench.common.screens.library.api.ProjectAssetsQuery)5 ProjectScreenModel (org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel)5 Date (java.util.Date)4 HashSet (java.util.HashSet)4 ExampleProject (org.kie.workbench.common.screens.examples.model.ExampleProject)4