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.propdev.impl.action.ProposalDevelopmentActionsAction.java

private int getBudgetNextChangeNumber(BusinessObjectService boService, String proposalNumber,
        String columnName) {/*from   ww  w  . j  a va  2  s . c o m*/
    int changeNumber = 0;
    Map<String, Object> keyMap = new HashMap<String, Object>();
    keyMap.put("proposalNumber", proposalNumber);
    keyMap.put("columnName", columnName);
    List<BudgetChangedData> changedDataList = (List<BudgetChangedData>) boService
            .findMatchingOrderBy(BudgetChangedData.class, keyMap, "changeNumber", true);
    if (CollectionUtils.isNotEmpty(changedDataList)) {
        changeNumber = ((BudgetChangedData) changedDataList.get(changedDataList.size() - 1)).getChangeNumber();
    }

    return ++changeNumber;
}

From source file:org.kuali.coeus.propdev.impl.basic.ProposalDevelopmentHomeController.java

@MethodAccessible
@Transactional//from   ww  w.jav a  2  s  .c o m
@RequestMapping(value = "/proposalDevelopment", params = "methodToCall=docHandler")
public ModelAndView docHandler(@ModelAttribute("KualiForm") DocumentFormBase form,
        @RequestParam(required = false) String auditActivated, @RequestParam(required = false) String viewOnly,
        @RequestParam(required = false) String navigateToPageId,
        @RequestParam(required = false) String defaultOpenTab) throws Exception {
    ProposalDevelopmentDocument document;
    boolean isDeleted = false;
    if (!ObjectUtils.isNull(form.getDocId())) {
        document = (ProposalDevelopmentDocument) getDocumentService().getByDocumentHeaderId(form.getDocId());
        isDeleted = document.isProposalDeleted();
    }
    if (auditActivated != null) {
        ((ProposalDevelopmentDocumentForm) form).setAuditActivated(Boolean.parseBoolean(auditActivated));
    }
    if (isDeleted) {
        Properties props = new Properties();
        props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.START_METHOD);
        props.put(UifConstants.UrlParams.VIEW_ID, "PropDev-DeletedView");
        return getModelAndViewService().performRedirect(form, "proposalDevelopment", props);
    } else {
        boolean summaryView = false;

        // Change command when sent from an action list show
        if (form.getCommand().equals("displayActionListInlineView")) {
            summaryView = true;
            // Command used to get document info
            form.setCommand("displayActionListView");
        }
        ProposalDevelopmentDocumentForm propDevForm = (ProposalDevelopmentDocumentForm) form;

        try {
            ModelAndView modelAndView = getTransactionalDocumentControllerService().docHandler(form);
            propDevForm.initialize();
            propDevForm.getCustomDataHelper().prepareCustomData();

            setS2sOpportunityFromLookup(form, propDevForm);

            propDevForm.setWorkingUserRoles(getProposalDevelopmentPermissionsService()
                    .getPermissions(propDevForm.getProposalDevelopmentDocument()));

            if (summaryView) {
                form.setView(this.getDataDictionaryService().getViewById("PropDev-SummaryView"));
                form.setViewId("PropDev-SummaryView");
                return modelAndView;
            }

            if (CollectionUtils.isNotEmpty(propDevForm.getDevelopmentProposal().getProposalChangedDataList())) {
                getGlobalVariableService().getMessageMap().putInfoForSectionId("PropDev-DetailsPage",
                        "info.dataoverride.occured");
            }

            if (propDevForm.getDocument().getDocumentHeader().getWorkflowDocument().isEnroute()) {
                ((ProposalDevelopmentViewHelperServiceImpl) form.getViewHelperService())
                        .prepareSummaryPage(propDevForm);
                propDevForm.getView().setEntryPageId(ProposalDevelopmentConstants.KradConstants.SUBMIT_PAGE);
            }

            if (StringUtils.isNotBlank(navigateToPageId)) {
                propDevForm.getView().setEntryPageId(navigateToPageId);
            }

            if (StringUtils.isNotBlank(defaultOpenTab)) {
                propDevForm.setDefaultOpenTab(defaultOpenTab);
            }

            if (!propDevForm.getDocument().getDocumentHeader().getWorkflowDocument().isEnroute()
                    && (StringUtils.equals(form.getRequest().getParameter("viewDocument"), "true")
                            || StringUtils.equals(viewOnly, "true"))) {
                propDevForm.setViewOnly(true);
            }

            return modelAndView;
        } catch (AuthorizationException e) {
            return getModelAndViewService().getMessageView(form, "Authorization Exception Report",
                    "Error Message: [color=red]" + e.getMessage() + "[/color]");
        }
    }
}

From source file:org.kuali.coeus.propdev.impl.core.DevelopmentProposal.java

public void updateProposalChangeHistory() {
    proposalChangeHistory = new TreeMap<String, List<ProposalChangedData>>();
    // Arranging Proposal Change History   
    if (CollectionUtils.isNotEmpty(this.getProposalChangedDataList())) {
        for (ProposalChangedData proposalChangedData : this.getProposalChangedDataList()) {
            if (this.getProposalChangeHistory()
                    .get(proposalChangedData.getEditableColumn().getColumnLabel()) == null) {
                this.getProposalChangeHistory().put(proposalChangedData.getEditableColumn().getColumnLabel(),
                        new ArrayList<ProposalChangedData>());
            }//w  w w  . j ava 2s  .c  o m
            this.getProposalChangeHistory().get(proposalChangedData.getEditableColumn().getColumnLabel())
                    .add(proposalChangedData);
        }
    }
}

From source file:org.kuali.coeus.propdev.impl.core.DevelopmentProposal.java

public void updateBudgetChangeHistory() {
    budgetChangeHistory = new TreeMap<String, List<BudgetChangedData>>();
    // Arranging Budget Change History   
    if (CollectionUtils.isNotEmpty(this.getBudgetChangedDataList())) {
        for (BudgetChangedData budgetChangedData : this.getBudgetChangedDataList()) {
            if (this.getBudgetChangeHistory()
                    .get(budgetChangedData.getEditableColumn().getColumnLabel()) == null) {
                this.getBudgetChangeHistory().put(budgetChangedData.getEditableColumn().getColumnLabel(),
                        new ArrayList<BudgetChangedData>());
            }//from w  w  w  . j a  v  a  2 s  .  c  o m
            this.getBudgetChangeHistory().get(budgetChangedData.getEditableColumn().getColumnLabel())
                    .add(budgetChangedData);
        }
    }
}

From source file:org.kuali.coeus.propdev.impl.core.PropDevLookupableHelperServiceImpl.java

@Override
protected Collection<?> executeSearch(Map<String, String> adjustedSearchCriteria,
        List<String> wildcardAsLiteralSearchCriteria, boolean bounded, Integer searchResultsLimit) {

    Map<String, String> modifiedSearchCriteria = new HashMap<String, String>();
    modifiedSearchCriteria.putAll(adjustedSearchCriteria);

    String proposalNumberCriteria = adjustedSearchCriteria.get(PROPOSAL_NUMBER);
    boolean proposalNumberWildcarded = false;

    if (!StringUtils.isEmpty(proposalNumberCriteria) && proposalNumberCriteria.contains("*")) {
        proposalNumberWildcarded = true;
    }/*from   w  w w . j  av a  2  s .c  om*/

    List<String> documentNumbers = new ArrayList<>();
    // If a specific proposal is not targeted by the proposal primary key, collect the document numbers of any
    // proposal documents which are associated with the various search person search fields and intersect them
    if (StringUtils.isEmpty(proposalNumberCriteria) || proposalNumberWildcarded) {
        String principalInvestigatorName = adjustedSearchCriteria.get(PRINCIPAL_INVESTIGATOR_NAME);
        String proposalPerson = adjustedSearchCriteria.get(PROPOSAL_PERSON);
        String initiator = adjustedSearchCriteria.get(INITIATOR);
        String participant = adjustedSearchCriteria.get(PARTICIPANT);
        String aggregator = adjustedSearchCriteria.get(AGGREGATOR);

        Collection<String> piProposals = getPiDocumentNumbers(principalInvestigatorName);
        Collection<String> personProposals = getProposalPersonDocumentNumbers(proposalPerson);
        Collection<String> initiatorProposals = getInitiatorDocumentNumbers(initiator);
        Collection<String> aggregatorProposals = getAggregatorDocumentNumbers(aggregator);
        Collection<String> participantProposals = getParticipantDocumentNumbers(participant);

        documentNumbers = intersectCollections(piProposals, personProposals, initiatorProposals,
                aggregatorProposals, participantProposals);

        if (documentNumbers.size() > IN_OP_LIMIT) {
            documentNumbers = documentNumbers.subList(0, IN_OP_LIMIT - 1);
        }
    }

    modifiedSearchCriteria.remove(PROPOSAL_PERSON);
    modifiedSearchCriteria.remove(INITIATOR);
    modifiedSearchCriteria.remove(PRINCIPAL_INVESTIGATOR_NAME);
    modifiedSearchCriteria.remove(PARTICIPANT);
    modifiedSearchCriteria.remove(AGGREGATOR);

    QueryByCriteria.Builder query = lookupCriteriaGenerator.generateCriteria(DevelopmentProposal.class,
            modifiedSearchCriteria, wildcardAsLiteralSearchCriteria,
            getLookupService().allPrimaryKeyValuesPresentAndNotWildcard(DevelopmentProposal.class,
                    modifiedSearchCriteria));
    if (searchResultsLimit != null) {
        query.setMaxResults(searchResultsLimit);
    }

    if ((StringUtils.isBlank(proposalNumberCriteria) || proposalNumberWildcarded)
            && documentNumbers.size() > 0) {
        if (modifiedSearchCriteria.size() > 0) {
            List<Predicate> predicateList = new ArrayList(Arrays.asList(query.getPredicates()));
            predicateList.add(PredicateFactory.in(PROPOSAL_DOCUMENT_DOCUMENT_NUMBER, documentNumbers));
            query.setPredicates(
                    PredicateFactory.and(predicateList.toArray(new Predicate[predicateList.size()])));
        } else {
            query.setPredicates(PredicateFactory.in(PROPOSAL_DOCUMENT_DOCUMENT_NUMBER, documentNumbers));
        }
    }

    final List<DevelopmentProposal> proposals = getDataObjectService()
            .findMatching(DevelopmentProposal.class, query.build()).getResults();

    boolean doNotFilter = false;
    if (CollectionUtils.isNotEmpty(proposals) && proposals.size() > SMALL_NUMBER_OF_RESULTS) {
        //if the proposal result list is more than a few proposals then attempt to figure out if a principal
        //has access to all proposals
        doNotFilter = canAccessAllProposals();
    }

    return doNotFilter ? proposals : filterPermissions(proposals);

}

From source file:org.kuali.coeus.propdev.impl.core.PropDevLookupableHelperServiceImpl.java

private boolean containsWildcardAttribute(Collection<Permission> perms, String attrName) {
    if (CollectionUtils.isNotEmpty(perms)) {
        for (Permission perm : perms) {
            if (MapUtils.isNotEmpty(perm.getAttributes())) {
                final String attrVal = perm.getAttributes().get(attrName);
                if ("*".equals(attrVal)) {
                    return true;
                }/*from ww w  .  j  av a 2 s . co m*/
            }
        }
    }
    return false;
}

From source file:org.kuali.coeus.propdev.impl.core.PropDevLookupableHelperServiceImpl.java

/**
 * Intersects all non-empty, non-null collections provided to this method.
 *///from   w w  w.  j  a v  a2  s .  c  o  m
private List<String> intersectCollections(Collection<String>... collections) {
    Collection<String> finalCollection = new ArrayList<>();
    for (Collection collection : collections) {
        if (CollectionUtils.isNotEmpty(collection) && CollectionUtils.isNotEmpty(finalCollection)) {
            finalCollection = CollectionUtils.intersection(collection, finalCollection);
        } else if (CollectionUtils.isNotEmpty(collection)) {
            // First non-empty/non-null collection starts the intersected collection
            finalCollection = collection;
        }
    }

    return new ArrayList<>(finalCollection);
}

From source file:org.kuali.coeus.propdev.impl.core.ProposalDevelopmentDocumentForm.java

public S2sAppSubmission getDisplayedS2sAppSubmission() {
    if (CollectionUtils.isNotEmpty(this.getDevelopmentProposal().getS2sAppSubmission())) {
        return this.getDevelopmentProposal().getS2sAppSubmission()
                .get(this.getDevelopmentProposal().getS2sAppSubmission().size() - 1);
    }//ww  w  . java 2s .  c  o  m
    return null;
}

From source file:org.kuali.coeus.propdev.impl.core.ProposalDevelopmentServiceImpl.java

protected void addDescendantUnits(Unit parentUnit, Set<Unit> units) {
    List<Unit> subunits = getUnitService().getActiveSubUnits(parentUnit.getUnitNumber());
    if (CollectionUtils.isNotEmpty(subunits)) {
        units.addAll(subunits);//ww w  .  j av  a2  s .c o  m
        for (Unit subunit : subunits) {
            addDescendantUnits(subunit, units);
        }
    }
}

From source file:org.kuali.coeus.propdev.impl.docperm.ProposalRoleTemplateServiceImpl.java

/**
 * Get the role templates for the proposal.  The retrieved role templates correspond
 * to the proposal's lead unit./*  w  w w  . j a  v a 2  s . c o m*/
 * @param unitNumber the lead unit of the proposal
 * @return the collection of role templates
 */
protected Collection<RoleMembership> getRoleTemplates(String unitNumber) {
    Map<String, String> qualifiedRoleAttributes = new HashMap<String, String>();
    qualifiedRoleAttributes.put("unitNumber", unitNumber);
    List<Role> proposalRoles = proposalRoleService.getRolesForDisplay();
    Collection<RoleMembership> membershipInfoList = new ArrayList<RoleMembership>();
    Collection<String> memberIds = null;
    RoleMembership.Builder roleMembershipBuilder = null;
    for (Role role : proposalRoles) {
        memberIds = roleManagementService.getRoleMemberPrincipalIds(role.getNamespaceCode(), role.getName(),
                qualifiedRoleAttributes);
        if (CollectionUtils.isNotEmpty(memberIds)) {
            for (String memberId : memberIds) {
                roleMembershipBuilder = RoleMembership.Builder.create(role.getId(), null, memberId,
                        MemberType.PRINCIPAL, null);
                membershipInfoList.add(roleMembershipBuilder.build());
            }
            roleMembershipBuilder = null;
            memberIds = null;
        }
    }
    return membershipInfoList;
}