Search in sources :

Example 51 with KieMavenRepository

use of org.kie.scanner.KieMavenRepository in project jbpm by kiegroup.

the class KModuleDeploymentService method deploy.

@Override
public void deploy(DeploymentUnit unit) {
    try {
        super.deploy(unit);
        if (!(unit instanceof KModuleDeploymentUnit)) {
            throw new IllegalArgumentException("Invalid deployment unit provided - " + unit.getClass().getName());
        }
        KModuleDeploymentUnit kmoduleUnit = (KModuleDeploymentUnit) unit;
        DeployedUnitImpl deployedUnit = new DeployedUnitImpl(unit);
        deployedUnit.setActive(kmoduleUnit.isActive());
        // Create the release id
        KieContainer kieContainer = kmoduleUnit.getKieContainer();
        ReleaseId releaseId = null;
        if (kieContainer == null) {
            KieServices ks = KieServices.Factory.get();
            releaseId = ks.newReleaseId(kmoduleUnit.getGroupId(), kmoduleUnit.getArtifactId(), kmoduleUnit.getVersion());
            KieMavenRepository repository = getKieMavenRepository();
            repository.resolveArtifact(releaseId.toExternalForm());
            kieContainer = ks.newKieContainer(releaseId);
            kmoduleUnit.setKieContainer(kieContainer);
        }
        releaseId = kieContainer.getReleaseId();
        // retrieve the kbase name
        String kbaseName = kmoduleUnit.getKbaseName();
        if (StringUtils.isEmpty(kbaseName)) {
            KieBaseModel defaultKBaseModel = ((KieContainerImpl) kieContainer).getKieProject().getDefaultKieBaseModel();
            if (defaultKBaseModel != null) {
                kbaseName = defaultKBaseModel.getName();
            } else {
                kbaseName = DEFAULT_KBASE_NAME;
            }
        }
        InternalKieModule module = (InternalKieModule) ((KieContainerImpl) kieContainer).getKieModuleForKBase(kbaseName);
        if (module == null) {
            throw new IllegalStateException("Cannot find kbase, either it does not exist or there are multiple default kbases in kmodule.xml");
        }
        KieBase kbase = kieContainer.getKieBase(kbaseName);
        Map<String, ProcessDescriptor> processDescriptors = new HashMap<String, ProcessDescriptor>();
        for (org.kie.api.definition.process.Process process : kbase.getProcesses()) {
            processDescriptors.put(process.getId(), ((ProcessDescriptor) process.getMetaData().get("ProcessDescriptor")).clone());
        }
        // TODO: add forms data?
        Collection<String> files = module.getFileNames();
        processResources(module, files, kieContainer, kmoduleUnit, deployedUnit, releaseId, processDescriptors);
        // process the files in the deployment
        if (module.getKieDependencies() != null) {
            Collection<InternalKieModule> dependencies = module.getKieDependencies().values();
            for (InternalKieModule depModule : dependencies) {
                logger.debug("Processing dependency module " + depModule.getReleaseId());
                files = depModule.getFileNames();
                processResources(depModule, files, kieContainer, kmoduleUnit, deployedUnit, depModule.getReleaseId(), processDescriptors);
            }
        }
        Collection<ReleaseId> dependencies = module.getJarDependencies(new DependencyFilter.ExcludeScopeFilter("test", "provided"));
        // process deployment dependencies
        if (dependencies != null && !dependencies.isEmpty()) {
            // Classes 2: classes added from project and dependencies added
            processClassloader(kieContainer, deployedUnit);
        }
        AuditEventBuilder auditLoggerBuilder = setupAuditLogger(identityProvider, unit.getIdentifier());
        RuntimeEnvironmentBuilder builder = boostrapRuntimeEnvironmentBuilder(kmoduleUnit, deployedUnit, kieContainer, kmoduleUnit.getMergeMode()).knowledgeBase(kbase).classLoader(kieContainer.getClassLoader());
        builder.registerableItemsFactory(getRegisterableItemsFactory(auditLoggerBuilder, kieContainer, kmoduleUnit));
        commonDeploy(unit, deployedUnit, builder.get(), kieContainer);
        kmoduleUnit.setDeployed(true);
    } catch (Throwable e) {
        logger.warn("Unexpected error while deploying unit {}", unit.getIdentifier(), e);
        // catch all possible errors to be able to report them to caller as RuntimeException
        throw new RuntimeException(e);
    }
}
Also used : HashMap(java.util.HashMap) KieServices(org.kie.api.KieServices) RuntimeEnvironmentBuilder(org.kie.api.runtime.manager.RuntimeEnvironmentBuilder) KieBase(org.kie.api.KieBase) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) KieContainer(org.kie.api.runtime.KieContainer) DependencyFilter(org.appformer.maven.support.DependencyFilter) ReleaseId(org.kie.api.builder.ReleaseId) KieBaseModel(org.kie.api.builder.model.KieBaseModel) AuditEventBuilder(org.jbpm.process.audit.event.AuditEventBuilder) ProcessDescriptor(org.jbpm.kie.services.impl.bpmn2.ProcessDescriptor) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 52 with KieMavenRepository

use of org.kie.scanner.KieMavenRepository in project jbpm by kiegroup.

the class ClientProcessServiceWithCustomDataEJBTest method prepare.

@Before
public void prepare() throws MalformedURLException {
    originClassLoader = Thread.currentThread().getContextClassLoader();
    configureServices();
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION);
    File kjar = new File("src/test/resources/kjar/custom-data-project-1.0.jar");
    File pom = new File("src/test/resources/kjar/pom.xml");
    KieMavenRepository repository = getKieMavenRepository();
    repository.installArtifact(releaseId, kjar, pom);
    URL[] urls = new URL[] { kjar.toURI().toURL() };
    customClassLoader = new URLClassLoader(urls, this.getClass().getClassLoader());
    Thread.currentThread().setContextClassLoader(customClassLoader);
}
Also used : URLClassLoader(java.net.URLClassLoader) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) File(java.io.File) URL(java.net.URL) Before(org.junit.Before)

Example 53 with KieMavenRepository

use of org.kie.scanner.KieMavenRepository in project jbpm by kiegroup.

the class KjarRuntimeEnvironmentTest method testXStreamUnmarshalCustomObject.

@Test
public void testXStreamUnmarshalCustomObject() {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId(GROUP_ID, "xstream-test", VERSION);
    File kjar = new File("src/test/resources/kjar/jbpm-module.jar");
    File pom = new File("src/test/resources/kjar/pom.xml");
    KieMavenRepository repository = getKieMavenRepository();
    repository.installArtifact(releaseId, kjar, pom);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(releaseId).registerableItemsFactory(new DefaultRegisterableItemsFactory() {

        @Override
        public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
            Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
            handlers.put("Rest", new WorkItemHandler() {

                @Override
                public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
                    Map<String, Object> results = new HashMap<String, Object>();
                    results.put("Result", "<pv207.finepayment.Client><exists>true</exists><name>Pavel</name></pv207.finepayment.Client>");
                    manager.completeWorkItem(workItem.getId(), results);
                }

                @Override
                public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
                }
            });
            return handlers;
        }
    }).userGroupCallback(userGroupCallback).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
    assertNotNull(engine);
    Map<String, Object> params = new HashMap<String, Object>();
    ProcessInstance processInstance = engine.getKieSession().startProcess("RESTTask.RestProcess", params);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    Object processClient = ((WorkflowProcessInstance) processInstance).getVariable("processClient");
    assertNotNull(processClient);
    assertEquals("pv207.finepayment.Client", processClient.getClass().getName());
    assertEquals("Pavel", valueOf(processClient, "name"));
    assertEquals("true", valueOf(processClient, "exists"));
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 54 with KieMavenRepository

use of org.kie.scanner.KieMavenRepository in project jbpm by kiegroup.

the class QueryServiceEJBIntegrationTest method deployKjar.

protected static void deployKjar() {
    logger.debug("Preparing kjar");
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION);
    List<String> processes = new ArrayList<String>();
    processes.add("repo/processes/general/EmptyHumanTask.bpmn");
    processes.add("repo/processes/general/humanTask.bpmn");
    processes.add("repo/processes/general/BPMN2-UserTask.bpmn2");
    processes.add("repo/processes/general/SimpleHTProcess.bpmn2");
    processes.add("repo/processes/general/AdHocSubProcess.bpmn2");
    InternalKieModule kJar1 = createKieJar(ks, releaseId, processes);
    File pom = new File("target/kmodule", "pom.xml");
    pom.getParentFile().mkdir();
    try {
        FileOutputStream fs = new FileOutputStream(pom);
        fs.write(getPom(releaseId).getBytes());
        fs.close();
    } catch (Exception e) {
    }
    KieMavenRepository repository = getKieMavenRepository();
    repository.installArtifact(releaseId, kJar1, pom);
}
Also used : FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) File(java.io.File) QueryNotFoundException(org.jbpm.services.api.query.QueryNotFoundException) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 55 with KieMavenRepository

use of org.kie.scanner.KieMavenRepository in project jbpm by kiegroup.

the class RuntimeDataServiceImplSecurityTest method deployKjar.

protected static void deployKjar() {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION);
    List<String> processes = new ArrayList<String>();
    processes.add("processes/EmptyHumanTask.bpmn");
    processes.add("processes/humanTask.bpmn");
    processes.add("processes/SimpleHTProcess.bpmn2");
    DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.domain");
    customDescriptor.getBuilder().addRequiredRole("view:managers");
    Map<String, String> resources = new HashMap<String, String>();
    resources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml());
    InternalKieModule kJar1 = createKieJar(ks, releaseId, processes, resources);
    File pom = new File("target/kmodule", "pom.xml");
    pom.getParentFile().mkdir();
    try {
        FileOutputStream fs = new FileOutputStream(pom);
        fs.write(getPom(releaseId).getBytes());
        fs.close();
    } catch (Exception e) {
    }
    KieMavenRepository repository = getKieMavenRepository();
    repository.installArtifact(releaseId, kJar1, pom);
}
Also used : HashMap(java.util.HashMap) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) ArrayList(java.util.ArrayList) DeploymentDescriptorImpl(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) FileOutputStream(java.io.FileOutputStream) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Aggregations

KieMavenRepository (org.kie.scanner.KieMavenRepository)58 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)55 KieServices (org.kie.api.KieServices)54 ReleaseId (org.kie.api.builder.ReleaseId)53 File (java.io.File)51 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)51 FileOutputStream (java.io.FileOutputStream)45 ArrayList (java.util.ArrayList)42 Before (org.junit.Before)32 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)17 HashMap (java.util.HashMap)15 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)15 DeploymentDescriptorImpl (org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl)12 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)12 Test (org.junit.Test)10 KieContainer (org.kie.api.runtime.KieContainer)7 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)5 ObjectModel (org.kie.internal.runtime.conf.ObjectModel)5 IOException (java.io.IOException)4 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)4