avoid NPE in check for dirty editors
[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.CdmMetaDataPropertyName;
18
19 /**
20 * Base class representing a CDM remote source.
21 * This class handles all the configuration relating to the remoting aspect of
22 * a CDM source.
23 *
24 */
25 public class CdmRemoteSourceBase extends CdmSource implements ICdmRemoteSource {
26
27 protected static final String DEFAULT_NAME = "default";
28 protected static final String DEFAULT_SERVER = "127.0.0.1";
29 protected static final int DEFAULT_PORT = 8080;
30 protected static final String DEFAULT_CONTEXT_PATH = "";
31 private String contextPath;
32 private String baseUrl;
33
34 private IMetadataService metadataService;
35
36 /**
37 * Constructs a CdmRemoteSourceBase object with default values.
38 *
39 */
40 protected CdmRemoteSourceBase() {
41 setName(DEFAULT_NAME);
42 setServer(DEFAULT_SERVER);
43 setPort(DEFAULT_PORT);
44 setContextPath(DEFAULT_CONTEXT_PATH);
45 }
46
47 /**
48 * Constructs a CdmRemoteSourceBase
49 *
50 * @param name
51 * @param server
52 * @param port
53 * @param contextPath
54 * @param nomenclaturalCode
55 */
56 public CdmRemoteSourceBase(String name, String server, int port, String contextPath) {
57 setName(name);
58 setServer(server);
59 setPort(port);
60 setContextPath(contextPath);
61 metadataService = CdmApplicationRemoteConfiguration.getMetadataService(this);
62 }
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 getContextPath() {
83 return contextPath;
84 }
85
86 /**
87 * Sets the context path.
88 * e.g. for 'http://127.0.0.1:8080/col/remoting/common.service', the
89 * context path would be 'col'
90 *
91 * @param contextPath
92 */
93 public void setContextPath(String contextPath) {
94 this.contextPath = contextPath;
95 }
96
97 @Override
98 public String getDbSchemaVersion() throws CdmSourceException {
99 return metadataService.getDbSchemaVersion();
100
101 }
102
103 @Override
104 public boolean isDbEmpty() throws CdmSourceException {
105 return metadataService.isDbEmpty();
106
107 }
108
109 @Override
110 public boolean checkConnection() throws CdmSourceException {
111 // assuming that database service works implies
112 // the connection is up
113 // if no exception is thrown then we assume that the
114 // connection is up
115 // FIXME:Remoting is this really correct?
116 metadataService.getDbSchemaVersion();
117
118 return true;
119 }
120
121 @Override
122 public String getConnectionMessage() {
123 return "Connecting to Remote CDM Instance " + getName() + ":" + getPort() + "/" + getContextPath();
124 }
125
126
127 @Override
128 public Map<CdmMetaDataPropertyName, String> getMetaDataMap() throws CdmSourceException {
129 return metadataService.getCdmMetadataMap();
130 }
131
132 }