try {
DocumentWrapper<DocumentModel> 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,
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;
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;
try {
DocumentWrapper<DocumentModel> 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<String> forDocTypeList = (List<String>) docModel.getPropertyValue(BatchJAXBSchema.FOR_DOC_TYPES);
+ List<String> forDocTypeList = (List<String>) 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);
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) {
+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<String> commonProcedureServiceTypes = null;
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);
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());
* @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.
*
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());
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,
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) {
+ "}:" + 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;
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;
+invocationMode);
}
-
RepositoryJavaClientImpl repoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx);
repoSession = this.getRepositorySession();
if (repoSession == null) {
try {
DocumentWrapper<DocumentModel> 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<String> forDocTypeList =
- (List<String>)docModel.getPropertyValue(InvocableJAXBSchema.FOR_DOC_TYPES);
- if(forDocTypeList==null
- || !forDocTypeList.contains(invContext.getDocType())) {
+ (List<String>) 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 {
Map<String, String> additionalValues = new HashMap<String, String>();
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);
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();
}