From: remillet Date: Wed, 15 Apr 2015 19:43:55 +0000 (-0700) Subject: CSPACE-6375: Merged with branch that included changes for Nuxeo 6 and Tomcat 7 upgrades. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=fe4a066f5d0b2145b5e9ae6ea21eee053b9fc6f5;p=tmp%2Fjakarta-migration.git CSPACE-6375: Merged with branch that included changes for Nuxeo 6 and Tomcat 7 upgrades. --- diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java index 506f1f12d..075c15624 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java @@ -485,7 +485,7 @@ public abstract class AuthorityItemDocumentModelHandler try { DocumentWrapper wrapper = repoClient.getDoc(repoSession, ctx, itemcsid); DocumentModel docModel = wrapper.getWrappedObject(); - String refName = (String) docModel.getPropertyValue(AuthorityItemJAXBSchema.REF_NAME); + String refName = (String) NuxeoUtils.getProperyValue(docModel, AuthorityItemJAXBSchema.REF_NAME); //docModel.getPropertyValue(AuthorityItemJAXBSchema.REF_NAME); authRefDocList = RefNameServiceUtils.getAuthorityRefDocs( repoSession, ctx, uriTemplateRegistry, repoClient, serviceTypes, diff --git a/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/BatchDocumentModelHandler.java b/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/BatchDocumentModelHandler.java index ce825c5a0..9f2aa7ae0 100644 --- a/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/BatchDocumentModelHandler.java +++ b/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/BatchDocumentModelHandler.java @@ -32,6 +32,7 @@ import org.collectionspace.services.jaxb.InvocableJAXBSchema; import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentModelHandler; import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface; import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl; +import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.collectionspace.services.batch.BatchCommon; import org.collectionspace.services.batch.BatchInvocable; import org.collectionspace.services.client.PoxPayloadIn; @@ -45,12 +46,9 @@ import org.collectionspace.services.common.invocable.Invocable; import org.collectionspace.services.common.invocable.InvocationContext; import org.collectionspace.services.common.invocable.InvocationResults; import org.collectionspace.services.common.invocable.Invocable.InvocationError; - import org.jboss.resteasy.spi.ResteasyProviderFactory; - import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.model.PropertyException; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -93,19 +91,19 @@ public class BatchDocumentModelHandler extends NuxeoDocumentModelHandler wrapper = repoClient.getDoc(repoSession, ctx, csid); DocumentModel docModel = wrapper.getWrappedObject(); - Boolean supports = (Boolean) docModel.getPropertyValue(modeProperty); + Boolean supports = (Boolean) NuxeoUtils.getProperyValue(docModel, modeProperty); if (!supports) { throw new BadRequestException("BatchResource: This Batch Job does not support Invocation Mode: " + invocationMode); } if (checkDocType) { - List forDocTypeList = (List) docModel.getPropertyValue(BatchJAXBSchema.FOR_DOC_TYPES); + List forDocTypeList = (List) NuxeoUtils.getProperyValue(docModel, BatchJAXBSchema.FOR_DOC_TYPES); //docModel.getPropertyValue(BatchJAXBSchema.FOR_DOC_TYPES); if (forDocTypeList == null || !forDocTypeList.contains(invContext.getDocType())) { throw new BadRequestException("BatchResource: Invoked with unsupported document type: " + invContext.getDocType()); } } - className = (String) docModel.getPropertyValue(BatchJAXBSchema.BATCH_CLASS_NAME); + className = (String) NuxeoUtils.getProperyValue(docModel, BatchJAXBSchema.BATCH_CLASS_NAME); //docModel.getPropertyValue(BatchJAXBSchema.BATCH_CLASS_NAME); } catch (PropertyException pe) { if (logger.isDebugEnabled()) { logger.debug("Property exception getting batch values: ", pe); diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java index 9c5be602b..69c134c83 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java @@ -169,6 +169,7 @@ public class ServiceBindingUtils { String logicalFieldName, DocumentModel docModel ) { // Now we have to get the number, which is configured as some field // on each docType + /* If we go to qualified field names, we'll need this String[] strings = qPropName.split(":"); if(strings.length!=2) { @@ -177,28 +178,37 @@ public class ServiceBindingUtils { +logicalFieldName+" field for: "+docModel.getDocumentType().getName()); } */ + String propName = getPropertyValue(sb, logicalFieldName); - if(Tools.isBlank(propName)) { + if (Tools.isBlank(propName)) { logger.warn("Property name is empty for property " + logicalFieldName + " in service " + sb.getName()); logger.warn("This may be due to an improperly configured or missing " + "generic property (objectNameProperty, objectNumberProperty ...) in tenant bindings configuration"); return ""; } - try { - Object obj = docModel.getPropertyValue(propName); - return DocumentUtils.propertyValueAsString(obj, docModel, propName); - } catch(IndexOutOfBoundsException ioobe) { - // Should not happen, but may with certain array forms - if(logger.isTraceEnabled()) { - logger.trace("SBUtils.getMappedField caught OOB exc, for Prop: "+propName - + " in: " + docModel.getDocumentType().getName() - + " csid: " + NuxeoUtils.getCsid(docModel)); - } - return null; - } catch(ClientException ce) { - throw new RuntimeException( - "getMappedFieldInDoc: Problem fetching: "+propName+" logicalfieldName: "+logicalFieldName+" docModel: "+docModel, ce); - } + // + // Try to get a value from the Nuxeo document for the property name. + // + String result = null; + try { + Object obj = NuxeoUtils.getProperyValue(docModel, propName); + result = DocumentUtils.propertyValueAsString(obj, docModel, propName); + } catch (IndexOutOfBoundsException ioobe) { + // Should not happen, but may with certain array forms + logger.trace("SBUtils.getMappedField caught OOB exc, for Prop: " + + propName + " in: " + docModel.getDocumentType().getName() + + " csid: " + NuxeoUtils.getCsid(docModel)); + } catch (ClientException ce) { + throw new RuntimeException( + "getMappedFieldInDoc: Problem fetching: " + propName + + " logicalfieldName: " + logicalFieldName + + " docModel CSID: " + docModel.getName(), ce); + } catch (Exception e) { + logger.warn(String.format("Could not get a value for the property '%s' in Nuxeo document with CSID '%s'.", + propName, docModel.getName())); + } + + return result; } private static ArrayList commonProcedureServiceTypes = null; diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java index 50f0ad311..74be6d1cd 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java @@ -704,7 +704,7 @@ public class RefNameServiceUtils { uri = template.buildUri(additionalValues); } else if (template.getUriTemplateType() == UriTemplateFactory.ITEM) { try { - String inAuthorityCsid = (String) docModel.getPropertyValue("inAuthority"); // AuthorityItemJAXBSchema.IN_AUTHORITY + String inAuthorityCsid = (String) NuxeoUtils.getProperyValue(docModel, "inAuthority"); //docModel.getPropertyValue("inAuthority"); // AuthorityItemJAXBSchema.IN_AUTHORITY additionalValues.put(UriTemplateFactory.IDENTIFIER_VAR, inAuthorityCsid); additionalValues.put(UriTemplateFactory.ITEM_IDENTIFIER_VAR, csid); uri = template.buildUri(additionalValues); 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 68389c824..6f81c24a6 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 @@ -756,7 +756,7 @@ public abstract class RemoteDocumentModelHandlerImpl protected String getSimpleStringProperty(DocumentModel docModel, String schema, String propName) { String xpath = "/"+schema+":"+propName; try { - return (String)docModel.getPropertyValue(xpath); + return (String) NuxeoUtils.getProperyValue(docModel, xpath); //docModel.getPropertyValue(xpath); } catch(PropertyException pe) { throw new RuntimeException("Problem retrieving property {"+xpath+"}. Not a simple String property?" +pe.getLocalizedMessage()); @@ -777,27 +777,27 @@ public abstract class RemoteDocumentModelHandlerImpl * @param listName The name of the scalar list property * @return first value in list, as a String, or empty string if the list is empty */ - protected String getFirstRepeatingStringProperty( - DocumentModel docModel, String schema, String listName) { - String xpath = "/"+schema+":"+listName+"/[0]"; - try { - return (String)docModel.getPropertyValue(xpath); - } catch(PropertyException pe) { - throw new RuntimeException("Problem retrieving property {"+xpath+"}. Not a repeating scalar?" - +pe.getLocalizedMessage()); - } catch(IndexOutOfBoundsException ioobe) { - // Nuxeo sometimes handles missing sub, and sometimes does not. Odd. - return ""; // gracefully handle missing elements - } catch(ClassCastException cce) { - throw new RuntimeException("Problem retrieving property {"+xpath+"} as String. Not a repeating String property?" - +cce.getLocalizedMessage()); - } catch(Exception e) { - throw new RuntimeException("Unknown problem retrieving property {"+xpath+"}." - +e.getLocalizedMessage()); - } - } + protected String getFirstRepeatingStringProperty(DocumentModel docModel, + String schema, String listName) { + String xpath = "/" + schema + ":" + listName + "/[0]"; + try { + return (String) NuxeoUtils.getProperyValue(docModel, xpath); // docModel.getPropertyValue(xpath); + } catch (PropertyException pe) { + throw new RuntimeException("Problem retrieving property {" + xpath + + "}. Not a repeating scalar?" + pe.getLocalizedMessage()); + } catch (IndexOutOfBoundsException ioobe) { + // Nuxeo sometimes handles missing sub, and sometimes does not. Odd. + return ""; // gracefully handle missing elements + } catch (ClassCastException cce) { + throw new RuntimeException("Problem retrieving property {" + xpath + + "} as String. Not a repeating String property?" + + cce.getLocalizedMessage()); + } catch (Exception e) { + throw new RuntimeException("Unknown problem retrieving property {" + + xpath + "}." + e.getLocalizedMessage()); + } + } - /** * Gets first of a repeating list of scalar values, as a String, from the document. * @@ -812,7 +812,7 @@ public abstract class RemoteDocumentModelHandlerImpl String xpath = "/" + NuxeoUtils.getPrimaryXPathPropertyName(schema, complexPropertyName, fieldName); try { - result = (String)docModel.getPropertyValue(xpath); + result = (String) NuxeoUtils.getProperyValue(docModel, xpath); //docModel.getPropertyValue(xpath); } catch(PropertyException pe) { throw new RuntimeException("Problem retrieving property {"+xpath+"}. Bad propertyNames?" +pe.getLocalizedMessage()); diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java index 2b4cf2aa0..15da22d1c 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java @@ -730,6 +730,27 @@ public class NuxeoUtils { return result; } + /* + * Returns the property value for an instance of a DocumentModel. If there is no value for the + * property, we'll return null. + * + * Beginning in Nuxeo 6, if a DocumentModel has no value for the property, we get a NPE when calling + * the DocumentModel.getPropertyValue method. This method catches that NPE and instead returns null. + */ + public static Object getProperyValue(DocumentModel docModel, + String propertyName) throws ClientException, PropertyException { + Object result = null; + + try { + result = docModel.getPropertyValue(propertyName); + } catch (NullPointerException npe) { + logger.warn(String.format("Could not get a value for the property '%s' in Nuxeo document with CSID '%s'.", + propertyName, docModel.getName())); + } + + return result; + } + /** * Gets XPath value from schema. Note that only "/" and "[n]" are * supported for xpath. Can omit grouping elements for repeating complex types, @@ -750,20 +771,22 @@ public class NuxeoUtils { String schema, String xpath) throws NuxeoDocumentException { Object result = null; + String targetCSID = null; xpath = schema + ":" + xpath; try { Object value = docModel.getPropertyValue(xpath); + targetCSID = docModel.getName(); String returnVal = null; if (value == null) { - // Nothing to do - leave returnVal null + // Nothing to do - leave returnVal null } else { - returnVal = DocumentUtils.propertyValueAsString(value, docModel, xpath); + returnVal = DocumentUtils.propertyValueAsString(value, docModel, xpath); } result = returnVal; } catch (ClientException ce) { String msg = "Unknown Nuxeo client exception."; if (ce instanceof PropertyException) { - msg = "Problem retrieving property {" + xpath + "}. Bad XPath spec?" + ce.getLocalizedMessage(); + msg = String.format("Problem retrieving property for xpath { %s } with CSID = %s.", xpath, targetCSID); } throw new NuxeoDocumentException(msg, ce); // We need to wrap this exception in order to retry failed requests caused by network errors } catch (ClassCastException cce) { @@ -789,8 +812,8 @@ public class NuxeoUtils { + "}:" + ioobe.getLocalizedMessage()); } } catch (NullPointerException npe) { - logger.error(String.format("Null value found for property %s for document with ID %s", - xpath, docModel.getId()), npe); + logger.error(String.format("Null value found for property '%s' for document with ID %s", + xpath, docModel.getName()), npe); } return result; diff --git a/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java b/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java index 1748a7a24..fd3331455 100644 --- a/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java +++ b/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java @@ -76,6 +76,7 @@ import org.collectionspace.services.jaxb.InvocableJAXBSchema; import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentModelHandler; import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface; import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl; +import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.jfree.util.Log; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.model.PropertyException; @@ -151,7 +152,6 @@ public class ReportDocumentModelHandler extends NuxeoDocumentModelHandler wrapper = repoClient.getDoc(repoSession, ctx, csid); DocumentModel docModel = wrapper.getWrappedObject(); - Boolean supports = (Boolean)docModel.getPropertyValue(modeProperty); + Boolean supports = (Boolean) NuxeoUtils.getProperyValue(docModel, modeProperty); //docModel.getPropertyValue(modeProperty); if(supports == null || !supports) { throw new BadRequestException( "ReportResource: This Report does not support Invocation Mode: " +invocationMode); } - if(checkDocType) { + if (checkDocType) { List forDocTypeList = - (List)docModel.getPropertyValue(InvocableJAXBSchema.FOR_DOC_TYPES); - if(forDocTypeList==null - || !forDocTypeList.contains(invContext.getDocType())) { + (List) NuxeoUtils.getProperyValue(docModel, InvocableJAXBSchema.FOR_DOC_TYPES); //docModel.getPropertyValue(InvocableJAXBSchema.FOR_DOC_TYPES); + if (forDocTypeList==null || !forDocTypeList.contains(invContext.getDocType())) { throw new BadRequestException( "ReportResource: Invoked with unsupported document type: " +invContext.getDocType()); } } - reportFileNameProperty = ((String)docModel.getPropertyValue(ReportJAXBSchema.FILENAME)); // Set the outgoing param with the report file name - String reportOutputMime = (String)docModel.getPropertyValue(ReportJAXBSchema.OUTPUT_MIME); + reportFileNameProperty = (String) NuxeoUtils.getProperyValue(docModel, ReportJAXBSchema.FILENAME); //docModel.getPropertyValue(ReportJAXBSchema.FILENAME)); // Set the outgoing param with the report file name + String reportOutputMime = (String) NuxeoUtils.getProperyValue(docModel, ReportJAXBSchema.OUTPUT_MIME); //docModel.getPropertyValue(ReportJAXBSchema.OUTPUT_MIME); if(!Tools.isEmpty(reportOutputMime)) { outMimeType.append(reportOutputMime); } else { diff --git a/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java index 37b8ab39b..7394e1dce 100644 --- a/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java +++ b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java @@ -218,11 +218,12 @@ public class ServiceGroupDocumentModelHandler Map additionalValues = new HashMap(); if (storedValuesResourceTemplate.getUriTemplateType() == UriTemplateFactory.ITEM) { try { - String inAuthorityCsid = (String) docModel.getPropertyValue("inAuthority"); // AuthorityItemJAXBSchema.IN_AUTHORITY + String inAuthorityCsid = (String) NuxeoUtils.getProperyValue(docModel, "inAuthority"); //docModel.getPropertyValue("inAuthority"); // AuthorityItemJAXBSchema.IN_AUTHORITY additionalValues.put(UriTemplateFactory.IDENTIFIER_VAR, inAuthorityCsid); additionalValues.put(UriTemplateFactory.ITEM_IDENTIFIER_VAR, csid); } catch (Exception e) { - logger.warn("Could not extract inAuthority property from authority item record: " + e.getMessage()); + String msg = String.format("Could not extract inAuthority property from authority item with CSID = ", docModel.getName()); + logger.warn(msg, e); } } else { additionalValues.put(UriTemplateFactory.IDENTIFIER_VAR, csid); @@ -240,12 +241,18 @@ public class ServiceGroupDocumentModelHandler String value = ServiceBindingUtils.getMappedFieldInDoc(sb, ServiceBindingUtils.OBJ_NUMBER_PROP, docModel); - item.put(DOC_NUMBER_FIELD, value); + if (value != null) { + item.put(DOC_NUMBER_FIELD, value); + } + value = ServiceBindingUtils.getMappedFieldInDoc(sb, ServiceBindingUtils.OBJ_NAME_PROP, docModel); - item.put(DOC_NAME_FIELD, value); - item.put(DOC_TYPE_FIELD, docType); + if (value != null) { + item.put(DOC_NAME_FIELD, value); + } + item.put(DOC_TYPE_FIELD, docType); + // add the item to the list list.addItem(item); item.clear(); }