]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-4074: Get on /accounts/0/accountperms resource now returns tentant ID in payload.
authorRichard Millet <richard.millet@berkeley.edu>
Sun, 12 Jun 2011 03:08:58 +0000 (03:08 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Sun, 12 Jun 2011 03:08:58 +0000 (03:08 +0000)
services/authorization/jaxb/src/main/resources/authorization_common.xsd
services/common-api/src/main/java/org/collectionspace/services/common/api/FileTools.java
services/common/src/main/java/org/collectionspace/services/common/query/QueryContext.java
services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageUtils.java
services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java

index 457c6fc9db51485186c3519cadee41ce3aa3d99a..906f27726f0070106807e24c6111532b3d345a56 100644 (file)
@@ -52,6 +52,7 @@
             <xs:element name="accountId" type="xs:string" minOccurs="1" maxOccurs="1"/>
             <xs:element name="screenName" type="xs:string" minOccurs="1" maxOccurs="1"/>
             <xs:element name="userId" type="xs:string" minOccurs="1" maxOccurs="1"/>
+            <xs:element name="tenantId" type="xs:string" minOccurs="1" maxOccurs="1"/>
         </xs:sequence>
     </xs:complexType>
 
index d1622ef1676ab6543a5548d896bea91ffa9e0df2..fcd32e12af5ebb30f813c547ba9b61d655c4bb17 100755 (executable)
@@ -40,6 +40,41 @@ import java.util.regex.Matcher;
  */\r
 public class FileTools {\r
 \r
+       public static String convertStreamToString(InputStream is) {\r
+               /*\r
+                * To convert the InputStream to String we use the\r
+                * Reader.read(char[] buffer) method. We iterate until the\r
+                * Reader return -1 which means there's no more data to\r
+                * read. We use the StringWriter class to produce the string.\r
+                */\r
+               if (is != null) {\r
+                       Writer writer = new StringWriter();\r
+\r
+                       char[] buffer = new char[1024];\r
+                       try {\r
+                               Reader reader = new BufferedReader(\r
+                                               new InputStreamReader(is, "UTF-8"));\r
+                               int n;\r
+                               while ((n = reader.read(buffer)) != -1) {\r
+                                       writer.write(buffer, 0, n);\r
+                               }\r
+                       } catch (IOException e) {\r
+                               // TODO Auto-generated catch block\r
+                               e.printStackTrace();\r
+                       } finally {\r
+                               try {\r
+                                       is.close();\r
+                               } catch (IOException e) {\r
+                                       // TODO Auto-generated catch block\r
+                                       e.printStackTrace();\r
+                               }\r
+                       }\r
+                       return writer.toString();\r
+               } else {       \r
+                       return "";\r
+               }\r
+       }\r
+       \r
     public static void forceParentDirectories(String filename) throws IOException {\r
         File theFile = new File(filename);\r
         String parent = theFile.getParent();\r
index c7b1ba101ba53aa6b491c59e2327dc160809724a..1ba06a4f1cede8820ac70e20bfc35ae6367ca515 100644 (file)
@@ -30,6 +30,12 @@ public class QueryContext {
     /** The tenant id. */\r
     String tenantId;\r
 \r
+    static public final String getTenantQualifiedDoctype(QueryContext queryContext, String docType) {\r
+//     return queryContext.getTenantId() + "_" + docType;\r
+       return docType; //FIXME: Need to use the line above to get a qualified doctype name \r
+\r
+    }\r
+    \r
     /**\r
      * Instantiates a new query context.\r
      *\r
@@ -133,6 +139,10 @@ public class QueryContext {
     public String getDocType() {\r
        return this.docType;\r
     }\r
+    \r
+    public final String getTenantQualifiedDoctype() {\r
+       return QueryContext.getTenantQualifiedDoctype(this, docType);\r
+    }    \r
 \r
     /**\r
      * Gets the doc type.\r
index 4323b6ac1554ad08c7c9ed4fee1e66518e275cce..468369f63f3dbe948cf8bfe48027687df173bd45 100644 (file)
@@ -268,7 +268,12 @@ public class JpaStorageUtils {
                 releaseEntityManagerFactory(emf);
             }
         }
-        
+        /*
+         * Add the currentTenantId to the payload so the client knows the current
+         * tenancy.
+         */
+        AccountValue av = result.getAccounts().get(0);
+        av.setTenantId(AuthN.get().getCurrentTenantId());
         return result;
     }
 
index fe6789b975e5be9ff1f95e013bad4103803d1145..03bc26d63bcea1d211c78c8073c9f77ec700e8ba 100644 (file)
@@ -351,12 +351,12 @@ public class NuxeoUtils {
      */
     static public final String buildNXQLQuery(QueryContext queryContext) throws Exception {
         StringBuilder query = new StringBuilder("SELECT * FROM ");
-        query.append(queryContext.getDocType());
+        query.append(queryContext.getTenantQualifiedDoctype()); // Nuxeo doctype must be tenant qualified.
         appendNXQLWhere(query, queryContext);
         appendNXQLOrderBy(query, queryContext);
         return query.toString();
     }
-
+    
     /**
      * Builds an NXQL SELECT query across multiple document types.
      *
@@ -365,7 +365,7 @@ public class NuxeoUtils {
      * @return an NXQL query
      */
     static public final String buildNXQLQuery(List<String> docTypes, QueryContext queryContext) {
-        StringBuilder query = new StringBuilder("SELECT * FROM ");
+        StringBuilder query = new StringBuilder("SELECT * FROM "); 
         boolean fFirst = true;
         for (String docType : docTypes) {
             if (fFirst) {
@@ -373,7 +373,8 @@ public class NuxeoUtils {
             } else {
                 query.append(",");
             }
-            query.append(docType);
+            String tqDocType = QueryContext.getTenantQualifiedDoctype(queryContext, docType);
+            query.append(tqDocType); // Nuxeo doctype must be tenant qualified.
         }
         appendNXQLWhere(query, queryContext);
         // FIXME add 'order by' clause here, if appropriate