]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-2558: sourceField values in authority reference lists from services once again...
authorAron Roberts <aron@socrates.berkeley.edu>
Mon, 2 Aug 2010 19:58:24 +0000 (19:58 +0000)
committerAron Roberts <aron@socrates.berkeley.edu>
Mon, 2 Aug 2010 19:58:24 +0000 (19:58 +0000)
services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java

index b05c43d38aac3638c01e751960360e717a838e3e..91aa42b445aab5a434c70023a3a410380b77063e 100644 (file)
@@ -88,8 +88,12 @@ public class DocumentUtils {
     private static final Logger logger =
         LoggerFactory.getLogger(DocumentUtils.class);
 
-    /** The NAM e_ valu e_ separator. */
+    /** The name value separator. */
     private static String NAME_VALUE_SEPARATOR = "|";
+
+    // The delimiter in a schema-qualified field name,
+    // between its schema name and field name components.
+    private static String SCHEMA_FIELD_DELIMITER = ":";
     
     /** The XML elements with this suffix will indicate. */
     private static String STRUCTURED_TYPE_SUFFIX = "List";
@@ -473,7 +477,7 @@ public class DocumentUtils {
         root.setAttribute("xmlns:" + ns, xc.getNamespaceURI());
         document.appendChild(root);
 
-        Schema schema = getSchema(partMeta.getLabel());
+        Schema schema = getSchemaFromName(partMeta.getLabel());
         
         buildDocument(document, root, objectProps, schema);
         
@@ -556,9 +560,53 @@ public class DocumentUtils {
        }
     }
 
-    public static Schema getSchema(String label) {
+    /*
+     * Returns a schema, given the name of a schema.
+     *
+     * @param schemaName  a schema name.
+     * @return  a schema.
+     */
+    public static Schema getSchemaFromName(String schemaName) {
         SchemaManager schemaManager = Framework.getLocalService(SchemaManager.class);
-        return schemaManager.getSchema(label);
+        return schemaManager.getSchema(schemaName);
+    }
+
+    /*
+     * Returns the schema part of a presumably schema-qualified field name.
+     *
+     * If the schema part is null or empty, returns the supplied field name.
+     *
+     * @param schemaQualifiedFieldName  a schema-qualified field name.
+     * @return  the schema part of the field name.
+     */
+    public static String getSchemaNamePart(String schemaQualifiedFieldName) {
+        if (schemaQualifiedFieldName == null || schemaQualifiedFieldName.trim().isEmpty()) {
+            return schemaQualifiedFieldName;
+        }
+        if (schemaQualifiedFieldName.indexOf(SCHEMA_FIELD_DELIMITER) > 0) {
+            String[] schemaQualifiedFieldNameParts =
+                    schemaQualifiedFieldName.split(SCHEMA_FIELD_DELIMITER);
+            String schemaName = schemaQualifiedFieldNameParts[0];
+            return schemaName;
+        } else {
+            return schemaQualifiedFieldName;
+        }
+    }
+
+    /*
+     * Returns a schema-qualified field name, given a schema name and field name.
+     *
+     * If the schema name is null or empty, returns the supplied field name.
+     *
+     * @param schemaName  a schema name.
+     * @param fieldName  a field name.
+     * @return  a schema-qualified field name.
+     */
+    public static String appendSchemaName(String schemaName, String fieldName) {
+        if (schemaName == null || schemaName.trim().isEmpty()) {
+            return fieldName;
+        }
+        return schemaName + SCHEMA_FIELD_DELIMITER + fieldName;
     }
 
 
index ed91ad635dc37ab453ec71f75679dd36783aba5e..c708791235e6f219e4c025e8417b73e0cbd545a3 100644 (file)
@@ -315,7 +315,6 @@ public abstract class RemoteDocumentModelHandlerImpl<T, TL>
             DocumentWrapper<DocumentModel> docWrapper,
             List<String> authRefFieldNames) throws PropertyException {
 
-        final String SCHEMA_FIELD_DELIMITER = ":";
         AuthorityRefList authRefList = new AuthorityRefList();
         List<AuthorityRefList.AuthorityRefItem> list = authRefList.getAuthorityRefItem();
         String refName = "";
@@ -325,18 +324,8 @@ public abstract class RemoteDocumentModelHandlerImpl<T, TL>
 
             for (String authRefFieldName : authRefFieldNames) {
 
-                String schemaName = "";
-                // FIXME: Replacing the following by an existing utility
-                // method or, if not already present, create a new utility
-                // method for this task in the common package.
-                if (authRefFieldName.indexOf(SCHEMA_FIELD_DELIMITER) > 0) {
-                    String[] authRefFieldNameParts =
-                            authRefFieldName.split(SCHEMA_FIELD_DELIMITER);
-                    schemaName = authRefFieldNameParts[0];
-                    authRefFieldName = authRefFieldNameParts[1];
-                }
-
-                Schema schema = DocumentUtils.getSchema(schemaName);
+                String schemaName = DocumentUtils.getSchemaNamePart(authRefFieldName);
+                Schema schema = DocumentUtils.getSchemaFromName(schemaName);
                 Field field = schema.getField(authRefFieldName);
                 Type type = field.getType();
 
@@ -350,9 +339,9 @@ public abstract class RemoteDocumentModelHandlerImpl<T, TL>
                     }
                 // FIXME: The following assumes a very simple structure
                 // for repeatable single scalar fields: a parent (continer)
-                // element, containing 0-n child elements, each of the same
-                // name and type, with values capable of being meaningfully
-                // cast to String.
+                // element, containing 0-n child elements, each of them
+                // of identical  name and type, with values capable of being
+                // meaningfully cast to String.
                 //
                 // Past release 1.0a, repeatability may consist
                 // of arbitrary nesting and complexity, rather than
@@ -372,7 +361,9 @@ public abstract class RemoteDocumentModelHandlerImpl<T, TL>
                         if (obj != null) {
                             refName = (String) obj;
                             if (refName != null || ! refName.trim().isEmpty()) {
-                                list.add(authorityRefListItem(childAuthRefFieldName, refName));
+                                String schemaQualifiedChildFieldName =
+                                    DocumentUtils.appendSchemaName(schemaName, childAuthRefFieldName);
+                                list.add(authorityRefListItem(schemaQualifiedChildFieldName, refName));
                             }
                         }
                     }