Search in sources :

Example 16 with KBaseModel

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

the class KnowledgeBaseItemPresenterTest method testSetDefault.

@Test
public void testSetDefault() {
    final KBaseModel kBaseModel = new KBaseModel();
    kBaseModel.setDefault(false);
    final KnowledgeBasesPresenter parentPresenter = mock(KnowledgeBasesPresenter.class);
    knowledgeBaseItemPresenter.kBaseModel = kBaseModel;
    knowledgeBaseItemPresenter.parentPresenter = parentPresenter;
    knowledgeBaseItemPresenter.setDefault(true);
    Assert.assertTrue(kBaseModel.isDefault());
    verify(defaultKnowledgeBaseChangeEvent).fire(any());
    verify(parentPresenter).fireChangeEvent();
}
Also used : KnowledgeBasesPresenter(org.kie.workbench.common.screens.library.client.settings.knowledgebases.KnowledgeBasesPresenter) KBaseModel(org.kie.workbench.common.services.shared.kmodule.KBaseModel) Test(org.junit.Test)

Example 17 with KBaseModel

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

the class KnowledgeSessionListItemPresenterTest method testOnDefaultKnowledgeSessionChangedWithAnotherKSessionModel.

@Test
public void testOnDefaultKnowledgeSessionChangedWithAnotherKSessionModel() {
    final KBaseModel kBaseModel = new KBaseModel();
    final KSessionModel kSessionModel = new KSessionModel();
    kSessionModel.setDefault(true);
    final KnowledgeSessionsModal parentPresenter = mock(KnowledgeSessionsModal.class);
    doReturn(kBaseModel).when(parentPresenter).getObject();
    knowledgeSessionListItemPresenter.parentPresenter = parentPresenter;
    knowledgeSessionListItemPresenter.kSessionModel = kSessionModel;
    final KSessionModel anotherKSessionModel = new KSessionModel();
    anotherKSessionModel.setName("Distinguishing name");
    knowledgeSessionListItemPresenter.onDefaultKnowledgeSessionChanged(new DefaultKnowledgeSessionChange(kBaseModel, anotherKSessionModel));
    Assert.assertEquals(false, kSessionModel.isDefault());
}
Also used : KSessionModel(org.kie.workbench.common.services.shared.kmodule.KSessionModel) KBaseModel(org.kie.workbench.common.services.shared.kmodule.KBaseModel) Test(org.junit.Test)

Example 18 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(pkg.trim());
        }
    }
    String includes = reader.getAttribute("includes");
    if (includes != null) {
        for (String include : includes.split(",")) {
            kBase.addInclude(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(include);
                }
            }
        }
    });
    return kBase;
}
Also used : 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 19 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 (String pkg : kBase.getPackages()) {
            if (first) {
                first = false;
            } else {
                buf.append(", ");
            }
            buf.append(pkg);
        }
        writer.addAttribute("packages", buf.toString());
    }
    if (!kBase.getIncludes().isEmpty()) {
        StringBuilder sb = new StringBuilder();
        boolean insertComma = false;
        for (String include : kBase.getIncludes()) {
            if (insertComma) {
                sb.append(", ");
            }
            sb.append(include);
            if (!insertComma) {
                insertComma = true;
            }
        }
        writer.addAttribute("includes", sb.toString());
    }
    for (KSessionModel kSessionModel : kBase.getKSessions()) {
        writeObject(writer, context, "ksession", kSessionModel);
    }
}
Also used : KSessionModel(org.kie.workbench.common.services.shared.kmodule.KSessionModel) KBaseModel(org.kie.workbench.common.services.shared.kmodule.KBaseModel)

Example 20 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)

Aggregations

KBaseModel (org.kie.workbench.common.services.shared.kmodule.KBaseModel)20 Test (org.junit.Test)11 KSessionModel (org.kie.workbench.common.services.shared.kmodule.KSessionModel)7 KnowledgeBasesPresenter (org.kie.workbench.common.screens.library.client.settings.knowledgebases.KnowledgeBasesPresenter)3 KModuleModel (org.kie.workbench.common.services.shared.kmodule.KModuleModel)3 HierarchicalStreamReader (com.thoughtworks.xstream.io.HierarchicalStreamReader)2 AbstractXStreamConverter (org.drools.core.util.AbstractXStreamConverter)2 KnowledgeBaseItemPresenter (org.kie.workbench.common.screens.library.client.settings.knowledgebases.item.KnowledgeBaseItemPresenter)1