use of org.openmrs.OpenmrsMetadata in project openmrs-core by openmrs.
the class CreateCoreUuids method getUUIDs.
// @Test
@SkipBaseSetup
public void getUUIDs() throws Exception {
Context.authenticate("admin", "test");
System.out.println("db: " + OpenmrsConstants.DATABASE_NAME);
Map<String, List<? extends OpenmrsMetadata>> coremetadatas = new LinkedHashMap<>();
coremetadatas.put("field_type", Context.getFormService().getAllFieldTypes(true));
coremetadatas.put("person_attribute_type", Context.getPersonService().getAllPersonAttributeTypes(true));
coremetadatas.put("encounter_type", Context.getEncounterService().getAllEncounterTypes(true));
coremetadatas.put("concept_datatype", Context.getConceptService().getAllConceptDatatypes(true));
coremetadatas.put("concept_class", Context.getConceptService().getAllConceptClasses(true));
coremetadatas.put("patient_identifier_type", Context.getPatientService().getAllPatientIdentifierTypes(true));
coremetadatas.put("location", Context.getLocationService().getAllLocations(true));
coremetadatas.put("hl7_source", Context.getHL7Service().getAllHL7Sources());
for (Map.Entry<String, List<? extends OpenmrsMetadata>> entry : coremetadatas.entrySet()) {
System.out.println("new table: " + entry.getKey());
for (OpenmrsMetadata obj : entry.getValue()) {
String output = "<update tableName=\"" + entry.getKey() + "\"><column name=\"uuid\" value=\"" + obj.getUuid() + "\"/><where>" + entry.getKey() + "_id" + "= '" + obj.getId() + "' and name = '" + obj.getName().replace("'", "\\'") + "'</where></update>";
System.out.println(output);
}
}
// /////////////////////////////////////
// exceptions:
//
// relationship types
System.out.println("Relationship type");
for (RelationshipType type : Context.getPersonService().getAllRelationshipTypes()) {
String output = "<update tableName=\"relationship_type\"><column name=\"uuid\" value=\"" + type.getUuid() + "\"/><where> relationship_type_id = '" + type.getRelationshipTypeId() + "' and a_is_to_b = '" + type.getaIsToB().replace("'", "\\'") + "' and b_is_to_a = '" + type.getbIsToA().replace("'", "\\'") + "'</where></update>";
System.out.println(output);
}
// roles:
System.out.println("Roles");
for (Role role : Context.getUserService().getAllRoles()) {
String output = "<update tableName=\"role\"><column name=\"uuid\" value=\"" + role.getUuid() + "\"/><where> role = '" + role.getRole().replace("'", "\\'") + "'</where></update>";
System.out.println(output);
}
// user:
System.out.println("Users");
for (User user : Context.getUserService().getAllUsers()) {
String output = "<update tableName=\"users\"><column name=\"uuid\" value=\"" + user.getUuid() + "\"/><where> user_id = '" + user.getUserId() + "' and system_id = '" + user.getSystemId().replace("'", "\\'") + "'</where></update>";
System.out.println(output);
}
}
use of org.openmrs.OpenmrsMetadata in project openmrs-core by openmrs.
the class BaseMetadataDatatypeTest method doGetTextSummary_shouldUseTheNameInSummaryInstance.
/**
* @see BaseMetadataDatatype#doGetTextSummary(org.openmrs.OpenmrsMetadata)
*/
@Test
public void doGetTextSummary_shouldUseTheNameInSummaryInstance() {
OpenmrsMetadata location = new Location();
String expectedSummary = "some summary";
location.setName(expectedSummary);
BaseMetadataDatatype datatype = new MockLocationDatatype();
CustomDatatype.Summary summary = datatype.doGetTextSummary(location);
Assert.assertEquals(expectedSummary, summary.getSummary());
Assert.assertEquals(true, summary.isComplete());
}
use of org.openmrs.OpenmrsMetadata in project openmrs-core by openmrs.
the class HibernateSerializedObjectDAO method saveObject.
/**
* @see SerializedObjectDAO#saveObject(OpenmrsObject, OpenmrsSerializer)
*/
@Override
public <T extends OpenmrsObject> T saveObject(T object, OpenmrsSerializer serializer) throws DAOException {
Class<? extends OpenmrsObject> baseType = getRegisteredTypeForObject(object);
if (baseType == null) {
throw new DAOException("SerializedObjectDAO does not support saving objects of type <" + object.getClass() + ">");
}
SerializedObject serializedObject = getSerializedObject(object.getId());
if (serializedObject == null) {
serializedObject = new SerializedObject();
}
if (serializer == null) {
serializer = getSerializer(serializedObject);
}
if (object instanceof Auditable) {
Auditable auditableObj = (Auditable) object;
if (auditableObj.getCreator() == null) {
auditableObj.setCreator(Context.getAuthenticatedUser());
}
serializedObject.setCreator(auditableObj.getCreator());
if (auditableObj.getDateCreated() == null) {
auditableObj.setDateCreated(new Date());
}
serializedObject.setDateCreated(auditableObj.getDateCreated());
serializedObject.setChangedBy(auditableObj.getChangedBy());
serializedObject.setDateChanged(auditableObj.getDateChanged());
}
String data;
try {
data = serializer.serialize(object);
} catch (SerializationException e) {
throw new DAOException("Unable to save object <" + object + "> because serialization failed.", e);
}
serializedObject.setUuid(object.getUuid());
serializedObject.setType(baseType.getName());
serializedObject.setSubtype(object.getClass().getName());
serializedObject.setSerializationClass(serializer.getClass());
serializedObject.setSerializedData(data);
if (object instanceof OpenmrsMetadata) {
OpenmrsMetadata metaObj = (OpenmrsMetadata) object;
serializedObject.setName(metaObj.getName());
serializedObject.setDescription(metaObj.getDescription());
serializedObject.setRetired(metaObj.getRetired());
serializedObject.setRetiredBy(metaObj.getRetiredBy());
serializedObject.setDateRetired(metaObj.getDateRetired());
serializedObject.setRetireReason(metaObj.getRetireReason());
}
if (object instanceof OpenmrsData) {
OpenmrsData dataObj = (OpenmrsData) object;
serializedObject.setRetired(dataObj.getVoided());
serializedObject.setRetiredBy(dataObj.getVoidedBy());
serializedObject.setDateRetired(dataObj.getDateVoided());
serializedObject.setRetireReason(dataObj.getVoidReason());
}
sessionFactory.getCurrentSession().saveOrUpdate(serializedObject);
object.setId(serializedObject.getId());
return object;
}
Aggregations