Package org.jbpm.pvm.internal.env

Examples of org.jbpm.pvm.internal.env.Environment


    DecisionHandler usedDecisionHandler = null;
    if (decisionHandler!=null) {
      usedDecisionHandler = decisionHandler;
     
    } else if (decisionHandlerName!=null) {
      Environment environment = Environment.getCurrent();
      Object object = environment.get(decisionHandlerName);
      if (object==null) {
        throw new JbpmException("decision handler for "+activity+" is null");
      }
      if (! (object instanceof DecisionHandler)) {
        throw new JbpmException("handler for decision is not a "+DecisionHandler.class.getName()+": "+object.getClass().getName());
View Full Code Here


  private static final long serialVersionUID = 1L;

  public void notify(EventListenerExecution execution) throws Exception {
    // find current task
    Environment environment = Environment.getCurrent();
    DbSession dbSession = environment.get(DbSession.class);
    TaskImpl task = dbSession.findTaskByExecution(execution);

    // make task available to mail templates through task context
    TaskContext taskContext = new TaskContext(task);
    environment.setContext(taskContext);
    try {
      Collection<Message> messages = mailProducer.produce(execution);
      environment.get(MailSession.class).send(messages);
    } finally {
      environment.removeContext(taskContext);
    }
  }
View Full Code Here

  protected ListDescriptor parametersDescriptor;
  protected String resultVariableName;
  protected boolean isResultUnique;

  public void perform(OpenExecution execution) {
    Environment environment = Environment.getCurrent();
    if (environment==null) {
      throw new JbpmException("no environment for jpdl activity "+HqlBinding.TAG);
    }
    Session session = environment.get(Session.class);
   
    Query q = createQuery(session);
   
    if (parametersDescriptor!=null) {
      for (Descriptor valueDescriptor: parametersDescriptor.getValueDescriptors()) {
View Full Code Here

    String transitionName = null;

    ExecutionContext originalExecutionContext = null;
    ExecutionContext subProcessExecutionContext = null;
    Environment environment = Environment.getCurrent();
    if (environment!=null) {
      originalExecutionContext = (ExecutionContext) environment.removeContext(Context.CONTEXTNAME_EXECUTION);
      subProcessExecutionContext = new ExecutionContext((ExecutionImpl) subProcessInstance);
      environment.setContext(subProcessExecutionContext);
    }

    try {
      subProcessInstance.setSuperProcessExecution(null);
      executionImpl.setSubProcessInstance(null);
     

      for (SubProcessOutParameterImpl outParameter: outParameters) {
        outParameter.consume(executionImpl, subProcessInstance);
      }
     
      Activity activity = execution.getActivity();
      String subProcessActivityName = subProcessInstance.getActivityName();
     
      if (outcomeExpression!=null) {
        ScriptManager scriptManager = Environment.getFromCurrent(ScriptManager.class);
        Object value = scriptManager.evaluateExpression(outcomeExpression, null);
        // if the value is a String and matches the name of an outgoing transition
        if ( (value instanceof String)
             && (activity.hasOutgoingTransition(((String) value)))
           ) {
          // then take that one
          transitionName = (String) value;
        } else {
          // else see if there is a value mapping
          transitionName = outcomeVariableMappings.get(value);
        }

      } else if (activity.hasOutgoingTransition(subProcessActivityName)) {
        transitionName = subProcessActivityName;
      }

    } finally {
      if (subProcessExecutionContext!=null) {
        environment.removeContext(subProcessExecutionContext);
      }
      if (originalExecutionContext!=null) {
        environment.setContext(originalExecutionContext);
      }
    }
   
    executionImpl.historyActivityEnd();
View Full Code Here

  private String getStartFormName(String id)
  {
    String name = null;

    Environment env = ((EnvironmentFactory)processEngine).openEnvironment();
    try
    {
      RepositoryService repoService = processEngine.getRepositoryService();
      List<String> startActivityNames = repoService.getStartActivityNames(id);

      if(null==startActivityNames) // who knows? I'd expect anything from jbpm
        throw new RuntimeException("Unable to resolve start activity names for process: "+id);

      String defaultActitvity = startActivityNames.get(0);
      if(startActivityNames.size()>1)
      {
        System.out.println("WARN: More then 1 start activity found. Default to " + defaultActitvity + " to resolve the form name.");
      }

      name = repoService.getStartFormResourceName(id, defaultActitvity);      
    }
    finally{
      env.close();
    }

    return name;
  }
View Full Code Here

    return name;
  }

  public DataHandler provideForm(FormAuthorityRef ref)
  {
    Environment env = ((EnvironmentFactory)processEngine).openEnvironment();

    DataHandler result = null;

    try
    {

      RepositoryService repoService = processEngine.getRepositoryService();

      // check if a template exists
      String startFormResourceName = getStartFormName(ref.getReferenceId());
      if(null==startFormResourceName)
        throw new IllegalArgumentException("Process " +ref.getReferenceId() + " doesn't provide a start form");

      ProcessDefinition procDef =
          repoService
              .createProcessDefinitionQuery()
              .processDefinitionId(ref.getReferenceId())
              .uniqueResult();

      InputStream template = repoService.getResourceAsStream(
          procDef.getDeploymentId(), startFormResourceName
      );

      // merge template with process variables
      if(template!=null)
      {
        // plugin context
        StringBuilder action = getBaseUrl();
        action.append("/form/process/");
        action.append( ref.getReferenceId() );
        action.append("/complete");

        Map<String, Object> renderContext = new HashMap<String,Object>();

        // form directive
        FormDirective formDirective = new FormDirective();
        formDirective.setAction( action.toString() );
        renderContext.put(FORM_DIRECTIVE_KEY, formDirective);

        // outcome directive
        renderContext.put(OUTCOME_DIRECTIVE_NAME, new OutcomeDirective());

        result = processTemplate(startFormResourceName, template, renderContext);
      }

      return result;
    }
    finally{
      env.close();
    }
  }
View Full Code Here

  private boolean taskHasForm(String id)
  {
    boolean result = false;

    Environment env = ((EnvironmentFactory)processEngine).openEnvironment();
    try
    {
      TaskService taskService = processEngine.getTaskService();
      Task task = taskService.getTask(id);
      result = (task.getFormResourceName()!=null);
    }
    finally
    {
      env.close();
    }

    return result;
  }
View Full Code Here

    return result;
  }

  public DataHandler provideForm(FormAuthorityRef ref)
  {
    Environment env = ((EnvironmentFactory)processEngine).openEnvironment();
  
    try
    {
      TaskService taskService = processEngine.getTaskService();
      Task task = taskService.getTask(ref.getReferenceId());

      // access the processdefition
      TaskImpl cast = ((TaskImpl) task);
      ExecutionImpl processInstance = cast.getProcessInstance();
      String processInstanceId =  processInstance.getId();
      String processId =  processInstance.getProcessDefinition().getId();

      RepositoryService repoService = processEngine.getRepositoryService();
      ProcessDefinitionQuery query = repoService.createProcessDefinitionQuery();
      query.processDefinitionId(processId);
      ProcessDefinition procDef = query.uniqueResult();

      // check if a template exists
      String name = task.getFormResourceName();
      InputStream template = repoService.getResourceAsStream(
          procDef.getDeploymentId(), name
      );

      // merge template with process variables
      if(template==null)
        throw new IllegalArgumentException("Task form resource '"+name+"' doesn't exist.");

      Map<String, Object> processContext = new HashMap<String, Object>(); // empty default
      ExecutionService execService = processEngine.getExecutionService();
      Set<String> varNames = execService.getVariableNames(processInstanceId);

      if(varNames!=null)
        processContext = execService.getVariables(processInstanceId, varNames);

      // plugin context
      StringBuilder action = getBaseUrl();
      action.append("/form/task/");
      action.append( ref.getReferenceId() );
      action.append("/complete");

      Map<String, Object> renderContext = new HashMap<String,Object>();

      // form directive
      FormDirective formDirective = new FormDirective();
      formDirective.setAction( action.toString() );
      renderContext.put(FORM_DIRECTIVE_KEY, formDirective);

      // outcome directive
      // TODO: Fix when https://jira.jboss.org/jira/browse/JBPM-2220 is done
      OutcomeDirective outcomeDirective = new OutcomeDirective();
      List<Transition> transitions =
          ((ExecutionImpl) processInstance).getActivity().getOutgoingTransitions();
      for(Transition t : transitions)
      {
        String outcomeName = t.getName()!=null ? t.getName() : "to_"+t.getDestination().getName();
        outcomeDirective.getValues().add(outcomeName);
      }
      renderContext.put(OUTCOME_DIRECTIVE_NAME, outcomeDirective);

      // process variables
      renderContext.putAll(processContext);

      DataHandler result = processTemplate(name, template, renderContext);
      return result;
    }
    finally
    {
      env.close();
    }
  }
View Full Code Here

  }

  public byte[] getProcessImage(String processId)
  {

    Environment env = ((EnvironmentFactory)processEngine).openEnvironment();

    try
    {
      RepositoryService repositoryService = this.processEngine.getRepositoryService();
      ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
          .processDefinitionId(processId)
          .uniqueResult();

      String imgRes = processDefinition.getImageResourceName();
      InputStream in = repositoryService.getResourceAsStream(
          processDefinition.getDeploymentId(), imgRes
      );

      if(null==in)
        throw new RuntimeException("Failed to retrieve image resource: " +imgRes);

      ByteArrayOutputStream out = new ByteArrayOutputStream();
      final int BUF_SIZE = 1 << 8; //1KiB buffer
      byte[] buffer = new byte[BUF_SIZE];
      int bytesRead = -1;
      try
      {
        while((bytesRead = in.read(buffer)) > -1)
        {
          out.write(buffer, 0, bytesRead);
        }
        in.close();
      }
      catch (IOException e)
      {
        throw new RuntimeException("Failed to read image resource: "+imgRes, e);
      }

      byte[] imageBytes = out.toByteArray();

      return imageBytes;

    }
    finally{
      env.close();
    }
  }
View Full Code Here

  public List<ActiveNodeInfo> getActiveNodeInfo(String instanceId)
  {

    List<ActiveNodeInfo> results = new ArrayList<ActiveNodeInfo>();

    Environment env = ((EnvironmentFactory)processEngine).openEnvironment();

    try
    {
      ExecutionService execService = this.processEngine.getExecutionService();
      ProcessInstanceQuery query = execService.createProcessInstanceQuery();
      query.processInstanceId(instanceId);
      ExecutionImpl processInstance = (ExecutionImpl) query.uniqueResult();

      String currentActivity = processInstance.getProcessInstance().getActivityName();

      // get coordinates
      RepositoryService repoService = this.processEngine.getRepositoryService();
      ActivityCoordinates coords = repoService.getActivityCoordinates(
          processInstance.getProcessDefinitionId(), currentActivity
      );


      results.add(new ActiveNodeInfo(
          coords.getWidth(), coords.getHeight(),
          new DiagramNodeInfo(
              currentActivity,
              coords.getX(), coords.getY(),
              coords.getWidth(), coords.getHeight()
          )
      )
      );

    }
    finally
    {
      env.close();
    }

    return results;
  }
View Full Code Here

TOP

Related Classes of org.jbpm.pvm.internal.env.Environment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.