Search in sources :

Example 31 with PackageDataModelOracle

use of org.kie.soup.project.datamodel.oracle.PackageDataModelOracle in project drools-wb by kiegroup.

the class GuidedDecisionTreeEditorCopyHelper method postProcess.

@Override
public void postProcess(final Path source, final Path destination) {
    // Load existing file
    final org.uberfire.java.nio.file.Path _destination = Paths.convert(destination);
    final String drl = ioService.readAllString(Paths.convert(destination));
    final String baseFileName = FileNameUtil.removeExtension(source, resourceType);
    final PackageDataModelOracle oracle = dataModelService.getDataModel(source);
    final GuidedDecisionTree model = GuidedDecisionTreeDRLPersistence.getInstance().unmarshal(drl, baseFileName, oracle);
    // Update tree name
    final String treeName = FileNameUtil.removeExtension(destination, resourceType);
    model.setTreeName(treeName);
    // Save file
    ioService.write(_destination, GuidedDecisionTreeDRLPersistence.getInstance().marshal(model), commentedOptionFactory.makeCommentedOption("File [" + source.toURI() + "] copied to [" + destination.toURI() + "]."));
}
Also used : PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) GuidedDecisionTree(org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree)

Example 32 with PackageDataModelOracle

use of org.kie.soup.project.datamodel.oracle.PackageDataModelOracle in project drools-wb by kiegroup.

the class GuidedDecisionTreeEditorServiceImpl method loadDataModel.

@Override
public PackageDataModelOracleBaselinePayload loadDataModel(final Path path) {
    try {
        final PackageDataModelOracle oracle = dataModelService.getDataModel(path);
        final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
        // There are no classes to pre-load into the DMO when requesting a new Data Model only
        DataModelOracleUtilities.populateDataModel(oracle, dataModel, new HashSet<String>());
        return dataModel;
    } catch (Exception e) {
        throw ExceptionUtilities.handleException(e);
    }
}
Also used : PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 33 with PackageDataModelOracle

use of org.kie.soup.project.datamodel.oracle.PackageDataModelOracle in project drools-wb by kiegroup.

the class GuidedDecisionTreeEditorServiceImpl method constructContent.

@Override
protected GuidedDecisionTreeEditorContent constructContent(Path path, Overview overview) {
    final GuidedDecisionTree model = load(path);
    final PackageDataModelOracle oracle = dataModelService.getDataModel(path);
    final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
    // Get FQCN's used by model
    final GuidedDecisionTreeModelVisitor visitor = new GuidedDecisionTreeModelVisitor(model);
    final Set<String> consumedFQCNs = visitor.getConsumedModelClasses();
    // Get FQCN's used by Globals
    consumedFQCNs.addAll(oracle.getPackageGlobals().values());
    DataModelOracleUtilities.populateDataModel(oracle, dataModel, consumedFQCNs);
    // Signal opening to interested parties
    resourceOpenedEvent.fire(new ResourceOpenedEvent(path, safeSessionInfo));
    return new GuidedDecisionTreeEditorContent(model, overview, dataModel);
}
Also used : PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) GuidedDecisionTree(org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree) ResourceOpenedEvent(org.uberfire.workbench.events.ResourceOpenedEvent) GuidedDecisionTreeEditorContent(org.drools.workbench.screens.guided.dtree.model.GuidedDecisionTreeEditorContent)

Example 34 with PackageDataModelOracle

use of org.kie.soup.project.datamodel.oracle.PackageDataModelOracle in project drools-wb by kiegroup.

the class GuidedRuleEditorServiceImpl method load.

@Override
public RuleModel load(final Path path) {
    try {
        final String drl = ioService.readAllString(Paths.convert(path));
        final List<String> globals = utilities.loadGlobalsForPackage(path);
        final PackageDataModelOracle oracle = dataModelService.getDataModel(path);
        RuleModel ruleModel = null;
        if (dslrResourceType.accept(path)) {
            final String[] dsls = utilities.loadDslsForPackage(path);
            ruleModel = RuleModelDRLPersistenceImpl.getInstance().unmarshalUsingDSL(drl, globals, oracle, persistenceExtensions, dsls);
        } else {
            ruleModel = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, globals, oracle, persistenceExtensions);
        }
        return ruleModel;
    } catch (Exception e) {
        throw ExceptionUtilities.handleException(e);
    }
}
Also used : PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 35 with PackageDataModelOracle

use of org.kie.soup.project.datamodel.oracle.PackageDataModelOracle in project drools-wb by kiegroup.

the class GuidedRuleEditorServiceImplTest method checkConstructContentPopulateProjectCollectionTypesAndDSLSentences.

@Test
public void checkConstructContentPopulateProjectCollectionTypesAndDSLSentences() throws Exception {
    final Path path = mock(Path.class);
    final Overview overview = mock(Overview.class);
    final ModuleDataModelOracle projectDataModelOracle = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(List.class).addClass(Set.class).addClass(Collection.class).addClass(Integer.class).build();
    final PackageDataModelOracle oracle = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator()).setModuleOracle(projectDataModelOracle).addExtension(DSLActionSentence.INSTANCE, Collections.singletonList(dslSentence)).addExtension(DSLConditionSentence.INSTANCE, Collections.singletonList(dslSentence)).build();
    when(path.toURI()).thenReturn("default://project/src/main/resources/mypackage/rule.rdrl");
    when(dataModelService.getDataModel(any())).thenReturn(oracle);
    final GuidedEditorContent content = service.constructContent(path, overview);
    assertEquals(3, content.getDataModel().getCollectionTypes().size());
    assertTrue(content.getDataModel().getCollectionTypes().containsKey("java.util.Collection"));
    assertTrue(content.getDataModel().getCollectionTypes().containsKey("java.util.List"));
    assertTrue(content.getDataModel().getCollectionTypes().containsKey("java.util.Set"));
    assertTrue(content.getDataModel().getPackageElements(DSLActionSentence.INSTANCE).contains(dslSentence));
    assertTrue(content.getDataModel().getPackageElements(DSLConditionSentence.INSTANCE).contains(dslSentence));
}
Also used : Path(org.uberfire.backend.vfs.Path) Set(java.util.Set) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) GuidedEditorContent(org.drools.workbench.screens.guided.rule.model.GuidedEditorContent) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Overview(org.guvnor.common.services.shared.metadata.model.Overview) Test(org.junit.Test)

Aggregations

PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)40 Test (org.junit.Test)24 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)19 Path (org.uberfire.backend.vfs.Path)18 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)12 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)12 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)12 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)11 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)11 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)11 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)10 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)9 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)9 FileAlreadyExistsException (org.uberfire.java.nio.file.FileAlreadyExistsException)8 ResourceOpenedEvent (org.uberfire.workbench.events.ResourceOpenedEvent)8 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)7 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)7 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)7 LimitedEntryActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52)6 LimitedEntryActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionSetFieldCol52)6