/** * Private method for retrieving the Serializer that should be used for the passed * SerializedObject, defaulting to the default system serializer if none is explicitly set on * the object */ private OpenmrsSerializer getSerializer(SerializedObject o) { if (o != null && o.getSerializationClass() != null) { return Context.getSerializationService().getSerializer(o.getSerializationClass()); } return Context.getSerializationService().getDefaultSerializer(); }
private void setAddressTemplate(String xml) { AddressTemplate addressTemplate; try { addressTemplate = Context.getSerializationService().getDefaultSerializer().deserialize(xml, AddressTemplate.class); } catch (SerializationException e) { log.error("Error in deserializing address template", e); addressTemplate = new AddressTemplate("Error while deserializing address layout template."); } List<AddressTemplate> list = new ArrayList<>(); list.add(addressTemplate); setAddressTemplate(list); }
/** * Deserializes a simple String-based configuration from the serialized form used by * {@link #serializeSimpleConfiguration(Map)} * Utility method for property-style configuration implementations. * * @param serializedConfig * @return deserialized configuration * @should deserialize a configuration serialized by the corresponding serialize method */ @SuppressWarnings("unchecked") public static Map<String, String> deserializeSimpleConfiguration(String serializedConfig) { if (StringUtils.isBlank(serializedConfig)) { return Collections.emptyMap(); } try { return Context.getSerializationService().getDefaultSerializer().deserialize(serializedConfig, Map.class); } catch (SerializationException ex) { throw new APIException(ex); } }
/** * Converts a simple String-based configuration to a serialized form. * Utility method for property-style configuration implementations. * * @param simpleConfig * @return serialized form */ public static String serializeSimpleConfiguration(Map<String, String> simpleConfig) { if (simpleConfig == null || simpleConfig.size() == 0) { return ""; } try { return Context.getSerializationService().getDefaultSerializer().serialize(simpleConfig); } catch (SerializationException ex) { throw new APIException(ex); } }
/** * @see org.openmrs.api.AdministrationService#getImplementationId() */ @Override @Transactional(readOnly = true) public ImplementationId getImplementationId() throws APIException { String property = Context.getAdministrationService().getGlobalProperty( OpenmrsConstants.GLOBAL_PROPERTY_IMPLEMENTATION_ID); // fail early if no gp has been defined yet if (property == null) { return null; } try { return Context.getSerializationService().getDefaultSerializer().deserialize(property, ImplementationId.class); } catch (Exception e) { log.debug("Error while getting implementation id", e); } return null; }
/** * Deserializes a <code>PersonMErgeLog</code> object * * @param personMergeLog the <code> PersonMergeLog</code> object to deserialize * @throws SerializationException */ private void deserialize(PersonMergeLog personMergeLog) throws SerializationException { PersonMergeLogData data = Context.getSerializationService().getDefaultSerializer() .deserialize(personMergeLog.getSerializedMergedData(), PersonMergeLogData.class); personMergeLog.setPersonMergeLogData(data); }
/** * @see org.openmrs.api.PersonService#savePersonMergeLog(PersonMergeLog) */ @Override public PersonMergeLog savePersonMergeLog(PersonMergeLog personMergeLog) throws SerializationException, APIException { //verify required fields if (Context.getSerializationService().getDefaultSerializer() == null) { throw new APIException("serializer.default.not.found", (Object[]) null); } log.debug("Auditing merging of non-preferred person " + personMergeLog.getLoser().getUuid() + " with preferred person " + personMergeLog.getWinner().getId()); //populate the mergedData XML from the PersonMergeLogData object String serialized = Context.getSerializationService().getDefaultSerializer() .serialize(personMergeLog.getPersonMergeLogData()); personMergeLog.setSerializedMergedData(serialized); log.debug(serialized); //save the bean to the database return dao.savePersonMergeLog(personMergeLog); }
/** * Run this before each unit test in this class. The "@Before" method in * {@link BaseContextSensitiveTest} is run right before this method. * * @throws Exception */ @Before public void runBeforeEachTest() { Assert.assertNotNull(Context.getSerializationService().getDefaultSerializer()); executeDataSet("org/openmrs/api/db/include/SerializedObjectDAOTest-initialData.xml"); if (dao == null) { dao = (SerializedObjectDAO) applicationContext.getBean("serializedObjectDAO"); dao.registerSupportedType(Program.class); } }
AddressTemplate addressTemplate = Context.getSerializationService().getDefaultSerializer().deserialize(xml, AddressTemplate.class); requiredElements = addressTemplate.getRequiredElements();
String value = Context.getSerializationService().getDefaultSerializer().serialize(implementationId); Context.getAdministrationService().saveGlobalProperty( new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_IMPLEMENTATION_ID, value));
private static SerializableFormObject deserializeXmlString(String xml) throws SerializationException{ OpenmrsSerializer serializer = Context.getSerializationService().getSerializer(SimpleXStreamSerializer.class); return serializer.deserialize(xml, SerializableFormObject.class); } }
/** * * @param directoryPath * @throws Exception */ public void serializeToXml(String directoryPath) throws Exception { String filename; if(directoryPath.endsWith(File.separator)) { filename = directoryPath.concat(getFileName()); } else { filename = directoryPath.concat(File.separator + getFileName()); } //Use OpenMRS simpleXStreamSerializer OpenmrsSerializer serializer = Context.getSerializationService().getSerializer(SimpleXStreamSerializer.class); String xmlEquivalent = serializer.serialize(this); BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter(filename+".xml")); bw.write(xmlEquivalent); }finally { if(bw != null) bw.close(); } } /**