Package org.jbpm.context.exe

Examples of org.jbpm.context.exe.ContextInstance


     * @see org.jbpm.graph.def.ActionHandler#execute(org.jbpm.graph.exe.ExecutionContext)
     */
    public void execute(ExecutionContext context) throws Exception {
     
      String pathTmpFold = null;
    ContextInstance contextInstance = null;
    File tempDir = null;
    IDossierDAO dossierDAO = null;
    logger.debug("IN");
    try {
        // RECOVER CONFIGURATION PARAMETER
        contextInstance = context.getContextInstance();
        logger.debug("Context Instance retrived " + contextInstance);
        ProcessInstance processInstance = context.getProcessInstance();
        Long workflowProcessId = new Long(processInstance.getId());
        String dossierIdStr = (String) contextInstance.getVariable(DossierConstants.DOSSIER_ID);
        logger.debug("Dossier id variable retrived " + dossierIdStr);
        Integer dossierId = new Integer(dossierIdStr);
        BIObject dossier = DAOFactory.getBIObjectDAO().loadBIObjectById(dossierId);
        dossier.setBiObjectParameters(DAOFactory.getBIObjectDAO().getBIObjectParameters(dossier));
        setAnalyticalDriversValues(dossier, (Map) contextInstance.getVariable(DossierConstants.DOSSIER_PARAMETERS));
        logger.debug("Dossier variable retrived " + dossier);
        dossierDAO = DAOFactory.getDossierDAO();
        pathTmpFold = dossierDAO.init(dossier);
        logger.debug("Using tmp folder path " + pathTmpFold);
        ConfigSingleton config = ConfigSingleton.getInstance();
        tempDir = new File(pathTmpFold);
        logger.debug("Create tmp folders " + tempDir);
 
        // GETS OO TEMPLATE AND WRITE IT INTO THE TMP DIRECTORY
        String templateFileName = dossierDAO.getPresentationTemplateFileName(pathTmpFold);
        logger.debug("dossier oo template name retrived " + templateFileName);
        InputStream contentTempIs = null;
        byte[] contentTempBytes = null;
        try {
          contentTempIs = dossierDAO.getPresentationTemplateContent(pathTmpFold);
          logger.debug("dossier oo template input stream retrived " + contentTempIs);
          contentTempBytes = GeneralUtilities.getByteArrayFromInputStream(contentTempIs);
          logger.debug("dossier oo template bytes retrived ");
        } finally {
          if (contentTempIs != null) contentTempIs.close();
        }
        // write template content into a temp file
        File templateOOFile = new File(tempDir, templateFileName);
        FileOutputStream fosTemplate = new FileOutputStream(templateOOFile);
        fosTemplate.write(contentTempBytes);
        logger.debug("oo template bytes written into a tmp file ");
        fosTemplate.flush();
        fosTemplate.close();
 
        // INITIALIZE OFFICE ENVIRONMENT
        SourceBean officeConnectSB = (SourceBean) config.getAttribute("DOSSIER.OFFICECONNECTION");
        if (officeConnectSB == null) {
          logger.error("Cannot found sourcebean DOSSIER.OFFICECONNECTION into configuration");
          throw new Exception("Cannot found sourcebean DOSSIER.OFFICECONNECTION into configuration");
        } else {
          logger.debug("Dossier office connection sourcebean retrived " + officeConnectSB);
        }
        String host = (String) officeConnectSB.getAttribute("host");
        String port = (String) officeConnectSB.getAttribute("port");
        logger.debug("office connection, using host " + host + " and port " + port);
        XComponentContext xRemoteContext = Bootstrap.createInitialComponentContext(null);
        logger.debug("initial XComponentContext created " + xRemoteContext);
 
        Object x = xRemoteContext.getServiceManager().createInstanceWithContext(
          "com.sun.star.connection.Connector", xRemoteContext);
        XConnector xConnector = (XConnector) UnoRuntime.queryInterface(XConnector.class, x);
        logger.debug("XConnector retrieved: " + xConnector);
            XConnection connection = null;
            try {
          connection = xConnector.connect("socket,host=" + host + ",port=" + port);
          if (connection == null) {
            logger.error("Cannot connect to open office using host " + host + " and port " + port);
            throw new OpenOfficeConnectionException("Cannot connect to open office using host " + host
                + " and port " + port);
          }
            } catch (Exception e) {
              logger.error("Cannot connect to open office using host " + host + " and port " + port, e);
              throw new OpenOfficeConnectionException("Cannot connect to open office using host " + host + " and port " + port);
            }
        logger.debug("XConnection retrieved: " + connection);
        x = xRemoteContext.getServiceManager().createInstanceWithContext("com.sun.star.bridge.BridgeFactory",
          xRemoteContext);
        XBridgeFactory xBridgeFactory = (XBridgeFactory) UnoRuntime.queryInterface(XBridgeFactory.class, x);
        logger.debug("XBridgeFactory retrieved: " + xBridgeFactory);
        // this is the bridge that you will dispose
        bridge = xBridgeFactory.createBridge("", "urp", connection, null);
        logger.debug("XBridge retrieved: " + bridge);
        XComponent xComp = (XComponent) UnoRuntime.queryInterface(XComponent.class, bridge);
        // get the remote instance
        x = bridge.getInstance("StarOffice.ServiceManager");
        logger.debug("StarOffice.ServiceManager instance retrieved: " + x);
        // Query the initial object for its main factory interface
        XMultiComponentFactory xRemoteServiceManager = (XMultiComponentFactory) UnoRuntime.queryInterface(
          XMultiComponentFactory.class, x);
 
        // XMultiComponentFactory xRemoteServiceManager =
        // (XMultiComponentFactory)UnoRuntime.queryInterface(XMultiComponentFactory.class,
        // initialObject);
        logger.debug("XMultiComponentFactory retrived " + xRemoteServiceManager);
        XPropertySet xProperySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
          xRemoteServiceManager);
        logger.debug("xProperySet retrived " + xProperySet);
        Object oDefaultContext = xProperySet.getPropertyValue("DefaultContext");
        logger.debug("DefaultContext Propery  value retrived " + oDefaultContext);
        xRemoteContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, oDefaultContext);
        logger.debug("remote XComponentContext retrived " + xRemoteContext);
        Object desktop = xRemoteServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop",
          xRemoteContext);
        logger.debug("Desktop object retrived " + desktop);
        xdesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, desktop);
        logger.debug("XDesktop object retrived " + desktop);
 
        // LOAD OO TEMPLATE INTO OPEN OFFICE
        XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class,
          xdesktop);
        logger.debug("XComponentLoader object retrived " + xComponentLoader);
        xComponent = openTemplate(xComponentLoader, "file:///" + templateOOFile.getAbsolutePath());
        logger.debug("Template loaded into openffice ");
 
        // ANALYZE OO TEMPLATE, EXTRACT NAME OF PLACEHOLDERS, CALL ENGINE
        // AND STORE RESULT IMAGES
        // gets the number of the parts of the documents
        XMultiServiceFactory xServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(
          XMultiServiceFactory.class, xComponent);
        logger.debug("XMultiServiceFactory of the Template retrived " + xServiceFactory);
        XDrawPagesSupplier xDrawPageSup = (XDrawPagesSupplier) UnoRuntime.queryInterface(XDrawPagesSupplier.class,
          xComponent);
        logger.debug("XDrawPagesSupplier retrived " + xDrawPageSup);
        XDrawPages drawPages = xDrawPageSup.getDrawPages();
        logger.debug("XDrawPages retrived " + drawPages);
        int numPages = drawPages.getCount();
        logger.debug("Template has " + numPages + " pages");
       
        // for each part of the document gets the image images and stores
        // them into cms
        for (int i = 0; i < numPages; i++) {
        int numPage = i + 1;
        logger.debug("processing page with index " + i);
        Object pageObj = drawPages.getByIndex(i);
        logger.debug("page object retrived " + pageObj);
        XDrawPage xDrawPage = (XDrawPage) UnoRuntime.queryInterface(XDrawPage.class, pageObj);
        logger.debug("XDrawPage retrived " + xDrawPage);
        XShapes xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xDrawPage);
        logger.debug("xShapes of pages retrived " + xShapes);
        int numShapes = xShapes.getCount();
        logger.debug("Page has " + numShapes + " shapes");
        for (int j = 0; j < numShapes; j++) {
            logger.debug("processing shape with index " + j);
            Object shapeObj = xShapes.getByIndex(j);
            logger.debug("shape object retrived " + shapeObj);
            XText xShapeText = (XText) UnoRuntime.queryInterface(XText.class, shapeObj);
            logger.debug("XShapeText retrived " + xShapeText);
            if (xShapeText != null) {
            String shapeText = xShapeText.getString();
            logger.debug("shape text retrived " + shapeText);
            shapeText = shapeText.trim();
            if (shapeText.startsWith("spagobi_placeholder_")) {
                String logicalObjectName = shapeText.substring(20);
                logger.debug("Logical Name of the shape " + logicalObjectName);
                ConfiguredBIDocument confDoc = dossierDAO.getConfiguredDocument(logicalObjectName, pathTmpFold);
                logger.debug("Configured document with Logical Name " + logicalObjectName
                  + " retrived " + confDoc);
                storeDocImages(confDoc, numPage, dossier, workflowProcessId);
            }
            }
        }
        }
 
    } catch (Exception e) {
        logger.error("Exception during execution : \n" + e);
        // AUDIT UPDATE
        if (contextInstance != null) {
        Integer auditId = (Integer) contextInstance.getVariable(AuditManager.AUDIT_ID);
        AuditManager auditManager = AuditManager.getInstance();
        auditManager.updateAudit(auditId, null, new Long(System.currentTimeMillis()), "EXECUTION_FAILED", e
          .getMessage(), null);
        }
        throw e;
View Full Code Here


         try {
           JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
                     jbpmContext = jbpmConfiguration.createJbpmContext();
           long activityKeyId = Long.valueOf(activityKey).longValue();
           TaskInstance taskInstance = jbpmContext.getTaskInstance(activityKeyId);
           ContextInstance contextInstance = taskInstance.getContextInstance();
           ProcessInstance processInstance = contextInstance.getProcessInstance();
           workflowProcessId = new Long(processInstance.getId());
           String dossierIdStr = (String) contextInstance.getVariable(DossierConstants.DOSSIER_ID);
           dossierId = new Integer(dossierIdStr);
         } finally {
           if (jbpmContext != null) jbpmContext.close();
         }
         if (dossierId != null) {
View Full Code Here

        throw e;
      }
      // create process instance
      ProcessInstance processInstance = new ProcessInstance(processDefinition);
      // get context instance and set the dossier id variable
      ContextInstance contextInstance = processInstance.getContextInstance();
      contextInstance.createVariable(DossierConstants.DOSSIER_ID, dossier.getId().toString());
      contextInstance.createVariable(DossierConstants.DOSSIER_PARAMETERS, getDossierParameters(dossier));
     
      // adding parameters for AUDIT updating
      if (auditId != null) {
        contextInstance.createVariable(AuditManager.AUDIT_ID, auditId);
      }
     
      // start workflow
      Token token = processInstance.getRootToken();
      GraphSession graphSess = jbpmContext.getGraphSession();
View Full Code Here

    return parameters;
  }

  private void approveHandler(SourceBean request, SourceBean response) {
    logger.debug("IN");
    ContextInstance contextInstance = null;
    JbpmContext jbpmContext = null;
    try {
      // recover task instance and variables
      String activityKey = (String) request.getAttribute(SpagoBIConstants.ACTIVITYKEY);
      String approved = (String) request.getAttribute("approved");
      JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
      jbpmContext = jbpmConfiguration.createJbpmContext();
      TaskInstance taskInstance = jbpmContext.getTaskInstance(new Long(activityKey).longValue());
      contextInstance = taskInstance.getContextInstance();
      ProcessInstance processInstance = contextInstance.getProcessInstance();
      Long workflowProcessId = new Long(processInstance.getId());
      String dossierIdStr = (String) contextInstance.getVariable(DossierConstants.DOSSIER_ID);
      Integer dossierId = new Integer(dossierIdStr);
      // store presentation
      SessionContainer session = this.getRequestContainer().getSessionContainer();
      SessionContainer permanentSession = session.getPermanentContainer();
      IEngUserProfile profile = (IEngUserProfile) permanentSession.getAttribute(IEngUserProfile.ENG_USER_PROFILE);

      IDossierPresentationsDAO dpDAO = DAOFactory.getDossierPresentationDAO();
      dpDAO.setUserProfile(profile);
      DossierPresentation currPresentation = dpDAO.getCurrentPresentation(dossierId, workflowProcessId);
      boolean approvedBool = false;
      if (approved.equalsIgnoreCase("true")) {
        approvedBool = true;
      }
      currPresentation.setApproved(new Boolean(approvedBool));
      Integer nextProg = dpDAO.getNextProg(dossierId);
      currPresentation.setProg(nextProg);
      dpDAO.updatePresentation(currPresentation);
      // put attributes into response
      if (approved.equalsIgnoreCase("true")) {
        response.setAttribute(DossierConstants.PUBLISHER_NAME, "DossierCompleteActivityLoopback");
      } else {
        response.setAttribute(DossierConstants.PUBLISHER_NAME, "DossierRejecrActivityLoopback");
      }
      response.setAttribute(SpagoBIConstants.ACTIVITYKEY, activityKey);
     
      // AUDIT UPDATE
      if (contextInstance != null) {
        Object auditIdObj = contextInstance.getVariable(AuditManager.AUDIT_ID);
        Integer auditId = convertIdType(auditIdObj);
        if(auditId!=null) {
          AuditManager auditManager = AuditManager.getInstance();
          auditManager.updateAudit(auditId, null, new Long(System.currentTimeMillis()),
              "EXECUTION_PERFORMED", null, null);
        }
      }
     
    } catch(Exception e){
      logger.error("Error while versioning presentation", e);
      // AUDIT UPDATE
      if (contextInstance != null) {
        Object auditIdObj = contextInstance.getVariable(AuditManager.AUDIT_ID);
        Integer auditId = convertIdType(auditIdObj);
        if(auditId!=null) {
          AuditManager auditManager = AuditManager.getInstance();
          auditManager.updateAudit(auditId, null, new Long(System.currentTimeMillis()),
              "EXECUTION_FAILED", e.getMessage(), null);
View Full Code Here

      JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
      jbpmContext = jbpmConfiguration.createJbpmContext();
      TaskInstance taskInstance = jbpmContext.getTaskInstance(new Long(activityKey).longValue());
      String index = (String)taskInstance.getVariable(DossierConstants.DOSSIER_PART_INDEX);
      int pageNum = Integer.parseInt(index);
      ContextInstance contextInstance = taskInstance.getContextInstance();
      ProcessInstance processInstance = contextInstance.getProcessInstance();
      Long workflowProcessId = new Long(processInstance.getId());
      String dossierIdStr = (String)contextInstance.getVariable(DossierConstants.DOSSIER_ID);
      Integer dossierId = new Integer(dossierIdStr);
     
      // recovers images and notes
        String notes = recoverNotes(dossierId, pageNum, workflowProcessId);
        Map imageurl = recoverImageUrls(dossierId, pageNum, workflowProcessId);
View Full Code Here

      String noteSent = (String)request.getAttribute("notes");
      String activityKey = (String)request.getAttribute(SpagoBIConstants.ACTIVITYKEY);
      JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
      jbpmContext = jbpmConfiguration.createJbpmContext();
      TaskInstance taskInstance = jbpmContext.getTaskInstance(new Long(activityKey).longValue());
      ContextInstance contextInstance = taskInstance.getContextInstance();
      ProcessInstance processInstance = contextInstance.getProcessInstance();
      Long workflowProcessId = new Long(processInstance.getId());
      SessionContainer session = this.getRequestContainer().getSessionContainer();
      SessionContainer permanentSession = session.getPermanentContainer();
      IEngUserProfile profile = (IEngUserProfile) permanentSession.getAttribute(IEngUserProfile.ENG_USER_PROFILE);
      IDossierPartsTempDAO dptDAO = DAOFactory.getDossierPartsTempDAO();
View Full Code Here

                  .getContextInstance(VariableScope.VARIABLE_SCOPE);
            }
            return variableScopeInstance.getVariable(name);
        }
        public ContextInstance getContextInstance() {
          ContextInstance contextInstance = new ContextInstance() {
            public Object getVariable(String name) {
              return JpdlExecutionContext.this.getVariable(name);
            }
          };
          return contextInstance;
View Full Code Here

                && (executionContext.getTaskInstance().hasVariableLocally(name))
              ) {
      value = executionContext.getTaskInstance().getVariable(name);

    } else {
      ContextInstance contextInstance = executionContext.getContextInstance();
      TaskMgmtInstance taskMgmtInstance = executionContext.getTaskMgmtInstance();
      Token token = executionContext.getToken();
     
      if ( (contextInstance!=null)
           && (contextInstance.hasVariable(name))
         ) {
        value = contextInstance.getVariable(name, token);

      } else if ( (contextInstance!=null)
                  && (contextInstance.hasTransientVariable(name))
                ) {
        value = contextInstance.getTransientVariable(name);
       
      } else if ( (taskMgmtInstance!=null)
                && (taskMgmtInstance.getSwimlaneInstances()!=null)
                && (taskMgmtInstance.getSwimlaneInstances().containsKey(name))
            ) {
        SwimlaneInstance swimlaneInstance = taskMgmtInstance.getSwimlaneInstance(name);
        value = (swimlaneInstance!=null ? swimlaneInstance.getActorId() : null);
       
      } else if ( (contextInstance!=null)
                  && (contextInstance.hasTransientVariable(name))
                ) {
        value = contextInstance.getTransientVariable(name);
       
      } else if (JbpmConfiguration.Configs.hasObject(name)) {
        value = JbpmConfiguration.Configs.getObject(name);
      }
    }
View Full Code Here

   */
  public void initializeVariables(TaskInstance taskInstance) {
    if (taskControllerDelegation != null) {
      TaskControllerHandler taskControllerHandler = (TaskControllerHandler) taskControllerDelegation.instantiate();
      ProcessInstance processInstance = taskInstance.getTaskMgmtInstance().getProcessInstance();
      ContextInstance contextInstance = (processInstance!=null ? processInstance.getContextInstance() : null);
      Token token = taskInstance.getToken();
     
      if (UserCodeInterceptorConfig.userCodeInterceptor!=null) {
        UserCodeInterceptorConfig.userCodeInterceptor.executeTaskControllerInitialization(taskControllerHandler, taskInstance, contextInstance, token);
      } else {
        taskControllerHandler.initializeTaskVariables(taskInstance, contextInstance, token);
      }

    } else {
      Token token = taskInstance.getToken();
      ProcessInstance processInstance = token.getProcessInstance();
      ContextInstance contextInstance = processInstance.getContextInstance();

      if (variableAccesses!=null) {
        Iterator iter = variableAccesses.iterator();
        while (iter.hasNext()) {
          VariableAccess variableAccess = (VariableAccess) iter.next();
          String mappedName = variableAccess.getMappedName();
          if (variableAccess.isReadable()) {
            String variableName = variableAccess.getVariableName();
            Object value = contextInstance.getVariable(variableName, token);
            log.debug("creating task instance variable '"+mappedName+"' from process variable '"+variableName+"', value '"+value+"'");
            taskInstance.setVariableLocally(mappedName, value);
          } else {
            log.debug("creating task instance local variable '"+mappedName+"'. initializing with null value.");
            taskInstance.setVariableLocally(mappedName, null);
View Full Code Here

   */
  public void submitParameters(TaskInstance taskInstance) {
    if (taskControllerDelegation != null) {
      TaskControllerHandler taskControllerHandler = (TaskControllerHandler) taskControllerDelegation.instantiate();
      ProcessInstance processInstance = taskInstance.getTaskMgmtInstance().getProcessInstance();
      ContextInstance contextInstance = (processInstance!=null ? processInstance.getContextInstance() : null);
      Token token = taskInstance.getToken();

      if (UserCodeInterceptorConfig.userCodeInterceptor!=null) {
        UserCodeInterceptorConfig.userCodeInterceptor.executeTaskControllerSubmission(taskControllerHandler, taskInstance, contextInstance, token);
      } else {
        taskControllerHandler.submitTaskVariables(taskInstance, contextInstance, token);
      }

    } else {

      Token token = taskInstance.getToken();
      ProcessInstance processInstance = token.getProcessInstance();
      ContextInstance contextInstance = processInstance.getContextInstance();

      if (variableAccesses!=null) {
        String missingTaskVariables = null;
        Iterator iter = variableAccesses.iterator();
        while (iter.hasNext()) {
          VariableAccess variableAccess = (VariableAccess) iter.next();
          String mappedName = variableAccess.getMappedName();
          // first check if the required variableInstances are present
          if ( (variableAccess.isRequired())
               && (! taskInstance.hasVariableLocally(mappedName))
             ) {
            if (missingTaskVariables==null) {
              missingTaskVariables = mappedName;
            } else {
              missingTaskVariables += ", "+mappedName;
            }
          }
        }

        // if there are missing, required parameters, throw an IllegalArgumentException
        if (missingTaskVariables!=null) {
          throw new IllegalArgumentException("missing task variables: "+missingTaskVariables);
        }

        iter = variableAccesses.iterator();
        while (iter.hasNext()) {
          VariableAccess variableAccess = (VariableAccess) iter.next();
          String mappedName = variableAccess.getMappedName();
          String variableName = variableAccess.getVariableName();
          if (variableAccess.isWritable()) {
            Object value = taskInstance.getVariable(mappedName);
            if (value!=null) {
              log.debug("submitting task variable '"+mappedName+"' to process variable '"+variableName+"', value '"+value+"'");
              contextInstance.setVariable(variableName, value, token);
            }
          }
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.jbpm.context.exe.ContextInstance

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.