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.IQueryManager;
28 import org.collectionspace.services.client.PoxPayloadIn;
29 import org.collectionspace.services.client.PoxPayloadOut;
31 import org.collectionspace.services.common.api.CommonAPI;
32 import org.collectionspace.services.common.api.RefName;
33 import org.collectionspace.services.common.api.Tools;
34 import org.collectionspace.services.common.authorityref.AuthorityRefDocList;
35 import org.collectionspace.services.common.context.MultipartServiceContext;
36 import org.collectionspace.services.common.context.ServiceContext;
37 import org.collectionspace.services.common.document.DocumentException;
38 import org.collectionspace.services.common.document.DocumentFilter;
39 import org.collectionspace.services.common.document.DocumentWrapper;
40 import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema;
41 import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
42 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
44 import org.collectionspace.services.config.service.ListResultField;
45 import org.collectionspace.services.config.service.ObjectPartType;
47 import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;
48 import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl;
49 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
51 import org.collectionspace.services.relation.RelationsCommonList;
52 import org.collectionspace.services.relation.RelationsDocListItem;
54 import org.collectionspace.services.vocabulary.VocabularyItemJAXBSchema;
56 import org.nuxeo.ecm.core.api.ClientException;
57 import org.nuxeo.ecm.core.api.DocumentModel;
58 import org.nuxeo.ecm.core.api.model.PropertyException;
59 import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
61 import org.slf4j.Logger;
62 import org.slf4j.LoggerFactory;
64 import javax.ws.rs.core.MultivaluedMap;
66 import java.util.ArrayList;
67 import java.util.HashMap;
68 import java.util.List;
70 import java.util.regex.Matcher;
71 import java.util.regex.Pattern;
73 //import org.collectionspace.services.common.authority.AuthorityItemRelations;
75 * AuthorityItemDocumentModelHandler
77 * $LastChangedRevision: $
80 public abstract class AuthorityItemDocumentModelHandler<AICommon>
81 extends DocHandlerBase<AICommon> {
83 private final Logger logger = LoggerFactory.getLogger(AuthorityItemDocumentModelHandler.class);
84 private String authorityItemCommonSchemaName;
85 private String authorityItemTermGroupXPathBase;
87 * inVocabulary is the parent Authority for this context
89 protected String inAuthority = null;
90 protected String authorityRefNameBase = null;
91 // Used to determine when the displayName changes as part of the update.
92 protected String oldDisplayNameOnUpdate = null;
94 public AuthorityItemDocumentModelHandler(String authorityItemCommonSchemaName) {
95 this.authorityItemCommonSchemaName = authorityItemCommonSchemaName;
98 public void setInAuthority(String inAuthority) {
99 this.inAuthority = inAuthority;
102 /** Subclasses may override this to customize the URI segment. */
103 public String getAuthorityServicePath() {
104 return getServiceContext().getServiceName().toLowerCase(); // Laramie20110510 CSPACE-3932
108 public String getUri(DocumentModel docModel) {
109 // Laramie20110510 CSPACE-3932
110 String authorityServicePath = getAuthorityServicePath();
111 if(inAuthority==null) { // Only happens on queries to wildcarded authorities
113 inAuthority = (String) docModel.getProperty(authorityItemCommonSchemaName,
114 AuthorityItemJAXBSchema.IN_AUTHORITY);
115 } catch (ClientException pe) {
116 throw new RuntimeException("Could not get parent specifier for item!");
119 return "/" + authorityServicePath + '/' + inAuthority + '/' + AuthorityClient.ITEMS + '/' + getCsid(docModel);
122 protected String getAuthorityRefNameBase() {
123 return this.authorityRefNameBase;
126 public void setAuthorityRefNameBase(String value) {
127 this.authorityRefNameBase = value;
131 * Note: the Vocabulary service's VocabularyItemDocumentModelHandler class overrides this method.
133 protected ListResultField getListResultsDisplayNameField() {
134 ListResultField result = new ListResultField();
135 // Per CSPACE-5132, the name of this element remains 'displayName'
136 // for backwards compatibility, although its value is obtained
137 // from the termDisplayName field.
139 // Update: this name is now being changed to 'termDisplayName', both
140 // because this is the actual field name and because the app layer
141 // work to convert over to this field is underway. Per Patrick, the
142 // app layer treats lists, in at least some context(s), as sparse record
143 // payloads, and thus fields in list results must all be present in
144 // (i.e. represent a strict subset of the fields in) record schemas.
148 // In CSPACE-5134, these list results will change substantially
149 // to return display names for both the preferred term and for
150 // each non-preferred term (if any).
151 result.setElement(AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
152 result.setXpath(NuxeoUtils.getPrimaryXPathPropertyName(
153 authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME));
159 * Note: the Vocabulary service's VocabularyItemDocumentModelHandler class overrides this method.
161 protected ListResultField getListResultsTermStatusField() {
162 ListResultField result = new ListResultField();
164 result.setElement(AuthorityItemJAXBSchema.TERM_STATUS);
165 result.setXpath(NuxeoUtils.getPrimaryXPathPropertyName(
166 authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_STATUS));
171 private boolean isTermDisplayName(String elName) {
172 return AuthorityItemJAXBSchema.TERM_DISPLAY_NAME.equals(elName) || VocabularyItemJAXBSchema.DISPLAY_NAME.equals(elName);
177 * @see org.collectionspace.services.nuxeo.client.java.DocHandlerBase#getListItemsArray()
179 * Note: We're updating the "global" service and tenant bindings instance here -the list instance here is
180 * a reference to the tenant bindings instance in the singleton ServiceMain.
183 public List<ListResultField> getListItemsArray() throws DocumentException {
184 List<ListResultField> list = super.getListItemsArray();
186 // One-time initialization for each authority item service.
187 if (isListItemArrayExtended() == false) {
188 synchronized(AuthorityItemDocumentModelHandler.class) {
189 if (isListItemArrayExtended() == false) {
190 int nFields = list.size();
191 // Ensure that each item in a list of Authority items includes
192 // a set of common fields, so we do not depend upon configuration
193 // for general logic.
194 boolean hasDisplayName = false;
195 boolean hasShortId = false;
196 boolean hasRefName = false;
197 boolean hasTermStatus = false;
198 for (int i = 0; i < nFields; i++) {
199 ListResultField field = list.get(i);
200 String elName = field.getElement();
201 if (isTermDisplayName(elName) == true) {
202 hasDisplayName = true;
203 } else if (AuthorityItemJAXBSchema.SHORT_IDENTIFIER.equals(elName)) {
205 } else if (AuthorityItemJAXBSchema.REF_NAME.equals(elName)) {
207 } else if (AuthorityItemJAXBSchema.TERM_STATUS.equals(elName)) {
208 hasTermStatus = true;
212 ListResultField field;
213 if (!hasDisplayName) {
214 field = getListResultsDisplayNameField();
218 field = new ListResultField();
219 field.setElement(AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
220 field.setXpath(AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
224 field = new ListResultField();
225 field.setElement(AuthorityItemJAXBSchema.REF_NAME);
226 field.setXpath(AuthorityItemJAXBSchema.REF_NAME);
229 if (!hasTermStatus) {
230 field = getListResultsTermStatusField();
235 setListItemArrayExtended(true);
236 } // end of synchronized block
243 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
246 public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
247 // first fill all the parts of the document
248 super.handleCreate(wrapDoc);
249 // Ensure we have required fields set properly
250 handleInAuthority(wrapDoc.getWrappedObject());
252 // FIXME: This call to synthesize a shortIdentifier from the termDisplayName
253 // of the preferred term may have been commented out, in the course of
254 // adding support for preferred / non-preferred terms, in CSPACE-4813
255 // and linked issues. Revisit this to determine whether we want to
259 handleDisplayNameAsShortIdentifier(wrapDoc.getWrappedObject(), authorityItemCommonSchemaName);
260 // refName includes displayName, so we force a correct value here.
261 updateRefnameForAuthorityItem(wrapDoc, authorityItemCommonSchemaName, getAuthorityRefNameBase());
265 * Note that the Vocabulary service's document-model for items overrides this method.
267 protected String getPrimaryDisplayName(DocumentModel docModel, String schema,
268 String complexPropertyName, String fieldName) {
269 String result = null;
271 result = getStringValueInPrimaryRepeatingComplexProperty(docModel, schema, complexPropertyName, fieldName);
277 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper)
280 public void handleUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
281 // First, get a copy of the old displayName
282 // oldDisplayNameOnUpdate = (String) wrapDoc.getWrappedObject().getProperty(authorityItemCommonSchemaName,
283 // AuthorityItemJAXBSchema.DISPLAY_NAME);
284 oldDisplayNameOnUpdate = getPrimaryDisplayName(wrapDoc.getWrappedObject(), authorityItemCommonSchemaName,
285 getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
286 oldRefNameOnUpdate = (String) wrapDoc.getWrappedObject().getProperty(authorityItemCommonSchemaName,
287 AuthorityItemJAXBSchema.REF_NAME);
288 super.handleUpdate(wrapDoc);
290 // Now, check the new display and handle the refname update.
291 String newDisplayName = (String) getPrimaryDisplayName(wrapDoc.getWrappedObject(), authorityItemCommonSchemaName,
292 authorityItemTermGroupXPathBase,
293 AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
294 if (newDisplayName != null && !newDisplayName.equals(oldDisplayNameOnUpdate)) {
295 // Need to update the refName, and then fix all references.
296 newRefNameOnUpdate = handleItemRefNameUpdateForDisplayName(wrapDoc.getWrappedObject(), newDisplayName);
298 // Mark as not needing attention in completeUpdate phase.
299 newRefNameOnUpdate = null;
300 oldRefNameOnUpdate = null;
305 * Handle refName updates for changes to display name.
306 * Assumes refName is already correct. Just ensures it is right.
308 * @param docModel the doc model
309 * @param newDisplayName the new display name
310 * @throws Exception the exception
312 protected String handleItemRefNameUpdateForDisplayName(DocumentModel docModel,
313 String newDisplayName) throws Exception {
314 RefName.AuthorityItem authItem = RefName.AuthorityItem.parse(oldRefNameOnUpdate);
315 if (authItem == null) {
316 String err = "Authority Item has illegal refName: " + oldRefNameOnUpdate;
318 throw new IllegalArgumentException(err);
320 authItem.displayName = newDisplayName;
321 String updatedRefName = authItem.toString();
322 docModel.setProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.REF_NAME, updatedRefName);
323 return updatedRefName;
327 * If no short identifier was provided in the input payload, generate a
328 * short identifier from the preferred term display name or term name.
330 private void handleDisplayNameAsShortIdentifier(DocumentModel docModel,
331 String schemaName) throws Exception {
332 String shortIdentifier = (String) docModel.getProperty(schemaName,
333 AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
335 if (Tools.isEmpty(shortIdentifier)) {
336 String termDisplayName = getPrimaryDisplayName(
337 docModel, authorityItemCommonSchemaName,
338 getItemTermInfoGroupXPathBase(),
339 AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
341 String termName = getPrimaryDisplayName(
342 docModel, authorityItemCommonSchemaName,
343 getItemTermInfoGroupXPathBase(),
344 AuthorityItemJAXBSchema.TERM_NAME);
346 String generatedShortIdentifier = AuthorityIdentifierUtils.generateShortIdentifierFromDisplayName(termDisplayName,
348 docModel.setProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER,
349 generatedShortIdentifier);
354 * Generate a refName for the authority item from the short identifier
357 * All refNames for authority items are generated. If a client supplies
358 * a refName, it will be overwritten during create (per this method)
359 * or discarded during update (per filterReadOnlyPropertiesForPart).
361 * @see #filterReadOnlyPropertiesForPart(Map<String, Object>, org.collectionspace.services.common.service.ObjectPartType)
364 protected void updateRefnameForAuthorityItem(DocumentWrapper<DocumentModel> wrapDoc,
366 String authorityRefBaseName) throws Exception {
367 DocumentModel docModel = wrapDoc.getWrappedObject();
368 String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
369 String displayName = getPrimaryDisplayName(docModel, authorityItemCommonSchemaName,
370 getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
372 if (Tools.isEmpty(authorityRefBaseName)) {
373 throw new Exception("Could not create the refName for this authority term, because the refName for its authority parent was empty.");
376 RefName.Authority authority = RefName.Authority.parse(authorityRefBaseName);
377 String refName = RefName.buildAuthorityItem(authority, shortIdentifier, displayName).toString();
378 docModel.setProperty(schemaName, AuthorityItemJAXBSchema.REF_NAME, refName);
382 * Check the logic around the parent pointer. Note that we only need do this on
383 * create, since we have logic to make this read-only on update.
387 * @throws Exception the exception
389 private void handleInAuthority(DocumentModel docModel) throws Exception {
390 if(inAuthority==null) { // Only happens on queries to wildcarded authorities
391 throw new IllegalStateException("Trying to Create an object with no inAuthority value!");
393 docModel.setProperty(authorityItemCommonSchemaName,
394 AuthorityItemJAXBSchema.IN_AUTHORITY, inAuthority);
397 public AuthorityRefDocList getReferencingObjects(
398 ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
399 List<String> serviceTypes,
401 String itemcsid) throws Exception {
402 AuthorityRefDocList authRefDocList = null;
403 RepositoryInstance repoSession = null;
404 boolean releaseRepoSession = false;
407 RepositoryJavaClientImpl repoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx);
408 repoSession = this.getRepositorySession();
409 if (repoSession == null) {
410 repoSession = repoClient.getRepositorySession(ctx);
411 releaseRepoSession = true;
413 DocumentFilter myFilter = getDocumentFilter();
416 DocumentWrapper<DocumentModel> wrapper = repoClient.getDoc(repoSession, ctx, itemcsid);
417 DocumentModel docModel = wrapper.getWrappedObject();
418 String refName = (String) docModel.getPropertyValue(AuthorityItemJAXBSchema.REF_NAME);
419 authRefDocList = RefNameServiceUtils.getAuthorityRefDocs(
420 repoSession, ctx, repoClient,
424 myFilter, true /*computeTotal*/);
425 } catch (PropertyException pe) {
427 } catch (DocumentException de) {
429 } catch (Exception e) {
430 if (logger.isDebugEnabled()) {
431 logger.debug("Caught exception ", e);
433 throw new DocumentException(e);
435 // If we got/aquired a new seesion then we're responsible for releasing it.
436 if (releaseRepoSession && repoSession != null) {
437 repoClient.releaseRepositorySession(ctx, repoSession);
440 } catch (Exception e) {
441 if (logger.isDebugEnabled()) {
442 logger.debug("Caught exception ", e);
444 throw new DocumentException(e);
447 return authRefDocList;
451 * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#extractPart(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, org.collectionspace.services.common.service.ObjectPartType)
454 protected Map<String, Object> extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta)
456 Map<String, Object> unQObjectProperties = super.extractPart(docModel, schema, partMeta);
458 // Add the CSID to the common part, since they may have fetched via the shortId.
459 if (partMeta.getLabel().equalsIgnoreCase(authorityItemCommonSchemaName)) {
460 String csid = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
461 unQObjectProperties.put("csid", csid);
464 return unQObjectProperties;
468 * Filters out selected values supplied in an update request.
470 * For example, filters out AuthorityItemJAXBSchema.IN_AUTHORITY, to ensure
471 * that the link to the item's parent remains untouched.
473 * @param objectProps the properties filtered out from the update payload
474 * @param partMeta metadata for the object to fill
477 public void filterReadOnlyPropertiesForPart(
478 Map<String, Object> objectProps, ObjectPartType partMeta) {
479 super.filterReadOnlyPropertiesForPart(objectProps, partMeta);
480 String commonPartLabel = getServiceContext().getCommonPartLabel();
481 if (partMeta.getLabel().equalsIgnoreCase(commonPartLabel)) {
482 objectProps.remove(AuthorityItemJAXBSchema.IN_AUTHORITY);
483 objectProps.remove(AuthorityItemJAXBSchema.CSID);
484 objectProps.remove(AuthorityJAXBSchema.SHORT_IDENTIFIER);
485 objectProps.remove(AuthorityItemJAXBSchema.REF_NAME);
489 protected List<String> getPartialTermDisplayNameMatches(List<String> termDisplayNameList, String partialTerm) {
490 List<String> result = new ArrayList<String>();
492 for (String termDisplayName : termDisplayNameList) {
493 if (termDisplayName.toLowerCase().contains(partialTerm.toLowerCase()) == true) {
494 result.add(termDisplayName);
501 @SuppressWarnings("unchecked")
502 private List<String> getPartialTermDisplayNameMatches(DocumentModel docModel, // REM - CSPACE-5133
503 String schema, ListResultField field, String partialTerm) {
504 List<String> result = null;
506 String xpath = field.getXpath(); // results in something like "persons_common:personTermGroupList/[0]/termDisplayName"
507 int endOfTermGroup = xpath.lastIndexOf("/[0]/");
508 String propertyName = endOfTermGroup != -1 ? xpath.substring(0, endOfTermGroup) : xpath; // it may not be multivalued so the xpath passed in would be the property name
512 value = docModel.getProperty(schema, propertyName);
513 } catch (Exception e) {
514 logger.error("Could not extract term display name with property = "
518 if (value != null && value instanceof ArrayList) {
519 ArrayList<HashMap<String, Object>> termGroupList = (ArrayList<HashMap<String, Object>>)value;
520 int arrayListSize = termGroupList.size();
521 if (arrayListSize > 1) { // if there's only 1 element in the list then we've already matched the primary term's display name
522 List<String> displayNameList = new ArrayList<String>();
523 for (int i = 1; i < arrayListSize; i++) { // start at 1, skip the primary term's displayName since we will always return it
524 HashMap<String, Object> map = (HashMap<String, Object>)termGroupList.get(i);
525 String termDisplayName = (String) map.get(AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
526 displayNameList.add(i - 1, termDisplayName);
529 result = getPartialTermDisplayNameMatches(displayNameList, partialTerm);
537 protected Object getListResultValue(DocumentModel docModel, // REM - CSPACE-5133
538 String schema, ListResultField field) {
539 Object result = null;
541 result = NuxeoUtils.getXPathValue(docModel, schema, field.getXpath());
542 String elName = field.getElement();
544 // If the list result value is the termDisplayName element, we need to check to see if a partial term query was made.
546 if (isTermDisplayName(elName) == true) {
547 MultivaluedMap<String, String> queryParams = this.getServiceContext().getQueryParams();
548 String partialTerm = queryParams != null ? queryParams.getFirst(IQueryManager.SEARCH_TYPE_PARTIALTERM) : null;
549 if (partialTerm != null && partialTerm.trim().isEmpty() == false) {
550 String primaryTermDisplayName = (String)result;
551 List<String> matches = getPartialTermDisplayNameMatches(docModel, schema, field, partialTerm);
552 if (matches != null && matches.isEmpty() == false) {
553 matches.add(0, primaryTermDisplayName); // insert the primary term's display name at the beginning of the list
554 result = matches; // set the result to a list of matching term display names with the primary term's display name at the beginning
563 public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
564 MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
565 super.extractAllParts(wrapDoc);
567 String showSiblings = ctx.getQueryParams().getFirst(CommonAPI.showSiblings_QP);
568 if (Tools.isTrue(showSiblings)) {
569 showSiblings(wrapDoc, ctx);
570 return; // actual result is returned on ctx.addOutputPart();
573 String showRelations = ctx.getQueryParams().getFirst(CommonAPI.showRelations_QP);
574 if (Tools.isTrue(showRelations)) {
575 showRelations(wrapDoc, ctx);
576 return; // actual result is returned on ctx.addOutputPart();
579 String showAllRelations = ctx.getQueryParams().getFirst(CommonAPI.showAllRelations_QP);
580 if (Tools.isTrue(showAllRelations)) {
581 showAllRelations(wrapDoc, ctx);
582 return; // actual result is returned on ctx.addOutputPart();
587 public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception {
589 // We currently don't override this method with any AuthorityItemDocumentModelHandler specific functionality, so
590 // we could remove this method.
592 super.fillAllParts(wrapDoc, action);
595 protected List<RelationsCommonList.RelationListItem> cloneList(List<RelationsCommonList.RelationListItem> inboundList) {
596 List<RelationsCommonList.RelationListItem> result = newRelationsCommonList();
597 for (RelationsCommonList.RelationListItem item : inboundList) {
603 // Note that item2 may be sparse (only refName, no CSID for subject or object)
604 // But item1 must not be sparse
605 private boolean itemsEqual(RelationsCommonList.RelationListItem item1, RelationsCommonList.RelationListItem item2) {
606 if (item1 == null || item2 == null) {
609 RelationsDocListItem subj1 = item1.getSubject();
610 RelationsDocListItem subj2 = item2.getSubject();
611 RelationsDocListItem obj1 = item1.getObject();
612 RelationsDocListItem obj2 = item2.getObject();
613 String subj1Csid = subj1.getCsid();
614 String subj2Csid = subj2.getCsid();
615 String subj1RefName = subj1.getRefName();
616 String subj2RefName = subj2.getRefName();
618 String obj1Csid = obj1.getCsid();
619 String obj2Csid = obj2.getCsid();
620 String obj1RefName = obj1.getRefName();
621 String obj2RefName = obj2.getRefName();
624 (subj1Csid.equals(subj2Csid) || ((subj2Csid==null) && subj1RefName.equals(subj2RefName)))
625 && (obj1Csid.equals(obj1Csid) || ((obj2Csid==null) && obj1RefName.equals(obj2RefName)))
626 // predicate is proper, but still allow relationshipType
627 && (item1.getPredicate().equals(item2.getPredicate())
628 || ((item2.getPredicate()==null) && item1.getRelationshipType().equals(item2.getRelationshipType())))
629 // Allow missing docTypes, so long as they do not conflict
630 && (obj1.getDocumentType().equals(obj2.getDocumentType()) || obj2.getDocumentType()==null)
631 && (subj1.getDocumentType().equals(subj2.getDocumentType()) || subj2.getDocumentType()==null);
636 /* don't even THINK of re-using this method.
637 * String example_uri = "/locationauthorities/7ec60f01-84ab-4908-9a6a/items/a5466530-713f-43b4-bc05";
639 private String extractInAuthorityCSID(String uri) {
640 String IN_AUTHORITY_REGEX = "/(.*?)/(.*?)/(.*)";
641 Pattern p = Pattern.compile(IN_AUTHORITY_REGEX);
642 Matcher m = p.matcher(uri);
644 if (m.groupCount() < 3) {
645 logger.warn("REGEX-WRONG-GROUPCOUNT looking in " + uri);
648 //String service = m.group(1);
649 String inauth = m.group(2);
650 //String theRest = m.group(3);
652 //print("service:"+service+", inauth:"+inauth+", rest:"+rest);
655 logger.warn("REGEX-NOT-MATCHED looking in " + uri);
660 //ensures CSPACE-4042
661 protected void uriPointsToSameAuthority(String thisURI, String inboundItemURI) throws Exception {
662 String authorityCSID = extractInAuthorityCSID(thisURI);
663 String authorityCSIDForInbound = extractInAuthorityCSID(inboundItemURI);
664 if (Tools.isBlank(authorityCSID)
665 || Tools.isBlank(authorityCSIDForInbound)
666 || (!authorityCSID.equalsIgnoreCase(authorityCSIDForInbound))) {
667 throw new Exception("Item URI " + thisURI + " must point to same authority as related item: " + inboundItemURI);
671 public String getItemTermInfoGroupXPathBase() {
672 return authorityItemTermGroupXPathBase;
675 public void setItemTermInfoGroupXPathBase(String itemTermInfoGroupXPathBase) {
676 authorityItemTermGroupXPathBase = itemTermInfoGroupXPathBase;
679 protected String getAuthorityItemCommonSchemaName() {
680 return authorityItemCommonSchemaName;