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
.taxeditor
.remoting
.source
;
13 import org
.springframework
.remoting
.httpinvoker
.HttpInvokerProxyFactoryBean
;
15 import eu
.etaxonomy
.cdm
.api
.service
.IUserService
;
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 IUserService userService
;
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(IUserService
.class);
80 // FIXME:Remoting need to fix this hardcoded url and make it configurable somehow
81 proxy
.setServiceUrl(baseUrl
+ "/remoting-public/user.service");
82 proxy
.afterPropertiesSet();
83 userService
= (IUserService
) 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 userService
.getDbSchemaVersion();
136 * @see eu.etaxonomy.cdm.config.CdmSource#isDbEmpty()
139 public boolean isDbEmpty() throws CdmSourceException
{
140 return userService
.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 userService
.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 userService
.getCdmMetadataMap();