public String getScheduleString() {
    StringBuilder builder = new StringBuilder();

    try {
      builder.append("start: ");
      builder.append(getParameter(PARAM_START_TIME.getName(), DEFAULT_START_TIME));
      builder.append(", ");

      builder.append("end: ");
      builder.append(getParameter(PARAM_END_TIME.getName(), DEFAULT_END_TIME));
      builder.append(", ");

      Integer repeat = getParameter(PARAM_REPEAT.getName(), DEFAULT_REPEAT);
      builder.append("repeat: ");
      builder.append((repeat == SimpleTrigger.REPEAT_INDEFINITELY ? "infinite" : repeat));
      builder.append(", ");

      builder.append("interval: ");
      builder.append(getParameter(PARAM_INTERVAL.getName(), DEFAULT_INTERVAL));
      builder.append(" hrs");

    } catch (PluggableTaskException e) {
      LOG.error("Exception occurred parsing plug-in parameters", e);
    }

    return builder.toString();
  }
  private Map<String, Object> makeCall(String json, String method) throws PluggableTaskException {

    LOG.debug("Calling method: '%s', with JSON: %s", method, json);

    MultiValueMap<String, String> postParameters = new LinkedMultiValueMap<String, String>();

    postParameters.add("rest_data", json);
    postParameters.add("input_type", "JSON");
    postParameters.add("method", method);
    postParameters.add("response_type", "JSON");

    RestTemplate restTemplate = new RestTemplate();

    String resultString =
        restTemplate.postForObject(
            ENTRY_POINT,
            postParameters,
            String.class,
            getParameter(PARAM_SERVER.getName()),
            getParameter(PARAM_SUGARINSTANCE.getName()));

    LOG.debug("Result contents: %s", resultString);

    // Tried to use Spring MappingJacksonHttpMessageConverter, but
    // server sends text/html mime type. Using Jackson directly:
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> result = null;
    try {
      result = mapper.readValue(resultString, Map.class);
    } catch (IOException ioe) {
      throw new PluggableTaskException(ioe);
    }

    return result;
  }
  private String login() throws PluggableTaskException {

    String json =
        "{"
            + "  \"user_auth\": {"
            + "    \"user_name\": \""
            + getParameter(PARAM_USER_NAME.getName())
            + "\", "
            + "    \"password\": \""
            + getParameter(PARAM_PASSWORD.getName())
            + "\", "
            + "    \"encryption\": \"PLAIN\" "
            + "  }, "
            + "  \"application_name\": \"JBilling\","
            + "  \"name_value_list\": null "
            + "}";

    Map<String, Object> result = makeCall(json, "login");

    if (result.get("id") == null) {
      String message = "No session id. Error calling SugarCRM: " + result.get("description");
      LOG.error(message);
      throw new PluggableTaskException(message);
    }

    return result.get("id").toString();
  }
Beispiel #4
0
 public boolean validate() {
   if (getParameterDescriptions() != null) {
     // validate that those required are present
     for (ParameterDescription param : getParameterDescriptions()) {
       if (param.isRequired()) {
         if (parameters == null || !parameters.containsKey(param.getName())) {
           return false;
         }
       }
     }
   }
   return true;
 }
  public SimpleTrigger getTrigger() throws PluggableTaskException {
    SimpleTrigger trigger =
        new SimpleTrigger(
            getTaskName(),
            Scheduler.DEFAULT_GROUP,
            getParameter(PARAM_START_TIME.getName(), DEFAULT_START_TIME),
            getParameter(PARAM_END_TIME.getName(), DEFAULT_END_TIME),
            getParameter(PARAM_REPEAT.getName(), DEFAULT_REPEAT),
            getParameter(PARAM_INTERVAL.getName(), DEFAULT_INTERVAL) * 3600 * 1000);

    trigger.setMisfireInstruction(
        SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT);

    return trigger;
  }
  public boolean process(PaymentDTOEx paymentInfo) throws PluggableTaskException {
    FormatLogger log = new FormatLogger(Logger.getLogger(PaymentEmailAuthorizeNetTask.class));
    boolean retValue = super.process(paymentInfo);
    String address = (String) parameters.get(PARAMETER_EMAIL_ADDRESS.getName());
    try {
      UserBL user = new UserBL(paymentInfo.getUserId());
      String message;
      if (new Integer(paymentInfo.getPaymentResult().getId()).equals(Constants.RESULT_OK)) {
        message = "payment.success";
      } else {
        message = "payment.fail";
      }
      String params[] = new String[6];
      params[0] = paymentInfo.getUserId().toString();
      params[1] = user.getEntity().getUserName();
      params[2] = paymentInfo.getId() + "";
      params[3] = paymentInfo.getAmount().toString();
      if (paymentInfo.getAuthorization() != null) {
        params[4] = paymentInfo.getAuthorization().getTransactionId();
        params[5] = paymentInfo.getAuthorization().getApprovalCode();
      } else {
        params[4] = "Not available";
        params[5] = "Not available";
      }
      log.debug(
          "Bkp 6 " + params[0] + " " + params[1] + " " + params[2] + " " + params[3] + " "
              + params[4] + " " + params[5] + " ");
      NotificationBL.sendSapienterEmail(
          address, user.getEntity().getEntity().getId(), message, null, params);
    } catch (Exception e) {

      log.warn("Cant send receit email");
    }

    return retValue;
  }