package org.collectionspace.services.common.vocabulary.nuxeo;
import org.collectionspace.services.client.AuthorityClient;
+import org.collectionspace.services.client.IQueryManager;
import org.collectionspace.services.client.PayloadInputPart;
import org.collectionspace.services.client.PayloadOutputPart;
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
import org.collectionspace.services.client.RelationClient;
import org.collectionspace.services.common.ResourceBase;
-import org.collectionspace.services.common.ServiceMessages;
import org.collectionspace.services.common.api.CommonAPI;
import org.collectionspace.services.common.api.RefName;
import org.collectionspace.services.common.api.Tools;
import org.collectionspace.services.common.document.DocumentException;
import org.collectionspace.services.common.document.DocumentFilter;
import org.collectionspace.services.common.document.DocumentWrapper;
-import org.collectionspace.services.common.document.DocumentWrapperImpl;
import org.collectionspace.services.common.relation.IRelationsManager;
import org.collectionspace.services.common.repository.RepositoryClient;
-import org.collectionspace.services.common.repository.RepositoryClientFactory;
import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema;
import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
import org.collectionspace.services.config.service.ListResultField;
import org.collectionspace.services.config.service.ObjectPartType;
+import org.collectionspace.services.jaxb.AbstractCommonList;
+import org.collectionspace.services.nuxeo.client.java.CommonList; //FIXME: REM - 5/15/2012 - CommonList should be moved out of this package and into a more "common" package
import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;
-import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl;
import org.collectionspace.services.nuxeo.util.NuxeoUtils;
import org.collectionspace.services.relation.RelationResource;
import org.collectionspace.services.relation.RelationsDocListItem;
import org.collectionspace.services.relation.RelationshipType;
import org.collectionspace.services.vocabulary.VocabularyItemJAXBSchema;
+
import org.nuxeo.ecm.core.api.ClientException;
import org.nuxeo.ecm.core.api.DocumentModel;
+import org.nuxeo.ecm.core.api.DocumentModelList;
import org.nuxeo.ecm.core.api.model.PropertyException;
-import org.nuxeo.ecm.core.api.model.PropertyNotFoundException;
import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
-import org.nuxeo.runtime.transaction.TransactionHelper;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
+
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
//import org.collectionspace.services.common.authority.AuthorityItemRelations;
/**
return result;
}
+ private boolean isTermDisplayName(String elName) {
+ return AuthorityItemJAXBSchema.TERM_DISPLAY_NAME.equals(elName) || VocabularyItemJAXBSchema.DISPLAY_NAME.equals(elName);
+ }
+
@Override
public List<ListResultField> getListItemsArray() throws DocumentException {
List<ListResultField> list = super.getListItemsArray();
for (int i = 0; i < nFields; i++) {
ListResultField field = list.get(i);
String elName = field.getElement();
- if (AuthorityItemJAXBSchema.TERM_DISPLAY_NAME.equals(elName) || VocabularyItemJAXBSchema.DISPLAY_NAME.equals(elName)) {
+ if (isTermDisplayName(elName) == true) {
hasDisplayName = true;
} else if (AuthorityItemJAXBSchema.SHORT_IDENTIFIER.equals(elName)) {
hasShortId = true;
field = getListResultsTermStatusField();
list.add(field);
}
-
+
return list;
}
-
-
+
/* (non-Javadoc)
* @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
*/
}
-
-
/* (non-Javadoc)
* @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#extractPart(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, org.collectionspace.services.common.service.ObjectPartType)
*/
}
}
+ @Override
+ protected Object getXPathValue(DocumentModel docModel, // REM - CSPACE-5133
+ String schema, ListResultField field) {
+ Object result = null;
+
+ result = NuxeoUtils.getXPathValue(docModel, schema, field.getXpath());
+ String elName = field.getElement();
+ if (isTermDisplayName(elName) == true) {
+ MultivaluedMap<String, String> queryParams = this.getServiceContext().getQueryParams();
+ String partialTerm = queryParams != null ? queryParams.getFirst(IQueryManager.SEARCH_TYPE_PARTIALTERM) : null;
+ if (partialTerm != null && partialTerm.trim().isEmpty() == false) {
+ List<String> strList = new ArrayList<String>();
+ strList.add((String)result);
+ strList.add("Tiny");
+ strList.add("Tucker");
+ strList.add("Tim");
+ result = strList;
+ }
+ }
+
+ return result;
+ }
+
@Override
public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
*/
public TL extractCommonPartList(DocumentWrapper<WTL> docWrap) throws Exception;
+
/**
* Extract paging info.
*
return uri + result + "/" + BlobInput.URI_CONTENT_PATH;\r
}\r
\r
- static private HashMap<String, String> createBlobListItem(Blob blob,\r
+ static private HashMap<String, Object> createBlobListItem(Blob blob,\r
String uri) {\r
- HashMap<String, String> item = new HashMap<String, String>();\r
+ HashMap<String, Object> item = new HashMap<String, Object>();\r
\r
String value = blob.getEncoding();\r
if (value != null && !value.trim().isEmpty()) {\r
.getAdapter(BlobHolder.class);\r
List<Blob> docBlobs = docBlobHolder.getBlobs();\r
// List<BlobListItem> blobListItems = result.getBlobListItem();\r
- HashMap<String, String> item = null;\r
+ HashMap<String, Object> item = null;\r
for (Blob blob : docBlobs) {\r
item = createBlobListItem(blob, uri);\r
commonList.addItem(item);\r
import org.jvnet.jaxb2_commons.lang.ToString;\r
import javax.xml.parsers.DocumentBuilder;\r
import javax.xml.parsers.DocumentBuilderFactory;\r
+\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
import org.w3c.dom.Document;\r
import org.w3c.dom.Element;\r
\r
import javax.xml.bind.annotation.XmlType;\r
import javax.xml.bind.annotation.XmlSeeAlso;\r
\r
-//import org.slf4j.Logger;\r
-//import org.slf4j.LoggerFactory;\r
+import org.slf4j.LoggerFactory;\r
\r
/**\r
* This class allows us to generically represent and marshall a set of list\r
public class CommonList extends AbstractCommonList {\r
\r
/** The logger. */\r
- //private final Logger logger = LoggerFactory.getLogger(this.getClass());\r
+ private final Logger logger = LoggerFactory.getLogger(CommonList.class);\r
@XmlTransient\r
private DocumentBuilderFactory factory;\r
@XmlTransient\r
}\r
return implodedString;\r
}\r
+ \r
+ private void addItem(List<Element> anyList, String key, Object value) {\r
+ if (value != null ) {\r
+ Element el = doc.createElement(key);\r
+ if (value instanceof String) {\r
+ el.setTextContent((String)value);\r
+ anyList.add(el);\r
+ } else if (value instanceof List<?>) {\r
+ List<String> valueList = (List<String>)value;\r
+ for (String val : valueList) {\r
+ addItem(anyList, key, val);\r
+ }\r
+ } else {\r
+ logger.error("Unknown value type found while processing common list results: "\r
+ + value.getClass().getCanonicalName());\r
+ }\r
+ } else {\r
+ logger.trace("Null value encountered while processing common list results for key: "\r
+ + key);\r
+ }\r
+ }\r
\r
/**\r
* Adds an item to the results list. Each item should have fields\r
* @param itemInfo\r
* @throws RuntimeException if this is called before fieldKeys has been set.\r
*/\r
- public void addItem(HashMap<String,String> itemInfo) {\r
- if(fieldKeys==null) {\r
- throw new RuntimeException("CommonList.addItem: Cannot add items before fieldKeys are set.");\r
+ public void addItem(HashMap<String, Object> itemInfo) {\r
+ if (fieldKeys == null) {\r
+ throw new RuntimeException(\r
+ "CommonList.addItem: Cannot add items before fieldKeys are set.");\r
}\r
List<AbstractCommonList.ListItem> itemsList = getListItem();\r
AbstractCommonList.ListItem listItem = new AbstractCommonList.ListItem();\r
itemsList.add(listItem);\r
+ \r
List<Element> anyList = listItem.getAny();\r
- for(String key:fieldKeys) {\r
- Element el = doc.createElement(key);\r
- el.setTextContent(itemInfo.get(key));\r
- anyList.add(el);\r
+ for (String key : fieldKeys) {\r
+ Object value = itemInfo.get(key);\r
+ addItem(anyList, key, value);\r
}\r
}\r
\r
ListResultField field = resultsFields.get(i - NUM_STANDARD_LIST_RESULT_FIELDS); \r
fields[i] = field.getElement();\r
}\r
- commonList.setFieldsReturned(fields);\r
- Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();\r
- HashMap<String,String> item = new HashMap<String,String>();\r
- while(iter.hasNext()){\r
- DocumentModel docModel = iter.next();\r
- String id = NuxeoUtils.getCsid(docModel);\r
- item.put(STANDARD_LIST_CSID_FIELD, id);\r
- String uri = getUri(docModel);\r
- item.put(STANDARD_LIST_URI_FIELD, uri);\r
- item.put(STANDARD_LIST_UPDATED_AT_FIELD, getUpdatedAtAsString(docModel));\r
- item.put(STANDARD_LIST_WORKFLOW_FIELD, docModel.getCurrentLifeCycleState());\r
-\r
- for (ListResultField field : resultsFields ){\r
- String schema = field.getSchema();\r
- if(schema==null || schema.trim().isEmpty())\r
- schema = commonSchema;\r
- String value = \r
- getXPathStringValue(docModel, schema, field.getXpath());\r
- if(value!=null && !value.trim().isEmpty()) {\r
- item.put(field.getElement(), value);\r
- }\r
- }\r
- commonList.addItem(item);\r
- item.clear();\r
- }\r
+ commonList.setFieldsReturned(fields);\r
+ Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();\r
+ HashMap<String, Object> item = new HashMap<String, Object>();\r
+ while (iter.hasNext()) {\r
+ DocumentModel docModel = iter.next();\r
+ String id = NuxeoUtils.getCsid(docModel);\r
+ item.put(STANDARD_LIST_CSID_FIELD, id);\r
+ String uri = getUri(docModel);\r
+ item.put(STANDARD_LIST_URI_FIELD, uri);\r
+ item.put(STANDARD_LIST_UPDATED_AT_FIELD,\r
+ getUpdatedAtAsString(docModel));\r
+ item.put(STANDARD_LIST_WORKFLOW_FIELD,\r
+ docModel.getCurrentLifeCycleState());\r
+\r
+ for (ListResultField field : resultsFields) {\r
+ String schema = field.getSchema();\r
+ if (schema == null || schema.trim().isEmpty()) {\r
+ schema = commonSchema;\r
+ }\r
+ Object value = getXPathValue(docModel, schema, field);\r
+ if (value != null && value instanceof String) {\r
+ String strValue = (String) value;\r
+ if (strValue.trim().isEmpty() == true) {\r
+ value = null;\r
+ }\r
+ }\r
+ if (value != null) {\r
+ item.put(field.getElement(), value);\r
+ }\r
+ }\r
+ commonList.addItem(item);\r
+ item.clear();\r
+ }\r
\r
return commonList;\r
}\r
String xpath)\r
throws Exception {\r
//Object prop = docModel.getProperty(label, elementName);\r
- String value = getXPathStringValue(docModel, schema, xpath);\r
+ String value = (String)NuxeoUtils.getXPathValue(docModel, schema, xpath);\r
return ReflectionMapper.callSetter(listItem, setterName, value);\r
}\r
\r
import org.collectionspace.services.common.vocabulary.RefNameUtils;
import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthRefConfigInfo;
+import org.collectionspace.services.config.service.InitHandler.Params.Field;
+import org.collectionspace.services.config.service.ListResultField;
import org.collectionspace.services.config.service.ObjectPartType;
import org.collectionspace.services.nuxeo.util.NuxeoUtils;
import org.dom4j.Element;
* @param xpath The XPath expression (without schema prefix)
* @return value the indicated property value as a String
*/
- protected static String getXPathStringValue(DocumentModel docModel,
- String schema, String xpath) {
- String result = null;
-
- xpath = schema + ":" + xpath;
- try {
- Object value = docModel.getPropertyValue(xpath);
- String returnVal = null;
- if (value == null) {
- // Nothing to do - leave returnVal null
- } else if (value instanceof GregorianCalendar) {
- returnVal = DateTimeFormatUtils.formatAsISO8601Timestamp((GregorianCalendar) value);
- } else {
- returnVal = value.toString();
- }
- result = returnVal;
- } catch (PropertyException pe) {
- throw new RuntimeException("Problem retrieving property {" + xpath
- + "}. Bad XPath spec?" + pe.getLocalizedMessage());
- } catch (ClassCastException cce) {
- throw new RuntimeException("Problem retrieving property {" + xpath
- + "} as String. Not a String property?"
- + cce.getLocalizedMessage());
- } catch (IndexOutOfBoundsException ioobe) {
- // Nuxeo seems to handle foo/[0]/bar when it is missing,
- // but not foo/bar[0] (for repeating scalars).
- if (xpath.endsWith("[0]")) { // gracefully handle missing elements
- result = "";
- } else {
- String msg = ioobe.getMessage();
- if (msg != null && msg.equals("Index: 0, Size: 0")) {
- // Some other variant on a missing sub-field; quietly
- // absorb.
- result = "";
- }
- }
- // Otherwise, e.g., for true OOB indices, propagate the exception.
- if (result == null) {
- throw new RuntimeException("Problem retrieving property {" + xpath
- + "}:" + ioobe.getLocalizedMessage());
- }
- } catch (Exception e) {
- throw new RuntimeException("Unknown problem retrieving property {"
- + xpath + "}." + e.getLocalizedMessage());
- }
+ protected Object getXPathValue(DocumentModel docModel, // REM - CSPACE-5133
+ String schema, ListResultField field) {
+ Object result = null;
+ result = NuxeoUtils.getXPathValue(docModel, schema, field.getXpath());
+
return result;
}
import java.io.IOException;
import java.io.File;
-import java.io.Serializable;
+import java.util.GregorianCalendar;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import org.collectionspace.services.common.api.Tools;
import org.collectionspace.services.common.context.ServiceBindingUtils;
import org.collectionspace.services.common.context.ServiceContext;
-import org.collectionspace.services.common.document.BadRequestException;
+import org.collectionspace.services.common.datetime.DateTimeFormatUtils;
import org.collectionspace.services.common.document.DocumentException;
-import org.collectionspace.services.common.document.DocumentWrapper;
-import org.collectionspace.services.common.document.DocumentWrapperImpl;
import org.collectionspace.services.common.query.QueryContext;
+import org.collectionspace.services.config.service.ListResultField;
import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
import org.dom4j.Document;
import org.nuxeo.ecm.core.api.DocumentRef;
import org.nuxeo.ecm.core.api.IdRef;
import org.nuxeo.ecm.core.api.PathRef;
-import org.nuxeo.ecm.core.api.IterableQueryResult;
-import org.nuxeo.ecm.core.api.model.DocumentPart;
+import org.nuxeo.ecm.core.api.model.PropertyException;
import org.nuxeo.ecm.core.io.DocumentPipe;
import org.nuxeo.ecm.core.io.DocumentReader;
-import org.nuxeo.ecm.core.io.impl.plugins.DocumentTreeReader;
import org.nuxeo.ecm.core.io.DocumentWriter;
import org.nuxeo.ecm.core.io.impl.DocumentPipeImpl;
import org.nuxeo.ecm.core.io.impl.plugins.SingleDocumentReader;
import org.nuxeo.ecm.core.schema.SchemaManager;
import org.nuxeo.ecm.core.search.api.client.querymodel.descriptor.QueryModelDescriptor;
-import org.nuxeo.ecm.core.storage.sql.jdbc.ResultSetQueryResult;
-import org.nuxeo.ecm.core.query.sql.NXQL;
import org.nuxeo.runtime.api.Framework;
return result;
}
+ /**
+ * Gets XPath value from schema. Note that only "/" and "[n]" are
+ * supported for xpath. Can omit grouping elements for repeating complex types,
+ * e.g., "fieldList/[0]" can be used as shorthand for "fieldList/field[0]" and
+ * "fieldGroupList/[0]/field" can be used as shorthand for "fieldGroupList/fieldGroup[0]/field".
+ * If there are no entries for a list of scalars or for a list of complex types,
+ * a 0 index expression (e.g., "fieldGroupList/[0]/field") will safely return an empty
+ * string. A non-zero index will throw an IndexOutOfBoundsException if there are not
+ * that many elements in the list.
+ * N.B.: This does not follow the XPath spec - indices are 0-based, not 1-based.
+ *
+ * @param docModel The document model to get info from
+ * @param schema The name of the schema (part)
+ * @param xpath The XPath expression (without schema prefix)
+ * @return value the indicated property value as a String
+ */
+ public static Object getXPathValue(DocumentModel docModel,
+ String schema, String xpath) {
+ Object result = null;
+
+ xpath = schema + ":" + xpath;
+ try {
+ Object value = docModel.getPropertyValue(xpath);
+ String returnVal = null;
+ if (value == null) {
+ // Nothing to do - leave returnVal null
+ } else if (value instanceof GregorianCalendar) {
+ returnVal = DateTimeFormatUtils.formatAsISO8601Timestamp((GregorianCalendar) value);
+ } else {
+ returnVal = value.toString();
+ }
+ result = returnVal;
+ } catch (PropertyException pe) {
+ throw new RuntimeException("Problem retrieving property {" + xpath
+ + "}. Bad XPath spec?" + pe.getLocalizedMessage());
+ } catch (ClassCastException cce) {
+ throw new RuntimeException("Problem retrieving property {" + xpath
+ + "} as String. Not a String property?"
+ + cce.getLocalizedMessage());
+ } catch (IndexOutOfBoundsException ioobe) {
+ // Nuxeo seems to handle foo/[0]/bar when it is missing,
+ // but not foo/bar[0] (for repeating scalars).
+ if (xpath.endsWith("[0]")) { // gracefully handle missing elements
+ result = "";
+ } else {
+ String msg = ioobe.getMessage();
+ if (msg != null && msg.equals("Index: 0, Size: 0")) {
+ // Some other variant on a missing sub-field; quietly
+ // absorb.
+ result = "";
+ }
+ }
+ // Otherwise, e.g., for true OOB indices, propagate the exception.
+ if (result == null) {
+ throw new RuntimeException("Problem retrieving property {" + xpath
+ + "}:" + ioobe.getLocalizedMessage());
+ }
+ } catch (Exception e) {
+ throw new RuntimeException("Unknown problem retrieving property {"
+ + xpath + "}." + e.getLocalizedMessage());
+ }
+
+ return result;
+ }
+
static public String getPrimaryXPathPropertyName(String schema, String complexPropertyName, String fieldName) {
if (Tools.isBlank(schema)) {
return complexPropertyName + "/[0]/" + fieldName;
fields[0] = ServiceGroupListItemJAXBSchema.NAME;
fields[1] = ServiceGroupListItemJAXBSchema.URI;
commonList.setFieldsReturned(fields);
- HashMap<String,String> item = new HashMap<String,String>();
+ HashMap<String, Object> item = new HashMap<String, Object>();
for(String groupName:svcGroups){
item.put(ServiceGroupListItemJAXBSchema.NAME, groupName);
String uri = "/" + getServiceName().toLowerCase() + "/" + groupName;
fields[6] = DOC_TYPE_FIELD;
list.setFieldsReturned(fields);
Iterator<DocumentModel> iter = docList.iterator();
- HashMap<String,String> item = new HashMap<String,String>();
+ HashMap<String, Object> item = new HashMap<String,String>();
while (iter.hasNext()) {
DocumentModel docModel = iter.next();
String docType = docModel.getDocumentType().getName();