示例#1
0
  /**
   * Checks the business object service to see if the profile account exists
   *
   * @see
   *     org.kuali.kfs.module.tem.service.TemProfileService#doesProfileAccountExist(org.kuali.kfs.module.tem.businessobject.TemProfileAccount,
   *     org.kuali.kfs.module.tem.businessobject.TemProfile)
   */
  @Override
  public boolean doesProfileAccountExist(TemProfileAccount account, TemProfile skipProfile) {
    Map<String, Object> fieldValues = new HashMap<String, Object>();
    fieldValues.put(KFSPropertyConstants.ACCOUNT_NUMBER, account.getAccountNumber());
    fieldValues.put(
        TemPropertyConstants.CREDIT_CARD_AGENCY_CODE, account.getCreditCardOrAgencyCode());
    fieldValues.put(KFSPropertyConstants.ACTIVE, Boolean.TRUE);
    final Collection<TemProfileAccount> profileAccounts =
        getBusinessObjectService().findMatching(TemProfileAccount.class, fieldValues);
    if (skipProfile != null && skipProfile.getId() != null) {
      List<TemProfileAccount> otherFolksAccounts = new ArrayList<TemProfileAccount>();
      for (TemProfileAccount profileAccount :
          profileAccounts) { // loop through all accounts to exhaust any iterator
        if (profileAccount.getProfileId().equals(skipProfile.getId())) {
          otherFolksAccounts.add(profileAccount);
        }
      }
      return otherFolksAccounts.size() > 0;
    }

    // otherwise, just return the size of the profileAccounts
    return profileAccounts.size() > 0;
  }
  /**
   * @see
   *     org.kuali.kfs.module.tem.batch.service.CreditCardDataImportService#validateCreditCardData(org.kuali.kfs.module.tem.businessobject.CreditCardImportData,
   *     java.lang.String)
   */
  @Override
  public List<CreditCardStagingData> validateCreditCardData(
      CreditCardImportData creditCardList, String dataFileName) {

    PrintStream reportDataStream =
        dataReportService.getReportPrintStream(
            getCreditCardDataReportDirectory(), getCreditCardDataReportFilePrefix());
    List<CreditCardStagingData> validData = new ArrayList<CreditCardStagingData>();

    try {
      dataReportService.writeReportHeader(
          reportDataStream,
          dataFileName,
          TemKeyConstants.MESSAGE_CREDIT_CARD_DATA_REPORT_HEADER,
          getCreditCardDataUploadReportHelper());
      Integer count = 1;
      for (CreditCardStagingData creditCardData : creditCardList.getCreditCardData()) {
        LOG.info(
            "Validating credit card import. Record# "
                + count
                + " of "
                + creditCardList.getCreditCardData().size());

        creditCardData.setErrorCode(CreditCardStagingDataErrorCodes.CREDIT_CARD_NO_ERROR);
        creditCardData.setImportBy(creditCardList.getImportBy());
        creditCardData.setStagingFileName(
            StringUtils.substringAfterLast(dataFileName, File.separator));

        List<ErrorMessage> errorMessages = new ArrayList<ErrorMessage>();

        if (validateAndSetCreditCardAgency(creditCardData)) {

          if (creditCardData.getExpenseImport() == ExpenseImport.traveler) {

            TemProfileAccount temProfileAccount = findTraveler(creditCardData);
            if (ObjectUtils.isNotNull(temProfileAccount)) {

              // Set Traveler Id
              if (ObjectUtils.isNull(creditCardData.getTravelerId())
                  || creditCardData.getTravelerId() == 0) {
                Integer travelerId =
                    new Integer(temProfileAccount.getProfile().getEmployeeId()).intValue();
                creditCardData.setTravelerId(travelerId);
              }

              creditCardData.setTemProfileId(temProfileAccount.getProfileId());

              // Set expense type code to O-Other if null
              if (creditCardData.getExpenseTypeCode() == null) {
                creditCardData.setExpenseTypeCode(ExpenseTypes.OTHER);
              }

              // write an error if the expense type code is not valid
              final ExpenseType expenseType =
                  businessObjectService.findBySinglePrimaryKey(
                      ExpenseType.class, creditCardData.getExpenseTypeCode());
              if (ObjectUtils.isNotNull(expenseType)) {

                // Set Credit Card Key(traveler Id + Credit Card Agency + Credit Card number
                creditCardData.setCreditCardKey(
                    creditCardData.getTravelerId()
                        + temProfileAccount.getCreditCardAgency().getCreditCardOrAgencyCode()
                        + creditCardData.getCreditCardNumber());

                // need to do the duplicate check at this point, since the CC key is one of the
                // fields being checked
                if (!isDuplicate(creditCardData, errorMessages)) {
                  creditCardData.setMoveToHistoryIndicator(true);
                  creditCardData.setProcessingTimestamp(dateTimeService.getCurrentTimestamp());
                  validData.add(creditCardData);
                }
              } else {
                LOG.error(
                    "Invalid expense type code "
                        + creditCardData.getExpenseTypeCode()
                        + " in Credit Card Data record");
                errorMessages.add(
                    new ErrorMessage(
                        TemKeyConstants.MESSAGE_CREDIT_CARD_DATA_INVALID_EXPENSE_TYPE_CODE,
                        creditCardData.getExpenseTypeCode()));
              }
            } else {
              LOG.error(
                  "No traveler found for credit card number: "
                      + creditCardData.getCreditCardNumber());
              errorMessages.add(
                  new ErrorMessage(
                      TemKeyConstants.MESSAGE_CREDIT_CARD_DATA_NO_TRAVELER_FOUND,
                      creditCardData.getCreditCardNumber()));
            }
          } else if (creditCardData.getExpenseImport() == ExpenseImport.trip) {

            if (!isDuplicate(creditCardData, errorMessages)) {
              creditCardData.setProcessingTimestamp(dateTimeService.getCurrentTimestamp());
              validData.add(creditCardData);
            }
          }

        } else {
          errorMessages.add(
              new ErrorMessage(
                  TemKeyConstants.MESSAGE_AGENCY_CREDIT_CARD_DATA_INVALID_CCA,
                  creditCardData.getCreditCardOrAgencyCode()));
        }

        // writer to error report
        if (!errorMessages.isEmpty()) {
          dataReportService.writeToReport(
              reportDataStream,
              creditCardData,
              errorMessages,
              getCreditCardDataUploadReportHelper());
        }

        count++;
      }
    } finally {
      if (reportDataStream != null) {
        reportDataStream.flush();
        reportDataStream.close();
      }
    }
    return validData;
  }