Search in sources :

Example 11 with ProcessAssetDesc

use of org.jbpm.kie.services.impl.model.ProcessAssetDesc in project jbpm by kiegroup.

the class KModuleDeploymentService method processResources.

/**
 * 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);
        }
    }
}
Also used : ProcessAssetDesc(org.jbpm.kie.services.impl.model.ProcessAssetDesc) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ProcessDescriptor(org.jbpm.kie.services.impl.bpmn2.ProcessDescriptor)

Example 12 with ProcessAssetDesc

use of org.jbpm.kie.services.impl.model.ProcessAssetDesc in project jbpm by kiegroup.

the class InMemoryFormProvider method render.

@Override
public String render(String name, ProcessDefinition process, Map<String, Object> renderContext) {
    ProcessAssetDesc asset = null;
    if (!(process instanceof ProcessAssetDesc)) {
        return null;
    }
    String templateString = formManagerService.getFormByKey(process.getDeploymentId(), process.getId());
    if (templateString == null) {
        templateString = formManagerService.getFormByKey(process.getDeploymentId(), process.getId() + getFormSuffix());
    }
    if (templateString == null || templateString.isEmpty()) {
        return null;
    } else {
        return render(name, new ByteArrayInputStream(templateString.getBytes()), renderContext);
    }
}
Also used : ProcessAssetDesc(org.jbpm.kie.services.impl.model.ProcessAssetDesc) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 13 with ProcessAssetDesc

use of org.jbpm.kie.services.impl.model.ProcessAssetDesc in project jbpm by kiegroup.

the class BPMN2DataServiceImpl method fillProcessDefinition.

private ProcessAssetDesc fillProcessDefinition(ProcessDescriptor helper, KieContainer kieContainer) {
    ProcessAssetDesc definition = helper.getProcess();
    definition.setAssociatedEntities(helper.getTaskAssignments());
    definition.setProcessVariables(helper.getInputs());
    definition.setServiceTasks(helper.getServiceTasks());
    definition.setSignals(helper.getSignals());
    definition.setGlobals(helper.getGlobals());
    definition.setReferencedRules(helper.getReferencedRules());
    if (kieContainer != null && helper.hasUnresolvedReusableSubProcessNames()) {
        helper.resolveReusableSubProcessNames(kieContainer.getKieBase().getProcesses());
    }
    definition.setReusableSubProcesses(helper.getReusableSubProcesses());
    return definition;
}
Also used : ProcessAssetDesc(org.jbpm.kie.services.impl.model.ProcessAssetDesc)

Aggregations

ProcessAssetDesc (org.jbpm.kie.services.impl.model.ProcessAssetDesc)13 HashSet (java.util.HashSet)3 DeployedAsset (org.jbpm.services.api.model.DeployedAsset)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ProcessDefinition (org.jbpm.services.api.model.ProcessDefinition)2 Process (org.kie.api.definition.process.Process)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toMap (java.util.stream.Collectors.toMap)1