From: Aron Roberts Date: Mon, 2 Aug 2010 19:58:24 +0000 (+0000) Subject: CSPACE-2558: sourceField values in authority reference lists from services once again... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=76bd5c63a5e764dd7599f83f54cddf132381b194;p=tmp%2Fjakarta-migration.git CSPACE-2558: sourceField values in authority reference lists from services once again are qualified by schema names; e.g. 'acquisitions_common:acquisitionSource'. This was a regression bug caught by Chris. Will create a JIRA to add client tests of sourceField values, to help avoid such issues in the future. --- diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java index b05c43d38..91aa42b44 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java @@ -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; } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java index ed91ad635..c70879123 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java @@ -315,7 +315,6 @@ public abstract class RemoteDocumentModelHandlerImpl DocumentWrapper docWrapper, List authRefFieldNames) throws PropertyException { - final String SCHEMA_FIELD_DELIMITER = ":"; AuthorityRefList authRefList = new AuthorityRefList(); List list = authRefList.getAuthorityRefItem(); String refName = ""; @@ -325,18 +324,8 @@ public abstract class RemoteDocumentModelHandlerImpl 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 } // 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 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)); } } }