Example usage for org.apache.commons.lang StringUtils deleteWhitespace

List of usage examples for org.apache.commons.lang StringUtils deleteWhitespace

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils deleteWhitespace.

Prototype

public static String deleteWhitespace(String str) 

Source Link

Document

Deletes all whitespaces from a String as defined by Character#isWhitespace(char) .

Usage

From source file:org.kuali.kra.proposaldevelopment.bo.ProposalPerson.java

/**
 * set the <code>simpleName</code> & the full name.
 *//*from  w  ww. j a  v  a  2 s  . c o m*/
public void setFullName(String fullName) {
    this.fullName = fullName;

    setSimpleName(getFullName());

    setSimpleName(getSimpleName().toLowerCase());
    setSimpleName(StringUtils.deleteWhitespace(getSimpleName()));
    setSimpleName(StringUtils.remove(getSimpleName(), '.'));
}

From source file:org.kuali.kra.rule.event.AuditCustomDataEvent.java

public void reportError(CustomAttribute customAttribute, String propertyName, String errorKey,
        String... errorParams) {//from   ww w.j  a  v a 2  s .  co  m
    String key = "CustomData" + StringUtils.deleteWhitespace(customAttribute.getGroupName()) + "Errors";
    AuditCluster auditCluster = (AuditCluster) KNSGlobalVariables.getAuditErrorMap().get(key);
    if (auditCluster == null) {
        List<AuditError> auditErrors = new ArrayList<AuditError>();
        auditCluster = new AuditCluster(customAttribute.getGroupName(), auditErrors, Constants.AUDIT_ERRORS);
        KNSGlobalVariables.getAuditErrorMap().put(key, auditCluster);
    }
    List<AuditError> auditErrors = auditCluster.getAuditErrorList();
    auditErrors
            .add(new AuditError(propertyName, errorKey,
                    StringUtils.deleteWhitespace(
                            Constants.CUSTOM_ATTRIBUTES_PAGE + "." + customAttribute.getGroupName()),
                    errorParams));

}

From source file:org.kuali.kra.rules.ResearchDocumentBaseAuditRule.java

/**
 * @see org.kuali.core.rule.DocumentAuditRule#processRunAuditBusinessRules(org.kuali.rice.kns.document.Document)
 *///from  ww  w. ja va  2 s.c  o  m
public boolean processRunAuditBusinessRules(Document document) {
    boolean valid = true;

    if (document instanceof ResearchDocumentBase) {
        Map<String, CustomAttributeDocument> customAttributeDocuments = ((ResearchDocumentBase) document)
                .getCustomAttributeDocuments();

        for (Map.Entry<String, CustomAttributeDocument> customAttributeDocumentEntry : customAttributeDocuments
                .entrySet()) {
            CustomAttributeDocument customAttributeDocument = customAttributeDocumentEntry.getValue();
            CustomAttribute customAttribute = customAttributeDocument.getCustomAttribute();
            if (customAttributeDocument.isRequired() && StringUtils.isEmpty(customAttribute.getValue())) {
                valid = false;
                String key = "CustomData" + StringUtils.deleteWhitespace(customAttribute.getGroupName())
                        + "Errors";
                AuditCluster auditCluster = (AuditCluster) GlobalVariables.getAuditErrorMap().get(key);
                if (auditCluster == null) {
                    List<AuditError> auditErrors = new ArrayList<AuditError>();
                    //auditCluster = new AuditCluster("Custom Data: " + customAttribute.getGroupName(), auditErrors, Constants.AUDIT_ERRORS);
                    auditCluster = new AuditCluster(customAttribute.getGroupName(), auditErrors,
                            Constants.AUDIT_ERRORS);
                    GlobalVariables.getAuditErrorMap().put(key, auditCluster);
                }
                List<AuditError> auditErrors = auditCluster.getAuditErrorList();
                auditErrors.add(new AuditError(
                        "customAttributeValues(id" + customAttributeDocument.getCustomAttributeId() + ")",
                        RiceKeyConstants.ERROR_REQUIRED,
                        StringUtils.deleteWhitespace(
                                Constants.CUSTOM_ATTRIBUTES_PAGE + "." + customAttribute.getGroupName()),
                        new String[] { customAttribute.getLabel() }));
            }
        }

    }

    return valid;
}

From source file:org.kuali.kra.rules.ResearchDocumentBaseAuditRuleTest.java

@Test
public void testRequiredCustomAttributeFieldsMissing() throws Exception {
    ProposalDevelopmentDocument document = getNewDocument();

    Map<String, CustomAttribute> requiredFields = new HashMap<String, CustomAttribute>();

    Map<String, CustomAttributeDocument> customAttributeDocuments = ((ResearchDocumentBase) document)
            .getCustomAttributeDocuments();
    for (Map.Entry<String, CustomAttributeDocument> customAttributeDocumentEntry : customAttributeDocuments
            .entrySet()) {//from w  ww . jav a2s.c om
        CustomAttributeDocument customAttributeDocument = customAttributeDocumentEntry.getValue();
        CustomAttribute customAttribute = customAttributeDocument.getCustomAttribute();
        if (customAttributeDocument.isRequired()) {
            requiredFields.put("customData." + customAttribute.getGroupName() + customAttribute.getName(),
                    customAttribute);
        }
        CustomAttributeDocValue newValue = new CustomAttributeDocValue();
        newValue.setCustomAttribute(customAttributeDocument.getCustomAttribute());
        newValue.setCustomAttributeId(customAttributeDocument.getCustomAttributeId().longValue());
        newValue.setValue(null);
        document.getCustomDataList().add(newValue);
    }

    assertFalse("Audit Rule should produce an audit error", auditRule.processRunAuditBusinessRules(document));
    assertEquals(requiredFields.size(), KNSGlobalVariables.getAuditErrorMap().size());

    for (String key : requiredFields.keySet()) {
        CustomAttribute customAttribute = requiredFields.get(key);
        AuditCluster auditCluster = (AuditCluster) KNSGlobalVariables.getAuditErrorMap()
                .get("CustomData" + StringUtils.deleteWhitespace(customAttribute.getGroupName()) + "Errors");

        assertEquals(1, auditCluster.getSize());
        //assertEquals("Custom Data: " + customAttribute.getGroupName(), auditCluster.getLabel());
        assertEquals(customAttribute.getGroupName(), auditCluster.getLabel());
        assertEquals("Validation Errors", auditCluster.getCategory());
        AuditError auditError = (AuditError) auditCluster.getAuditErrorList().get(0);
        int index = 0;
        for (CustomAttributeDocValue value : document.getCustomDataList()) {
            if (value.getCustomAttributeId().longValue() == customAttribute.getId().longValue()) {
                break;
            }
            index++;
        }
        assertEquals("customDataHelper.customDataList[" + index + "].value", auditError.getErrorKey());
        assertEquals("customData." + StringUtils.deleteWhitespace(customAttribute.getGroupName()),
                auditError.getLink());
        assertEquals(customAttribute.getLabel(), auditError.getParams()[0]);
        assertEquals(RiceKeyConstants.ERROR_REQUIRED, auditError.getMessageKey());
    }

}

From source file:org.kuali.kra.test.infrastructure.KcSeleniumHelper.java

/**
 * Returns the generated id of a tab based on the {@code tabTitle}, which appears between "tab-" and "-imageToggle" and without whitespace.
 * //from   ww  w .j  ava 2 s.com
 * @param tabTitle the title of the tab on the web page
 */
private String getTabId(final String tabTitle) {
    return "tab-" + StringUtils.deleteWhitespace(tabTitle) + "-imageToggle";
}

From source file:org.kuali.ole.module.purap.util.ItemParserBase.java

/**
 * @see org.kuali.ole.module.purap.util.ItemParser#parseItem(org.apache.struts.upload.FormFile, java.lang.Class, java.lang.String)
 */// w w  w  .  j a  v  a  2s .c om
public List<PurApItem> importItems(FormFile itemFile, Class<? extends PurApItem> itemClass,
        String documentNumber) {
    // check input parameters
    try {
        checkItemClass(itemClass);
        checkItemFile(itemFile);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("unable to import items.", e);
    }

    // open input stream
    List<PurApItem> importedItems = new ArrayList<PurApItem>();
    InputStream is;
    BufferedReader br;
    try {
        is = itemFile.getInputStream();
        br = new BufferedReader(new InputStreamReader(is));
    } catch (IOException e) {
        throw new IllegalArgumentException("unable to open import file in ItemParserBase.", e);
    }

    // parse items line by line
    lineNo = 0;
    boolean failed = false;
    String itemLine = null;
    try {
        while ((itemLine = br.readLine()) != null) {
            lineNo++;

            if (StringUtils
                    .isBlank(StringUtils.remove(StringUtils.deleteWhitespace(itemLine), OLEConstants.COMMA))) {
                continue;
            }

            try {
                PurApItem item = parseItem(itemLine, itemClass, documentNumber);
                importedItems.add(item);
            } catch (ItemParserException e) {
                // continue to parse the rest of the items after the current item fails
                // error messages are already dealt with inside parseItem, so no need to do anything here
                failed = true;
            }
        }

        if (failed) {
            throw new ItemParserException("errors in parsing item lines in file " + itemFile.getFileName(),
                    ERROR_ITEMPARSER_ITEM_LINE, itemFile.getFileName());
        }
    } catch (IOException e) {
        throw new IllegalArgumentException("unable to read line from BufferReader in ItemParserBase", e);
    } finally {
        try {
            br.close();
        } catch (IOException e) {
            throw new IllegalArgumentException("unable to close BufferReader in ItemParserBase", e);
        }
    }

    return importedItems;
}

From source file:org.kuali.ole.pdp.service.impl.PdpEmailServiceImpl.java

/**
 * @see org.kuali.ole.pdp.service.PdpEmailService#sendErrorEmail(org.kuali.ole.pdp.businessobject.PaymentFileLoad,
 *      org.kuali.rice.kns.util.ErrorMap)
 *///from  w  w w .j  av  a  2 s.c  o  m
@Override
public void sendErrorEmail(PaymentFileLoad paymentFile, MessageMap errors) {
    LOG.debug("sendErrorEmail() starting");

    // check email configuration
    if (!isPaymentEmailEnabled()) {
        return;
    }

    MailMessage message = new MailMessage();

    String returnAddress = parameterService.getParameterValueAsString(
            OleParameterConstants.PRE_DISBURSEMENT_BATCH.class, OLEConstants.FROM_EMAIL_ADDRESS_PARM_NM);
    if (StringUtils.isEmpty(returnAddress)) {
        returnAddress = mailService.getBatchMailingList();
    }
    message.setFromAddress(returnAddress);
    message.setSubject(
            getEmailSubject(PdpParameterConstants.PAYMENT_LOAD_FAILURE_EMAIL_SUBJECT_PARAMETER_NAME));

    StringBuilder body = new StringBuilder();
    List<String> ccAddresses = new ArrayList<String>(parameterService
            .getParameterValuesAsString(LoadPaymentsStep.class, PdpParameterConstants.HARD_EDIT_CC));

    if (paymentFile == null) {
        if (ccAddresses.isEmpty()) {
            LOG.error("sendErrorEmail() No HARD_EDIT_CC addresses.  No email sent");
            return;
        }

        message.getToAddresses().addAll(ccAddresses);

        body.append(getMessage(PdpKeyConstants.MESSAGE_PAYMENT_EMAIL_BAD_FILE_PARSE) + "\n\n");
    } else {
        CustomerProfile customer = customerProfileService.get(paymentFile.getChart(), paymentFile.getUnit(),
                paymentFile.getSubUnit());
        if (customer == null) {
            LOG.error("sendErrorEmail() Invalid Customer.  Sending email to CC addresses");

            if (ccAddresses.isEmpty()) {
                LOG.error("sendErrorEmail() No HARD_EDIT_CC addresses.  No email sent");
                return;
            }

            message.getToAddresses().addAll(ccAddresses);

            body.append(getMessage(PdpKeyConstants.MESSAGE_PAYMENT_EMAIL_INVALID_CUSTOMER) + "\n\n");
        } else {
            String toAddresses = StringUtils.deleteWhitespace(customer.getProcessingEmailAddr());
            List<String> toAddressList = Arrays.asList(toAddresses.split(","));

            message.getToAddresses().addAll(toAddressList);
            message.getCcAddresses().addAll(ccAddresses);
            //TODO: for some reason the mail service does not work unless the bcc list has addresss. This is a temporary workaround
            message.getBccAddresses().addAll(ccAddresses);
        }
    }

    if (paymentFile != null) {
        body.append(getMessage(PdpKeyConstants.MESSAGE_PAYMENT_EMAIL_FILE_NOT_LOADED) + "\n\n");
        addPaymentFieldsToBody(body, null, paymentFile.getChart(), paymentFile.getUnit(),
                paymentFile.getSubUnit(), paymentFile.getCreationDate(), paymentFile.getPaymentCount(),
                paymentFile.getPaymentTotalAmount());
    }

    body.append("\n" + getMessage(PdpKeyConstants.MESSAGE_PAYMENT_EMAIL_ERROR_MESSAGES) + "\n");
    List<ErrorMessage> errorMessages = errors.getMessages(OLEConstants.GLOBAL_ERRORS);
    for (ErrorMessage errorMessage : errorMessages) {
        body.append(getMessage(errorMessage.getErrorKey(), (Object[]) errorMessage.getMessageParameters())
                + "\n\n");
    }

    message.setMessage(body.toString());

    // KFSMI-6475 - if not a production instance, replace the recipients with the testers list
    alterMessageWhenNonProductionInstance(message, null);

    try {
        mailService.sendMessage(message);
    } catch (Exception e) {
        LOG.error("sendErrorEmail() Invalid email address.  Message not sent", e);
    }
}

From source file:org.kuali.ole.pdp.service.impl.PdpEmailServiceImpl.java

/**
 * @see org.kuali.ole.pdp.service.PdpEmailService#sendLoadEmail(org.kuali.ole.pdp.businessobject.PaymentFileLoad,
 *      java.util.List)//from   w w w .jav a2s .  c  om
 */
@Override
public void sendLoadEmail(PaymentFileLoad paymentFile, List<String> warnings) {
    LOG.debug("sendLoadEmail() starting");

    // check email configuration
    if (!isPaymentEmailEnabled()) {
        return;
    }

    MailMessage message = new MailMessage();

    String returnAddress = parameterService.getParameterValueAsString(
            OleParameterConstants.PRE_DISBURSEMENT_BATCH.class, OLEConstants.FROM_EMAIL_ADDRESS_PARM_NM);
    if (StringUtils.isEmpty(returnAddress)) {
        returnAddress = mailService.getBatchMailingList();
    }
    message.setFromAddress(returnAddress);
    message.setSubject(
            getEmailSubject(PdpParameterConstants.PAYMENT_LOAD_SUCCESS_EMAIL_SUBJECT_PARAMETER_NAME));

    List<String> ccAddresses = new ArrayList<String>(parameterService
            .getParameterValuesAsString(LoadPaymentsStep.class, PdpParameterConstants.HARD_EDIT_CC));
    message.getCcAddresses().addAll(ccAddresses);
    message.getBccAddresses().addAll(ccAddresses);

    CustomerProfile customer = customerProfileService.get(paymentFile.getChart(), paymentFile.getUnit(),
            paymentFile.getSubUnit());
    String toAddresses = StringUtils.deleteWhitespace(customer.getProcessingEmailAddr());
    List<String> toAddressList = Arrays.asList(toAddresses.split(","));

    message.getToAddresses().addAll(toAddressList);

    StringBuilder body = new StringBuilder();
    body.append(getMessage(PdpKeyConstants.MESSAGE_PAYMENT_EMAIL_FILE_LOADED) + "\n\n");
    addPaymentFieldsToBody(body, paymentFile.getBatchId().intValue(), paymentFile.getChart(),
            paymentFile.getUnit(), paymentFile.getSubUnit(), paymentFile.getCreationDate(),
            paymentFile.getPaymentCount(), paymentFile.getPaymentTotalAmount());

    body.append("\n" + getMessage(PdpKeyConstants.MESSAGE_PAYMENT_EMAIL_WARNING_MESSAGES) + "\n");
    for (String warning : warnings) {
        body.append(warning + "\n\n");
    }

    message.setMessage(body.toString());

    // KFSMI-6475 - if not a production instance, replace the recipients with the testers list
    alterMessageWhenNonProductionInstance(message, null);

    try {
        mailService.sendMessage(message);
    } catch (Exception e) {
        LOG.error("sendErrorEmail() Invalid email address. Message not sent", e);
    }

    if (paymentFile.isFileThreshold()) {
        sendThresholdEmail(true, paymentFile, customer);
    }

    if (paymentFile.isDetailThreshold()) {
        sendThresholdEmail(false, paymentFile, customer);
    }
}

From source file:org.kuali.ole.pdp.service.impl.PdpEmailServiceImpl.java

/**
 * Sends email for a payment that was over the customer file threshold or the detail threshold
 * //from   w w w  .  j  a v  a2 s  .  c  o  m
 * @param fileThreshold indicates whether the file threshold (true) was violated or the detail threshold (false)
 * @param paymentFile parsed payment file object
 * @param customer payment customer
 */
protected void sendThresholdEmail(boolean fileThreshold, PaymentFileLoad paymentFile,
        CustomerProfile customer) {
    MailMessage message = new MailMessage();

    String returnAddress = parameterService.getParameterValueAsString(
            OleParameterConstants.PRE_DISBURSEMENT_BATCH.class, OLEConstants.FROM_EMAIL_ADDRESS_PARM_NM);
    if (StringUtils.isEmpty(returnAddress)) {
        returnAddress = mailService.getBatchMailingList();
    }
    message.setFromAddress(returnAddress);
    message.setSubject(
            getEmailSubject(PdpParameterConstants.PAYMENT_LOAD_THRESHOLD_EMAIL_SUBJECT_PARAMETER_NAME));

    StringBuilder body = new StringBuilder();

    body.append(getMessage(PdpKeyConstants.MESSAGE_PAYMENT_EMAIL_FILE_LOADED) + "\n\n");
    addPaymentFieldsToBody(body, paymentFile.getBatchId().intValue(), paymentFile.getChart(),
            paymentFile.getUnit(), paymentFile.getSubUnit(), paymentFile.getCreationDate(),
            paymentFile.getPaymentCount(), paymentFile.getPaymentTotalAmount());

    if (fileThreshold) {
        String toAddresses = StringUtils.deleteWhitespace(customer.getFileThresholdEmailAddress());
        List<String> toAddressList = Arrays.asList(toAddresses.split(","));

        message.getToAddresses().addAll(toAddressList);
        body.append("\n" + getMessage(PdpKeyConstants.MESSAGE_PAYMENT_EMAIL_FILE_THRESHOLD,
                paymentFile.getPaymentTotalAmount(), customer.getFileThresholdAmount()));
    } else {
        String toAddresses = StringUtils.deleteWhitespace(customer.getPaymentThresholdEmailAddress());
        List<String> toAddressList = Arrays.asList(toAddresses.split(","));

        message.getToAddresses().addAll(toAddressList);

        body.append("\n" + getMessage(PdpKeyConstants.MESSAGE_PAYMENT_EMAIL_DETAIL_THRESHOLD,
                customer.getPaymentThresholdAmount()) + "\n\n");
        for (PaymentDetail paymentDetail : paymentFile.getThresholdPaymentDetails()) {
            paymentDetail.refresh();
            body.append(getMessage(PdpKeyConstants.MESSAGE_PAYMENT_EMAIL_FILE_THRESHOLD,
                    paymentDetail.getPaymentGroup().getPayeeName(), paymentDetail.getNetPaymentAmount())
                    + "\n");
        }
    }

    List<String> ccAddresses = new ArrayList<String>(parameterService
            .getParameterValuesAsString(LoadPaymentsStep.class, PdpParameterConstants.HARD_EDIT_CC));
    message.getCcAddresses().addAll(ccAddresses);
    message.getBccAddresses().addAll(ccAddresses);

    message.setMessage(body.toString());

    // KFSMI-6475 - if not a production instance, replace the recipients with the testers list
    alterMessageWhenNonProductionInstance(message, null);

    try {
        mailService.sendMessage(message);
    } catch (Exception e) {
        LOG.error("sendErrorEmail() Invalid email address. Message not sent", e);
    }
}

From source file:org.kuali.ole.pdp.service.impl.PdpEmailServiceImpl.java

/**
 * @see org.kuali.ole.pdp.service.PdpEmailService#sendLoadEmail(org.kuali.ole.pdp.businessobject.Batch)
 *///from   w  w w  . j  a  va  2  s.  co m
@Override
public void sendLoadEmail(Batch batch) {
    LOG.debug("sendLoadEmail() starting");

    // check email configuration
    if (!isPaymentEmailEnabled()) {
        return;
    }

    MailMessage message = new MailMessage();

    String returnAddress = parameterService.getParameterValueAsString(
            OleParameterConstants.PRE_DISBURSEMENT_BATCH.class, OLEConstants.FROM_EMAIL_ADDRESS_PARM_NM);
    if (StringUtils.isEmpty(returnAddress)) {
        returnAddress = mailService.getBatchMailingList();
    }
    message.setFromAddress(returnAddress);
    message.setSubject(
            getEmailSubject(PdpParameterConstants.PAYMENT_LOAD_SUCCESS_EMAIL_SUBJECT_PARAMETER_NAME));

    StringBuilder body = new StringBuilder();

    List<String> ccAddresses = new ArrayList<String>(parameterService
            .getParameterValuesAsString(LoadPaymentsStep.class, PdpParameterConstants.HARD_EDIT_CC));
    message.getCcAddresses().addAll(ccAddresses);
    message.getBccAddresses().addAll(ccAddresses);

    CustomerProfile customer = batch.getCustomerProfile();
    String toAddresses = StringUtils.deleteWhitespace(customer.getProcessingEmailAddr());
    List<String> toAddressList = Arrays.asList(toAddresses.split(","));

    message.getToAddresses().addAll(toAddressList);

    body.append(getMessage(PdpKeyConstants.MESSAGE_PAYMENT_EMAIL_FILE_LOADED) + "\n\n");
    addPaymentFieldsToBody(body, batch.getId().intValue(), customer.getChartCode(), customer.getUnitCode(),
            customer.getSubUnitCode(), batch.getCustomerFileCreateTimestamp(),
            batch.getPaymentCount().intValue(), batch.getPaymentTotalAmount());

    message.setMessage(body.toString());

    // KFSMI-6475 - if not a production instance, replace the recipients with the testers list
    alterMessageWhenNonProductionInstance(message, null);

    try {
        mailService.sendMessage(message);
    } catch (Exception e) {
        LOG.error("sendErrorEmail() Invalid email address. Message not sent", e);
    }
}