Search in sources :

Example 26 with NamedObjectModel

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

the class DeploymentDescriptorTest method testPrintDescriptor.

@Test
public void testPrintDescriptor() {
    DeploymentDescriptor descriptor = new DeploymentDescriptorImpl("org.jbpm.domain");
    descriptor.getBuilder().addWorkItemHandler(new NamedObjectModel("mvel", "Log", "new org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler()")).addWorkItemHandler(new NamedObjectModel("mvel", "WebService", "new org.jbpm.process.workitem.webservice.WebServiceWorkItemHandler(ksession)")).addWorkItemHandler(new NamedObjectModel("mvel", "Rest", "new org.jbpm.process.workitem.rest.RESTWorkItemHandler()")).addWorkItemHandler(new NamedObjectModel("mvel", "Service Task", "new org.jbpm.process.workitem.bpmn2.ServiceTaskHandler(ksession)"));
    logger.debug(descriptor.toXml());
}
Also used : NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) Test(org.junit.Test)

Example 27 with NamedObjectModel

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

the class DeploymentDescriptorTest method testWriteDeploymentDescriptorXmlWithDuplicateNamedObjects.

@Test
public void testWriteDeploymentDescriptorXmlWithDuplicateNamedObjects() {
    DeploymentDescriptor descriptor = new DeploymentDescriptorImpl("org.jbpm.domain");
    descriptor.getBuilder().addWorkItemHandler(new NamedObjectModel("mvel", "Log", "new org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler()")).addWorkItemHandler(new NamedObjectModel("mvel", "Log", "new org.jbpm.process.instance.impl.demo.CustomSystemOutWorkItemHandler()")).addRequiredRole("experts");
    String deploymentDescriptorXml = descriptor.toXml();
    assertNotNull(deploymentDescriptorXml);
    logger.info(deploymentDescriptorXml);
    ByteArrayInputStream stream = new ByteArrayInputStream(deploymentDescriptorXml.getBytes());
    DeploymentDescriptor fromXml = DeploymentDescriptorIO.fromXml(stream);
    assertNotNull(fromXml);
    assertEquals("org.jbpm.domain", fromXml.getPersistenceUnit());
    assertEquals("org.jbpm.domain", fromXml.getAuditPersistenceUnit());
    assertEquals(AuditMode.JPA, fromXml.getAuditMode());
    assertEquals(PersistenceMode.JPA, fromXml.getPersistenceMode());
    assertEquals(RuntimeStrategy.SINGLETON, fromXml.getRuntimeStrategy());
    assertEquals(0, fromXml.getMarshallingStrategies().size());
    assertEquals(0, fromXml.getConfiguration().size());
    assertEquals(0, fromXml.getEnvironmentEntries().size());
    assertEquals(0, fromXml.getEventListeners().size());
    assertEquals(0, fromXml.getGlobals().size());
    assertEquals(0, fromXml.getTaskEventListeners().size());
    assertEquals(1, fromXml.getWorkItemHandlers().size());
    assertEquals(1, fromXml.getRequiredRoles().size());
}
Also used : NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) ByteArrayInputStream(java.io.ByteArrayInputStream) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) Test(org.junit.Test)

Example 28 with NamedObjectModel

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

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

the class DeploymentDescriptorMerger method merge.

public DeploymentDescriptor merge(DeploymentDescriptor master, DeploymentDescriptor slave, MergeMode mode) {
    if (master == null || slave == null) {
        throw new IllegalArgumentException("Descriptors to merge must be provided");
    }
    DeploymentDescriptor merged = null;
    DeploymentDescriptorBuilder builder = master.getBuilder();
    builder.setBuildHandler(new MergeModeBuildHandler(mode));
    switch(mode) {
        case KEEP_ALL:
            // do nothing as master wins
            merged = master;
            break;
        case OVERRIDE_ALL:
            // do nothing as slave wins
            merged = slave;
            break;
        case OVERRIDE_EMPTY:
            builder.auditMode(slave.getAuditMode());
            builder.auditPersistenceUnit(slave.getAuditPersistenceUnit());
            builder.persistenceMode(slave.getPersistenceMode());
            builder.persistenceUnit(slave.getPersistenceUnit());
            builder.runtimeStrategy(slave.getRuntimeStrategy());
            builder.setConfiguration(slave.getConfiguration());
            builder.setEnvironmentEntries(slave.getEnvironmentEntries());
            builder.setEventListeners(slave.getEventListeners());
            builder.setGlobals(slave.getGlobals());
            builder.setMarshalingStrategies(slave.getMarshallingStrategies());
            builder.setTaskEventListeners(slave.getTaskEventListeners());
            builder.setWorkItemHandlers(slave.getWorkItemHandlers());
            builder.setRequiredRoles(slave.getRequiredRoles());
            builder.setClasses(slave.getClasses());
            builder.setLimitSerializationClasses(slave.getLimitSerializationClasses());
            merged = builder.get();
            break;
        case MERGE_COLLECTIONS:
            builder.auditMode(slave.getAuditMode());
            builder.auditPersistenceUnit(slave.getAuditPersistenceUnit());
            builder.persistenceMode(slave.getPersistenceMode());
            builder.persistenceUnit(slave.getPersistenceUnit());
            builder.runtimeStrategy(slave.getRuntimeStrategy());
            for (ObjectModel model : slave.getEventListeners()) {
                builder.addEventListener(model);
            }
            for (ObjectModel model : slave.getMarshallingStrategies()) {
                builder.addMarshalingStrategy(model);
            }
            for (ObjectModel model : slave.getTaskEventListeners()) {
                builder.addTaskEventListener(model);
            }
            for (NamedObjectModel model : slave.getConfiguration()) {
                builder.addConfiguration(model);
            }
            for (NamedObjectModel model : slave.getEnvironmentEntries()) {
                builder.addEnvironmentEntry(model);
            }
            for (NamedObjectModel model : slave.getGlobals()) {
                builder.addGlobal(model);
            }
            for (NamedObjectModel model : slave.getWorkItemHandlers()) {
                builder.addWorkItemHandler(model);
            }
            for (String requiredRole : slave.getRequiredRoles()) {
                builder.addRequiredRole(requiredRole);
            }
            for (String clazz : slave.getClasses()) {
                builder.addClass(clazz);
            }
            Boolean slaveLimit = slave.getLimitSerializationClasses();
            Boolean masterLimit = master.getLimitSerializationClasses();
            if (slaveLimit != null && masterLimit != null && (!slaveLimit || !masterLimit)) {
                builder.setLimitSerializationClasses(false);
            }
            merged = builder.get();
            break;
        default:
            break;
    }
    return merged;
}
Also used : NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) ObjectModel(org.kie.internal.runtime.conf.ObjectModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeploymentDescriptorBuilder(org.kie.internal.runtime.conf.DeploymentDescriptorBuilder)

Aggregations

NamedObjectModel (org.kie.internal.runtime.conf.NamedObjectModel)29 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)24 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)11 ObjectModel (org.kie.internal.runtime.conf.ObjectModel)10 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)9 KieServices (org.kie.api.KieServices)9 ReleaseId (org.kie.api.builder.ReleaseId)8 DeploymentDescriptorImpl (org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl)7 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)6 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)6 File (java.io.File)5 FileOutputStream (java.io.FileOutputStream)5 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)5 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)5 DeploymentDescriptorBuilder (org.kie.internal.runtime.conf.DeploymentDescriptorBuilder)5 KieMavenRepository (org.kie.scanner.KieMavenRepository)5 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)4 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)4