Search in sources :

Example 6 with SingleValueItemObjectModel

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

the class KnowledgeBaseItemPresenter method addNewIncludedKnowledgeBase.

public void addNewIncludedKnowledgeBase() {
    includedKnowledgeBasesListPresenter.add(new SingleValueItemObjectModel(""));
    parentPresenter.fireChangeEvent();
    ;
}
Also used : SingleValueItemObjectModel(org.kie.workbench.common.services.shared.kmodule.SingleValueItemObjectModel)

Example 7 with SingleValueItemObjectModel

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

the class KnowledgeBaseItemPresenter method addPackage.

public void addPackage() {
    packageListPresenter.add(new SingleValueItemObjectModel(""));
    parentPresenter.fireChangeEvent();
}
Also used : SingleValueItemObjectModel(org.kie.workbench.common.services.shared.kmodule.SingleValueItemObjectModel)

Example 8 with SingleValueItemObjectModel

use of org.kie.workbench.common.services.shared.kmodule.SingleValueItemObjectModel 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 9 with SingleValueItemObjectModel

use of org.kie.workbench.common.services.shared.kmodule.SingleValueItemObjectModel 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 10 with SingleValueItemObjectModel

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

the class ListPresenterTest method testSetup.

@Test
public void testSetup() {
    doNothing().when(listPresenter).addToListElement(any());
    final List<SingleValueItemObjectModel> objs = Arrays.asList(new SingleValueItemObjectModel("foo"), new SingleValueItemObjectModel("bar"));
    listPresenter.setup(mock(HTMLElement.class), objs, (a, b) -> {
    });
    assertEquals(objs, listPresenter.getObjectsList());
    verify(listPresenter, times(2)).addToListElement(any());
}
Also used : SingleValueItemObjectModel(org.kie.workbench.common.services.shared.kmodule.SingleValueItemObjectModel) HTMLElement(elemental2.dom.HTMLElement) Test(org.junit.Test)

Aggregations

SingleValueItemObjectModel (org.kie.workbench.common.services.shared.kmodule.SingleValueItemObjectModel)10 Test (org.junit.Test)6 HTMLElement (elemental2.dom.HTMLElement)4 KnowledgeBaseItemPresenter (org.kie.workbench.common.screens.library.client.settings.sections.knowledgebases.item.KnowledgeBaseItemPresenter)2 IncludedKnowledgeBaseItemPresenter (org.kie.workbench.common.screens.library.client.settings.sections.knowledgebases.item.includedknowledgebases.IncludedKnowledgeBaseItemPresenter)2 KBaseModel (org.kie.workbench.common.services.shared.kmodule.KBaseModel)2 KSessionModel (org.kie.workbench.common.services.shared.kmodule.KSessionModel)2 HierarchicalStreamReader (com.thoughtworks.xstream.io.HierarchicalStreamReader)1 ArrayList (java.util.ArrayList)1 AbstractXStreamConverter (org.drools.core.util.AbstractXStreamConverter)1