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.Collections;
70 import java.util.HashMap;
71 import java.util.List;
73 import java.util.regex.Matcher;
74 import java.util.regex.Pattern;
76 //import org.collectionspace.services.common.authority.AuthorityItemRelations;
78 * AuthorityItemDocumentModelHandler
80 * $LastChangedRevision: $
83 public abstract class AuthorityItemDocumentModelHandler<AICommon>
84 extends DocHandlerBase<AICommon> {
86 private final Logger logger = LoggerFactory.getLogger(AuthorityItemDocumentModelHandler.class);
87 private String authorityItemCommonSchemaName;
88 private String authorityItemTermGroupXPathBase;
90 * inVocabulary is the parent Authority for this context
92 protected String inAuthority = null;
93 protected boolean wildcardedAuthorityRequest = false;
94 protected String authorityRefNameBase = null;
95 // Used to determine when the displayName changes as part of the update.
96 protected String oldDisplayNameOnUpdate = null;
97 private final static String LIST_SUFFIX = "List";
99 public AuthorityItemDocumentModelHandler(String authorityItemCommonSchemaName) {
100 this.authorityItemCommonSchemaName = authorityItemCommonSchemaName;
104 protected String getRefnameDisplayName(DocumentWrapper<DocumentModel> docWrapper) {
105 String result = null;
107 DocumentModel docModel = docWrapper.getWrappedObject();
108 ServiceContext ctx = this.getServiceContext();
109 RefName.AuthorityItem refname = (RefName.AuthorityItem)getRefName(ctx, docModel);
110 result = refname.getDisplayName();
116 * After calling this method successfully, the document model will contain an updated refname and short ID
118 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getRefName(org.collectionspace.services.common.context.ServiceContext, org.nuxeo.ecm.core.api.DocumentModel)
121 public RefName.RefNameInterface getRefName(ServiceContext ctx,
122 DocumentModel docModel) {
123 RefName.RefNameInterface refname = null;
126 String displayName = getPrimaryDisplayName(docModel, authorityItemCommonSchemaName,
127 getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
128 if (Tools.isEmpty(displayName)) {
129 throw new Exception("The displayName for this authority term was empty or not set.");
132 String shortIdentifier = (String) docModel.getProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
133 if (Tools.isEmpty(shortIdentifier)) {
134 // We didn't find a short ID in the payload request, so we need to synthesize one.
135 shortIdentifier = handleDisplayNameAsShortIdentifier(docModel); // updates the document model with the new short ID as a side-effect
138 String authorityRefBaseName = getAuthorityRefNameBase();
139 if (Tools.isEmpty(authorityRefBaseName)) {
140 throw new Exception("Could not create the refName for this authority term, because the refName for its authority parent was empty.");
143 // Create the items refname using the parent's as a base
144 RefName.Authority parentsRefName = RefName.Authority.parse(authorityRefBaseName);
145 refname = RefName.buildAuthorityItem(parentsRefName, shortIdentifier, displayName);
146 // Now update the document model with the refname value
147 String refNameStr = refname.toString();
148 docModel.setProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.REF_NAME, refNameStr); // REM - This field is deprecated now that the refName is part of the collection_space core schema
150 } catch (Exception e) {
151 logger.error(e.getMessage(), e);
157 public void setInAuthority(String inAuthority) {
158 this.inAuthority = inAuthority;
161 public String getInAuthority() {
162 return this.inAuthority;
165 /** Subclasses may override this to customize the URI segment. */
166 public String getAuthorityServicePath() {
167 return getServiceContext().getServiceName().toLowerCase(); // Laramie20110510 CSPACE-3932
171 public String getUri(DocumentModel docModel) {
172 // Laramie20110510 CSPACE-3932
173 String authorityServicePath = getAuthorityServicePath();
174 if(inAuthority==null) { // Only true with the first document model received, on queries to wildcarded authorities
175 wildcardedAuthorityRequest = true;
177 // If this search crosses multiple authorities, get the inAuthority value
178 // from each record, rather than using the cached value from the first record
179 if(wildcardedAuthorityRequest) {
181 inAuthority = (String) docModel.getProperty(authorityItemCommonSchemaName,
182 AuthorityItemJAXBSchema.IN_AUTHORITY);
183 } catch (ClientException pe) {
184 throw new RuntimeException("Could not get parent specifier for item!");
187 return "/" + authorityServicePath + '/' + inAuthority + '/' + AuthorityClient.ITEMS + '/' + getCsid(docModel);
190 protected String getAuthorityRefNameBase() {
191 return this.authorityRefNameBase;
194 public void setAuthorityRefNameBase(String value) {
195 this.authorityRefNameBase = value;
199 * Note: the Vocabulary service's VocabularyItemDocumentModelHandler class overrides this method.
201 protected ListResultField getListResultsDisplayNameField() {
202 ListResultField result = new ListResultField();
203 // Per CSPACE-5132, the name of this element remains 'displayName'
204 // for backwards compatibility, although its value is obtained
205 // from the termDisplayName field.
207 // Update: this name is now being changed to 'termDisplayName', both
208 // because this is the actual field name and because the app layer
209 // work to convert over to this field is underway. Per Patrick, the
210 // app layer treats lists, in at least some context(s), as sparse record
211 // payloads, and thus fields in list results must all be present in
212 // (i.e. represent a strict subset of the fields in) record schemas.
216 // In CSPACE-5134, these list results will change substantially
217 // to return display names for both the preferred term and for
218 // each non-preferred term (if any).
219 result.setElement(AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
220 result.setXpath(NuxeoUtils.getPrimaryXPathPropertyName(
221 authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME));
227 * Note: the Vocabulary service's VocabularyItemDocumentModelHandler class overrides this method.
229 protected ListResultField getListResultsTermStatusField() {
230 ListResultField result = new ListResultField();
232 result.setElement(AuthorityItemJAXBSchema.TERM_STATUS);
233 result.setXpath(NuxeoUtils.getPrimaryXPathPropertyName(
234 authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_STATUS));
239 private boolean isTermDisplayName(String elName) {
240 return AuthorityItemJAXBSchema.TERM_DISPLAY_NAME.equals(elName) || VocabularyItemJAXBSchema.DISPLAY_NAME.equals(elName);
245 * @see org.collectionspace.services.nuxeo.client.java.DocHandlerBase#getListItemsArray()
247 * Note: We're updating the "global" service and tenant bindings instance here -the list instance here is
248 * a reference to the tenant bindings instance in the singleton ServiceMain.
251 public List<ListResultField> getListItemsArray() throws DocumentException {
252 List<ListResultField> list = super.getListItemsArray();
254 // One-time initialization for each authority item service.
255 if (isListItemArrayExtended() == false) {
256 synchronized(AuthorityItemDocumentModelHandler.class) {
257 if (isListItemArrayExtended() == false) {
258 int nFields = list.size();
259 // Ensure that each item in a list of Authority items includes
260 // a set of common fields, so we do not depend upon configuration
261 // for general logic.
262 List<Integer> termDisplayNamePositionsInList = new ArrayList<>();;
263 boolean hasShortId = false;
264 boolean hasTermStatus = false;
265 for (int i = 0; i < nFields; i++) {
266 ListResultField field = list.get(i);
267 String elName = field.getElement();
268 if (isTermDisplayName(elName) == true) {
269 termDisplayNamePositionsInList.add(i);
270 } else if (AuthorityItemJAXBSchema.SHORT_IDENTIFIER.equals(elName)) {
272 } else if (AuthorityItemJAXBSchema.TERM_STATUS.equals(elName)) {
273 hasTermStatus = true;
277 ListResultField field;
279 // Certain fields in authority item list results
280 // are handled specially here
284 // Ignore (throw out) any configuration entries that
285 // specify how the termDisplayName field should be
286 // emitted in authority item lists. This field will
287 // be handled in a standardized manner (see block below).
288 if (termDisplayNamePositionsInList.isEmpty() == false) {
289 // Remove matching items starting at the end of the list
290 // and moving towards the start, so that reshuffling of
291 // list order doesn't alter the positions of earlier items
292 Collections.sort(termDisplayNamePositionsInList, Collections.reverseOrder());
293 for (int i : termDisplayNamePositionsInList) {
297 // termDisplayName values in authority item lists
298 // will be handled via code that emits display names
299 // for both the preferred term and all non-preferred
300 // terms (if any). The following is a placeholder
301 // entry that will trigger this code. See the
302 // getListResultValue() method in this class.
303 field = getListResultsDisplayNameField();
308 field = new ListResultField();
309 field.setElement(AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
310 field.setXpath(AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
315 if (!hasTermStatus) {
316 field = getListResultsTermStatusField();
322 setListItemArrayExtended(true);
323 } // end of synchronized block
330 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
333 public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
334 // first fill all the parts of the document, refname and short ID get set as well
335 super.handleCreate(wrapDoc);
336 // Ensure we have required fields set properly
337 handleInAuthority(wrapDoc.getWrappedObject());
341 * This method gets called after the primary update to an authority item has happened. If the authority item's refName
342 * has changed, then we need to updated all the records that use that refname with the new/updated version
345 * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#completeUpdate(org.collectionspace.services.common.document.DocumentWrapper)
347 public void completeUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
348 // Must call our super class' version first
349 super.completeUpdate(wrapDoc);
352 // Look for and update authority references with the updated refName
354 if (hasRefNameUpdate() == true) {
355 // We have work to do.
356 if (logger.isDebugEnabled()) {
357 final String EOL = System.getProperty("line.separator");
358 logger.debug("Need to find and update references to authority item." + EOL
359 + " Old refName" + oldRefNameOnUpdate + EOL
360 + " New refName" + newRefNameOnUpdate);
362 ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = getServiceContext();
363 RepositoryClient<PoxPayloadIn, PoxPayloadOut> repoClient = getRepositoryClient(ctx);
364 RepositoryInstance repoSession = this.getRepositorySession();
366 // Update all the existing records that have a field with the old refName in it
367 int nUpdated = RefNameServiceUtils.updateAuthorityRefDocs(ctx, repoClient, repoSession,
368 oldRefNameOnUpdate, newRefNameOnUpdate, getRefPropName());
370 // Finished so log a message.
371 if (logger.isDebugEnabled()) {
372 logger.debug("Updated " + nUpdated + " instances of oldRefName to newRefName");
378 * Note that the Vocabulary service's document-model for items overrides this method.
380 protected String getPrimaryDisplayName(DocumentModel docModel, String schema,
381 String complexPropertyName, String fieldName) {
382 String result = null;
384 result = getStringValueInPrimaryRepeatingComplexProperty(docModel, schema, complexPropertyName, fieldName);
390 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper)
393 // 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.
395 public void handleUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
396 // Must call our super's version first, this updates the core schema and the relationship records to deal with possible refName changes/update
397 super.handleUpdate(wrapDoc);
398 if (this.hasRefNameUpdate() == true) {
399 DocumentModel docModel = wrapDoc.getWrappedObject();
400 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
405 * If no short identifier was provided in the input payload, generate a
406 * short identifier from the preferred term display name or term name.
408 private String handleDisplayNameAsShortIdentifier(DocumentModel docModel) throws Exception {
409 String result = (String) docModel.getProperty(authorityItemCommonSchemaName,
410 AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
412 if (Tools.isEmpty(result)) {
413 String termDisplayName = getPrimaryDisplayName(
414 docModel, authorityItemCommonSchemaName,
415 getItemTermInfoGroupXPathBase(),
416 AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
418 String termName = getPrimaryDisplayName(
419 docModel, authorityItemCommonSchemaName,
420 getItemTermInfoGroupXPathBase(),
421 AuthorityItemJAXBSchema.TERM_NAME);
423 String generatedShortIdentifier = AuthorityIdentifierUtils.generateShortIdentifierFromDisplayName(termDisplayName,
425 docModel.setProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER,
426 generatedShortIdentifier);
427 result = generatedShortIdentifier;
434 * Generate a refName for the authority item from the short identifier
437 * All refNames for authority items are generated. If a client supplies
438 * a refName, it will be overwritten during create (per this method)
439 * or discarded during update (per filterReadOnlyPropertiesForPart).
441 * @see #filterReadOnlyPropertiesForPart(Map<String, Object>, org.collectionspace.services.common.service.ObjectPartType)
444 protected String updateRefnameForAuthorityItem(DocumentModel docModel,
445 String schemaName) throws Exception {
446 String result = null;
448 RefName.RefNameInterface refname = getRefName(getServiceContext(), docModel);
449 String refNameStr = refname.toString();
450 docModel.setProperty(schemaName, AuthorityItemJAXBSchema.REF_NAME, refNameStr);
457 * Check the logic around the parent pointer. Note that we only need do this on
458 * create, since we have logic to make this read-only on update.
462 * @throws Exception the exception
464 private void handleInAuthority(DocumentModel docModel) throws Exception {
465 if(inAuthority==null) { // Only happens on queries to wildcarded authorities
466 throw new IllegalStateException("Trying to Create an object with no inAuthority value!");
468 docModel.setProperty(authorityItemCommonSchemaName,
469 AuthorityItemJAXBSchema.IN_AUTHORITY, inAuthority);
472 public AuthorityRefDocList getReferencingObjects(
473 ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
474 UriTemplateRegistry uriTemplateRegistry,
475 List<String> serviceTypes,
477 String itemcsid) throws Exception {
478 AuthorityRefDocList authRefDocList = null;
479 RepositoryInstance repoSession = null;
480 boolean releaseRepoSession = false;
483 RepositoryJavaClientImpl repoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx);
484 repoSession = this.getRepositorySession();
485 if (repoSession == null) {
486 repoSession = repoClient.getRepositorySession(ctx);
487 releaseRepoSession = true;
489 DocumentFilter myFilter = getDocumentFilter();
492 DocumentWrapper<DocumentModel> wrapper = repoClient.getDoc(repoSession, ctx, itemcsid);
493 DocumentModel docModel = wrapper.getWrappedObject();
494 String refName = (String) docModel.getPropertyValue(AuthorityItemJAXBSchema.REF_NAME);
495 authRefDocList = RefNameServiceUtils.getAuthorityRefDocs(
496 repoSession, ctx, uriTemplateRegistry, repoClient,
500 myFilter, true /*computeTotal*/);
501 } catch (PropertyException pe) {
503 } catch (DocumentException de) {
505 } catch (Exception e) {
506 if (logger.isDebugEnabled()) {
507 logger.debug("Caught exception ", e);
509 throw new DocumentException(e);
511 // If we got/aquired a new seesion then we're responsible for releasing it.
512 if (releaseRepoSession && repoSession != null) {
513 repoClient.releaseRepositorySession(ctx, repoSession);
516 } catch (Exception e) {
517 if (logger.isDebugEnabled()) {
518 logger.debug("Caught exception ", e);
520 throw new DocumentException(e);
523 return authRefDocList;
527 * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#extractPart(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, org.collectionspace.services.common.service.ObjectPartType)
530 protected Map<String, Object> extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta)
532 Map<String, Object> unQObjectProperties = super.extractPart(docModel, schema, partMeta);
534 // Add the CSID to the common part, since they may have fetched via the shortId.
535 if (partMeta.getLabel().equalsIgnoreCase(authorityItemCommonSchemaName)) {
536 String csid = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
537 unQObjectProperties.put("csid", csid);
540 return unQObjectProperties;
544 * Filters out selected values supplied in an update request.
546 * For example, filters out AuthorityItemJAXBSchema.IN_AUTHORITY, to ensure
547 * that the link to the item's parent remains untouched.
549 * @param objectProps the properties filtered out from the update payload
550 * @param partMeta metadata for the object to fill
553 public void filterReadOnlyPropertiesForPart(
554 Map<String, Object> objectProps, ObjectPartType partMeta) {
555 super.filterReadOnlyPropertiesForPart(objectProps, partMeta);
556 String commonPartLabel = getServiceContext().getCommonPartLabel();
557 if (partMeta.getLabel().equalsIgnoreCase(commonPartLabel)) {
558 objectProps.remove(AuthorityItemJAXBSchema.IN_AUTHORITY);
559 objectProps.remove(AuthorityItemJAXBSchema.CSID);
560 objectProps.remove(AuthorityJAXBSchema.SHORT_IDENTIFIER);
561 objectProps.remove(AuthorityItemJAXBSchema.REF_NAME);
565 protected List<String> getPartialTermDisplayNameMatches(List<String> termDisplayNameList, String partialTerm) {
566 List<String> result = new ArrayList<String>();
568 for (String termDisplayName : termDisplayNameList) {
569 if (termDisplayName.toLowerCase().contains(partialTerm.toLowerCase()) == true) {
570 result.add(termDisplayName);
577 @SuppressWarnings("unchecked")
578 private List<String> getPartialTermDisplayNameMatches(DocumentModel docModel, // REM - CSPACE-5133
579 String schema, ListResultField field, String partialTerm) {
580 List<String> result = null;
582 String xpath = field.getXpath(); // results in something like "persons_common:personTermGroupList/[0]/termDisplayName"
583 int endOfTermGroup = xpath.lastIndexOf("/[0]/");
584 String propertyName = endOfTermGroup != -1 ? xpath.substring(0, endOfTermGroup) : xpath; // it may not be multivalued so the xpath passed in would be the property name
588 value = docModel.getProperty(schema, propertyName);
589 } catch (Exception e) {
590 logger.error("Could not extract term display name with property = "
594 if (value != null && value instanceof ArrayList) {
595 ArrayList<HashMap<String, Object>> termGroupList = (ArrayList<HashMap<String, Object>>)value;
596 int arrayListSize = termGroupList.size();
597 if (arrayListSize > 1) { // if there's only 1 element in the list then we've already matched the primary term's display name
598 List<String> displayNameList = new ArrayList<String>();
599 for (int i = 1; i < arrayListSize; i++) { // start at 1, skip the primary term's displayName since we will always return it
600 HashMap<String, Object> map = (HashMap<String, Object>)termGroupList.get(i);
601 String termDisplayName = (String) map.get(AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
602 displayNameList.add(i - 1, termDisplayName);
605 result = getPartialTermDisplayNameMatches(displayNameList, partialTerm);
613 protected Object getListResultValue(DocumentModel docModel, // REM - CSPACE-5133
614 String schema, ListResultField field) {
615 Object result = null;
617 result = NuxeoUtils.getXPathValue(docModel, schema, field.getXpath());
620 // Special handling of list item values for authority items (only)
623 // If the list result field is the termDisplayName element,
624 // check whether a partial term matching query was made.
625 // If it was, emit values for both the preferred (aka primary)
626 // term and for all non-preferred terms, if any.
628 String elName = field.getElement();
629 if (isTermDisplayName(elName) == true) {
630 MultivaluedMap<String, String> queryParams = this.getServiceContext().getQueryParams();
631 String partialTerm = queryParams != null ? queryParams.getFirst(IQueryManager.SEARCH_TYPE_PARTIALTERM) : null;
632 if (partialTerm != null && partialTerm.trim().isEmpty() == false) {
633 String primaryTermDisplayName = (String)result;
634 List<String> matches = getPartialTermDisplayNameMatches(docModel, schema, field, partialTerm);
635 if (matches != null && matches.isEmpty() == false) {
636 matches.add(0, primaryTermDisplayName); // insert the primary term's display name at the beginning of the list
637 result = matches; // set the result to a list of matching term display names with the primary term's display name at the beginning
646 public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
647 MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
648 super.extractAllParts(wrapDoc);
652 public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception {
654 // We currently don't override this method with any AuthorityItemDocumentModelHandler specific functionality, so
655 // we could remove this method.
657 super.fillAllParts(wrapDoc, action);
660 protected List<RelationsCommonList.RelationListItem> cloneList(List<RelationsCommonList.RelationListItem> inboundList) {
661 List<RelationsCommonList.RelationListItem> result = newRelationsCommonList();
662 for (RelationsCommonList.RelationListItem item : inboundList) {
669 /* don't even THINK of re-using this method.
670 * String example_uri = "/locationauthorities/7ec60f01-84ab-4908-9a6a/items/a5466530-713f-43b4-bc05";
673 private String extractInAuthorityCSID(String uri) {
674 String IN_AUTHORITY_REGEX = "/(.*?)/(.*?)/(.*)";
675 Pattern p = Pattern.compile(IN_AUTHORITY_REGEX);
676 Matcher m = p.matcher(uri);
678 if (m.groupCount() < 3) {
679 logger.warn("REGEX-WRONG-GROUPCOUNT looking in " + uri);
682 //String service = m.group(1);
683 String inauth = m.group(2);
684 //String theRest = m.group(3);
686 //print("service:"+service+", inauth:"+inauth+", rest:"+rest);
689 logger.warn("REGEX-NOT-MATCHED looking in " + uri);
694 //ensures CSPACE-4042
695 protected void uriPointsToSameAuthority(String thisURI, String inboundItemURI) throws Exception {
696 String authorityCSID = extractInAuthorityCSID(thisURI);
697 String authorityCSIDForInbound = extractInAuthorityCSID(inboundItemURI);
698 if (Tools.isBlank(authorityCSID)
699 || Tools.isBlank(authorityCSIDForInbound)
700 || (!authorityCSID.equalsIgnoreCase(authorityCSIDForInbound))) {
701 throw new Exception("Item URI " + thisURI + " must point to same authority as related item: " + inboundItemURI);
705 public String getItemTermInfoGroupXPathBase() {
706 return authorityItemTermGroupXPathBase;
709 public void setItemTermInfoGroupXPathBase(String itemTermInfoGroupXPathBase) {
710 authorityItemTermGroupXPathBase = itemTermInfoGroupXPathBase;
713 protected String getAuthorityItemCommonSchemaName() {
714 return authorityItemCommonSchemaName;
718 public boolean isJDBCQuery() {
719 boolean result = false;
721 MultivaluedMap<String, String> queryParams = getServiceContext().getQueryParams();
723 // Look the query params to see if we need to make a SQL query.
725 String partialTerm = queryParams.getFirst(IQueryManager.SEARCH_TYPE_PARTIALTERM);
726 if (partialTerm != null && partialTerm.trim().isEmpty() == false) {
733 // By convention, the name of the database table that contains
734 // repeatable term information group records is derivable from
735 // an existing XPath base value, by removing a suffix and converting
737 protected String getTermGroupTableName() {
738 String termInfoGroupListName = getItemTermInfoGroupXPathBase();
739 return termInfoGroupListName.substring(0, termInfoGroupListName.lastIndexOf(LIST_SUFFIX)).toLowerCase();
742 protected String getInAuthorityValue() {
743 String inAuthorityValue = getInAuthority();
744 if (Tools.notBlank(inAuthorityValue)) {
745 return inAuthorityValue;
747 return AuthorityResource.PARENT_WILDCARD;
752 public Map<String,String> getJDBCQueryParams() {
753 // FIXME: Get all of the following values from appropriate external constants.
754 // At present, these are duplicated in both RepositoryJavaClientImpl
755 // and in AuthorityItemDocumentModelHandler.
756 final String TERM_GROUP_LIST_NAME = "TERM_GROUP_LIST_NAME";
757 final String TERM_GROUP_TABLE_NAME_PARAM = "TERM_GROUP_TABLE_NAME";
758 final String IN_AUTHORITY_PARAM = "IN_AUTHORITY";
760 Map<String,String> params = super.getJDBCQueryParams();
761 params.put(TERM_GROUP_LIST_NAME, getItemTermInfoGroupXPathBase());
762 params.put(TERM_GROUP_TABLE_NAME_PARAM, getTermGroupTableName());
763 params.put(IN_AUTHORITY_PARAM, getInAuthorityValue());