List of usage examples for org.apache.commons.collections CollectionUtils collect
public static Collection collect(Iterator inputIterator, Transformer transformer)
From source file:org.openmrs.module.pharmacyapi.api.service.dispensationservice.DispensationServiceTest.java
@SuppressWarnings("unchecked") @Test//from w ww. j ava 2s . c o m public void shouldDispenseOrdersForArvPrescription() throws Exception { this.executeDataSet("dispensationservice/shouldDispenseOrdersForArvPrescription-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.setRegimeUuid("9dc17c1b-7b6d-488e-a38d-505a7b6xxx1"); 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(4)); 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, MappedConcepts.PREVIOUS_ANTIRETROVIRAL_DRUGS)); }
From source file:org.openo.sdnhub.overlayvpndriver.rest.IpSecROAResource.java
/** * Deletes IPSec VPN configuration using a specific controller.<br> * * @param ctrlUuidParam Controller UUID/*from ww w. j ava2 s . c o m*/ * @param deviceId device id * @param ipsecList collection of IPSec VPN configuration * @return ResultRsp object with IPSec VPN deleted configuration status data * @throws ServiceException when input validation fails * @since SDNHUB 0.5 */ @POST @Path("/device/{deviceid}/ipsecs/{extipsecid}/batch-delete-ipsec") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @SuppressWarnings("unchecked") public ResultRsp<SbiNeIpSec> deleteIpSec(@HeaderParam(CTRL_HEADER_PARAM) String ctrlUuidParam, @PathParam("deviceid") String deviceId, List<SbiNeIpSec> ipsecList) throws ServiceException { long beginTime = System.currentTimeMillis(); LOGGER.debug("Ipsec delete begin time = " + beginTime); String ctrlUuid = RequestHeaderUtil.readControllerUUID(ctrlUuidParam); if (!UuidUtil.validate(ctrlUuid)) { LOGGER.error(CONTROLLER_INV_UUID); throw new ParameterServiceException(CONTROLLER_INV_UUID); } if (CollectionUtils.isEmpty(ipsecList)) { LOGGER.error(REQ_BODY_NULL_OR_EMPTY); throw new ParameterServiceException(REQ_BODY_NULL_OR_EMPTY); } CheckStrUtil.checkUuidStr(deviceId); List<String> externalIds = new ArrayList<>(CollectionUtils.collect(ipsecList, new Transformer() { @Override public Object transform(Object arg0) { return ((SbiNeIpSec) arg0).getExternalId(); } })); ipsecService.checkSeqNumber(externalIds); ResultRsp<SbiNeIpSec> response = ipsecService.batchDeleteIpsecConn(ctrlUuid, ipsecList); LOGGER.debug("delete Ipsec cost time = " + (System.currentTimeMillis() - beginTime)); return response; }
From source file:org.openo.sdnhub.servicechaindriverservice.db.ServiceChainInfoDao.java
/** * Allocate VLAN Id Resource.<br>// w w w . j a v a2 s. com * * @return VLAN Id allocated * @throws ServiceException when allocate VLAN id failed * @since SDNHUB 0.5 */ public int allocVlanId() throws ServiceException { List<ServiceChainInfo> scInfoList = queryAllServiceChainInfo(); if (scInfoList.isEmpty()) { return MIN_VLAN_ID; } @SuppressWarnings("unchecked") List<Integer> vlanIdList = new ArrayList<>(CollectionUtils.collect(scInfoList, new Transformer() { @Override public Object transform(Object arg0) { return ((ServiceChainInfo) arg0).getVlanId(); } })); for (Integer vlanId = MIN_VLAN_ID; vlanId <= MAX_VLAN_ID; vlanId++) { if (!vlanIdList.contains(vlanId)) { return vlanId; } } return INVALID_VLAN_ID; }
From source file:org.oztrack.view.OaiPmhRecordWriter.java
private void writeOaiDcRepositoryMetadataElement(OaiPmhRecord record) throws XMLStreamException { out.writeStartElement(OAI_DC.nsPrefix, "dc", OAI_DC.nsUri); // Every metadata part must include xmlns attributes for its metadata formats. // http://www.openarchives.org/OAI/2.0/openarchivesprotocol.htm#Record out.setPrefix(OAI_DC.nsPrefix, OAI_DC.nsUri); out.writeNamespace(OAI_DC.nsPrefix, OAI_DC.nsUri); out.setPrefix(DC.nsPrefix, DC.nsUri); out.writeNamespace(DC.nsPrefix, DC.nsUri); // Every metadata part must include the attributes xmlns:xsi (namespace URI for XML schema) and // xsi:schemaLocation (namespace URI and XML schema URL for validating metadata that follows). // http://www.openarchives.org/OAI/2.0/openarchivesprotocol.htm#Record out.setPrefix(XSI.nsPrefix, XSI.nsUri); out.writeNamespace(XSI.nsPrefix, XSI.nsUri); out.writeAttribute(XSI.nsUri, "schemaLocation", OAI_DC.nsUri + " " + OAI_DC.xsdUri); if (StringUtils.isNotBlank(record.getObjectIdentifier())) { out.writeStartElement(DC.nsUri, "identifier"); out.writeCharacters(record.getObjectIdentifier()); out.writeEndElement(); // identifier }/*w w w . ja va 2 s. co m*/ Transformer namePartToTextTransformer = new Transformer() { @Override public Object transform(Object input) { return ((OaiPmhRecord.Name.NamePart) input).getNamePartText(); } }; String title = StringUtils .join(CollectionUtils.collect(record.getName().getNameParts(), namePartToTextTransformer), " "); if (StringUtils.isNotBlank(title)) { out.writeStartElement(DC.nsUri, "title"); out.writeCharacters(title); out.writeEndElement(); // title } if (StringUtils.isNotBlank(record.getDescription())) { out.writeStartElement(DC.nsUri, "description"); out.writeCharacters(record.getDescription()); out.writeEndElement(); // description } if (StringUtils.isNotBlank(record.getCreator())) { out.writeStartElement(DC.nsUri, "creator"); out.writeCharacters(record.getCreator()); out.writeEndElement(); // creator } if (record.getRecordCreateDate() != null) { out.writeStartElement(DC.nsUri, "created"); out.writeCharacters(utcDateTimeFormat.format(record.getRecordCreateDate())); out.writeEndElement(); // created } if (record.getRecordUpdateDate() != null) { out.writeStartElement(DC.nsUri, "date"); out.writeCharacters(utcDateTimeFormat.format(record.getRecordUpdateDate())); out.writeEndElement(); // date } if (record.getSpatialCoverage() != null) { out.writeStartElement(DC.nsUri, "coverage"); out.writeCharacters("North " + record.getSpatialCoverage().getMaxY() + ", "); out.writeCharacters("East " + record.getSpatialCoverage().getMaxX() + ", "); out.writeCharacters("South " + record.getSpatialCoverage().getMinY() + ", "); out.writeCharacters("West " + record.getSpatialCoverage().getMinX() + "."); out.writeEndElement(); // coverage } if (StringUtils.isNotBlank(record.getAccessRights())) { out.writeStartElement(DC.nsUri, "accessRights"); out.writeCharacters(record.getAccessRights()); out.writeEndElement(); // accessRights } if ((record.getLicence() != null) && StringUtils.isNotBlank(record.getLicence().getLicenceText())) { out.writeStartElement(DC.nsUri, "license"); out.writeCharacters(record.getLicence().getLicenceText()); out.writeEndElement(); // license } if (StringUtils.isNotBlank(record.getRightsStatement())) { out.writeStartElement(DC.nsUri, "rights"); out.writeCharacters(record.getRightsStatement()); out.writeEndElement(); // rights } if (record.getRelations() != null) { for (OaiPmhRecord.Relation relation : record.getRelations()) { out.writeStartElement(DC.nsUri, "relation"); out.writeAttribute("type", relation.getRelationType()); out.writeCharacters(relation.getRelatedObjectIdentifier()); out.writeEndElement(); // relation } } if (record.getSubjects() != null) { for (OaiPmhRecord.Subject subject : record.getSubjects()) { if (subject.getSubjectType().equals("local")) { out.writeStartElement(DC.nsUri, "subject"); out.writeCharacters(subject.getSubjectText()); out.writeEndElement(); // subject } } } if (StringUtils.isNotBlank(record.getDcType())) { out.writeStartElement(DC.nsUri, "type"); out.writeCharacters(record.getDcType()); out.writeEndElement(); // type } out.writeEndElement(); // dc }
From source file:org.paxml.bean.AbstractLazyTag.java
@Override protected Object doInvoke(Context context) throws Exception { Iterator it = getIterator(context); if (lazy) {/*www .j a v a2s .c om*/ return it; } else { return CollectionUtils.collect(it, new Transformer() { @Override public Object transform(Object obj) { return obj; } }); } }
From source file:org.projectforge.core.DisplayHistoryEntry.java
private Object toShortNameOfList(final Object value) { if (value instanceof Collection<?>) { return CollectionUtils.collect((Collection<?>) value, new Transformer() { public Object transform(final Object input) { return toShortName(input); }/*www. j a va 2s . c om*/ }); } return value; }
From source file:org.projectforge.framework.persistence.history.DisplayHistoryEntry.java
private Object toShortNameOfList(final Object value) { if (value instanceof Collection<?>) { return CollectionUtils.collect((Collection<?>) value, new Transformer() { @Override/*from www.j ava 2s. co m*/ public Object transform(final Object input) { return toShortName(input); } }); } return toShortName(value); }
From source file:org.robotframework.swing.keyword.concurrent.ThreadKeywords.java
@SuppressWarnings("unchecked") private Collection<String> normalizeKeywordNames(String[] keywordNames) { List<String> keywordsList = Arrays.asList(keywordNames); return CollectionUtils.collect(keywordsList, new Transformer() { public Object transform(Object input) { return normalizer.normalize(input.toString()); }//w w w . j av a 2 s . c om }); }
From source file:org.robotframework.swing.tree.TreeOperator.java
@SuppressWarnings("unchecked") public Collection<String> getTreeNodeChildNames(String nodeIdentifier) { final TreePath treePath = createTreePath(nodeIdentifier); return CollectionUtils.collect(getChildPaths(treePath), new Transformer() { public Object transform(Object input) { Object node = ((TreePath) input).getLastPathComponent(); return new NodeTextExtractor((JTree) getSource()).getText(node, treePath); }/*ww w. ja v a2 s .co m*/ }); }
From source file:org.sipfoundry.sipxconfig.admin.dialplan.DialPlanContextTestDb.java
public void testDuplicateDefaultRules() throws Exception { m_resetDialPlanTask.reset(true);/*from w w w . ja v a 2s. c om*/ List rules = m_context.getRules(); Transformer bean2id = new BeanWithId.BeanToId(); Collection ruleIds = CollectionUtils.collect(rules, bean2id); m_context.duplicateRules(ruleIds); assertEquals(ruleIds.size() * 2, m_context.getRules().size()); IDataSet set = TestHelper.getConnection().createDataSet(); ITable table = set.getTable("dialing_rule"); assertEquals(ruleIds.size() * 2, table.getRowCount()); }