/**
   * Publishes a message to qpid that describes what action a user has just performed on a task.
   * These actions may be either TaskTaken or TaskCompleted. This calls checkInitialized to see if
   * there is a valid connection to qpid.
   *
   * @param task the task that has been acted upon
   * @param exchangeName the exchange name for messaging
   * @param eventName the event that correlates with the action
   * @param taskId the id of the task that was acted upon
   */
  public void amqpTaskPublish(Task task, String exchangeName, String eventName, String taskId) {
    String info = "";
    if (checkInitialized()) {
      if (eventName.equals("TaskTaken")) {

        try {
          info =
              "eventType="
                  + eventName
                  + ";"
                  + "processID="
                  + task.getProcessInstanceId()
                  + ";"
                  + "taskID="
                  + task.getId()
                  + ";"
                  + "assignee="
                  + task.getAssignee()
                  + ";";
        } catch (Exception e) {
          log.debug(e.getMessage());
        }
      } else if (eventName.equals("TaskCompleted")) {
        try {
          org.jbpm.task.Task ht = taskRepo.findById(Long.decode(taskId));
          String processName = ht.getTaskData().getProcessId();
          String processId = Long.toString(ht.getTaskData().getProcessInstanceId());
          String assignee = ht.getTaskData().getActualOwner().getId();
          info =
              "eventType="
                  + eventName
                  + ";"
                  + "processID="
                  + processName
                  + "."
                  + processId
                  + ";"
                  + "taskID="
                  + taskId
                  + ";"
                  + "assignee="
                  + assignee
                  + ";";
        } catch (Exception e) {
          log.debug(e.getMessage());
        }
      }
      sendMessage(info, exchangeName);
    }
  }
 private static Object parseAttributeValue(String type, String value) {
   switch (type) {
     case "bool":
       return Boolean.parseBoolean(value);
     case "int":
       return Integer.parseInt(value);
     case "long":
       return Long.parseLong(value);
     case "float":
       return Float.parseFloat(value);
     case "double":
       return Double.parseDouble(value);
   }
   return value;
 }
Example #3
0
  public synchronized boolean send() {
    Boolean complete_send_to_crm = true;

    SimpleDateFormat format = new SimpleDateFormat();
    format.applyPattern("dd/MM/yyyy HH:mm:ss");

    try {
      BasicXmlData xml = new BasicXmlData("action");
      xml.setAttribute("name", "Comment");

      BasicXmlData xml_level_1 = new BasicXmlData("parameters");

      BasicXmlData xml_level_2_id_trouble = new BasicXmlData("parameter");
      xml_level_2_id_trouble.setAttribute("name", "id_trouble");
      xml_level_2_id_trouble.setAttribute("value", String.valueOf(trouble.getId()));
      xml_level_1.addKid(xml_level_2_id_trouble);

      BasicXmlData xml_level_2_id_comment = new BasicXmlData("parameter");
      xml_level_2_id_comment.setAttribute("name", "id_comment");
      xml_level_2_id_comment.setAttribute("value", String.valueOf(comment.getId()));
      xml_level_1.addKid(xml_level_2_id_comment);

      BasicXmlData xml_level_2_author = new BasicXmlData("parameter");
      xml_level_2_author.setAttribute("name", "author");
      xml_level_2_author.setAttribute("value", comment.getAuthor().getFio());
      xml_level_1.addKid(xml_level_2_author);

      BasicXmlData xml_level_2_desc = new BasicXmlData("parameter");
      xml_level_2_desc.setAttribute("name", "content");
      xml_level_2_desc.setAttribute("value", comment.getText());
      xml_level_1.addKid(xml_level_2_desc);

      BasicXmlData xml_level_2_date = new BasicXmlData("parameter");
      xml_level_2_date.setAttribute("name", "date");
      xml_level_2_date.setAttribute(
          "value", format.format(new Date(Long.valueOf(comment.getTime()))));
      xml_level_1.addKid(xml_level_2_date);

      xml.addKid(xml_level_1);

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      xml.save(baos);

      SendToCrm.send(baos);
    } catch (Exception e) {
      log.error(
          "Comment ["
              + comment.getId()
              + "] to trouble "
              + trouble.getTitle()
              + " ["
              + trouble.getId()
              + "] is not sent to CRM - "
              + e.getMessage());
      e.printStackTrace();
      complete_send_to_crm = false;
    }

    if (complete_send_to_crm) {
      log.info(
          "Comment ["
              + trouble.getId()
              + "] to trouble "
              + trouble.getTitle()
              + " ["
              + trouble.getId()
              + "] successfully submitted to CRM successfully.");
    }

    return complete_send_to_crm;
  }