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);
}
}
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;
}
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);
}
}
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;
}
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\"/>"));
}
Aggregations