From c7a96e1c309d0bf9851b68843eb8bfa888445183 Mon Sep 17 00:00:00 2001 From: Patrick Schmitz Date: Tue, 24 Aug 2010 00:17:19 +0000 Subject: [PATCH] CSPACE-2660. Added first responsibleDepartment (from list) and the objectName field from the first objectName repeating structure, to the summary list schema. --- .../CollectionObjectListItemJAXBSchema.java | 3 ++ .../resources/collectionobjects_common.xsd | 4 ++ .../CollectionObjectDocumentModelHandler.java | 35 ++++++++++++---- .../common/document/DocumentUtils.java | 40 +++++++++++++++++++ 4 files changed, 75 insertions(+), 7 deletions(-) diff --git a/services/collectionobject/jaxb/src/main/java/org/collectionspace/services/CollectionObjectListItemJAXBSchema.java b/services/collectionobject/jaxb/src/main/java/org/collectionspace/services/CollectionObjectListItemJAXBSchema.java index 09b044133..a098b525c 100644 --- a/services/collectionobject/jaxb/src/main/java/org/collectionspace/services/CollectionObjectListItemJAXBSchema.java +++ b/services/collectionobject/jaxb/src/main/java/org/collectionspace/services/CollectionObjectListItemJAXBSchema.java @@ -2,7 +2,10 @@ package org.collectionspace.services; public interface CollectionObjectListItemJAXBSchema { final static String OBJECT_NUMBER = "objectNumber"; + final static String OBJECT_NAME_LIST = "objectNameList"; + final static String OBJECT_NAME = "objectName"; final static String TITLE = "title"; + final static String RESPONSIBLE_DEPARTMENTS = "responsibleDepartments"; final static String CSID = "csid"; final static String URI = "url"; } diff --git a/services/collectionobject/jaxb/src/main/resources/collectionobjects_common.xsd b/services/collectionobject/jaxb/src/main/resources/collectionobjects_common.xsd index 1be4712f5..90d401710 100644 --- a/services/collectionobject/jaxb/src/main/resources/collectionobjects_common.xsd +++ b/services/collectionobject/jaxb/src/main/resources/collectionobjects_common.xsd @@ -516,8 +516,12 @@ + + diff --git a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java index 1f763a4bd..cf4559f30 100644 --- a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java +++ b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java @@ -23,6 +23,7 @@ */ package org.collectionspace.services.collectionobject.nuxeo; +import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -32,11 +33,13 @@ import org.collectionspace.services.CollectionObjectListItemJAXBSchema; import org.collectionspace.services.collectionobject.CollectionobjectsCommon; import org.collectionspace.services.collectionobject.CollectionobjectsCommonList; import org.collectionspace.services.collectionobject.CollectionobjectsCommonList.CollectionObjectListItem; +import org.collectionspace.services.common.document.DocumentUtils; import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.DocumentModelList; +import org.nuxeo.ecm.core.schema.types.ComplexType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -123,16 +126,34 @@ public class CollectionObjectDocumentModelHandler wrapDoc); List list = coList.getCollectionObjectListItem(); Iterator iter = wrapDoc.getWrappedObject().iterator(); + String label = getServiceContext().getCommonPartLabel(); while(iter.hasNext()){ DocumentModel docModel = iter.next(); CollectionObjectListItem coListItem = new CollectionObjectListItem(); - coListItem.setObjectNumber((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), - CollectionObjectListItemJAXBSchema.OBJECT_NUMBER)); - coListItem.setTitle((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), - CollectionObjectListItemJAXBSchema.TITLE)); - String id = NuxeoUtils.extractId(docModel.getPathAsString()); - coListItem.setUri(getServiceContextPath() + id); - coListItem.setCsid(id); + try { + coListItem.setObjectNumber((String) docModel.getProperty(label, + CollectionObjectListItemJAXBSchema.OBJECT_NUMBER)); + List names = (List) docModel.getProperty(label, + CollectionObjectListItemJAXBSchema.OBJECT_NAME_LIST); + if(names!=null && !names.isEmpty()) { + HashMap firstNameInfo = (HashMap)names.get(0); + coListItem.setObjectName((String)firstNameInfo.get( + CollectionObjectListItemJAXBSchema.OBJECT_NAME) ); + } + coListItem.setTitle((String) docModel.getProperty(label, + CollectionObjectListItemJAXBSchema.TITLE)); + Object respDepts = docModel.getProperty(label, + CollectionObjectListItemJAXBSchema.RESPONSIBLE_DEPARTMENTS); + coListItem.setResponsibleDepartment(DocumentUtils.getFirstString(respDepts)); + + String id = NuxeoUtils.extractId(docModel.getPathAsString()); + coListItem.setUri(getServiceContextPath() + id); + coListItem.setCsid(id); + } catch (ClassCastException cce) { + throw new RuntimeException("Unexpected schema structure encountered", cce); + } catch (Exception e) { + throw new RuntimeException("Problem encountered retrieving values", e); + } list.add(coListItem); } 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 d4334cc34..7d288ecf3 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 @@ -972,6 +972,46 @@ public class DocumentUtils { return nv; } */ + + public static String getFirstString(Object list) { + if (list==null) { + return null; + } + if (list instanceof List) { + return ((List)list).size()==0?null:(String)((List)list).get(0); + } + Class arrType = list.getClass().getComponentType(); + if ((arrType != null) && arrType.isPrimitive()) { + if (arrType == Integer.TYPE) { + int[] ar = (int[]) list; + return ar.length==0?null:String.valueOf(ar[0]); + } else if (arrType == Long.TYPE) { + long[] ar = (long[]) list; + return ar.length==0?null:String.valueOf(ar[0]); + } else if (arrType == Double.TYPE) { + double[] ar = (double[]) list; + return ar.length==0?null:String.valueOf(ar[0]); + } else if (arrType == Float.TYPE) { + float[] ar = (float[]) list; + return ar.length==0?null:String.valueOf(ar[0]); + } else if (arrType == Character.TYPE) { + char[] ar = (char[]) list; + return ar.length==0?null:String.valueOf(ar[0]); + } else if (arrType == Byte.TYPE) { + byte[] ar = (byte[]) list; + return ar.length==0?null:String.valueOf(ar[0]); + } else if (arrType == Short.TYPE) { + short[] ar = (short[]) list; + return ar.length==0?null:String.valueOf(ar[0]); + } + throw new IllegalArgumentException( + "Primitive list of unsupported type: " + + list); + } + throw new IllegalArgumentException( + "A value of list type is neither list neither array: " + + list); + } /** * writeDocument streams out given document to given output stream -- 2.47.3