@Test
  public void processIdAndProcessDefinitionTest() throws Exception {
    // JaxbProcessDefinition
    ProcessAssetDesc assetDesc =
        new ProcessAssetDesc(
            "org.test.proc.id",
            "The Name Of The Process",
            "1.999.23.Final",
            "org.test.proc",
            "RuleFlow",
            KnowledgeType.PROCESS.toString(),
            "org.test.proc",
            "org.test.proc:procs:1.999.Final");

    JaxbProcessDefinition jaxbProcDef = new JaxbProcessDefinition();
    jaxbProcDef.setDeploymentId(assetDesc.getDeploymentId());
    jaxbProcDef.setId(assetDesc.getId());
    jaxbProcDef.setName(assetDesc.getName());
    jaxbProcDef.setPackageName(assetDesc.getPackageName());
    jaxbProcDef.setVersion(assetDesc.getVersion());
    Map<String, String> forms = new HashMap<String, String>();
    forms.put("locationForm", "GPS: street: post code: city: state: land: planet: universe: ");
    jaxbProcDef.setForms(forms);

    JaxbProcessDefinition copyJaxbProcDef = testRoundTrip(jaxbProcDef);
    ComparePair.compareObjectsViaFields(jaxbProcDef, copyJaxbProcDef);
  }
예제 #2
0
  /**
   * Goes through all files in a deployment, and processes them so that they are then ready for use
   * after deployment.
   *
   * @param module The {@link InternalKieModule}, necessary to get form content
   * @param files The {@link List} of file (names) to process.
   * @param kieContainer The {@link KieContainer}, necesary in order to load classes
   * @param deploymentUnit The {@link DeploymentUnit}, necessary to get the deployment id
   * @param deployedUnit The {@link DeployedUnit}, which contains the results of actions here
   */
  protected void processResources(
      InternalKieModule module,
      Collection<String> files,
      KieContainer kieContainer,
      DeploymentUnit unit,
      DeployedUnitImpl deployedUnit,
      ReleaseId releaseId,
      Map<String, ProcessDescriptor> processes) {
    for (String fileName : files) {
      if (fileName.matches(".+bpmn[2]?$")) {
        ProcessAssetDesc process;
        try {
          String processString = new String(module.getBytes(fileName), "UTF-8");
          String processId = getProcessId(processString);
          ProcessDescriptor processDesriptor = processes.get(processId);
          if (processDesriptor != null) {
            process = processDesriptor.getProcess();
            if (process == null) {
              throw new IllegalArgumentException("Unable to read process " + fileName);
            }
            process.setEncodedProcessSource(Base64.encodeBase64String(processString.getBytes()));
            process.setDeploymentId(unit.getIdentifier());

            deployedUnit.addAssetLocation(process.getId(), process);
            bpmn2Service.addProcessDefinition(
                unit.getIdentifier(), processId, processDesriptor, kieContainer);
          }
        } catch (UnsupportedEncodingException e) {
          throw new IllegalArgumentException(
              "Unsupported encoding while processing process " + fileName);
        }
      } else if (fileName.matches(".+ftl$")
          || fileName.matches(".+form$")
          || fileName.matches(".+frm$")) {
        try {
          String formContent = new String(module.getBytes(fileName), "UTF-8");
          if (fileName.indexOf("/") != -1)
            fileName = fileName.substring(fileName.lastIndexOf("/") + 1);
          formManagerService.registerForm(unit.getIdentifier(), fileName, formContent);
        } catch (UnsupportedEncodingException e) {
          throw new IllegalArgumentException(
              "Unsupported encoding while processing form " + fileName);
        }
      } else if (fileName.matches(".+class$")) {
        // Classes 1: classes from deployment added
        String className = fileName.replaceAll("/", ".");
        className = className.substring(0, fileName.length() - ".class".length());
        Class deploymentClass = null;
        try {
          deploymentClass = kieContainer.getClassLoader().loadClass(className);
        } 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(deploymentClass, deployedUnit);
      }
    }
  }