use of org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent 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 ExampleProject exProject1 = mock(ExampleProject.class);
doReturn("project 1").when(exProject1).getName();
final ExampleProject exProject2 = mock(ExampleProject.class);
doReturn("project 2").when(exProject1).getName();
final List<ExampleProject> exProjects = new ArrayList<ExampleProject>() {
{
add(exProject1);
add(exProject2);
}
};
final OrganizationalUnit ou = mock(OrganizationalUnit.class);
doReturn("ou").when(ou).getName();
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> master = Optional.of(new Branch("master", PathFactory.newPath("testFile", "file:///")));
when(repository1.getDefaultBranch()).thenReturn(master);
when(repositoryRoot.toURI()).thenReturn("default:///");
when(module1Root.toURI()).thenReturn("default:///module1");
when(module2Root.toURI()).thenReturn("default:///module2");
when(ouService.getOrganizationalUnit(eq("ou"))).thenReturn(ou);
doReturn(repository1).when(repositoryCopier).copy(eq(ou), anyString(), eq(module1Root));
doReturn(repository1).when(repositoryCopier).copy(eq(ou), anyString(), eq(module2Root));
final WorkspaceProject project = spy(new WorkspaceProject());
doReturn("project").when(project).getName();
doReturn(project).when(projectService).resolveProject(repository1);
final WorkspaceProjectContextChangeEvent event = service.setupExamples(exOU, exProjects);
assertNull(event.getOrganizationalUnit());
assertEquals(project, event.getWorkspaceProject());
verify(ouService, never()).createOrganizationalUnit(eq("ou"), eq(""), eq(""));
verify(repositoryCopier, times(2)).copy(eq(ou), anyString(), any(Path.class));
verify(newProjectEvent, times(2)).fire(any(NewProjectEvent.class));
}
use of org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent in project kie-wb-common by kiegroup.
the class LibraryPlaces method goToOrganizationalUnits.
public void goToOrganizationalUnits() {
if (closeAllPlacesOrNothing()) {
PortablePreconditions.checkNotNull("libraryPerspective.closeAllPlacesOrNothing", libraryPerspective);
projectContextChangeEvent.fire(new WorkspaceProjectContextChangeEvent());
final DefaultPlaceRequest placeRequest = new DefaultPlaceRequest(LibraryPlaces.ORGANIZATIONAL_UNITS_SCREEN);
final PartDefinitionImpl part = new PartDefinitionImpl(placeRequest);
part.setSelectable(false);
placeManager.goTo(part, libraryPerspective.getRootPanel());
setupLibraryBreadCrumbs();
}
}
use of org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent in project kie-wb-common by kiegroup.
the class LibraryPlaces method setupLibraryPerspective.
private void setupLibraryPerspective() {
OrganizationalUnit activeOu = projectContext.getActiveOrganizationalUnit().orElseThrow(() -> new IllegalStateException("Cannot setup library perspective without active space."));
PortablePreconditions.checkNotNull("libraryPerspective", libraryPerspective);
final PlaceRequest placeRequest = new DefaultPlaceRequest(LibraryPlaces.LIBRARY_SCREEN);
final PartDefinitionImpl part = new PartDefinitionImpl(placeRequest);
part.setSelectable(false);
if (!projectContext.getActiveWorkspaceProject().isPresent()) {
projectContextChangeEvent.fire(new WorkspaceProjectContextChangeEvent(activeOu));
}
closeLibraryPlaces();
placeManager.goTo(part, libraryPerspective.getRootPanel());
setupLibraryBreadCrumbsWithoutProject();
hideDocks();
}
use of org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent in project kie-wb-common by kiegroup.
the class LibraryPlaces method goToAsset.
public void goToAsset(final Path path) {
moduleService.call(new RemoteCallback<org.guvnor.common.services.project.model.Package>() {
@Override
public void callback(final org.guvnor.common.services.project.model.Package response) {
projectContextChangeEvent.fire(new WorkspaceProjectContextChangeEvent(projectContext.getActiveWorkspaceProject().orElse(null), projectContext.getActiveModule().orElse(null), response));
final PlaceRequest placeRequest = generatePlaceRequest(path);
placeManager.goTo(placeRequest);
if (path != null) {
final ObservablePath observablePath = ((PathPlaceRequest) placeRequest).getPath();
observablePath.onRename(() -> setupLibraryBreadCrumbsForAsset(observablePath));
}
}
}).resolvePackage(path);
}
use of org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent in project kie-wb-common by kiegroup.
the class LibraryPlaces method openBestSuitedScreen.
private void openBestSuitedScreen(final String eventType, final Path path, final WorkspaceProject project) {
if (!projectContext.getActiveWorkspaceProject().map(active -> active.equals(project)).orElse(false)) {
projectContextChangeEvent.fire(new WorkspaceProjectContextChangeEvent(project, project.getMainModule()));
}
final PlaceRequest libraryPerspectivePlace = getLibraryPlaceRequestWithoutRefresh();
if (isRepositoryEvent(eventType)) {
placeManager.goTo(REPOSITORY_STRUCTURE_SCREEN);
} else if (isModuleEvent(eventType)) {
placeManager.goTo(libraryPerspectivePlace);
goToProject();
} else if (path != null) {
placeManager.goTo(libraryPerspectivePlace);
goToProject(() -> goToAsset(path));
}
}
Aggregations