Esempio n. 1
0
  /**
   * Adds Attachemnts based on formData to task.
   *
   * @param oFormData FormData from task where we search file fields.
   * @param oTask where we add Attachments.
   */
  public void addAttachmentsToTask(FormData oFormData, DelegateTask oTask) {
    DelegateExecution oExecution = oTask.getExecution();

    LOG.info("SCAN:file");
    List<String> asFieldID = getListFieldCastomTypeFile(oFormData);
    LOG.info("[addAttachmentsToTask]");
    LOG.info("(asFieldID={})", asFieldID.toString());
    List<String> asFieldValue = getVariableValues(oExecution, asFieldID);
    LOG.info("(asFieldValue={})", asFieldValue.toString());
    List<String> asFieldName = getListCastomFieldName(oFormData);
    LOG.info("(asFieldName={})", asFieldName.toString());
    if (!asFieldValue.isEmpty()) {
      int n = 0;
      for (String sKeyRedis : asFieldValue) {
        LOG.info("(sKeyRedis={})", sKeyRedis);
        if (sKeyRedis != null
            && !sKeyRedis.isEmpty()
            && !"".equals(sKeyRedis.trim())
            && !"null".equals(sKeyRedis.trim())
            && sKeyRedis.length() > 15) {
          if (!asFieldName.isEmpty() && n < asFieldName.size()) {
            // String sDescription = asFieldName.get((asFieldName.size() - 1) - n);
            String sDescription = asFieldName.get(n);
            LOG.info("(sDescription={})", sDescription);
            String sID_Field = asFieldID.get(n);
            LOG.info("(sID_Field={})", sID_Field);

            byte[] aByteFile;
            ByteArrayMultipartFile oByteArrayMultipartFile = null;
            try {
              aByteFile = oBytesDataInmemoryStorage.getBytes(sKeyRedis);
              oByteArrayMultipartFile = getByteArrayMultipartFileFromStorageInmemory(aByteFile);
            } catch (ClassNotFoundException | IOException | RecordInmemoryException e1) {
              throw new ActivitiException(e1.getMessage(), e1);
            }
            if (oByteArrayMultipartFile != null) {
              String sFileName = null;
              try {
                sFileName =
                    new String(oByteArrayMultipartFile.getOriginalFilename().getBytes(), "UTF-8");
              } catch (java.io.UnsupportedEncodingException oException) {
                LOG.error("error on getting sFileName: {}", oException.getMessage());
                throw new ActivitiException(oException.getMessage(), oException);
              }
              LOG.info("(sFileName={})", sFileName);

              // ===
              InputStream oInputStream = null;
              try {
                oInputStream = oByteArrayMultipartFile.getInputStream();
              } catch (Exception e) {
                throw new ActivitiException(e.getMessage(), e);
              }
              Attachment oAttachment =
                  oExecution
                      .getEngineServices()
                      .getTaskService()
                      .createAttachment(
                          oByteArrayMultipartFile.getContentType()
                              + ";"
                              + oByteArrayMultipartFile.getExp(),
                          oTask.getId(),
                          oExecution.getProcessInstanceId(),
                          sFileName,
                          sDescription,
                          oInputStream);

              if (oAttachment != null) {
                String nID_Attachment = oAttachment.getId();
                // LOG.info("(nID_Attachment={})", nID_Attachment);
                LOG.info(
                    "Try set variable(sID_Field={}) with the value(nID_Attachment={}), for new attachment...",
                    sID_Field,
                    nID_Attachment);
                oExecution
                    .getEngineServices()
                    .getRuntimeService()
                    .setVariable(oExecution.getProcessInstanceId(), sID_Field, nID_Attachment);
                LOG.info(
                    "Finished setting new value for variable with attachment (sID_Field={})",
                    sID_Field);
              } else {
                LOG.error("Can't add attachment to (oTask.getId()={})", oTask.getId());
              }
              // ===

            } else {
              LOG.error("oByteArrayMultipartFile==null!  (sKeyRedis={})", sKeyRedis);
            }
          } else {
            LOG.error("asFieldName has nothing! (asFieldName={})", asFieldName);
          }
        } else {
          LOG.error("Invalid Redis Key!!! (sKeyRedis={})", sKeyRedis);
        }
        n++;
      }
    }

    scanExecutionOnQueueTickets(oExecution, oFormData); // , oTask);//startformData

    /*LOG.info("SCAN:queueData");
    asFieldID = getListField_QueueDataFormType(formData);
    LOG.info("asFieldID="+asFieldID.toString());
    asFieldValue = getVariableValues(execution, asFieldID);
    LOG.info("asFieldValue="+asFieldValue.toString());
    //asFieldName = getListCastomFieldName(formData);
    //LOG.info("asFieldName="+asFieldName.toString());
    if (!asFieldValue.isEmpty()) {
    String sValue = asFieldValue.get(0);
    LOG.info("sValue=" + sValue);
    long nID_FlowSlotTicket=0;
    int nAt=sValue.indexOf(":");
    int nTo=sValue.indexOf(",");
    String s=sValue.substring(nAt+1,nTo);
    LOG.info("s=" + s);
    try{
    nID_FlowSlotTicket = Long.valueOf(s);
    LOG.info("Ok!");
    }catch(Exception oException){
    LOG.error(oException.getMessage());
    nID_FlowSlotTicket=1;
    }
    LOG.info("nID_FlowSlotTicket=" + nID_FlowSlotTicket);

    try{


    //                FlowSlotTicket oFlowSlotTicket = baseEntityDao.getById(FlowSlotTicket.class, nID_FlowSlotTicket);
    //                if (oFlowSlotTicket == null) {
    //                    LOG.error("FlowSlotTicket with id=" + nID_FlowSlotTicket + " is not found!");
    //                }else{
    //                    long nID_FlowSlot=oFlowSlotTicket.getoFlowSlot().getId();
    //                    LOG.error("nID_FlowSlot="+nID_FlowSlot);
    //                    long nID_Subject = oFlowSlotTicket.getnID_Subject();
    //                    LOG.error("nID_Subject="+nID_Subject);
    //                    long nID_Task_Activiti = 1; //TODO set real ID!!!
    //                    oFlowSlotTicket.setnID_Task_Activiti(nID_Task_Activiti);
    //                    baseEntityDao.saveOrUpdate(oFlowSlotTicket);
    //                    LOG.info("JSON:" + JsonRestUtils.toJsonResponse(new SaveFlowSlotTicketResponse(oFlowSlotTicket.getId())));
    //                }

    }catch(Exception oException){
    LOG.error(oException.getMessage());
    }

    }*/

  }
 private void addCandidateUser(DelegateTask delegateTask, String assignee, String attorney) {
   logger.info("自动委托任务,设置候选人: {} to {}", delegateTask, attorney);
   delegateTask.addCandidateUser(attorney);
   delegateService.saveRecord(assignee, attorney, delegateTask.getId());
 }