Search in sources :

Example 1 with GuidedTemplateEditorContent

use of org.drools.workbench.screens.guided.template.model.GuidedTemplateEditorContent in project drools-wb by kiegroup.

the class GuidedRuleTemplateEditorServiceImplCDITest method testLoadContent.

@Test
public void testLoadContent() throws Exception {
    final Path testedPath = getPath(CARS);
    final GuidedTemplateEditorContent testedContent = testedService.loadContent(testedPath);
    oracleFactory.makeAsyncPackageDataModelOracle(testedPath, testedContent.getModel(), testedContent.getDataModel());
    final String declaredFactInEnum = "Car";
    final String declaredFieldInEnum = "price";
    final Map<String, String> actualFieldValues = new HashMap<String, String>() {

        {
            put("color", "red");
        }
    };
    final DropDownData dropDownData = asyncOracle.getEnums(declaredFactInEnum, declaredFieldInEnum, actualFieldValues);
    Assertions.assertThat(dropDownData.getQueryExpression()).isEqualTo("(new org.kiegroup.PriceHelper()).getPrices(\"@{color}\")");
    Assertions.assertThat(dropDownData.getValuePairs()).hasSize(1);
    Assertions.assertThat(dropDownData.getValuePairs()[0]).isEqualTo("color=red");
}
Also used : Path(org.uberfire.backend.vfs.Path) GuidedTemplateEditorContent(org.drools.workbench.screens.guided.template.model.GuidedTemplateEditorContent) HashMap(java.util.HashMap) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) Test(org.junit.Test)

Example 2 with GuidedTemplateEditorContent

use of org.drools.workbench.screens.guided.template.model.GuidedTemplateEditorContent in project drools-wb by kiegroup.

the class GuidedRuleTemplateEditorServiceImplTest method checkConstructContentPopulateProjectCollectionTypes.

@Test
public void checkConstructContentPopulateProjectCollectionTypes() {
    final Path path = mock(Path.class);
    final Overview overview = mock(Overview.class);
    final PackageDataModelOracle oracle = mock(PackageDataModelOracle.class);
    when(path.toURI()).thenReturn("default://project/src/main/resources/mypackage/rule.template");
    when(dataModelService.getDataModel(any())).thenReturn(oracle);
    when(oracle.getPackageGlobals()).thenReturn(new HashMap<String, String>() {

        {
            put("number", "java.lang.Number");
            put("collection", "java.util.Collection");
        }
    });
    when(oracle.getModuleCollectionTypes()).thenReturn(new HashMap<String, Boolean>() {

        {
            put("java.util.List", true);
            put("java.util.Set", true);
            put("java.util.Collection", true);
            put("java.util.UnknownCollection", false);
        }
    });
    final GuidedTemplateEditorContent 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"));
}
Also used : Path(org.uberfire.backend.vfs.Path) GuidedTemplateEditorContent(org.drools.workbench.screens.guided.template.model.GuidedTemplateEditorContent) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Overview(org.guvnor.common.services.shared.metadata.model.Overview) Test(org.junit.Test)

Example 3 with GuidedTemplateEditorContent

use of org.drools.workbench.screens.guided.template.model.GuidedTemplateEditorContent 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 4 with GuidedTemplateEditorContent

use of org.drools.workbench.screens.guided.template.model.GuidedTemplateEditorContent 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

GuidedTemplateEditorContent (org.drools.workbench.screens.guided.template.model.GuidedTemplateEditorContent)4 Path (org.uberfire.backend.vfs.Path)3 Overview (org.guvnor.common.services.shared.metadata.model.Overview)2 Test (org.junit.Test)2 PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)2 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 PostConstruct (javax.annotation.PostConstruct)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Event (javax.enterprise.event.Event)1 Inject (javax.inject.Inject)1 Named (javax.inject.Named)1 RuleTemplateModelXMLPersistenceImpl (org.drools.workbench.models.guided.template.backend.RuleTemplateModelXMLPersistenceImpl)1 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)1 GuidedRuleModelVisitor (org.drools.workbench.screens.guided.rule.backend.server.GuidedRuleModelVisitor)1 GuidedRuleTemplateEditorService (org.drools.workbench.screens.guided.template.service.GuidedRuleTemplateEditorService)1