Search in sources :

Example 6 with GlobalsModel

use of org.drools.workbench.screens.globals.model.GlobalsModel in project drools-wb by kiegroup.

the class DecisionTableXLSToDecisionTableGuidedConverter method createNewGlobals.

private void createNewGlobals(final Path context, final List<Import> imports, final List<Global> globals, final ConversionResult result) {
    if (globals == null || globals.isEmpty()) {
        return;
    }
    // Create new asset for Globals. All Globals can be in one file.
    final String assetName = makeNewAssetName("Global", globalsType);
    final GlobalsModel model = makeGlobalsModel(imports, globals, result);
    globalsService.create(context, assetName, model, "Converted from XLS Decision Table");
    result.addMessage("Created Globals '" + assetName + "'", ConversionMessageType.INFO);
}
Also used : GlobalsModel(org.drools.workbench.screens.globals.model.GlobalsModel)

Example 7 with GlobalsModel

use of org.drools.workbench.screens.globals.model.GlobalsModel in project drools-wb by kiegroup.

the class NewGlobalHandler method create.

@Override
public void create(final Package pkg, final String baseFileName, final NewResourcePresenter presenter) {
    final GlobalsModel model = new GlobalsModel();
    busyIndicatorView.showBusyIndicator(CommonConstants.INSTANCE.Saving());
    globalsService.call(getSuccessCallback(presenter), new HasBusyIndicatorDefaultErrorCallback(busyIndicatorView)).create(pkg.getPackageMainResourcesPath(), buildFileName(baseFileName, resourceType), model, "");
}
Also used : GlobalsModel(org.drools.workbench.screens.globals.model.GlobalsModel) HasBusyIndicatorDefaultErrorCallback(org.uberfire.ext.widgets.common.client.callbacks.HasBusyIndicatorDefaultErrorCallback)

Example 8 with GlobalsModel

use of org.drools.workbench.screens.globals.model.GlobalsModel in project drools-wb by kiegroup.

the class GlobalsPersistence method unmarshal.

public GlobalsModel unmarshal(final String content) {
    // De-serialize model
    final List<Pair<String, String>> parsedGlobalsContent = GlobalsParser.parseGlobals(content);
    final List<Global> globals = makeGlobals(parsedGlobalsContent);
    final GlobalsModel model = new GlobalsModel();
    model.setGlobals(globals);
    // De-serialize Package name
    final String packageName = PackageNameParser.parsePackageName(content);
    model.setPackageName(packageName);
    return model;
}
Also used : GlobalsModel(org.drools.workbench.screens.globals.model.GlobalsModel) Global(org.drools.workbench.screens.globals.model.Global) Pair(org.uberfire.commons.data.Pair)

Example 9 with GlobalsModel

use of org.drools.workbench.screens.globals.model.GlobalsModel in project drools-wb by kiegroup.

the class GlobalsEditorServiceTest method save.

@Test
public void save() {
    Path path = PathFactory.newPath("test", "file:///test");
    GlobalsModel globalsModel = mock(GlobalsModel.class);
    when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(false);
    globalsEditorService.create(path, "test", globalsModel, "comment");
    verify(ioService, times(1)).write(any(org.uberfire.java.nio.file.Path.class), anyString(), any(CommentedOption.class));
}
Also used : Path(org.uberfire.backend.vfs.Path) GlobalsModel(org.drools.workbench.screens.globals.model.GlobalsModel) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) Test(org.junit.Test)

Example 10 with GlobalsModel

use of org.drools.workbench.screens.globals.model.GlobalsModel in project drools-wb by kiegroup.

the class GlobalsEditorServiceTest method generate.

@Test
public void generate() {
    Path path = PathFactory.newPath("test", "file:///test");
    GlobalsModel globalsModel = mock(GlobalsModel.class);
    when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(false);
    Map<String, Object> metadataMap = new HashMap<String, Object>() {

        {
            put(GeneratedAttributesView.GENERATED_ATTRIBUTE_NAME, true);
        }
    };
    when(metadataService.configAttrs(anyMapOf(String.class, Object.class), any(Metadata.class))).thenReturn(metadataMap);
    globalsEditorService.generate(path, "test", globalsModel, "comment");
    ArgumentCaptor<Map> mapArgumentCaptor = ArgumentCaptor.forClass(Map.class);
    verify(ioService, times(1)).write(any(org.uberfire.java.nio.file.Path.class), anyString(), mapArgumentCaptor.capture(), any(CommentedOption.class));
    Map capturedMap = mapArgumentCaptor.getValue();
    assertEquals(metadataMap, capturedMap);
    Object generatedAttribute = capturedMap.get(GeneratedAttributesView.GENERATED_ATTRIBUTE_NAME);
    assertNotNull(generatedAttribute);
    assertTrue(Boolean.parseBoolean(generatedAttribute.toString()));
}
Also used : Path(org.uberfire.backend.vfs.Path) GlobalsModel(org.drools.workbench.screens.globals.model.GlobalsModel) HashMap(java.util.HashMap) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) Matchers.anyString(org.mockito.Matchers.anyString) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

GlobalsModel (org.drools.workbench.screens.globals.model.GlobalsModel)12 Test (org.junit.Test)7 Path (org.uberfire.backend.vfs.Path)5 Global (org.drools.workbench.screens.globals.model.Global)3 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)3 GlobalsEditorContent (org.drools.workbench.screens.globals.model.GlobalsEditorContent)2 Matchers.anyString (org.mockito.Matchers.anyString)2 CommentedOption (org.uberfire.java.nio.base.options.CommentedOption)2 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Global (org.drools.template.model.Global)1 Import (org.drools.template.model.Import)1 ConversionResult (org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult)1 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)1 Overview (org.guvnor.common.services.shared.metadata.model.Overview)1 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)1 ObservablePath (org.uberfire.backend.vfs.ObservablePath)1 Pair (org.uberfire.commons.data.Pair)1 HasBusyIndicatorDefaultErrorCallback (org.uberfire.ext.widgets.common.client.callbacks.HasBusyIndicatorDefaultErrorCallback)1