Search in sources :

Example 1 with RuntimeStrategy

use of org.kie.internal.runtime.conf.RuntimeStrategy 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 2 with RuntimeStrategy

use of org.kie.internal.runtime.conf.RuntimeStrategy in project jbpm by kiegroup.

the class DeploymentDescriptorImpl method getBuilder.

@Override
public DeploymentDescriptorBuilder getBuilder() {
    return new DeploymentDescriptorBuilder() {

        private BuilderHandler handler = new BuilderHandler() {

            @Override
            public boolean accepted(Object value) {
                return true;
            }
        };

        private DeploymentDescriptorImpl descriptor = DeploymentDescriptorImpl.this;

        @Override
        public DeploymentDescriptorBuilder runtimeStrategy(RuntimeStrategy strategy) {
            if (handler.accepted(strategy)) {
                descriptor.setRuntimeStrategy(strategy);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder persistenceUnit(String pu) {
            if (handler.accepted(pu)) {
                descriptor.setPersistenceUnit(pu);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder persistenceMode(PersistenceMode mode) {
            if (handler.accepted(mode)) {
                descriptor.setPersistenceMode(mode);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder auditPersistenceUnit(String pu) {
            if (handler.accepted(pu)) {
                descriptor.setAuditPersistenceUnit(pu);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder auditMode(AuditMode mode) {
            if (handler.accepted(mode)) {
                descriptor.setAuditMode(mode);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder addWorkItemHandler(NamedObjectModel model) {
            if (handler.accepted(model)) {
                if (!descriptor.workItemHandlers.add(model)) {
                    descriptor.workItemHandlers.remove(model);
                    descriptor.workItemHandlers.add(model);
                }
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder addTaskEventListener(ObjectModel model) {
            if (handler.accepted(model)) {
                if (!descriptor.taskEventListeners.add(model)) {
                    descriptor.taskEventListeners.remove(model);
                    descriptor.taskEventListeners.add(model);
                }
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder addMarshalingStrategy(ObjectModel model) {
            if (handler.accepted(model)) {
                if (!descriptor.marshallingStrategies.add(model)) {
                    descriptor.marshallingStrategies.remove(model);
                    descriptor.marshallingStrategies.add(model);
                }
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder addGlobal(NamedObjectModel model) {
            if (handler.accepted(model)) {
                if (!descriptor.globals.add(model)) {
                    descriptor.globals.remove(model);
                    descriptor.globals.add(model);
                }
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder addEventListener(ObjectModel model) {
            if (handler.accepted(model)) {
                if (!descriptor.eventListeners.add(model)) {
                    descriptor.eventListeners.remove(model);
                    descriptor.eventListeners.add(model);
                }
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder addEnvironmentEntry(NamedObjectModel model) {
            if (handler.accepted(model)) {
                if (!descriptor.environmentEntries.add(model)) {
                    descriptor.environmentEntries.remove(model);
                    descriptor.environmentEntries.add(model);
                }
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder addConfiguration(NamedObjectModel model) {
            if (handler.accepted(model)) {
                if (!descriptor.configuration.add(model)) {
                    descriptor.configuration.remove(model);
                    descriptor.configuration.add(model);
                }
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder addRequiredRole(String role) {
            if (handler.accepted(role)) {
                descriptor.requiredRoles.add(role);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder addClass(String clazz) {
            if (handler.accepted(clazz)) {
                descriptor.classes.add(clazz);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder setConfiguration(List<NamedObjectModel> models) {
            if (handler.accepted(models)) {
                descriptor.setConfiguration(models);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder setEnvironmentEntries(List<NamedObjectModel> models) {
            if (handler.accepted(models)) {
                descriptor.setEnvironmentEntries(models);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder setWorkItemHandlers(List<NamedObjectModel> models) {
            if (handler.accepted(models)) {
                descriptor.setWorkItemHandlers(models);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder setGlobals(List<NamedObjectModel> models) {
            if (handler.accepted(models)) {
                descriptor.setGlobals(models);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder setEventListeners(List<ObjectModel> models) {
            if (handler.accepted(models)) {
                descriptor.setEventListeners(models);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder setTaskEventListeners(List<ObjectModel> models) {
            if (handler.accepted(models)) {
                descriptor.setTaskEventListeners(models);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder setMarshalingStrategies(List<ObjectModel> models) {
            if (handler.accepted(models)) {
                descriptor.setMarshallingStrategies(models);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder setRequiredRoles(List<String> roles) {
            if (handler.accepted(roles)) {
                descriptor.setRequiredRoles(roles);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder setClasses(List<String> classes) {
            if (handler.accepted(classes)) {
                descriptor.setClasses(classes);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder setLimitSerializationClasses(Boolean limit) {
            if (handler.accepted(limit)) {
                descriptor.setLimitSerializationClasses(limit);
            }
            return this;
        }

        @Override
        public void setBuildHandler(BuilderHandler handler) {
            this.handler = handler;
        }

        @Override
        public DeploymentDescriptor get() {
            return descriptor;
        }
    };
}
Also used : ObjectModel(org.kie.internal.runtime.conf.ObjectModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) RuntimeStrategy(org.kie.internal.runtime.conf.RuntimeStrategy) DeploymentDescriptorBuilder(org.kie.internal.runtime.conf.DeploymentDescriptorBuilder) BuilderHandler(org.kie.internal.runtime.conf.BuilderHandler) PersistenceMode(org.kie.internal.runtime.conf.PersistenceMode) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) AuditMode(org.kie.internal.runtime.conf.AuditMode) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with RuntimeStrategy

use of org.kie.internal.runtime.conf.RuntimeStrategy in project drools by kiegroup.

the class DeploymentDescriptorImpl method getBuilder.

@Override
public DeploymentDescriptorBuilder getBuilder() {
    return new DeploymentDescriptorBuilder() {

        private BuilderHandler handler = new BuilderHandler() {

            @Override
            public boolean accepted(Object value) {
                return true;
            }
        };

        private DeploymentDescriptorImpl descriptor = DeploymentDescriptorImpl.this;

        @Override
        public DeploymentDescriptorBuilder runtimeStrategy(RuntimeStrategy strategy) {
            if (handler.accepted(strategy)) {
                descriptor.setRuntimeStrategy(strategy);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder persistenceUnit(String pu) {
            if (handler.accepted(pu)) {
                descriptor.setPersistenceUnit(pu);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder persistenceMode(PersistenceMode mode) {
            if (handler.accepted(mode)) {
                descriptor.setPersistenceMode(mode);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder auditPersistenceUnit(String pu) {
            if (handler.accepted(pu)) {
                descriptor.setAuditPersistenceUnit(pu);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder auditMode(AuditMode mode) {
            if (handler.accepted(mode)) {
                descriptor.setAuditMode(mode);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder addWorkItemHandler(NamedObjectModel model) {
            if (handler.accepted(model)) {
                if (!descriptor.workItemHandlers.add(model)) {
                    descriptor.workItemHandlers.remove(model);
                    descriptor.workItemHandlers.add(model);
                }
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder addTaskEventListener(ObjectModel model) {
            if (handler.accepted(model)) {
                if (!descriptor.taskEventListeners.contains(model)) {
                    descriptor.taskEventListeners.add(model);
                }
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder addMarshalingStrategy(ObjectModel model) {
            if (handler.accepted(model)) {
                if (!descriptor.marshallingStrategies.add(model)) {
                    descriptor.marshallingStrategies.remove(model);
                    descriptor.marshallingStrategies.add(model);
                }
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder addGlobal(NamedObjectModel model) {
            if (handler.accepted(model)) {
                if (!descriptor.globals.add(model)) {
                    descriptor.globals.remove(model);
                    descriptor.globals.add(model);
                }
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder addEventListener(ObjectModel model) {
            if (handler.accepted(model)) {
                if (!descriptor.eventListeners.add(model)) {
                    descriptor.eventListeners.remove(model);
                    descriptor.eventListeners.add(model);
                }
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder addEnvironmentEntry(NamedObjectModel model) {
            if (handler.accepted(model)) {
                if (!descriptor.environmentEntries.add(model)) {
                    descriptor.environmentEntries.remove(model);
                    descriptor.environmentEntries.add(model);
                }
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder addConfiguration(NamedObjectModel model) {
            if (handler.accepted(model)) {
                if (!descriptor.configuration.add(model)) {
                    descriptor.configuration.remove(model);
                    descriptor.configuration.add(model);
                }
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder addRequiredRole(String role) {
            if (handler.accepted(role)) {
                descriptor.requiredRoles.add(role);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder addClass(String clazz) {
            if (handler.accepted(clazz)) {
                descriptor.classes.add(clazz);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder setConfiguration(List<NamedObjectModel> models) {
            if (handler.accepted(models)) {
                descriptor.setConfiguration(models);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder setEnvironmentEntries(List<NamedObjectModel> models) {
            if (handler.accepted(models)) {
                descriptor.setEnvironmentEntries(models);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder setWorkItemHandlers(List<NamedObjectModel> models) {
            if (handler.accepted(models)) {
                descriptor.setWorkItemHandlers(models);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder setGlobals(List<NamedObjectModel> models) {
            if (handler.accepted(models)) {
                descriptor.setGlobals(models);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder setEventListeners(List<ObjectModel> models) {
            if (handler.accepted(models)) {
                descriptor.setEventListeners(models);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder setTaskEventListeners(List<ObjectModel> models) {
            if (handler.accepted(models)) {
                descriptor.setTaskEventListeners(models);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder setMarshalingStrategies(List<ObjectModel> models) {
            if (handler.accepted(models)) {
                descriptor.setMarshallingStrategies(models);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder setRequiredRoles(List<String> roles) {
            if (handler.accepted(roles)) {
                descriptor.setRequiredRoles(roles);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder setClasses(List<String> classes) {
            if (handler.accepted(classes)) {
                descriptor.setClasses(classes);
            }
            return this;
        }

        @Override
        public DeploymentDescriptorBuilder setLimitSerializationClasses(Boolean limit) {
            if (handler.accepted(limit)) {
                descriptor.setLimitSerializationClasses(limit);
            }
            return this;
        }

        @Override
        public void setBuildHandler(BuilderHandler handler) {
            this.handler = handler;
        }

        @Override
        public DeploymentDescriptor get() {
            return descriptor;
        }
    };
}
Also used : ObjectModel(org.kie.internal.runtime.conf.ObjectModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) RuntimeStrategy(org.kie.internal.runtime.conf.RuntimeStrategy) DeploymentDescriptorBuilder(org.kie.internal.runtime.conf.DeploymentDescriptorBuilder) BuilderHandler(org.kie.internal.runtime.conf.BuilderHandler) PersistenceMode(org.kie.internal.runtime.conf.PersistenceMode) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) AuditMode(org.kie.internal.runtime.conf.AuditMode) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

RuntimeStrategy (org.kie.internal.runtime.conf.RuntimeStrategy)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AuditMode (org.kie.internal.runtime.conf.AuditMode)2 BuilderHandler (org.kie.internal.runtime.conf.BuilderHandler)2 DeploymentDescriptorBuilder (org.kie.internal.runtime.conf.DeploymentDescriptorBuilder)2 NamedObjectModel (org.kie.internal.runtime.conf.NamedObjectModel)2 ObjectModel (org.kie.internal.runtime.conf.ObjectModel)2 PersistenceMode (org.kie.internal.runtime.conf.PersistenceMode)2 InputStream (java.io.InputStream)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 KBaseModel (org.kie.workbench.common.services.shared.kmodule.KBaseModel)1 KSessionModel (org.kie.workbench.common.services.shared.kmodule.KSessionModel)1