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();
}
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());
}
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;
}
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);
}
}
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);
}
}
Aggregations