コード例 #1
0
  public SmsMessage assembleFromJson(final JsonCommand command) {

    final JsonElement element = command.parsedJson();

    String mobileNo = null;

    Group group = null;
    if (this.fromApiJsonHelper.parameterExists(SmsApiConstants.groupIdParamName, element)) {
      final Long groupId =
          this.fromApiJsonHelper.extractLongNamed(SmsApiConstants.groupIdParamName, element);
      group = this.groupRepository.findOneWithNotFoundDetection(groupId);
    }

    Client client = null;
    if (this.fromApiJsonHelper.parameterExists(SmsApiConstants.clientIdParamName, element)) {
      final Long clientId =
          this.fromApiJsonHelper.extractLongNamed(SmsApiConstants.clientIdParamName, element);
      client = this.clientRepository.findOneWithNotFoundDetection(clientId);
      mobileNo = client.mobileNo();
    }

    Staff staff = null;
    if (this.fromApiJsonHelper.parameterExists(SmsApiConstants.staffIdParamName, element)) {
      final Long staffId =
          this.fromApiJsonHelper.extractLongNamed(SmsApiConstants.staffIdParamName, element);
      staff = this.staffRepository.findOneWithNotFoundDetection(staffId);
      mobileNo = staff.mobileNo();
    }

    final String message =
        this.fromApiJsonHelper.extractStringNamed(SmsApiConstants.messageParamName, element);

    return SmsMessage.pendingSms(group, client, staff, message, mobileNo);
  }
  @Override
  public CommandProcessingResult updateOfficeRunningBalance(JsonCommand command) {
    this.dataValidator.validateForUpdateRunningbalance(command);
    final Long officeId =
        this.fromApiJsonHelper.extractLongNamed(
            JournalEntryJsonInputParams.OFFICE_ID.getValue(), command.parsedJson());
    CommandProcessingResultBuilder commandProcessingResultBuilder =
        new CommandProcessingResultBuilder().withCommandId(command.commandId());
    if (officeId == null) {
      updateRunningBalance();
    } else {
      final Office office = this.officeRepository.findOne(officeId);
      if (office == null) {
        throw new OfficeNotFoundException(officeId);
      }

      String dateFinder =
          "select MIN(je.entry_date) as entityDate "
              + "from acc_gl_journal_entry  je "
              + "where je.is_running_balance_calculated=0  and je.office_id=?";
      try {
        Date entityDate = this.jdbcTemplate.queryForObject(dateFinder, Date.class, officeId);
        updateRunningBalance(officeId, entityDate);
      } catch (EmptyResultDataAccessException e) {
        logger.debug(
            "No results found for updation of office running balance with office id:" + officeId);
      }
      commandProcessingResultBuilder.withOfficeId(officeId);
    }
    return commandProcessingResultBuilder.build();
  }