List of usage examples for org.apache.commons.collections CollectionUtils collect
public static Collection collect(Iterator inputIterator, Transformer transformer)
From source file:org.onebusaway.nyc.sms.actions.IndexAction.java
/** * METHODS FOR VIEWS//from w ww.ja v a 2 s . c o m */ public String getResponse() { String response = _response.trim(); if (_needsGlobalAlert != null && _needsGlobalAlert) { List<ServiceAlertBean> globalAlerts = _realtimeService.getServiceAlertsGlobal(); if (globalAlerts != null && globalAlerts.size() > 0) { String alertsThatFit = "\n\nService Notice: "; String end = "... More at mta.info"; for (ServiceAlertBean alert : globalAlerts) { @SuppressWarnings("unchecked") Collection<String> descriptions = CollectionUtils.collect(alert.getDescriptions(), new Transformer() { @Override public Object transform(Object input) { return ((NaturalLanguageStringBean) input).getValue(); } }); String descriptionString = StringUtils.join(descriptions, "\n\n"); if (response.length() + descriptionString.length() + alertsThatFit.length() > MAX_SMS_CHARACTER_COUNT * 2) { int endIndex = MAX_SMS_CHARACTER_COUNT * 2 - response.length() - alertsThatFit.length() - end.length(); descriptionString = descriptionString.substring(0, endIndex) + end; alertsThatFit += descriptionString; break; } alertsThatFit += descriptionString + "\n\n"; } response += alertsThatFit; } _needsGlobalAlert = false; } syncSession(); return response; }
From source file:org.opencastproject.metadata.dublincore.DublinCoreCatalog.java
@Override @SuppressWarnings("unchecked") public List<String> get(EName property, final String language) { RequireUtil.notNull(property, "property"); RequireUtil.notNull(language, "language"); if (LANGUAGE_ANY.equals(language)) { return (List<String>) CollectionUtils.collect(getValuesAsList(property), new Transformer() { @Override//from w w w . ja v a 2s. c o m public Object transform(Object o) { return ((CatalogEntry) o).getValue(); } }); } else { final List<String> values = new ArrayList<String>(); final boolean langUndef = LANGUAGE_UNDEFINED.equals(language); CollectionUtils.forAllDo(getValuesAsList(property), new Closure() { @Override public void execute(Object o) { CatalogEntry c = (CatalogEntry) o; String lang = c.getAttribute(XML_LANG_ATTR); if ((langUndef && lang == null) || (language.equals(lang))) values.add(c.getValue()); } }); return values; } }
From source file:org.opencastproject.metadata.dublincore.DublinCoreCatalogImpl.java
@SuppressWarnings("unchecked") public List<String> get(EName property, final String language) { if (property == null) throw new IllegalArgumentException("Property name must not be null"); if (language == null) throw new IllegalArgumentException("Language code must not be null"); if (LANGUAGE_ANY.equals(language)) { return (List<String>) CollectionUtils.collect(getValuesAsList(property), new Transformer() { public Object transform(Object o) { return ((CatalogEntry) o).getValue(); }/*from www . j av a 2 s. co m*/ }); } else { final List<String> values = new ArrayList<String>(); final boolean langUndef = LANGUAGE_UNDEFINED.equals(language); CollectionUtils.forAllDo(getValuesAsList(property), new Closure() { public void execute(Object o) { CatalogEntry c = (CatalogEntry) o; String lang = c.getAttribute(XML_LANG_ATTR); if ((langUndef && lang == null) || (language.equals(lang))) values.add(c.getValue()); } }); return values; } }
From source file:org.opencastproject.metadata.dublincore.DublinCoreCatalogImpl.java
public String getAsText(EName property, String language, String delimiter) { if (property == null) throw new IllegalArgumentException("Property name must not be null"); if (language == null) throw new IllegalArgumentException("Language code must not be null"); if (delimiter == null) delimiter = ""; List<CatalogEntry> values; if (LANGUAGE_UNDEFINED.equals(language)) { values = getLocalizedValuesAsList(property, null); } else if (LANGUAGE_ANY.equals(language)) { values = getValuesAsList(property); } else {/*from w ww .ja v a 2 s. co m*/ values = getLocalizedValuesAsList(property, language); } return values.size() > 0 ? StringUtils.join(CollectionUtils.collect(values, new Transformer() { public Object transform(Object o) { return ((CatalogEntry) o).getValue(); } }), delimiter) : null; }
From source file:org.openlmis.restapi.service.RestRequisitionService.java
private void insertRnrSignatures(Report report, Rnr rnr, final Long userId) { if (report.getRnrSignatures() != null) { List<Signature> rnrSignatures = new ArrayList( CollectionUtils.collect(report.getRnrSignatures(), new Transformer() { @Override/*from w w w .j ava2s . co m*/ public Object transform(Object input) { ((Signature) input).setCreatedBy(userId); ((Signature) input).setModifiedBy(userId); return input; } })); rnr.setRnrSignatures(rnrSignatures); requisitionService.insertRnrSignatures(rnr); } }
From source file:org.openmrs.module.kenyaemr.fragment.controller.system.FormsContentFragmentController.java
public void controller(FragmentModel model, @SpringBean FormManager formManager) { List<SimpleObject> forms = new ArrayList<SimpleObject>(); for (FormDescriptor descriptor : formManager.getAllFormDescriptors()) { Form form = descriptor.getTarget(); Collection<String> allowedApps = CollectionUtils.collect(descriptor.getApps(), new Transformer() { @Override/* w ww. j a v a 2 s .c o m*/ public Object transform(Object o) { return ((AppDescriptor) o).getLabel(); } }); forms.add(SimpleObject.create("name", form.getName(), "encounterType", form.getEncounterType().getName(), "allowedApps", allowedApps)); } model.addAttribute("forms", forms); }
From source file:org.openmrs.module.kenyaemr.fragment.controller.system.ProgramsContentFragmentController.java
public void controller(FragmentModel model, @SpringBean ProgramManager programManager) { List<SimpleObject> programs = new ArrayList<SimpleObject>(); for (ProgramDescriptor descriptor : programManager.getAllProgramDescriptors()) { Program program = descriptor.getTarget(); Collection<String> visitForms; if (descriptor.getVisitForms() != null) { visitForms = CollectionUtils.collect(descriptor.getVisitForms(), new Transformer() { @Override/*w w w . ja va 2 s. com*/ public Object transform(Object o) { return ((FormDescriptor) o).getTarget().getName(); } }); } else { visitForms = Collections.emptyList(); } programs.add(SimpleObject.create("name", program.getName(), "enrollmentForm", descriptor.getDefaultEnrollmentForm().getTarget().getName(), "visitForms", visitForms, "completionForm", descriptor.getDefaultCompletionForm().getTarget().getName())); } model.addAttribute("programs", programs); }
From source file:org.openmrs.module.kenyaemr.fragment.controller.system.ReportsContentFragmentController.java
public void controller(FragmentModel model, UiUtils ui, @SpringBean ReportManager reportManager) { List<SimpleObject> reports = new ArrayList<SimpleObject>(); for (ReportDescriptor report : reportManager.getAllReportDescriptors()) { SimpleObject simpleReport = ui.simplifyObject(report); Collection<String> allowedApps = CollectionUtils.collect(report.getApps(), new Transformer() { @Override/*from w w w . j a va2 s. co m*/ public Object transform(Object o) { return ((AppDescriptor) o).getLabel(); } }); simpleReport.put("allowedApps", allowedApps); reports.add(simpleReport); } model.addAttribute("reports", reports); }
From source file:org.openmrs.module.pharmacyapi.api.prescription.validation.PrescriptionItemRule.java
@SuppressWarnings("unchecked") private void checkAllArvItemHaveUniqueRegimen(final Prescription prescription, final List<PrescriptionItem> prescriptionItems) throws PharmacyBusinessException { final DrugRegimeService drugRegimeService = Context.getService(DrugRegimeService.class); final Concept regimen = prescription.getRegime(); if (regimen != null) { final Collection<Concept> itemsRegimens = new ArrayList<>(); for (final PrescriptionItem prescriptionItem : prescriptionItems) { final Drug drug = Context.getConceptService() .getDrugByUuid(prescriptionItem.getDrugOrder().getDrug().getUuid()); final List<DrugRegime> drugRegimens = drugRegimeService.findDrugRegimeByDrugUuid(drug.getUuid()); final Collection<Concept> regimens = CollectionUtils.collect(drugRegimens, TransformerUtils.invokerTransformer("getRegime")); if (!regimens.isEmpty() && !regimens.contains(regimen)) { final Collection<String> regimeNames = CollectionUtils.collect(regimens, TransformerUtils.invokerTransformer("getDisplayString")); throw new PharmacyBusinessException("Nao foi encontrada correspondencia entre os regimes " + StringUtils.join(regimeNames, "|") + " do medicamento " + drug.getDisplayName() + " e o regime " + regimen.getDisplayString() + " informado"); }/*from w w w .j a v a2 s. c o m*/ itemsRegimens.addAll(regimens); } if (itemsRegimens.isEmpty()) { throw new PharmacyBusinessException("Nao pode ser criada Prescricao ARV para medicamentos nao ARV"); } } }
From source file:org.openmrs.module.pharmacyapi.api.service.dispensationservice.DispensationServiceTest.java
@SuppressWarnings("unchecked") @Test/* w ww .j a v a2s. c o m*/ public void shouldDispenseOrdersForNonArvPrescription() throws Exception { this.executeDataSet("dispensationservice/shouldDispenseOrdersForNonArvPrescription-dataset.xml"); final Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2005); calendar.set(Calendar.MONTH, 0); calendar.set(Calendar.DAY_OF_MONTH, 1); final Dispensation dispensation = new Dispensation(); dispensation.setPatientUuid("5946f880-b197-400b-9caa-a3c661d23041"); dispensation.setLocationUuid("8d6c993e-c2cc-11de-8d13-0010c6dffd0f"); dispensation.setProviderUuid("ba1b19c2-3ed6-4f63-b8c0-f762dc8d7562"); dispensation.setDispensationDate(calendar.getTime()); final DispensationItem dispensationItem = new DispensationItem(); dispensationItem.setQuantityDispensed(0d); dispensationItem.setQuantityToDispense(3d); final String orderUuid = "921de0a3-05c4-444a-be03-0001"; final String encounterPrescriptionUuid = "eec646cb-c847-4ss-enc-who-adult"; dispensationItem.setOrderUuid(orderUuid); dispensationItem.setPrescriptionUuid(encounterPrescriptionUuid); dispensation.setDispensationItems(Arrays.asList(dispensationItem)); final Dispensation createdDispensation = Context.getService(DispensationService.class) .dispense(dispensation); Assert.assertNotNull(createdDispensation); final List<PrescriptionDispensation> prescriptionDispensations = Context .getService(PrescriptionDispensationService.class) .findPrescriptionDispensationByPrescription(new Encounter(1000)); Assert.assertTrue(!prescriptionDispensations.isEmpty()); Assert.assertEquals(1, prescriptionDispensations.size()); final PrescriptionDispensation prescriptionDispensation = prescriptionDispensations.iterator().next(); final Encounter dispensationEncounter = prescriptionDispensation.getDispensation(); Assert.assertEquals(MappedEncounters.DISPENSATION_ENCOUNTER_TYPE, dispensationEncounter.getEncounterType().getUuid()); final List<Obs> observations = Context.getObsService().getObservations(null, Arrays.asList(dispensationEncounter), null, null, null, null, null, null, null, null, null, false); MatcherAssert.assertThat(observations, IsCollectionWithSize.hasSize(3)); final Collection<Concept> concepts = CollectionUtils.collect(observations, TransformerUtils.invokerTransformer("getConcept")); final Collection<String> uuids = CollectionUtils.collect(concepts, TransformerUtils.invokerTransformer("getUuid")); MatcherAssert.assertThat(uuids, Matchers.hasItems(MappedConcepts.DISPENSATION_SET, MappedConcepts.MEDICATION_QUANTITY, MappedConcepts.DATE_OF_NEXT_PICK_UP)); }