Search in sources :

Example 1 with AuditEventBuilder

use of org.jbpm.process.audit.event.AuditEventBuilder 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)

Aggregations

HashMap (java.util.HashMap)1 DependencyFilter (org.appformer.maven.support.DependencyFilter)1 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)1 ProcessDescriptor (org.jbpm.kie.services.impl.bpmn2.ProcessDescriptor)1 AuditEventBuilder (org.jbpm.process.audit.event.AuditEventBuilder)1 KieBase (org.kie.api.KieBase)1 KieServices (org.kie.api.KieServices)1 ReleaseId (org.kie.api.builder.ReleaseId)1 KieBaseModel (org.kie.api.builder.model.KieBaseModel)1 KieContainer (org.kie.api.runtime.KieContainer)1 RuntimeEnvironmentBuilder (org.kie.api.runtime.manager.RuntimeEnvironmentBuilder)1 KieMavenRepository (org.kie.scanner.KieMavenRepository)1 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)1