Exemplo n.º 1
0
 /*
  * (non-Javadoc)
  *
  * @see org.smslib.smsserver.AInterface#markMessage(org.smslib.OutboundMessage)
  */
 @Override
 public void markMessage(org.smslib.OutboundMessage msg) throws Exception {
   if (msg == null) {
     return;
   }
   File f = getMessageCache().get(msg.getMessageId());
   File newF = null;
   switch (msg.getMessageStatus()) {
     case SENT:
       newF = new File(this.outSentDirectory, f.getName());
       break;
     case FAILED:
       newF = new File(this.outFailedDirectory, f.getName());
       break;
     default:
       break;
   }
   if (f.renameTo(newF)) {
     getService().getLogger().logInfo(f + " marked.", null, null);
   } else {
     getService().getLogger().logWarn("Can't move " + f + " to " + newF, null, null);
   }
   getMessageCache().remove(msg.getMessageId());
 }
Exemplo n.º 2
0
 /*
  * (non-Javadoc)
  *
  * @see org.smslib.smsserver.AInterface#getMessagesToSend()
  */
 @Override
 public Collection<OutboundMessage> getMessagesToSend() throws Exception {
   Collection<OutboundMessage> messageList = new ArrayList<OutboundMessage>();
   File[] outFiles =
       this.outDirectory.listFiles(
           new FileFilter() {
             public boolean accept(File f) {
               /* Read only unprocessed files with an .xml suffix */
               return (f.getAbsolutePath().endsWith(".xml")
                   && !getMessageCache().containsValue(f));
             }
           });
   for (int i = 0; i < outFiles.length; i++) {
     try {
       /* Process each document and add message to the list */
       OutboundMessage msg = readDocument(outFiles[i]);
       if (msg == null) {
         throw new IllegalArgumentException("Missing required fieldes!");
       }
       messageList.add(msg);
       getMessageCache().put(msg.getMessageId(), outFiles[i]);
     } catch (IllegalArgumentException e) {
       getService()
           .getLogger()
           .logWarn(
               "Skipping outgoing file "
                   + outFiles[i].getAbsolutePath()
                   + ": File is not valid: "
                   + e.getLocalizedMessage(),
               null,
               null);
       File brokenFile = new File(this.outBrokenDirectory, outFiles[i].getName());
       if (!outFiles[i].renameTo(brokenFile))
         getService()
             .getLogger()
             .logError("Can't move " + outFiles[i] + " to " + brokenFile, null, null);
     }
   }
   return messageList;
 }
  /**
   * @param smsMessage
   * @param msg
   * @return
   * @throws PersistenceException
   */
  @Override
  public SendModem2Info saveOrUpdate(SendSMSMessage smsMessage, OutboundMessage msg)
      throws PersistenceException {
    SendModem2Info config = new SendModem2Info();

    config.setGatewayID(msg.getGatewayId());

    config.setMessageId(String.valueOf(msg.getMessageId()));
    config.setMessageUUID(msg.getUuid());
    config.setEncoding(msg.getEncoding().toString());
    config.setDataGerada(msg.getDate().toString());
    config.setSmscRefNum(msg.getRefNo());
    config.setNumDestinatario(smsMessage.getNumero());
    if (msg.getDispatchDate() == null) {

      config.setDataExapedicao("Não há data prevista para expedição");

    } else {
      config.setDataExapedicao(msg.getDispatchDate().toString());
    }
    config.setMsgStatus(msg.getMessageStatus().toString());
    config.setCausaFalha(String.valueOf(msg.getFailureCause()));
    config.setPeriodoValido(String.valueOf(msg.getValidityPeriod()));
    config.setRelatorioStatus(msg.getStatusReport());
    config.setPortaDestino(String.valueOf(msg.getSrcPort()));
    config.setFlashSMS(msg.getFlashSms());
    config.setMensagem(smsMessage.getMensagem());
    config.setPduData(msg.getPduUserData());

    if (msg.getScheduledDeliveryDate() == null) {

      config.setEntregaPrevista("SEM DATA PREVISTA");
    } else {
      config.setEntregaPrevista(msg.getScheduledDeliveryDate().toString());
    }
    return new BaseRepository<SendModem2Info>(SendModem2Info.class).saveOrUpdate(config);
  }