import java.io.IOException;
import java.net.Socket;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.json.JSONObject;
import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.type.TypeFactory;
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
import eu.etaxonomy.cdm.common.CdmUtils;
private boolean ignoreCdmLibVersion = false;
- public CdmServerInfo(String name, String server, int port, String prefix, boolean ignoreCdmLibVersion) {
- this.name = name;
- this.server = server;
- this.port = port;
- this.prefix = prefix;
- this.ignoreCdmLibVersion = ignoreCdmLibVersion;
+ public CdmServerInfo(CdmServerInfoConfig parameterObject) {
+ this.name = parameterObject.getName();
+ this.server = parameterObject.getServer();
+ this.port = parameterObject.getPort();
+ this.prefix = parameterObject.getPrefix();
+ this.ignoreCdmLibVersion = parameterObject.isIgnoreCdmLibVersion();
instances = new ArrayList<CdmInstanceInfo>();
-
}
public static List<CdmServerInfo> getCdmServers() {
- return loadFromJSONConfigFile(new File(CdmUtils.perUserCdmFolder, CDM_REMOTE_SERVERS_CONFIG_FILE));
+ List<CdmServerInfoConfig> configList = loadFromConfigFile(new File(CdmUtils.perUserCdmFolder, CDM_REMOTE_SERVERS_CONFIG_FILE));
+ List<CdmServerInfo> serverInfoList = new ArrayList<CdmServerInfo>(configList.size());
+ for(CdmServerInfoConfig config : configList) {
+ serverInfoList.add(new CdmServerInfo(config));
+ }
+ // The local host managed server must not be in the config file
+ CdmServerInfoConfig localHostManagedConfig = new CdmServerInfoConfig(NAME_LOCALHOST_MGD, SERVER_LOCALHOST, NULL_PORT, CDMSERVER_PREFIX, false);
+ serverInfoList.add(new CdmServerInfo(localHostManagedConfig));
+ return serverInfoList;
}
* @throws JsonMappingException
* @throws JsonParseException
*/
- private static List<CdmServerInfo> loadFromJSONConfigFile(File file) {
+ private static List<CdmServerInfoConfig> loadFromConfigFile(File file) {
+
+ List<CdmServerInfoConfig> serverList = null;
- List<CdmServerInfo> serverList = null;
ObjectMapper mapper = new ObjectMapper();
if(!file.exists()) {
logger.info("The remote server config file '" + file.getAbsolutePath() +
"' does not yet exist, it will be created based on the defaults.");
try {
- serverList = createDefaultServerList();
- mapper.writerWithDefaultPrettyPrinter().writeValue(new FileOutputStream(file), serverList.toArray(new CdmServerInfo[serverList.size()]));
+ serverList = createDefaultServerConfigList();
+ mapper.writerWithDefaultPrettyPrinter().writeValue(new FileOutputStream(file), serverList);
+
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
try {
- CdmServerInfo[] serverInfo = mapper.readValue(new FileInputStream(file),
- TypeFactory.defaultInstance().constructArrayType(CdmServerInfo.class));
- serverList = Arrays.asList(serverInfo);
+ serverList = mapper.readValue(new FileInputStream(file), new TypeReference<List<CdmServerInfoConfig>>(){});
} catch (IOException e) {
throw new RuntimeException(e);
}
/**
*
*/
- private static List<CdmServerInfo> createDefaultServerList() {
-
- List<CdmServerInfo> serverInfoList = new ArrayList<CdmServerInfo>();
- // serverInfoList.add(new CdmServerInfo(NAME_PRODUCTION, SERVER_PRODUCTION, 80, ""));
- //serverInfoList.add(new CdmServerInfo(NAME_INTEGRATION, SERVER_INTEGRATION, 80, CDMSERVER_PREFIX));
- serverInfoList.add(new CdmServerInfo(NAME_DEMO_1, SERVER_DEMO_1, 80, CDMSERVER_PREFIX, false));
- // serverInfoList.add(new CdmServerInfo(NAME_DEMO_2, SERVER_DEMO_2, 80, CDMSERVER_PREFIX));
- serverInfoList.add(new CdmServerInfo(NAME_TEST, SERVER_TEST, 80, CDMSERVER_PREFIX, false));
- serverInfoList.add(new CdmServerInfo(NAME_LOCALHOST, SERVER_LOCALHOST, 8080, CDMSERVER_PREFIX, true));
- serverInfoList.add(new CdmServerInfo(NAME_LOCALHOST_MGD, SERVER_LOCALHOST, NULL_PORT, CDMSERVER_PREFIX, false));
+ private static List<CdmServerInfoConfig> createDefaultServerConfigList() {
+
+ List<CdmServerInfoConfig> serverInfoList = new ArrayList<CdmServerInfoConfig>();
+ // serverInfoList.add(new CdmServerInfoConfig(NAME_PRODUCTION, SERVER_PRODUCTION, 80, ""));
+ //serverInfoList.add(new CdmServerInfoConfig(NAME_INTEGRATION, SERVER_INTEGRATION, 80, CDMSERVER_PREFIX));
+ serverInfoList.add(new CdmServerInfoConfig(NAME_DEMO_1, SERVER_DEMO_1, 80, CDMSERVER_PREFIX, false));
+ // serverInfoList.add(new CdmServerInfoConfig(NAME_DEMO_2, SERVER_DEMO_2, 80, CDMSERVER_PREFIX));
+ serverInfoList.add(new CdmServerInfoConfig(NAME_TEST, SERVER_TEST, 80, CDMSERVER_PREFIX, false));
+ serverInfoList.add(new CdmServerInfoConfig(NAME_LOCALHOST, SERVER_LOCALHOST, 8080, CDMSERVER_PREFIX, true));
return serverInfoList;
}
CdmInstanceInfo devInstance = null;
if(value != null && !value.isEmpty()) {
int devPort = Integer.valueOf(value);
- CdmServerInfo devCii = new CdmServerInfo(NAME_LOCALHOST_DEV, SERVER_LOCALHOST_DEV, devPort, "", false);
+ CdmServerInfo devCii = new CdmServerInfo(new CdmServerInfoConfig(NAME_LOCALHOST_DEV, SERVER_LOCALHOST_DEV, devPort, "", false));
try {
devInstance = devCii.addInstance(NAME_INSTANCE_LOCALHOST_DEV, BASEPATH_LOCALHOST_DEV);
available = devCii.pingInstance(devInstance, devPort);
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2016 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.remoting.source;
+
+/**
+ * @author a.kohlbecker
+ * @date Feb 10, 2016
+ */
+public class CdmServerInfoConfig {
+ /**
+ *
+ */
+ private String name;
+ /**
+ *
+ */
+ private String server;
+ /**
+ *
+ */
+ private int port;
+ /**
+ *
+ */
+ private String prefix;
+ /**
+ *
+ */
+ private boolean ignoreCdmLibVersion;
+
+ /**
+ *
+ */
+ public CdmServerInfoConfig(String name, String server, int port, String prefix, boolean ignoreCdmLibVersion) {
+ this.name = name;
+ this.server = server;
+ this.port = port;
+ this.prefix = prefix;
+ this.ignoreCdmLibVersion = ignoreCdmLibVersion;
+ }
+
+ public CdmServerInfoConfig() {
+
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the server
+ */
+ public String getServer() {
+ return server;
+ }
+
+ /**
+ * @param server the server to set
+ */
+ public void setServer(String server) {
+ this.server = server;
+ }
+
+ /**
+ * @return the port
+ */
+ public int getPort() {
+ return port;
+ }
+
+ /**
+ * @param port the port to set
+ */
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ /**
+ * @return the prefix
+ */
+ public String getPrefix() {
+ return prefix;
+ }
+
+ /**
+ * @param prefix the prefix to set
+ */
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ /**
+ * @return the ignoreCdmLibVersion
+ */
+ public boolean isIgnoreCdmLibVersion() {
+ return ignoreCdmLibVersion;
+ }
+
+ /**
+ * @param ignoreCdmLibVersion the ignoreCdmLibVersion to set
+ */
+ public void setIgnoreCdmLibVersion(boolean ignoreCdmLibVersion) {
+ this.ignoreCdmLibVersion = ignoreCdmLibVersion;
+ }
+}
\ No newline at end of file
import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo;
import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo.CdmInstanceInfo;
+import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfoConfig;
/**
* @author cmathew
@Ignore // this should be targetting integration or production
@Test
public void pingInstancesTest() {
- CdmServerInfo csii = new CdmServerInfo("edit-test", "test.e-taxonomy.eu", 8080, "cdmserver/", false);
+ CdmServerInfo csii = new CdmServerInfo(new CdmServerInfoConfig("edit-test", "test.e-taxonomy.eu", 8080, "cdmserver/", false));
try {
csii.refreshInstances();
List<CdmInstanceInfo> instances = csii.getInstances();
@Test
public void refreshWrongInstancesTest() {
- CdmServerInfo wrongCsii = new CdmServerInfo("local", "local", 8080, "noserver", false);
+ CdmServerInfo wrongCsii = new CdmServerInfo(new CdmServerInfoConfig("local", "local", 8080, "noserver", false));
try {
wrongCsii.refreshInstances();
List<CdmInstanceInfo> instances = wrongCsii.getInstances();
@Ignore // this should be targetting integration or production
@Test
public void refreshInstancesTest() throws CDMServerException {
- CdmServerInfo cdmServerInfo = new CdmServerInfo("edit-test", "test.e-taxonomy.eu", 8080, "cdmserver/", false);
+ CdmServerInfo cdmServerInfo = new CdmServerInfo(new CdmServerInfoConfig("edit-test", "test.e-taxonomy.eu", 8080, "cdmserver/", false));
cdmServerInfo.refreshInstances();
List<CdmInstanceInfo> instances = cdmServerInfo.getInstances();
Assert.assertTrue(instances != null && !instances.isEmpty());