public ProcessResult processCall(Call call, Map<String, Object> accumulatedData) {
    if (call.getType() != Call.CALL_TYPE_SENT) {
      return null;
    }

    Long secondsTotal = (Long) accumulatedData.get(ACCUMULATED_DATA_SECONDS);
    if (secondsTotal == null) {
      secondsTotal = new Long(0);
    }
    secondsTotal += call.getDuration();
    accumulatedData.put(ACCUMULATED_DATA_SECONDS, secondsTotal);

    ProcessResult ret = new ProcessResult();
    if (call.getContact().getMsisdnType() == MsisdnType.ES_SPECIAL_ZER0) {
      ret.price = 0.0;
      ret.type = Type.ZERO;
    } else {
      boolean insidePlan = secondsTotal <= maxSecondsMonth;
      if (insidePlan) {
        ret.price = 0.0;
        ret.type = Type.INSIDE_PLAN;
      } else {
        long duration =
            (secondsTotal > maxSecondsMonth)
                    && (secondsTotal - call.getDuration() <= maxSecondsMonth)
                ? secondsTotal - maxSecondsMonth
                : call.getDuration();
        ret.price = initialPrice + (duration * pricePerSecond);
        ret.type = Type.OUTSIDE_PLAN;
      }
    }
    return ret;
  }
Example #2
0
 protected PlanChargeable processSpecialChargeableCall(Call call) {
   Double price = null;
   String msisdn = call.getContact().getMsisdn();
   for (HashMap.Entry<String, SpecialChargeProcessor> entry : SPECIAL_CHARGE_NUMBERS.entrySet()) {
     if (msisdn.startsWith(entry.getKey())) {
       price = entry.getValue().process(call.getDuration());
       break;
     }
   }
   return new PlanChargeable(call, price, this.getCurrency());
 }
Example #3
0
 protected PlanChargeable processInternationalChargeableCall(Call call) {
   Double price = null;
   String destinationCountry = call.getContact().getIsoCountryCode();
   if ("CU".equals(destinationCountry)
       || "KP".equals(destinationCountry)
       || "SO".equals(destinationCountry)) {
     price =
         INTERNATIONAL_INITIAL_PRICE
             + (call.getDuration() * INTERNATIONAL_PRICE_PER_SECOND_CU_KP_SO);
   } else {
     price = INTERNATIONAL_INITIAL_PRICE + (call.getDuration() * INTERNATIONAL_PRICE_PER_SECOND);
   }
   return new PlanChargeable(call, price, this.getCurrency());
 }
Example #4
0
  public PlanSummary process(ArrayList<Chargeable> data) {
    PlanSummary ret = new PlanSummary(this);
    ret.addPlanCall(
        new PlanChargeable(
            new ChargeableMessage(ChargeableMessage.MESSAGE_MONTH_FEE),
            monthFee,
            this.getCurrency()));

    Set<String> recipients = new HashSet<String>();

    int secondsTotal = 0;
    for (Chargeable chargeable : data) {
      if (chargeable.getChargeableType() == Chargeable.CHARGEABLE_TYPE_CALL) {
        Call call = (Call) chargeable;

        if (call.getType() != Call.CALL_TYPE_SENT) {
          continue;
        }

        double callPrice = 0;

        if (call.getContact().getMsisdnType() == MsisdnType.ES_SPECIAL_ZER0) {
          callPrice = 0;
        } else {
          int hourOfDay = call.getDate().get(Calendar.HOUR_OF_DAY);
          boolean insideDay = (hourOfDay < 8 || hourOfDay >= 18);
          if (insideDay) {
            secondsTotal += call.getDuration();
            recipients.add(call.getContact().getMsisdn());
          }
          boolean insidePlan =
              insideDay && secondsTotal <= maxSecondsMonth && recipients.size() <= maxRecipients;
          if (!insidePlan) {
            long duration =
                (secondsTotal > maxSecondsMonth)
                        && (secondsTotal - call.getDuration() <= maxSecondsMonth)
                    ? secondsTotal - maxSecondsMonth
                    : call.getDuration();
            callPrice += initialPrice + (duration * pricePerSecond);
          }
        }
        ret.addPlanCall(new PlanChargeable(call, callPrice, this.getCurrency()));
      } else if (chargeable.getChargeableType() == Chargeable.CHARGEABLE_TYPE_SMS) {
        Sms sms = (Sms) chargeable;
        if (sms.getType() == Sms.SMS_TYPE_RECEIVED) {
          continue;
        }
        ret.addPlanCall(new PlanChargeable(chargeable, smsPrice, this.getCurrency()));
      }
    }
    return ret;
  }
Example #5
0
  public PlanSummary process(ArrayList<Chargeable> data) {
    PlanSummary ret = new PlanSummary(this);
    ret.addPlanCall(
        new PlanChargeable(
            new ChargeableMessage(ChargeableMessage.MESSAGE_MONTH_FEE),
            monthFee,
            this.getCurrency()));

    long secondsTotal = 0;
    int smsSent = 0;
    for (Chargeable chargeable : data) {
      if (chargeable.getChargeableType() == Chargeable.CHARGEABLE_TYPE_CALL) {
        Call call = (Call) chargeable;
        if (call.getType() != Call.CALL_TYPE_SENT) {
          continue;
        }

        double callPrice = 0;

        if (call.getContact().getMsisdnType() == MsisdnType.ES_SPECIAL_ZER0) {
          callPrice = 0;
        } else {
          secondsTotal += call.getDuration();
          if (secondsTotal > maxSecondsMonth) {
            long duration =
                (secondsTotal > maxSecondsMonth)
                        && (secondsTotal - call.getDuration() <= maxSecondsMonth)
                    ? secondsTotal - maxSecondsMonth
                    : call.getDuration();
            callPrice += initialPrice + (duration * pricePerSecond);
          }
        }
        ret.addPlanCall(new PlanChargeable(call, callPrice, this.getCurrency()));
      } else if (chargeable.getChargeableType() == Chargeable.CHARGEABLE_TYPE_SMS) {
        Sms sms = (Sms) chargeable;
        if (sms.getType() == Sms.SMS_TYPE_RECEIVED) {
          continue;
        }
        smsSent++;
        ret.addPlanCall(
            new PlanChargeable(
                chargeable, (smsSent > maxFreeSMS) ? smsPrice : 0, this.getCurrency()));
      }
    }
    return ret;
  }