Search in sources :

Example 26 with KBaseModel

use of org.kie.workbench.common.services.shared.kmodule.KBaseModel in project kie-wb-common by kiegroup.

the class KBaseConverter method marshal.

public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    KBaseModel kBase = (KBaseModel) value;
    writer.addAttribute("name", kBase.getName());
    writer.addAttribute("default", Boolean.toString(kBase.isDefault()));
    if (kBase.getEventProcessingMode() != null) {
        writer.addAttribute("eventProcessingMode", kBase.getEventProcessingMode().getMode());
    }
    if (kBase.getEqualsBehavior() != null) {
        writer.addAttribute("equalsBehavior", kBase.getEqualsBehavior().toString());
    }
    if (kBase.getDeclarativeAgenda() != null) {
        writer.addAttribute("declarativeAgenda", kBase.getDeclarativeAgenda().toString());
    }
    if (kBase.getScope() != null) {
        writer.addAttribute("scope", kBase.getScope());
    }
    if (!kBase.getPackages().isEmpty()) {
        StringBuilder buf = new StringBuilder();
        boolean first = true;
        for (SingleValueItemObjectModel pkg : kBase.getPackages()) {
            if (first) {
                first = false;
            } else {
                buf.append(", ");
            }
            buf.append(pkg.getValue());
        }
        writer.addAttribute("packages", buf.toString());
    }
    if (!kBase.getIncludes().isEmpty()) {
        StringBuilder sb = new StringBuilder();
        boolean insertComma = false;
        for (SingleValueItemObjectModel include : kBase.getIncludes()) {
            if (insertComma) {
                sb.append(", ");
            }
            sb.append(include.getValue());
            if (!insertComma) {
                insertComma = true;
            }
        }
        writer.addAttribute("includes", sb.toString());
    }
    for (KSessionModel kSessionModel : kBase.getKSessions()) {
        writeObject(writer, context, "ksession", kSessionModel);
    }
}
Also used : SingleValueItemObjectModel(org.kie.workbench.common.services.shared.kmodule.SingleValueItemObjectModel) KSessionModel(org.kie.workbench.common.services.shared.kmodule.KSessionModel) KBaseModel(org.kie.workbench.common.services.shared.kmodule.KBaseModel)

Example 27 with KBaseModel

use of org.kie.workbench.common.services.shared.kmodule.KBaseModel in project kie-wb-common by kiegroup.

the class KBaseConverter method unmarshal.

public Object unmarshal(HierarchicalStreamReader reader, final UnmarshallingContext context) {
    final KBaseModel kBase = new KBaseModel();
    kBase.setName(reader.getAttribute("name"));
    kBase.setDefault("true".equals(reader.getAttribute("default")));
    String eventMode = reader.getAttribute("eventProcessingMode");
    if (eventMode != null) {
        kBase.setEventProcessingMode(EventProcessingOption.determineEventProcessingMode(eventMode));
    }
    String equalsBehavior = reader.getAttribute("equalsBehavior");
    if (equalsBehavior != null) {
        kBase.setEqualsBehavior(AssertBehaviorOption.determineAssertBehaviorMode(equalsBehavior));
    }
    String declarativeAgenda = reader.getAttribute("declarativeAgenda");
    if (declarativeAgenda != null) {
        kBase.setDeclarativeAgenda(DeclarativeAgendaOption.determineDeclarativeAgendaMode(declarativeAgenda));
    }
    String scope = reader.getAttribute("scope");
    if (scope != null) {
        kBase.setScope(scope.trim());
    }
    String pkgs = reader.getAttribute("packages");
    if (pkgs != null) {
        for (String pkg : pkgs.split(",")) {
            kBase.addPackage(new SingleValueItemObjectModel(pkg.trim()));
        }
    }
    String includes = reader.getAttribute("includes");
    if (includes != null) {
        for (String include : includes.split(",")) {
            kBase.addInclude(new SingleValueItemObjectModel(include.trim()));
        }
    }
    readNodes(reader, new AbstractXStreamConverter.NodeReader() {

        public void onNode(HierarchicalStreamReader reader, String name, String value) {
            if ("ksession".equals(name)) {
                KSessionModel kSession = readObject(reader, context, KSessionModel.class);
                kBase.getKSessions().add(kSession);
            } else if ("includes".equals(name)) {
                for (String include : readList(reader)) {
                    kBase.addInclude(new SingleValueItemObjectModel(include));
                }
            }
        }
    });
    return kBase;
}
Also used : SingleValueItemObjectModel(org.kie.workbench.common.services.shared.kmodule.SingleValueItemObjectModel) KSessionModel(org.kie.workbench.common.services.shared.kmodule.KSessionModel) HierarchicalStreamReader(com.thoughtworks.xstream.io.HierarchicalStreamReader) KBaseModel(org.kie.workbench.common.services.shared.kmodule.KBaseModel) AbstractXStreamConverter(org.drools.core.util.AbstractXStreamConverter)

Example 28 with KBaseModel

use of org.kie.workbench.common.services.shared.kmodule.KBaseModel in project kie-wb-common by kiegroup.

the class KModuleConverter method marshal.

public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    KModuleModel kModule = (KModuleModel) value;
    // https://issues.jboss.org/browse/DROOLS-1023 introduced "version-less" XSDs
    writer.addAttribute("xmlns", "http://www.drools.org/xsd/kmodule");
    writer.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    for (KBaseModel kBaseModule : kModule.getKBases().values()) {
        writeObject(writer, context, "kbase", kBaseModule);
    }
}
Also used : KBaseModel(org.kie.workbench.common.services.shared.kmodule.KBaseModel) KModuleModel(org.kie.workbench.common.services.shared.kmodule.KModuleModel)

Example 29 with KBaseModel

use of org.kie.workbench.common.services.shared.kmodule.KBaseModel in project kie-wb-common by kiegroup.

the class DeploymentDescriptorServiceCDI method getProcessConfig.

@Override
public ProcessConfigModule getProcessConfig(String path) throws IOException {
    ProcessConfigModule processConfig = new ProcessConfigModule();
    KModuleContentHandler kModuleContentHandler = new KModuleContentHandler();
    try (InputStream in = IOUtils.toInputStream(guvnorM2Repository.getKieDeploymentDescriptorText(path), StandardCharsets.UTF_8)) {
        RuntimeStrategy runtimeStrategy = DeploymentDescriptorIO.fromXml(in).getRuntimeStrategy();
        switch(runtimeStrategy) {
            case SINGLETON:
                processConfig.setRuntimeStrategy(SINGLETON);
                break;
            case PER_CASE:
                processConfig.setRuntimeStrategy(PER_CASE);
                break;
            case PER_PROCESS_INSTANCE:
                processConfig.setRuntimeStrategy(PER_PROCESS_INSTANCE);
                break;
            case PER_REQUEST:
                processConfig.setRuntimeStrategy(PER_REQUEST);
                break;
        }
    }
    Map<String, KBaseModel> kBaseModelHashMap = kModuleContentHandler.toModel(guvnorM2Repository.getKModuleText(path)).getKBases();
    KBaseModel defaultKBaseModel = null;
    Optional<KBaseModel> optionalKBaseModel = kBaseModelHashMap.values().stream().filter(KBaseModel::isDefault).findFirst();
    if (optionalKBaseModel.isPresent()) {
        defaultKBaseModel = optionalKBaseModel.get();
    }
    if (defaultKBaseModel != null) {
        processConfig.setKBase(defaultKBaseModel.getName());
        Optional<KSessionModel> optionalKSessionModel = defaultKBaseModel.getKSessions().stream().filter(KSessionModel::isDefault).findFirst();
        KSessionModel defaultKSessionModel = null;
        if (optionalKSessionModel.isPresent()) {
            defaultKSessionModel = optionalKSessionModel.get();
            processConfig.setKSession(defaultKSessionModel.getName());
        }
    }
    return processConfig;
}
Also used : ProcessConfigModule(org.kie.workbench.common.screens.server.management.model.ProcessConfigModule) InputStream(java.io.InputStream) RuntimeStrategy(org.kie.internal.runtime.conf.RuntimeStrategy) RuntimeStrategy(org.kie.workbench.common.screens.server.management.model.RuntimeStrategy) KSessionModel(org.kie.workbench.common.services.shared.kmodule.KSessionModel) KBaseModel(org.kie.workbench.common.services.shared.kmodule.KBaseModel) KModuleContentHandler(org.kie.workbench.common.services.backend.kmodule.KModuleContentHandler)

Example 30 with KBaseModel

use of org.kie.workbench.common.services.shared.kmodule.KBaseModel in project kie-wb-common by kiegroup.

the class KModuleContentHandlerTest method testBasic.

@Test
public void testBasic() throws Exception {
    final KModuleContentHandler kModuleContentHandler = new KModuleContentHandler();
    final KModuleModel model = kModuleContentHandler.toModel(readResource("simpleKModule.xml"));
    assertNotNull(model);
    assertEquals(1, model.getKBases().size());
    final KBaseModel kBaseModel = model.getKBases().get("org.kie.example1");
    assertNotNull(kBaseModel);
    assertEquals(1, kBaseModel.getKSessions().size());
    final KSessionModel kSessionModel = kBaseModel.getKSessions().get(0);
    assertEquals("ksession1", kSessionModel.getName());
    assertEquals("stateful", kSessionModel.getType());
    assertTrue(kSessionModel.isDefault());
    assertEquals(ClockTypeOption.REALTIME, kSessionModel.getClockType());
    assertTrue(kSessionModel.getLogger() instanceof FileLogger);
    final FileLogger logger = (FileLogger) kSessionModel.getLogger();
    assertEquals("response-builder_filelogger", logger.getName());
    assertEquals("/tmp/response-builder_filelogger.log", logger.getFile());
    assertTrue(logger.isThreaded());
    assertEquals(1500, logger.getInterval());
    final String xml = kModuleContentHandler.toString(model);
    assertTrue(xml.contains("<kbase name=\"org.kie.example1\" default=\"false\" eventProcessingMode=\"stream\" equalsBehavior=\"identity\">"));
    assertTrue(xml.contains("<ksession name=\"ksession1\" type=\"stateful\" default=\"true\" clockType=\"realtime\">"));
    assertTrue(xml.contains("<fileLogger name=\"response-builder_filelogger\" file=\"/tmp/response-builder_filelogger.log\" threaded=\"true\" interval=\"1500\"/>"));
}
Also used : KSessionModel(org.kie.workbench.common.services.shared.kmodule.KSessionModel) FileLogger(org.kie.workbench.common.services.shared.kmodule.FileLogger) KBaseModel(org.kie.workbench.common.services.shared.kmodule.KBaseModel) KModuleModel(org.kie.workbench.common.services.shared.kmodule.KModuleModel) Test(org.junit.Test)

Aggregations

KBaseModel (org.kie.workbench.common.services.shared.kmodule.KBaseModel)38 Test (org.junit.Test)27 KSessionModel (org.kie.workbench.common.services.shared.kmodule.KSessionModel)12 KModuleModel (org.kie.workbench.common.services.shared.kmodule.KModuleModel)6 KnowledgeBasesPresenter (org.kie.workbench.common.screens.library.client.settings.sections.knowledgebases.KnowledgeBasesPresenter)5 KnowledgeBasesPresenter (org.kie.workbench.common.screens.library.client.settings.knowledgebases.KnowledgeBasesPresenter)3 HierarchicalStreamReader (com.thoughtworks.xstream.io.HierarchicalStreamReader)2 AbstractXStreamConverter (org.drools.core.util.AbstractXStreamConverter)2 SingleValueItemObjectModel (org.kie.workbench.common.services.shared.kmodule.SingleValueItemObjectModel)2 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 RuntimeStrategy (org.kie.internal.runtime.conf.RuntimeStrategy)1 KnowledgeBaseItemPresenter (org.kie.workbench.common.screens.library.client.settings.knowledgebases.item.KnowledgeBaseItemPresenter)1 KnowledgeBaseItemPresenter (org.kie.workbench.common.screens.library.client.settings.sections.knowledgebases.item.KnowledgeBaseItemPresenter)1 ProcessConfigModule (org.kie.workbench.common.screens.server.management.model.ProcessConfigModule)1 RuntimeStrategy (org.kie.workbench.common.screens.server.management.model.RuntimeStrategy)1 KModuleContentHandler (org.kie.workbench.common.services.backend.kmodule.KModuleContentHandler)1 ConsoleLogger (org.kie.workbench.common.services.shared.kmodule.ConsoleLogger)1 FileLogger (org.kie.workbench.common.services.shared.kmodule.FileLogger)1