Search in sources :

Example 46 with PackageDataModelOracleBaselinePayload

use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project drools-wb by kiegroup.

the class FromAccumulateCompositeFactPatternWidgetTest method setUp.

@Before
public void setUp() throws Exception {
    // listBox is used for verification fo added available fact types into UI
    GwtMockito.useProviderForType(ListBox.class, aClass -> listBox);
    // Mock partially the AsyncPackageDataModelOracle
    validatorInstance = new MockInstanceImpl<>();
    oracle = spy(new AsyncPackageDataModelOracleImpl(new CallerMock<>(incrementalDataModelService), validatorInstance));
    // Mock partially the AsyncPackageDataModelOracleFactory and ensure oracle will contain data form payload below
    doReturn(syncBeanDef).when(syncBeanManager).lookupBean(AsyncPackageDataModelOracle.class);
    doReturn(oracle).when(syncBeanDef).getInstance();
    doReturn(oracle).when(ruleModeller).getDataModelOracle();
    // Prepare base payload that simulates two Facts in the package, Person and Car
    dataModelPayload = new PackageDataModelOracleBaselinePayload();
    dataModelPayload.setModelFields(new HashMap<String, ModelField[]>() {

        {
            final String fqnPerson = REDHAT_PACKAGE + "." + FACT_TYPE_PERSON;
            final String fqnCar = REDHAT_PACKAGE + "." + FACT_TYPE_CAR;
            final String fqnNumber = Number.class.getName();
            put(fqnPerson, new ModelField[] { modelField(DataType.TYPE_THIS, fqnPerson) });
            put(fqnCar, new ModelField[] { modelField(DataType.TYPE_THIS, fqnCar) });
            put(fqnNumber, new ModelField[] { modelField(DataType.TYPE_THIS, fqnNumber) });
        }
    });
    // Prevent NPE in FromAccumulateCompositeFactPatternWidget constructor
    when(pattern.useFunctionOrCode()).thenReturn(FromAccumulateCompositeFactPattern.USE_FUNCTION);
    fromAccumulateWidget = new FromAccumulateCompositeFactPatternWidget(ruleModeller, eventBus, pattern);
    ruleModelWithImportedNumber = new RuleModel() {

        {
            setImports(new Imports() {

                {
                    addImport(new Import(Number.class));
                }
            });
        }
    };
}
Also used : AsyncPackageDataModelOracleImpl(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracleImpl) Import(org.kie.soup.project.datamodel.imports.Import) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) Matchers.anyString(org.mockito.Matchers.anyString) Imports(org.kie.soup.project.datamodel.imports.Imports) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Before(org.junit.Before)

Example 47 with PackageDataModelOracleBaselinePayload

use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project drools-wb by kiegroup.

the class GuidedRuleTemplateEditorServiceImpl method constructContent.

@Override
protected GuidedTemplateEditorContent constructContent(Path path, Overview overview) {
    final TemplateModel model = load(path);
    final PackageDataModelOracle oracle = dataModelService.getDataModel(path);
    final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
    // Get FQCN's used by model
    final GuidedRuleModelVisitor visitor = new GuidedRuleModelVisitor(model);
    final Set<String> consumedFQCNs = visitor.getConsumedModelClasses();
    // Get FQCN's used by Globals
    consumedFQCNs.addAll(oracle.getPackageGlobals().values());
    // Get FQCN's of collections defined in project settings
    // they can be used in From Collect expressions
    consumedFQCNs.addAll(oracle.getModuleCollectionTypes().entrySet().stream().filter(entry -> entry.getValue()).map(entry -> entry.getKey()).collect(Collectors.toSet()));
    DataModelOracleUtilities.populateDataModel(oracle, dataModel, consumedFQCNs);
    // Signal opening to interested parties
    resourceOpenedEvent.fire(new ResourceOpenedEvent(path, safeSessionInfo));
    return new GuidedTemplateEditorContent(model, overview, dataModel);
}
Also used : PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) Level(org.guvnor.common.services.shared.message.Level) ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) GuidedRuleTemplateResourceTypeDefinition(org.drools.workbench.screens.guided.template.type.GuidedRuleTemplateResourceTypeDefinition) ArrayList(java.util.ArrayList) Package(org.guvnor.common.services.project.model.Package) Paths(org.uberfire.backend.server.util.Paths) Inject(javax.inject.Inject) ExceptionUtilities(org.guvnor.common.services.backend.exceptions.ExceptionUtilities) CommentedOptionFactory(org.guvnor.common.services.backend.util.CommentedOptionFactory) GuidedRuleTemplateEditorService(org.drools.workbench.screens.guided.template.service.GuidedRuleTemplateEditorService) Overview(org.guvnor.common.services.shared.metadata.model.Overview) Service(org.jboss.errai.bus.server.annotations.Service) SafeSessionInfo(org.guvnor.common.services.backend.config.SafeSessionInfo) SessionInfo(org.uberfire.rpc.SessionInfo) Named(javax.inject.Named) KieService(org.kie.workbench.common.services.backend.service.KieService) RenameService(org.uberfire.ext.editor.commons.service.RenameService) Path(org.uberfire.backend.vfs.Path) DeleteService(org.uberfire.ext.editor.commons.service.DeleteService) Event(javax.enterprise.event.Event) DataModelService(org.kie.workbench.common.services.datamodel.backend.server.service.DataModelService) SaveAndRenameServiceImpl(org.uberfire.ext.editor.commons.backend.service.SaveAndRenameServiceImpl) DataModelOracleUtilities(org.kie.workbench.common.services.datamodel.backend.server.DataModelOracleUtilities) Set(java.util.Set) Collectors(java.util.stream.Collectors) ResourceOpenedEvent(org.uberfire.workbench.events.ResourceOpenedEvent) RuleTemplateModelXMLPersistenceImpl(org.drools.workbench.models.guided.template.backend.RuleTemplateModelXMLPersistenceImpl) GenericValidator(org.guvnor.common.services.backend.validation.GenericValidator) List(java.util.List) GuidedTemplateEditorContent(org.drools.workbench.screens.guided.template.model.GuidedTemplateEditorContent) GuidedRuleModelVisitor(org.drools.workbench.screens.guided.rule.backend.server.GuidedRuleModelVisitor) PostConstruct(javax.annotation.PostConstruct) IOService(org.uberfire.io.IOService) ApplicationScoped(javax.enterprise.context.ApplicationScoped) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) CopyService(org.uberfire.ext.editor.commons.service.CopyService) GuidedTemplateEditorContent(org.drools.workbench.screens.guided.template.model.GuidedTemplateEditorContent) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) GuidedRuleModelVisitor(org.drools.workbench.screens.guided.rule.backend.server.GuidedRuleModelVisitor) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) ResourceOpenedEvent(org.uberfire.workbench.events.ResourceOpenedEvent)

Example 48 with PackageDataModelOracleBaselinePayload

use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project drools-wb by kiegroup.

the class GuidedRuleTemplateEditorPresenter method getModelSuccessCallback.

private RemoteCallback<GuidedTemplateEditorContent> getModelSuccessCallback() {
    return new RemoteCallback<GuidedTemplateEditorContent>() {

        @Override
        public void callback(final GuidedTemplateEditorContent content) {
            // Path is set to null when the Editor is closed (which can happen before async calls complete).
            if (versionRecordManager.getCurrentPath() == null) {
                return;
            }
            resetEditorPages(content.getOverview());
            addSourcePage();
            addPage(new PageImpl(dataView, GuidedTemplateEditorConstants.INSTANCE.Data()) {

                @Override
                public void onFocus() {
                    dataView.setContent(model, oracle, eventBus, isReadOnly);
                }

                @Override
                public void onLostFocus() {
                // Nothing to do here
                }
            });
            addImportsTab(importsWidget);
            model = content.getModel();
            final PackageDataModelOracleBaselinePayload dataModel = content.getDataModel();
            oracle = oracleFactory.makeAsyncPackageDataModelOracle(versionRecordManager.getCurrentPath(), model, dataModel);
            view.setContent(model, oracle, ruleNamesService, eventBus, isReadOnly);
            importsWidget.setContent(oracle, model.getImports(), isReadOnly);
            createOriginalHash(model);
            view.hideBusyIndicator();
        }
    };
}
Also used : PageImpl(org.uberfire.client.views.pfly.multipage.PageImpl) GuidedTemplateEditorContent(org.drools.workbench.screens.guided.template.model.GuidedTemplateEditorContent) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback)

Aggregations

PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)48 Path (org.uberfire.backend.vfs.Path)33 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)32 Test (org.junit.Test)29 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)29 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)29 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)26 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)25 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)25 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)24 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)19 PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)19 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)14 ArrayList (java.util.ArrayList)13 List (java.util.List)12 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)12 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)12 LimitedEntryActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52)9 LimitedEntryActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionSetFieldCol52)9 ColumnUtilities (org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.ColumnUtilities)7