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<T1, T2>
46 implements ServiceContext<T1, T2> {
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 public AbstractServiceContext(String serviceName) {
54 TenantBindingConfigReader tReader =
55 ServiceMain.getInstance().getTenantBindingConfigReader();
56 //TODO: get tenant binding from security context (Subject.g
57 String tenantId = "1"; //hardcoded for movingimages.us
58 tenantBinding = tReader.getTenantBinding(tenantId);
59 if(tenantBinding == null){
60 String msg = "No tenant binding found while processing request for " +
63 throw new IllegalStateException(msg);
65 serviceBinding = tReader.getServiceBinding(tenantId, serviceName);
66 if(serviceBinding == null){
67 String msg = "No service binding found while processing request for " +
68 serviceName + " for tenant id=" + getTenantId() +
69 " name=" + getTenantName();
71 throw new IllegalStateException(msg);
73 if(logger.isDebugEnabled()){
74 logger.debug("tenantId=" + tenantId +
75 " service binding=" + serviceBinding.getName());
80 * getCommonPartLabel get common part label
84 public String getCommonPartLabel() {
85 return getServiceName().toLowerCase() + "-common";
89 public Map<String, ObjectPartType> getPartsMetadata() {
90 if(objectPartMap.size() != 0){
93 ServiceBindingType serviceBinding = getServiceBinding();
94 List<ServiceObjectType> objectTypes = serviceBinding.getObject();
95 for(ServiceObjectType objectType : objectTypes){
96 List<ObjectPartType> objectPartTypes = objectType.getPart();
97 for(ObjectPartType objectPartType : objectPartTypes){
98 objectPartMap.put(objectPartType.getLabel(), objectPartType);
101 return objectPartMap;
105 public String getQualifiedServiceName() {
106 return TenantBindingConfigReader.getTenantQualifiedServiceName(getTenantId(), getServiceName());
110 public String getRepositoryClientName() {
111 return serviceBinding.getRepositoryClient();
115 public ClientType getRepositoryClientType() {
116 //assumption: there is only one repository client configured
117 return ServiceMain.getInstance().getClientType();
121 public String getRepositoryDomainName() {
122 return tenantBinding.getRepositoryDomain();
126 public String getRepositoryWorkspaceId() {
127 TenantBindingConfigReader tbConfigReader = ServiceMain.getInstance().getTenantBindingConfigReader();
128 return tbConfigReader.getWorkspaceId(getTenantId(), getServiceName());
132 public String getRepositoryWorkspaceName() {
133 //service name is workspace name by convention
134 return serviceBinding.getName();
138 public ServiceBindingType getServiceBinding() {
139 return serviceBinding;
143 public String getServiceName() {
144 return serviceBinding.getName();
148 public String getTenantId() {
149 return tenantBinding.getId();
153 public String getTenantName() {
154 return tenantBinding.getName();
158 public abstract T1 getInput();
161 public abstract void setInput(T1 input) throws Exception;
164 public abstract T2 getOutput();
167 public abstract void setOutput(T2 output) throws Exception;
170 public String toString() {
171 return "AbstractServiceContext [" +
172 "service name=" + serviceBinding.getName() + " " +
173 "service version=" + serviceBinding.getVersion() + " " +
174 "tenant id=" + tenantBinding.getId() + " " +
175 "tenant name=" + tenantBinding.getName() + " " +
176 tenantBinding.getDisplayName() + " " +
177 "tenant repository domain=" + tenantBinding.getRepositoryDomain() + " " +