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.context;
26 import java.util.HashMap;
27 import java.util.List;
29 import org.collectionspace.services.common.ClientType;
30 import org.collectionspace.services.common.ServiceMain;
31 import org.collectionspace.services.common.config.TenantBindingConfigReader;
32 import org.collectionspace.services.common.service.ObjectPartType;
33 import org.collectionspace.services.common.service.ServiceBindingType;
34 import org.collectionspace.services.common.service.ServiceObjectType;
35 import org.collectionspace.services.common.tenant.TenantBindingType;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
40 * AbstractServiceContext
42 * $LastChangedRevision: $
45 public abstract class AbstractServiceContext<IT, OT>
46 implements ServiceContext<IT, OT> {
48 final Logger logger = LoggerFactory.getLogger(AbstractServiceContext.class);
49 Map<String, ObjectPartType> objectPartMap = new HashMap<String, ObjectPartType>();
50 private ServiceBindingType serviceBinding;
51 private TenantBindingType tenantBinding;
53 private String overrideDocumentType = null;
55 public AbstractServiceContext(String serviceName) {
56 TenantBindingConfigReader tReader =
57 ServiceMain.getInstance().getTenantBindingConfigReader();
58 //TODO: get tenant binding from security context (Subject.g
59 String tenantId = "1"; //hardcoded for movingimages.us
60 tenantBinding = tReader.getTenantBinding(tenantId);
61 if(tenantBinding == null){
62 String msg = "No tenant binding found while processing request for " +
65 throw new IllegalStateException(msg);
67 serviceBinding = tReader.getServiceBinding(tenantId, serviceName);
68 if(serviceBinding == null){
69 String msg = "No service binding found while processing request for " +
70 serviceName + " for tenant id=" + getTenantId() +
71 " name=" + getTenantName();
73 throw new IllegalStateException(msg);
75 if(logger.isDebugEnabled()){
76 logger.debug("tenantId=" + tenantId +
77 " service binding=" + serviceBinding.getName());
82 * getCommonPartLabel get common part label
86 public String getCommonPartLabel() {
87 return getCommonPartLabel(getServiceName());
91 * getCommonPartLabel get common part label
94 public String getCommonPartLabel(String schemaName) {
95 return schemaName.toLowerCase() + PART_LABEL_SEPERATOR + PART_COMMON_LABEL;
99 public Map<String, ObjectPartType> getPartsMetadata() {
100 if(objectPartMap.size() != 0){
101 return objectPartMap;
103 ServiceBindingType serviceBinding = getServiceBinding();
104 List<ServiceObjectType> objectTypes = serviceBinding.getObject();
105 for(ServiceObjectType objectType : objectTypes){
106 List<ObjectPartType> objectPartTypes = objectType.getPart();
107 for(ObjectPartType objectPartType : objectPartTypes){
108 objectPartMap.put(objectPartType.getLabel(), objectPartType);
111 return objectPartMap;
115 public String getQualifiedServiceName() {
116 return TenantBindingConfigReader.getTenantQualifiedServiceName(getTenantId(), getServiceName());
120 public String getRepositoryClientName() {
121 return serviceBinding.getRepositoryClient();
125 public ClientType getRepositoryClientType() {
126 //assumption: there is only one repository client configured
127 return ServiceMain.getInstance().getClientType();
131 public String getRepositoryDomainName() {
132 return tenantBinding.getRepositoryDomain();
136 public String getRepositoryWorkspaceId() {
137 TenantBindingConfigReader tbConfigReader = ServiceMain.getInstance().getTenantBindingConfigReader();
138 return tbConfigReader.getWorkspaceId(getTenantId(), getServiceName());
142 public String getRepositoryWorkspaceName() {
143 //service name is workspace name by convention
144 return serviceBinding.getName();
148 public ServiceBindingType getServiceBinding() {
149 return serviceBinding;
153 public String getServiceName() {
154 return serviceBinding.getName();
158 public String getDocumentType() {
159 // If they have not overridden the setting, use the type of the service
161 return(overrideDocumentType!=null)?overrideDocumentType:
162 serviceBinding.getObject().get(0).getName();
166 public void setDocumentType(String docType) {
167 overrideDocumentType = docType;
171 public String getTenantId() {
172 return tenantBinding.getId();
176 public String getTenantName() {
177 return tenantBinding.getName();
181 public abstract IT getInput();
184 public abstract void setInput(IT input) throws Exception;
187 public abstract OT getOutput();
190 public abstract void setOutput(OT output) throws Exception;
193 public String toString() {
194 return "AbstractServiceContext [" +
195 "service name=" + serviceBinding.getName() + " " +
196 "service version=" + serviceBinding.getVersion() + " " +
197 "tenant id=" + tenantBinding.getId() + " " +
198 "tenant name=" + tenantBinding.getName() + " " +
199 tenantBinding.getDisplayName() + " " +
200 "tenant repository domain=" + tenantBinding.getRepositoryDomain() + " " +