<artifactId>org.collectionspace.services.authorization.jaxb</artifactId>\r
<version>${project.version}</version>\r
</dependency>\r
+ <dependency>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <artifactId>org.collectionspace.services.common</artifactId>\r
+ <version>${project.version}</version>\r
+ <scope>provided</scope>\r
+ </dependency>\r
<dependency>\r
<groupId>org.collectionspace.services</groupId>\r
<artifactId>org.collectionspace.services.client</artifactId>\r
import org.collectionspace.services.common.types.PropertyItemType;
import org.collectionspace.services.common.types.PropertyType;
import org.collectionspace.services.nuxeo.client.java.NuxeoConnector;
+import org.collectionspace.services.nuxeo.client.java.TenantRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @return
*/
public static ServiceMain getInstance() {
- if(instance == null){
- synchronized(ServiceMain.class){
- if(instance == null){
+ if (instance == null) {
+ synchronized (ServiceMain.class) {
+ if (instance == null) {
ServiceMain temp = new ServiceMain();
- try{
+ try {
temp.initialize();
- }catch(Exception e){
+ } catch (Exception e) {
instance = null;
- if(e instanceof RuntimeException){
+ if (e instanceof RuntimeException) {
throw (RuntimeException) e;
- }else{
+ } else {
throw new RuntimeException(e);
}
}
setServerRootDir();
readConfig();
propagateConfiguredProperties();
- if(getClientType().equals(ClientType.JAVA)){
+ if (getClientType().equals(ClientType.JAVA)) {
nuxeoConnector = NuxeoConnector.getInstance();
nuxeoConnector.initialize(
getServicesConfigReader().getConfiguration().getRepositoryClient());
* but not necessarily those occupied by individual services
*/
public void release() {
- try{
- if(nuxeoConnector != null){
+ try {
+ if (nuxeoConnector != null) {
nuxeoConnector.release();
}
instance = null;
- }catch(Exception e){
+ } catch (Exception e) {
e.printStackTrace();
//gobble it
}
tenantBindingConfigReader = new TenantBindingConfigReaderImpl(getServerRootDir());
getTenantBindingConfigReader().read();
}
-
+
private void propagateConfiguredProperties() {
- List<PropertyType> repoPropListHolder =
- servicesConfigReader.getConfiguration().getRepositoryClient().getProperties();
- if(repoPropListHolder != null && !repoPropListHolder.isEmpty()) {
- List<PropertyItemType> propList = repoPropListHolder.get(0).getItem();
- if(propList != null && !propList.isEmpty()) {
- tenantBindingConfigReader.setDefaultPropertiesOnTenants(propList, true);
- }
- }
+ List<PropertyType> repoPropListHolder =
+ servicesConfigReader.getConfiguration().getRepositoryClient().getProperties();
+ if (repoPropListHolder != null && !repoPropListHolder.isEmpty()) {
+ List<PropertyItemType> propList = repoPropListHolder.get(0).getItem();
+ if (propList != null && !propList.isEmpty()) {
+ tenantBindingConfigReader.setDefaultPropertiesOnTenants(propList, true);
+ }
+ }
}
void retrieveAllWorkspaceIds() throws Exception {
//all configs are read, connector is initialized, retrieve workspaceids
- getTenantBindingConfigReader().retrieveAllWorkspaceIds();
+ Hashtable<String, TenantBindingType> tenantBindings =
+ getTenantBindingConfigReader().getTenantBindings();
+ TenantRepository.get().retrieveAllWorkspaceIds(tenantBindings);
+ }
+
+ /**
+ * getWorkspaceId returns workspace id for given tenant and service name
+ * @param tenantId
+ * @param serviceName
+ * @return
+ */
+ public String getWorkspaceId(String tenantId, String serviceName) {
+ return TenantRepository.get().getWorkspaceId(tenantId, serviceName);
}
/**
public NuxeoConnector getNuxeoConnector() {
return nuxeoConnector;
}
+
+ /**
+ * @return the serverRootDir
+ */
+ public String getServerRootDir() {
+ return serverRootDir;
+ }
private void setServerRootDir() {
serverRootDir = System.getProperty("jboss.server.home.dir");
- if(serverRootDir == null){
+ if (serverRootDir == null) {
serverRootDir = "."; //assume server is started from server root, e.g. server/cspace
}
}
- /**
- * @return the serverRootDir
- */
- public String getServerRootDir() {
- return serverRootDir;
- }
/**
* @return the serviceConfig
import java.util.Hashtable;
import java.util.List;
-import org.collectionspace.services.common.ClientType;
-import org.collectionspace.services.common.RepositoryClientConfigType;
-import org.collectionspace.services.common.ServiceMain;
-import org.collectionspace.services.common.repository.RepositoryClient;
-import org.collectionspace.services.common.repository.RepositoryClientFactory;
import org.collectionspace.services.common.service.ServiceBindingType;
import org.collectionspace.services.common.tenant.TenantBindingType;
import org.collectionspace.services.common.tenant.TenantBindingConfig;
//tenant-qualified servicename, service binding
private Hashtable<String, ServiceBindingType> serviceBindings =
new Hashtable<String, ServiceBindingType>();
- //tenant-qualified service, workspace
- private Hashtable<String, String> serviceWorkspaces = new Hashtable<String, String>();
public TenantBindingConfigReaderImpl(String serverRootDir) {
super(serverRootDir);
}
}
- /**
- * retrieveWorkspaceIds is called at initialization time to retrieve
- * workspace ids of all the tenants
- * @throws Exception
- */
- public void retrieveAllWorkspaceIds() throws Exception {
- for (TenantBindingType tenantBinding : tenantBindings.values()) {
- retrieveWorkspaceIds(tenantBinding);
- }
- }
-
- /**
- * retrieveWorkspaceIds retrieves workspace ids for services used by
- * the given tenant
- * @param tenantBinding
- * @throws Exception
- */
- public void retrieveWorkspaceIds(TenantBindingType tenantBinding) throws Exception {
- Hashtable<String, String> workspaceIds = new Hashtable<String, String>();
- ServiceMain svcMain = ServiceMain.getInstance();
- RepositoryClientConfigType rclientConfig = svcMain.getServicesConfigReader().getConfiguration().getRepositoryClient();
- ClientType clientType = svcMain.getClientType();
- if (clientType.equals(ClientType.JAVA)
- && rclientConfig.getName().equalsIgnoreCase("nuxeo-java")) {
- //FIXME only one repository client is recognized
- workspaceIds = svcMain.getNuxeoConnector().retrieveWorkspaceIds(
- tenantBinding.getRepositoryDomain());
- }
- //verify if workspace exists for each service in the tenant binding
- for (ServiceBindingType serviceBinding : tenantBinding.getServiceBindings()) {
- String serviceName = serviceBinding.getName();
- String repositoryClientName = serviceBinding.getRepositoryClient();
- if (repositoryClientName == null) {
- //no repository needed for this service...skip
- if (logger.isInfoEnabled()) {
- logger.info("The service " + serviceName
- + " does not seem to require a document repository.");
- }
- continue;
- }
-
- if (repositoryClientName.isEmpty()) {
- String msg = "Invalid repositoryClient " + serviceName;
- logger.error(msg);
- continue;
- }
- repositoryClientName = repositoryClientName.trim();
- RepositoryClient repositoryClient = getRepositoryClient(
- repositoryClientName);
- if (repositoryClient == null) {
- String msg = "Could not find repositoryClient " + repositoryClientName
- + " for service=" + serviceName;
- logger.error(msg);
- continue;
- }
- String workspaceId = null;
- //workspace name is service name by convention
- String workspace = serviceName.toLowerCase();
- if (clientType.equals(ClientType.JAVA)) {
- workspaceId = workspaceIds.get(workspace);
- if (workspaceId == null) {
- if (logger.isWarnEnabled()) {
- logger.warn("Failed to retrieve workspace ID for " + workspace
- + " from repository, trying to create a new workspace ...");
- }
- workspaceId = repositoryClient.createWorkspace(
- tenantBinding.getRepositoryDomain(),
- serviceBinding.getName());
- if (workspaceId == null) {
- if (logger.isWarnEnabled()) {
- logger.warn("Failed to create workspace in repository"
- + " for service=" + workspace);
- }
- continue;
- }
- if (logger.isDebugEnabled()) {
- logger.debug("Successfully created workspace in repository" +
- " id=" + workspaceId + " for service=" + workspace);
- }
- }
- } else {
- workspaceId = serviceBinding.getRepositoryWorkspaceId();
- if (workspaceId == null || "".equals(workspaceId)) {
- logger.error("Could not find workspace in repository for" +
- " service=" + workspace);
- //FIXME: should we throw an exception here?
- continue;
- }
- }
- String tenantService = getTenantQualifiedServiceName(tenantBinding.getId(), serviceName);
- serviceWorkspaces.put(tenantService, workspaceId);
- if (logger.isInfoEnabled()) {
- logger.info("Created/retrieved repository workspace=" +
- workspace + " id=" + workspaceId
- + " for service=" + serviceName);
- }
- }
- }
-
@Override
public TenantBindingConfig getConfiguration() {
return tenantBindingConfig;
}
+ /**
+ * getTenantBindings returns all the tenant bindings read from configuration
+ * @return
+ */
+ public Hashtable<String, TenantBindingType> getTenantBindings() {
+ return tenantBindings;
+ }
+
/**
* getTenantBinding gets tenant binding for given tenant
* @param tenantId
return list;
}
- /**
- * getWorkspaceId retrieves workspace id for given tenant for given service
- * @param tenantId
- * @param serviceName
- * @return
- */
- public String getWorkspaceId(String tenantId, String serviceName) {
- String tenantService = getTenantQualifiedServiceName(tenantId, serviceName);
- return serviceWorkspaces.get(tenantService);
- }
/**
* @param tenantId
return tenantId + "." + serviceName.toLowerCase();
}
- private RepositoryClient getRepositoryClient(String clientName) {
- return RepositoryClientFactory.getInstance().getClient(clientName);
- }
-
/**
* Sets properties in the passed list on the local properties for this TenantBinding.
* Note: will only set properties not already set on the TenantBinding.
*/
@Override
public String getRepositoryWorkspaceId() {
- TenantBindingConfigReaderImpl tbConfigReader = ServiceMain.getInstance().getTenantBindingConfigReader();
- return tbConfigReader.getWorkspaceId(getTenantId(), getServiceName());
+ return ServiceMain.getInstance().getWorkspaceId(getTenantId(), getServiceName());
}
/* (non-Javadoc)
--- /dev/null
+/**
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+
+ * Copyright 2010 University of California at Berkeley
+
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+
+ * You may obtain a copy of the ECL 2.0 License at
+
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.collectionspace.services.nuxeo.client.java;
+
+import java.util.Hashtable;
+import org.collectionspace.services.common.ServiceMain;
+import org.collectionspace.services.common.ClientType;
+import org.collectionspace.services.common.RepositoryClientConfigType;
+import org.collectionspace.services.common.repository.RepositoryClient;
+import org.collectionspace.services.common.repository.RepositoryClientFactory;
+import org.collectionspace.services.common.service.ServiceBindingType;
+import org.collectionspace.services.common.tenant.TenantBindingType;
+import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * TenatnRepository is used to retrieve workspaces for a tenant as well as to
+ * create workspaces for each service used by a teant
+ * @author
+ */
+public class TenantRepository {
+
+ final private static TenantRepository self = new TenantRepository();
+
+ final Logger logger = LoggerFactory.getLogger(TenantRepository.class);
+ //tenant-qualified service, workspace
+ private Hashtable<String, String> serviceWorkspaces = new Hashtable<String, String>();
+
+ private TenantRepository() {
+
+ }
+
+ public static TenantRepository get() {
+ return self;
+ }
+
+ /**
+ * retrieveWorkspaceIds is called at initialization time to retrieve
+ * workspace ids of all the tenants
+ * @param hashtable <tenant name, tenantbinding>
+ * @throws Exception
+ */
+ synchronized public void retrieveAllWorkspaceIds(Hashtable<String, TenantBindingType> tenantBindings)
+ throws Exception {
+ for (TenantBindingType tenantBinding : tenantBindings.values()) {
+ retrieveWorkspaceIds(tenantBinding);
+ }
+ }
+
+ /**
+ * retrieveWorkspaceIds retrieves workspace ids for services used by
+ * the given tenant
+ * @param tenantBinding
+ * @throws Exception
+ */
+ synchronized public void retrieveWorkspaceIds(TenantBindingType tenantBinding) throws Exception {
+ Hashtable<String, String> workspaceIds = new Hashtable<String, String>();
+ ServiceMain svcMain = ServiceMain.getInstance();
+ RepositoryClientConfigType rclientConfig = svcMain.getServicesConfigReader().getConfiguration().getRepositoryClient();
+ ClientType clientType = svcMain.getClientType();
+ if (clientType.equals(ClientType.JAVA)
+ && rclientConfig.getName().equalsIgnoreCase("nuxeo-java")) {
+ //FIXME only one repository client is recognized
+ workspaceIds = svcMain.getNuxeoConnector().retrieveWorkspaceIds(
+ tenantBinding.getRepositoryDomain());
+ }
+ //verify if workspace exists for each service in the tenant binding
+ for (ServiceBindingType serviceBinding : tenantBinding.getServiceBindings()) {
+ String serviceName = serviceBinding.getName();
+ String repositoryClientName = serviceBinding.getRepositoryClient();
+ if (repositoryClientName == null) {
+ //no repository needed for this service...skip
+ if (logger.isInfoEnabled()) {
+ logger.info("The service " + serviceName
+ + " does not seem to require a document repository.");
+ }
+ continue;
+ }
+
+ if (repositoryClientName.isEmpty()) {
+ String msg = "Invalid repositoryClient " + serviceName;
+ logger.error(msg);
+ continue;
+ }
+ repositoryClientName = repositoryClientName.trim();
+ RepositoryClient repositoryClient = getRepositoryClient(
+ repositoryClientName);
+ if (repositoryClient == null) {
+ String msg = "Could not find repositoryClient " + repositoryClientName
+ + " for service=" + serviceName;
+ logger.error(msg);
+ continue;
+ }
+ String workspaceId = null;
+ //workspace name is service name by convention
+ String workspace = serviceName.toLowerCase();
+ if (clientType.equals(ClientType.JAVA)) {
+ workspaceId = workspaceIds.get(workspace);
+ if (workspaceId == null) {
+ if (logger.isWarnEnabled()) {
+ logger.warn("Failed to retrieve workspace ID for " + workspace
+ + " from repository, trying to create a new workspace ...");
+ }
+ workspaceId = repositoryClient.createWorkspace(
+ tenantBinding.getRepositoryDomain(),
+ serviceBinding.getName());
+ if (workspaceId == null) {
+ if (logger.isWarnEnabled()) {
+ logger.warn("Failed to create workspace in repository"
+ + " for service=" + workspace);
+ }
+ continue;
+ }
+ if (logger.isDebugEnabled()) {
+ logger.debug("Successfully created workspace in repository"
+ + " id=" + workspaceId + " for service=" + workspace);
+ }
+ }
+ } else {
+ workspaceId = serviceBinding.getRepositoryWorkspaceId();
+ if (workspaceId == null || "".equals(workspaceId)) {
+ logger.error("Could not find workspace in repository for"
+ + " service=" + workspace);
+ //FIXME: should we throw an exception here?
+ continue;
+ }
+ }
+ String tenantService =
+ TenantBindingConfigReaderImpl.getTenantQualifiedServiceName(tenantBinding.getId(), serviceName);
+ serviceWorkspaces.put(tenantService, workspaceId);
+ if (logger.isInfoEnabled()) {
+ logger.info("Created/retrieved repository workspace="
+ + workspace + " id=" + workspaceId
+ + " for service=" + serviceName);
+ }
+ }
+ }
+
+ /**
+ * getWorkspaceId for a tenant's service
+ * @param tenantId
+ * @param serviceName
+ * @return workspace id
+ */
+ public String getWorkspaceId(String tenantId, String serviceName) {
+ String tenantService =
+ TenantBindingConfigReaderImpl.getTenantQualifiedServiceName(tenantId, serviceName);
+ return serviceWorkspaces.get(tenantService);
+ }
+
+
+ private RepositoryClient getRepositoryClient(String clientName) {
+ return RepositoryClientFactory.getInstance().getClient(clientName);
+ }
+}