List of usage examples for org.apache.commons.collections4 Predicate Predicate
Predicate
From source file:org.jasig.cas.support.oauth.OAuthTokenUtils.java
/** * Return a list of refresh tokens associated with a specific client application. * * @param centralAuthenticationService the central authentication service * @param clientId the client id// w w w . j a v a 2s . co m * @return Collection of refresh tokens for the application specified */ public static Collection<Ticket> getRefreshTokens( final CentralAuthenticationService centralAuthenticationService, final String clientId) { return centralAuthenticationService.getTickets(new Predicate() { @Override public boolean evaluate(final Object currentTicket) { if (currentTicket instanceof TicketGrantingTicket) { final TicketGrantingTicket currentTicketGrantingTicket = (TicketGrantingTicket) currentTicket; final Map<String, Object> currentAttributes = currentTicketGrantingTicket.getAuthentication() .getAttributes(); if ((currentAttributes.containsKey(OAuthCredential.AUTHENTICATION_ATTRIBUTE_OAUTH) && (Boolean) currentAttributes.get(OAuthCredential.AUTHENTICATION_ATTRIBUTE_OAUTH)) && (currentAttributes.containsKey(OAuthConstants.CLIENT_ID) && currentAttributes.get(OAuthConstants.CLIENT_ID).equals(clientId))) { return !currentTicketGrantingTicket.isExpired(); } } return false; } }); }
From source file:org.jasig.cas.support.oauth.OAuthTokenUtils.java
/** * Return a list of refresh tokens associated with the a principal. * * @param centralAuthenticationService the central authentication service * @param principal the principal// w ww . ja va 2 s.c o m * @return Collection of refresh tokens associated with the principal specified */ public static Collection<Ticket> getRefreshTokens( final CentralAuthenticationService centralAuthenticationService, final Principal principal) { return centralAuthenticationService.getTickets(new Predicate() { @Override public boolean evaluate(final Object currentTicket) { if (currentTicket instanceof TicketGrantingTicket) { final TicketGrantingTicket currentTicketGrantingTicket = (TicketGrantingTicket) currentTicket; final Principal currentPrincipal = currentTicketGrantingTicket.getAuthentication() .getPrincipal(); final Map<String, Object> currentAttributes = currentTicketGrantingTicket.getAuthentication() .getAttributes(); if ((currentAttributes.containsKey(OAuthCredential.AUTHENTICATION_ATTRIBUTE_OAUTH) && (Boolean) currentAttributes.get(OAuthCredential.AUTHENTICATION_ATTRIBUTE_OAUTH)) && currentPrincipal.getId().equals(principal.getId())) { return !currentTicketGrantingTicket.isExpired(); } } return false; } }); }
From source file:org.jasig.cas.web.report.SingleSignOnSessionsReportController.java
/** * Gets non expired ticket granting tickets. * * @return the non expired ticket granting tickets *//*from ww w. j a v a2s . c o m*/ private Collection<Ticket> getNonExpiredTicketGrantingTickets() { return this.centralAuthenticationService.getTickets(new Predicate() { @Override public boolean evaluate(final Object ticket) { if (ticket instanceof TicketGrantingTicket) { return !((TicketGrantingTicket) ticket).isExpired(); } return false; } }); }
From source file:org.kuali.coeus.common.budget.impl.struts.BudgetPersonnelAction.java
/** * This method is used to add a new Personnel Budget Line Item * @param mapping/*from w w w.j ava 2 s . c o m*/ * @param form * @param request * @param response * @return mapping forward * @throws Exception */ public ActionForward addPersonnelLineItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { BudgetForm budgetForm = (BudgetForm) form; Budget budget = budgetForm.getBudget(); Integer budgetCategoryTypeIndex = Integer.parseInt(getBudgetCategoryTypeIndex(request)); BudgetLineItem newBudgetLineItem = budgetForm.getNewBudgetLineItems().get(budgetCategoryTypeIndex); final BudgetPersonnelDetails budgetPersonDetails = budgetForm.getNewBudgetPersonnelDetails(); budgetPersonDetails.setBudgetId(budget.getBudgetId()); budgetPersonDetails.setPeriodTypeCode(this.getParameterService().getParameterValueAsString(Budget.class, Constants.BUDGET_PERSON_DETAILS_DEFAULT_PERIODTYPE)); budgetPersonDetails.setCostElement(newBudgetLineItem.getCostElement()); budgetPersonDetails .setBudgetPerson(CollectionUtils.find(budget.getBudgetPersons(), new Predicate<BudgetPerson>() { @Override public boolean evaluate(BudgetPerson object) { return object != null && object.getBudgetId().equals(budgetPersonDetails.getBudgetId()) && object.getPersonSequenceNumber() .equals(budgetPersonDetails.getPersonSequenceNumber()); } })); String groupErrorKey = ""; if (StringUtils.isNotEmpty(newBudgetLineItem.getGroupName())) { groupErrorKey = "newBudgetLineItems[" + budgetCategoryTypeIndex + "].costElement"; } if (StringUtils.isEmpty(newBudgetLineItem.getGroupName())) { newBudgetLineItem.setGroupName(budgetForm.getNewGroupName()); groupErrorKey = "newGroupName"; } //if the group name is empty or still the default group name(JS error?) then set the group name to the empty string. if (StringUtils.isEmpty(newBudgetLineItem.getGroupName()) || StringUtils.equals(newBudgetLineItem.getGroupName(), DEFAULT_GROUP_NAME)) { newBudgetLineItem.setGroupName(EMPTY_GROUP_NAME); } if (getKcBusinessRulesEngine().applyRules( new AddPersonnelBudgetEvent(budget, budget.getBudgetPeriod(budgetForm.getViewBudgetPeriod() - 1), newBudgetLineItem, budgetPersonDetails, groupErrorKey))) { Map<String, Object> primaryKeys = new HashMap<String, Object>(); primaryKeys.put("budgetId", budget.getBudgetId()); primaryKeys.put("budgetPeriod", budgetForm.getViewBudgetPeriod().toString()); List<BudgetPeriod> budgetPeriods = (List<BudgetPeriod>) getBusinessObjectService() .findMatching(BudgetPeriod.class, primaryKeys); BudgetPeriod budgetPeriod = null; if (CollectionUtils.isNotEmpty(budgetPeriods)) { budgetPeriod = budgetPeriods.get(0); } BudgetCategory newBudgetCategory = new BudgetCategory(); newBudgetCategory.setBudgetCategoryTypeCode(getSelectedBudgetCategoryType(request)); newBudgetCategory.refreshNonUpdateableReferences(); boolean existingCeGroupCombo = false; int openTabLineItemIndex = -1; List<BudgetLineItem> existingPersonnelLineItems = new ArrayList<BudgetLineItem>(); List<BudgetLineItem> existingLineItems = budget.getBudgetPeriod(budgetPeriod.getBudgetPeriod() - 1) .getBudgetLineItems(); if (GlobalVariables.getMessageMap().hasNoErrors()) { for (BudgetLineItem budgetLineItem : existingLineItems) { budgetLineItem.refreshNonUpdateableReferences(); if (budgetLineItem.getBudgetCategory().getBudgetCategoryTypeCode() .equalsIgnoreCase(newBudgetCategory.getBudgetCategoryTypeCode())) { existingPersonnelLineItems.add(budgetLineItem); if (newBudgetLineItem.getCostElement().equalsIgnoreCase(budgetLineItem.getCostElement()) && (StringUtils.equals(newBudgetLineItem.getGroupName(), budgetLineItem.getGroupName()) || (StringUtils.isEmpty(newBudgetLineItem.getGroupName()) && StringUtils.isEmpty(budgetLineItem.getGroupName())))) { //Existing ObjCode / Group Name combo - add the new Person to the Line Item's Person List if (budgetPersonDetails.getPersonSequenceNumber().intValue() != -1) { //This is NOT a Summary entry if (getKcBusinessRulesEngine().applyRules(new AddPersonnelLineItemBudgetEvent( budget, "newBudgetPersonnelDetails", budgetLineItem))) { addBudgetPersonnelDetails(budgetForm, budgetPeriod, budgetLineItem, budgetPersonDetails); } } else if (!getKcBusinessRulesEngine() .applyRules(new AddSummaryPersonnelLineItemBudgetEvent(budget, "newBudgetPersonnelDetails", budgetLineItem))) { existingCeGroupCombo = true; break; } openTabLineItemIndex = budgetLineItem.getLineItemNumber(); setLineItemQuantity(budgetLineItem); //set some flag to indicate path of progress existingCeGroupCombo = true; break; } } } //If flag not set, then create a new Budget Line Item - ObjCode / Group Name combo is new if (!existingCeGroupCombo) { newBudgetLineItem.setBudgetPeriod(budgetPeriod.getBudgetPeriod()); newBudgetLineItem.setBudgetPeriodId(budgetPeriod.getBudgetPeriodId()); newBudgetLineItem.setBudgetPeriodBO(budgetPeriod); newBudgetLineItem.setBudgetCategory(newBudgetCategory); newBudgetLineItem.setStartDate( budget.getBudgetPeriod(budgetPeriod.getBudgetPeriod() - 1).getStartDate()); newBudgetLineItem .setEndDate(budget.getBudgetPeriod(budgetPeriod.getBudgetPeriod() - 1).getEndDate()); newBudgetLineItem.setStartDate(newBudgetLineItem.getStartDate()); newBudgetLineItem.setEndDate(newBudgetLineItem.getEndDate()); newBudgetLineItem.setBudgetId(budget.getBudgetId()); newBudgetLineItem.setLineItemNumber(budgetForm.getBudgetDocument() .getHackedDocumentNextValue(Constants.BUDGET_LINEITEM_NUMBER)); newBudgetLineItem.setApplyInRateFlag(true); newBudgetLineItem.refreshReferenceObject("costElementBO"); // on/off campus flag enhancement String onOffCampusFlag = budget.getOnOffCampusFlag(); if (onOffCampusFlag.equalsIgnoreCase(BudgetConstants.DEFAULT_CAMPUS_FLAG)) { newBudgetLineItem .setOnOffCampusFlag(newBudgetLineItem.getCostElementBO().getOnOffCampusFlag()); } else { newBudgetLineItem .setOnOffCampusFlag(onOffCampusFlag.equalsIgnoreCase(Constants.ON_CAMUS_FLAG)); } newBudgetLineItem .setBudgetCategoryCode(newBudgetLineItem.getCostElementBO().getBudgetCategoryCode()); newBudgetLineItem.setLineItemSequence(newBudgetLineItem.getLineItemNumber()); if (budgetPersonDetails.getPersonSequenceNumber().intValue() != -1) { addBudgetPersonnelDetails(budgetForm, budgetPeriod, newBudgetLineItem, budgetPersonDetails); } setLineItemQuantity(newBudgetLineItem); budget.getBudgetPeriod(budgetPeriod.getBudgetPeriod() - 1).getBudgetLineItems() .add(newBudgetLineItem); recalculateBudgetPeriod(budgetForm, budget, budget.getBudgetPeriod(budgetPeriod.getBudgetPeriod() - 1)); getCalculationService().populateCalculatedAmount(budget, newBudgetLineItem); openTabLineItemIndex = newBudgetLineItem.getLineItemNumber(); } BudgetLineItem newLineItemToAdd = budget.getNewBudgetLineItem(); budgetForm.getNewBudgetLineItems().set(budgetCategoryTypeIndex, newLineItemToAdd); request.setAttribute("openTabLineItemIndex", openTabLineItemIndex); budgetForm.setNewBudgetPersonnelDetails(newLineItemToAdd.getNewBudgetPersonnelLineItem()); } } return mapping.findForward(Constants.MAPPING_BASIC); }
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 w w w. j a v a2 s. 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 a v a 2 s . com 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.sys.impl.service.SpringBeanConfigurationTest.java
/** * This method looks for the same bean name in different context but of different class types. * This is either a "partial" bean override or a bean name conflict *//* w w w. j a va2 s . c o m*/ @Test public void test_beans_across_other_contexts_name_conflict() { final HashMap<String, Set<Class<?>>> beans = new HashMap<>(); toEachSpringBean(new VoidFunction() { @Override public void r(ApplicationContext context, String name) { Object o = context.getBean(name); if (o != null) { Set<Class<?>> beanClasses = beans.get(name); if (beanClasses == null) { beanClasses = new HashSet<>(); } final Class<?> clazz; if (Proxy.isProxyClass(o.getClass())) { try { clazz = (Class<?>) Proxy.getInvocationHandler(o).invoke(o, Object.class.getMethod("getClass", new Class[] {}), new Object[] {}); } catch (Throwable e) { throw new RuntimeException(e); } } else { clazz = o.getClass(); } beanClasses.add(clazz); beans.put(name, beanClasses); } else { LOG.warn("bean " + name + " is null"); } } }, true); final Set<Map.Entry<String, Set<Class<?>>>> entrySet = new HashSet<>(beans.entrySet()); CollectionUtils.filter(entrySet, new Predicate<Map.Entry<String, Set<Class<?>>>>() { @Override public boolean evaluate(Map.Entry<String, Set<Class<?>>> object) { return object.getValue().size() > 1; } }); Assert.assertTrue( "The following bean names are duplicated in different contexts with different class names " + entrySet, entrySet.isEmpty()); }
From source file:org.kuali.kra.timeandmoney.service.impl.TimeAndMoneyHistoryServiceImpl.java
protected List<TransactionDetail> getIntermediateTransactions(List<TransactionDetail> transactions) { return ListUtils.select(transactions, new Predicate<TransactionDetail>() { @Override// ww w . j av a 2s. co m public boolean evaluate(TransactionDetail detail) { return TransactionDetailType.INTERMEDIATE.toString().equals(detail.getTransactionDetailType()); } }); }
From source file:org.molasdin.wbase.transaction.profiles.ProfilesManager.java
public TransactionProfile profileFor(final String dbName) { String key = CollectionUtils.find(profiles.keySet(), new Predicate<String>() { @Override//from w ww. j a va 2s. c o m public boolean evaluate(String object) { return StringUtils.containsIgnoreCase(dbName, object); } }); if (key == null) { return commonTransactionProfile; } return profiles.get(key); }
From source file:org.ohdsi.webapi.service.IRAnalysisService.java
@GET @Path("/{id}/report/{sourceKey}") @Produces(MediaType.APPLICATION_JSON)//from ww w . j av a 2 s . co m @Transactional public AnalysisReport getAnalysisReport(@PathParam("id") final int id, @PathParam("sourceKey") final String sourceKey, @QueryParam("targetId") final int targetId, @QueryParam("outcomeId") final int outcomeId) { Source source = this.getSourceRepository().findBySourceKey(sourceKey); AnalysisReport.Summary summary = IterableUtils.find(getAnalysisSummaryList(id, source), new Predicate<AnalysisReport.Summary>() { @Override public boolean evaluate(AnalysisReport.Summary summary) { return ((summary.targetId == targetId) && (summary.outcomeId == outcomeId)); } }); Collection<AnalysisReport.StrataStatistic> strataStats = CollectionUtils .select(getStrataStatistics(id, source), new Predicate<AnalysisReport.StrataStatistic>() { @Override public boolean evaluate(AnalysisReport.StrataStatistic summary) { return ((summary.targetId == targetId) && (summary.outcomeId == outcomeId)); } }); String treemapData = getStrataTreemapData(id, targetId, outcomeId, strataStats.size(), source); AnalysisReport report = new AnalysisReport(); report.summary = summary; report.stratifyStats = new ArrayList<>(strataStats); report.treemapData = treemapData; return report; }