+++ /dev/null
-/**
-* Copyright (C) 2014 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-package eu.etaxonomy.cdm.remote;
-
-import java.util.Map;
-
-import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
-
-import eu.etaxonomy.cdm.api.service.IDatabaseService;
-import eu.etaxonomy.cdm.config.CdmSource;
-import eu.etaxonomy.cdm.config.CdmSourceException;
-import eu.etaxonomy.cdm.model.metadata.CdmMetaData.MetaDataPropertyName;
-import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
-
-/**
- * Base class representing a CDM remote source.
- * This class handles all the configuration relating to the remoting aspect of
- * a CDM source.
- *
- */
-public class CdmRemoteSourceBase extends CdmSource implements ICdmRemoteSource {
-
- protected static final String DEFAULT_NAME = "default";
- protected static final String DEFAULT_SERVER = "127.0.0.1";
- protected static final int DEFAULT_PORT = 8080;
- protected static final String DEFAULT_CONTEXT_PATH = "";
- protected static final NomenclaturalCode DEFAULT_NOMENCLATURAL_CODE = NomenclaturalCode.ICNAFP;
- private String contextPath;
- private String baseUrl;
-
- private IDatabaseService databaseService;
-
- /**
- * Constructs a CdmRemoteSourceBase object with default values.
- *
- */
- protected CdmRemoteSourceBase() {
- setName(DEFAULT_NAME);
- setServer(DEFAULT_SERVER);
- setPort(DEFAULT_PORT);
- setContextPath(DEFAULT_CONTEXT_PATH);
- setNomenclaturalCode(DEFAULT_NOMENCLATURAL_CODE);
- }
-
- /**
- * Constructs a CdmRemoteSourceBase
- *
- * @param name
- * @param server
- * @param port
- * @param contextPath
- * @param nomenclaturalCode
- */
- public CdmRemoteSourceBase(String name, String server, int port, String contextPath, NomenclaturalCode nomenclaturalCode) {
- setName(name);
- setServer(server);
- setPort(port);
- setContextPath(contextPath);
- setNomenclaturalCode(nomenclaturalCode);
- initDatabaseConnection();
- }
-
- protected void initDatabaseConnection() {
- if(getContextPath() == null || getContextPath().equals("")) {
- setBaseUrl("http://" + getServer() + ":" + String.valueOf(getPort()));
- } else {
- setBaseUrl("http://" + getServer() + ":" + String.valueOf(getPort()) + "/" + getContextPath());
- }
- // the database service needs to be initialised (before the spring
- // application context initialsation) since it is required to
- // to make queries related to the source database
- HttpInvokerProxyFactoryBean proxy = new HttpInvokerProxyFactoryBean();
- proxy.setServiceInterface(IDatabaseService.class);
- proxy.setServiceUrl(baseUrl + "/remoting/database.service");
- proxy.afterPropertiesSet();
- databaseService = (IDatabaseService) proxy.getObject();
-
- }
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.cdm.remote.ICdmRemoteSource#getBaseUrl()
- */
- @Override
- public String getBaseUrl() {
- return baseUrl;
- }
-
- /**
- * Sets the base url for the http-invoker services as listed in
- * httpInvokerServicesClients.xml.
- * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
- * base url would be 'http://127.0.0.1:8080/col'
- *
- * @param baseUrl
- */
- public void setBaseUrl(String baseUrl) {
- this.baseUrl = baseUrl;
- }
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.cdm.remote.ICdmRemoteSource#getContextPath()
- */
- @Override
- public String getContextPath() {
- return contextPath;
- }
-
- /**
- * Sets the context path.
- * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
- * context path would be 'col'
- *
- * @param contextPath
- */
- public void setContextPath(String contextPath) {
- this.contextPath = contextPath;
- }
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.cdm.config.CdmSource#getDbSchemaVersion()
- */
- @Override
- public String getDbSchemaVersion() throws CdmSourceException {
- return databaseService.getDbSchemaVersion();
-
- }
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.cdm.config.CdmSource#isDbEmpty()
- */
- @Override
- public boolean isDbEmpty() throws CdmSourceException {
- return databaseService.isDbEmpty();
-
- }
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.cdm.config.CdmSource#checkConnection()
- */
- @Override
- public boolean checkConnection() throws CdmSourceException {
- // assuming that database service works implies
- // the connection is up
- // if no exception is thrown then we assume that the
- // connection is up
- // FIXME:Remoting is this really correct?
- databaseService.getDbSchemaVersion();
-
- return true;
- }
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.cdm.config.CdmSource#getConnectionMessage()
- */
- @Override
- public String getConnectionMessage() {
- return "Conncting to Remote CDM Server " + getName();
- }
-
-
- @Override
- public Map<MetaDataPropertyName, String> getMetaDataMap() throws CdmSourceException {
- return databaseService.getCdmMetadataMap();
- }
-
-
-}