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
.database
.DatabaseTypeEnum
;
19 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmMetaData
.MetaDataPropertyName
;
20 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
23 * Base class representing a CDM remote source.
24 * This class handles all the configuration relating to the remoting aspect of
28 public class CdmRemoteSourceBase
extends CdmSource
implements ICdmRemoteSource
{
30 protected static final String DEFAULT_NAME
= "default";
31 protected static final String DEFAULT_SERVER
= "127.0.0.1";
32 protected static final int DEFAULT_PORT
= 8080;
33 protected static final String DEFAULT_CONTEXT_PATH
= "";
34 protected static final NomenclaturalCode DEFAULT_NOMENCLATURAL_CODE
= NomenclaturalCode
.ICNAFP
;
35 private String contextPath
;
36 private String baseUrl
;
38 private IDatabaseService databaseService
;
41 * Constructs a CdmRemoteSourceBase object with default values.
44 protected CdmRemoteSourceBase() {
45 setName(DEFAULT_NAME
);
46 setServer(DEFAULT_SERVER
);
47 setPort(DEFAULT_PORT
);
48 setContextPath(DEFAULT_CONTEXT_PATH
);
49 setNomenclaturalCode(DEFAULT_NOMENCLATURAL_CODE
);
53 * Constructs a CdmRemoteSourceBase
59 * @param nomenclaturalCode
61 protected CdmRemoteSourceBase(String name
, String server
, int port
, String contextPath
, NomenclaturalCode nomenclaturalCode
) {
65 setContextPath(contextPath
);
66 setNomenclaturalCode(nomenclaturalCode
);
67 initDatabaseConnection();
70 protected void initDatabaseConnection() {
71 if(getContextPath() == null || getContextPath().equals("")) {
72 setBaseUrl("http://" + getServer() + ":" + String
.valueOf(getPort()));
74 setBaseUrl("http://" + getServer() + ":" + String
.valueOf(getPort()) + "/" + getContextPath());
76 // the database service needs to be initialised (before the spring
77 // application context initialsation) since it is required to
78 // to make queries related to the source database
79 HttpInvokerProxyFactoryBean proxy
= new HttpInvokerProxyFactoryBean();
80 proxy
.setServiceInterface(IDatabaseService
.class);
81 proxy
.setServiceUrl(baseUrl
+ "/remoting/database.service");
82 proxy
.afterPropertiesSet();
83 databaseService
= (IDatabaseService
) proxy
.getObject();
88 * @see eu.etaxonomy.cdm.remote.ICdmRemoteSource#getBaseUrl()
91 public String
getBaseUrl() {
96 * Sets the base url for the http-invoker services as listed in
97 * httpInvokerServicesClients.xml.
98 * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
99 * base url would be 'http://127.0.0.1:8080/col'
103 public void setBaseUrl(String baseUrl
) {
104 this.baseUrl
= baseUrl
;
108 * @see eu.etaxonomy.cdm.remote.ICdmRemoteSource#getContextPath()
111 public String
getContextPath() {
116 * Sets the context path.
117 * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
118 * context path would be 'col'
122 public void setContextPath(String contextPath
) {
123 this.contextPath
= contextPath
;
127 * @see eu.etaxonomy.cdm.config.CdmSource#getDbSchemaVersion()
130 public String
getDbSchemaVersion() throws CdmSourceException
{
131 return databaseService
.getDbSchemaVersion();
136 * @see eu.etaxonomy.cdm.config.CdmSource#isDbEmpty()
139 public boolean isDbEmpty() throws CdmSourceException
{
140 return databaseService
.isDbEmpty();
145 * @see eu.etaxonomy.cdm.config.CdmSource#checkConnection()
148 public boolean checkConnection() throws CdmSourceException
{
149 // assuming that database service works implies
150 // the connection is up
151 // if no exception is thrown then we assume that the
153 // FIXME:Remoting is this really correct?
154 databaseService
.getDbSchemaVersion();
160 * @see eu.etaxonomy.cdm.config.CdmSource#getConnectionMessage()
163 public String
getConnectionMessage() {
164 return "Conncting to Remote CDM Server " + getName();
169 public Map
<MetaDataPropertyName
, String
> getMetaDataMap() throws CdmSourceException
{
170 return databaseService
.getCdmMetadataMap();