PathValue implements I_PathValue { public static Object decodeValue(String dvClassName, Map<String, String> dvMap, Map<String, Object> args) throws Exception { Map<String, Object> values = new HashMap<>(); for (String atributeName: args.keySet()){ if (dvMap.containsKey(atributeName)){ String attributeClassName = dvMap.get(atributeName); if (attributeClassName.contains("java.lang.")){ Class clazz = ClassUtils.getClass(attributeClassName); Constructor constructor = clazz.getDeclaredConstructor(new Class[]{String.class}); Object value = constructor.newInstance(args.get(atributeName)); values.put(atributeName, value); } else if (attributeClassName.contains(RMBuilder.OPENEHR_RM_PACKAGE)) { String attrClassSimpleName = attributeClassName.substring(attributeClassName.lastIndexOf(".")+1); Class attributeInstrument = VBeanUtil.findInstrumentalizedClass(attrClassSimpleName); if (attributeInstrument != null) { Method generate = attributeInstrument.getDeclaredMethod("generate", null); Object generated = generate.invoke(null, null); Constructor constructor = attributeInstrument.getDeclaredConstructor(new Class[]{generated.getClass()}); Object instrumentalized = constructor.newInstance(generated); Method parser = attributeInstrument.getDeclaredMethod("parse", new Class[]{String.class, String[].class}); Object value = parser.invoke(instrumentalized, args.get(atributeName), (String)null); values.put(atributeName, value); } else { log.info("possible primitive?" + attrClassSimpleName); values.put(atributeName, args.get(atributeName)); } } else { Class clazz = ClassUtils.getClass(attributeClassName); Class wrapperClass = ClassUtils.primitiveToWrapper(clazz); Constructor constructor = wrapperClass.getDeclaredConstructor(new Class[]{String.class}); Object value = constructor.newInstance(args.get(atributeName)); values.put(atributeName, value); } } } Class mainInstrument = VBeanUtil.findInstrumentalizedClass(dvClassName); Method instanceGetter = mainInstrument.getDeclaredMethod("getInstance", new Class[]{Map.class}); Map<String, Object> valueMap = new HashMap<>(); valueMap.put(CompositionSerializer.TAG_VALUE, values); Object generated = instanceGetter.invoke(null, valueMap); if (generated instanceof DataValue) return (DataValue)generated; return generated; } PathValue(I_KnowledgeCache cache, String templateId, Properties properties);  PathValue(I_ContentBuilder contentBuilder, I_KnowledgeCache cache, String templateId, Properties properties);  PathValue(Properties properties); Composition assign(Map<String, Object> keyValues); Boolean update(Composition composition, Map<String, Object> keyValues); Boolean updateEventContext(EventContext eventContext, Map<String, Object> keyValues); boolean assignItemStructure(String filterTag, Locatable locatable, Map<String, Object> pathValues); static Object decodeValue(String dvClassName, Map<String, String> dvMap, Map<String, Object> args); @Override boolean isModifiedContext(); @Override boolean isModifiedAttributes(); @Override boolean isModifiedContent(); @Override void setLenient(Boolean lenient);  }
@Test public void testCodePhrase() throws Exception { kvPairs.clear(); kvPairs.put("codeString", "1111"); Map<String, String> terminology = new HashMap<>(); terminology.put("value", "openehr"); kvPairs.put("terminologyId", terminology); dataValue = (DataValue)PathValue.decodeValue("CodePhrase", FieldUtil.flatten(FieldUtil.getAttributes(CodePhraseVBean.generate())), kvPairs); assertEquals(((CodePhrase) dataValue).getCodeString(), "1111"); }
@Test public void testDvCount() throws Exception { kvPairs.clear(); kvPairs.put("magnitude", "1"); dataValue = (DataValue)PathValue.decodeValue("DvCount", FieldUtil.flatten(FieldUtil.getAttributes(DvCountVBean.generate())), kvPairs); assertEquals(((DvCount) dataValue).getMagnitude(), (Integer) 1); }
@Test public void testDvBoolean() throws Exception { kvPairs.clear(); kvPairs.put("value", "false"); dataValue = (DataValue)PathValue.decodeValue("DvBoolean", FieldUtil.flatten(FieldUtil.getAttributes(DvBooleanVBean.generate())), kvPairs); assertEquals(((DvBoolean) dataValue).getValue(), false); }
@Test public void testDvCodedText() throws Exception { kvPairs.clear(); kvPairs.put("value", "zzz"); kvPairs.put("definingCode", "openehr::111"); dataValue = (DataValue)PathValue.decodeValue("DvCodedText", FieldUtil.flatten(FieldUtil.getAttributes(DvCodedTextVBean.generate())), kvPairs); assertEquals(((DvCodedText) dataValue).getValue(), "zzz"); }
@Test public void testDvDateTime() throws Exception { kvPairs.clear(); String dateTime = new DateTime(DateTime.now()).toString(); kvPairs.put("value", dateTime); dataValue = (DataValue)PathValue.decodeValue("DvDateTime", FieldUtil.flatten(FieldUtil.getAttributes(DvDateTimeVBean.generate())), kvPairs); assertEquals(((DvDateTime) dataValue).getValue(), dateTime); }
@Test public void testDvDate() throws Exception { kvPairs.clear(); String dateTime = "2010-10-10"; kvPairs.put("value", dateTime); dataValue = (DataValue)PathValue.decodeValue("DvDate", FieldUtil.flatten(FieldUtil.getAttributes(DvDateTimeVBean.generate())), kvPairs); assertEquals(((DvDate) dataValue).getValue(), dateTime); }
@Test public void testDvTime() throws Exception { kvPairs.clear(); String dateTime = "10:10:10"; kvPairs.put("value", dateTime); dataValue = (DataValue)PathValue.decodeValue("DvTime", FieldUtil.flatten(FieldUtil.getAttributes(DvDateTimeVBean.generate())), kvPairs); assertEquals(((DvTime) dataValue).getValue(), dateTime); }
@Test public void testDvDuration() throws Exception { kvPairs.clear(); String value = "P1Y1M1W1DT1H1M1S"; kvPairs.put("value", value); dataValue = (DataValue)PathValue.decodeValue("DvDuration", FieldUtil.flatten(FieldUtil.getAttributes(DvDateTimeVBean.generate())), kvPairs); assertEquals(((DvDuration) dataValue).getValue(), value); }
@Test public void testDvEHRURI() throws Exception { kvPairs.clear(); String value = "compositions/87284370-2D4B-4e3d-A3F3-F303D2F4F34B/data%5Bat0001%5D/items%5Bat0001%5D/test"; kvPairs.put("value", value); dataValue = (DataValue)PathValue.decodeValue("DvEHRURI", FieldUtil.flatten(FieldUtil.getAttributes(DvEHRURIVBean.generate())), kvPairs); assertEquals(((DvEHRURI)dataValue).getValue(), value); }
@Test public void testDvIdentifier() throws Exception { kvPairs.clear(); kvPairs.put("assigner", "dummyAssigner"); kvPairs.put("id", "123.456.789"); kvPairs.put("issuer", "dummyIssuer"); kvPairs.put("type", "dummyType"); dataValue = (DataValue)PathValue.decodeValue("DvIdentifier", FieldUtil.flatten(FieldUtil.getAttributes(DvIdentifierVBean.generate())), kvPairs); assertEquals(((DvIdentifier)dataValue).getAssigner(), kvPairs.get("assigner")); assertEquals(((DvIdentifier)dataValue).getId(), kvPairs.get("id")); }
@Test public void testDvMultimedia() throws Exception { kvPairs.clear(); kvPairs.put("integrityCheckAlgorithm", "openehr_integrity_check_algorithms::SHA-1"); kvPairs.put("mediaType", "IANA_media-types::text/plain"); kvPairs.put("compressionAlgorithm", "openehr_compression_algorithms::other"); kvPairs.put("uri", "file: dataValue = (DataValue)PathValue.decodeValue("DvMultimedia", FieldUtil.flatten(FieldUtil.getAttributes(DvMultimediaVBean.generate())), kvPairs); assertEquals(((DvMultimedia)dataValue).getIntegrityCheckAlgorithm().toString(), kvPairs.get("integrityCheckAlgorithm")); assertEquals(((DvMultimedia)dataValue).getMediaType().toString(), kvPairs.get("mediaType")); }
@Test public void testDvOrdinal() throws Exception { kvPairs.clear(); Integer value = 1; kvPairs.put("value", value+""); kvPairs.put("symbol", "openehr::111|symbol|"); dataValue = (DataValue)PathValue.decodeValue("DvOrdinal", FieldUtil.flatten(FieldUtil.getAttributes(DvOrdinalVBean.generate())), kvPairs); assertEquals(((DvOrdinal) dataValue).getValue(), 1); }
@Test public void testDvParsable() throws Exception { kvPairs.clear(); kvPairs.put("value", ""); kvPairs.put("formalism", "formalism"); dataValue = (DataValue)PathValue.decodeValue("DvParsable", FieldUtil.flatten(FieldUtil.getAttributes(DvParsableVBean.generate())), kvPairs); assertEquals(((DvParsable) dataValue).getValue(), ""); }
@Test public void testDvProportion() throws Exception { kvPairs.clear(); kvPairs.put("numerator", 4+""); kvPairs.put("denominator", 5+""); kvPairs.put("type", "FRACTION"); kvPairs.put("precision", 0+""); dataValue = (DataValue)PathValue.decodeValue("DvProportion", FieldUtil.flatten(FieldUtil.getAttributes(DvProportionVBean.generate())), kvPairs); assertEquals(((DvProportion) dataValue).getNumerator(), 4, 0); }
@Test public void testDvQuantity() throws Exception { kvPairs.clear(); kvPairs.put("magnitude", 4.5+""); kvPairs.put("units", "kg"); kvPairs.put("precision", 2+""); dataValue = (DataValue)PathValue.decodeValue("DvQuantity", FieldUtil.flatten(FieldUtil.getAttributes(DvQuantityVBean.generate())), kvPairs); assertEquals(((DvQuantity) dataValue).getMagnitude(), 4.5, 0); }
@Test public void testDvText() throws Exception { kvPairs.clear(); kvPairs.put("value", "zzz"); dataValue = (DataValue)PathValue.decodeValue("DvText", FieldUtil.flatten(FieldUtil.getAttributes(DvTextVBean.generate())), kvPairs); assertEquals(((DvText) dataValue).getValue(), "zzz"); }
@Test public void testDvURI() throws Exception { kvPairs.clear(); kvPairs.put("value", "file: dataValue = (DataValue)PathValue.decodeValue("DvURI", FieldUtil.flatten(FieldUtil.getAttributes(DvURIVBean.generate())), kvPairs); assertEquals(((DvURI) dataValue).getValue(), "file: }
@Test public void testHierObjectID() throws Exception { String test = "c2bd0416-91b5-11e5-8994-feff819cdc9f"; kvPairs.clear(); kvPairs.put("value", test); HierObjectID objectID = (HierObjectID)PathValue.decodeValue("HierObjectID", FieldUtil.flatten(FieldUtil.getAttributes(HierObjectIDVBean.generate())), kvPairs); assertEquals(objectID.toString(), test); }