import org.json.JSONObject;
import eu.etaxonomy.cdm.config.CdmSourceException;
+import eu.etaxonomy.cdm.database.CdmPersistentDataSource;
+import eu.etaxonomy.cdm.database.ICdmDataSource;
import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
/**
private final static String NAME_TEST = "edit-test";
private final static String SERVER_TEST = "test.e-taxonomy.eu";
- private final static String SERVER_LOCALHOST = "localhost";
+ public final static String SERVER_LOCALHOST = "localhost";
private final static String NAME_LOCALHOST = "localhost";
- private final static String NAME_LOCALHOST_MGD = "localhost mgd.";
+ public final static String NAME_LOCALHOST_MGD = "localhost mgd.";
private final static String NAME_LOCALHOST_DEV = "localhost-dev";
private final static String NAME_INSTANCE_LOCALHOST_DEV = "local-dev";
private final int port;
private final List<CdmInstanceInfo> instances;
+ private static List<CdmServerInfo> cdmServerInfoList;
public CdmServerInfo(String name, String server, int port) {
this.name = name;
}
public boolean isLocalhost() {
- return name.startsWith(SERVER_LOCALHOST_DEV);
+ return name.startsWith(SERVER_LOCALHOST);
}
+
+ public boolean isLocalhostMgd() {
+ return NAME_LOCALHOST_MGD.equals(name);
+ }
+
public void refreshInstances() throws CDMServerException {
instances.clear();
+ if(isLocalhostMgd()) {
+ addInstancesFromDataSourcesConfig();
+ } else {
+ addInstancesViaHttp();
+ }
+
+ }
+
+ public void addInstancesViaHttp() throws CDMServerException {
String url = "http://" + server + ":" + String.valueOf(port) + "/" + CDMSERVER_PREFIX + "/instances.jsp";
HttpClient client = new DefaultHttpClient();
throw new CDMServerException(e);
}
}
+ }
+
+ public void addInstancesFromDataSourcesConfig() {
+
+ for(ICdmDataSource dataSource : CdmPersistentDataSource.getAllDataSources()){
+ logger.warn("Adding local instance " + dataSource.getName());
+ addInstance(dataSource.getName(), dataSource.getName());
+ }
}
}
public static List<CdmServerInfo> getCdmServers() {
- List<CdmServerInfo> cdmServerInfoList = new ArrayList<CdmServerInfo>();
- cdmServerInfoList.add(new CdmServerInfo(NAME_PRODUCTION, SERVER_PRODUCTION, 80));
- cdmServerInfoList.add(new CdmServerInfo(NAME_INTEGRATION, SERVER_INTEGRATION, 80));
- cdmServerInfoList.add(new CdmServerInfo(NAME_TEST, SERVER_TEST, 80));
- cdmServerInfoList.add(new CdmServerInfo(NAME_LOCALHOST, SERVER_LOCALHOST, 8080));
- cdmServerInfoList.add(new CdmServerInfo(NAME_LOCALHOST_MGD, SERVER_LOCALHOST,8080));
+ if(cdmServerInfoList == null) {
+ cdmServerInfoList = new ArrayList<CdmServerInfo>();
+ cdmServerInfoList.add(new CdmServerInfo(NAME_PRODUCTION, SERVER_PRODUCTION, 80));
+ cdmServerInfoList.add(new CdmServerInfo(NAME_INTEGRATION, SERVER_INTEGRATION, 80));
+ cdmServerInfoList.add(new CdmServerInfo(NAME_TEST, SERVER_TEST, 80));
+ cdmServerInfoList.add(new CdmServerInfo(NAME_LOCALHOST, SERVER_LOCALHOST, 8080));
+ cdmServerInfoList.add(new CdmServerInfo(NAME_LOCALHOST_MGD, SERVER_LOCALHOST,8080));
+ }
return cdmServerInfoList;
}
public class CdmInstanceInfo {
private final String name;
+
+ /**
+ * The full path of the instance including the the prefix (if any).
+ * E.g. for an EDIT instance this would be something like "cdmserver/remoting"
+ * For a managed local server this would simply be "remoting"
+ */
private final String basePath;
package eu.etaxonomy.taxeditor.editor;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
import eu.etaxonomy.cdm.api.service.ITaxonService;
import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
import eu.etaxonomy.cdm.model.taxon.Synonym;
"taxon.rights",
"taxon.sources",
"taxon.descriptions",
- "taxon.synonymRelations",
+ "taxon.synonymRelations.relatedFrom.name.homotypicalGroup.typifiedNames",
"taxon.relationsToThisTaxon",
"taxon.relationsFromThisTaxon",
"taxon.taxonNodes",
private void initForTaxonBase(UUID taxonBaseUuid) {
- TaxonBase taxonBase = CdmStore.getService(ITaxonService.class).load(taxonBaseUuid);
+
+ List<String> taxonBasePropertyPaths = Arrays.asList(new String[] {
+ "annotations",
+ "markers",
+ "credits",
+ "extensions",
+ "rights",
+ "sources",
+ "descriptions",
+ "relationsToThisTaxon",
+ "relationsFromThisTaxon",
+ "taxonNodes",
+ "name.status",
+ "name.nomenclaturalReference",
+ "synonymRelations.relatedFrom.name.status.type",
+ "synonymRelations.relatedFrom.name.nomenclaturalReference.inReference",
+ "name.taxonBases",
+ "name.descriptions.descriptionElements",
+ "name.descriptions.markers"
+
+
+ });
+ TaxonBase taxonBase = CdmStore.getService(ITaxonService.class).load(taxonBaseUuid, taxonBasePropertyPaths);
if (taxonBase != null){
if(taxonBase.isInstanceOf(Taxon.class)){
Taxon taxon = CdmBase.deproxy(taxonBase, Taxon.class);
@Override
public Map<Object, List<String>> getPropertyPathsMap() {
-// Map<Object, List<String>> propertyPathsMap = new HashMap<Object, List<String>>();
+ Map<Object, List<String>> propertyPathsMap = new HashMap<Object, List<String>>();
// List<String> taxonNameBasePropertyPaths = Arrays.asList(new String[] {
// "status",
// "taxonBases.taxonNodes",
// "taxon.descriptions"
// });
// propertyPathsMap.put(TaxonNode.class, taxonBasePropertyPaths);
-// return propertyPathsMap;
- return null;
+ List<String> homotypicalGroupPropertyPaths = Arrays.asList(new String[] {
+ "typifiedNames.taxonBases.synonymRelations.relatedFrom.name",
+ "typifiedNames.taxonBases.synonymRelations.relatedFrom.name.status"
+ });
+ propertyPathsMap.put(HomotypicalGroup.class, homotypicalGroupPropertyPaths);
+ return propertyPathsMap;
+// return null;
}
}
xpndblcmpstAdvanced.setExpanded(false);
- CdmRemoteSource devRemoteSource = CdmServerInfo.getDevServerRemoteSource();
- if(devRemoteSource != null) {
- CdmStore.connect(devRemoteSource, this);
- isDevRemoteSource = true;
- }
-
Display display = getParent().getDisplay();
while (!shlConnect.isDisposed()) {
}
refreshCdmServer();
updatePort();
+ CdmRemoteSource devRemoteSource = CdmServerInfo.getDevServerRemoteSource();
+ if(devRemoteSource != null) {
+ String username = System.getProperty("cdm.server.dev.username");
+ String password = System.getProperty("cdm.server.dev.password");
+ if(username != null && !username.isEmpty() && password != null && !password.isEmpty()) {
+ txtLogin.setText(username);
+ txtPassword.setText(password);
+ CdmStore.connect(devRemoteSource, RemotingLoginDialog.this);
+ }
+ }
}
});
return Status.OK_STATUS;
private void readPrefCredentials() {
String username, password;
- if(isDevRemoteSource) {
- username = System.getProperty("cdm.server.dev.username");
- password = System.getProperty("cdm.server.dev.password");
- if(username != null && !username.isEmpty() && password != null && !password.isEmpty()) {
- txtLogin.setText(username);
- txtPassword.setText(password);
- return;
- }
- }
IEclipsePreferences preferences = ConfigurationScope.INSTANCE.getNode(STORE_PREFERENCES_NODE);
Preferences credentialsPrefs = preferences.node(LOGIN_NODE);
username = credentialsPrefs.get(getUsernamePrefKey(), "");
private void emptyCredentials() {
txtLogin.setText("");
- txtLogin.setText("");
+ txtPassword.setText("");
}
private String getUsernamePrefKey() {
lib/unitils-dbmaintainer-3.4.2.jar,
lib/unitils-dbunit-3.4.2.jar,
lib/unitils-spring-3.4.2.jar,
- lib/dbunit-2.4.9.jar
-Export-Package: org.hamcrest
+ lib/dbunit-2.4.9.jar
\ No newline at end of file
import org.apache.log4j.Logger;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
-import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.osgi.framework.Bundle;
public static final Resource SERVER_PROPERTIES_FILE =
new ClassPathResource("server.properties");
-// public static final Resource EDITOR_DATASOURCES_FILE =
-// new ClassPathResource(".cdmLibrary/writableResources/cdm.datasources.xml");
-
- //private static CdmApplicationRemoteController remoteApplicationController;
private static ICdmRemoteSource cdmRemoteSource;
private static CdmPersistentRemoteSource remotePersistentSource;
private static String user = DEFAULT_USER;
private static String password = DEFAULT_PASSWORD;
+ protected static CDMServer cdmServer;
+
@BeforeClass
public static void initializeBaseRemotingTest() {
File userHomeDir = new File(FileLocator.resolve(userHomeDirURL).toURI());
userHomeDirPath = userHomeDir.getAbsolutePath();
-
-
- logger.info("Setting user.home to " + userHomeDirPath);
- System.setProperty(userHomeKey, userHomeDirPath);
-
- CDMServer cdmServer = CDMServer.getInstance();
-
-
- Properties prop = new Properties();
-
URL serverPropertiesURL = bundle.getEntry("src/test/resources/server.properties");
File serverPropertiesFile = new File(FileLocator.resolve(serverPropertiesURL).toURI());
InputStream inputStream = new FileInputStream(serverPropertiesFile);
+ Properties prop = new Properties();
if (inputStream != null) {
prop.load(inputStream);
inputStream.close();
}
- if(prop.getProperty("httpPort") != null) {
- cdmServer.setHttpPort(Integer.valueOf(prop.getProperty("httpPort")));
- }
+ logger.info("Setting user.home to " + userHomeDirPath);
+ System.setProperty(userHomeKey, userHomeDirPath);
- if(prop.getProperty("stopPort") != null) {
- cdmServer.setStopPort(Integer.valueOf(prop.getProperty("stopPort")));
- }
+ cdmServer = new CDMServer("cdmTest");
- if(prop.getProperty("stopKey") != null) {
- cdmServer.setStopKey(prop.getProperty("stopKey"));
- }
if(prop.getProperty("user") != null) {
user = prop.getProperty("user");
password = prop.getProperty("password");
}
- cdmServer.start();
- initializeController(CDMServer.getInstance().getName(),
- CDMServer.getInstance().getHost(),
- CDMServer.getInstance().getPort(),
- CDMServer.getInstance().getContextPath(),
+ initializeController(cdmServer.getName(),
+ cdmServer.getHost(),
+ cdmServer.getPort(),
+ cdmServer.getContextPath(),
NomenclaturalCode.ICNAFP,
user,
password);
return (CdmTransientEntityCacher) getFieldValueViaReflection(getSession(sessionOwner), "cdmTransientEntityCacher");
}
- @AfterClass
- public static void cleanup() {
- try {
- CDMServer.getInstance().stop();
- } catch (Exception e) {
- Assert.fail("Server could not be stopped. Reason : " + e.getMessage());
- }
- }
-
protected static Object getFieldValueViaReflection(Object object, String fieldName) {
Class<?> clazz = object.getClass();
package eu.etaxonomy.taxeditor.httpinvoker;
import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Properties;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.sql.DataSource;
import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Platform;
+import org.osgi.framework.Bundle;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.unitils.database.annotations.TestDataSource;
+import eu.etaxonomy.cdm.database.CdmPersistentDataSource;
+import eu.etaxonomy.cdm.database.ICdmDataSource;
import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSourceBase;
private boolean serverAlreadyRunning = false;
- private void CDMServer() {}
+ private File dataSourcesFile;
+ private final String dataSourceName;
- public static CDMServer getInstance() {
- if(cdmServer == null) {
- cdmServer = new CDMServer();
+ public CDMServer(String dataSourceName) throws CDMServerException {
+ this.dataSourceName = dataSourceName;
+ Properties prop = new Properties();
+
+ Bundle bundle = Platform.getBundle("eu.etaxonomy.taxeditor.cdmlib");
+ URL serverPropertiesURL = bundle.getEntry("src/test/resources/server.properties");
+
+ try {
+ File serverPropertiesFile = new File(FileLocator.resolve(serverPropertiesURL).toURI());
+ InputStream inputStream = new FileInputStream(serverPropertiesFile);
+
+ if (inputStream != null) {
+ prop.load(inputStream);
+ inputStream.close();
+ }
+ } catch (FileNotFoundException e) {
+ throw new CDMServerException(e);
+ } catch (URISyntaxException e) {
+ throw new CDMServerException(e);
+ } catch (IOException e) {
+ throw new CDMServerException(e);
}
- return cdmServer;
+
+
+
+ if(prop.getProperty("httpPort") != null) {
+ setHttpPort(Integer.valueOf(prop.getProperty("httpPort")));
+ }
+
+ if(prop.getProperty("stopPort") != null) {
+ setStopPort(Integer.valueOf(prop.getProperty("stopPort")));
+ }
+
+ if(prop.getProperty("stopKey") != null) {
+ setStopKey(prop.getProperty("stopKey"));
+ }
+
}
+
+
public String getName() {
return name;
}
public void stop(boolean force) throws Exception {
if(!force) {
- if(!getInstance().isStarted(1)) {
+ if(!cdmServer.isStarted(1)) {
logger.info("[CDM-Server] Server already stopped @ " + host + ":" + httpPort );
return;
}
} catch (MalformedObjectNameException e) {
throw new CDMServerException(e);
}
+ }
+ public void convertEditorToServerConfig() {
+ String xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> " + System.lineSeparator() +
+ "<beans xmlns=\"http://www.springframework.org/schema/beans\"" + System.lineSeparator() +
+ "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + System.lineSeparator() +
+ "xmlns:tx=\"http://www.springframework.org/schema/tx\"" + System.lineSeparator() +
+ "xmlns:context=\"http://www.springframework.org/schema/context\"" + System.lineSeparator() +
+ "xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd" + System.lineSeparator() +
+ "http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd" + System.lineSeparator() +
+ "http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd" + System.lineSeparator() +
+ ">" + System.lineSeparator() +
+ "<bean id=\"dataSourceProperties\" class=\"eu.etaxonomy.cdm.remote.config.DataSourceProperties\">" + System.lineSeparator() +
+ " <property name=\"propsMap\">" + System.lineSeparator() +
+ " <map/>" + System.lineSeparator() +
+ " </property>" + System.lineSeparator() +
+ "</bean>";
+
+ for(ICdmDataSource dataSource : CdmPersistentDataSource.getAllDataSources()) {
-
+ }
}
}
@Test
public void whenConnectingToInactiveServerThenFailToConnect() {
+
// check if non-active server throws the right exception
- CdmRemoteSource inactiveCrs = CdmRemoteSource.NewInstance(CDMServer.getInstance().getName(),
- CDMServer.getInstance().getHost(),
+ CdmRemoteSource inactiveCrs = CdmRemoteSource.NewInstance(cdmServer.getName(),
+ cdmServer.getHost(),
808080,
- CDMServer.getInstance().getContextPath(),
+ cdmServer.getContextPath(),
NomenclaturalCode.ICNAFP);
try {
inactiveCrs.getDbSchemaVersion();
@Test
public void whenConnectingToAnActiveServerThenConnectSuccessfully() {
// check if active server throws the right exception
- CdmRemoteSource activeCrs = CdmRemoteSource.NewInstance(CDMServer.getInstance().getName(),
- CDMServer.getInstance().getHost(),
- CDMServer.getInstance().getPort(),
- CDMServer.getInstance().getContextPath(),
+ CdmRemoteSource activeCrs = CdmRemoteSource.NewInstance(cdmServer.getName(),
+ cdmServer.getHost(),
+ cdmServer.getPort(),
+ cdmServer.getContextPath(),
NomenclaturalCode.ICNAFP);
String dbSchemaVersion = "";
try {
@Test
public void startCdmServer() throws CDMServerException {
- CDMServer.getInstance().start();
- }
-
- @Test
- public void stopCdmServer() {
+ CDMServer cdmServer = new CDMServer("cdmTest");
+ cdmServer .start();
try {
- CDMServer.getInstance().stop(true);
+ cdmServer.stop(true);
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Server could not be stopped. Reason : " + e.getMessage());
}
}
+
+ @Test
+ public void refreshInstancesTest() throws CDMServerException {
+ CdmServerInfo cdmServerInfo = new CdmServerInfo(CdmServerInfo.NAME_LOCALHOST_MGD, CdmServerInfo.SERVER_LOCALHOST,8080);
+ cdmServerInfo.refreshInstances();
+ List<CdmInstanceInfo> instances = cdmServerInfo.getInstances();
+ Assert.assertTrue(instances != null && !instances.isEmpty());
+ }
+
+ @Test
+ public void convertToServerConfigTest() {
+
+
+ }
}