Search in sources :

Example 21 with Package

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

the class GuidedDecisionTreeEditorServiceImpl method save.

@Override
public Path save(final Path resource, final GuidedDecisionTree model, final Metadata metadata, final String comment) {
    try {
        final Package pkg = moduleService.resolvePackage(resource);
        final String packageName = (pkg == null ? null : pkg.getPackageName());
        model.setPackageName(packageName);
        Metadata currentMetadata = metadataService.getMetadata(resource);
        ioService.write(Paths.convert(resource), GuidedDecisionTreeDRLPersistence.getInstance().marshal(model), metadataService.setUpAttributes(resource, metadata), commentedOptionFactory.makeCommentedOption(comment));
        fireMetadataSocialEvents(resource, currentMetadata, metadata);
        return resource;
    } catch (Exception e) {
        throw ExceptionUtilities.handleException(e);
    }
}
Also used : Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) Package(org.guvnor.common.services.project.model.Package) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 22 with Package

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

the class GuidedRuleTemplateEditorServiceImpl method save.

@Override
public Path save(final Path resource, final TemplateModel model, final Metadata metadata, final String comment) {
    try {
        final Package pkg = moduleService.resolvePackage(resource);
        final String packageName = (pkg == null ? null : pkg.getPackageName());
        model.setPackageName(packageName);
        Metadata currentMetadata = metadataService.getMetadata(resource);
        ioService.write(Paths.convert(resource), RuleTemplateModelXMLPersistenceImpl.getInstance().marshal(model), metadataService.setUpAttributes(resource, metadata), commentedOptionFactory.makeCommentedOption(comment));
        fireMetadataSocialEvents(resource, currentMetadata, metadata);
        return resource;
    } catch (Exception e) {
        throw ExceptionUtilities.handleException(e);
    }
}
Also used : Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) Package(org.guvnor.common.services.project.model.Package) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 23 with Package

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

the class NewScoreCardXLSHandlerTest method testSuccessMultiByteProjectNameAndFileName.

@Test
public void testSuccessMultiByteProjectNameAndFileName() {
    final String fileName = "あああ";
    final Package pkg = mock(Package.class);
    final Path resourcesPath = PathFactory.newPath("resources", "default://" + encode("ああ") + "/src/main/resources");
    when(pkg.getPackageMainResourcesPath()).thenReturn(resourcesPath);
    handler.create(pkg, fileName, newResourcePresenter);
    verify(uploadWidget, times(1)).submit(eq(resourcesPath), eq(fileName + "." + resourceType.getSuffix()), any(String.class), successCmdCaptor.capture(), failureCmdCaptor.capture());
    successCmdCaptor.getValue().execute();
    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(newPathCaptor.capture());
    assertEquals("default://%E3%81%82%E3%81%82/src/main/resources/%E3%81%82%E3%81%82%E3%81%82.sxls", newPathCaptor.getValue().toURI());
}
Also used : Path(org.uberfire.backend.vfs.Path) 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 24 with Package

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

the class ScenarioTestEditorServiceImpl method load.

@Override
public Scenario load(final Path path) {
    try {
        final String content = ioService.readAllString(Paths.convert(path));
        final Scenario scenario = ScenarioXMLPersistence.getInstance().unmarshal(content);
        scenario.setName(path.getFileName());
        return scenario;
    } catch (final Exception e) {
        logger.error("Unable to unmarshal content. Returning an empty Test Scenario.", e);
        final Package resolvedPackage = moduleService.resolvePackage(path);
        final Scenario scenario = new Scenario();
        if (resolvedPackage != null) {
            scenario.setPackageName(resolvedPackage.getPackageName());
        }
        scenario.setImports(new Imports());
        return scenario;
    }
}
Also used : Package(org.guvnor.common.services.project.model.Package) Imports(org.kie.soup.project.datamodel.imports.Imports) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario)

Example 25 with Package

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

the class ScenarioTestEditorServiceImplTest method loadBrokenScenario.

@Test
public void loadBrokenScenario() throws Exception {
    final Package pgk = mock(Package.class);
    when(pgk.getPackageName()).thenReturn("org.test");
    when(moduleService.resolvePackage(path)).thenReturn(pgk);
    final Scenario load = testEditorService.load(path);
    assertNotNull(load);
    assertEquals("org.test", load.getPackageName());
    assertNotNull(load.getImports());
}
Also used : Package(org.guvnor.common.services.project.model.Package) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) Test(org.junit.Test)

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