Example usage for org.apache.commons.collections4 CollectionUtils isNotEmpty

List of usage examples for org.apache.commons.collections4 CollectionUtils isNotEmpty

Introduction

In this page you can find the example usage for org.apache.commons.collections4 CollectionUtils isNotEmpty.

Prototype

public static boolean isNotEmpty(final Collection<?> coll) 

Source Link

Document

Null-safe check if the specified collection is not empty.

Usage

From source file:org.kuali.coeus.common.committee.impl.web.struts.form.schedule.WeeklyScheduleDetails.java

private List<String> convertToWeekDays(List<String> daysOfWeek) {
    if (daysOfWeek.size() == 1 && daysOfWeek.get(0).equalsIgnoreCase("Hidden"))
        return null;
    List<String> tmp = new ArrayList<String>(daysOfWeek.size() - 1);
    int i = 0;//  w w  w.  j a va 2  s.c  o m
    if (CollectionUtils.isNotEmpty(daysOfWeek)) {
        for (String dayOfWeek : daysOfWeek) {
            if (dayOfWeek.equalsIgnoreCase("Hidden"))
                continue;
            tmp.add(dayOfWeek);
        }
    }
    return tmp;
}

From source file:org.kuali.coeus.common.impl.auth.UnitAuthorizationServiceImpl.java

public boolean hasMatchingQualifiedUnits(String userId, String namespaceCode, String permissionName,
        String unitNumber) {//from   w ww.  ja va2s .c om
    List<String> roleIds = new ArrayList<String>();
    Map<String, String> qualifiedRoleAttributes = new HashMap<String, String>();
    qualifiedRoleAttributes.put(UNIT_NUMBER, unitNumber);
    roleIds = systemAuthorizationService.getRoleIdsForPermission(permissionName, namespaceCode);

    List<Map<String, String>> qualifiers = roleManagementService
            .getNestedRoleQualifiersForPrincipalByRoleIds(userId, roleIds, qualifiedRoleAttributes);
    List<String> units = new ArrayList<String>();
    for (Map<String, String> qualifier : qualifiers) {
        String tmpUnitNumber = qualifier.get(UNIT_NUMBER);
        if (StringUtils.isNotEmpty(tmpUnitNumber)) {
            units.add(tmpUnitNumber);
        }
    }

    return CollectionUtils.isNotEmpty(units);
}

From source file:org.kuali.coeus.common.impl.editable.PersonEditableServiceImpl.java

public void populateContactFieldsFromRolodexId(PersonEditable protocolPerson) {
    Map valueMap = new HashMap();
    valueMap.put("rolodexId", protocolPerson.getRolodexId());
    Collection<Rolodex> rolodexes = businessObjectService.findMatching(Rolodex.class, valueMap);

    if (CollectionUtils.isNotEmpty(rolodexes)) {
        for (Rolodex rolodex : rolodexes) {
            protocolPerson.setRolodexId(rolodex.getRolodexId());
            protocolPerson.setAddressLine1(rolodex.getAddressLine1());
            protocolPerson.setAddressLine2(rolodex.getAddressLine2());
            protocolPerson.setAddressLine3(rolodex.getAddressLine3());
            protocolPerson.setCity(rolodex.getCity());
            protocolPerson.setCountryCode(rolodex.getCountryCode());
            protocolPerson.setCounty(rolodex.getCounty());
            protocolPerson.setEmailAddress(rolodex.getEmailAddress());
            protocolPerson.setFaxNumber(rolodex.getFaxNumber());
            protocolPerson.setFirstName(rolodex.getFirstName());
            protocolPerson.setLastName(rolodex.getLastName());
            protocolPerson.setMiddleName(rolodex.getMiddleName());
            protocolPerson.setOfficePhone(rolodex.getPhoneNumber());
            protocolPerson.setPostalCode(rolodex.getPostalCode());
            protocolPerson.setState(rolodex.getState());
            protocolPerson.setPrimaryTitle(rolodex.getTitle());
            protocolPerson.setFullName("");
            if (isNotBlank(rolodex.getFirstName())) {
                protocolPerson.setFullName(rolodex.getFirstName());
            }/*w  w w. ja  v  a 2s . co m*/
            if (isNotBlank(rolodex.getMiddleName())) {
                protocolPerson.setFullName(protocolPerson.getFullName() + " " + rolodex.getMiddleName());
            }
            if (isNotBlank(rolodex.getLastName())) {
                protocolPerson.setFullName(protocolPerson.getFullName() + " " + rolodex.getLastName());
            }
        }
    }
}

From source file:org.kuali.coeus.common.impl.mail.KcEmailServiceImpl.java

public void sendEmailWithAttachments(String from, Set<String> toAddresses, String subject,
        Set<String> ccAddresses, Set<String> bccAddresses, String body, boolean htmlMessage,
        List<EmailAttachment> attachments) {

    if (mailSender != null) {
        if (CollectionUtils.isEmpty(toAddresses) && CollectionUtils.isEmpty(ccAddresses)
                && CollectionUtils.isEmpty(bccAddresses)) {
            return;
        }/*ww  w  .  j a  v  a 2s. c  o  m*/

        MimeMessage message = mailSender.createMimeMessage();
        MimeMessageHelper helper = null;

        try {
            helper = new MimeMessageHelper(message, true, DEFAULT_ENCODING);
            helper.setFrom(from);

            if (StringUtils.isNotBlank(subject)) {
                helper.setSubject(subject);
            } else {
                LOG.warn("Sending message with empty subject.");
            }

            if (isEmailTestEnabled()) {
                helper.setText(getTestMessageBody(body, toAddresses, ccAddresses, bccAddresses), true);
                String toAddress = getEmailNotificationTestAddress();
                if (StringUtils.isNotBlank(getEmailNotificationTestAddress())) {
                    helper.addTo(toAddress);
                }
            } else {
                helper.setText(body, htmlMessage);
                if (CollectionUtils.isNotEmpty(toAddresses)) {
                    for (String toAddress : toAddresses) {
                        try {
                            helper.addTo(toAddress);
                        } catch (Exception ex) {
                            LOG.warn("Could not set to address:", ex);
                        }
                    }
                }
                if (CollectionUtils.isNotEmpty(ccAddresses)) {
                    for (String ccAddress : ccAddresses) {
                        try {
                            helper.addCc(ccAddress);
                        } catch (Exception ex) {
                            LOG.warn("Could not set to address:", ex);
                        }
                    }
                }
                if (CollectionUtils.isNotEmpty(bccAddresses)) {
                    for (String bccAddress : bccAddresses) {
                        try {
                            helper.addBcc(bccAddress);
                        } catch (Exception ex) {
                            LOG.warn("Could not set to address:", ex);
                        }
                    }
                }
            }

            if (CollectionUtils.isNotEmpty(attachments)) {
                for (EmailAttachment attachment : attachments) {
                    try {
                        helper.addAttachment(attachment.getFileName(),
                                new ByteArrayResource(attachment.getContents()), attachment.getMimeType());
                    } catch (Exception ex) {
                        LOG.warn("Could not set to address:", ex);
                    }
                }
            }
            executorService.execute(() -> mailSender.send(message));

        } catch (MessagingException ex) {
            LOG.error("Failed to create mime message helper.", ex);
        }
    } else {
        LOG.info(
                "Failed to send email due to inability to obtain valid email mailSender, please check your configuration.");
    }
}

From source file:org.kuali.coeus.common.impl.mail.KcEmailServiceImpl.java

private String getTestMessageBody(String body, Set<String> toAddresses, Set<String> ccAddresses,
        Set<String> bccAddresses) {
    StringBuffer testEmailBody = new StringBuffer("");
    testEmailBody.append("-----------------------------------------------------------<br/>");
    testEmailBody.append("TEST MODE<br/>");
    testEmailBody.append("In Production mode this mail will be sent to the following... <br/>");
    if (CollectionUtils.isNotEmpty(toAddresses)) {
        testEmailBody.append("TO: ");
        testEmailBody.append(toAddresses);
    }/* ww w  .j  av  a2s.  c om*/
    if (CollectionUtils.isNotEmpty(ccAddresses)) {
        testEmailBody.append("CC: ");
        testEmailBody.append(toAddresses);
    }
    if (CollectionUtils.isNotEmpty(bccAddresses)) {
        testEmailBody.append("BCC: ");
        testEmailBody.append(toAddresses);
    }
    testEmailBody.append("<br/>-----------------------------------------------------------");
    return testEmailBody.toString() + "<br/>" + body;

}

From source file:org.kuali.coeus.common.impl.unit.UnitServiceImpl.java

protected List<Unit> findUnitsWithDirectParent(List<Unit> units, final String directParent) {
    if (CollectionUtils.isNotEmpty(units)) {
        final List<Unit> matched = ListUtils.select(units, new Predicate<Unit>() {
            @Override/*from ww w .  ja  v  a2s  .  co m*/
            public boolean evaluate(Unit input) {
                return input.getParentUnitNumber() != null && input.getParentUnitNumber().equals(directParent);
            }
        });

        final List<Unit> totalMatched = new ArrayList<>(matched);
        for (Unit child : matched) {
            totalMatched.addAll(findUnitsWithDirectParent(units, child.getUnitNumber()));
        }
        return totalMatched;
    }
    return Collections.emptyList();
}

From source file:org.kuali.coeus.common.impl.unit.UnitServiceImpl.java

protected List<Unit> getParentUnitsInclusive(List<Unit> units, final String unit) {
    if (CollectionUtils.isNotEmpty(units)) {
        final Unit matched = CollectionUtils.find(units, new Predicate<Unit>() {
            @Override/*from   w  w w . j  av a2 s. c o m*/
            public boolean evaluate(Unit input) {
                return input.getUnitNumber() != null && input.getUnitNumber().equals(unit);
            }
        });

        if (matched != null) {
            final List<Unit> totalMatched = new ArrayList<>();
            totalMatched.add(matched);
            totalMatched.addAll(getParentUnitsInclusive(units, matched.getParentUnitNumber()));
            return totalMatched;
        } else if (unit != null) {
            LOGGER.error("Invalid parent found " + unit);
        }
    }
    return Collections.emptyList();
}

From source file:org.kuali.coeus.common.impl.version.history.VersionHistoryServiceImpl.java

@SuppressWarnings("unchecked")
public VersionHistory findPendingVersion(Class<? extends SequenceOwner> klass, String versionName,
        String sequenceNumber) {/*from  w w w.  j av  a 2  s  . co m*/
    VersionHistory pendingVersionHistory = null;

    Map<String, Object> fieldValues = new HashMap<String, Object>();
    fieldValues.put(SEQUENCE_OWNER_CLASS_NAME_FIELD, klass.getName());
    fieldValues.put(SEQUENCE_OWNER_REFERENCE_VERSION_NAME, versionName);
    fieldValues.put(SEQUENCE_OWNER_REFERENCE_SEQ_NUMBER, sequenceNumber);
    fieldValues.put(VERSION_STATUS_FIELD, VersionStatus.PENDING.name());

    List<VersionHistory> histories = new ArrayList<VersionHistory>(
            bos.findMatching(VersionHistory.class, fieldValues));
    if (CollectionUtils.isNotEmpty(histories)) {
        pendingVersionHistory = histories.get(0);
    }

    return pendingVersionHistory;
}

From source file:org.kuali.coeus.common.impl.version.history.VersionHistoryServiceImpl.java

@SuppressWarnings("unchecked")
public VersionHistory findPendingVersion(Class<? extends SequenceOwner> klass, String versionName) {
    VersionHistory pendingVersionHistory = null;

    Map<String, Object> fieldValues = new HashMap<String, Object>();
    fieldValues.put(SEQUENCE_OWNER_CLASS_NAME_FIELD, klass.getName());
    fieldValues.put(SEQUENCE_OWNER_REFERENCE_VERSION_NAME, versionName);
    fieldValues.put(VERSION_STATUS_FIELD, VersionStatus.PENDING.name());

    List<VersionHistory> histories = new ArrayList<VersionHistory>(
            bos.findMatching(VersionHistory.class, fieldValues));
    if (CollectionUtils.isNotEmpty(histories)) {
        pendingVersionHistory = histories.get(0);
    }//from   ww w .  ja v  a 2s.  c o m

    return pendingVersionHistory;
}

From source file:org.kuali.coeus.common.notification.impl.lookup.keyvalue.NotificationTypeRecipientRoleNameValuesFinder.java

@Override
public List<KeyValue> getKeyValues() {

    String moduleCode = null;/*from   w w w .j  av  a  2s .c o  m*/

    Document doc = getDocument();

    if (doc != null && doc instanceof MaintenanceDocumentBase) {
        NotificationType notificationType = (NotificationType) doc.getNoteTarget();
        if (notificationType != null) {
            moduleCode = notificationType.getModuleCode();
        }
    }

    List<KeyLabelSortByValue> keyValues = new ArrayList<KeyLabelSortByValue>();
    keyValues.add(new KeyLabelSortByValue(PrefixValuesFinder.getPrefixKey(),
            PrefixValuesFinder.getDefaultPrefixValue()));
    if (moduleCode != null) {
        List<NotificationModuleRole> moduleRoles = getKcNotificationModuleRoleService()
                .getNotificationModuleRoles(moduleCode);
        if (CollectionUtils.isNotEmpty(moduleRoles)) {
            for (NotificationModuleRole moduleRole : moduleRoles) {
                keyValues.add(new KeyLabelSortByValue(moduleRole.getRoleName(), moduleRole.getRoleName()));
            }
        }
    }

    // sort values for usability
    Collections.sort(keyValues);
    List<KeyValue> returnKeyValues = new ArrayList<KeyValue>();
    returnKeyValues.addAll(keyValues);

    return returnKeyValues;
}