2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
24 package org.collectionspace.services.nuxeo.client.java;
26 import java.util.ArrayList;
27 import java.util.GregorianCalendar;
28 import java.util.HashMap;
29 import java.util.List;
31 import java.util.Map.Entry;
34 import javax.ws.rs.WebApplicationException;
35 import javax.ws.rs.core.MediaType;
36 import javax.ws.rs.core.Response;
37 import javax.xml.bind.JAXBElement;
39 import org.collectionspace.services.authorization.AccountPermission;
40 import org.collectionspace.services.jaxb.AbstractCommonList;
41 import org.collectionspace.services.lifecycle.TransitionDef;
42 import org.collectionspace.services.client.PayloadInputPart;
43 import org.collectionspace.services.client.PayloadOutputPart;
44 import org.collectionspace.services.client.PoxPayloadIn;
45 import org.collectionspace.services.client.PoxPayloadOut;
46 import org.collectionspace.services.client.workflow.WorkflowClient;
47 import org.collectionspace.services.common.authorityref.AuthorityRefList;
48 import org.collectionspace.services.common.context.JaxRsContext;
49 import org.collectionspace.services.common.context.MultipartServiceContext;
50 import org.collectionspace.services.common.context.ServiceContext;
51 import org.collectionspace.services.common.datetime.DateTimeFormatUtils;
52 import org.collectionspace.services.common.document.BadRequestException;
53 import org.collectionspace.services.common.document.DocumentUtils;
54 import org.collectionspace.services.common.document.DocumentWrapper;
55 import org.collectionspace.services.common.document.DocumentFilter;
56 import org.collectionspace.services.common.profile.Profiler;
57 import org.collectionspace.services.common.security.SecurityUtils;
58 import org.collectionspace.services.common.storage.jpa.JpaStorageUtils;
59 import org.collectionspace.services.common.vocabulary.RefNameUtils;
60 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
61 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthRefConfigInfo;
62 import org.collectionspace.services.config.service.InitHandler.Params.Field;
63 import org.collectionspace.services.config.service.ListResultField;
64 import org.collectionspace.services.config.service.ObjectPartType;
65 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
66 import org.dom4j.Element;
68 import org.nuxeo.ecm.core.api.DocumentModel;
69 import org.nuxeo.ecm.core.api.DocumentModelList;
70 import org.nuxeo.ecm.core.api.model.Property;
71 import org.nuxeo.ecm.core.api.model.PropertyException;
72 import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
74 import org.nuxeo.ecm.core.schema.types.Schema;
76 import org.slf4j.Logger;
77 import org.slf4j.LoggerFactory;
80 * RemoteDocumentModelHandler
82 * $LastChangedRevision: $
87 public abstract class RemoteDocumentModelHandlerImpl<T, TL>
88 extends DocumentModelHandler<T, TL> {
91 private final Logger logger = LoggerFactory.getLogger(RemoteDocumentModelHandlerImpl.class);
94 * @see org.collectionspace.services.common.document.AbstractDocumentHandlerImpl#setServiceContext(org.collectionspace.services.common.context.ServiceContext)
97 public void setServiceContext(ServiceContext ctx) { //FIXME: Apply proper generics to ServiceContext<PoxPayloadIn, PoxPayloadOut>
98 if (ctx instanceof MultipartServiceContext) {
99 super.setServiceContext(ctx);
101 throw new IllegalArgumentException("setServiceContext requires instance of "
102 + MultipartServiceContext.class.getName());
107 public void handleWorkflowTransition(DocumentWrapper<DocumentModel> wrapDoc, TransitionDef transitionDef)
109 // Do nothing by default, but children can override if they want. The really workflow transition happens in the WorkflowDocumemtModelHandler class
113 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#completeUpdate(org.collectionspace.services.common.document.DocumentWrapper)
116 public void completeUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
117 DocumentModel docModel = wrapDoc.getWrappedObject();
118 //return at least those document part(s) that were received
119 Map<String, ObjectPartType> partsMetaMap = getServiceContext().getPartsMetadata();
120 MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
121 PoxPayloadIn input = ctx.getInput();
123 List<PayloadInputPart> inputParts = ctx.getInput().getParts();
124 for (PayloadInputPart part : inputParts) {
125 String partLabel = part.getLabel();
127 ObjectPartType partMeta = partsMetaMap.get(partLabel);
128 // CSPACE-4030 - generates NPE if the part is missing.
130 Map<String, Object> unQObjectProperties = extractPart(docModel, partLabel, partMeta);
131 if(unQObjectProperties!=null) {
132 addOutputPart(unQObjectProperties, partLabel, partMeta);
135 } catch (Throwable t){
137 logger.error("Unable to addOutputPart: "+partLabel
138 +" in serviceContextPath: "+this.getServiceContextPath()
139 +" with URI: "+this.getServiceContext().getUriInfo().getPath()
144 if (logger.isWarnEnabled() == true) {
145 logger.warn("MultipartInput part was null for document id = " +
152 * Adds the output part.
154 * @param unQObjectProperties the un q object properties
155 * @param schema the schema
156 * @param partMeta the part meta
157 * @throws Exception the exception
158 * MediaType.APPLICATION_XML_TYPE
160 protected void addOutputPart(Map<String, Object> unQObjectProperties, String schema, ObjectPartType partMeta)
162 Element doc = DocumentUtils.buildDocument(partMeta, schema,
163 unQObjectProperties);
164 if (logger.isTraceEnabled() == true) {
165 logger.trace(doc.asXML());
167 MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
168 ctx.addOutputPart(schema, doc, partMeta.getContent().getContentType());
172 * Extract paging info.
174 * @param commonsList the commons list
176 * @throws Exception the exception
178 public TL extractPagingInfo(TL theCommonList, DocumentWrapper<DocumentModelList> wrapDoc)
180 AbstractCommonList commonList = (AbstractCommonList) theCommonList;
182 DocumentFilter docFilter = this.getDocumentFilter();
183 long pageSize = docFilter.getPageSize();
184 long pageNum = pageSize != 0 ? docFilter.getOffset() / pageSize : pageSize;
185 // set the page size and page number
186 commonList.setPageNum(pageNum);
187 commonList.setPageSize(pageSize);
188 DocumentModelList docList = wrapDoc.getWrappedObject();
189 // Set num of items in list. this is useful to our testing framework.
190 commonList.setItemsInPage(docList.size());
191 // set the total result size
192 commonList.setTotalItems(docList.totalSize());
194 return (TL) commonList;
198 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractAllParts(org.collectionspace.services.common.document.DocumentWrapper)
201 public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc)
204 DocumentModel docModel = wrapDoc.getWrappedObject();
205 String[] schemas = docModel.getDeclaredSchemas();
206 Map<String, ObjectPartType> partsMetaMap = getServiceContext().getPartsMetadata();
207 for (String schema : schemas) {
208 ObjectPartType partMeta = partsMetaMap.get(schema);
209 if (partMeta == null) {
210 continue; // unknown part, ignore
212 Map<String, Object> unQObjectProperties = extractPart(docModel, schema, partMeta);
213 if(COLLECTIONSPACE_CORE_SCHEMA.equals(schema)) {
214 addExtraCoreValues(docModel, unQObjectProperties);
216 addOutputPart(unQObjectProperties, schema, partMeta);
218 addAccountPermissionsPart();
221 private void addExtraCoreValues(DocumentModel docModel, Map<String, Object> unQObjectProperties)
223 unQObjectProperties.put(COLLECTIONSPACE_CORE_WORKFLOWSTATE, docModel.getCurrentLifeCycleState());
226 private void addAccountPermissionsPart() throws Exception {
227 Profiler profiler = new Profiler("addAccountPermissionsPart():", 1);
230 MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
231 String currentServiceName = ctx.getServiceName();
232 String workflowSubResource = "/";
233 JaxRsContext jaxRsContext = ctx.getJaxRsContext();
234 if (jaxRsContext != null) {
235 String resourceName = SecurityUtils.getResourceName(jaxRsContext.getUriInfo());
236 workflowSubResource = workflowSubResource + resourceName + WorkflowClient.SERVICE_PATH + "/";
238 workflowSubResource = workflowSubResource + currentServiceName + WorkflowClient.SERVICE_AUTHZ_SUFFIX;
240 AccountPermission accountPermission = JpaStorageUtils.getAccountPermissions(JpaStorageUtils.CS_CURRENT_USER,
241 currentServiceName, workflowSubResource);
242 org.collectionspace.services.authorization.ObjectFactory objectFactory =
243 new org.collectionspace.services.authorization.ObjectFactory();
244 JAXBElement<AccountPermission> ap = objectFactory.createAccountPermission(accountPermission);
245 PayloadOutputPart accountPermissionPart = new PayloadOutputPart("account_permission", ap);
246 ctx.addOutputPart(accountPermissionPart);
252 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillAllParts(org.collectionspace.services.common.document.DocumentWrapper)
255 public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception {
257 //TODO filling extension parts should be dynamic
258 //Nuxeo APIs lack to support stream/byte[] input, get/setting properties is
259 //not an ideal way of populating objects.
260 DocumentModel docModel = wrapDoc.getWrappedObject();
261 MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
262 PoxPayloadIn input = ctx.getInput();
263 if (input.getParts().isEmpty()) {
264 String msg = "No payload found!";
265 logger.error(msg + "Ctx=" + getServiceContext().toString());
266 throw new BadRequestException(msg);
269 Map<String, ObjectPartType> partsMetaMap = getServiceContext().getPartsMetadata();
271 //iterate over parts received and fill those parts
272 List<PayloadInputPart> inputParts = input.getParts();
273 for (PayloadInputPart part : inputParts) {
275 String partLabel = part.getLabel();
276 if (partLabel == null) {
277 String msg = "Part label is missing or empty!";
278 logger.error(msg + "Ctx=" + getServiceContext().toString());
279 throw new BadRequestException(msg);
282 //skip if the part is not in metadata
283 ObjectPartType partMeta = partsMetaMap.get(partLabel);
284 if (partMeta == null) {
287 fillPart(part, docModel, partMeta, action, ctx);
293 * fillPart fills an XML part into given document model
294 * @param part to fill
295 * @param docModel for the given object
296 * @param partMeta metadata for the object to fill
299 protected void fillPart(PayloadInputPart part, DocumentModel docModel,
300 ObjectPartType partMeta, Action action, ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx)
302 //check if this is an xml part
303 if (part.getMediaType().equals(MediaType.APPLICATION_XML_TYPE)) {
304 Element element = part.getElementBody();
305 Map<String, Object> objectProps = DocumentUtils.parseProperties(partMeta, element, ctx);
306 if (action == Action.UPDATE) {
307 this.filterReadOnlyPropertiesForPart(objectProps, partMeta);
309 docModel.setProperties(partMeta.getLabel(), objectProps);
314 * Filters out read only properties, so they cannot be set on update.
315 * TODO: add configuration support to do this generally
316 * @param objectProps the properties parsed from the update payload
317 * @param partMeta metadata for the object to fill
319 public void filterReadOnlyPropertiesForPart(
320 Map<String, Object> objectProps, ObjectPartType partMeta) {
321 // Should add in logic to filter most of the core items on update
322 if(partMeta.getLabel().equalsIgnoreCase(COLLECTIONSPACE_CORE_SCHEMA)) {
323 objectProps.remove(COLLECTIONSPACE_CORE_CREATED_AT);
324 objectProps.remove(COLLECTIONSPACE_CORE_CREATED_BY);
325 objectProps.remove(COLLECTIONSPACE_CORE_URI);
326 objectProps.remove(COLLECTIONSPACE_CORE_TENANTID);
327 // Note that the updatedAt/updatedBy fields are set internally
328 // in DocumentModelHandler.handleCoreValues().
333 * extractPart extracts an XML object from given DocumentModel
335 * @param schema of the object to extract
336 * @param partMeta metadata for the object to extract
339 protected Map<String, Object> extractPart(DocumentModel docModel, String schema)
341 return extractPart(docModel, schema, (Map<String, Object>)null);
345 * extractPart extracts an XML object from given DocumentModel
347 * @param schema of the object to extract
348 * @param partMeta metadata for the object to extract
352 protected Map<String, Object> extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta)
354 return extractPart(docModel, schema, partMeta, null);
358 * extractPart extracts an XML object from given DocumentModel
360 * @param schema of the object to extract
361 * @param partMeta metadata for the object to extract
364 protected Map<String, Object> extractPart(
365 DocumentModel docModel,
367 Map<String, Object> addToMap)
369 Map<String, Object> result = null;
371 Map<String, Object> objectProps = docModel.getProperties(schema);
372 if (objectProps != null) {
373 //unqualify properties before sending the doc over the wire (to save bandwidh)
374 //FIXME: is there a better way to avoid duplication of a Map/Collection?
375 Map<String, Object> unQObjectProperties =
376 (addToMap != null) ? addToMap : (new HashMap<String, Object>());
377 Set<Entry<String, Object>> qualifiedEntries = objectProps.entrySet();
378 for (Entry<String, Object> entry : qualifiedEntries) {
379 String unqProp = getUnQProperty(entry.getKey());
380 unQObjectProperties.put(unqProp, entry.getValue());
382 result = unQObjectProperties;
389 * extractPart extracts an XML object from given DocumentModel
391 * @param schema of the object to extract
392 * @param partMeta metadata for the object to extract
396 protected Map<String, Object> extractPart(
397 DocumentModel docModel, String schema, ObjectPartType partMeta,
398 Map<String, Object> addToMap)
400 Map<String, Object> result = null;
402 result = this.extractPart(docModel, schema, addToMap);
408 public String getStringPropertyFromDoc(
411 String propertyXPath ) throws DocumentNotFoundException, DocumentException {
412 RepositoryInstance repoSession = null;
413 boolean releaseRepoSession = false;
414 String returnValue = null;
417 RepositoryJavaClientImpl repoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx);
418 repoSession = this.getRepositorySession();
419 if (repoSession == null) {
420 repoSession = repoClient.getRepositorySession();
421 releaseRepoSession = true;
425 DocumentWrapper<DocumentModel> wrapper = repoClient.getDoc(repoSession, ctx, csid);
426 DocumentModel docModel = wrapper.getWrappedObject();
427 returnValue = (String) docModel.getPropertyValue(propertyXPath);
428 } catch (PropertyException pe) {
430 } catch (DocumentException de) {
432 } catch (Exception e) {
433 if (logger.isDebugEnabled()) {
434 logger.debug("Caught exception ", e);
436 throw new DocumentException(e);
438 if (releaseRepoSession && repoSession != null) {
439 repoClient.releaseRepositorySession(repoSession);
442 } catch (Exception e) {
443 if (logger.isDebugEnabled()) {
444 logger.debug("Caught exception ", e);
446 throw new DocumentException(e);
450 if (logger.isWarnEnabled() == true) {
451 logger.warn("Returned DocumentModel instance was created with a repository session that is now closed.");
460 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getAuthorityRefs(org.collectionspace.services.common.document.DocumentWrapper, java.util.List)
463 public AuthorityRefList getAuthorityRefs(
465 List<AuthRefConfigInfo> authRefsInfo) throws PropertyException {
467 AuthorityRefList authRefList = new AuthorityRefList();
468 AbstractCommonList commonList = (AbstractCommonList) authRefList;
470 DocumentFilter docFilter = this.getDocumentFilter();
471 long pageSize = docFilter.getPageSize();
472 long pageNum = pageSize != 0 ? docFilter.getOffset() / pageSize : pageSize;
473 // set the page size and page number
474 commonList.setPageNum(pageNum);
475 commonList.setPageSize(pageSize);
477 List<AuthorityRefList.AuthorityRefItem> list = authRefList.getAuthorityRefItem();
480 int iFirstToUse = (int)(pageSize*pageNum);
481 int nFoundInPage = 0;
484 ArrayList<RefNameServiceUtils.AuthRefInfo> foundProps
485 = new ArrayList<RefNameServiceUtils.AuthRefInfo>();
487 boolean releaseRepoSession = false;
488 ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = this.getServiceContext();
489 RepositoryJavaClientImpl repoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx);
490 RepositoryInstance repoSession = this.getRepositorySession();
491 if (repoSession == null) {
492 repoSession = repoClient.getRepositorySession();
493 releaseRepoSession = true;
497 DocumentModel docModel = repoClient.getDoc(repoSession, ctx, csid).getWrappedObject();
498 RefNameServiceUtils.findAuthRefPropertiesInDoc(docModel, authRefsInfo, null, foundProps);
499 // Slightly goofy pagination support - how many refs do we expect from one object?
500 for(RefNameServiceUtils.AuthRefInfo ari:foundProps) {
501 if((nFoundTotal >= iFirstToUse) && (nFoundInPage < pageSize)) {
502 if(appendToAuthRefsList(ari, list)) {
511 if (releaseRepoSession == true) {
512 repoClient.releaseRepositorySession(repoSession);
516 // Set num of items in list. this is useful to our testing framework.
517 commonList.setItemsInPage(nFoundInPage);
518 // set the total result size
519 commonList.setTotalItems(nFoundTotal);
521 } catch (PropertyException pe) {
522 String msg = "Attempted to retrieve value for invalid or missing authority field. "
523 + "Check authority field properties in tenant bindings.";
524 logger.warn(msg, pe);
526 } catch (Exception e) {
527 if (logger.isDebugEnabled()) {
528 logger.debug("Caught exception in getAuthorityRefs", e);
530 Response response = Response.status(
531 Response.Status.INTERNAL_SERVER_ERROR).entity(
532 "Failed to retrieve authority references").type(
533 "text/plain").build();
534 throw new WebApplicationException(response);
540 private boolean appendToAuthRefsList(RefNameServiceUtils.AuthRefInfo ari,
541 List<AuthorityRefList.AuthorityRefItem> list)
543 String fieldName = ari.getQualifiedDisplayName();
545 String refNameValue = (String)ari.getProperty().getValue();
546 AuthorityRefList.AuthorityRefItem item = authorityRefListItem(fieldName, refNameValue);
547 if(item!=null) { // ignore garbage values.
551 } catch(PropertyException pe) {
552 logger.debug("PropertyException on: "+ari.getProperty().getPath()+pe.getLocalizedMessage());
557 private AuthorityRefList.AuthorityRefItem authorityRefListItem(String authRefFieldName, String refName) {
559 AuthorityRefList.AuthorityRefItem ilistItem = new AuthorityRefList.AuthorityRefItem();
561 RefNameUtils.AuthorityTermInfo termInfo = RefNameUtils.parseAuthorityTermInfo(refName);
562 ilistItem.setRefName(refName);
563 ilistItem.setAuthDisplayName(termInfo.inAuthority.displayName);
564 ilistItem.setItemDisplayName(termInfo.displayName);
565 ilistItem.setSourceField(authRefFieldName);
566 ilistItem.setUri(termInfo.getRelativeUri());
567 } catch (Exception e) {
568 logger.error("Trouble parsing refName from value: "+refName+" in field: "+authRefFieldName+e.getLocalizedMessage());
575 * Returns the primary value from a list of values.
577 * Assumes that the first value is the primary value.
578 * This assumption may change when and if the primary value
579 * is identified explicitly.
581 * @param values a list of values.
582 * @param propertyName the name of a property through
583 * which the value can be extracted.
584 * @return the primary value.
585 protected String primaryValueFromMultivalue(List<Object> values, String propertyName) {
586 String primaryValue = "";
587 if (values == null || values.size() == 0) {
590 Object value = values.get(0);
591 if (value instanceof String) {
593 primaryValue = (String) value;
595 // Multivalue group of fields
596 } else if (value instanceof Map) {
598 Map map = (Map) value;
599 if (map.values().size() > 0) {
600 if (map.get(propertyName) != null) {
601 primaryValue = (String) map.get(propertyName);
606 logger.warn("Unexpected type for property " + propertyName
607 + " in multivalue list: not String or Map.");
614 * Gets a simple property from the document.
616 * For completeness, as this duplicates DocumentModel method.
618 * @param docModel The document model to get info from
619 * @param schema The name of the schema (part)
620 * @param propertyName The simple scalar property type
621 * @return property value as String
623 protected String getSimpleStringProperty(DocumentModel docModel, String schema, String propName) {
624 String xpath = "/"+schema+":"+propName;
626 return (String)docModel.getPropertyValue(xpath);
627 } catch(PropertyException pe) {
628 throw new RuntimeException("Problem retrieving property {"+xpath+"}. Not a simple String property?"
629 +pe.getLocalizedMessage());
630 } catch(ClassCastException cce) {
631 throw new RuntimeException("Problem retrieving property {"+xpath+"} as String. Not a scalar String property?"
632 +cce.getLocalizedMessage());
633 } catch(Exception e) {
634 throw new RuntimeException("Unknown problem retrieving property {"+xpath+"}."
635 +e.getLocalizedMessage());
640 * Gets first of a repeating list of scalar values, as a String, from the document.
642 * @param docModel The document model to get info from
643 * @param schema The name of the schema (part)
644 * @param listName The name of the scalar list property
645 * @return first value in list, as a String, or empty string if the list is empty
647 protected String getFirstRepeatingStringProperty(
648 DocumentModel docModel, String schema, String listName) {
649 String xpath = "/"+schema+":"+listName+"/[0]";
651 return (String)docModel.getPropertyValue(xpath);
652 } catch(PropertyException pe) {
653 throw new RuntimeException("Problem retrieving property {"+xpath+"}. Not a repeating scalar?"
654 +pe.getLocalizedMessage());
655 } catch(IndexOutOfBoundsException ioobe) {
656 // Nuxeo sometimes handles missing sub, and sometimes does not. Odd.
657 return ""; // gracefully handle missing elements
658 } catch(ClassCastException cce) {
659 throw new RuntimeException("Problem retrieving property {"+xpath+"} as String. Not a repeating String property?"
660 +cce.getLocalizedMessage());
661 } catch(Exception e) {
662 throw new RuntimeException("Unknown problem retrieving property {"+xpath+"}."
663 +e.getLocalizedMessage());
669 * Gets first of a repeating list of scalar values, as a String, from the document.
671 * @param docModel The document model to get info from
672 * @param schema The name of the schema (part)
673 * @param listName The name of the scalar list property
674 * @return first value in list, as a String, or empty string if the list is empty
676 protected String getStringValueInPrimaryRepeatingComplexProperty(
677 DocumentModel docModel, String schema, String complexPropertyName, String fieldName) {
678 String result = null;
680 String xpath = "/" + NuxeoUtils.getPrimaryXPathPropertyName(schema, complexPropertyName, fieldName);
682 result = (String)docModel.getPropertyValue(xpath);
683 } catch(PropertyException pe) {
684 throw new RuntimeException("Problem retrieving property {"+xpath+"}. Bad propertyNames?"
685 +pe.getLocalizedMessage());
686 } catch(IndexOutOfBoundsException ioobe) {
687 // Nuxeo sometimes handles missing sub, and sometimes does not. Odd.
688 result = ""; // gracefully handle missing elements
689 } catch(ClassCastException cce) {
690 throw new RuntimeException("Problem retrieving property {"+xpath+"} as String. Not a String property?"
691 +cce.getLocalizedMessage());
692 } catch(Exception e) {
693 throw new RuntimeException("Unknown problem retrieving property {"+xpath+"}."
694 +e.getLocalizedMessage());
701 * Gets XPath value from schema. Note that only "/" and "[n]" are
702 * supported for xpath. Can omit grouping elements for repeating complex types,
703 * e.g., "fieldList/[0]" can be used as shorthand for "fieldList/field[0]" and
704 * "fieldGroupList/[0]/field" can be used as shorthand for "fieldGroupList/fieldGroup[0]/field".
705 * If there are no entries for a list of scalars or for a list of complex types,
706 * a 0 index expression (e.g., "fieldGroupList/[0]/field") will safely return an empty
707 * string. A non-zero index will throw an IndexOutOfBoundsException if there are not
708 * that many elements in the list.
709 * N.B.: This does not follow the XPath spec - indices are 0-based, not 1-based.
711 * @param docModel The document model to get info from
712 * @param schema The name of the schema (part)
713 * @param xpath The XPath expression (without schema prefix)
714 * @return value the indicated property value as a String
716 protected Object getListResultValue(DocumentModel docModel, // REM - CSPACE-5133
717 String schema, ListResultField field) {
718 Object result = null;
720 result = NuxeoUtils.getXPathValue(docModel, schema, field.getXpath());