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.common.vocabulary.nuxeo;
26 import org.collectionspace.services.client.AuthorityClient;
27 import org.collectionspace.services.client.CollectionSpaceClient;
28 import org.collectionspace.services.client.IQueryManager;
29 import org.collectionspace.services.client.PoxPayloadIn;
30 import org.collectionspace.services.client.PoxPayloadOut;
32 import org.collectionspace.services.common.api.CommonAPI;
33 import org.collectionspace.services.common.api.RefName;
34 import org.collectionspace.services.common.api.Tools;
35 import org.collectionspace.services.common.authorityref.AuthorityRefDocList;
36 import org.collectionspace.services.common.context.MultipartServiceContext;
37 import org.collectionspace.services.common.context.ServiceContext;
38 import org.collectionspace.services.common.document.DocumentException;
39 import org.collectionspace.services.common.document.DocumentFilter;
40 import org.collectionspace.services.common.document.DocumentWrapper;
41 import org.collectionspace.services.common.document.DocumentWrapperImpl;
42 import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema;
43 import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
44 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
46 import org.collectionspace.services.config.service.ListResultField;
47 import org.collectionspace.services.config.service.ObjectPartType;
49 import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;
50 import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl;
51 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
53 import org.collectionspace.services.relation.RelationsCommonList;
54 import org.collectionspace.services.relation.RelationsDocListItem;
56 import org.collectionspace.services.vocabulary.VocabularyItemJAXBSchema;
58 import org.nuxeo.ecm.core.api.ClientException;
59 import org.nuxeo.ecm.core.api.DocumentModel;
60 import org.nuxeo.ecm.core.api.model.PropertyException;
61 import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
63 import org.slf4j.Logger;
64 import org.slf4j.LoggerFactory;
66 import javax.ws.rs.core.MultivaluedMap;
68 import java.util.ArrayList;
69 import java.util.HashMap;
70 import java.util.List;
72 import java.util.regex.Matcher;
73 import java.util.regex.Pattern;
75 //import org.collectionspace.services.common.authority.AuthorityItemRelations;
77 * AuthorityItemDocumentModelHandler
79 * $LastChangedRevision: $
82 public abstract class AuthorityItemDocumentModelHandler<AICommon>
83 extends DocHandlerBase<AICommon> {
85 private final Logger logger = LoggerFactory.getLogger(AuthorityItemDocumentModelHandler.class);
86 private String authorityItemCommonSchemaName;
87 private String authorityItemTermGroupXPathBase;
89 * inVocabulary is the parent Authority for this context
91 protected String inAuthority = null;
92 protected String authorityRefNameBase = null;
93 // Used to determine when the displayName changes as part of the update.
94 protected String oldDisplayNameOnUpdate = null;
96 public AuthorityItemDocumentModelHandler(String authorityItemCommonSchemaName) {
97 this.authorityItemCommonSchemaName = authorityItemCommonSchemaName;
101 protected String getRefnameDisplayName(DocumentWrapper<DocumentModel> docWrapper) {
102 String result = null;
104 DocumentModel docModel = docWrapper.getWrappedObject();
105 ServiceContext ctx = this.getServiceContext();
106 RefName.AuthorityItem refname = (RefName.AuthorityItem)getRefName(ctx, docModel);
107 result = refname.getDisplayName();
113 * After calling this method successfully, the document model will contain an updated refname and short ID
115 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getRefName(org.collectionspace.services.common.context.ServiceContext, org.nuxeo.ecm.core.api.DocumentModel)
118 public RefName.RefNameInterface getRefName(ServiceContext ctx,
119 DocumentModel docModel) {
120 RefName.RefNameInterface refname = null;
123 String displayName = getPrimaryDisplayName(docModel, authorityItemCommonSchemaName,
124 getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
125 if (Tools.isEmpty(displayName)) {
126 throw new Exception("The displayName for this authority term was empty or not set.");
129 String shortIdentifier = (String) docModel.getProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
130 if (Tools.isEmpty(shortIdentifier)) {
131 // We didn't find a short ID in the payload request, so we need to synthesize one.
132 shortIdentifier = handleDisplayNameAsShortIdentifier(docModel); // updates the document model with the new short ID as a side-effect
135 String authorityRefBaseName = getAuthorityRefNameBase();
136 if (Tools.isEmpty(authorityRefBaseName)) {
137 throw new Exception("Could not create the refName for this authority term, because the refName for its authority parent was empty.");
140 // Create the items refname using the parent's as a base
141 RefName.Authority parentsRefName = RefName.Authority.parse(authorityRefBaseName);
142 refname = RefName.buildAuthorityItem(parentsRefName, shortIdentifier, displayName);
143 // Now update the document model with the refname value
144 String refNameStr = refname.toString();
145 docModel.setProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.REF_NAME, refNameStr);
147 } catch (Exception e) {
148 logger.error(e.getMessage(), e);
154 public void setInAuthority(String inAuthority) {
155 this.inAuthority = inAuthority;
158 /** Subclasses may override this to customize the URI segment. */
159 public String getAuthorityServicePath() {
160 return getServiceContext().getServiceName().toLowerCase(); // Laramie20110510 CSPACE-3932
164 public String getUri(DocumentModel docModel) {
165 // Laramie20110510 CSPACE-3932
166 String authorityServicePath = getAuthorityServicePath();
167 if(inAuthority==null) { // Only happens on queries to wildcarded authorities
169 inAuthority = (String) docModel.getProperty(authorityItemCommonSchemaName,
170 AuthorityItemJAXBSchema.IN_AUTHORITY);
171 } catch (ClientException pe) {
172 throw new RuntimeException("Could not get parent specifier for item!");
175 return "/" + authorityServicePath + '/' + inAuthority + '/' + AuthorityClient.ITEMS + '/' + getCsid(docModel);
178 protected String getAuthorityRefNameBase() {
179 return this.authorityRefNameBase;
182 public void setAuthorityRefNameBase(String value) {
183 this.authorityRefNameBase = value;
187 * Note: the Vocabulary service's VocabularyItemDocumentModelHandler class overrides this method.
189 protected ListResultField getListResultsDisplayNameField() {
190 ListResultField result = new ListResultField();
191 // Per CSPACE-5132, the name of this element remains 'displayName'
192 // for backwards compatibility, although its value is obtained
193 // from the termDisplayName field.
195 // Update: this name is now being changed to 'termDisplayName', both
196 // because this is the actual field name and because the app layer
197 // work to convert over to this field is underway. Per Patrick, the
198 // app layer treats lists, in at least some context(s), as sparse record
199 // payloads, and thus fields in list results must all be present in
200 // (i.e. represent a strict subset of the fields in) record schemas.
204 // In CSPACE-5134, these list results will change substantially
205 // to return display names for both the preferred term and for
206 // each non-preferred term (if any).
207 result.setElement(AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
208 result.setXpath(NuxeoUtils.getPrimaryXPathPropertyName(
209 authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME));
215 * Note: the Vocabulary service's VocabularyItemDocumentModelHandler class overrides this method.
217 protected ListResultField getListResultsTermStatusField() {
218 ListResultField result = new ListResultField();
220 result.setElement(AuthorityItemJAXBSchema.TERM_STATUS);
221 result.setXpath(NuxeoUtils.getPrimaryXPathPropertyName(
222 authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_STATUS));
227 private boolean isTermDisplayName(String elName) {
228 return AuthorityItemJAXBSchema.TERM_DISPLAY_NAME.equals(elName) || VocabularyItemJAXBSchema.DISPLAY_NAME.equals(elName);
233 * @see org.collectionspace.services.nuxeo.client.java.DocHandlerBase#getListItemsArray()
235 * Note: We're updating the "global" service and tenant bindings instance here -the list instance here is
236 * a reference to the tenant bindings instance in the singleton ServiceMain.
239 public List<ListResultField> getListItemsArray() throws DocumentException {
240 List<ListResultField> list = super.getListItemsArray();
242 // One-time initialization for each authority item service.
243 if (isListItemArrayExtended() == false) {
244 synchronized(AuthorityItemDocumentModelHandler.class) {
245 if (isListItemArrayExtended() == false) {
246 int nFields = list.size();
247 // Ensure that each item in a list of Authority items includes
248 // a set of common fields, so we do not depend upon configuration
249 // for general logic.
250 boolean hasDisplayName = false;
251 boolean hasShortId = false;
252 boolean hasRefName = false;
253 boolean hasTermStatus = false;
254 for (int i = 0; i < nFields; i++) {
255 ListResultField field = list.get(i);
256 String elName = field.getElement();
257 if (isTermDisplayName(elName) == true) {
258 hasDisplayName = true;
259 } else if (AuthorityItemJAXBSchema.SHORT_IDENTIFIER.equals(elName)) {
261 } else if (AuthorityItemJAXBSchema.REF_NAME.equals(elName)) {
263 } else if (AuthorityItemJAXBSchema.TERM_STATUS.equals(elName)) {
264 hasTermStatus = true;
268 ListResultField field;
269 if (!hasDisplayName) {
270 field = getListResultsDisplayNameField();
274 field = new ListResultField();
275 field.setElement(AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
276 field.setXpath(AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
280 field = new ListResultField();
281 field.setElement(AuthorityItemJAXBSchema.REF_NAME);
282 field.setXpath(AuthorityItemJAXBSchema.REF_NAME);
285 if (!hasTermStatus) {
286 field = getListResultsTermStatusField();
291 setListItemArrayExtended(true);
292 } // end of synchronized block
299 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
302 public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
303 // first fill all the parts of the document, refname and short ID get set as well
304 super.handleCreate(wrapDoc);
305 // Ensure we have required fields set properly
306 handleInAuthority(wrapDoc.getWrappedObject());
310 * Note that the Vocabulary service's document-model for items overrides this method.
312 protected String getPrimaryDisplayName(DocumentModel docModel, String schema,
313 String complexPropertyName, String fieldName) {
314 String result = null;
316 result = getStringValueInPrimaryRepeatingComplexProperty(docModel, schema, complexPropertyName, fieldName);
322 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper)
325 public void handleUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
326 // First, get a copy of the old displayName
327 // oldDisplayNameOnUpdate = (String) wrapDoc.getWrappedObject().getProperty(authorityItemCommonSchemaName,
328 // AuthorityItemJAXBSchema.DISPLAY_NAME);
329 oldDisplayNameOnUpdate = getPrimaryDisplayName(wrapDoc.getWrappedObject(), authorityItemCommonSchemaName,
330 getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
331 oldRefNameOnUpdate = (String) wrapDoc.getWrappedObject().getProperty(authorityItemCommonSchemaName,
332 AuthorityItemJAXBSchema.REF_NAME);
333 super.handleUpdate(wrapDoc);
335 // Now, check the new display and handle the refname update.
336 String newDisplayName = (String) getPrimaryDisplayName(wrapDoc.getWrappedObject(), authorityItemCommonSchemaName,
337 authorityItemTermGroupXPathBase,
338 AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
339 if (newDisplayName != null && !newDisplayName.equals(oldDisplayNameOnUpdate)) {
340 // Need to update the refName, and then fix all references.
341 newRefNameOnUpdate = handleItemRefNameUpdateForDisplayName(wrapDoc.getWrappedObject(), newDisplayName);
343 // Mark as not needing attention in completeUpdate phase.
344 newRefNameOnUpdate = null;
345 oldRefNameOnUpdate = null;
350 * Handle refName updates for changes to display name.
351 * Assumes refName is already correct. Just ensures it is right.
353 * @param docModel the doc model
354 * @param newDisplayName the new display name
355 * @throws Exception the exception
357 protected String handleItemRefNameUpdateForDisplayName(DocumentModel docModel,
358 String newDisplayName) throws Exception {
359 RefName.AuthorityItem authItem = RefName.AuthorityItem.parse(oldRefNameOnUpdate);
360 if (authItem == null) {
361 String err = "Authority Item has illegal refName: " + oldRefNameOnUpdate;
363 throw new IllegalArgumentException(err);
365 authItem.displayName = newDisplayName;
366 String updatedRefName = authItem.toString();
367 docModel.setProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.REF_NAME, updatedRefName);
368 return updatedRefName;
372 * If no short identifier was provided in the input payload, generate a
373 * short identifier from the preferred term display name or term name.
375 private String handleDisplayNameAsShortIdentifier(DocumentModel docModel) throws Exception {
376 String result = (String) docModel.getProperty(authorityItemCommonSchemaName,
377 AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
379 if (Tools.isEmpty(result)) {
380 String termDisplayName = getPrimaryDisplayName(
381 docModel, authorityItemCommonSchemaName,
382 getItemTermInfoGroupXPathBase(),
383 AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
385 String termName = getPrimaryDisplayName(
386 docModel, authorityItemCommonSchemaName,
387 getItemTermInfoGroupXPathBase(),
388 AuthorityItemJAXBSchema.TERM_NAME);
390 String generatedShortIdentifier = AuthorityIdentifierUtils.generateShortIdentifierFromDisplayName(termDisplayName,
392 docModel.setProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER,
393 generatedShortIdentifier);
394 result = generatedShortIdentifier;
401 * Generate a refName for the authority item from the short identifier
404 * All refNames for authority items are generated. If a client supplies
405 * a refName, it will be overwritten during create (per this method)
406 * or discarded during update (per filterReadOnlyPropertiesForPart).
408 * @see #filterReadOnlyPropertiesForPart(Map<String, Object>, org.collectionspace.services.common.service.ObjectPartType)
411 protected String updateRefnameForAuthorityItem(DocumentModel docModel,
412 String schemaName) throws Exception {
413 String result = null;
415 RefName.RefNameInterface refname = getRefName(getServiceContext(), docModel);
416 String refNameStr = refname.toString();
417 docModel.setProperty(schemaName, AuthorityItemJAXBSchema.REF_NAME, refNameStr);
424 * Check the logic around the parent pointer. Note that we only need do this on
425 * create, since we have logic to make this read-only on update.
429 * @throws Exception the exception
431 private void handleInAuthority(DocumentModel docModel) throws Exception {
432 if(inAuthority==null) { // Only happens on queries to wildcarded authorities
433 throw new IllegalStateException("Trying to Create an object with no inAuthority value!");
435 docModel.setProperty(authorityItemCommonSchemaName,
436 AuthorityItemJAXBSchema.IN_AUTHORITY, inAuthority);
439 public AuthorityRefDocList getReferencingObjects(
440 ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
441 List<String> serviceTypes,
443 String itemcsid) throws Exception {
444 AuthorityRefDocList authRefDocList = null;
445 RepositoryInstance repoSession = null;
446 boolean releaseRepoSession = false;
449 RepositoryJavaClientImpl repoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx);
450 repoSession = this.getRepositorySession();
451 if (repoSession == null) {
452 repoSession = repoClient.getRepositorySession(ctx);
453 releaseRepoSession = true;
455 DocumentFilter myFilter = getDocumentFilter();
458 DocumentWrapper<DocumentModel> wrapper = repoClient.getDoc(repoSession, ctx, itemcsid);
459 DocumentModel docModel = wrapper.getWrappedObject();
460 String refName = (String) docModel.getPropertyValue(AuthorityItemJAXBSchema.REF_NAME);
461 authRefDocList = RefNameServiceUtils.getAuthorityRefDocs(
462 repoSession, ctx, repoClient,
466 myFilter, true /*computeTotal*/);
467 } catch (PropertyException pe) {
469 } catch (DocumentException de) {
471 } catch (Exception e) {
472 if (logger.isDebugEnabled()) {
473 logger.debug("Caught exception ", e);
475 throw new DocumentException(e);
477 // If we got/aquired a new seesion then we're responsible for releasing it.
478 if (releaseRepoSession && repoSession != null) {
479 repoClient.releaseRepositorySession(ctx, repoSession);
482 } catch (Exception e) {
483 if (logger.isDebugEnabled()) {
484 logger.debug("Caught exception ", e);
486 throw new DocumentException(e);
489 return authRefDocList;
493 * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#extractPart(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, org.collectionspace.services.common.service.ObjectPartType)
496 protected Map<String, Object> extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta)
498 Map<String, Object> unQObjectProperties = super.extractPart(docModel, schema, partMeta);
500 // Add the CSID to the common part, since they may have fetched via the shortId.
501 if (partMeta.getLabel().equalsIgnoreCase(authorityItemCommonSchemaName)) {
502 String csid = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
503 unQObjectProperties.put("csid", csid);
506 return unQObjectProperties;
510 * Filters out selected values supplied in an update request.
512 * For example, filters out AuthorityItemJAXBSchema.IN_AUTHORITY, to ensure
513 * that the link to the item's parent remains untouched.
515 * @param objectProps the properties filtered out from the update payload
516 * @param partMeta metadata for the object to fill
519 public void filterReadOnlyPropertiesForPart(
520 Map<String, Object> objectProps, ObjectPartType partMeta) {
521 super.filterReadOnlyPropertiesForPart(objectProps, partMeta);
522 String commonPartLabel = getServiceContext().getCommonPartLabel();
523 if (partMeta.getLabel().equalsIgnoreCase(commonPartLabel)) {
524 objectProps.remove(AuthorityItemJAXBSchema.IN_AUTHORITY);
525 objectProps.remove(AuthorityItemJAXBSchema.CSID);
526 objectProps.remove(AuthorityJAXBSchema.SHORT_IDENTIFIER);
527 objectProps.remove(AuthorityItemJAXBSchema.REF_NAME);
531 protected List<String> getPartialTermDisplayNameMatches(List<String> termDisplayNameList, String partialTerm) {
532 List<String> result = new ArrayList<String>();
534 for (String termDisplayName : termDisplayNameList) {
535 if (termDisplayName.toLowerCase().contains(partialTerm.toLowerCase()) == true) {
536 result.add(termDisplayName);
543 @SuppressWarnings("unchecked")
544 private List<String> getPartialTermDisplayNameMatches(DocumentModel docModel, // REM - CSPACE-5133
545 String schema, ListResultField field, String partialTerm) {
546 List<String> result = null;
548 String xpath = field.getXpath(); // results in something like "persons_common:personTermGroupList/[0]/termDisplayName"
549 int endOfTermGroup = xpath.lastIndexOf("/[0]/");
550 String propertyName = endOfTermGroup != -1 ? xpath.substring(0, endOfTermGroup) : xpath; // it may not be multivalued so the xpath passed in would be the property name
554 value = docModel.getProperty(schema, propertyName);
555 } catch (Exception e) {
556 logger.error("Could not extract term display name with property = "
560 if (value != null && value instanceof ArrayList) {
561 ArrayList<HashMap<String, Object>> termGroupList = (ArrayList<HashMap<String, Object>>)value;
562 int arrayListSize = termGroupList.size();
563 if (arrayListSize > 1) { // if there's only 1 element in the list then we've already matched the primary term's display name
564 List<String> displayNameList = new ArrayList<String>();
565 for (int i = 1; i < arrayListSize; i++) { // start at 1, skip the primary term's displayName since we will always return it
566 HashMap<String, Object> map = (HashMap<String, Object>)termGroupList.get(i);
567 String termDisplayName = (String) map.get(AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
568 displayNameList.add(i - 1, termDisplayName);
571 result = getPartialTermDisplayNameMatches(displayNameList, partialTerm);
579 protected Object getListResultValue(DocumentModel docModel, // REM - CSPACE-5133
580 String schema, ListResultField field) {
581 Object result = null;
583 result = NuxeoUtils.getXPathValue(docModel, schema, field.getXpath());
584 String elName = field.getElement();
586 // If the list result value is the termDisplayName element, we need to check to see if a partial term query was made.
588 if (isTermDisplayName(elName) == true) {
589 MultivaluedMap<String, String> queryParams = this.getServiceContext().getQueryParams();
590 String partialTerm = queryParams != null ? queryParams.getFirst(IQueryManager.SEARCH_TYPE_PARTIALTERM) : null;
591 if (partialTerm != null && partialTerm.trim().isEmpty() == false) {
592 String primaryTermDisplayName = (String)result;
593 List<String> matches = getPartialTermDisplayNameMatches(docModel, schema, field, partialTerm);
594 if (matches != null && matches.isEmpty() == false) {
595 matches.add(0, primaryTermDisplayName); // insert the primary term's display name at the beginning of the list
596 result = matches; // set the result to a list of matching term display names with the primary term's display name at the beginning
605 public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
606 MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
607 super.extractAllParts(wrapDoc);
609 String showSiblings = ctx.getQueryParams().getFirst(CommonAPI.showSiblings_QP);
610 if (Tools.isTrue(showSiblings)) {
611 showSiblings(wrapDoc, ctx);
612 return; // actual result is returned on ctx.addOutputPart();
615 String showRelations = ctx.getQueryParams().getFirst(CommonAPI.showRelations_QP);
616 if (Tools.isTrue(showRelations)) {
617 showRelations(wrapDoc, ctx);
618 return; // actual result is returned on ctx.addOutputPart();
621 String showAllRelations = ctx.getQueryParams().getFirst(CommonAPI.showAllRelations_QP);
622 if (Tools.isTrue(showAllRelations)) {
623 showAllRelations(wrapDoc, ctx);
624 return; // actual result is returned on ctx.addOutputPart();
629 public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception {
631 // We currently don't override this method with any AuthorityItemDocumentModelHandler specific functionality, so
632 // we could remove this method.
634 super.fillAllParts(wrapDoc, action);
637 protected List<RelationsCommonList.RelationListItem> cloneList(List<RelationsCommonList.RelationListItem> inboundList) {
638 List<RelationsCommonList.RelationListItem> result = newRelationsCommonList();
639 for (RelationsCommonList.RelationListItem item : inboundList) {
645 // Note that item2 may be sparse (only refName, no CSID for subject or object)
646 // But item1 must not be sparse
647 private boolean itemsEqual(RelationsCommonList.RelationListItem item1, RelationsCommonList.RelationListItem item2) {
648 if (item1 == null || item2 == null) {
651 RelationsDocListItem subj1 = item1.getSubject();
652 RelationsDocListItem subj2 = item2.getSubject();
653 RelationsDocListItem obj1 = item1.getObject();
654 RelationsDocListItem obj2 = item2.getObject();
655 String subj1Csid = subj1.getCsid();
656 String subj2Csid = subj2.getCsid();
657 String subj1RefName = subj1.getRefName();
658 String subj2RefName = subj2.getRefName();
660 String obj1Csid = obj1.getCsid();
661 String obj2Csid = obj2.getCsid();
662 String obj1RefName = obj1.getRefName();
663 String obj2RefName = obj2.getRefName();
666 (subj1Csid.equals(subj2Csid) || ((subj2Csid==null) && subj1RefName.equals(subj2RefName)))
667 && (obj1Csid.equals(obj1Csid) || ((obj2Csid==null) && obj1RefName.equals(obj2RefName)))
668 // predicate is proper, but still allow relationshipType
669 && (item1.getPredicate().equals(item2.getPredicate())
670 || ((item2.getPredicate()==null) && item1.getRelationshipType().equals(item2.getRelationshipType())))
671 // Allow missing docTypes, so long as they do not conflict
672 && (obj1.getDocumentType().equals(obj2.getDocumentType()) || obj2.getDocumentType()==null)
673 && (subj1.getDocumentType().equals(subj2.getDocumentType()) || subj2.getDocumentType()==null);
678 /* don't even THINK of re-using this method.
679 * String example_uri = "/locationauthorities/7ec60f01-84ab-4908-9a6a/items/a5466530-713f-43b4-bc05";
681 private String extractInAuthorityCSID(String uri) {
682 String IN_AUTHORITY_REGEX = "/(.*?)/(.*?)/(.*)";
683 Pattern p = Pattern.compile(IN_AUTHORITY_REGEX);
684 Matcher m = p.matcher(uri);
686 if (m.groupCount() < 3) {
687 logger.warn("REGEX-WRONG-GROUPCOUNT looking in " + uri);
690 //String service = m.group(1);
691 String inauth = m.group(2);
692 //String theRest = m.group(3);
694 //print("service:"+service+", inauth:"+inauth+", rest:"+rest);
697 logger.warn("REGEX-NOT-MATCHED looking in " + uri);
702 //ensures CSPACE-4042
703 protected void uriPointsToSameAuthority(String thisURI, String inboundItemURI) throws Exception {
704 String authorityCSID = extractInAuthorityCSID(thisURI);
705 String authorityCSIDForInbound = extractInAuthorityCSID(inboundItemURI);
706 if (Tools.isBlank(authorityCSID)
707 || Tools.isBlank(authorityCSIDForInbound)
708 || (!authorityCSID.equalsIgnoreCase(authorityCSIDForInbound))) {
709 throw new Exception("Item URI " + thisURI + " must point to same authority as related item: " + inboundItemURI);
713 public String getItemTermInfoGroupXPathBase() {
714 return authorityItemTermGroupXPathBase;
717 public void setItemTermInfoGroupXPathBase(String itemTermInfoGroupXPathBase) {
718 authorityItemTermGroupXPathBase = itemTermInfoGroupXPathBase;
721 protected String getAuthorityItemCommonSchemaName() {
722 return authorityItemCommonSchemaName;