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.UriTemplateRegistry;
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.repository.RepositoryClient;
41 import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema;
42 import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
43 import org.collectionspace.services.common.vocabulary.AuthorityResource;
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 boolean wildcardedAuthorityRequest = false;
93 protected String authorityRefNameBase = null;
94 // Used to determine when the displayName changes as part of the update.
95 protected String oldDisplayNameOnUpdate = null;
96 private final static String LIST_SUFFIX = "List";
98 public AuthorityItemDocumentModelHandler(String authorityItemCommonSchemaName) {
99 this.authorityItemCommonSchemaName = authorityItemCommonSchemaName;
103 protected String getRefnameDisplayName(DocumentWrapper<DocumentModel> docWrapper) {
104 String result = null;
106 DocumentModel docModel = docWrapper.getWrappedObject();
107 ServiceContext ctx = this.getServiceContext();
108 RefName.AuthorityItem refname = (RefName.AuthorityItem)getRefName(ctx, docModel);
109 result = refname.getDisplayName();
115 * After calling this method successfully, the document model will contain an updated refname and short ID
117 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getRefName(org.collectionspace.services.common.context.ServiceContext, org.nuxeo.ecm.core.api.DocumentModel)
120 public RefName.RefNameInterface getRefName(ServiceContext ctx,
121 DocumentModel docModel) {
122 RefName.RefNameInterface refname = null;
125 String displayName = getPrimaryDisplayName(docModel, authorityItemCommonSchemaName,
126 getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
127 if (Tools.isEmpty(displayName)) {
128 throw new Exception("The displayName for this authority term was empty or not set.");
131 String shortIdentifier = (String) docModel.getProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
132 if (Tools.isEmpty(shortIdentifier)) {
133 // We didn't find a short ID in the payload request, so we need to synthesize one.
134 shortIdentifier = handleDisplayNameAsShortIdentifier(docModel); // updates the document model with the new short ID as a side-effect
137 String authorityRefBaseName = getAuthorityRefNameBase();
138 if (Tools.isEmpty(authorityRefBaseName)) {
139 throw new Exception("Could not create the refName for this authority term, because the refName for its authority parent was empty.");
142 // Create the items refname using the parent's as a base
143 RefName.Authority parentsRefName = RefName.Authority.parse(authorityRefBaseName);
144 refname = RefName.buildAuthorityItem(parentsRefName, shortIdentifier, displayName);
145 // Now update the document model with the refname value
146 String refNameStr = refname.toString();
147 docModel.setProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.REF_NAME, refNameStr); // REM - This field is deprecated now that the refName is part of the collection_space core schema
149 } catch (Exception e) {
150 logger.error(e.getMessage(), e);
156 public void setInAuthority(String inAuthority) {
157 this.inAuthority = inAuthority;
160 public String getInAuthority() {
161 return this.inAuthority;
164 /** Subclasses may override this to customize the URI segment. */
165 public String getAuthorityServicePath() {
166 return getServiceContext().getServiceName().toLowerCase(); // Laramie20110510 CSPACE-3932
170 public String getUri(DocumentModel docModel) {
171 // Laramie20110510 CSPACE-3932
172 String authorityServicePath = getAuthorityServicePath();
173 if(inAuthority==null) { // Only true with the first document model received, on queries to wildcarded authorities
174 wildcardedAuthorityRequest = true;
176 // If this search crosses multiple authorities, get the inAuthority value
177 // from each record, rather than using the cached value from the first record
178 if(wildcardedAuthorityRequest) {
180 inAuthority = (String) docModel.getProperty(authorityItemCommonSchemaName,
181 AuthorityItemJAXBSchema.IN_AUTHORITY);
182 } catch (ClientException pe) {
183 throw new RuntimeException("Could not get parent specifier for item!");
186 return "/" + authorityServicePath + '/' + inAuthority + '/' + AuthorityClient.ITEMS + '/' + getCsid(docModel);
189 protected String getAuthorityRefNameBase() {
190 return this.authorityRefNameBase;
193 public void setAuthorityRefNameBase(String value) {
194 this.authorityRefNameBase = value;
198 * Note: the Vocabulary service's VocabularyItemDocumentModelHandler class overrides this method.
200 protected ListResultField getListResultsDisplayNameField() {
201 ListResultField result = new ListResultField();
202 // Per CSPACE-5132, the name of this element remains 'displayName'
203 // for backwards compatibility, although its value is obtained
204 // from the termDisplayName field.
206 // Update: this name is now being changed to 'termDisplayName', both
207 // because this is the actual field name and because the app layer
208 // work to convert over to this field is underway. Per Patrick, the
209 // app layer treats lists, in at least some context(s), as sparse record
210 // payloads, and thus fields in list results must all be present in
211 // (i.e. represent a strict subset of the fields in) record schemas.
215 // In CSPACE-5134, these list results will change substantially
216 // to return display names for both the preferred term and for
217 // each non-preferred term (if any).
218 result.setElement(AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
219 result.setXpath(NuxeoUtils.getPrimaryXPathPropertyName(
220 authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME));
226 * Note: the Vocabulary service's VocabularyItemDocumentModelHandler class overrides this method.
228 protected ListResultField getListResultsTermStatusField() {
229 ListResultField result = new ListResultField();
231 result.setElement(AuthorityItemJAXBSchema.TERM_STATUS);
232 result.setXpath(NuxeoUtils.getPrimaryXPathPropertyName(
233 authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_STATUS));
238 private boolean isTermDisplayName(String elName) {
239 return AuthorityItemJAXBSchema.TERM_DISPLAY_NAME.equals(elName) || VocabularyItemJAXBSchema.DISPLAY_NAME.equals(elName);
244 * @see org.collectionspace.services.nuxeo.client.java.DocHandlerBase#getListItemsArray()
246 * Note: We're updating the "global" service and tenant bindings instance here -the list instance here is
247 * a reference to the tenant bindings instance in the singleton ServiceMain.
250 public List<ListResultField> getListItemsArray() throws DocumentException {
251 List<ListResultField> list = super.getListItemsArray();
253 // One-time initialization for each authority item service.
254 if (isListItemArrayExtended() == false) {
255 synchronized(AuthorityItemDocumentModelHandler.class) {
256 if (isListItemArrayExtended() == false) {
257 int nFields = list.size();
258 // Ensure that each item in a list of Authority items includes
259 // a set of common fields, so we do not depend upon configuration
260 // for general logic.
261 boolean hasDisplayName = false;
262 boolean hasShortId = false;
263 boolean hasTermStatus = false;
264 for (int i = 0; i < nFields; i++) {
265 ListResultField field = list.get(i);
266 String elName = field.getElement();
267 if (isTermDisplayName(elName) == true) {
268 hasDisplayName = true;
269 } else if (AuthorityItemJAXBSchema.SHORT_IDENTIFIER.equals(elName)) {
271 } else if (AuthorityItemJAXBSchema.TERM_STATUS.equals(elName)) {
272 hasTermStatus = true;
276 ListResultField field;
277 if (!hasDisplayName) {
278 field = getListResultsDisplayNameField();
282 field = new ListResultField();
283 field.setElement(AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
284 field.setXpath(AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
287 if (!hasTermStatus) {
288 field = getListResultsTermStatusField();
293 setListItemArrayExtended(true);
294 } // end of synchronized block
301 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
304 public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
305 // first fill all the parts of the document, refname and short ID get set as well
306 super.handleCreate(wrapDoc);
307 // Ensure we have required fields set properly
308 handleInAuthority(wrapDoc.getWrappedObject());
312 * This method gets called after the primary update to an authority item has happened. If the authority item's refName
313 * has changed, then we need to updated all the records that use that refname with the new/updated version
316 * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#completeUpdate(org.collectionspace.services.common.document.DocumentWrapper)
318 public void completeUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
319 // Must call our super class' version first
320 super.completeUpdate(wrapDoc);
323 // Look for and update authority references with the updated refName
325 if (hasRefNameUpdate() == true) {
326 // We have work to do.
327 if (logger.isDebugEnabled()) {
328 final String EOL = System.getProperty("line.separator");
329 logger.debug("Need to find and update references to authority item." + EOL
330 + " Old refName" + oldRefNameOnUpdate + EOL
331 + " New refName" + newRefNameOnUpdate);
333 ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = getServiceContext();
334 RepositoryClient<PoxPayloadIn, PoxPayloadOut> repoClient = getRepositoryClient(ctx);
335 RepositoryInstance repoSession = this.getRepositorySession();
337 // Update all the existing records that have a field with the old refName in it
338 int nUpdated = RefNameServiceUtils.updateAuthorityRefDocs(ctx, repoClient, repoSession,
339 oldRefNameOnUpdate, newRefNameOnUpdate, getRefPropName());
341 // Finished so log a message.
342 if (logger.isDebugEnabled()) {
343 logger.debug("Updated " + nUpdated + " instances of oldRefName to newRefName");
349 * Note that the Vocabulary service's document-model for items overrides this method.
351 protected String getPrimaryDisplayName(DocumentModel docModel, String schema,
352 String complexPropertyName, String fieldName) {
353 String result = null;
355 result = getStringValueInPrimaryRepeatingComplexProperty(docModel, schema, complexPropertyName, fieldName);
361 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper)
364 // FIXME: Once we remove the refName field from the authority item schemas, we can remove this override method since our super does everthing for us now.
366 public void handleUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
367 // Must call our super's version first, this updates the core schema and the relationship records to deal with possible refName changes/update
368 super.handleUpdate(wrapDoc);
369 if (this.hasRefNameUpdate() == true) {
370 DocumentModel docModel = wrapDoc.getWrappedObject();
371 docModel.setProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.REF_NAME, this.newRefNameOnUpdate); // This field is deprecated since it is now a duplicate of what is in the collectionspace_core:refName field
376 * If no short identifier was provided in the input payload, generate a
377 * short identifier from the preferred term display name or term name.
379 private String handleDisplayNameAsShortIdentifier(DocumentModel docModel) throws Exception {
380 String result = (String) docModel.getProperty(authorityItemCommonSchemaName,
381 AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
383 if (Tools.isEmpty(result)) {
384 String termDisplayName = getPrimaryDisplayName(
385 docModel, authorityItemCommonSchemaName,
386 getItemTermInfoGroupXPathBase(),
387 AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
389 String termName = getPrimaryDisplayName(
390 docModel, authorityItemCommonSchemaName,
391 getItemTermInfoGroupXPathBase(),
392 AuthorityItemJAXBSchema.TERM_NAME);
394 String generatedShortIdentifier = AuthorityIdentifierUtils.generateShortIdentifierFromDisplayName(termDisplayName,
396 docModel.setProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER,
397 generatedShortIdentifier);
398 result = generatedShortIdentifier;
405 * Generate a refName for the authority item from the short identifier
408 * All refNames for authority items are generated. If a client supplies
409 * a refName, it will be overwritten during create (per this method)
410 * or discarded during update (per filterReadOnlyPropertiesForPart).
412 * @see #filterReadOnlyPropertiesForPart(Map<String, Object>, org.collectionspace.services.common.service.ObjectPartType)
415 protected String updateRefnameForAuthorityItem(DocumentModel docModel,
416 String schemaName) throws Exception {
417 String result = null;
419 RefName.RefNameInterface refname = getRefName(getServiceContext(), docModel);
420 String refNameStr = refname.toString();
421 docModel.setProperty(schemaName, AuthorityItemJAXBSchema.REF_NAME, refNameStr);
428 * Check the logic around the parent pointer. Note that we only need do this on
429 * create, since we have logic to make this read-only on update.
433 * @throws Exception the exception
435 private void handleInAuthority(DocumentModel docModel) throws Exception {
436 if(inAuthority==null) { // Only happens on queries to wildcarded authorities
437 throw new IllegalStateException("Trying to Create an object with no inAuthority value!");
439 docModel.setProperty(authorityItemCommonSchemaName,
440 AuthorityItemJAXBSchema.IN_AUTHORITY, inAuthority);
443 public AuthorityRefDocList getReferencingObjects(
444 ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
445 UriTemplateRegistry uriTemplateRegistry,
446 List<String> serviceTypes,
448 String itemcsid) throws Exception {
449 AuthorityRefDocList authRefDocList = null;
450 RepositoryInstance repoSession = null;
451 boolean releaseRepoSession = false;
454 RepositoryJavaClientImpl repoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx);
455 repoSession = this.getRepositorySession();
456 if (repoSession == null) {
457 repoSession = repoClient.getRepositorySession(ctx);
458 releaseRepoSession = true;
460 DocumentFilter myFilter = getDocumentFilter();
463 DocumentWrapper<DocumentModel> wrapper = repoClient.getDoc(repoSession, ctx, itemcsid);
464 DocumentModel docModel = wrapper.getWrappedObject();
465 String refName = (String) docModel.getPropertyValue(AuthorityItemJAXBSchema.REF_NAME);
466 authRefDocList = RefNameServiceUtils.getAuthorityRefDocs(
467 repoSession, ctx, uriTemplateRegistry, repoClient,
471 myFilter, true /*computeTotal*/);
472 } catch (PropertyException pe) {
474 } catch (DocumentException de) {
476 } catch (Exception e) {
477 if (logger.isDebugEnabled()) {
478 logger.debug("Caught exception ", e);
480 throw new DocumentException(e);
482 // If we got/aquired a new seesion then we're responsible for releasing it.
483 if (releaseRepoSession && repoSession != null) {
484 repoClient.releaseRepositorySession(ctx, repoSession);
487 } catch (Exception e) {
488 if (logger.isDebugEnabled()) {
489 logger.debug("Caught exception ", e);
491 throw new DocumentException(e);
494 return authRefDocList;
498 * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#extractPart(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, org.collectionspace.services.common.service.ObjectPartType)
501 protected Map<String, Object> extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta)
503 Map<String, Object> unQObjectProperties = super.extractPart(docModel, schema, partMeta);
505 // Add the CSID to the common part, since they may have fetched via the shortId.
506 if (partMeta.getLabel().equalsIgnoreCase(authorityItemCommonSchemaName)) {
507 String csid = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
508 unQObjectProperties.put("csid", csid);
511 return unQObjectProperties;
515 * Filters out selected values supplied in an update request.
517 * For example, filters out AuthorityItemJAXBSchema.IN_AUTHORITY, to ensure
518 * that the link to the item's parent remains untouched.
520 * @param objectProps the properties filtered out from the update payload
521 * @param partMeta metadata for the object to fill
524 public void filterReadOnlyPropertiesForPart(
525 Map<String, Object> objectProps, ObjectPartType partMeta) {
526 super.filterReadOnlyPropertiesForPart(objectProps, partMeta);
527 String commonPartLabel = getServiceContext().getCommonPartLabel();
528 if (partMeta.getLabel().equalsIgnoreCase(commonPartLabel)) {
529 objectProps.remove(AuthorityItemJAXBSchema.IN_AUTHORITY);
530 objectProps.remove(AuthorityItemJAXBSchema.CSID);
531 objectProps.remove(AuthorityJAXBSchema.SHORT_IDENTIFIER);
532 objectProps.remove(AuthorityItemJAXBSchema.REF_NAME);
536 protected List<String> getPartialTermDisplayNameMatches(List<String> termDisplayNameList, String partialTerm) {
537 List<String> result = new ArrayList<String>();
539 for (String termDisplayName : termDisplayNameList) {
540 if (termDisplayName.toLowerCase().contains(partialTerm.toLowerCase()) == true) {
541 result.add(termDisplayName);
548 @SuppressWarnings("unchecked")
549 private List<String> getPartialTermDisplayNameMatches(DocumentModel docModel, // REM - CSPACE-5133
550 String schema, ListResultField field, String partialTerm) {
551 List<String> result = null;
553 String xpath = field.getXpath(); // results in something like "persons_common:personTermGroupList/[0]/termDisplayName"
554 int endOfTermGroup = xpath.lastIndexOf("/[0]/");
555 String propertyName = endOfTermGroup != -1 ? xpath.substring(0, endOfTermGroup) : xpath; // it may not be multivalued so the xpath passed in would be the property name
559 value = docModel.getProperty(schema, propertyName);
560 } catch (Exception e) {
561 logger.error("Could not extract term display name with property = "
565 if (value != null && value instanceof ArrayList) {
566 ArrayList<HashMap<String, Object>> termGroupList = (ArrayList<HashMap<String, Object>>)value;
567 int arrayListSize = termGroupList.size();
568 if (arrayListSize > 1) { // if there's only 1 element in the list then we've already matched the primary term's display name
569 List<String> displayNameList = new ArrayList<String>();
570 for (int i = 1; i < arrayListSize; i++) { // start at 1, skip the primary term's displayName since we will always return it
571 HashMap<String, Object> map = (HashMap<String, Object>)termGroupList.get(i);
572 String termDisplayName = (String) map.get(AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
573 displayNameList.add(i - 1, termDisplayName);
576 result = getPartialTermDisplayNameMatches(displayNameList, partialTerm);
584 protected Object getListResultValue(DocumentModel docModel, // REM - CSPACE-5133
585 String schema, ListResultField field) {
586 Object result = null;
588 result = NuxeoUtils.getXPathValue(docModel, schema, field.getXpath());
589 String elName = field.getElement();
591 // If the list result value is the termDisplayName element, we need to check to see if a partial term query was made.
593 if (isTermDisplayName(elName) == true) {
594 MultivaluedMap<String, String> queryParams = this.getServiceContext().getQueryParams();
595 String partialTerm = queryParams != null ? queryParams.getFirst(IQueryManager.SEARCH_TYPE_PARTIALTERM) : null;
596 if (partialTerm != null && partialTerm.trim().isEmpty() == false) {
597 String primaryTermDisplayName = (String)result;
598 List<String> matches = getPartialTermDisplayNameMatches(docModel, schema, field, partialTerm);
599 if (matches != null && matches.isEmpty() == false) {
600 matches.add(0, primaryTermDisplayName); // insert the primary term's display name at the beginning of the list
601 result = matches; // set the result to a list of matching term display names with the primary term's display name at the beginning
610 public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
611 MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
612 super.extractAllParts(wrapDoc);
616 public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception {
618 // We currently don't override this method with any AuthorityItemDocumentModelHandler specific functionality, so
619 // we could remove this method.
621 super.fillAllParts(wrapDoc, action);
624 protected List<RelationsCommonList.RelationListItem> cloneList(List<RelationsCommonList.RelationListItem> inboundList) {
625 List<RelationsCommonList.RelationListItem> result = newRelationsCommonList();
626 for (RelationsCommonList.RelationListItem item : inboundList) {
633 /* don't even THINK of re-using this method.
634 * String example_uri = "/locationauthorities/7ec60f01-84ab-4908-9a6a/items/a5466530-713f-43b4-bc05";
637 private String extractInAuthorityCSID(String uri) {
638 String IN_AUTHORITY_REGEX = "/(.*?)/(.*?)/(.*)";
639 Pattern p = Pattern.compile(IN_AUTHORITY_REGEX);
640 Matcher m = p.matcher(uri);
642 if (m.groupCount() < 3) {
643 logger.warn("REGEX-WRONG-GROUPCOUNT looking in " + uri);
646 //String service = m.group(1);
647 String inauth = m.group(2);
648 //String theRest = m.group(3);
650 //print("service:"+service+", inauth:"+inauth+", rest:"+rest);
653 logger.warn("REGEX-NOT-MATCHED looking in " + uri);
658 //ensures CSPACE-4042
659 protected void uriPointsToSameAuthority(String thisURI, String inboundItemURI) throws Exception {
660 String authorityCSID = extractInAuthorityCSID(thisURI);
661 String authorityCSIDForInbound = extractInAuthorityCSID(inboundItemURI);
662 if (Tools.isBlank(authorityCSID)
663 || Tools.isBlank(authorityCSIDForInbound)
664 || (!authorityCSID.equalsIgnoreCase(authorityCSIDForInbound))) {
665 throw new Exception("Item URI " + thisURI + " must point to same authority as related item: " + inboundItemURI);
669 public String getItemTermInfoGroupXPathBase() {
670 return authorityItemTermGroupXPathBase;
673 public void setItemTermInfoGroupXPathBase(String itemTermInfoGroupXPathBase) {
674 authorityItemTermGroupXPathBase = itemTermInfoGroupXPathBase;
677 protected String getAuthorityItemCommonSchemaName() {
678 return authorityItemCommonSchemaName;
682 public boolean isJDBCQuery() {
683 boolean result = false;
685 MultivaluedMap<String, String> queryParams = getServiceContext().getQueryParams();
687 // Look the query params to see if we need to make a SQL query.
689 String partialTerm = queryParams.getFirst(IQueryManager.SEARCH_TYPE_PARTIALTERM);
690 if (partialTerm != null && partialTerm.trim().isEmpty() == false) {
697 // By convention, the name of the database table that contains
698 // repeatable term information group records is derivable from
699 // an existing XPath base value, by removing a suffix and converting
701 protected String getTermGroupTableName() {
702 String termInfoGroupListName = getItemTermInfoGroupXPathBase();
703 return termInfoGroupListName.substring(0, termInfoGroupListName.lastIndexOf(LIST_SUFFIX)).toLowerCase();
706 protected String getInAuthorityValue() {
707 String inAuthorityValue = getInAuthority();
708 if (Tools.notBlank(inAuthorityValue)) {
709 return inAuthorityValue;
711 return AuthorityResource.PARENT_WILDCARD;
716 public Map<String,String> getJDBCQueryParams() {
717 // FIXME: Get all of the following values from appropriate external constants.
718 // At present, these are duplicated in both RepositoryJavaClientImpl
719 // and in AuthorityItemDocumentModelHandler.
720 final String TERM_GROUP_LIST_NAME = "TERM_GROUP_LIST_NAME";
721 final String TERM_GROUP_TABLE_NAME_PARAM = "TERM_GROUP_TABLE_NAME";
722 final String IN_AUTHORITY_PARAM = "IN_AUTHORITY";
724 Map<String,String> params = super.getJDBCQueryParams();
725 params.put(TERM_GROUP_LIST_NAME, getItemTermInfoGroupXPathBase());
726 params.put(TERM_GROUP_TABLE_NAME_PARAM, getTermGroupTableName());
727 params.put(IN_AUTHORITY_PARAM, getInAuthorityValue());