List of usage examples for org.apache.commons.collections CollectionUtils find
public static Object find(Collection collection, Predicate predicate)
From source file:org.kuali.mobility.academics.dao.AcademicsDaoImpl.java
/** * @return the subjects/*from w ww .ja va2 s . co m*/ */ public List<Subject> getSubjects(final Map<String, String> query) { List<Subject> tSubjects = new ArrayList<Subject>(); if (null != query && query.containsKey(AcademicsConstants.TERM_ID)) { List<Career> tCareer = getCareers(query); if (query.containsKey(AcademicsConstants.CAREER_ID) && !query.get(AcademicsConstants.CAREER_ID).equalsIgnoreCase("ALL")) { Career career = (Career) CollectionUtils.find(tCareer, new CareerPredicate(query.get(AcademicsConstants.CAREER_ID))); tSubjects = career.getSubjects(); } else { for (Career c : tCareer) { tSubjects.addAll(c.getSubjects()); } Comparator<Subject> comparator = new Comparator<Subject>() { public int compare(Subject c1, Subject c2) { return c1.getDescription().compareToIgnoreCase(c2.getDescription()); } }; Collections.sort(tSubjects, comparator); } } else { tSubjects = subjects; } return tSubjects; }
From source file:org.kuali.mobility.academics.dao.AcademicsDaoImplDemo.java
public List<Section> getSections(Map<String, String> query) { List<Section> lSection = new ArrayList<Section>(); StringBuilder keyBuilder = new StringBuilder(); keyBuilder.append(query.get(AcademicsConstants.TERM_ID)); keyBuilder.append("#"); keyBuilder.append(query.get(AcademicsConstants.SUBJECT_ID)); String key = keyBuilder.toString(); if (getDemoCache().containsKey(key)) { List<CatalogNumber> numbers = getDemoCache().get(key); CatalogNumber number = (CatalogNumber) CollectionUtils.find(numbers, new CatalogNumberPredicate(query.get(AcademicsConstants.CATALOG_NUMBER))); for (Section s : number.getSections()) { s.setSubjectId(query.get(AcademicsConstants.SUBJECT_ID)); s.setCatalogNumber(query.get(AcademicsConstants.CATALOG_NUMBER)); lSection.add(s);/* w ww . j av a 2 s. c om*/ } } return lSection; }
From source file:org.kuali.mobility.academics.dao.AcademicsDaoImplDemo.java
public Section getSectionDetail(String termId, String careerId, String subjectId, String catalogNumber, String sectionNumber) {//www.j a v a2s.c om Section lSection = null; StringBuilder keyBuilder = new StringBuilder(); keyBuilder.append(termId); keyBuilder.append("#"); keyBuilder.append(subjectId); String key = keyBuilder.toString(); if (getDemoCache().containsKey(key)) { List<CatalogNumber> numbers = getDemoCache().get(key); CatalogNumber number = (CatalogNumber) CollectionUtils.find(numbers, new CatalogNumberPredicate(catalogNumber)); for (Section s : number.getSections()) { if (sectionNumber.equalsIgnoreCase(s.getNumber())) { lSection = s; s.setSubjectId(subjectId); s.setCatalogNumber(catalogNumber); break; } } } return lSection; }
From source file:org.kuali.mobility.academics.service.AcademicsServiceImpl.java
@Override @GET/*from ww w . j ava2 s. c om*/ @Path("/getTerm") public Term getTerm(@QueryParam("termId") final String termId) { Term term = (Term) CollectionUtils.find(getDao().getTerms(null), new TermPredicate(termId)); return term; }
From source file:org.kuali.mobility.events.dao.EventsDaoUMImpl.java
public List<Event> loadEventsForCategory(final String campus, final String categoryId) { LOG.debug("Loading event feed for category " + categoryId); if (null == getEvents() || getEvents().isEmpty()) { LOG.debug("Events list was empty, creating a new one."); //setEvents( new ArrayList<Event>() ); }/*from ww w . j a va2s . c om*/ if (null == getCategories() || getCategories().isEmpty()) { LOG.debug("Category list was empty, initializing a new one."); initData(campus); } List<Event> newEvents = new ArrayList<Event>(); Category category = (Category) CollectionUtils.find(getCategories(), new CategoryPredicate(campus, categoryId)); ; if (category != null) { LOG.debug("Found category object for id " + categoryId); XStream xstream = new XStream(); xstream.processAnnotations(UMEventReader.class); xstream.processAnnotations(UMEvent.class); xstream.processAnnotations(UMSponsor.class); UMEventReader eventReader = null; try { URL url = new URL(category.getUrlString() + "&_type=xml"); LOG.debug("Mapping events from url: " + category.getUrlString()); if (url != null) { eventReader = (UMEventReader) xstream.fromXML(url); } } catch (MalformedURLException mue) { LOG.error(mue.getLocalizedMessage()); } LOG.debug("check eventReader " + (eventReader == null ? "null" : "mnot null")); LOG.debug("check eventReader.getEvents " + (eventReader.getEvents() == null ? "null" : "mnot null")); if (eventReader != null && eventReader.getEvents() != null) { for (UMEvent e : eventReader.getEvents()) { LOG.debug("processing e " + e.getTitle()); Event newEvent = (Event) getApplicationContext().getBean("event"); newEvent.setEventId(e.getId()); newEvent.setCategory(category); newEvent.setTitle(e.getTitle()); newEvent.setDisplayStartTime(e.getTimeBegin()); //Saket's Addition newEvent.setType(e.getType()); newEvent.setDisplayStartDate(e.getDateBegin()); newEvent.setLocation(e.getBuildingName()); newEvent.setLink(e.getUrl()); try { if (e.getTsBegin() != null && e.getTsBegin().isEmpty() == false) { newEvent.setStartDate(sdf.parse(e.getTsBegin())); } if (e.getTsEnd() != null && e.getTsEnd().isEmpty() == false) { newEvent.setEndDate(sdf.parse(e.getTsEnd())); } } catch (ParseException e1) { LOG.error(e1.getLocalizedMessage()); } newEvent.setDisplayEndTime(e.getTimeEnd()); newEvent.setDisplayEndDate(e.getDateEnd()); List<String> myDescription = new ArrayList<String>(); myDescription.add(e.getDescription()); newEvent.setDescription(myDescription); List<EventContact> myContacts = new ArrayList<EventContact>(); for (UMSponsor f : e.getSponsors()) { EventContact newContact = (EventContact) getApplicationContext().getBean("eventContact"); newContact.setName(f.getGroupName()); newContact.setUrl(f.getWebsite()); myContacts.add(newContact); } newEvent.setContact(myContacts); LOG.debug("CONTACT " + newEvent.getContact()); newEvents.add(newEvent); } } } return (newEvents); }
From source file:org.kuali.mobility.events.service.EventsServiceImpl.java
@GET @Path("/category/{categoryId}") @Override/*from w ww. j av a 2 s .co m*/ public CategoryImpl getCategory(@QueryParam(value = "campus") String campus, @PathParam(value = "categoryId") String categoryId) { if (getDao().getCategories() == null || getDao().getCategories().isEmpty()) { getDao().initData(campus); } Category category = (Category) CollectionUtils.find(getDao().getCategories(), new CategoryPredicate(campus, categoryId)); return (CategoryImpl) (new CategoryTransform().transform(category)); }
From source file:org.mifos.accounts.loan.struts.action.LoanAccountAction.java
private List<String> fetchClientIdsWithMatchingLoans(final List<LoanBO> individualLoans, final List<LoanAccountDetailsDto> clientDetails) { List<String> clientIds = new ArrayList<String>(); for (final LoanAccountDetailsDto clientDetail : clientDetails) { LoanBO loanMatchingClientDetail = (LoanBO) CollectionUtils.find(individualLoans, new Predicate() { @Override// w ww.j a v a 2 s .c o m public boolean evaluate(final Object object) { return ((LoanBO) object).getCustomer().getCustomerId().toString() .equals(clientDetail.getClientId()); } }); if (loanMatchingClientDetail != null) { clientIds.add(clientDetail.getClientId()); } else { clientIds.add(""); } } return clientIds; }
From source file:org.mifos.accounts.loan.struts.action.LoanAccountAction.java
List<LoanAccountDetailsDto> populateClientDetailsFromLoan(final List<ClientBO> activeClientsUnderGroup, final List<LoanBO> individualLoans, final List<ValueListElement> businessActivities) { List<LoanAccountDetailsDto> clientDetails = new ArrayList<LoanAccountDetailsDto>(); for (final ClientBO client : activeClientsUnderGroup) { LoanAccountDetailsDto clientDetail = new LoanAccountDetailsDto(); clientDetail.setClientId(getStringValue(client.getCustomerId())); clientDetail.setClientName(client.getDisplayName()); LoanBO loanAccount = (LoanBO) CollectionUtils.find(individualLoans, new Predicate() { @Override/*from w w w. j a v a2 s. c om*/ public boolean evaluate(final Object object) { return client.getCustomerId().equals(((LoanBO) object).getCustomer().getCustomerId()); } }); if (loanAccount != null) { final Integer businessActivityId = loanAccount.getBusinessActivityId(); if (businessActivityId != null) { clientDetail.setBusinessActivity(Integer.toString(businessActivityId)); ValueListElement businessActivityElement = (ValueListElement) CollectionUtils .find(businessActivities, new Predicate() { @Override public boolean evaluate(final Object object) { return ((ValueListElement) object).getId().equals(businessActivityId); } }); if (businessActivityElement != null) { clientDetail.setBusinessActivityName(businessActivityElement.getName()); } } clientDetail.setLoanAmount( loanAccount.getLoanAmount() != null ? loanAccount.getLoanAmount().toString() : "0.0"); } clientDetails.add(clientDetail); } return clientDetails; }
From source file:org.mifos.accounts.loan.struts.action.LoanAccountAction.java
private List<LoanAccountDetailsDto> populateDetailsForSelectedClients( final List<LoanAccountDetailsDto> clientDetails, final List<String> selectedClients) { List<LoanAccountDetailsDto> loanAccountDetailsView = new ArrayList<LoanAccountDetailsDto>(); for (final String clientId : selectedClients) { if (StringUtils.isNotEmpty(clientId)) { LoanAccountDetailsDto matchingClientDetail = (LoanAccountDetailsDto) CollectionUtils .find(clientDetails, new Predicate() { @Override public boolean evaluate(final Object object) { return ((LoanAccountDetailsDto) object).getClientId().equals(clientId); }/*from w w w . j av a 2s . co m*/ }); if (matchingClientDetail != null) { setGovernmentIdAndPurpose(matchingClientDetail); loanAccountDetailsView.add(matchingClientDetail); } } } return loanAccountDetailsView; }
From source file:org.mifos.accounts.loan.struts.action.LoanAccountAction.java
void handleIndividualLoans(final LoanBO loanBO, final LoanAccountActionForm loanAccountActionForm, final boolean isRepaymentIndepOfMeetingEnabled, final List<LoanAccountDetailsDto> loanAccountDetailsList, final List<LoanBO> individualLoans) throws AccountException, ServiceException { List<Integer> foundLoans = new ArrayList<Integer>(); for (final LoanAccountDetailsDto loanAccountDetail : loanAccountDetailsList) { Predicate predicate = new Predicate() { @Override//from w w w .j a v a 2s.c o m public boolean evaluate(final Object object) { return ((LoanBO) object).getCustomer().getCustomerId().toString() .equals(loanAccountDetail.getClientId()); } }; LoanBO individualLoan = (LoanBO) CollectionUtils.find(individualLoans, predicate); if (individualLoan == null) { // glimLoanUpdater.createIndividualLoan(loanAccountActionForm, loanBO, isRepaymentIndepOfMeetingEnabled, // loanAccountDetail); } else { foundLoans.add(individualLoan.getAccountId()); glimLoanUpdater.updateIndividualLoan(loanAccountDetail, individualLoan); } } for (LoanBO loan : individualLoans) { if (!foundLoans.contains(loan.getAccountId())) { glimLoanUpdater.delete(loan); } } }