59c24ea3b2f5497c692570e00582113aee6584b0
[taxeditor.git] / eu.etaxonomy.taxeditor.cdmlib / src / main / java / eu / etaxonomy / taxeditor / remoting / source / CdmRemoteSourceBase.java
1 /**
2 * Copyright (C) 2014 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9 package eu.etaxonomy.taxeditor.remoting.source;
10
11 import java.util.Map;
12
13 import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteConfiguration;
14 import eu.etaxonomy.cdm.api.service.IMetadataService;
15 import eu.etaxonomy.cdm.config.CdmSource;
16 import eu.etaxonomy.cdm.config.CdmSourceException;
17 import eu.etaxonomy.cdm.model.metadata.CdmMetaData.MetaDataPropertyName;
18 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
19
20 /**
21 * Base class representing a CDM remote source.
22 * This class handles all the configuration relating to the remoting aspect of
23 * a CDM source.
24 *
25 */
26 public class CdmRemoteSourceBase extends CdmSource implements ICdmRemoteSource {
27
28 protected static final String DEFAULT_NAME = "default";
29 protected static final String DEFAULT_SERVER = "127.0.0.1";
30 protected static final int DEFAULT_PORT = 8080;
31 protected static final String DEFAULT_CONTEXT_PATH = "";
32 protected static final NomenclaturalCode DEFAULT_NOMENCLATURAL_CODE = NomenclaturalCode.ICNAFP;
33 private String contextPath;
34 private String baseUrl;
35
36 private IMetadataService metadataService;
37
38 /**
39 * Constructs a CdmRemoteSourceBase object with default values.
40 *
41 */
42 protected CdmRemoteSourceBase() {
43 setName(DEFAULT_NAME);
44 setServer(DEFAULT_SERVER);
45 setPort(DEFAULT_PORT);
46 setContextPath(DEFAULT_CONTEXT_PATH);
47 setNomenclaturalCode(DEFAULT_NOMENCLATURAL_CODE);
48 }
49
50 /**
51 * Constructs a CdmRemoteSourceBase
52 *
53 * @param name
54 * @param server
55 * @param port
56 * @param contextPath
57 * @param nomenclaturalCode
58 */
59 public CdmRemoteSourceBase(String name, String server, int port, String contextPath, NomenclaturalCode nomenclaturalCode) {
60 setName(name);
61 setServer(server);
62 setPort(port);
63 setContextPath(contextPath);
64 setNomenclaturalCode(nomenclaturalCode);
65 metadataService = CdmApplicationRemoteConfiguration.getMetadataService(this);
66 }
67
68
69 /* (non-Javadoc)
70 * @see eu.etaxonomy.cdm.remote.ICdmRemoteSource#getBaseUrl()
71 */
72 @Override
73 public String getBaseUrl() {
74 return baseUrl;
75 }
76
77 /**
78 * Sets the base url for the http-invoker services as listed in
79 * httpInvokerServicesClients.xml.
80 * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
81 * base url would be 'http://127.0.0.1:8080/col'
82 *
83 * @param baseUrl
84 */
85 public void setBaseUrl(String baseUrl) {
86 this.baseUrl = baseUrl;
87 }
88
89 /* (non-Javadoc)
90 * @see eu.etaxonomy.cdm.remote.ICdmRemoteSource#getContextPath()
91 */
92 @Override
93 public String getContextPath() {
94 return contextPath;
95 }
96
97 /**
98 * Sets the context path.
99 * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
100 * context path would be 'col'
101 *
102 * @param contextPath
103 */
104 public void setContextPath(String contextPath) {
105 this.contextPath = contextPath;
106 }
107
108 /* (non-Javadoc)
109 * @see eu.etaxonomy.cdm.config.CdmSource#getDbSchemaVersion()
110 */
111 @Override
112 public String getDbSchemaVersion() throws CdmSourceException {
113 return metadataService.getDbSchemaVersion();
114
115 }
116
117 /* (non-Javadoc)
118 * @see eu.etaxonomy.cdm.config.CdmSource#isDbEmpty()
119 */
120 @Override
121 public boolean isDbEmpty() throws CdmSourceException {
122 return metadataService.isDbEmpty();
123
124 }
125
126 /* (non-Javadoc)
127 * @see eu.etaxonomy.cdm.config.CdmSource#checkConnection()
128 */
129 @Override
130 public boolean checkConnection() throws CdmSourceException {
131 // assuming that database service works implies
132 // the connection is up
133 // if no exception is thrown then we assume that the
134 // connection is up
135 // FIXME:Remoting is this really correct?
136 metadataService.getDbSchemaVersion();
137
138 return true;
139 }
140
141 /* (non-Javadoc)
142 * @see eu.etaxonomy.cdm.config.CdmSource#getConnectionMessage()
143 */
144 @Override
145 public String getConnectionMessage() {
146 return "Connecting to Remote CDM Instance " + getName() + ":" + getPort() + "/" + getContextPath();
147 }
148
149
150 @Override
151 public Map<MetaDataPropertyName, String> getMetaDataMap() throws CdmSourceException {
152 return metadataService.getCdmMetadataMap();
153 }
154
155
156 }