Search in sources :

Example 1 with ExampleOrganizationalUnit

use of org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit 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 2 with ExampleOrganizationalUnit

use of org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit in project kie-wb-common by kiegroup.

the class ExamplesWizardTest method testSetDefaultTargetOrganizationalUnit.

@Test
public void testSetDefaultTargetOrganizationalUnit() {
    wizard.setDefaultTargetOrganizationalUnit("testOU");
    ExampleOrganizationalUnit targetOrganizationalUnit = wizard.getModel().getTargetOrganizationalUnit();
    assertNotNull(targetOrganizationalUnit);
    assertEquals("testOU", targetOrganizationalUnit.getName());
}
Also used : ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) Test(org.junit.Test)

Example 3 with ExampleOrganizationalUnit

use of org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit in project kie-wb-common by kiegroup.

the class LibraryServiceImpl method importProject.

@Override
public WorkspaceProject importProject(final OrganizationalUnit organizationalUnit, final ExampleProject exampleProject) {
    final ExampleOrganizationalUnit exampleOrganizationalUnit = new ExampleOrganizationalUnit(organizationalUnit.getName());
    final List<ExampleProject> exampleProjects = Collections.singletonList(exampleProject);
    final WorkspaceProjectContextChangeEvent projectContextChangeEvent = examplesService.setupExamples(exampleOrganizationalUnit, exampleProjects);
    return projectContextChangeEvent.getWorkspaceProject();
}
Also used : 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)

Example 4 with ExampleOrganizationalUnit

use of org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit in project kie-wb-common by kiegroup.

the class LibraryServiceImplTest method importDefaultProjectTest.

@Test
public void importDefaultProjectTest() {
    final Repository repository = mock(Repository.class);
    when(repository.getAlias()).thenReturn("example");
    final OrganizationalUnit organizationalUnit = mock(OrganizationalUnit.class);
    when(organizationalUnit.getName()).thenReturn("ou");
    when(organizationalUnit.getIdentifier()).thenReturn("ou");
    when(organizationalUnit.getRepositories()).thenReturn(singletonList(repository));
    when(ouService.getOrganizationalUnits()).thenReturn(singletonList(organizationalUnit));
    final ExampleProject exampleProject = mock(ExampleProject.class);
    doReturn("example").when(exampleProject).getName();
    final WorkspaceProject project = mock(WorkspaceProject.class);
    final Module module = mock(Module.class);
    doReturn(module).when(project).getMainModule();
    final WorkspaceProjectContextChangeEvent projectContextChangeEvent = mock(WorkspaceProjectContextChangeEvent.class);
    doReturn(project).when(projectContextChangeEvent).getWorkspaceProject();
    doReturn(projectContextChangeEvent).when(examplesService).setupExamples(any(ExampleOrganizationalUnit.class), anyList());
    final WorkspaceProject importedProject = libraryService.importProject(organizationalUnit, exampleProject);
    assertEquals(module, importedProject.getMainModule());
    verify(examplesService).setupExamples(new ExampleOrganizationalUnit(organizationalUnit.getName()), singletonList(exampleProject));
}
Also used : 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) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) Module(org.guvnor.common.services.project.model.Module) ExampleProject(org.kie.workbench.common.screens.examples.model.ExampleProject) Test(org.junit.Test)

Example 5 with ExampleOrganizationalUnit

use of org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit in project kie-wb-common by kiegroup.

the class ExamplesServiceImplTest method testSetupExamples_ProjectCopy.

@Test
public void testSetupExamples_ProjectCopy() {
    final ExampleOrganizationalUnit exOU = mock(ExampleOrganizationalUnit.class);
    final ImportProject exProject1 = mock(ImportProject.class);
    doReturn("project 1").when(exProject1).getName();
    final ImportProject exProject2 = mock(ImportProject.class);
    doReturn("project 2").when(exProject1).getName();
    final List<ImportProject> exProjects = Arrays.asList(exProject1, exProject2);
    final GitRepository repository1 = mock(GitRepository.class);
    final Path repositoryRoot = mock(Path.class);
    final Path module1Root = mock(Path.class);
    final Path module2Root = mock(Path.class);
    when(exOU.getName()).thenReturn("ou");
    when(exProject1.getName()).thenReturn("module1");
    when(exProject1.getRoot()).thenReturn(module1Root);
    when(exProject2.getName()).thenReturn("module2");
    when(exProject2.getRoot()).thenReturn(module2Root);
    when(repository1.getBranch("dev_branch")).thenReturn(Optional.of(new Branch("dev_branch", repositoryRoot)));
    final Optional<Branch> main = Optional.of(new Branch("main", PathFactory.newPath("testFile", "file:///")));
    when(repository1.getDefaultBranch()).thenReturn(main);
    when(repositoryRoot.toURI()).thenReturn("default:///");
    when(module1Root.toURI()).thenReturn("default:///module1");
    when(module2Root.toURI()).thenReturn("default:///module2");
    when(ouService.getOrganizationalUnit(eq("ou"))).thenReturn(ou);
    final WorkspaceProject project = spy(new WorkspaceProject());
    doReturn(project).when(service).importProject(eq(ou), eq(exProject1));
    doReturn(project).when(service).importProject(eq(ou), eq(exProject2));
    doReturn("project").when(project).getName();
    doReturn(project).when(projectService).resolveProject(repository1);
    final WorkspaceProjectContextChangeEvent event = service.setupExamples(exOU, exProjects);
    assertNull(event.getWorkspaceProject());
    assertEquals(ou, event.getOrganizationalUnit());
    verify(ouService, never()).createOrganizationalUnit(eq("ou"), eq(""));
    verify(service, times(2)).importProject(eq(ou), Mockito.<ImportProject>any());
    verify(newProjectEvent, times(2)).fire(Mockito.<NewProjectEvent>any());
}
Also used : Path(org.uberfire.backend.vfs.Path) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) ImportUtils.makeGitRepository(org.kie.workbench.common.screens.examples.backend.server.ImportUtils.makeGitRepository) ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) Branch(org.guvnor.structure.repositories.Branch) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) Test(org.junit.Test)

Aggregations

ExampleOrganizationalUnit (org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit)8 WorkspaceProjectContextChangeEvent (org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent)5 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)4 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)4 Test (org.junit.Test)4 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)3 ExampleProject (org.kie.workbench.common.screens.examples.model.ExampleProject)3 Branch (org.guvnor.structure.repositories.Branch)2 Repository (org.guvnor.structure.repositories.Repository)2 ImportUtils.makeGitRepository (org.kie.workbench.common.screens.examples.backend.server.ImportUtils.makeGitRepository)2 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)2 ImportProject (org.kie.workbench.common.screens.examples.model.ImportProject)2 Path (org.uberfire.backend.vfs.Path)2 NewProjectEvent (org.guvnor.common.services.project.events.NewProjectEvent)1 Module (org.guvnor.common.services.project.model.Module)1 IOException (org.uberfire.java.nio.IOException)1