Project

General

Profile

Download (3.62 KB) Statistics
| Branch: | Tag: | Revision:
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
 */
28
public class CdmRemoteSourceBase extends CdmSource implements ICdmRemoteSource {
29

    
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
	private String contextPath;
35
	private String baseUrl;
36

    
37
	private IMetadataService metadataService;
38

    
39
	/**
40
	 * Constructs a CdmRemoteSourceBase object with default values.
41
	 *
42
	 */
43
	protected CdmRemoteSourceBase() {
44
		setName(DEFAULT_NAME);
45
		setServer(DEFAULT_SERVER);
46
		setPort(DEFAULT_PORT);
47
		setContextPath(DEFAULT_CONTEXT_PATH);
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) {
60
		setName(name);
61
		setServer(server);
62
		setPort(port);
63
		setContextPath(contextPath);
64
		metadataService = CdmApplicationRemoteConfiguration.getMetadataService(this);
65
	}
66

    
67
	@Override
68
	public String getBaseUrl() {
69
		return baseUrl;
70
	}
71

    
72
	/**
73
	 * Sets the base url for the http-invoker services as listed in
74
	 * httpInvokerServicesClients.xml.
75
	 * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
76
	 * base url would be 'http://127.0.0.1:8080/col'
77
	 *
78
	 * @param baseUrl
79
	 */
80
	public void setBaseUrl(String baseUrl) {
81
		this.baseUrl = baseUrl;
82
	}
83

    
84
	@Override
85
	public String getContextPath() {
86
		return contextPath;
87
	}
88

    
89
	/**
90
	 * Sets the context path.
91
	 * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
92
	 * context path would be 'col'
93
	 *
94
	 * @param contextPath
95
	 */
96
	public void setContextPath(String contextPath) {
97
		this.contextPath = contextPath;
98
	}
99

    
100
	@Override
101
	public String getDbSchemaVersion() throws CdmSourceException {
102
		return metadataService.getDbSchemaVersion();
103

    
104
	}
105

    
106
	@Override
107
	public boolean isDbEmpty() throws CdmSourceException {
108
		return metadataService.isDbEmpty();
109

    
110
	}
111

    
112
	@Override
113
	public boolean checkConnection() throws CdmSourceException {
114
		// assuming that database service works implies
115
		// the connection is up
116
		// if no exception is thrown then we assume that the
117
		// connection is up
118
		// FIXME:Remoting is this really correct?
119
		metadataService.getDbSchemaVersion();
120

    
121
		return true;
122
	}
123

    
124
	@Override
125
	public String getConnectionMessage() {
126
		return "Connecting to Remote CDM Instance " + getName() + ":" + getPort() + "/" + getContextPath();
127
	}
128

    
129

    
130
	@Override
131
	public Map<CdmMetaDataPropertyName, String> getMetaDataMap() throws CdmSourceException {
132
		return metadataService.getCdmMetadataMap();
133
	}
134

    
135
	@Override
136
	public String toString() {
137
		String result = CdmUtils.concat("/", baseUrl, contextPath);
138
		if (StringUtils.isBlank(result)){
139
			return super.toString();
140
		}else{
141
			return result;
142
		}
143
	}
144
}
(3-3/7)