@Test
  public void testDeploymentOfProcessesKieConteinerInjection() {

    assertNotNull(deploymentService);

    KModuleDeploymentUnit deploymentUnit =
        new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION, "KBase-test", "ksession-test-2");

    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);

    assertNotNull(deploymentUnit.getDeploymentDescriptor());

    DeployedUnit deployed = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
    assertNotNull(deployed);
    assertNotNull(deployed.getDeploymentUnit());
    assertNotNull(deployed.getRuntimeManager());
    assertNull(deployed.getDeployedAssetLocation("customtask"));
    assertEquals(
        GROUP_ID + ":" + ARTIFACT_ID + ":" + VERSION + ":" + "KBase-test" + ":" + "ksession-test-2",
        deployed.getDeploymentUnit().getIdentifier());

    RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnit.getIdentifier());
    assertNotNull(manager);

    RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
    assertNotNull(engine);

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("id", "test");
    ProcessInstance processInstance = engine.getKieSession().startProcess("customtask", params);

    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    manager.disposeRuntimeEngine(engine);
  }
  @Test
  public void testStartProcess() throws InterruptedException {
    assertNotNull(deploymentService);

    KModuleDeploymentUnit deploymentUnit =
        new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);

    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    assertNotNull(processService);

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("expiresAt", "2s");

    long processInstanceId =
        processService.startProcess(
            deploymentUnit.getIdentifier(), "timer-test.timer-process", params);
    assertNotNull(processInstanceId);

    ProcessInstance pi = processService.getProcessInstance(processInstanceId);
    assertNotNull(pi);

    Thread.sleep(3000);

    pi = processService.getProcessInstance(processInstanceId);
    assertNull(pi);
  }
  @Test
  public void testDeploymentOfProcesses() {

    assertNotNull(deploymentService);

    KModuleDeploymentUnit deploymentUnit =
        new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION, "KBase-test", "ksession-test");

    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);

    assertNotNull(deploymentUnit.getDeploymentDescriptor());

    DeployedUnit deployed = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
    assertNotNull(deployed);
    assertNotNull(deployed.getDeploymentUnit());
    assertNotNull(deployed.getRuntimeManager());
    assertNull(deployed.getDeployedAssetLocation("customtask"));
    assertEquals(
        GROUP_ID + ":" + ARTIFACT_ID + ":" + VERSION + ":" + "KBase-test" + ":" + "ksession-test",
        deployed.getDeploymentUnit().getIdentifier());

    assertNotNull(runtimeDataService);
    Collection<ProcessDefinition> processes = runtimeDataService.getProcesses(new QueryContext());
    assertNotNull(processes);
    assertEquals(3, processes.size());

    processes = runtimeDataService.getProcessesByFilter("custom", new QueryContext());
    assertNotNull(processes);
    assertEquals(1, processes.size());

    processes =
        runtimeDataService.getProcessesByDeploymentId(
            deploymentUnit.getIdentifier(), new QueryContext());
    assertNotNull(processes);
    assertEquals(3, processes.size());

    ProcessDefinition process = runtimeDataService.getProcessById("customtask");
    assertNotNull(process);

    RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnit.getIdentifier());
    assertNotNull(manager);

    RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
    assertNotNull(engine);

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("id", "test");
    ProcessInstance processInstance = engine.getKieSession().startProcess("customtask", params);

    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
  }
 protected RegisterableItemsFactory getRegisterableItemsFactory(
     AuditEventBuilder auditLoggerBuilder, KieContainer kieContainer, KModuleDeploymentUnit unit) {
   KModuleRegisterableItemsFactory factory =
       new KModuleRegisterableItemsFactory(kieContainer, unit.getKsessionName());
   factory.setAuditBuilder(auditLoggerBuilder);
   return factory;
 }
  @Override
  protected RegisterableItemsFactory getRegisterableItemsFactory(
      AuditEventBuilder auditLoggerBuilder, KieContainer kieContainer, KModuleDeploymentUnit unit) {

    return InjectableRegisterableItemsFactory.getFactory(
        beanManager, auditLoggerBuilder, kieContainer, unit.getKsessionName());
  }
  @Test
  public void deploymentObjectsTest() throws Exception {
    Assume.assumeFalse(getType().equals(TestType.YAML));

    // for test at end, fill during test
    JaxbDeploymentUnitList depUnitList = new JaxbDeploymentUnitList();

    // dep jobs
    JaxbDeploymentJobResult jaxbJob = new JaxbDeploymentJobResult();
    testRoundTrip(jaxbJob);

    // complex dep jobs
    KModuleDeploymentUnit kDepUnit =
        new KModuleDeploymentUnit("org", "jar", "1.0", "kbase", "ksession");
    kDepUnit.setStrategy(RuntimeStrategy.PER_PROCESS_INSTANCE);

    JaxbDeploymentUnit depUnit =
        new JaxbDeploymentUnit(
            kDepUnit.getGroupId(), kDepUnit.getArtifactId(), kDepUnit.getArtifactId());
    depUnit.setKbaseName(kDepUnit.getKbaseName());
    depUnit.setKsessionName(kDepUnit.getKsessionName());
    depUnit.setStrategy(kDepUnit.getStrategy());
    depUnit.setStatus(JaxbDeploymentStatus.NONEXISTENT);
    depUnitList.getDeploymentUnitList().add(depUnit);

    jaxbJob = new JaxbDeploymentJobResult(null, "test", depUnit, "deploy");
    jaxbJob.setIdentifier(23L);
    jaxbJob.setSuccess(false);
    JaxbDeploymentJobResult copyJaxbJob = testRoundTrip(jaxbJob);
    ComparePair.compareObjectsViaFields(jaxbJob, copyJaxbJob, "jobId", "identifier");

    depUnit = new JaxbDeploymentUnit("g", "a", "v");
    depUnit.setKbaseName("kbase");
    depUnit.setKsessionName("ksession");
    depUnit.setStatus(JaxbDeploymentStatus.DEPLOY_FAILED);
    depUnit.setStrategy(RuntimeStrategy.PER_PROCESS_INSTANCE);
    depUnitList.getDeploymentUnitList().add(depUnit);

    JaxbDeploymentUnit copyDepUnit = testRoundTrip(depUnit);

    ComparePair.compareObjectsViaFields(depUnit, copyDepUnit, "identifier");

    JaxbDeploymentJobResult depJob =
        new JaxbDeploymentJobResult(null, "testing stuff", copyDepUnit, "test");
    depJob.setSuccess(true);
    JaxbDeploymentJobResult copyDepJob = testRoundTrip(depJob);

    ComparePair.compareObjectsViaFields(copyDepJob, depJob, "jobId", "identifier");

    JaxbDeploymentUnitList roundTripUnitList = testRoundTrip(depUnitList);
    ComparePair.compareObjectsViaFields(
        depUnitList.getDeploymentUnitList().get(0),
        roundTripUnitList.getDeploymentUnitList().get(0),
        "jobId",
        "identifier");
  }
  @Override
  public void undeploy(DeploymentUnit unit) {
    if (!(unit instanceof KModuleDeploymentUnit)) {
      throw new IllegalArgumentException(
          "Invalid deployment unit provided - " + unit.getClass().getName());
    }
    KModuleDeploymentUnit kmoduleUnit = (KModuleDeploymentUnit) unit;
    super.undeploy(unit);

    formManagerService.unRegisterForms(unit.getIdentifier());

    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId =
        ks.newReleaseId(
            kmoduleUnit.getGroupId(), kmoduleUnit.getArtifactId(), kmoduleUnit.getVersion());
    ks.getRepository().removeKieModule(releaseId);
  }
Exemple #8
0
  /**
   * Returns a RuntimeManager from the ProcessEngineService for the given KModuleDeploymentUnit.
   * Creates a RuntimeManager if it didn't already exist.
   *
   * @param processEngineService
   * @param unit
   * @return RuntimeManager
   */
  public RuntimeManager getRuntimeManager(
      ProcessEngineService processEngineService, KModuleDeploymentUnit unit) {

    // First see if we have one
    RuntimeManager runtimeManager = processEngineService.getRuntimeManager(unit.getIdentifier());
    if (runtimeManager == null) {
      if (isSRAMPPackageDeployed(unit.getGroupId(), unit.getArtifactId(), unit.getVersion())) {
        unit.setStrategy(RuntimeStrategy.PER_PROCESS_INSTANCE);
        processEngineService.deployUnit(unit);
        runtimeManager = processEngineService.getRuntimeManager(unit.getIdentifier());
        logger.info(
            Messages.i18n.format(
                "KieSrampUtil.FoundAndDeployed", unit.getIdentifier())); // $NON-NLS-1$
      } else {
        logger.error(
            Messages.i18n.format("KieSrampUtil.NotFound", unit.getIdentifier())); // $NON-NLS-1$
        throw new IllegalStateException(
            Messages.i18n.format("KieSrampUtil.NotFound", unit.getIdentifier())); // $NON-NLS-1$
      }
    }
    return runtimeManager;
  }
  @Test
  public void testStartProcessWithHTDeadline() throws InterruptedException {
    assertNotNull(deploymentService);

    KModuleDeploymentUnit deploymentUnit =
        new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);

    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    assertNotNull(processService);

    processInstanceId =
        processService.startProcess(deploymentUnit.getIdentifier(), "htdeadlinetest");

    List<TaskSummary> krisTasks =
        runtimeDataService.getTasksAssignedAsPotentialOwner("krisv", new QueryFilter());
    assertEquals(1, krisTasks.size());
    List<TaskSummary> johnTasks =
        runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
    assertEquals(0, johnTasks.size());
    List<TaskSummary> maryTasks =
        runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
    assertEquals(0, maryTasks.size());

    // now wait for 2 seconds for first reassignment
    Thread.sleep(3000);

    krisTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("krisv", new QueryFilter());
    assertEquals(0, krisTasks.size());
    johnTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
    assertEquals(1, johnTasks.size());
    maryTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
    assertEquals(0, maryTasks.size());

    userTaskService.start(johnTasks.get(0).getId(), "john");

    // now wait for 2 more seconds for second reassignment
    Thread.sleep(2000);
    krisTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("krisv", new QueryFilter());
    assertEquals(0, krisTasks.size());
    johnTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
    assertEquals(1, johnTasks.size());
    maryTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
    assertEquals(0, maryTasks.size());

    // now wait for 1 seconds to make sure that reassignment did not happen any more since task was
    // already started
    Thread.sleep(3000);

    krisTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("krisv", new QueryFilter());
    assertEquals(0, krisTasks.size());
    johnTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
    assertEquals(0, johnTasks.size());
    maryTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
    assertEquals(1, maryTasks.size());
    userTaskService.start(maryTasks.get(0).getId(), "mary");
    userTaskService.complete(maryTasks.get(0).getId(), "mary", null);

    // now wait for 2 seconds to make sure that reassignment did not happen any more since task was
    // completed
    Thread.sleep(2000);

    ProcessInstance processInstance = processService.getProcessInstance(processInstanceId);
    assertNull(processInstance);
    processInstanceId = null;
  }
  /**
   * This creates and fills a {@link RuntimeEnvironmentBuilder} instance, which is later used when
   * creating services. A lot of the logic here is used to process the information in the {@link
   * DeploymentDescriptor} instance, which is part of the {@link DeploymentUnit}.
   *
   * @param deploymentUnit The {@link KModuleDeploymentUnit}, which is filled by the method
   * @param deployedUnit The {@link DeployedUnit}, which is also filled by the method
   * @param kieContainer The {@link KieContainer}, which contains information needed to fill the
   *     above two arguments
   * @param mode The {@link MergeMode} used to resolve conflicts in the {@link
   *     DeploymentDescriptor}.
   * @return A {@link RuntimeEnvironmentBuilder} instance ready for use
   */
  protected RuntimeEnvironmentBuilder boostrapRuntimeEnvironmentBuilder(
      KModuleDeploymentUnit deploymentUnit,
      DeployedUnit deployedUnit,
      KieContainer kieContainer,
      MergeMode mode) {
    DeploymentDescriptor descriptor = deploymentUnit.getDeploymentDescriptor();
    if (descriptor == null
        || ((DeploymentDescriptorImpl) descriptor)
            .isEmpty()) { // skip empty descriptors as its default can override settings
      DeploymentDescriptorManager descriptorManager =
          new DeploymentDescriptorManager("org.jbpm.domain");
      List<DeploymentDescriptor> descriptorHierarchy =
          descriptorManager.getDeploymentDescriptorHierarchy(kieContainer);

      descriptor = merger.merge(descriptorHierarchy, mode);
      deploymentUnit.setDeploymentDescriptor(descriptor);
    } else if (descriptor != null && !deploymentUnit.isDeployed()) {
      DeploymentDescriptorManager descriptorManager =
          new DeploymentDescriptorManager("org.jbpm.domain");
      List<DeploymentDescriptor> descriptorHierarchy =
          descriptorManager.getDeploymentDescriptorHierarchy(kieContainer);

      descriptorHierarchy.add(0, descriptor);
      descriptor = merger.merge(descriptorHierarchy, mode);
      deploymentUnit.setDeploymentDescriptor(descriptor);
    }

    // first set on unit the strategy
    deploymentUnit.setStrategy(descriptor.getRuntimeStrategy());

    // setting up runtime environment via builder
    RuntimeEnvironmentBuilder builder = null;
    if (descriptor.getPersistenceMode() == PersistenceMode.NONE) {
      builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultInMemoryBuilder();
    } else {
      builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder();
    }
    // populate various properties of the builder
    EntityManagerFactory emf =
        EntityManagerFactoryManager.get().getOrCreate(descriptor.getPersistenceUnit());
    builder.entityManagerFactory(emf);

    Map<String, Object> contaxtParams = new HashMap<String, Object>();
    contaxtParams.put("entityManagerFactory", emf);
    contaxtParams.put("classLoader", kieContainer.getClassLoader());
    // process object models that are globally configured (environment entries, session
    // configuration)
    for (NamedObjectModel model : descriptor.getEnvironmentEntries()) {
      Object entry = getInstanceFromModel(model, kieContainer, contaxtParams);
      builder.addEnvironmentEntry(model.getName(), entry);
    }

    for (NamedObjectModel model : descriptor.getConfiguration()) {
      Object entry = getInstanceFromModel(model, kieContainer, contaxtParams);
      builder.addConfiguration(model.getName(), (String) entry);
    }
    ObjectMarshallingStrategy[] mStrategies =
        new ObjectMarshallingStrategy[descriptor.getMarshallingStrategies().size() + 1];
    int index = 0;
    for (ObjectModel model : descriptor.getMarshallingStrategies()) {
      Object strategy = getInstanceFromModel(model, kieContainer, contaxtParams);
      mStrategies[index] = (ObjectMarshallingStrategy) strategy;
      index++;
    }
    // lastly add the main default strategy
    mStrategies[index] =
        new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT);
    builder.addEnvironmentEntry(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, mStrategies);

    builder.addEnvironmentEntry("KieDeploymentDescriptor", descriptor);
    builder.addEnvironmentEntry("KieContainer", kieContainer);
    if (executorService != null) {
      builder.addEnvironmentEntry("ExecutorService", executorService);
    }
    // populate all assets with roles for this deployment unit
    List<String> requiredRoles = descriptor.getRequiredRoles(DeploymentDescriptor.TYPE_VIEW);
    if (requiredRoles != null && !requiredRoles.isEmpty()) {
      for (DeployedAsset desc : deployedUnit.getDeployedAssets()) {
        if (desc instanceof ProcessAssetDesc) {
          ((ProcessAssetDesc) desc).setRoles(requiredRoles);
        }
      }
    }

    // Classes 3: classes added from descriptor
    List<String> remoteableClasses = descriptor.getClasses();
    if (remoteableClasses != null && !remoteableClasses.isEmpty()) {
      for (String className : remoteableClasses) {
        Class descriptorClass = null;
        try {
          descriptorClass = kieContainer.getClassLoader().loadClass(className);
          logger.debug(
              "Loaded {} into the classpath from deployment descriptor {}",
              className,
              kieContainer.getReleaseId().toExternalForm());
        } catch (ClassNotFoundException cnfe) {
          throw new IllegalArgumentException("Class " + className + " not found in the project");
        } catch (NoClassDefFoundError e) {
          throw new IllegalArgumentException("Class " + className + " not found in the project");
        }
        addClassToDeployedUnit(descriptorClass, (DeployedUnitImpl) deployedUnit);
      }
    }

    return builder;
  }
  @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);

      // 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());

        MavenRepository repository = getMavenRepository();
        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"));
      }

      // 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);
    }
  }
  @Override
  public void deploy(DeploymentUnit unit) {
    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);
    KieServices ks = KieServices.Factory.get();
    MavenRepository repository = getMavenRepository();
    repository.resolveArtifact(kmoduleUnit.getIdentifier());

    ReleaseId releaseId =
        ks.newReleaseId(
            kmoduleUnit.getGroupId(), kmoduleUnit.getArtifactId(), kmoduleUnit.getVersion());
    KieContainer kieContainer = ks.newKieContainer(releaseId);

    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 with name " + kbaseName);
    }

    Map<String, String> formsData = new HashMap<String, String>();
    Collection<String> files = module.getFileNames();
    for (String fileName : files) {
      if (fileName.matches(".+bpmn[2]?$")) {
        ProcessDesc process;
        try {
          String processString = new String(module.getBytes(fileName), "UTF-8");
          process = bpmn2Service.findProcessId(processString, kieContainer.getClassLoader());
          process.setEncodedProcessSource(Base64.encodeBase64String(processString.getBytes()));
          process.setDeploymentId(unit.getIdentifier());
          process.setForms(formsData);
          deployedUnit.addAssetLocation(process.getId(), process);
        } catch (UnsupportedEncodingException e) {
          logger.warn("Unable to load content for file '{}' : {}", fileName, e);
        }
      } else if (fileName.matches(".+ftl$")) {
        try {
          String formContent = new String(module.getBytes(fileName), "UTF-8");
          Pattern regex = Pattern.compile("(.{0}|.*/)([^/]*?)\\.ftl");
          Matcher m = regex.matcher(fileName);
          String key = fileName;
          while (m.find()) {
            key = m.group(2);
          }
          formsData.put(key, formContent);
        } catch (UnsupportedEncodingException e) {
          logger.warn("Unable to load content for form '{}' : {}", fileName, e);
        }
      } else if (fileName.matches(".+form$")) {
        try {
          String formContent = new String(module.getBytes(fileName), "UTF-8");
          Pattern regex = Pattern.compile("(.{0}|.*/)([^/]*?)\\.form");
          Matcher m = regex.matcher(fileName);
          String key = fileName;
          while (m.find()) {
            key = m.group(2);
          }
          formsData.put(key + ".form", formContent);
        } catch (UnsupportedEncodingException e) {
          logger.warn("Unable to load content for form '{}' : {}", fileName, e);
        }
      }
    }

    KieBase kbase = kieContainer.getKieBase(kbaseName);

    AbstractAuditLogger auditLogger = getAuditLogger();
    ServicesAwareAuditEventBuilder auditEventBuilder = new ServicesAwareAuditEventBuilder();
    auditEventBuilder.setIdentityProvider(identityProvider);
    auditEventBuilder.setDeploymentUnitId(unit.getIdentifier());
    auditLogger.setBuilder(auditEventBuilder);

    RuntimeEnvironmentBuilder builder =
        RuntimeEnvironmentBuilder.getDefault()
            .entityManagerFactory(getEmf())
            .knowledgeBase(kbase)
            .classLoader(kieContainer.getClassLoader());
    if (beanManager != null) {
      builder.registerableItemsFactory(
          InjectableRegisterableItemsFactory.getFactory(
              beanManager, auditLogger, kieContainer, kmoduleUnit.getKsessionName()));
    }
    commonDeploy(unit, deployedUnit, builder.get());
  }