Fixes issue 31519: Opens the API of SystemService
authorAugusto Mauch <augusto.mauch@openbravo.com>
Mon, 23 Nov 2015 10:20:38 +0100
changeset 28118 0eb0853e3d48
parent 28116 ef24b25b675a
child 28119 502f1cd5e0ce
Fixes issue 31519: Opens the API of SystemService

There three new public methods in the SystemService class:
- killConnectionsAndSafeMode
- resetSafeMode
- getModelFromDatabase

The first two where private methods that have been made public. The third one has been extracted from code that used to be within the disableConstraints method.
src/org/openbravo/service/system/SystemService.java
--- a/src/org/openbravo/service/system/SystemService.java	Thu Dec 10 07:11:19 2015 +0100
+++ b/src/org/openbravo/service/system/SystemService.java	Mon Nov 23 10:20:38 2015 +0100
@@ -386,7 +386,14 @@
     }
   }
 
-  private void resetSafeMode(Connection con) {
+  /**
+   * Callend after killConnectionsAndSafeMode, it disables the restriction to log only with the
+   * System Administrator role
+   * 
+   * @param con
+   *          Connection used to make the queries
+   */
+  public void resetSafeMode(Connection con) {
 
     try {
       PreparedStatement ps2 = null;
@@ -403,7 +410,14 @@
     }
   }
 
-  private void killConnectionsAndSafeMode(Connection con) {
+  /**
+   * Kills the active sessions for the current user and sets the System Admin role as the only one
+   * available
+   * 
+   * @param con
+   *          the Connection used to execute the queries
+   */
+  public void killConnectionsAndSafeMode(Connection con) {
     try {
       PreparedStatement updateSession = null;
       try {
@@ -452,10 +466,7 @@
 
   private void disableConstraints(Platform platform) throws FileNotFoundException, IOException {
     log4j.info("Disabling constraints...");
-    ExcludeFilter excludeFilter = DBSMOBUtil.getInstance().getExcludeFilter(
-        new File(OBPropertiesProvider.getInstance().getOpenbravoProperties()
-            .getProperty("source.path")));
-    Database xmlModel = platform.loadModelFromDatabase(excludeFilter);
+    Database xmlModel = getModelFromDatabase(platform);
     Connection con = null;
     try {
       con = platform.borrowConnection();
@@ -474,6 +485,17 @@
     }
   }
 
+  /**
+   * Given a org.apache.ddlutils.Platform, builds a org.apache.ddlutils.model.Database after
+   * applying the exclude filters
+   */
+  public Database getModelFromDatabase(Platform platform) {
+    ExcludeFilter excludeFilter = DBSMOBUtil.getInstance().getExcludeFilter(
+        new File(OBPropertiesProvider.getInstance().getOpenbravoProperties()
+            .getProperty("source.path")));
+    return platform.loadModelFromDatabase(excludeFilter);
+  }
+
   private void enableConstraints(Platform platform) {
     Properties obProp = OBPropertiesProvider.getInstance().getOpenbravoProperties();
     String obDir = obProp.getProperty("source.path");