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.CdmSourceException;
|
19
|
import eu.etaxonomy.cdm.model.metadata.CdmMetaDataPropertyName;
|
20
|
|
21
|
/**
|
22
|
* Class representing a CDM remote source
|
23
|
*/
|
24
|
public class CdmRemoteSource extends CdmRemoteSourceBase {
|
25
|
|
26
|
protected static final String DEFAULT_CONTEXT_PATH = "";
|
27
|
|
28
|
private String contextPath;
|
29
|
private IMetadataService metadataService;
|
30
|
|
31
|
/**
|
32
|
* Creates a new instance of CdmRemoteSource
|
33
|
*/
|
34
|
public static CdmRemoteSource NewInstance() {
|
35
|
return new CdmRemoteSource(DEFAULT_NAME, DEFAULT_SERVER, DEFAULT_PORT, DEFAULT_CONTEXT_PATH);
|
36
|
}
|
37
|
|
38
|
/**
|
39
|
* Creates a new instance of CdmRemoteSource
|
40
|
*
|
41
|
* @param name
|
42
|
* @param server
|
43
|
* @param port
|
44
|
* @param contextPath
|
45
|
* @return
|
46
|
*/
|
47
|
public static CdmRemoteSource NewInstance(String name, String server, int port, String contextPath) {
|
48
|
return new CdmRemoteSource(name, server, port, contextPath);
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* Creates a new CdmRemoteSource
|
53
|
*
|
54
|
* @param name
|
55
|
* @param server
|
56
|
* @param port
|
57
|
* @param contextPath
|
58
|
*/
|
59
|
protected CdmRemoteSource(String name, String server, int port, String contextPath) {
|
60
|
super(name, server, port);
|
61
|
this.contextPath = contextPath;
|
62
|
metadataService = CdmApplicationRemoteConfiguration.getMetadataService(this);
|
63
|
}
|
64
|
|
65
|
|
66
|
@Override
|
67
|
public String getDbSchemaVersion() throws CdmSourceException {
|
68
|
return metadataService.getDbSchemaVersion();
|
69
|
}
|
70
|
|
71
|
@Override
|
72
|
public boolean isDbEmpty() throws CdmSourceException {
|
73
|
return metadataService.isDbEmpty();
|
74
|
}
|
75
|
|
76
|
@Override
|
77
|
public boolean checkConnection() throws CdmSourceException {
|
78
|
// assuming that database service works implies
|
79
|
// the connection is up
|
80
|
// if no exception is thrown then we assume that the
|
81
|
// connection is up
|
82
|
// FIXME:Remoting is this really correct?
|
83
|
metadataService.getDbSchemaVersion();
|
84
|
|
85
|
return true;
|
86
|
}
|
87
|
|
88
|
@Override
|
89
|
public Map<CdmMetaDataPropertyName, String> getMetaDataMap() throws CdmSourceException {
|
90
|
return metadataService.getCdmMetadataMap();
|
91
|
}
|
92
|
|
93
|
|
94
|
@Override
|
95
|
public String getContext() {
|
96
|
return contextPath;
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* @see #setContextPath(String)
|
101
|
*/
|
102
|
public String getContextPath() {
|
103
|
return contextPath;
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* Sets the context path.
|
108
|
* e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
|
109
|
* context path would be 'col'
|
110
|
*
|
111
|
* @param contextPath
|
112
|
*/
|
113
|
public void setContextPath(String contextPath) {
|
114
|
this.contextPath = contextPath;
|
115
|
}
|
116
|
|
117
|
@Override
|
118
|
public String toString() {
|
119
|
String result = CdmUtils.concat("/", getName(), contextPath);
|
120
|
if (StringUtils.isBlank(result)){
|
121
|
return super.toString();
|
122
|
}else{
|
123
|
return result.replace("cdmserver/", "");
|
124
|
}
|
125
|
}
|
126
|
|
127
|
}
|