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 org.apache.commons.lang3.StringUtils;
|
14
|
|
15
|
import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteConfiguration;
|
16
|
import eu.etaxonomy.cdm.api.service.IMetadataService;
|
17
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
18
|
import eu.etaxonomy.cdm.config.CdmSource;
|
19
|
import eu.etaxonomy.cdm.config.CdmSourceException;
|
20
|
import eu.etaxonomy.cdm.model.metadata.CdmMetaDataPropertyName;
|
21
|
|
22
|
/**
|
23
|
* Base class representing a CDM remote source.
|
24
|
* This class handles all the configuration relating to the remoting aspect of
|
25
|
* a CDM source.
|
26
|
*/
|
27
|
public class CdmRemoteSourceBase extends CdmSource implements ICdmRemoteSource {
|
28
|
|
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
|
private String contextPath;
|
34
|
private String baseUrl;
|
35
|
|
36
|
private IMetadataService metadataService;
|
37
|
|
38
|
/**
|
39
|
* Constructs a CdmRemoteSourceBase object with default values.
|
40
|
*/
|
41
|
protected CdmRemoteSourceBase() {
|
42
|
setName(DEFAULT_NAME);
|
43
|
setServer(DEFAULT_SERVER);
|
44
|
setPort(DEFAULT_PORT);
|
45
|
setContextPath(DEFAULT_CONTEXT_PATH);
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* Constructs a CdmRemoteSourceBase
|
50
|
*
|
51
|
* @param name
|
52
|
* @param server
|
53
|
* @param port
|
54
|
* @param contextPath
|
55
|
* @param nomenclaturalCode
|
56
|
*/
|
57
|
public CdmRemoteSourceBase(String name, String server, int port, String contextPath) {
|
58
|
setName(name);
|
59
|
setServer(server);
|
60
|
setPort(port);
|
61
|
setContextPath(contextPath);
|
62
|
metadataService = CdmApplicationRemoteConfiguration.getMetadataService(this);
|
63
|
}
|
64
|
|
65
|
@Override
|
66
|
public String getBaseUrl() {
|
67
|
return baseUrl;
|
68
|
}
|
69
|
|
70
|
/**
|
71
|
* Sets the base url for the http-invoker services as listed in
|
72
|
* httpInvokerServicesClients.xml.
|
73
|
* e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
|
74
|
* base url would be 'http://127.0.0.1:8080/col'
|
75
|
*
|
76
|
* @param baseUrl
|
77
|
*/
|
78
|
public void setBaseUrl(String baseUrl) {
|
79
|
this.baseUrl = baseUrl;
|
80
|
}
|
81
|
|
82
|
@Override
|
83
|
public String getContextPath() {
|
84
|
return contextPath;
|
85
|
}
|
86
|
|
87
|
/**
|
88
|
* Sets the context path.
|
89
|
* e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
|
90
|
* context path would be 'col'
|
91
|
*
|
92
|
* @param contextPath
|
93
|
*/
|
94
|
public void setContextPath(String contextPath) {
|
95
|
this.contextPath = contextPath;
|
96
|
}
|
97
|
|
98
|
@Override
|
99
|
public String getDbSchemaVersion() throws CdmSourceException {
|
100
|
return metadataService.getDbSchemaVersion();
|
101
|
}
|
102
|
|
103
|
@Override
|
104
|
public boolean isDbEmpty() throws CdmSourceException {
|
105
|
return metadataService.isDbEmpty();
|
106
|
}
|
107
|
|
108
|
@Override
|
109
|
public boolean checkConnection() throws CdmSourceException {
|
110
|
// assuming that database service works implies
|
111
|
// the connection is up
|
112
|
// if no exception is thrown then we assume that the
|
113
|
// connection is up
|
114
|
// FIXME:Remoting is this really correct?
|
115
|
metadataService.getDbSchemaVersion();
|
116
|
|
117
|
return true;
|
118
|
}
|
119
|
|
120
|
@Override
|
121
|
public String getConnectionMessage() {
|
122
|
return "Connecting to Remote CDM Instance " + getName() + ":" + getPort() + "/" + getContextPath();
|
123
|
}
|
124
|
|
125
|
@Override
|
126
|
public Map<CdmMetaDataPropertyName, String> getMetaDataMap() throws CdmSourceException {
|
127
|
return metadataService.getCdmMetadataMap();
|
128
|
}
|
129
|
|
130
|
@Override
|
131
|
public String toString() {
|
132
|
String result = CdmUtils.concat("/", getName(),contextPath);
|
133
|
if (StringUtils.isBlank(result)){
|
134
|
return super.toString();
|
135
|
}else{
|
136
|
return result.replace("cdmserver/", "");
|
137
|
}
|
138
|
}
|
139
|
}
|