details:   http://code.openbravo.com/erp/devel/pi/rev/92d129f93321
changeset: 3547:92d129f93321
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Tue Apr 07 22:35:32 2009 +0200
summary:   (no commit message)

diffstat:

 src/org/openbravo/base/model/NamingUtil.java                 |   1 +
 src/org/openbravo/dal/core/DalThreadHandler.java             |   3 -
 src/org/openbravo/dal/core/TriggerHandler.java               |   5 +-
 src/org/openbravo/dal/xml/EntityResolver.java                |  86 
++++++++++-------
 src/org/openbravo/dal/xml/EntityXMLConverter.java            |   5 +-
 src/org/openbravo/service/dataset/DataSetService.java        |  76 
++++++++------
 src/org/openbravo/service/db/ClientImportEntityResolver.java |   1 +
 src/org/openbravo/service/db/DataImportService.java          |   4 +-
 src/org/openbravo/service/rest/DalWebService.java            |   5 +-
 9 files changed, 109 insertions(+), 77 deletions(-)

diffs (truncated from 329 to 300 lines):

diff -r 1981bfff8d14 -r 92d129f93321 
src/org/openbravo/base/model/NamingUtil.java
--- a/src/org/openbravo/base/model/NamingUtil.java      Wed Apr 08 12:45:20 
2009 +0530
+++ b/src/org/openbravo/base/model/NamingUtil.java      Tue Apr 07 22:35:32 
2009 +0200
@@ -50,6 +50,7 @@
     reservedNames.put("transient", "trnsnt");
     reservedNames.put("case", "cse");
     reservedNames.put("char", "chr");
+    reservedNames.put("public", "pblic");
   }
 
   /**
diff -r 1981bfff8d14 -r 92d129f93321 
src/org/openbravo/dal/core/DalThreadHandler.java
--- a/src/org/openbravo/dal/core/DalThreadHandler.java  Wed Apr 08 12:45:20 
2009 +0530
+++ b/src/org/openbravo/dal/core/DalThreadHandler.java  Tue Apr 07 22:35:32 
2009 +0200
@@ -52,9 +52,6 @@
       }
     } finally {
       SessionHandler.deleteSessionHandler();
-      if (OBContext.getOBContext() != null) {
-        OBContext.getOBContext().setInAdministratorMode(false);
-      }
       OBContext.setOBContext((OBContext) null);
     }
   }
diff -r 1981bfff8d14 -r 92d129f93321 
src/org/openbravo/dal/core/TriggerHandler.java
--- a/src/org/openbravo/dal/core/TriggerHandler.java    Wed Apr 08 12:45:20 
2009 +0530
+++ b/src/org/openbravo/dal/core/TriggerHandler.java    Tue Apr 07 22:35:32 
2009 +0200
@@ -59,6 +59,7 @@
     log.debug("Disabling triggers");
     Check.isNull(sessionStatus.get(), "There is already a ADSessionStatus 
present in this thread, "
         + "call enable before calling disable again");
+    final boolean adminMode = OBContext.getOBContext().isInAdministratorMode();
     try {
       OBContext.getOBContext().setInAdministratorMode(true);
       final SessionStatus localSessionStatus = 
OBProvider.getInstance().get(SessionStatus.class);
@@ -70,7 +71,9 @@
       Check.isNotNull(localSessionStatus.getId(), "The id is not set after 
insert");
       sessionStatus.set(localSessionStatus);
     } finally {
-      OBContext.getOBContext().restorePreviousAdminMode();
+      if (!adminMode) {
+        OBContext.getOBContext().restorePreviousAdminMode();
+      }
     }
   }
 
diff -r 1981bfff8d14 -r 92d129f93321 
src/org/openbravo/dal/xml/EntityResolver.java
--- a/src/org/openbravo/dal/xml/EntityResolver.java     Wed Apr 08 12:45:20 
2009 +0530
+++ b/src/org/openbravo/dal/xml/EntityResolver.java     Tue Apr 07 22:35:32 
2009 +0200
@@ -163,45 +163,55 @@
         data.put(getKey(entityName, id), result);
       }
 
-      // TODO: add warning if the entity is created in a different
-      // client/organization than the inputted ones
-      // Set the client and organization on the most detailed level
-      // looking at the accesslevel of the entity
-      Client setClient;
-      Organization setOrg;
-      if (entity.getAccessLevel() == AccessLevel.SYSTEM) {
-        setClient = clientZero;
-        setOrg = organizationZero;
-      } else if (entity.getAccessLevel() == AccessLevel.SYSTEM_CLIENT) {
-        setClient = client;
-        setOrg = organizationZero;
-      } else if (entity.getAccessLevel() == AccessLevel.CLIENT) {
-        setClient = client;
-        setOrg = organizationZero;
-      } else if (entity.getAccessLevel() == AccessLevel.CLIENT_ORGANIZATION) {
-        setClient = client;
-        setOrg = organization;
-      } else if (entity.getAccessLevel() == AccessLevel.ORGANIZATION) {
-        // TODO: is this correct? That it is the same as the previous
-        // one?
-        setClient = client;
-        setOrg = organization;
-      } else if (entity.getAccessLevel() == AccessLevel.ALL) {
-        setClient = client;
-        setOrg = organization;
-      } else {
-        throw new EntityXMLException("Access level " + entity.getAccessLevel() 
+ " not supported");
-      }
-      if (entity.isClientEnabled()) {
-        result.setValue(PROPERTY_CLIENT, setClient);
-      }
-      if (entity.isOrganizationEnabled()) {
-        result.setValue(PROPERTY_ORGANIZATION, setOrg);
-      }
+      setClientOrganization(result);
     }
     return result;
   }
 
+  protected void setClientOrganization(BaseOBObject bob) {
+
+    setClientOrganizationZero();
+
+    final Entity entity = bob.getEntity();
+
+    // TODO: add warning if the entity is created in a different
+    // client/organization than the inputted ones
+    // Set the client and organization on the most detailed level
+    // looking at the accesslevel of the entity
+    Client setClient;
+    Organization setOrg;
+    if (entity.getAccessLevel() == AccessLevel.SYSTEM) {
+      setClient = clientZero;
+      setOrg = organizationZero;
+    } else if (entity.getAccessLevel() == AccessLevel.SYSTEM_CLIENT) {
+      setClient = client;
+      setOrg = organizationZero;
+    } else if (entity.getAccessLevel() == AccessLevel.CLIENT) {
+      setClient = client;
+      setOrg = organizationZero;
+    } else if (entity.getAccessLevel() == AccessLevel.CLIENT_ORGANIZATION) {
+      setClient = client;
+      setOrg = organization;
+    } else if (entity.getAccessLevel() == AccessLevel.ORGANIZATION) {
+      // TODO: is this correct? That it is the same as the previous
+      // one?
+      setClient = client;
+      setOrg = organization;
+    } else if (entity.getAccessLevel() == AccessLevel.ALL) {
+      setClient = client;
+      setOrg = organization;
+    } else {
+      throw new EntityXMLException("Access level " + entity.getAccessLevel() + 
" not supported");
+    }
+    if (entity.isClientEnabled()) {
+      bob.setValue(PROPERTY_CLIENT, setClient);
+    }
+    if (entity.isOrganizationEnabled()) {
+      bob.setValue(PROPERTY_ORGANIZATION, setOrg);
+    }
+
+  }
+
   // search on the basis of the access level of the entity
   protected BaseOBObject searchInstance(Entity entity, String id) {
     final AccessLevel al = entity.getAccessLevel();
@@ -297,6 +307,7 @@
   // and then re-imported that it occurs multiple times.
   private List<String> getId(String id, Entity entity, String orgId) {
     final String[] searchOrgIds = getOrgIds(orgId);
+    final boolean adminMode = OBContext.getOBContext().isInAdministratorMode();
     try {
       OBContext.getOBContext().setInAdministratorMode(true);
       final OBCriteria<ReferenceDataStore> rdlCriteria = 
OBDal.getInstance().createCriteria(
@@ -319,7 +330,10 @@
       }
       return result;
     } finally {
-      OBContext.getOBContext().restorePreviousAdminMode();
+      // only set back if the previous was false
+      if (!adminMode) {
+        OBContext.getOBContext().restorePreviousAdminMode();
+      }
     }
   }
 
diff -r 1981bfff8d14 -r 92d129f93321 
src/org/openbravo/dal/xml/EntityXMLConverter.java
--- a/src/org/openbravo/dal/xml/EntityXMLConverter.java Wed Apr 08 12:45:20 
2009 +0530
+++ b/src/org/openbravo/dal/xml/EntityXMLConverter.java Tue Apr 07 22:35:32 
2009 +0200
@@ -504,7 +504,10 @@
           .getCodeRevision()
           + "");
     } finally {
-      OBContext.getOBContext().setInAdministratorMode(adminMode);
+      // only set back if the previous was false
+      if (!adminMode) {
+        OBContext.getOBContext().setInAdministratorMode(adminMode);
+      }
     }
   }
 
diff -r 1981bfff8d14 -r 92d129f93321 
src/org/openbravo/service/dataset/DataSetService.java
--- a/src/org/openbravo/service/dataset/DataSetService.java     Wed Apr 08 
12:45:20 2009 +0530
+++ b/src/org/openbravo/service/dataset/DataSetService.java     Tue Apr 07 
22:35:32 2009 +0200
@@ -228,50 +228,58 @@
     // do the part which can be done as super user separately from the
     // actual read of the db
 
-    OBContext.getOBContext().setInAdministratorMode(true);
-    final String entityName = dataSetTable.getTable().getName();
-    final Entity entity = ModelProvider.getInstance().getEntity(entityName);
+    final boolean adminMode = OBContext.getOBContext().isInAdministratorMode();
+    try {
+      OBContext.getOBContext().setInAdministratorMode(true);
+      final String entityName = dataSetTable.getTable().getName();
+      final Entity entity = ModelProvider.getInstance().getEntity(entityName);
 
-    if (entity == null) {
-      log.error("Entity not found using table name " + entityName);
-      return new ArrayList<BaseOBObject>();
-    }
+      if (entity == null) {
+        log.error("Entity not found using table name " + entityName);
+        return new ArrayList<BaseOBObject>();
+      }
 
-    String whereClause = dataSetTable.getSQLWhereClause();
+      String whereClause = dataSetTable.getSQLWhereClause();
 
-    final Map<String, Object> existingParams = new HashMap<String, Object>();
-    if (whereClause != null) {
-      if (parameters != null) {
-        for (final String name : parameters.keySet()) {
-          if (whereClause.indexOf(":" + name) != -1) {
-            existingParams.put(name, parameters.get(name));
+      final Map<String, Object> existingParams = new HashMap<String, Object>();
+      if (whereClause != null) {
+        if (parameters != null) {
+          for (final String name : parameters.keySet()) {
+            if (whereClause.indexOf(":" + name) != -1) {
+              existingParams.put(name, parameters.get(name));
+            }
           }
         }
       }
-    }
 
-    if (moduleId != null && whereClause != null) {
-      while (whereClause.indexOf("@moduleid@") != -1) {
-        whereClause = whereClause.replace("@moduleid@", "'" + moduleId + "'");
+      if (moduleId != null && whereClause != null) {
+        while (whereClause.indexOf("@moduleid@") != -1) {
+          whereClause = whereClause.replace("@moduleid@", "'" + moduleId + 
"'");
+        }
+        if (whereClause.indexOf(":moduleid") != -1 && 
parameters.get("moduleid") == null) {
+          existingParams.put("moduleid", moduleId);
+        }
       }
-      if (whereClause.indexOf(":moduleid") != -1 && parameters.get("moduleid") 
== null) {
-        existingParams.put("moduleid", moduleId);
+
+      final OBQuery<BaseOBObject> oq = 
OBDal.getInstance().createQuery(entity.getName(),
+          whereClause);
+      oq.setFilterOnActive(false);
+      oq.setNamedParameters(existingParams);
+
+      if (OBContext.getOBContext().getRole().getId().equals("0")
+          && OBContext.getOBContext().getCurrentClient().getId().equals("0")) {
+        oq.setFilterOnReadableOrganization(false);
+        oq.setFilterOnReadableClients(false);
+      }
+
+      final List<?> list = oq.list();
+      Collections.sort(list, new BaseOBIDHexComparator());
+      return (List<BaseOBObject>) list;
+    } finally {
+      if (!adminMode) {
+        OBContext.getOBContext().restorePreviousAdminMode();
       }
     }
-
-    final OBQuery<BaseOBObject> oq = 
OBDal.getInstance().createQuery(entity.getName(), whereClause);
-    oq.setFilterOnActive(false);
-    oq.setNamedParameters(existingParams);
-
-    if (OBContext.getOBContext().getRole().getId().equals("0")
-        && OBContext.getOBContext().getCurrentClient().getId().equals("0")) {
-      oq.setFilterOnReadableOrganization(false);
-      oq.setFilterOnReadableClients(false);
-    }
-
-    final List<?> list = oq.list();
-    Collections.sort(list, new BaseOBIDHexComparator());
-    return (List<BaseOBObject>) list;
   }
 
   /**
diff -r 1981bfff8d14 -r 92d129f93321 
src/org/openbravo/service/db/ClientImportEntityResolver.java
--- a/src/org/openbravo/service/db/ClientImportEntityResolver.java      Wed Apr 
08 12:45:20 2009 +0530
+++ b/src/org/openbravo/service/db/ClientImportEntityResolver.java      Tue Apr 
07 22:35:32 2009 +0200
@@ -104,6 +104,7 @@
         // keep it here so it can be found later
         getData().put(getKey(entityName, id), result);
       }
+      setClientOrganization(result);
     }
     return result;
   }
diff -r 1981bfff8d14 -r 92d129f93321 
src/org/openbravo/service/db/DataImportService.java
--- a/src/org/openbravo/service/db/DataImportService.java       Wed Apr 08 
12:45:20 2009 +0530
+++ b/src/org/openbravo/service/db/DataImportService.java       Tue Apr 07 
22:35:32 2009 +0200
@@ -141,11 +141,11 @@
   public ImportResult importClientData(EntityXMLProcessor importProcessor, 
boolean importAuditInfo,
       Reader reader) {
     try {
+      OBContext.getOBContext().setInAdministratorMode(true);
 
       final ImportResult ir = new ImportResult();
 
       boolean rolledBack = false;
-      OBContext.getOBContext().setInAdministratorMode(true);
       try {
         // disable the triggers to prevent unexpected extra db actions
         // during import
@@ -279,6 +279,8 @@
       return ir;

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to