private void testUpdateCreate(boolean edit) throws ClassNotFoundException {
    final DateTime dtValue = DateUtil.now();

    mockSampleFields();
    mockDataService();
    mockEntity();
    when(motechDataService.retrieve("id", INSTANCE_ID)).thenReturn(new TestSample());

    List<FieldRecord> fieldRecords =
        asList(
            FieldTestHelper.fieldRecord("strField", String.class.getName(), "", "this is a test"),
            FieldTestHelper.fieldRecord("intField", Integer.class.getName(), "", 16),
            FieldTestHelper.fieldRecord("timeField", Time.class.getName(), "", "10:17"),
            FieldTestHelper.fieldRecord("dtField", DateTime.class.getName(), "", dtValue));

    Long id = (edit) ? INSTANCE_ID : null;
    EntityRecord record = new EntityRecord(id, ENTITY_ID, fieldRecords);

    MDSClassLoader.getInstance().loadClass(TestSample.class.getName());
    instanceService.saveInstance(record);

    ArgumentCaptor<TestSample> captor = ArgumentCaptor.forClass(TestSample.class);
    if (edit) {
      verify(motechDataService).update(captor.capture());
    } else {
      verify(motechDataService).create(captor.capture());
    }

    TestSample sample = captor.getValue();
    assertEquals("this is a test", sample.getStrField());
    assertEquals(Integer.valueOf(16), sample.getIntField());
    assertEquals(new Time(10, 17), sample.getTimeField());
    assertEquals(dtValue, sample.getDtField());
  }
 private void prepareUser() {
   user = new MotechUser();
   user.setLastPasswordChange(
       DateUtil.now().minusDays(DAYS_TO_CHANGE_PASSWORD - DAYS_FOR_REMINDER));
   user.setUserName("FooUsername");
   user.setEmail("*****@*****.**");
 }
  @Override
  public void generateDailyReports() {
    DateTimeFormatter formatter = DateTimeFormat.forPattern(EbodacConstants.REPORT_DATE_FORMAT);

    Config config = configService.getConfig();

    if (config.getGenerateReports() != null && config.getGenerateReports()) {
      String lastCalculationDate = config.getLastCalculationDate();
      String calculationStartDate = config.getFirstCalculationStartDate();

      LocalDate startDate;

      if (StringUtils.isNotBlank(lastCalculationDate)) {
        startDate = LocalDate.parse(lastCalculationDate, formatter).plusDays(1);
      } else if (StringUtils.isNotBlank(calculationStartDate)) {
        startDate = LocalDate.parse(calculationStartDate, formatter);
      } else {
        startDate = subjectService.findOldestPrimerVaccinationDate();
      }

      updateBoosterVaccinationReportsForDates(
          reportUpdateService.getBoosterVaccinationReportsToUpdate());
      updatePrimerVaccinationReportsForDates(
          reportUpdateService.getPrimerVaccinationReportsToUpdate());

      generateDailyReportsFromDate(startDate);

      config = configService.getConfig();
      config.setGenerateReports(false);
      config.setLastCalculationDate(DateUtil.now().minusDays(1).toString(formatter));
      configService.updateConfig(config);
    }
  }
  @Override
  public void generateDailyReportsFromDate(LocalDate startDate) {
    LocalDate now = DateUtil.now().toLocalDate();

    for (LocalDate date = startDate; date.isBefore(now); date = date.plusDays(1)) {
      generateOrUpdatePrimerVaccinationReport(
          subjectService.findSubjectsPrimerVaccinatedAtDay(date), date);
      generateOrUpdateBoosterVaccinationReport(
          subjectService.findSubjectsBoosterVaccinatedAtDay(date), date);
    }
  }
Beispiel #5
0
  public Alert(
      String externalId,
      AlertType alertType,
      AlertStatus status,
      int priority,
      Map<String, String> data) {
    this.externalId = externalId;
    this.alertType = alertType;
    this.status = status;
    this.priority = (long) priority;
    this.dateTime = DateUtil.now();
    this.data = new HashMap<>();

    if (null != data) {
      this.data.putAll(data);
    }
  }
  @Override
  public void generateIvrAndSmsStatisticReportsFromDate(LocalDate startDate) {
    List<CallDetailRecord> callDetailRecords = new ArrayList<>();

    if (startDate == null) {
      callDetailRecords =
          callDetailRecordDataService.findByCallStatus(
              EbodacConstants.IVR_CALL_DETAIL_RECORD_STATUS_INITIATED);
    } else {
      LocalDate now = DateUtil.now().toLocalDate();

      for (LocalDate date = startDate; date.isBefore(now); date = date.plusDays(1)) {
        String dateString = SIMPLE_DATE_FORMATTER.print(date);
        callDetailRecords.addAll(
            callDetailRecordDataService.findByMotechTimestampAndCallStatus(
                dateString, EbodacConstants.IVR_CALL_DETAIL_RECORD_STATUS_INITIATED));
      }
    }

    Config config = configService.getConfig();
    Set<String> reportsToUpdate = config.getIvrAndSmsStatisticReportsToUpdate();
    config.setIvrAndSmsStatisticReportsToUpdate(null);
    configService.updateConfig(config);

    if (startDate != null && !reportsToUpdate.isEmpty()) {
      callDetailRecords.addAll(callDetailRecordDataService.findByMotechCallIds(reportsToUpdate));
    }

    for (CallDetailRecord callDetailRecord : callDetailRecords) {
      try {
        createIvrAndSmsStatisticReport(callDetailRecord);
        reportsToUpdate.remove(callDetailRecord.getMotechCallId());
      } catch (EbodacReportException e) {
        LOGGER.warn(e.getMessage());
      }
    }

    config = configService.getConfig();
    reportsToUpdate.addAll(config.getIvrAndSmsStatisticReportsToUpdate());
    config.setIvrAndSmsStatisticReportsToUpdate(reportsToUpdate);
    configService.updateConfig(config);
  }
Beispiel #7
0
  @Test
  public void shouldProperlyApplyManipulations() throws Exception {
    String string = "ala-has-a-cat";
    DateTime now = DateUtil.now();
    String toString = now.toString();
    String toStringWithPattern = now.toString("yyyy-MM-dd");
    KeyEvaluator keyEvaluator = new KeyEvaluator(null);

    String pastDate = "2015-05-15";
    String timeZone =
        new DateTime(pastDate)
            .toString("Z"); // Figure out the correct time zone for the given date and locale

    assertEquals("lower_case", keyEvaluator.manipulate("tolower", "LOWER_CASE"));
    assertEquals("UPPER_CASE", keyEvaluator.manipulate("toupper", "upper_case"));
    assertEquals("Capitalize", keyEvaluator.manipulate("capitalize", "capitalize"));
    assertEquals("My+sample+message", keyEvaluator.manipulate("urlencode", "My sample message"));
    assertEquals("37%2365%4078%2490", keyEvaluator.manipulate("URLEncode", "37#65@78$90"));
    assertEquals("67890", keyEvaluator.manipulate("substring(5)", "1234567890"));
    assertEquals("67", keyEvaluator.manipulate("substring(5,7)", "1234567890"));
    assertEquals(string, keyEvaluator.manipulate("join(-)", "ala has a cat"));
    assertEquals("ala", keyEvaluator.manipulate("split(-,0)", string));
    assertEquals("cat", keyEvaluator.manipulate("split(-,3)", string));
    assertEquals(
        pastDate + " 11:32 " + timeZone,
        keyEvaluator.manipulate("parseDate(yyyy/dd/MM hh:mm)", "2015/15/05 11:32"));
    assertEquals(toStringWithPattern, keyEvaluator.manipulate("datetime(yyyy-MM-dd)", toString));
    assertEquals(now.plusDays(1).toString(), keyEvaluator.manipulate("plusDays(1)", toString));
    assertEquals(now.minusDays(1).toString(), keyEvaluator.manipulate("minusDays(1)", toString));
    assertEquals(now.plusHours(2).toString(), keyEvaluator.manipulate("plusHours(2)", toString));
    assertEquals(now.minusHours(2).toString(), keyEvaluator.manipulate("minusHours(2)", toString));
    assertEquals(
        now.plusMinutes(20).toString(), keyEvaluator.manipulate("plusMinutes(20)", toString));
    assertEquals(
        now.minusMinutes(20).toString(), keyEvaluator.manipulate("minusMinutes(20)", toString));
  }