2 * Copyright (C) 2014 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.remote
;
13 import org
.springframework
.remoting
.httpinvoker
.HttpInvokerProxyFactoryBean
;
15 import eu
.etaxonomy
.cdm
.api
.service
.IDatabaseService
;
16 import eu
.etaxonomy
.cdm
.config
.CdmSource
;
17 import eu
.etaxonomy
.cdm
.config
.CdmSourceException
;
18 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmMetaData
.MetaDataPropertyName
;
19 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
22 * Base class representing a CDM remote source.
23 * This class handles all the configuration relating to the remoting aspect of
27 public class CdmRemoteSourceBase
extends CdmSource
implements ICdmRemoteSource
{
29 protected static final String DEFAULT_NAME
= "default";
30 protected static final String DEFAULT_SERVER
= "127.0.0.1";
31 protected static final int DEFAULT_PORT
= 8080;
32 protected static final String DEFAULT_CONTEXT_PATH
= "";
33 protected static final NomenclaturalCode DEFAULT_NOMENCLATURAL_CODE
= NomenclaturalCode
.ICNAFP
;
34 private String contextPath
;
35 private String baseUrl
;
37 private IDatabaseService databaseService
;
40 * Constructs a CdmRemoteSourceBase object with default values.
43 protected CdmRemoteSourceBase() {
44 setName(DEFAULT_NAME
);
45 setServer(DEFAULT_SERVER
);
46 setPort(DEFAULT_PORT
);
47 setContextPath(DEFAULT_CONTEXT_PATH
);
48 setNomenclaturalCode(DEFAULT_NOMENCLATURAL_CODE
);
52 * Constructs a CdmRemoteSourceBase
58 * @param nomenclaturalCode
60 public CdmRemoteSourceBase(String name
, String server
, int port
, String contextPath
, NomenclaturalCode nomenclaturalCode
) {
64 setContextPath(contextPath
);
65 setNomenclaturalCode(nomenclaturalCode
);
66 initDatabaseConnection();
69 protected void initDatabaseConnection() {
70 if(getContextPath() == null || getContextPath().equals("")) {
71 setBaseUrl("http://" + getServer() + ":" + String
.valueOf(getPort()));
73 setBaseUrl("http://" + getServer() + ":" + String
.valueOf(getPort()) + "/" + getContextPath());
75 // the database service needs to be initialised (before the spring
76 // application context initialsation) since it is required to
77 // to make queries related to the source database
78 HttpInvokerProxyFactoryBean proxy
= new HttpInvokerProxyFactoryBean();
79 proxy
.setServiceInterface(IDatabaseService
.class);
80 proxy
.setServiceUrl(baseUrl
+ "/remoting/database.service");
81 proxy
.afterPropertiesSet();
82 databaseService
= (IDatabaseService
) proxy
.getObject();
87 * @see eu.etaxonomy.cdm.remote.ICdmRemoteSource#getBaseUrl()
90 public String
getBaseUrl() {
95 * Sets the base url for the http-invoker services as listed in
96 * httpInvokerServicesClients.xml.
97 * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
98 * base url would be 'http://127.0.0.1:8080/col'
102 public void setBaseUrl(String baseUrl
) {
103 this.baseUrl
= baseUrl
;
107 * @see eu.etaxonomy.cdm.remote.ICdmRemoteSource#getContextPath()
110 public String
getContextPath() {
115 * Sets the context path.
116 * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
117 * context path would be 'col'
121 public void setContextPath(String contextPath
) {
122 this.contextPath
= contextPath
;
126 * @see eu.etaxonomy.cdm.config.CdmSource#getDbSchemaVersion()
129 public String
getDbSchemaVersion() throws CdmSourceException
{
130 return databaseService
.getDbSchemaVersion();
135 * @see eu.etaxonomy.cdm.config.CdmSource#isDbEmpty()
138 public boolean isDbEmpty() throws CdmSourceException
{
139 return databaseService
.isDbEmpty();
144 * @see eu.etaxonomy.cdm.config.CdmSource#checkConnection()
147 public boolean checkConnection() throws CdmSourceException
{
148 // assuming that database service works implies
149 // the connection is up
150 // if no exception is thrown then we assume that the
152 // FIXME:Remoting is this really correct?
153 databaseService
.getDbSchemaVersion();
159 * @see eu.etaxonomy.cdm.config.CdmSource#getConnectionMessage()
162 public String
getConnectionMessage() {
163 return "Conncting to Remote CDM Server " + getName();
168 public Map
<MetaDataPropertyName
, String
> getMetaDataMap() throws CdmSourceException
{
169 return databaseService
.getCdmMetadataMap();