@Override
 public void execute() {
   if (!this.isEnable()) {
     this.log.info(("no process for this job | enable-" + this.isEnable()));
     return;
   }
   try {
     ProviderAmountDao providerAmountDao = new ProviderAmountDao();
     List listCurProviderAmounts = providerAmountDao.selectAll();
     if (listCurProviderAmounts != null) {
       for (int i = 0; i < listCurProviderAmounts.size(); ++i) {
         ProviderAmount providerAmount = (ProviderAmount) listCurProviderAmounts.get(i);
         String providerId = providerAmount.getProviderId();
         ProviderAccountDao accountDao = new ProviderAccountDao();
         long totalAmount =
             accountDao.selectTotalAmountByProviderId(providerAmount.getProviderId());
         long currentAmount = totalAmount - providerAmount.getTotalUsed();
         if (currentAmount < providerAmount.getNotifAmount()) {
           if (providerAmount.getNotifSent().booleanValue()) continue;
           ContextBase context = new ContextBase();
           context.put("provider_id", providerId);
           context.putLong("current_amount", currentAmount);
           context.putLong("notif_amount", providerAmount.getNotifAmount().longValue());
           if (AppConstants.NOTIFICATION_SETTINGS.sendNotification(
               NotificationSettings.TEMPLATE_TYPE.PROVIDER_AMOUNT_ALERT, new Object[] {context})) {
             providerAmount = new ProviderAmount();
             providerAmount.setProviderId(providerId);
             providerAmount.setNotifSent(Boolean.valueOf(true));
             providerAmountDao.update(providerAmount);
             continue;
           }
           this.log.error("======================================================");
           this.log.error("========= Fail to send PROVIDER_AMOUNT_ALERT =========");
           this.log.error("======================================================");
           continue;
         }
         if (!providerAmount.getNotifSent().booleanValue()) continue;
         providerAmount = new ProviderAmount();
         providerAmount.setProviderId(providerId);
         providerAmount.setNotifSent(Boolean.valueOf(false));
         providerAmountDao.update(providerAmount);
       }
     }
   } catch (Exception e) {
     this.log.error(e);
   }
 }
示例#2
0
  public void transfer(SimTransaction txn) {
    try {
      SimTransaction simTransaction = new SimTransaction();
      simTransaction.setTxnId(txn.getTxnId());
      simTransaction.setTxnStatus(AppConstants.TXN_STATUS_DELIVERING);

      SimTransactionDao simTransactionDao = new SimTransactionDao();
      if (simTransactionDao.update(simTransaction)) {
        ContextBase ctxRequest = new ContextBase();
        ctxRequest.put(Attributes.ATTR_TXN_TYPE, txn.getTxnType());
        ctxRequest.put(Attributes.ATTR_COM_ID, txn.getSimId());
        ctxRequest.put(Attributes.ATTR_MSISDN, txn.getMsisdn());
        ctxRequest.putLong(Attributes.ATTR_AMOUNT, txn.getAmount());
        ContextBase response = SimConnectionFactory.getInstance().process(ctxRequest);
        log.info("Transfer money:" + response);
      } else log.info("Fail to change txn status of transfer txn :" + txn);
    } catch (Exception e) {
      log.error("Fail to transfer money", e);
    }
  }
 @Override
 public void execute() {
   if (!this.isEnable()) {
     this.log.info(("no process for this job | enable-" + this.isEnable()));
     return;
   }
   ContextBase context = new ContextBase();
   try {
     context.put(Attributes.ATTR_ERROR_CODE, "SUCCESS");
     context.put(Attributes.ATTR_WFP_NAME, "wfpMobiFoneBalanceRequestPushToQueue");
     IExecutor executor = ExecutorFactory.getInstance().getExecutor("WorkFlowConnection");
     context = executor.process(context);
   } catch (Exception e) {
     this.log.error(
         ("Fail to process request.| errorCode-"
             + context.getErrorCode()
             + "| context-"
             + context),
         (Throwable) e);
   }
 }
示例#4
0
  public ContextBase process(ContextBase context) {

    if (log.isDebugEnabled()) {
      log.debug("Receive request. |context-" + context.toString());
    }

    String errCode = null;
    QueueRequest request = null;
    ContextBase result = new ContextBase();
    if (StringUtils.isEmpty(context.get(Attributes.ATTR_ERROR_CODE)))
      context.put(Attributes.ATTR_ERROR_CODE, ErrorCode.SUCCESS);

    try {

      if (shutdownFlag.get()) {
        log.warn("Queue Manager is shuting down.");
        result.put(Attributes.ATTR_ERROR_CODE, ErrorCode.QUEUE_SHUTINGDOWN);
        return result;
      }

      errCode = validate(context);
      context.put(Attributes.ATTR_QUEUE_REQUEST_ID, context.get(Attributes.ATTR_TRANSACTION_ID));

      if (!ErrorCode.SUCCESS.equals(errCode)) {
        result.put(Attributes.ATTR_ERROR_CODE, errCode);
        return result;
      }

      request = RequestDbFactory.getInstance().insert(context);

      if (request == null) {
        errCode = ErrorCode.DATABASE_EXCEPTION;
        result.put(Attributes.ATTR_ERROR_CODE, errCode);
        log.error(
            "Fail to insert context to queue db. | ErrorCode-" + errCode + " | context-" + context);
        return result;
      }

      QueueServer qServer = queues.get(request.getQueueId());
      if (qServer == null) result.setErrorCode(ErrorCode.QUEUE_NOT_EXISTED);
      else result = qServer.process(request);

      if (!ErrorCode.SUCCESS.equals(result.getErrorCode())) {
        RequestDbFactory.getInstance().delete(request);
        log.error("Process put request to Queue failed. | result-" + result);
      } else {
        log.info("Process put request to Queue successful. | result-" + result);
      }

      return result;
    } catch (Exception e) {
      log.error(
          "Exception while processing received context. | context-"
              + context.toString()
              + " | ErrorMessage-"
              + e.getMessage(),
          e);
      result.put(Attributes.ATTR_ERROR_CODE, ErrorCode.SYS_INTERNAL_ERROR);
      return result;
    }
  }