### Eclipse Workspace Patch 1.0
#P openmrs-sync
Index: src/api/org/openmrs/api/db/AdministrationDAO.java
===================================================================
--- src/api/org/openmrs/api/db/AdministrationDAO.java (revision 5975)
+++ src/api/org/openmrs/api/db/AdministrationDAO.java (working copy)
@@ -123,6 +123,11 @@
* @see org.openmrs.api.AdministrationService#getGlobalProperty(String)
*/
public String getGlobalProperty(String propertyName) throws DAOException;
+
+ /**
+ * @see org.openmrs.api.AdministrationService#getGlobalPropertyObject(java.lang.String)
+ */
+ public GlobalProperty getGlobalPropertyObject(String propertyName);
public GlobalProperty getGlobalPropertyByGuid(String guid) throws DAOException;
Index: src/api/org/openmrs/api/AdministrationService.java
===================================================================
--- src/api/org/openmrs/api/AdministrationService.java (revision 5975)
+++ src/api/org/openmrs/api/AdministrationService.java (working copy)
@@ -450,6 +450,15 @@
public String getGlobalProperty(String propertyName, String defaultValue) throws APIException;
/**
+ *
+ * Gets the global property that has the given propertyName
+ *
+ * @param propertyName property key to look for
+ * @return the global property that matches the given propertyName
+ */
+ public GlobalProperty getGlobalPropertyObject(String propertyName);
+
+ /**
* Get a list of all global properties in the system
*
* @return list of global properties
Index: src/api/org/openmrs/module/ModuleFactory.java
===================================================================
--- src/api/org/openmrs/module/ModuleFactory.java (revision 5975)
+++ src/api/org/openmrs/module/ModuleFactory.java (working copy)
@@ -574,7 +574,7 @@
String key = module.getModuleId() + ".database_version";
String select = "select property_value from global_property where property = '"
+ key + "'";
-
+
List> results = as.executeSQL(select, true);
boolean executeSQL = false;
@@ -590,9 +590,6 @@
executeSQL = true;
}
} else {
- String insert = "insert into global_property (property, property_value) values ('"
- + key + "', '0')";
- as.executeSQL(insert, false);
executeSQL = true;
}
@@ -605,12 +602,31 @@
if (sqlStatement.trim().length() > 0)
as.executeSQL(sqlStatement, false);
}
- String description = "DO NOT MODIFY. Current database version number for the "
- + module.getModuleId() + " module.";
- String update = "update global_property set property_value = '"
- + version + "', description = '" + description
- + "' where property = '" + key + "'";
- as.executeSQL(update, false);
+
+ try {
+ Context.addProxyPrivilege(OpenmrsConstants.PRIV_MANAGE_GLOBAL_PROPERTIES);
+
+ String description = "DO NOT MODIFY. Current database version number for the "
+ + module.getModuleId() + " module.";
+
+ GlobalProperty gp = as.getGlobalPropertyObject(key);
+
+ System.out.println("Global property key is " + key);
+
+ if(gp==null) {
+ gp = new GlobalProperty(key,version,description);
+ System.out.println("Global property not found!!");
+ } else {
+ gp.setDescription(description);
+ gp.setPropertyValue(version);
+ }
+
+ if(gp != null && ! (gp.getPropertyValue().equals(version)))
+ as.saveGlobalProperty(gp);
+ } finally {
+ Context.removeProxyPrivilege(OpenmrsConstants.PRIV_MANAGE_GLOBAL_PROPERTIES);
+ }
+
}
}
Index: src/api/org/openmrs/api/impl/AdministrationServiceImpl.java
===================================================================
--- src/api/org/openmrs/api/impl/AdministrationServiceImpl.java (revision 5975)
+++ src/api/org/openmrs/api/impl/AdministrationServiceImpl.java (working copy)
@@ -627,7 +627,7 @@
// This method should not have any authorization check
return dao.getGlobalProperty(propertyName);
}
-
+
/**
* @see org.openmrs.api.AdministrationService#getGlobalProperty(java.lang.String, java.lang.String)
*/
@@ -639,6 +639,14 @@
}
/**
+ *
+ * @see org.openmrs.api.AdministrationService#getGlobalPropertyObject(java.lang.String)
+ */
+ public GlobalProperty getGlobalPropertyObject(String propertyName) {
+ return dao.getGlobalPropertyObject(propertyName);
+ }
+
+ /**
* @see org.openmrs.api.AdministrationService#getGlobalProperties()
* @deprecated
*/
Index: src/api/org/openmrs/api/db/hibernate/HibernateAdministrationDAO.java
===================================================================
--- src/api/org/openmrs/api/db/hibernate/HibernateAdministrationDAO.java (revision 5975)
+++ src/api/org/openmrs/api/db/hibernate/HibernateAdministrationDAO.java (working copy)
@@ -254,6 +254,20 @@
return gp.getPropertyValue();
}
+
+ /**
+ *
+ * @see org.openmrs.api.db.AdministrationDAO#getGlobalPropertyObject(java.lang.String)
+ */
+ public GlobalProperty getGlobalPropertyObject(String propertyName) {
+ GlobalProperty gp = (GlobalProperty)sessionFactory.getCurrentSession().get(GlobalProperty.class, propertyName);
+
+ // if no gp exists, return a null value
+ if (gp == null)
+ return null;
+
+ return gp;
+ }
public GlobalProperty getGlobalPropertyByGuid(String guid) throws DAOException {
GlobalProperty gp = (GlobalProperty)sessionFactory.getCurrentSession().createQuery("from GlobalProperty t where t.guid = :guid").setString("guid", guid).uniqueResult();