Search in sources :

Example 1 with ErrorMessage

use of org.kuali.kfs.krad.util.ErrorMessage in project cu-kfs by CU-CommunityApps.

the class IWantDocumentFeedServiceImpl method logErrorMessages.

/**
 * Logs error messages from GlobalVariables.
 */
protected void logErrorMessages() {
    Map<String, AutoPopulatingList<ErrorMessage>> errors = GlobalVariables.getMessageMap().getErrorMessages();
    for (AutoPopulatingList<ErrorMessage> error : errors.values()) {
        Iterator<ErrorMessage> iterator = error.iterator();
        while (iterator.hasNext()) {
            ErrorMessage errorMessage = iterator.next();
            LOG.error(errorMessage.toString());
        }
    }
    GlobalVariables.getMessageMap().clearErrorMessages();
}
Also used : ErrorMessage(org.kuali.kfs.krad.util.ErrorMessage) AutoPopulatingList(org.springframework.util.AutoPopulatingList)

Example 2 with ErrorMessage

use of org.kuali.kfs.krad.util.ErrorMessage in project cu-kfs by CU-CommunityApps.

the class CuPaymentFileValidationServiceImpl method printErrorMap.

public String printErrorMap(MessageMap errorMap) {
    StringBuilder sb = new StringBuilder();
    Set<String> keys = errorMap.getErrorMessages().keySet();
    if (keys.size() > 0) {
        for (String key : keys) {
            AutoPopulatingList<ErrorMessage> errors = errorMap.getErrorMessages().get(key);
            for (ErrorMessage error : errors) {
                sb.append("  Key: ").append(key).append("  error: ").append(error.toString());
            }
        }
    } else {
        sb.append("No errors");
    }
    return sb.toString();
}
Also used : ErrorMessage(org.kuali.kfs.krad.util.ErrorMessage)

Example 3 with ErrorMessage

use of org.kuali.kfs.krad.util.ErrorMessage in project cu-kfs by CU-CommunityApps.

the class BatchFeedHelperServiceImpl method getAuditMessage.

/**
 * @see com.rsmart.kuali.kfs.sys.batch.service.BatchFeedHelperService#getAuditMessage(java.lang.String, java.lang.String,
 *      org.kuali.kfs.kns.util.ErrorMap)
 */
public String getAuditMessage(String successfulErrorKey, String documentNumber, MessageMap errorMap) {
    String auditMessage = "";
    if (errorMap.hasErrors()) {
        for (String errorProperty : errorMap.getAllPropertiesWithErrors()) {
            for (Object errorMessage : errorMap.getMessages(errorProperty)) {
                String errorMsg = kualiConfigurationService.getPropertyValueAsString(((ErrorMessage) errorMessage).getErrorKey());
                if (errorMsg == null) {
                    throw new RuntimeException("Cannot find message for error key: " + ((ErrorMessage) errorMessage).getErrorKey());
                } else {
                    Object[] arguments = (Object[]) ((ErrorMessage) errorMessage).getMessageParameters();
                    if (arguments != null && arguments.length != 0) {
                        errorMsg = MessageFormat.format(errorMsg, arguments);
                    }
                }
                auditMessage += errorMsg + " ";
            }
        }
    }
    // add error prefix
    if (!StringUtils.isBlank(auditMessage)) {
        auditMessage = com.rsmart.kuali.kfs.sys.KFSConstants.AUDIT_REPORT_ERROR_PREFIX + auditMessage;
    } else {
        String successMessage = kualiConfigurationService.getPropertyValueAsString(successfulErrorKey);
        auditMessage = MessageFormat.format(successMessage, documentNumber);
    }
    return auditMessage;
}
Also used : PersistableBusinessObject(org.kuali.kfs.krad.bo.PersistableBusinessObject) ErrorMessage(org.kuali.kfs.krad.util.ErrorMessage)

Example 4 with ErrorMessage

use of org.kuali.kfs.krad.util.ErrorMessage in project cu-kfs by CU-CommunityApps.

the class PaymentFileServiceImpl method createOutputFile.

/**
 * @see org.kuali.kfs.pdp.service.PaymentFileService#createOutputFile(org.kuali.kfs.pdp.businessobject.LoadPaymentStatus,
 *      java.lang.String)
 */
@Override
public boolean createOutputFile(LoadPaymentStatus status, String inputFileName) {
    // add a step to check for directory paths
    prepareDirectories(getRequiredDirectoryNames());
    // construct the outgoing file name
    String filename = outgoingDirectoryName + "/" + getBaseFileName(inputFileName);
    // set code-message indicating overall load status
    String code;
    String message;
    if (LoadPaymentStatus.LoadStatus.SUCCESS.equals(status.getLoadStatus())) {
        code = "SUCCESS";
        message = "Successful Load";
    } else {
        code = "FAIL";
        message = "Load Failed: ";
        List<ErrorMessage> errorMessages = status.getMessageMap().getMessages(KFSConstants.GLOBAL_ERRORS);
        for (ErrorMessage errorMessage : errorMessages) {
            String resourceMessage = kualiConfigurationService.getPropertyValueAsString(errorMessage.getErrorKey());
            resourceMessage = MessageFormat.format(resourceMessage, (Object[]) errorMessage.getMessageParameters());
            message += resourceMessage + ", ";
        }
    }
    try {
        FileOutputStream out = new FileOutputStream(filename);
        PrintStream p = new PrintStream(out);
        p.println("<pdp_load_status>");
        p.println("  <input_file_name>" + inputFileName + "</input_file_name>");
        p.println("  <code>" + code + "</code>");
        p.println("  <count>" + status.getDetailCount() + "</count>");
        if (status.getDetailTotal() != null) {
            p.println("  <total>" + status.getDetailTotal() + "</total>");
        } else {
            p.println("  <total>0</total>");
        }
        p.println("  <description>" + message + "</description>");
        if (ObjectUtils.isNotNull(status.getWarnings())) {
            // Warnings list may be null if file failed to load.
            p.println("  <messages>");
            for (String warning : status.getWarnings()) {
                p.println("    <message>" + warning + "</message>");
            }
            p.println("  </messages>");
        }
        p.println("</pdp_load_status>");
        p.close();
        out.close();
        // creating .done file
        File doneFile = new File(filename.substring(0, filename.lastIndexOf(".")) + ".done");
        doneFile.createNewFile();
    } catch (FileNotFoundException e) {
        LOG.error("createOutputFile() Cannot create output file", e);
        return false;
    } catch (IOException e) {
        LOG.error("createOutputFile() Cannot write to output file", e);
        return false;
    }
    return true;
}
Also used : PrintStream(java.io.PrintStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ErrorMessage(org.kuali.kfs.krad.util.ErrorMessage) File(java.io.File)

Example 5 with ErrorMessage

use of org.kuali.kfs.krad.util.ErrorMessage in project cu-kfs by CU-CommunityApps.

the class PaymentWorksDataProcessingIntoKfsServiceImpl method convertReportDataValidationErrors.

private List<String> convertReportDataValidationErrors(Map<String, AutoPopulatingList<ErrorMessage>> kfsGlobalVariablesMessageMap) {
    List<String> reportDataErrors = new ArrayList<String>();
    ErrorMessage errorMessage = null;
    String errorText = KFSConstants.EMPTY_STRING;
    for (Map.Entry<String, AutoPopulatingList<ErrorMessage>> errorEntry : kfsGlobalVariablesMessageMap.entrySet()) {
        Iterator<ErrorMessage> iterator = errorEntry.getValue().iterator();
        while (iterator.hasNext()) {
            errorMessage = iterator.next();
            errorText = getConfigurationService().getPropertyValueAsString(errorMessage.getErrorKey());
            errorText = MessageFormat.format(errorText, (Object[]) errorMessage.getMessageParameters());
            reportDataErrors.add(errorText);
            LOG.error("convertReportDataValidationErrors: errorKey: " + errorMessage.getErrorKey() + "  errorMessages:: " + errorText);
        }
    }
    return reportDataErrors;
}
Also used : ArrayList(java.util.ArrayList) ErrorMessage(org.kuali.kfs.krad.util.ErrorMessage) Map(java.util.Map) AutoPopulatingList(org.springframework.util.AutoPopulatingList)

Aggregations

ErrorMessage (org.kuali.kfs.krad.util.ErrorMessage)5 AutoPopulatingList (org.springframework.util.AutoPopulatingList)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 PersistableBusinessObject (org.kuali.kfs.krad.bo.PersistableBusinessObject)1