]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
f6b080220f49c21a27bab5b485d13ac7a1c71841
[tmp/jakarta-migration.git] /
1 /**
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:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2009 University of California at Berkeley
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
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.
23  */
24 package org.collectionspace.services.common.context;
25
26 import java.util.ArrayList;
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Map;
30
31 import javax.ws.rs.core.MultivaluedMap;
32 import javax.ws.rs.core.UriInfo;
33
34 import org.collectionspace.authentication.spi.AuthNContext;
35 import org.collectionspace.services.client.IClientQueryParams;
36 import org.collectionspace.services.client.IQueryManager;
37 import org.collectionspace.services.client.workflow.WorkflowClient;
38 import org.collectionspace.services.common.ServiceMain;
39 import org.collectionspace.services.common.authorization_mgt.AuthorizationCommon;
40 import org.collectionspace.services.common.config.PropertyItemUtils;
41 import org.collectionspace.services.common.config.ServiceConfigUtils;
42 import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
43 import org.collectionspace.services.common.document.DocumentHandler;
44 import org.collectionspace.services.common.document.DocumentFilter;
45 import org.collectionspace.services.common.document.ValidatorHandler;
46 import org.collectionspace.services.common.security.SecurityContext;
47 import org.collectionspace.services.common.security.SecurityContextImpl;
48 import org.collectionspace.services.common.security.UnauthorizedException;
49 import org.collectionspace.services.config.ClientType;
50 import org.collectionspace.services.config.service.ObjectPartType;
51 import org.collectionspace.services.config.service.ServiceBindingType;
52 import org.collectionspace.services.config.tenant.RepositoryDomainType;
53 import org.collectionspace.services.config.tenant.TenantBindingType;
54 import org.collectionspace.services.config.types.PropertyItemType;
55 import org.collectionspace.services.config.types.PropertyType;
56 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory;
58
59 /**
60  * AbstractServiceContext
61  *
62  * $LastChangedRevision: $
63  * $LastChangedDate: $
64  */
65 /**
66  * @author pschmitz
67  *
68  * @param <IT>
69  * @param <OT>
70  */
71 /**
72  * @author pschmitz
73  *
74  * @param <IT>
75  * @param <OT>
76  */
77 public abstract class AbstractServiceContextImpl<IT, OT>
78         implements ServiceContext<IT, OT> {
79
80     /** The logger. */
81     final Logger logger = LoggerFactory.getLogger(AbstractServiceContextImpl.class);
82     
83     /** The properties. */
84     Map<String, Object> properties = new HashMap<String, Object>();
85     /** The object part map. */
86     Map<String, ObjectPartType> objectPartMap = new HashMap<String, ObjectPartType>();
87     /** The service binding. */
88     protected ServiceBindingType serviceBinding;
89     /** The tenant binding. */
90     private TenantBindingType tenantBinding;
91     /** repository domain used by the service */
92     private RepositoryDomainType repositoryDomain;
93         /** The override document type. */
94     private String overrideDocumentType = null;
95     /** The val handlers. */
96     private List<ValidatorHandler<IT, OT>> valHandlers = null;
97     /** The doc handler. */
98     private DocumentHandler docHandler = null;
99     /** security context */
100     private SecurityContext securityContext;
101     /** The sessions JAX-RS URI information */
102     private UriInfo uriInfo;
103     /** The current repository session */
104     private Object currentRepositorySession;
105     /** A reference count for the current repository session */
106     private int currentRepoSesssionRefCount = 0;
107         
108     /**
109      * Instantiates a new abstract service context impl.
110      */
111     private AbstractServiceContextImpl() {
112         // private constructor for singleton pattern
113     }
114     // request query params
115     /** The query params. */
116     private MultivaluedMap<String, String> queryParams;
117
118     /**
119      * Instantiates a new abstract service context impl.
120      * 
121      * @param serviceName the service name
122      * 
123      * @throws UnauthorizedException the unauthorized exception
124      */
125     protected AbstractServiceContextImpl(String serviceName, UriInfo uriInfo) throws UnauthorizedException {
126
127         //establish security context
128         securityContext = new SecurityContextImpl(uriInfo);
129         //make sure tenant context exists
130         checkTenantContext();
131
132         String tenantId = securityContext.getCurrentTenantId();
133         if (AuthorizationCommon.ALL_TENANTS_MANAGER_TENANT_ID.equals(tenantId) ||
134                         AuthNContext.ANONYMOUS_TENANT_ID.equals(tenantId)) {
135                 // Tenant Manager has no tenant binding, so don't bother...
136                 tenantBinding = null;
137                 serviceBinding = null;
138                 repositoryDomain = null;
139         } else {
140                 //retrieve service bindings
141                 TenantBindingConfigReaderImpl tReader =
142                         ServiceMain.getInstance().getTenantBindingConfigReader();
143                 tenantBinding = tReader.getTenantBinding(tenantId);
144                 if (tenantBinding == null) {
145                     String msg = "No tenant binding found for tenantId=" + tenantId
146                             + " while processing request for service= " + serviceName;
147                     logger.error(msg);
148                     throw new IllegalStateException(msg);
149                 }
150                 serviceBinding = tReader.getServiceBinding(tenantId, serviceName);
151                 if (serviceBinding == null) {
152                     String msg = "No service binding found while processing request for "
153                             + serviceName + " for tenant id=" + getTenantId()
154                             + " name=" + getTenantName();
155                     logger.error(msg);
156                     throw new IllegalStateException(msg);
157                 }
158                 if (logger.isDebugEnabled()) {
159                     logger.debug("tenantId=" + tenantId
160                             + " service binding=" + serviceBinding.getName());
161                 }
162                 repositoryDomain = tReader.getRepositoryDomain(tenantId, serviceName);
163                 if (repositoryDomain != null) {
164                     if (logger.isDebugEnabled()) {
165                         logger.debug("tenantId=" + tenantId
166                                 + " repository doamin=" + repositoryDomain.getName());
167                     }
168                 }
169         }
170     }
171     
172     public int getTimeoutParam(UriInfo ui) {
173                 int result = DEFAULT_TX_TIMEOUT;
174
175                 MultivaluedMap<String, String> queryParams = (ui == null) ? null : ui.getQueryParameters();
176                 if (queryParams != null) {
177                         String timeoutString = queryParams.getFirst(IClientQueryParams.IMPORT_TIMEOUT_PARAM);
178                         if (timeoutString != null)
179                                 try {
180                                         result = Integer.parseInt(timeoutString);
181                                 } catch (NumberFormatException e) {
182                                         logger.warn("Transaction timeout period parameter could not be parsed.  The characters in the parameter string must all be decimal digits.  The Import service will use the default timeout period instead.",
183                                                         e);
184                                 }
185                 }
186
187                 return result;
188         }
189     
190     @Override
191     public int getTimeoutSecs() {
192         UriInfo uriInfo = this.getUriInfo();
193         return this.getTimeoutParam(uriInfo);
194     }
195
196     /* (non-Javadoc)
197      * @see org.collectionspace.services.common.context.ServiceContext#getCommonPartLabel()
198      */
199     @Override
200     public String getCommonPartLabel() {
201         return getCommonPartLabel(getServiceName());
202     }
203
204     /* (non-Javadoc)
205      * @see org.collectionspace.services.common.context.ServiceContext#getCommonPartLabel(java.lang.String)
206      */
207     public String getCommonPartLabel(String schemaName) {
208         return schemaName.toLowerCase() + PART_LABEL_SEPARATOR + PART_COMMON_LABEL;
209     }
210
211     /* (non-Javadoc)
212      * @see org.collectionspace.services.common.context.ServiceContext#getPartsMetadata()
213      */
214     @Override
215     public Map<String, ObjectPartType> getPartsMetadata() {
216         if (objectPartMap.size() != 0) {
217             return objectPartMap;
218         }
219         ServiceBindingUtils.getPartsMetadata(getServiceBinding(), objectPartMap);
220         return objectPartMap;
221     }
222
223     /**
224      * Gets the properties for part.
225      * 
226      * @param partLabel the part label
227      * 
228      * @return the properties for part
229      */
230     public List<PropertyItemType> getPropertiesForPart(String partLabel) {
231         Map<String, ObjectPartType> partMap = getPartsMetadata();
232         ObjectPartType part = partMap.get(partLabel);
233         if (part == null) {
234             throw new RuntimeException("No such part found: " + partLabel);
235         }
236         List<PropertyType> propNodeList = part.getProperties();
237         return propNodeList.isEmpty() ? null : propNodeList.get(0).getItem();
238     }
239
240     /**
241      * @param partLabel The name of the scehma part to search in
242      * @param propName The name of the property (or properties) to find
243      * @param qualified Whether the returned values should be qualified with the
244      *          partLabel. This is when the property values are schema field references.
245      * @return List of property values for the matched property on the named schema part.
246      */
247     public List<String> getPropertyValuesForPart(String partLabel, String propName, boolean qualified) {
248         List<PropertyItemType> allProps = getPropertiesForPart(partLabel);
249         return PropertyItemUtils.getPropertyValuesByName(allProps, propName,
250                 (qualified ? (partLabel + ":") : null));
251     }
252
253     /**
254      * @param propName The name of the property (or properties) to find
255      * @param qualified Whether the returned values should be qualified with the
256      *          partLabel. This is when the property values are schema field references.
257      * @return List of property values for the matched property on any schema part.
258      */
259     public List<String> getAllPartsPropertyValues(String propName, boolean qualified) {
260         return ServiceBindingUtils.getAllPartsPropertyValues(getServiceBinding(), propName, qualified);
261     }
262
263     /* (non-Javadoc)
264      * @see org.collectionspace.services.common.context.ServiceContext#getServiceBindingPropertyValue(java.lang.String)
265      */
266     public String getServiceBindingPropertyValue(String propName) {
267         return ServiceBindingUtils.getPropertyValue(getServiceBinding(), propName);
268     }
269
270     /**
271      * Gets the common part properties.
272      * 
273      * @return the common part properties
274      */
275     public List<PropertyItemType> getCommonPartProperties() {
276         return getPropertiesForPart(getCommonPartLabel());
277     }
278
279     /**
280      * @param propName The name of the property (or properties) to find
281      * @param qualified Whether the returned values should be qualified with the
282      *          partLabel. This is when the property values are schema field references.
283      * @return List of property values for the matched property on the common schema part.
284      */
285     public List<String> getCommonPartPropertyValues(String propName, boolean qualified) {
286         return getPropertyValuesForPart(getCommonPartLabel(), propName, qualified);
287     }
288
289     /* (non-Javadoc)
290      * @see org.collectionspace.services.common.context.ServiceContext#getQualifiedServiceName()
291      */
292     @Override
293     public String getQualifiedServiceName() {
294         return TenantBindingConfigReaderImpl.getTenantQualifiedServiceName(getTenantId(), getServiceName());
295     }
296
297     /* (non-Javadoc)
298      * @see org.collectionspace.services.common.context.ServiceContext#getRepositoryClientName()
299      */
300     @Override
301     public String getRepositoryClientName() {
302         if (repositoryDomain == null) {
303             return null;
304         }
305         return repositoryDomain.getRepositoryClient();
306     }
307
308     /* (non-Javadoc)
309      * @see org.collectionspace.services.common.context.ServiceContext#getRepositoryClientType()
310      */
311     @Override
312     public ClientType getRepositoryClientType() {
313         //assumption: there is only one repository client configured
314         return ServiceMain.getInstance().getClientType();
315     }
316
317     /* (non-Javadoc)
318      * @see org.collectionspace.services.common.context.ServiceContext#getRepositoryDomainName()
319      */
320     @Override
321     public String getRepositoryDomainName() {
322         if (repositoryDomain == null) {
323             return null;
324         }
325         return repositoryDomain.getName();
326     }
327
328     /* (non-Javadoc)
329      * @see org.collectionspace.services.common.context.ServiceContext#getRepositoryDomainName()
330      */
331     @Override
332     public String getRepositoryDomainStorageName() {
333         if (repositoryDomain == null) {
334             return null;
335         }
336         return repositoryDomain.getStorageName();
337     }
338
339     /* (non-Javadoc)
340      * @see org.collectionspace.services.common.context.ServiceContext#getRepositoryWorkspaceId()
341      */
342     @Override
343     public String getRepositoryWorkspaceId() {
344         return ServiceMain.getInstance().getWorkspaceId(getTenantId(), getServiceName());
345     }
346
347     /* (non-Javadoc)
348      * @see org.collectionspace.services.common.context.ServiceContext#getRepositoryWorkspaceName()
349      */
350     @Override
351     public String getRepositoryWorkspaceName() {
352         //service name is workspace name by convention
353         return serviceBinding.getName();
354     }
355
356     /* (non-Javadoc)
357      * @see org.collectionspace.services.common.context.ServiceContext#getServiceBinding()
358      */
359     @Override
360     public ServiceBindingType getServiceBinding() {
361         return serviceBinding;
362     }
363
364     /* (non-Javadoc)
365      * @see org.collectionspace.services.common.context.ServiceContext#getServiceName()
366      */
367     @Override
368     public String getServiceName() {
369         return serviceBinding.getName();
370     }
371
372     /* (non-Javadoc)
373      * @see org.collectionspace.services.common.context.ServiceContext#getDocumentType()
374      */
375     @Override
376     public String getDocumentType() {
377         // If they have not overridden the setting, use the type of the service
378         // object.
379         return (overrideDocumentType != null) ? overrideDocumentType : serviceBinding.getObject().getName();
380     }
381     
382     @Override
383     public String getTenantQualifiedDoctype(String docType) {
384         // If they have not overridden the setting, use the type of the service
385         // object.
386         String result = ServiceBindingUtils.getTenantQualifiedDocType(this.getTenantId(), docType);
387         
388         return result;
389     }
390     
391     @Override
392     public String getTenantQualifiedDoctype() {
393         String docType = (overrideDocumentType != null) ? overrideDocumentType : serviceBinding.getObject().getName();
394         return getTenantQualifiedDoctype(docType);
395     }
396
397     /* (non-Javadoc)
398      * @see org.collectionspace.services.common.context.ServiceContext#setDocumentType(java.lang.String)
399      */
400     @Override
401     public void setDocumentType(String docType) {
402         overrideDocumentType = docType;
403     }
404
405     /* (non-Javadoc)
406      * @see org.collectionspace.services.common.context.ServiceContext#getSecurityContext()
407      */
408     @Override
409     public SecurityContext getSecurityContext() {
410         return securityContext;
411     }
412
413     /* (non-Javadoc)
414      * @see org.collectionspace.services.common.context.ServiceContext#getUserId()
415      */
416     @Override
417     public String getUserId() {
418         return securityContext.getUserId();
419     }
420
421     /* (non-Javadoc)
422      * @see org.collectionspace.services.common.context.ServiceContext#getTenantId()
423      */
424     @Override
425     public String getTenantId() {
426         return securityContext.getCurrentTenantId();
427     }
428
429     /* (non-Javadoc)
430      * @see org.collectionspace.services.common.context.ServiceContext#getTenantName()
431      */
432     @Override
433     public String getTenantName() {
434         return securityContext.getCurrentTenantName();
435     }
436
437     /* (non-Javadoc)
438      * @see org.collectionspace.services.common.context.ServiceContext#getInput()
439      */
440     @Override
441     public abstract IT getInput();
442
443     /* (non-Javadoc)
444      * @see org.collectionspace.services.common.context.ServiceContext#setInput(java.lang.Object)
445      */
446     @Override
447     public abstract void setInput(IT input);
448
449     /* (non-Javadoc)
450      * @see org.collectionspace.services.common.context.ServiceContext#getOutput()
451      */
452     @Override
453     public abstract OT getOutput();
454
455     /* (non-Javadoc)
456      * @see org.collectionspace.services.common.context.ServiceContext#setOutput(java.lang.Object)
457      */
458     @Override
459     public abstract void setOutput(OT output);
460
461     /* (non-Javadoc)
462      * @see org.collectionspace.services.common.context.ServiceContext#getProperties()
463      */
464     @Override
465     public Map<String, Object> getProperties() {
466         return properties;
467     }
468
469     /* (non-Javadoc)
470      * @see org.collectionspace.services.common.context.ServiceContext#setProperties(java.util.Map)
471      */
472     @Override
473     public void setProperties(Map<String, Object> props) {
474         properties.putAll(props);
475     }
476
477     /* (non-Javadoc)
478      * @see org.collectionspace.services.common.context.ServiceContext#getProperty(java.lang.String)
479      */
480     public Object getProperty(String name) {
481         return properties.get(name);
482     }
483
484     /* (non-Javadoc)
485      * @see org.collectionspace.services.common.context.ServiceContext#setProperty(java.lang.String, java.lang.Object)
486      */
487     public void setProperty(String name, Object o) {
488         properties.put(name, o);
489     }
490
491     /**
492      * checkTenantContext makss sure tenant context exists
493      *
494      * @return the string
495      *
496      * @throws UnauthorizedException the unauthorized exception
497      */
498     private void checkTenantContext() throws UnauthorizedException {
499
500         String tenantId = securityContext.getCurrentTenantId();
501         if (tenantId == null) {
502             String msg = "Could not find tenant context";
503             logger.error(msg);
504             throw new UnauthorizedException(msg);
505         }
506     }
507
508     private static String buildWorkflowWhereClause(MultivaluedMap<String, String> queryParams) {
509         String result = null;
510         
511         String includeDeleted = queryParams.getFirst(WorkflowClient.WORKFLOW_QUERY_NONDELETED);
512         if (includeDeleted != null && includeDeleted.equalsIgnoreCase(Boolean.FALSE.toString())) {      
513                 result = "ecm:currentLifeCycleState <> 'deleted'";
514         }
515         
516         return result;
517     }
518     
519     /**
520      * Creates the document handler instance.
521      * 
522      * @return the document handler
523      * 
524      * @throws Exception the exception
525      */
526     private DocumentHandler createDocumentHandlerInstance() throws Exception {
527         docHandler = ServiceConfigUtils.createDocumentHandlerInstance(tenantBinding, serviceBinding);
528         //
529         // Create a default document filter
530         //
531         docHandler.setServiceContext(this);
532         DocumentFilter docFilter = docHandler.createDocumentFilter();
533         //
534         // If the context was created with query parameters,
535         // reflect the values of those parameters in the document filter
536         // to specify sort ordering, pagination, etc.
537         //
538         if (this.getQueryParams() != null) {
539           docFilter.setSortOrder(this.getQueryParams());
540           docFilter.setPagination(this.getQueryParams());
541           String workflowWhereClause = buildWorkflowWhereClause(queryParams);
542           if (workflowWhereClause != null) {
543                   docFilter.appendWhereClause(workflowWhereClause, IQueryManager.SEARCH_QUALIFIER_AND);                 
544           }            
545
546         }
547         docHandler.setDocumentFilter(docFilter);
548
549         return docHandler;
550     }
551
552     /* (non-Javadoc)
553      * @see org.collectionspace.services.common.context.ServiceContext#getDocumentHandler()
554      */
555     @Override
556     public DocumentHandler getDocumentHandler() throws Exception {
557         DocumentHandler result = docHandler;
558         // create a new instance if one does not yet exist
559         if (result == null) {
560             result = createDocumentHandlerInstance();
561         }
562         return result;
563     }
564
565     @Override
566     public void setDocumentHandler(DocumentHandler handler) throws Exception {
567         if (handler != null) {
568                 docHandler = handler;
569         }
570     }
571
572     /* (non-Javadoc)
573      * @see org.collectionspace.services.common.context.ServiceContext#getDocumentHanlder(javax.ws.rs.core.MultivaluedMap)
574      */
575     @Override
576     public DocumentHandler getDocumentHandler(MultivaluedMap<String, String> queryParams) throws Exception {
577         DocumentHandler result = getDocumentHandler();
578         DocumentFilter documentFilter = result.getDocumentFilter(); //to see results in debugger variables view
579         documentFilter.setPagination(queryParams);
580         return result;
581     }
582     
583     /*
584      * If this element is set in the service binding then use it otherwise
585      * assume that asserts are NOT disabled.
586      */
587     private boolean disableValidationAsserts() {
588         boolean result;
589         Boolean disableAsserts = getServiceBinding().isDisableAsserts();
590         result = (disableAsserts != null) ? disableAsserts : false;
591         return result;
592     }
593     
594     /* (non-Javadoc)
595      * @see org.collectionspace.services.common.context.ServiceContext#getValidatorHandlers()
596      */
597     @Override
598     public List<ValidatorHandler<IT, OT>> getValidatorHandlers() throws Exception {
599         if (valHandlers != null) {
600             return valHandlers;
601         }
602         List<String> handlerClazzes = getServiceBinding().getValidatorHandler();
603         List<ValidatorHandler<IT, OT>> handlers = new ArrayList<ValidatorHandler<IT, OT>>(handlerClazzes.size());
604         ClassLoader tccl = Thread.currentThread().getContextClassLoader();
605         for (String clazz : handlerClazzes) {
606             clazz = clazz.trim();
607             try {
608                     Class<?> c = tccl.loadClass(clazz);
609                     if (disableValidationAsserts() == false) {
610                         // enable validation assertions
611                         tccl.setClassAssertionStatus(clazz, true);
612                     }
613                     if (ValidatorHandler.class.isAssignableFrom(c)) {
614                         handlers.add((ValidatorHandler) c.newInstance());
615                     }
616             } catch (ClassNotFoundException e) {
617                 String msg = String.format("Missing document validation handler: '%s'.", clazz);
618                 logger.warn(msg);
619                 logger.trace(msg, e);
620             }
621         }
622         valHandlers = handlers;
623         return valHandlers;
624     }
625     
626     @Override
627     public void addValidatorHandler(ValidatorHandler<IT, OT> validator) throws Exception {
628         if (valHandlers == null) {
629             valHandlers = new ArrayList<ValidatorHandler<IT, OT>>();
630         }
631         valHandlers.add(validator);
632     }
633
634     /* (non-Javadoc)
635      * @see java.lang.Object#toString()
636      */
637     @Override
638     public String toString() {
639         StringBuilder msg = new StringBuilder();
640         msg.append("AbstractServiceContext [");
641         msg.append("service name=" + serviceBinding.getName() + " ");
642         msg.append("service version=" + serviceBinding.getVersion() + " ");
643         msg.append("tenant id=" + tenantBinding.getId() + " ");
644         msg.append("tenant name=" + tenantBinding.getName() + " ");
645         msg.append(tenantBinding.getDisplayName() + " ");
646         if (repositoryDomain != null) {
647             msg.append("tenant repository domain=" + repositoryDomain.getName());
648         }
649         for (Map.Entry<String, Object> entry : properties.entrySet()) {
650             msg.append("property name=" + entry.getKey() + " value=" + entry.getValue().toString());
651         }
652         msg.append("]");
653         return msg.toString();
654     }
655
656     /* (non-Javadoc)
657      * @see org.collectionspace.services.common.context.ServiceContext#getQueryParams()
658      */
659     @Override
660     public MultivaluedMap<String, String> getQueryParams() {
661
662          if (queryParams == null){
663               if (this.uriInfo != null){
664                 queryParams = this.uriInfo.getQueryParameters();
665             }
666          }
667          if (queryParams == null){
668              queryParams = new org.jboss.resteasy.specimpl.MultivaluedMapImpl<String,String>();
669         }
670         return this.queryParams;
671     }
672
673     @Override
674      public MultivaluedMap<String, String> getQueryParamsPtr() {
675            return this.queryParams;
676     }
677
678     /* (non-Javadoc)
679      * @see org.collectionspace.services.common.context.ServiceContext#setQueryParams(javax.ws.rs.core.MultivaluedMap)
680      */
681     @Override
682     public void setQueryParams(MultivaluedMap<String, String> theQueryParams) {
683         this.queryParams = theQueryParams;
684     }
685
686     @Override
687     public void setUriInfo(UriInfo ui){
688         this.uriInfo = ui;
689     }
690
691         @Override
692         public UriInfo getUriInfo() {
693                 return this.uriInfo;
694         }
695         
696         /*
697          * We expect the 'currentRepositorySession' member to be set only once per instance.  Also, we expect only one open repository session
698          * per HTTP request.  We'll log an error if we see more than one attempt to set a service context's current repo session.
699          * (non-Javadoc)
700          * @see org.collectionspace.services.common.context.ServiceContext#setCurrentRepositorySession(java.lang.Object)
701          */
702         @Override
703         public void setCurrentRepositorySession(Object repoSession) throws Exception {
704                 if (repoSession == null) {
705                         String errMsg = "Setting a service context's repository session to null is not allowed.";
706                         logger.error(errMsg);
707                         throw new Exception(errMsg);
708                 } else if (currentRepositorySession != null && currentRepositorySession != repoSession) {
709                         String errMsg = "The current service context's repository session was replaced.  This may cause unexpected behavior and/or data loss.";
710                         logger.error(errMsg);
711                         throw new Exception(errMsg);
712                 }
713                 
714                 currentRepositorySession = repoSession;
715                 this.currentRepoSesssionRefCount++;
716         }
717         
718         @Override
719         public void clearCurrentRepositorySession() {
720                 if (this.currentRepoSesssionRefCount > 0) {
721                         currentRepoSesssionRefCount--;
722                 }
723                 
724                 if (currentRepoSesssionRefCount == 0) {
725                         this.currentRepositorySession = null;
726                 }
727         }
728         
729         @Override
730         public Object getCurrentRepositorySession() {
731                 // TODO Auto-generated method stub
732                 return currentRepositorySession;
733         }       
734
735         @Override       
736         public RepositoryDomainType getRepositoryDomain() {
737                 return repositoryDomain;
738         }
739
740         @Override       
741         public void setRepositoryDomain(RepositoryDomainType repositoryDomain) {
742                 this.repositoryDomain = repositoryDomain;
743         }
744 }