List of usage examples for org.apache.commons.collections15 CollectionUtils forAllDo
public static <E> void forAllDo(Iterable<E> iterable, Closure<? super E> closure)
From source file:gov.nih.nci.cabig.caaers.domain.ResearchStaff.java
/** * Will copy into this Person, the details from the input Person. * * @param rs - The Person from which the details to be copied from. *//*w w w . j a v a2 s . co m*/ public void sync(final ResearchStaff rs) { super.sync(rs); setNciIdentifier(rs.getNciIdentifier()); if (getAddress() != null) { getAddress().sync(rs.getAddress()); } else { setAddress(rs.getAddress()); } //sync the site researchstaffs CollectionUtils.forAllDo(getSiteResearchStaffs(), new Closure<SiteResearchStaff>() { public void execute(SiteResearchStaff srs) { SiteResearchStaff otherSRS = rs.findSiteResearchStaff(srs); srs.sync(otherSRS); } }); //add new site researchstaff if needed for (SiteResearchStaff srs : rs.getSiteResearchStaffs()) { SiteResearchStaff availableSRS = findSiteResearchStaff(srs); if (availableSRS == null) addSiteResearchStaff(srs); } }
From source file:gov.nih.nci.cabig.caaers.web.ae.AbstractExpeditedAdverseEventInputCommand.java
/** * Will update the mandatory fields details. * 1. Evaluate the mandatory-ness via EvaluationService * 2. Update the mandatory properties./*from w w w. j av a 2s . c o m*/ * 3. Update the rendering decisions */ public void updateFieldMandatoryness() { //figureout the reports List<Report> reportsToEvaluate = new ArrayList<Report>(); for (ReportDefinition rd : getSelectedReportDefinitions()) { reportsToEvaluate.add(rd.createReport()); } mandatoryProperties = new MandatoryProperties(expeditedReportTree); //evaluate the mandatoryness CollectionUtils.forAllDo(reportsToEvaluate, new Closure<Report>() { public void execute(Report report) { evaluationService.evaluateMandatoryness(aeReport, report); for (ReportMandatoryField mf : report.getMandatoryFields()) { Mandatory mandatoryness = mf.getMandatory(); if (mandatoryness == Mandatory.MANDATORY) { if (mf.isSelfReferenced()) { mandatoryProperties.addRealPropertyPath(mf.getFieldPath()); } else { mandatoryProperties.addNode(mf.getFieldPath()); } } } } }); //update the render decision renderDecisionManager.updateRenderDecision(reportsToEvaluate); }
From source file:gov.nih.nci.cabig.caaers.rules.business.service.EvaluationServiceImpl.java
/** * Evaluate the mandatoryness of a specific report, the {@link gov.nih.nci.cabig.caaers.domain.report.ReportMandatoryField} will be populated in the Report. * @param aeReport/* w w w. j a v a 2s .com*/ * @param report */ public void evaluateMandatoryness(final ExpeditedAdverseEventReport aeReport, final Report report) { final ReportDefinition rd = report.getReportDefinition(); //clear the mandatory fields in report final List<ReportMandatoryField> mfList = new ArrayList<ReportMandatoryField>(); report.setMandatoryFields(mfList); if (log.isDebugEnabled()) log.debug("Static Mandatory field evaluation"); //evaluation of static field rules CollectionUtils.forAllDo(rd.getAllNonRuleBasedMandatoryFields(), new Closure<ReportMandatoryFieldDefinition>() { public void execute(ReportMandatoryFieldDefinition mfd) { ReportMandatoryField mf = new ReportMandatoryField(mfd.getFieldPath(), Mandatory.NA); //update the mandatory flag if (mfd.getMandatory().equals(RequirednessIndicator.OPTIONAL)) mf.setMandatory(Mandatory.OPTIONAL); if (mfd.getMandatory().equals(RequirednessIndicator.MANDATORY)) mf.setMandatory(Mandatory.MANDATORY); if (log.isDebugEnabled()) log.debug(mfd.getFieldPath() + " -->" + mf.getMandatory().getName()); mfList.add(mf); } }); final List<Object> baseInputObjects = new ArrayList<Object>(); baseInputObjects.add(aeReport); baseInputObjects.add(rd); if (aeReport.getStudy() != null) baseInputObjects.add(aeReport.getStudy()); if (aeReport.getTreatmentInformation() != null) baseInputObjects.add(aeReport.getTreatmentInformation()); //non self referenced rules final List<Object> inputObjects = new ArrayList(baseInputObjects); inputObjects.addAll(aeReport.getActiveAdverseEvents()); final HashMap<String, Mandatory> rulesDecisionCache = new HashMap<String, Mandatory>(); if (log.isDebugEnabled()) log.debug("Non Self referenced rule evaluation"); final String fieldRulesBindURL = adverseEventEvaluationService.fetchBindURI(RuleType.FIELD_LEVEL_RULES, null, null, null); if (StringUtils.isEmpty(fieldRulesBindURL)) { log.warn("No active field level rules found, so ignoring rule based mandatoryness evaluation"); } CollectionUtils.forAllDo(rd.getNonSelfReferencedRuleBasedMandatoryFields(), new Closure<ReportMandatoryFieldDefinition>() { public void execute(ReportMandatoryFieldDefinition mfd) { String ruleName = mfd.getRuleName(); String path = mfd.getFieldPath(); Mandatory m = rulesDecisionCache.get(ruleName); if (StringUtils.isEmpty(fieldRulesBindURL)) { log.info(mfd.getFieldPath() + " marking it as optional, as there is no field rules found"); m = Mandatory.OPTIONAL; } if (m == null) { String decision = adverseEventEvaluationService .evaluateFieldLevelRules(fieldRulesBindURL, ruleName, inputObjects); if (log.isDebugEnabled()) log.debug("rules decision : " + decision); m = translateRulesMandatorynessResult(decision); rulesDecisionCache.put(ruleName, m); if (log.isDebugEnabled()) log.debug("caching --> " + m.getName()); } if (log.isDebugEnabled()) log.debug(mfd.getFieldPath() + " -->" + m.getName()); mfList.add(new ReportMandatoryField(path, m)); } }); //self referenced rules if (log.isDebugEnabled()) log.debug("Self referenced rule evaluation"); CollectionUtils.forAllDo(rd.getSelfReferencedRuleBasedMandatoryFields(), new Closure<ReportMandatoryFieldDefinition>() { public void execute(ReportMandatoryFieldDefinition mfd) { Map<String, Object> map = CaaersRuleUtil.multiplexAndEvaluate(aeReport, mfd.getFieldPath()); for (String path : map.keySet()) { List<Object> inputObjects = new ArrayList(baseInputObjects); Object o = map.get(path); if (o == null) continue; if (o instanceof Collection) { inputObjects.addAll((Collection) o); } else { inputObjects.add(o); } String decision = null; if (StringUtils.isEmpty(fieldRulesBindURL)) { log.info(mfd.getFieldPath() + " marking it as optional, as there is no field rules found"); } else { decision = adverseEventEvaluationService.evaluateFieldLevelRules(fieldRulesBindURL, mfd.getRuleName(), inputObjects); } if (log.isDebugEnabled()) log.debug("rules decision : " + decision); Mandatory m = translateRulesMandatorynessResult(decision); if (log.isDebugEnabled()) log.debug(mfd.getFieldPath() + " -->" + m.getName()); mfList.add(new ReportMandatoryField(path, m)); } } }); }
From source file:org.funcito.example.collectionsgeneric.MyClass.java
protected static void demoClosures(List<MyClass> list) { CollectionUtils.forAllDo(list, incAndReturn); printValues("List has incremented each", CollectionUtils.collect(list, getOther)); CollectionUtils.forAllDo(list, inc); printValues("List has incremented each again", CollectionUtils.collect(list, getOther)); }
From source file:org.springframework.jdbc.repo.impl.AbstractIdentifiedEntityRepo.java
@Override public List<E> findEntities(Collection<String> idsList) { if (ExtendedCollectionUtils.isEmpty(idsList)) { return Collections.emptyList(); }/*from www . j a v a2 s. co m*/ final List<E> result = new ArrayList<E>(idsList.size()); Set<String> idSet = (idsList instanceof Set) ? (Set<String>) idsList : new LinkedHashSet<>(idsList); CollectionUtils.forAllDo(idSet, new AbstractExtendedClosure<String>(String.class) { @Override public void execute(String id) { if (StringUtils.isEmpty(id)) { return; } E entity = findEntityById(id); if (entity == null) { return; } result.add(entity); } }); return result; }
From source file:org.springframework.jdbc.repo.impl.AbstractIdentifiedEntityRepo.java
@Override public List<E> removeAll(Collection<String> idsList) { if (ExtendedCollectionUtils.isEmpty(idsList)) { return Collections.emptyList(); }/*from www .j a v a2 s . c o m*/ final List<E> result = new ArrayList<E>(idsList.size()); CollectionUtils.forAllDo(idsList, new AbstractExtendedClosure<String>(String.class) { @Override public void execute(String id) { if (StringUtils.isEmpty(id)) { return; } E entity = removeEntity(id); if (entity == null) { return; } result.add(entity); } }); return result; }