Project

General

Profile

Download (3.18 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.config.CdmSource;
18
import eu.etaxonomy.cdm.config.CdmSourceException;
19
import eu.etaxonomy.cdm.model.metadata.CdmMetaDataPropertyName;
20

    
21
/**
22
 * Base class representing a CDM remote source.
23
 * This class handles all the configuration relating to the remoting aspect of
24
 * a CDM source.
25
 */
26
public abstract 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

    
32
	private String baseUrl;
33

    
34
	private IMetadataService metadataService;
35

    
36
	/**
37
	 * Constructs a CdmRemoteSourceBase object with default values.
38
	 */
39
	protected CdmRemoteSourceBase() {
40
		setName(DEFAULT_NAME);
41
		setServer(DEFAULT_SERVER);
42
		setPort(DEFAULT_PORT);
43
	}
44

    
45
	/**
46
	 * Constructs a CdmRemoteSourceBase
47
	 *
48
	 * @param name
49
	 * @param server
50
	 * @param port
51
	 * @param contextPath
52
	 * @param nomenclaturalCode
53
	 */
54
	public CdmRemoteSourceBase(String name, String server, int port) {
55
		setName(name);
56
		setServer(server);
57
		setPort(port);
58
		metadataService = CdmApplicationRemoteConfiguration.getMetadataService(this);
59
	}
60

    
61
	/**
62
	 * @see #setBaseUrl(String)
63
	 */
64
	@Override
65
	public String getBaseUrl() {
66
		return baseUrl;
67
	}
68

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

    
81
    @Override
82
    public String getConnectionMessage() {
83
        return "Connecting to Remote CDM Instance " + getName() + ":" + getPort() + "/" + getContext();
84
    }
85

    
86
	@Override
87
	public String getDbSchemaVersion() throws CdmSourceException {
88
		return metadataService.getDbSchemaVersion();
89
	}
90

    
91
	@Override
92
	public boolean isDbEmpty() throws CdmSourceException {
93
		return metadataService.isDbEmpty();
94
	}
95

    
96
	@Override
97
	public boolean checkConnection() throws CdmSourceException {
98
		// assuming that database service works implies
99
		// the connection is up
100
		// if no exception is thrown then we assume that the
101
		// connection is up
102
		// FIXME:Remoting is this really correct?
103
		metadataService.getDbSchemaVersion();
104

    
105
		return true;
106
	}
107

    
108
	@Override
109
	public Map<CdmMetaDataPropertyName, String> getMetaDataMap() throws CdmSourceException {
110
		return metadataService.getCdmMetadataMap();
111
	}
112

    
113
    @Override
114
    public String toString() {
115
        String result = getName();
116
        if (StringUtils.isBlank(result)){
117
            return super.toString();
118
        }else{
119
            return result.replace("cdmserver/", "");
120
        }
121
    }
122
}
(4-4/8)