Search in sources :

Example 16 with Package

use of org.guvnor.common.services.project.model.Package in project drools-wb by kiegroup.

the class NewGuidedDecisionTableHandlerTest method testCreate_WithoutWizard.

@Test
public void testCreate_WithoutWizard() {
    final String fileName = "fileName";
    final Package pkg = mock(Package.class);
    final Path resourcesPath = PathFactory.newPath("resources", "default://project/src/main/resources");
    when(pkg.getPackageMainResourcesPath()).thenReturn(resourcesPath);
    when(options.isUsingWizard()).thenReturn(false);
    handler.create(pkg, fileName, newResourcePresenter);
    verify(busyIndicatorView, times(1)).hideBusyIndicator();
    verify(newResourcePresenter, times(1)).complete();
    verify(mockNotificationEvent, times(1)).fire(any(NotificationEvent.class));
    verify(newResourceSuccessEventMock, times(1)).fire(any(NewResourceSuccessEvent.class));
    verify(placeManager, times(1)).goTo(pathCaptor.capture());
    assertEquals("default://project/src/main/resources/fileName.gdst", pathCaptor.getValue().toURI());
    verify(service, times(1)).create(eq(resourcesPath), eq(fileName + "." + resourceType.getSuffix()), any(GuidedDecisionTable52.class), any(String.class));
}
Also used : Path(org.uberfire.backend.vfs.Path) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) Package(org.guvnor.common.services.project.model.Package) NewResourceSuccessEvent(org.kie.workbench.common.widgets.client.handlers.NewResourceSuccessEvent) Test(org.junit.Test)

Example 17 with Package

use of org.guvnor.common.services.project.model.Package in project drools-wb by kiegroup.

the class NewGuidedDecisionTableHandlerTest method testCreate_WithWizard.

@Test
public void testCreate_WithWizard() {
    final String fileName = "fileName";
    final Package pkg = mock(Package.class);
    final Path resourcesPath = PathFactory.newPath("resources", "default://project/src/main/resources");
    when(pkg.getPackageMainResourcesPath()).thenReturn(resourcesPath);
    when(options.isUsingWizard()).thenReturn(true);
    when(options.getTableFormat()).thenReturn(TableFormat.EXTENDED_ENTRY);
    when(options.getHitPolicy()).thenReturn(GuidedDecisionTable52.HitPolicy.FIRST_HIT);
    handler.create(pkg, fileName, newResourcePresenter);
    verify(wizardBean, times(1)).setContent(pathCaptor.capture(), fileNameCaptor.capture(), eq(TableFormat.EXTENDED_ENTRY), eq(GuidedDecisionTable52.HitPolicy.FIRST_HIT), any(AsyncPackageDataModelOracle.class), any(NewGuidedDecisionTableWizard.GuidedDecisionTableWizardHandler.class));
}
Also used : Path(org.uberfire.backend.vfs.Path) AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) Package(org.guvnor.common.services.project.model.Package) Test(org.junit.Test)

Example 18 with Package

use of org.guvnor.common.services.project.model.Package in project drools-wb by kiegroup.

the class NewGuidedDecisionTableGraphHandlerTest method testCreate.

@Test
public void testCreate() {
    final String fileName = "fileName";
    final Package pkg = mock(Package.class);
    final Path resourcesPath = PathFactory.newPath("resources", "default://project/src/main/resources");
    when(pkg.getPackageMainResourcesPath()).thenReturn(resourcesPath);
    handler.create(pkg, fileName, newResourcePresenter);
    verify(busyIndicatorView, times(1)).hideBusyIndicator();
    verify(newResourcePresenter, times(1)).complete();
    verify(mockNotificationEvent, times(1)).fire(any(NotificationEvent.class));
    verify(newResourceSuccessEventMock, times(1)).fire(any(NewResourceSuccessEvent.class));
    verify(placeManager, times(1)).goTo(pathCaptor.capture());
    assertEquals("default://project/src/main/resources/fileName." + resourceType.getSuffix(), pathCaptor.getValue().toURI());
    verify(service, times(1)).create(eq(resourcesPath), eq(fileName + "." + resourceType.getSuffix()), any(GuidedDecisionTableEditorGraphModel.class), any(String.class));
}
Also used : Path(org.uberfire.backend.vfs.Path) GuidedDecisionTableEditorGraphModel(org.drools.workbench.screens.guided.dtable.model.GuidedDecisionTableEditorGraphModel) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) Package(org.guvnor.common.services.project.model.Package) NewResourceSuccessEvent(org.kie.workbench.common.widgets.client.handlers.NewResourceSuccessEvent) Test(org.junit.Test)

Example 19 with Package

use of org.guvnor.common.services.project.model.Package in project drools-wb by kiegroup.

the class GuidedDecisionTableEditorServiceImpl method create.

@Override
public Path create(final Path context, final String fileName, final GuidedDecisionTable52 content, final String comment) {
    try {
        final Package pkg = moduleService.resolvePackage(context);
        final String packageName = (pkg == null ? null : pkg.getPackageName());
        content.setPackageName(packageName);
        final org.uberfire.java.nio.file.Path nioPath = Paths.convert(context).resolve(fileName);
        final Path newPath = Paths.convert(nioPath);
        if (ioService.exists(nioPath)) {
            throw new FileAlreadyExistsException(nioPath.toString());
        }
        ioService.write(nioPath, GuidedDTXMLPersistence.getInstance().marshal(content), commentedOptionFactory.makeCommentedOption(comment));
        return newPath;
    } catch (Exception e) {
        throw ExceptionUtilities.handleException(e);
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) Package(org.guvnor.common.services.project.model.Package) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 20 with Package

use of org.guvnor.common.services.project.model.Package in project drools-wb by kiegroup.

the class GuidedDecisionTableGraphEditorServiceImpl method listDecisionTablesInPackage.

@Override
public List<Path> listDecisionTablesInPackage(final Path path) {
    try {
        final Package pkg = moduleService.resolvePackage(path);
        if (pkg == null) {
            return Collections.emptyList();
        }
        final Path pkgPath = pkg.getPackageMainResourcesPath();
        final org.uberfire.java.nio.file.Path nioPkgPath = Paths.convert(pkgPath);
        final List<Path> paths = findDecisionTables(nioPkgPath);
        return paths;
    } catch (Exception e) {
        throw ExceptionUtilities.handleException(e);
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) Package(org.guvnor.common.services.project.model.Package) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Aggregations

Package (org.guvnor.common.services.project.model.Package)30 Path (org.uberfire.backend.vfs.Path)19 FileAlreadyExistsException (org.uberfire.java.nio.file.FileAlreadyExistsException)15 Test (org.junit.Test)13 NotificationEvent (org.uberfire.workbench.events.NotificationEvent)10 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)7 NewResourceSuccessEvent (org.kie.workbench.common.widgets.client.handlers.NewResourceSuccessEvent)7 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)3 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)2 Module (org.guvnor.common.services.project.model.Module)2 DefaultIndexBuilder (org.kie.workbench.common.services.refactoring.backend.server.indexing.DefaultIndexBuilder)2 SourceGenerationFailedException (org.kie.workbench.common.services.shared.source.SourceGenerationFailedException)2 HashMap (java.util.HashMap)1 MetadataCol52 (org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52)1 GuidedDecisionTableEditorGraphModel (org.drools.workbench.screens.guided.dtable.model.GuidedDecisionTableEditorGraphModel)1 InvalidateDMOPackageCacheEvent (org.guvnor.common.services.project.builder.events.InvalidateDMOPackageCacheEvent)1 Import (org.kie.soup.project.datamodel.imports.Import)1 Imports (org.kie.soup.project.datamodel.imports.Imports)1 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)1 HasPackageName (org.kie.soup.project.datamodel.packages.HasPackageName)1