Ejemplo n.º 1
0
    @SuppressWarnings("unchecked")
    @Override
    public void execute(final Object message) throws Exception {
      if (logger.isInfoEnabled()) {
        logger.info("Downloading RCML");
      }
      final Class<?> klass = message.getClass();
      final CallDetailRecordsDao records = storage.getCallDetailRecordsDao();
      if (CallResponse.class.equals(klass)) {
        final CallResponse<CallInfo> response = (CallResponse<CallInfo>) message;
        callInfo = response.get();
        callState = callInfo.state();
        if (callInfo.direction().equals("inbound")) {
          // Create a call detail record for the call.
          final CallDetailRecord.Builder builder = CallDetailRecord.builder();
          builder.setSid(callInfo.sid());
          builder.setInstanceId(RestcommConfiguration.getInstance().getMain().getInstanceId());
          builder.setDateCreated(callInfo.dateCreated());
          builder.setAccountSid(accountId);
          builder.setTo(callInfo.to());
          builder.setCallerName(callInfo.fromName());
          builder.setFrom(callInfo.from());
          builder.setForwardedFrom(callInfo.forwardedFrom());
          builder.setPhoneNumberSid(phoneId);
          builder.setStatus(callState.toString());
          final DateTime now = DateTime.now();
          builder.setStartTime(now);
          builder.setDirection(callInfo.direction());
          builder.setApiVersion(version);
          builder.setPrice(new BigDecimal("0.00"));
          // TODO implement currency property to be read from Configuration
          builder.setPriceUnit(Currency.getInstance("USD"));
          final StringBuilder buffer = new StringBuilder();
          buffer.append("/").append(version).append("/Accounts/");
          buffer.append(accountId.toString()).append("/Calls/");
          buffer.append(callInfo.sid().toString());
          final URI uri = URI.create(buffer.toString());
          builder.setUri(uri);

          builder.setCallPath(ussdCall.path().toString());

          callRecord = builder.build();
          records.addCallDetailRecord(callRecord);
          // Update the application.
          callback();
        }
      }
      // Ask the downloader to get us the application that will be executed.
      final List<NameValuePair> parameters = parameters();
      request = new HttpRequestDescriptor(url, method, parameters);
      downloader.tell(request, source);
    }
Ejemplo n.º 2
0
 @Override
 public void execute(final Object message) throws Exception {
   if (logger.isInfoEnabled()) {
     logger.info("In Finished state");
   }
   final Class<?> klass = message.getClass();
   if (CallStateChanged.class.equals(klass)) {
     final CallStateChanged event = (CallStateChanged) message;
     callState = event.state();
     if (callRecord != null) {
       callRecord = callRecord.setStatus(callState.toString());
       final DateTime end = DateTime.now();
       callRecord = callRecord.setEndTime(end);
       final int seconds =
           (int) (end.getMillis() - callRecord.getStartTime().getMillis()) / 1000;
       callRecord = callRecord.setDuration(seconds);
       final CallDetailRecordsDao records = storage.getCallDetailRecordsDao();
       records.updateCallDetailRecord(callRecord);
     }
     callback();
   }
   context().stop(self());
 }