From 77d15efc8c0baa965fffc884924a023325f308cd Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Thu, 8 Sep 2016 11:50:51 +0200 Subject: [PATCH] new versioning system --- CHANGELOG | 2 +- build.xml | 223 ++-- .../lcsb/mapviewer/common/Configuration.java | 755 +++++++------ .../mapviewer/common/FrameworkVersion.java | 91 ++ .../mapviewer/common/ConfigurationTest.java | 172 +-- commons/testFiles/version/CHANGELOG | 6 + .../version/{svnversion.txt => version.txt} | 2 +- .../mapviewer/model/log/ChangelogType.java | 43 - .../mapviewer/model/log/FrameworkVersion.java | 143 --- .../log/FrameworkVersionChangelogEntry.java | 173 --- .../lcsb/mapviewer/model/log/AllLogTests.java | 31 +- .../model/log/ChangelogTypeTest.java | 29 - .../FrameworkVersionChangelogEntryTest.java | 62 - .../model/log/FrameworkVersionTest.java | 56 - persist/src/db/11/fix_db_20160907.sql | 2 + .../FrameworkVersionChangelogEntryDao.java | 48 - .../persist/dao/log/FrameworkVersionDao.java | 62 - .../resources/applicationContext-persist.xml | 522 +++++---- .../persist/dao/log/AllLogTests.java | 26 +- ...FrameworkVersionChangelogEntryDaoTest.java | 102 -- .../dao/log/FrameworkVersionDaoTest.java | 89 -- .../services/impl/ConfigurationService.java | 391 +++---- .../impl/InvalidSvnVersionException.java | 26 - .../interfaces/IConfigurationService.java | 221 ++-- .../services/view/ChangelogView.java | 103 -- .../services/view/ChangelogViewFactory.java | 44 - .../services/view/FrameworkVersionView.java | 146 --- .../view/FrameworkVersionViewFactory.java | 44 - .../resources/applicationContext-service.xml | 152 ++- .../impl/ConfigurationServiceTest.java | 292 +++-- .../mapviewer/services/view/AllViewTests.java | 81 +- .../services/view/ChangelogViewTest.java | 27 - .../view/FrameworkVersionViewTest.java | 56 +- .../testCorrectSvn/version.txt} | 0 .../testModified/version.txt} | 0 .../gitVersionTest/testNormal/CHANGELOG | 6 + .../testNormal/version.txt} | 0 .../org.eclipse.wst.common.component | 86 +- .../mapviewer/bean/ConfigurationBean.java | 1001 ++++++++--------- .../bean/utils/VersionResourceHandler.java | 222 ++-- web/src/main/webapp/.gitignore | 2 + .../WEB-INF/components/admin/footer.xhtml | 47 +- web/src/main/webapp/admin/configuration.xhtml | 155 ++- 43 files changed, 2263 insertions(+), 3478 deletions(-) create mode 100644 commons/src/main/java/lcsb/mapviewer/common/FrameworkVersion.java create mode 100644 commons/testFiles/version/CHANGELOG rename commons/testFiles/version/{svnversion.txt => version.txt} (87%) delete mode 100644 model/src/main/java/lcsb/mapviewer/model/log/ChangelogType.java delete mode 100644 model/src/main/java/lcsb/mapviewer/model/log/FrameworkVersion.java delete mode 100644 model/src/main/java/lcsb/mapviewer/model/log/FrameworkVersionChangelogEntry.java delete mode 100644 model/src/test/java/lcsb/mapviewer/model/log/ChangelogTypeTest.java delete mode 100644 model/src/test/java/lcsb/mapviewer/model/log/FrameworkVersionChangelogEntryTest.java delete mode 100644 model/src/test/java/lcsb/mapviewer/model/log/FrameworkVersionTest.java create mode 100644 persist/src/db/11/fix_db_20160907.sql delete mode 100644 persist/src/main/java/lcsb/mapviewer/persist/dao/log/FrameworkVersionChangelogEntryDao.java delete mode 100644 persist/src/main/java/lcsb/mapviewer/persist/dao/log/FrameworkVersionDao.java delete mode 100644 persist/src/test/java/lcsb/mapviewer/persist/dao/log/FrameworkVersionChangelogEntryDaoTest.java delete mode 100644 persist/src/test/java/lcsb/mapviewer/persist/dao/log/FrameworkVersionDaoTest.java delete mode 100644 service/src/main/java/lcsb/mapviewer/services/impl/InvalidSvnVersionException.java delete mode 100644 service/src/main/java/lcsb/mapviewer/services/view/ChangelogView.java delete mode 100644 service/src/main/java/lcsb/mapviewer/services/view/ChangelogViewFactory.java delete mode 100644 service/src/main/java/lcsb/mapviewer/services/view/FrameworkVersionView.java delete mode 100644 service/src/main/java/lcsb/mapviewer/services/view/FrameworkVersionViewFactory.java delete mode 100644 service/src/test/java/lcsb/mapviewer/services/view/ChangelogViewTest.java rename service/testFiles/{svnVersionTest/testCorrectSvn/svnversion.txt => gitVersionTest/testCorrectSvn/version.txt} (100%) rename service/testFiles/{svnVersionTest/testModified/svnversion.txt => gitVersionTest/testModified/version.txt} (100%) create mode 100644 service/testFiles/gitVersionTest/testNormal/CHANGELOG rename service/testFiles/{svnVersionTest/testNormal/svnversion.txt => gitVersionTest/testNormal/version.txt} (100%) create mode 100644 web/src/main/webapp/.gitignore diff --git a/CHANGELOG b/CHANGELOG index a477846353..d9f196003e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -minerva (11) stable; urgency=medium +minerva (11alpha) stable; urgency=medium * Export to image without selecting region diff --git a/build.xml b/build.xml index 34da9647bf..d07a746c62 100644 --- a/build.xml +++ b/build.xml @@ -1,109 +1,114 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project name="minerva" default="main" basedir="."> - <property environment="env"/> - - <property name="build.dir" value="web/target" /> - <property name="war.file" value="web-1.0.war" /> - <property name="tomcat.home" value="${env.CATALINA_HOME}" /> - <property name="tomcat.deploy.dir" value="${tomcat.home}/webapps" /> - - <condition property="isWindows"> - <os family="windows" /> - </condition> - - <condition property="isUnix"> - <os family="unix" /> - </condition> - - <target name="war-exists"> - <available file="${tomcat.deploy.dir}/${ant.project.name}.war" property="war.exists"/> - </target> - - <target name="remove-war" depends="war-exists" if="war.exists"> - <delete file="${tomcat.deploy.dir}/${ant.project.name}.war" /> - </target> - - <target name="war-dir-exists"> - <available file="${tomcat.deploy.dir}/${ant.project.name}" property="war-dir.exists" type="dir"/> - </target> - - <target name="remove-war-dir" depends="war-dir-exists" if="war-dir.exists"> - <delete dir="${tomcat.deploy.dir}/${ant.project.name}" /> - </target> - - <target name="deploy" depends="remove-war,remove-war-dir"> - <copy file="${build.dir}/${war.file}" todir="${tomcat.deploy.dir}" /> - <move file="${tomcat.deploy.dir}/${war.file}" tofile="${tomcat.deploy.dir}/${ant.project.name}.war"/> - </target> - - - <target name="main" depends="tomcat-stop,maven-build,deploy,tomcat-start"> - </target> - - <target name="all" depends="main"> - </target> - - <target name="tomcat-start"> - <exec executable="${tomcat.home}/bin/startup.bat"> - </exec> - </target> - - <target name="tomcat-stop"> - <exec executable="${tomcat.home}/bin/shutdown.bat"> - </exec> - </target> - - <target name="maven-build" depends="svnversion, maven-build-windows, maven-build-unix"/> - - <target name="maven-build-windows" if="isWindows"> - <exec dir="." executable="cmd" > - <arg line="/c mvn -Dmaven.test.skip=true clean install -pl web -am" /> - </exec> - </target> - - <target name="maven-build-unix" if="isUnix"> - <exec dir="." executable="sh" > - <arg line="-c 'mvn -Dmaven.test.skip=true clean install -pl web -am'" /> - </exec> - </target> - - <target name="maven-test" depends="maven-test-windows, maven-test-unix"/> - - <target name="maven-test-windows" depends="maven-build" if="isWindows"> - <exec dir="." executable="cmd" > - <arg line="/c mvn test -fn" /> -<!-- <arg line="/c mvn surefire-report:report" /> --> - </exec> - </target> - - <target name="maven-test-unix" depends="maven-build" if="isUnix"> - <exec dir="." executable="sh" > - <arg line="-c 'mvn test -fn'" /> -<!-- <arg line="-c 'mvn surefire-report:report'" /> --> - </exec> - </target> - - <target name="deployMapFiles"> - <copy todir="${tomcat.deploy.dir}/map_images"> - <fileset dir="map_images" /> - </copy> - </target> - - - <target name="svnversion"> - <exec executable="svnversion" outputproperty="svnversion" /> - <tstamp> - <format property="build.time" pattern="dd/MM/yyyy HH:mm" - unit="hour"/> - </tstamp> - <echo >SVN Version: ${svnversion} -Build timestamp: ${build.time}</echo> - - <echo file="web/src/main/webapp/svnversion.txt">${svnversion} -${build.time}</echo> - </target> - - <target name="debian-pkg" depends="maven-build"> - <exec executable="debian/create-debian-pkg.sh"/> - </target> -</project> +<?xml version="1.0" encoding="UTF-8"?> +<project name="minerva" default="main" basedir="."> + <property environment="env"/> + + <property name="build.dir" value="web/target" /> + <property name="war.file" value="web-1.0.war" /> + <property name="tomcat.home" value="${env.CATALINA_HOME}" /> + <property name="tomcat.deploy.dir" value="${tomcat.home}/webapps" /> + + <condition property="isWindows"> + <os family="windows" /> + </condition> + + <condition property="isUnix"> + <os family="unix" /> + </condition> + + <target name="war-exists"> + <available file="${tomcat.deploy.dir}/${ant.project.name}.war" property="war.exists"/> + </target> + + <target name="remove-war" depends="war-exists" if="war.exists"> + <delete file="${tomcat.deploy.dir}/${ant.project.name}.war" /> + </target> + + <target name="war-dir-exists"> + <available file="${tomcat.deploy.dir}/${ant.project.name}" property="war-dir.exists" type="dir"/> + </target> + + <target name="remove-war-dir" depends="war-dir-exists" if="war-dir.exists"> + <delete dir="${tomcat.deploy.dir}/${ant.project.name}" /> + </target> + + <target name="deploy" depends="remove-war,remove-war-dir"> + <copy file="${build.dir}/${war.file}" todir="${tomcat.deploy.dir}" /> + <move file="${tomcat.deploy.dir}/${war.file}" tofile="${tomcat.deploy.dir}/${ant.project.name}.war"/> + </target> + + + <target name="main" depends="tomcat-stop,maven-build,deploy,tomcat-start"> + </target> + + <target name="all" depends="main"> + </target> + + <target name="tomcat-start"> + <exec executable="${tomcat.home}/bin/startup.bat"> + </exec> + </target> + + <target name="tomcat-stop"> + <exec executable="${tomcat.home}/bin/shutdown.bat"> + </exec> + </target> + + <target name="maven-build" depends="gitversion, maven-build-windows, maven-build-unix"/> + + <target name="maven-build-windows" if="isWindows"> + <exec dir="." executable="cmd" > + <arg line="/c mvn -Dmaven.test.skip=true clean install -pl web -am" /> + </exec> + </target> + + <target name="maven-build-unix" if="isUnix"> + <exec dir="." executable="sh" > + <arg line="-c 'mvn -Dmaven.test.skip=true clean install -pl web -am'" /> + </exec> + </target> + + <target name="maven-test" depends="maven-test-windows, maven-test-unix"/> + + <target name="maven-test-windows" depends="maven-build" if="isWindows"> + <exec dir="." executable="cmd" > + <arg line="/c mvn test -fn" /> +<!-- <arg line="/c mvn surefire-report:report" /> --> + </exec> + </target> + + <target name="maven-test-unix" depends="maven-build" if="isUnix"> + <exec dir="." executable="sh" > + <arg line="-c 'mvn test -fn'" /> +<!-- <arg line="-c 'mvn surefire-report:report'" /> --> + </exec> + </target> + + <target name="deployMapFiles"> + <copy todir="${tomcat.deploy.dir}/map_images"> + <fileset dir="map_images" /> + </copy> + </target> + + + <target name="gitversion"> + <exec executable="git" outputproperty="gitversion"> + <arg value="rev-parse"/> + <arg value="HEAD"/> + </exec> + + <tstamp> + <format property="build.time" pattern="dd/MM/yyyy HH:mm" + unit="hour"/> + </tstamp> + <echo >GIT Version: ${gitversion} +Build timestamp: ${build.time}</echo> + + <echo file="web/src/main/webapp/version.txt">${gitversion} +${build.time}</echo> + <copy file="CHANGELOG" tofile="web/src/main/webapp/CHANGELOG" overwrite="true"/> + </target> + + <target name="debian-pkg" depends="maven-build"> + <exec executable="debian/create-debian-pkg.sh"/> + </target> +</project> diff --git a/commons/src/main/java/lcsb/mapviewer/common/Configuration.java b/commons/src/main/java/lcsb/mapviewer/common/Configuration.java index 3ddb0cfdf9..a9c965f074 100644 --- a/commons/src/main/java/lcsb/mapviewer/common/Configuration.java +++ b/commons/src/main/java/lcsb/mapviewer/common/Configuration.java @@ -1,333 +1,422 @@ -package lcsb.mapviewer.common; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; - -import org.apache.log4j.Logger; - -/** - * Basic configuration parameters of the system (these values cannot be modified - * by the user, user modified values are kept in the db: - * {@link lcsb.mapviewer.db.model.user.Configuration Configuration} ). - * - * @author Piotr Gawron - * - */ -public final class Configuration { - - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(Configuration.class); - - /** - * How many elements should be visible in autocomplete lists. - */ - private static final int DEFAULT_AUTOCOMPLETE_SIZE = 5; - - /** - * What is the minimal zoom level in the Google Maps API. It cannot be set to - * 0 because Google Maps API was designed to visualize map of Earth which is - * based on torus. Therefore, if we use too small zoom level we will see next - * to the right edge elements from the left part. When we increase minimal - * zoom level there will be a gap (huge enough) between the overlapping parts - * and user will be unaware of that fact. - */ - public static final int MIN_ZOOM_LEVEL = 2; - - /** - * This constant describes minimum size (in square pixels) of object visible - * during nesting (it is a soft limit, can be override by depth of the - * depending tree). - */ - public static final double MIN_VISIBLE_OBJECT_SIZE = 55000; - - /** - * This constant describes maximum size (in square pixels) of object visible - * during nesting. - */ - public static final double MAX_VISIBLE_OBJECT_SIZE = 80000; - - /** - * Address where Parkinson's Disease map is available in the Internet. - */ - public static final String PUBLICALY_AVAILABLE_PD_MAP = "http://pdmap.uni.lu/MapViewer/?id=pdmap"; - - /** - * Where the main webpgae is located. - */ - public static final String MAIN_PAGE = "/index.xhtml"; - - /** - * Where miriam redirecting webpage is located. - */ - public static final String MIRIAM_PAGE = "miriam.xhtml"; - - /** - * Where the login webpage is located. - */ - public static final String LOGIN_PAGE = "/login.xhtml"; - - /** - * Spring url for login. - */ - public static final String SPRING_SECURITY_ACTION = "/login"; - - /** - * Spring url for logout. - */ - public static final String SPRING_SECURITY_LOGOUT = "/j_spring_security_logout"; - - /** - * Guest account. - */ - public static final String ANONYMOUS_LOGIN = "anonymous"; - - /** - * Should the application cache be turned on. - */ - private static boolean applicationCacheOn = true; - - /** - * Should the database cache be turned on. - */ - private static boolean dbCacheOn = true; - - /** - * This const defines at what memory usage level application should release - * cached objects (to prevent unnecessary out of memory execptions). - */ - // CHECKSTYLE:OFF - private static Double memorySaturationRatioTriggerClean = 0.9; - // CHECKSTYLE:ON - - /** - * What is the size of autocomplete elements. - */ - private static int autocompleteSize = DEFAULT_AUTOCOMPLETE_SIZE; - - /** - * Epsilon used for different types of comparisons. - */ - public static final double EPSILON = 1e-6; - - /** - * Svn version from which framework was built. - */ - private static String systemVersion = null; - - /** - * Date when the framework was built. - */ - private static String systemBuild = null; - - /** - * Address that should be allowed to use x-frame. - */ - private static String xFrametDomain = null; - - /** - * Directory where tomcat webapp folder is located. Default value is "." - * because it should be set to proper value when tomcat application is - * deployed and run. - */ - private static String webAppDir = "./"; - - /** - * Default constructor which prevents instatiation. - */ - private Configuration() { - - } - - /** - * @return the applicationCacheOn - */ - public static boolean isApplicationCacheOn() { - return applicationCacheOn; - } - - /** - * @param applicationCacheOn - * the applicationCacheOn to set - */ - public static void setApplicationCacheOn(boolean applicationCacheOn) { - Configuration.applicationCacheOn = applicationCacheOn; - } - - /** - * @return the dbCacheOn - */ - public static boolean isDbCacheOn() { - return dbCacheOn; - } - - /** - * @param dbCacheOn - * the dbCacheOn to set - */ - public static void setDbCacheOn(boolean dbCacheOn) { - Configuration.dbCacheOn = dbCacheOn; - } - - /** - * @return the autocompleteSize - */ - public static int getAutocompleteSize() { - return autocompleteSize; - } - - /** - * @param autocompleteSize - * the autocompleteSize to set - */ - public static void setAutocompleteSize(int autocompleteSize) { - Configuration.autocompleteSize = autocompleteSize; - } - - /** - * @param baseDir - * directory where the system is placed - * @return {@link #systemVersion} - */ - public static String getSystemVersion(String baseDir) { - if (systemVersion == null) { - loadSystemVersion(baseDir); - } - return systemVersion; - } - - /** - * @param baseDir - * directory where the system is placed - * @param forceReload - * if true then forces to reload data from text file - * @return {@link #systemVersion} - */ - public static String getSystemVersion(String baseDir, boolean forceReload) { - if (forceReload) { - systemVersion = null; - } - return getSystemVersion(baseDir); - } - - /** - * Loads system version (svn version, build date) from the file. - * - * @param baseDir - * directory where the system is placed - */ - protected static void loadSystemVersion(String baseDir) { - systemVersion = "Unknown"; - systemBuild = "Unknown"; - File file = null; - if (baseDir == null) { - file = new File("svnversion.txt"); - } else { - file = new File(baseDir + "svnversion.txt"); - } - if (file.exists()) { - loadSystemVersion(file); - } else { - logger.error(file.getAbsoluteFile() + " doesn't exist."); - } - } - - /** - * Loads system version (svn version, build date) from the file. - * - * @param file - * file from which data is loaded - */ - protected static void loadSystemVersion(File file) { - try { - BufferedReader reader = new BufferedReader(new FileReader(file)); - systemVersion = reader.readLine(); - systemBuild = reader.readLine(); - reader.close(); - } catch (IOException e) { - logger.error(e); - } - } - - /** - * @param baseDir - * directory where the system is placed - * @return the systemBuild - * @see #systemBuild - */ - public static String getSystemBuild(String baseDir) { - if (systemBuild == null) { - loadSystemVersion(baseDir); - } - return systemBuild; - } - - /** - * @param baseDir - * directory where the system is placed - * @param forceReload - * if true then forces to reload data from text file - * @return the systemBuild - * @see #systemBuild - */ - public static String getSystemBuild(String baseDir, boolean forceReload) { - if (forceReload) { - systemBuild = null; - } - return getSystemBuild(baseDir); - } - - /** - * @return the xFrametDomain - * @see #xFrametDomain - */ - public static String getxFrameDomain() { - return xFrametDomain; - } - - /** - * @param xFrametDomain - * the xFrametDomain to set - * @see #xFrametDomain - */ - public static void setxFrameDomain(String xFrametDomain) { - Configuration.xFrametDomain = xFrametDomain; - } - - /** - * @param path - * the path to webapp to set - * @see #webAppDir - */ - public static void setWebAppDir(String path) { - Configuration.webAppDir = path; - } - - /** - * @return the {@link #webAppDir} - */ - public static String getWebAppDir() { - return Configuration.webAppDir; - } - - /** - * @return the memorySaturationRatioTriggerClean - * @see #memorySaturationRatioTriggerClean - */ - public static Double getMemorySaturationRatioTriggerClean() { - return memorySaturationRatioTriggerClean; - } - - /** - * @param memorySaturationRatioTriggerClean - * the memorySaturationRatioTriggerClean to set - * @see #memorySaturationRatioTriggerClean - */ - public static void setMemorySaturationRatioTriggerClean(Double memorySaturationRatioTriggerClean) { - Configuration.memorySaturationRatioTriggerClean = memorySaturationRatioTriggerClean; - } - -} +package lcsb.mapviewer.common; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +import org.apache.log4j.Logger; + +/** + * Basic configuration parameters of the system (these values cannot be modified + * by the user, user modified values are kept in the db: + * {@link lcsb.mapviewer.db.model.user.Configuration Configuration} ). + * + * @author Piotr Gawron + * + */ +public final class Configuration { + + /** + * Default value for {@link #memorySaturationRatioTriggerClean}. It defines at + * what memory usage level application should release cached objects (to + * prevent unnecessary out of memory execptions). + * + */ + private static final double DEFAULT_MEMORY_SATURATION_TRIGGER_CLEAN = 0.9; + + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(Configuration.class); + + /** + * How many elements should be visible in autocomplete lists. + */ + private static final int DEFAULT_AUTOCOMPLETE_SIZE = 5; + + /** + * What is the minimal zoom level in the Google Maps API. It cannot be set to + * 0 because Google Maps API was designed to visualize map of Earth which is + * based on torus. Therefore, if we use too small zoom level we will see next + * to the right edge elements from the left part. When we increase minimal + * zoom level there will be a gap (huge enough) between the overlapping parts + * and user will be unaware of that fact. + */ + public static final int MIN_ZOOM_LEVEL = 2; + + /** + * This constant describes minimum size (in square pixels) of object visible + * during nesting (it is a soft limit, can be override by depth of the + * depending tree). + */ + public static final double MIN_VISIBLE_OBJECT_SIZE = 55000; + + /** + * This constant describes maximum size (in square pixels) of object visible + * during nesting. + */ + public static final double MAX_VISIBLE_OBJECT_SIZE = 80000; + + /** + * Address where Parkinson's Disease map is available in the Internet. + */ + public static final String PUBLICALY_AVAILABLE_PD_MAP = "http://pdmap.uni.lu/MapViewer/?id=pdmap"; + + /** + * Where the main webpgae is located. + */ + public static final String MAIN_PAGE = "/index.xhtml"; + + /** + * Where miriam redirecting webpage is located. + */ + public static final String MIRIAM_PAGE = "miriam.xhtml"; + + /** + * Where the login webpage is located. + */ + public static final String LOGIN_PAGE = "/login.xhtml"; + + /** + * Spring url for login. + */ + public static final String SPRING_SECURITY_ACTION = "/login"; + + /** + * Spring url for logout. + */ + public static final String SPRING_SECURITY_LOGOUT = "/j_spring_security_logout"; + + /** + * Guest account. + */ + public static final String ANONYMOUS_LOGIN = "anonymous"; + + /** + * Should the application cache be turned on. + */ + private static boolean applicationCacheOn = true; + + /** + * Should the database cache be turned on. + */ + private static boolean dbCacheOn = true; + + /** + * This const defines at what memory usage level application should release + * cached objects (to prevent unnecessary out of memory execptions). + */ + private static Double memorySaturationRatioTriggerClean = DEFAULT_MEMORY_SATURATION_TRIGGER_CLEAN; + + /** + * What is the size of autocomplete elements. + */ + private static int autocompleteSize = DEFAULT_AUTOCOMPLETE_SIZE; + + /** + * Epsilon used for different types of comparisons. + */ + public static final double EPSILON = 1e-6; + + /** + * Git version from which framework was built. + */ + private static String systemBuildVersion = null; + + /** + * Date when the framework was built. + */ + private static String systemBuildTime = null; + + /** + * Version of the system (used by debian package). + */ + private static String systemVersion = null; + + /** + * Address that should be allowed to use x-frame. + */ + private static String xFrametDomain = null; + + /** + * Directory where tomcat webapp folder is located. Default value is "." + * because it should be set to proper value when tomcat application is + * deployed and run. + */ + private static String webAppDir = "./"; + + /** + * Default constructor which prevents instatiation. + */ + private Configuration() { + + } + + /** + * @return the applicationCacheOn + */ + public static boolean isApplicationCacheOn() { + return applicationCacheOn; + } + + /** + * @param applicationCacheOn + * the applicationCacheOn to set + */ + public static void setApplicationCacheOn(boolean applicationCacheOn) { + Configuration.applicationCacheOn = applicationCacheOn; + } + + /** + * @return the dbCacheOn + */ + public static boolean isDbCacheOn() { + return dbCacheOn; + } + + /** + * @param dbCacheOn + * the dbCacheOn to set + */ + public static void setDbCacheOn(boolean dbCacheOn) { + Configuration.dbCacheOn = dbCacheOn; + } + + /** + * @return the autocompleteSize + */ + public static int getAutocompleteSize() { + return autocompleteSize; + } + + /** + * @param autocompleteSize + * the autocompleteSize to set + */ + public static void setAutocompleteSize(int autocompleteSize) { + Configuration.autocompleteSize = autocompleteSize; + } + + /** + * @param baseDir + * directory where the system is placed + * @return {@link #systemBuildVersion} + */ + public static String getSystemBuildVersion(String baseDir) { + if (systemBuildVersion == null) { + loadSystemVersion(baseDir); + } + return systemBuildVersion; + } + + /** + * @param baseDir + * directory where the system is placed + * @return {@link #systemVersion} + */ + public static String getSystemVersion(String baseDir) { + if (systemVersion == null) { + loadSystemVersion(baseDir); + } + return systemVersion; + } + + /** + * @param baseDir + * directory where the system is placed + * @param forceReload + * if true then forces to reload data from text file + * @return {@link #systemBuildVersion} + */ + public static String getSystemBuildVersion(String baseDir, boolean forceReload) { + if (forceReload) { + systemBuildVersion = null; + } + return getSystemBuildVersion(baseDir); + } + + /** + * @param baseDir + * directory where the system is placed + * @param forceReload + * if true then forces to reload data from text file + * @return {@link #systemBuildVersion} + */ + public static String getSystemVersion(String baseDir, boolean forceReload) { + if (forceReload) { + systemVersion = null; + } + return getSystemVersion(baseDir); + } + + /** + * Loads system version (git version, build date) from the file. + * + * @param baseDir + * directory where the system is placed + */ + protected static void loadSystemVersion(String baseDir) { + systemBuildVersion = "Unknown"; + systemBuildTime = "Unknown"; + systemVersion = "Unknown"; + File buildVersionFile = null; + File changelogFile = null; + if (baseDir == null) { + buildVersionFile = new File("version.txt"); + changelogFile = new File("CHANGELOG"); + } else { + buildVersionFile = new File(baseDir + "version.txt"); + changelogFile = new File(baseDir + "CHANGELOG"); + } + if (buildVersionFile.exists()) { + loadSystemBuildVersion(buildVersionFile); + } else { + logger.error(buildVersionFile.getAbsoluteFile() + " doesn't exist."); + } + + if (changelogFile.exists()) { + loadSystemVersion(changelogFile); + } else { + logger.error(changelogFile.getAbsoluteFile() + " doesn't exist."); + } + } + + /** + * Loads system version (git version, build date) from the file. + * + * @param file + * file from which data is loaded + */ + protected static void loadSystemBuildVersion(File file) { + try { + BufferedReader reader = new BufferedReader(new FileReader(file)); + systemBuildVersion = reader.readLine(); + systemBuildTime = reader.readLine(); + reader.close(); + } catch (IOException e) { + logger.error(e); + } + } + + /** + * Loads system version from debian changelog file. + * + * @param file + * debian changelog file + */ + protected static void loadSystemVersion(File file) { + try { + BufferedReader reader = new BufferedReader(new FileReader(file)); + String line = reader.readLine(); + + int startIndex = line.indexOf("("); + int endIndex = line.indexOf(")"); + + if (startIndex >= 0 && endIndex >= 0) { + systemVersion = line.substring(startIndex + 1, endIndex); + } else { + logger.error("Invalid CHANGELOG file. Cannot find system version in line: " + line); + } + reader.close(); + } catch (IOException e) { + logger.error(e); + } + } + + /** + * @param baseDir + * directory where the system is placed + * @return the systemBuild + * @see #systemBuildTime + */ + public static String getSystemBuild(String baseDir) { + if (systemBuildTime == null) { + loadSystemVersion(baseDir); + } + return systemBuildTime; + } + + /** + * @param baseDir + * directory where the system is placed + * @param forceReload + * if true then forces to reload data from text file + * @return the systemBuild + * @see #systemBuildTime + */ + public static String getSystemBuild(String baseDir, boolean forceReload) { + if (forceReload) { + systemBuildTime = null; + } + return getSystemBuild(baseDir); + } + + /** + * @return the xFrametDomain + * @see #xFrametDomain + */ + public static String getxFrameDomain() { + return xFrametDomain; + } + + /** + * @param xFrametDomain + * the xFrametDomain to set + * @see #xFrametDomain + */ + public static void setxFrameDomain(String xFrametDomain) { + Configuration.xFrametDomain = xFrametDomain; + } + + /** + * @param path + * the path to webapp to set + * @see #webAppDir + */ + public static void setWebAppDir(String path) { + Configuration.webAppDir = path; + } + + /** + * @return the {@link #webAppDir} + */ + public static String getWebAppDir() { + return Configuration.webAppDir; + } + + /** + * @return the memorySaturationRatioTriggerClean + * @see #memorySaturationRatioTriggerClean + */ + public static Double getMemorySaturationRatioTriggerClean() { + return memorySaturationRatioTriggerClean; + } + + /** + * @param memorySaturationRatioTriggerClean + * the memorySaturationRatioTriggerClean to set + * @see #memorySaturationRatioTriggerClean + */ + public static void setMemorySaturationRatioTriggerClean(Double memorySaturationRatioTriggerClean) { + Configuration.memorySaturationRatioTriggerClean = memorySaturationRatioTriggerClean; + } + + /** + * Returns information about version of the framework. + * + * @param baseDir + * directory where project was deployed (or information about version + * is stored) + * @return information about version of the framework + */ + public static FrameworkVersion getFrameworkVersion(String baseDir) { + FrameworkVersion result = new FrameworkVersion(); + loadSystemVersion(baseDir); + result.setGitVersion(getSystemBuildVersion(baseDir)); + result.setTime(getSystemBuild(baseDir)); + result.setVersion(getSystemVersion(baseDir)); + return result; + } + +} diff --git a/commons/src/main/java/lcsb/mapviewer/common/FrameworkVersion.java b/commons/src/main/java/lcsb/mapviewer/common/FrameworkVersion.java new file mode 100644 index 0000000000..b088af39f7 --- /dev/null +++ b/commons/src/main/java/lcsb/mapviewer/common/FrameworkVersion.java @@ -0,0 +1,91 @@ +package lcsb.mapviewer.common; + +import java.io.Serializable; + +/** + * View representation of the {@link FrameworkVersion}. Contains information + * about single framework version. + * + * @author Piotr Gawron + * + */ +public class FrameworkVersion implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Version of the framework. + */ + private String version; + + /** + * When this version was committed to git. + */ + private String gitVersion; + + /** + * When the framework was built. + */ + private String time; + + /** + * Default constructor. + * + */ + public FrameworkVersion() { + } + + /** + * @return the version + * @see #version + */ + public String getVersion() { + return version; + } + + /** + * @param version + * the version to set + * @see #version + */ + public void setVersion(String version) { + this.version = version; + } + + /** + * @return the gitVersion + * @see #gitVersion + */ + public String getGitVersion() { + return gitVersion; + } + + /** + * @param gitVersion + * the gitVersion to set + * @see #gitVersion + */ + public void setGitVersion(String gitVersion) { + this.gitVersion = gitVersion; + } + + /** + * @return the time + * @see #time + */ + public String getTime() { + return time; + } + + /** + * @param time + * the time to set + * @see #time + */ + public void setTime(String time) { + this.time = time; + } + +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/ConfigurationTest.java b/commons/src/test/java/lcsb/mapviewer/common/ConfigurationTest.java index b4e82478cd..ac518fde1d 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/ConfigurationTest.java +++ b/commons/src/test/java/lcsb/mapviewer/common/ConfigurationTest.java @@ -1,84 +1,88 @@ -package lcsb.mapviewer.common; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; - -import java.io.File; -import java.lang.reflect.Constructor; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class ConfigurationTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testGetters() { - Configuration.setApplicationCacheOn(false); - assertFalse(Configuration.isApplicationCacheOn()); - Configuration.setAutocompleteSize(1); - assertEquals(1, Configuration.getAutocompleteSize()); - Configuration.setDbCacheOn(false); - assertFalse(Configuration.isDbCacheOn()); - } - - @Test - public void testLoadSystemVersion() { - Configuration.loadSystemVersion((String) null); - assertEquals("Unknown", Configuration.getSystemVersion(null)); - assertEquals("Unknown", Configuration.getSystemBuild(null)); - } - - @Test - public void testLoadSystemVersion2() { - Configuration.loadSystemVersion(new File("unknown.xxx")); - assertEquals("Unknown", Configuration.getSystemVersion(null)); - assertEquals("Unknown", Configuration.getSystemBuild(null)); - } - - @Test - public void testGetSystemVersion() { - assertEquals("100", Configuration.getSystemVersion("testFiles/version/", true)); - assertEquals("100", Configuration.getSystemVersion(null, false)); - } - - @Test - public void testGetSystemBuild() { - assertEquals("102", Configuration.getSystemBuild("testFiles/version/", true)); - assertEquals("102", Configuration.getSystemBuild(null, false)); - } - - @Test - public void testXGetSystemVersion() { - String frame = "test"; - Configuration.setxFrameDomain(frame); - assertEquals(frame, Configuration.getxFrameDomain()); - } - - @Test - public void testWebAppDir() { - String dir = "test2"; - Configuration.setWebAppDir(dir); - assertEquals(dir, Configuration.getWebAppDir()); - } - - @Test - public void testPrivateConstructor() throws Exception { - try { - Constructor<?> constr = Configuration.class.getDeclaredConstructor(new Class<?>[] {}); - constr.setAccessible(true); - assertNotNull(constr.newInstance(new Object[] {})); - } catch (Exception e) { - throw e; - } - } -} +package lcsb.mapviewer.common; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + +import java.io.File; +import java.lang.reflect.Constructor; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class ConfigurationTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testGetters() { + Configuration.setApplicationCacheOn(false); + assertFalse(Configuration.isApplicationCacheOn()); + Configuration.setAutocompleteSize(1); + assertEquals(1, Configuration.getAutocompleteSize()); + Configuration.setDbCacheOn(false); + assertFalse(Configuration.isDbCacheOn()); + } + + @Test + public void testLoadSystemBuildVersion() { + Configuration.loadSystemVersion((String) null); + assertEquals("Unknown", Configuration.getSystemBuildVersion(null)); + assertEquals("Unknown", Configuration.getSystemBuild(null)); + assertEquals("Unknown", Configuration.getSystemVersion(null)); + } + + @Test + public void testLoadSystemBuildVersion2() { + Configuration.loadSystemVersion((String)null); + Configuration.loadSystemVersion(new File("unknown.xxx")); + assertEquals("Unknown", Configuration.getSystemBuildVersion(null)); + assertEquals("Unknown", Configuration.getSystemBuild(null)); + assertEquals("Unknown", Configuration.getSystemVersion(null)); + } + + @Test + public void testGetSystemBuildVersion() { + assertEquals("100", Configuration.getSystemBuildVersion("testFiles/version/", true)); + assertEquals("100", Configuration.getSystemBuildVersion(null, false)); + assertEquals("101", Configuration.getSystemVersion("testFiles/version/",true)); + } + + @Test + public void testGetSystemBuild() { + assertEquals("102", Configuration.getSystemBuild("testFiles/version/", true)); + assertEquals("102", Configuration.getSystemBuild(null, false)); + } + + @Test + public void testXGetSystemVersion() { + String frame = "test"; + Configuration.setxFrameDomain(frame); + assertEquals(frame, Configuration.getxFrameDomain()); + } + + @Test + public void testWebAppDir() { + String dir = "test2"; + Configuration.setWebAppDir(dir); + assertEquals(dir, Configuration.getWebAppDir()); + } + + @Test + public void testPrivateConstructor() throws Exception { + try { + Constructor<?> constr = Configuration.class.getDeclaredConstructor(new Class<?>[] {}); + constr.setAccessible(true); + assertNotNull(constr.newInstance(new Object[] {})); + } catch (Exception e) { + throw e; + } + } +} diff --git a/commons/testFiles/version/CHANGELOG b/commons/testFiles/version/CHANGELOG new file mode 100644 index 0000000000..7cea19f28c --- /dev/null +++ b/commons/testFiles/version/CHANGELOG @@ -0,0 +1,6 @@ +minerva (101) stable; urgency=medium + + * Initial release + + -- Piotr Gawron <piotr.gawron@uni.lu> Wed, 4 Dec 2013 22:00:00 +0200 + \ No newline at end of file diff --git a/commons/testFiles/version/svnversion.txt b/commons/testFiles/version/version.txt similarity index 87% rename from commons/testFiles/version/svnversion.txt rename to commons/testFiles/version/version.txt index 05a53c9930..4a6ba583e1 100644 --- a/commons/testFiles/version/svnversion.txt +++ b/commons/testFiles/version/version.txt @@ -1,2 +1,2 @@ -100 +100 102 \ No newline at end of file diff --git a/model/src/main/java/lcsb/mapviewer/model/log/ChangelogType.java b/model/src/main/java/lcsb/mapviewer/model/log/ChangelogType.java deleted file mode 100644 index c0f137cadb..0000000000 --- a/model/src/main/java/lcsb/mapviewer/model/log/ChangelogType.java +++ /dev/null @@ -1,43 +0,0 @@ -package lcsb.mapviewer.model.log; - -/** - * Defines type o {@link FrameworkVersionChangelogEntry changlog entry}. - * - * @author Piotr Gawron - * - */ -public enum ChangelogType { - /** - * New functionality. - */ - FUNCTIONALITY("functionality"), - - /** - * Bug fix. - */ - BUG_FIX("bug fix"); - - /** - * Common name of the type. - */ - private String commonName; - - /** - * Default constructor. - * - * @param name - * common name of the type - */ - ChangelogType(String name) { - this.commonName = name; - } - - /** - * @return the commonName - * @see #commonName - */ - public String getCommonName() { - return commonName; - } - -} diff --git a/model/src/main/java/lcsb/mapviewer/model/log/FrameworkVersion.java b/model/src/main/java/lcsb/mapviewer/model/log/FrameworkVersion.java deleted file mode 100644 index e3dd1655a1..0000000000 --- a/model/src/main/java/lcsb/mapviewer/model/log/FrameworkVersion.java +++ /dev/null @@ -1,143 +0,0 @@ -package lcsb.mapviewer.model.log; - -import java.io.Serializable; -import java.util.Calendar; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; - -/** - * Describes single release version of the MapViewer framework. - * - * @author Piotr Gawron - * - */ -@Entity -@Table(name = "framework_version") -public class FrameworkVersion implements Serializable { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Unique database identifier. - */ - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "idDb", unique = true, nullable = false) - private int id; - - /** - * Unique version identifier. - */ - @Column(unique = true, nullable = false) - private int version; - - /** - * Svn version of this release. - */ - @Column(unique = true, nullable = false) - private int svnVersion; - - /** - * Short description of the release. - */ - private String description; - - /** - * When the release took place. - */ - @Column(nullable = false) - private Calendar time; - - /** - * @return the version - * @see #version - */ - public int getVersion() { - return version; - } - - /** - * @param version - * the version to set - * @see #version - */ - public void setVersion(int version) { - this.version = version; - } - - /** - * @return the svnVersion - * @see #svnVersion - */ - public int getSvnVersion() { - return svnVersion; - } - - /** - * @param svnVersion - * the svnVersion to set - * @see #svnVersion - */ - public void setSvnVersion(int svnVersion) { - this.svnVersion = svnVersion; - } - - /** - * @return the description - * @see #description - */ - public String getDescription() { - return description; - } - - /** - * @param description - * the description to set - * @see #description - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * @return the time - * @see #time - */ - public Calendar getTime() { - return time; - } - - /** - * @param time - * the time to set - * @see #time - */ - public void setTime(Calendar time) { - this.time = time; - } - - /** - * @return the id - * @see #id - */ - public int getId() { - return id; - } - - /** - * @param id the id to set - * @see #id - */ - public void setId(int id) { - this.id = id; - } - -} diff --git a/model/src/main/java/lcsb/mapviewer/model/log/FrameworkVersionChangelogEntry.java b/model/src/main/java/lcsb/mapviewer/model/log/FrameworkVersionChangelogEntry.java deleted file mode 100644 index 41f90c366c..0000000000 --- a/model/src/main/java/lcsb/mapviewer/model/log/FrameworkVersionChangelogEntry.java +++ /dev/null @@ -1,173 +0,0 @@ -package lcsb.mapviewer.model.log; - -import java.io.Serializable; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - -import lcsb.mapviewer.model.user.ExternalProject; -import lcsb.mapviewer.model.user.ExternalUser; - -/** - * Describes single changelog entry.. - * - * @author Piotr Gawron - * - */ -@Entity -@Table(name = "changelog") -public class FrameworkVersionChangelogEntry implements Serializable { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Unique database identifier. - */ - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "idDb", unique = true, nullable = false) - private int id; - - /** - * Svn version of for this changelog. - */ - @Column(nullable = false) - private int svnVersion; - - /** - * Short description of the changelog. - */ - @Column(nullable = false) - private String description; - - /** - * Type of changelog. - */ - @Column(nullable = false) - private ChangelogType type; - - /** - * Which project requested this change. - */ - @ManyToOne - @JoinColumn - private ExternalProject requestProject; - - /** - * Who requested this change. - */ - @ManyToOne - @JoinColumn - private ExternalUser requestUser; - - /** - * @return the svnVersion - * @see #svnVersion - */ - public int getSvnVersion() { - return svnVersion; - } - - /** - * @param svnVersion - * the svnVersion to set - * @see #svnVersion - */ - public void setSvnVersion(int svnVersion) { - this.svnVersion = svnVersion; - } - - /** - * @return the description - * @see #description - */ - public String getDescription() { - return description; - } - - /** - * @param description - * the description to set - * @see #description - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * @return the type - * @see #type - */ - public ChangelogType getType() { - return type; - } - - /** - * @param type - * the type to set - * @see #type - */ - public void setType(ChangelogType type) { - this.type = type; - } - - /** - * @return the requestProject - * @see #requestProject - */ - public ExternalProject getRequestProject() { - return requestProject; - } - - /** - * @param requestProject - * the requestProject to set - * @see #requestProject - */ - public void setRequestProject(ExternalProject requestProject) { - this.requestProject = requestProject; - } - - /** - * @return the requestUser - * @see #requestUser - */ - public ExternalUser getRequestUser() { - return requestUser; - } - - /** - * @param requestUser - * the requestUser to set - * @see #requestUser - */ - public void setRequestUser(ExternalUser requestUser) { - this.requestUser = requestUser; - } - - /** - * @return the id - * @see #id - */ - public int getId() { - return id; - } - - /** - * @param id the id to set - * @see #id - */ - public void setId(int id) { - this.id = id; - } - -} diff --git a/model/src/test/java/lcsb/mapviewer/model/log/AllLogTests.java b/model/src/test/java/lcsb/mapviewer/model/log/AllLogTests.java index 66e7c4b5f2..8ac37dc1f1 100644 --- a/model/src/test/java/lcsb/mapviewer/model/log/AllLogTests.java +++ b/model/src/test/java/lcsb/mapviewer/model/log/AllLogTests.java @@ -1,17 +1,14 @@ -package lcsb.mapviewer.model.log; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -@RunWith(Suite.class) -@SuiteClasses({ FrameworkVersionChangelogEntryTest.class, // - ChangelogTypeTest.class, // - FrameworkVersionTest.class, // - LogTypeTest.class, // - ObjectLogTest.class, // - SystemLogTest.class // -}) -public class AllLogTests { - -} +package lcsb.mapviewer.model.log; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({ LogTypeTest.class, // + ObjectLogTest.class, // + SystemLogTest.class // +}) +public class AllLogTests { + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/log/ChangelogTypeTest.java b/model/src/test/java/lcsb/mapviewer/model/log/ChangelogTypeTest.java deleted file mode 100644 index 7f89d01a5a..0000000000 --- a/model/src/test/java/lcsb/mapviewer/model/log/ChangelogTypeTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package lcsb.mapviewer.model.log; - -import static org.junit.Assert.assertNotNull; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class ChangelogTypeTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testValidValues() { - for (ChangelogType type : ChangelogType.values()) { - assertNotNull(type); - - // for coverage tests - ChangelogType.valueOf(type.toString()); - assertNotNull(type.getCommonName()); - } - } -} diff --git a/model/src/test/java/lcsb/mapviewer/model/log/FrameworkVersionChangelogEntryTest.java b/model/src/test/java/lcsb/mapviewer/model/log/FrameworkVersionChangelogEntryTest.java deleted file mode 100644 index b0cf9369ee..0000000000 --- a/model/src/test/java/lcsb/mapviewer/model/log/FrameworkVersionChangelogEntryTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package lcsb.mapviewer.model.log; - -import static org.junit.Assert.assertEquals; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.model.user.ExternalProject; -import lcsb.mapviewer.model.user.ExternalUser; - -public class FrameworkVersionChangelogEntryTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new FrameworkVersionChangelogEntry()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - FrameworkVersionChangelogEntry entry = new FrameworkVersionChangelogEntry(); - String description = "desC"; - int id = 6; - ExternalProject requestProject = new ExternalProject(); - ExternalUser requestUser = new ExternalUser(); - int svnVersion = 960; - ChangelogType type = ChangelogType.BUG_FIX; - - entry.setDescription(description); - entry.setId(id); - entry.setRequestProject(requestProject); - entry.setRequestUser(requestUser); - entry.setSvnVersion(svnVersion); - entry.setType(type); - - assertEquals(description, entry.getDescription()); - assertEquals(id, entry.getId()); - assertEquals(requestProject, entry.getRequestProject()); - assertEquals(requestUser, entry.getRequestUser()); - assertEquals(svnVersion, entry.getSvnVersion()); - assertEquals(type, entry.getType()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } -} diff --git a/model/src/test/java/lcsb/mapviewer/model/log/FrameworkVersionTest.java b/model/src/test/java/lcsb/mapviewer/model/log/FrameworkVersionTest.java deleted file mode 100644 index 85750c2136..0000000000 --- a/model/src/test/java/lcsb/mapviewer/model/log/FrameworkVersionTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package lcsb.mapviewer.model.log; - -import static org.junit.Assert.assertEquals; - -import java.util.Calendar; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class FrameworkVersionTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new FrameworkVersion()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - FrameworkVersion fv = new FrameworkVersion(); - String description = "as"; - int id = 15; - int svnVersion = 63; - Calendar time = Calendar.getInstance(); - int version = 7; - fv.setDescription(description); - assertEquals(description, fv.getDescription()); - fv.setId(id); - assertEquals(id, fv.getId()); - fv.setSvnVersion(svnVersion); - assertEquals(svnVersion, fv.getSvnVersion()); - fv.setTime(time); - assertEquals(time, fv.getTime()); - fv.setVersion(version); - assertEquals(version, fv.getVersion()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } -} diff --git a/persist/src/db/11/fix_db_20160907.sql b/persist/src/db/11/fix_db_20160907.sql new file mode 100644 index 0000000000..a2f1f1aed7 --- /dev/null +++ b/persist/src/db/11/fix_db_20160907.sql @@ -0,0 +1,2 @@ +drop table changelog; +drop table framework_version; \ No newline at end of file diff --git a/persist/src/main/java/lcsb/mapviewer/persist/dao/log/FrameworkVersionChangelogEntryDao.java b/persist/src/main/java/lcsb/mapviewer/persist/dao/log/FrameworkVersionChangelogEntryDao.java deleted file mode 100644 index 534c5df541..0000000000 --- a/persist/src/main/java/lcsb/mapviewer/persist/dao/log/FrameworkVersionChangelogEntryDao.java +++ /dev/null @@ -1,48 +0,0 @@ -package lcsb.mapviewer.persist.dao.log; - -import java.util.List; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.model.log.FrameworkVersionChangelogEntry; -import lcsb.mapviewer.persist.dao.BaseDao; - -/** - * Data access object class for {@link FrameworkVersionChangelogEntry} objects. - * - * @author Piotr Gawron - * - */ -public class FrameworkVersionChangelogEntryDao extends BaseDao<FrameworkVersionChangelogEntry> { - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private final Logger logger = Logger.getLogger(FrameworkVersionChangelogEntryDao.class); - - /** - * Default constructor. - */ - public FrameworkVersionChangelogEntryDao() { - super(FrameworkVersionChangelogEntry.class); - } - - /** - * Returns entries between two svn versions (startSvnVersion,endSvnVersion>. - * - * @param startSvnVersion - * starting svn version - * @param endSvnVersion - * end svn version - * @return changelog entries between two svn versions - */ - @SuppressWarnings("unchecked") - public List<FrameworkVersionChangelogEntry> getChangelogBetweenSvnVersions(int startSvnVersion, int endSvnVersion) { - List<?> list = getSession() - .createQuery( - " from " + this.getClazz().getSimpleName() + " where svnversion > :param_val AND svnversion <= :param_val_end order by id" - + removableAndStatemant()).setParameter("param_val", startSvnVersion).setParameter("param_val_end", endSvnVersion).list(); - return (List<FrameworkVersionChangelogEntry>) list; - } - -} diff --git a/persist/src/main/java/lcsb/mapviewer/persist/dao/log/FrameworkVersionDao.java b/persist/src/main/java/lcsb/mapviewer/persist/dao/log/FrameworkVersionDao.java deleted file mode 100644 index 1d33fd8edd..0000000000 --- a/persist/src/main/java/lcsb/mapviewer/persist/dao/log/FrameworkVersionDao.java +++ /dev/null @@ -1,62 +0,0 @@ -package lcsb.mapviewer.persist.dao.log; - -import java.util.List; - -import lcsb.mapviewer.model.log.FrameworkVersion; -import lcsb.mapviewer.persist.dao.BaseDao; - -/** - * Data access object class for {@link FrameworkVersion} objects. - * - * @author Piotr Gawron - * - */ -public class FrameworkVersionDao extends BaseDao<FrameworkVersion> { - /** - * Default constructor. - */ - public FrameworkVersionDao() { - super(FrameworkVersion.class); - } - - /** - * Returns last {@link FrameworkVersion} before (or equal to ) given svn - * version. - * - * @param version - * svn version - * @return {@link FrameworkVersion} before (or equal to ) given svn version or - * null if such version doesn't exists - */ - public FrameworkVersion getVersionForSvnVersion(Integer version) { - List<?> list = getSession() - .createQuery(" from " + this.getClazz().getSimpleName() + " where svnVersion <= :param_val " + removableAndStatemant() + " order by svnVersion desc") - .setParameter("param_val", version).setMaxResults(1).list(); - - if (list.size() > 0) { - return (FrameworkVersion) list.get(0); - } else { - return null; - } - } - - /** - * Returns {@link FrameworkVersion} for given system version. - * - * @param version - * {@link FrameworkVersion#version version} - * @return {@link FrameworkVersion} for given system version or null if such - * version doesn't exists - */ - public FrameworkVersion getByVersion(int version) { - List<?> list = getSession() - .createQuery(" from " + this.getClazz().getSimpleName() + " where version = :param_val " + removableAndStatemant()).setParameter("param_val", version) - .list(); - if (list.size() > 0) { - return (FrameworkVersion) list.get(0); - } else { - return null; - } - } - -} diff --git a/persist/src/main/resources/applicationContext-persist.xml b/persist/src/main/resources/applicationContext-persist.xml index cf4026122d..d551dccd27 100644 --- a/persist/src/main/resources/applicationContext-persist.xml +++ b/persist/src/main/resources/applicationContext-persist.xml @@ -1,263 +1,259 @@ -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:tx="http://www.springframework.org/schema/tx" - xmlns:context="http://www.springframework.org/schema/context" - xsi:schemaLocation="http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans-4.0.xsd - http://www.springframework.org/schema/tx - http://www.springframework.org/schema/tx/spring-tx-4.0.xsd - http://www.springframework.org/schema/context - http://www.springframework.org/schema/context/spring-context-4.0.xsd"> - -<!-- Data Source Declaration --> - <bean id="DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> - <property name="driverClass" value="org.postgresql.Driver" /> - <property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/map_viewer" /> - <property name="user" value="map_viewer" /> - <property name="password" value="123qweasdzxc" /> - <property name="maxPoolSize" value="100" /> - <property name="maxStatements" value="5" /> - <property name="minPoolSize" value="5" /> - </bean> - - - <bean id="BaseDao" class="lcsb.mapviewer.persist.dao.BaseDao" abstract="true"> - </bean> - - <bean id="ExternalUserDao" class="lcsb.mapviewer.persist.dao.user.ExternalUserDao" parent="BaseDao"/> - <bean id="ExternalProjectDao" class="lcsb.mapviewer.persist.dao.user.ExternalProjectDao" parent="BaseDao"/> - <bean id="UserDao" class="lcsb.mapviewer.persist.dao.user.UserDao" parent="BaseDao"/> - <bean id="PrivilegeDao" class="lcsb.mapviewer.persist.dao.user.PrivilegeDao" parent="BaseDao"/> - - <bean id="FrameworkVersionChangelogEntryDao" class="lcsb.mapviewer.persist.dao.log.FrameworkVersionChangelogEntryDao" parent="BaseDao"/> - <bean id="FrameworkVersionDao" class="lcsb.mapviewer.persist.dao.log.FrameworkVersionDao" parent="BaseDao"/> - <bean id="LogDao" class="lcsb.mapviewer.persist.dao.log.LogDao" parent="BaseDao"/> - - - <bean id="BigFileEntryDao" class="lcsb.mapviewer.persist.dao.cache.BigFileEntryDao" parent="BaseDao"/> - <bean id="UploadedFileEntryDao" class="lcsb.mapviewer.persist.dao.cache.UploadedFileEntryDao" parent="BaseDao"/> - <bean id="ConfigurationDao" class="lcsb.mapviewer.persist.dao.ConfigurationDao" parent="BaseDao"/> - <bean id="CacheQueryDao" class="lcsb.mapviewer.persist.dao.cache.CacheQueryDao" parent="BaseDao"/> - <bean id="CacheTypeDao" class="lcsb.mapviewer.persist.dao.cache.CacheTypeDao" parent="BaseDao"/> - - <bean id="DataMiningDao" class="lcsb.mapviewer.persist.dao.map.graph.DataMiningDao" parent="BaseDao"/> - <bean id="DataMiningSetDao" class="lcsb.mapviewer.persist.dao.map.graph.DataMiningSetDao" parent="BaseDao"/> - - <bean id="AliasDao" class="lcsb.mapviewer.persist.dao.map.layout.alias.AliasDao" parent="BaseDao"/> - - <bean id="ReferenceGenomeDao" class="lcsb.mapviewer.persist.dao.map.layout.ReferenceGenomeDao" parent="BaseDao"/> - <bean id="ReferenceGenomeGeneMappingDao" class="lcsb.mapviewer.persist.dao.map.layout.ReferenceGenomeGeneMappingDao" parent="BaseDao"/> - - <bean id="SpeciesDao" class="lcsb.mapviewer.persist.dao.map.species.SpeciesDao" parent="BaseDao"/> - <bean id="ReactionDao" class="lcsb.mapviewer.persist.dao.map.species.ReactionDao" parent="BaseDao"/> - - <bean id="DbUtils" class="lcsb.mapviewer.persist.DbUtils"> - <property name="sessionFactory" ref="SessionFactory" /> - </bean> - <bean id="SpringApplicationContext" class="lcsb.mapviewer.persist.SpringApplicationContext"/> - - <bean id="SearchHistoryDao" class="lcsb.mapviewer.persist.dao.map.statistics.SearchHistoryDao" parent="BaseDao"/> - - <bean id="PolylineDao" class="lcsb.mapviewer.persist.dao.graphics.PolylineDao" parent="BaseDao"/> - <bean id="ModelDao" class="lcsb.mapviewer.persist.dao.map.ModelDao" parent="BaseDao"/> - <bean id="CommentDao" class="lcsb.mapviewer.persist.dao.map.CommentDao" parent="BaseDao"/> - <bean id="LayoutDao" class="lcsb.mapviewer.persist.dao.map.LayoutDao" parent="BaseDao"/> - <bean id="ProjectDao" class="lcsb.mapviewer.persist.dao.ProjectDao" parent="BaseDao"/> - - - <bean id="SessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> - <property name="dataSource" ref="DataSource" /> - <property name="annotatedClasses"> - <list> - - <value>lcsb.mapviewer.model.map.graph.DataMining</value> - <value>lcsb.mapviewer.model.map.graph.DataMiningSet</value> - - <value>lcsb.mapviewer.model.map.reaction.type.BooleanLogicGateReaction</value> - <value>lcsb.mapviewer.model.map.reaction.type.DissociationReaction</value> - <value>lcsb.mapviewer.model.map.reaction.type.HeterodimerAssociationReaction</value> - <value>lcsb.mapviewer.model.map.reaction.type.KnownTransitionOmittedReaction</value> - <value>lcsb.mapviewer.model.map.reaction.type.NegativeInfluenceReaction</value> - <value>lcsb.mapviewer.model.map.reaction.type.PhysicalStimulationReaction</value> - <value>lcsb.mapviewer.model.map.reaction.type.PositiveInfluenceReaction</value> - <value>lcsb.mapviewer.model.map.reaction.type.ReducedModulationReaction</value> - <value>lcsb.mapviewer.model.map.reaction.type.ReducedPhysicalStimulationReaction</value> - <value>lcsb.mapviewer.model.map.reaction.type.ReducedTriggerReaction</value> - <value>lcsb.mapviewer.model.map.reaction.type.StateTransitionReaction</value> - <value>lcsb.mapviewer.model.map.reaction.type.TranscriptionReaction</value> - <value>lcsb.mapviewer.model.map.reaction.type.TranslationReaction</value> - <value>lcsb.mapviewer.model.map.reaction.type.TransportReaction</value> - <value>lcsb.mapviewer.model.map.reaction.type.TriggerReaction</value> - <value>lcsb.mapviewer.model.map.reaction.type.TruncationReaction</value> - <value>lcsb.mapviewer.model.map.reaction.type.UnknownNegativeInfluenceReaction</value> - <value>lcsb.mapviewer.model.map.reaction.type.UnknownPositiveInfluenceReaction</value> - <value>lcsb.mapviewer.model.map.reaction.type.UnknownReducedModulationReaction</value> - <value>lcsb.mapviewer.model.map.reaction.type.UnknownReducedPhysicalStimulationReaction</value> - <value>lcsb.mapviewer.model.map.reaction.type.UnknownReducedTriggerReaction</value> - <value>lcsb.mapviewer.model.map.reaction.type.UnknownTransitionReaction</value> - - <value>lcsb.mapviewer.model.graphics.ArrowTypeData</value> - <value>lcsb.mapviewer.model.graphics.PolylineData</value> - - <value>lcsb.mapviewer.model.log.FrameworkVersion</value> - <value>lcsb.mapviewer.model.log.FrameworkVersionChangelogEntry</value> - <value>lcsb.mapviewer.model.log.GenericLog</value> - <value>lcsb.mapviewer.model.log.ObjectLog</value> - <value>lcsb.mapviewer.model.log.SystemLog</value> - - <value>lcsb.mapviewer.model.user.BasicPrivilege</value> - <value>lcsb.mapviewer.model.user.Configuration</value> - <value>lcsb.mapviewer.model.user.ExternalProject</value> - <value>lcsb.mapviewer.model.user.ExternalUser</value> - <value>lcsb.mapviewer.model.user.ObjectPrivilege</value> - <value>lcsb.mapviewer.model.user.User</value> - <value>lcsb.mapviewer.model.user.UserAnnotationSchema</value> - <value>lcsb.mapviewer.model.user.UserClassAnnotators</value> - <value>lcsb.mapviewer.model.user.UserClassValidAnnotations</value> - <value>lcsb.mapviewer.model.user.UserClassRequiredAnnotations</value> - - <value>lcsb.mapviewer.model.Project</value> - - <value>lcsb.mapviewer.model.map.Comment</value> - <value>lcsb.mapviewer.model.map.Element</value> - <value>lcsb.mapviewer.model.map.OverviewImage</value> - <value>lcsb.mapviewer.model.map.OverviewImageLink</value> - <value>lcsb.mapviewer.model.map.OverviewLink</value> - <value>lcsb.mapviewer.model.map.OverviewModelLink</value> - <value>lcsb.mapviewer.model.map.OverviewSearchLink</value> - - <value>lcsb.mapviewer.model.map.layout.Layout</value> - - <value>lcsb.mapviewer.model.map.model.ModelData</value> - - <value>lcsb.mapviewer.model.map.model.AliasSubmodelConnection</value> - <value>lcsb.mapviewer.model.map.model.ModelSubmodelConnection</value> - <value>lcsb.mapviewer.model.map.model.SubmodelConnection</value> - - <value>lcsb.mapviewer.model.map.statistics.SearchHistory</value> - - <value>lcsb.mapviewer.model.cache.BigFileEntry</value> - <value>lcsb.mapviewer.model.cache.CacheQuery</value> - <value>lcsb.mapviewer.model.cache.CacheType</value> - <value>lcsb.mapviewer.model.cache.UploadedFileEntry</value> - - <value>lcsb.mapviewer.model.map.reaction.AbstractNode</value> - <value>lcsb.mapviewer.model.map.reaction.AndOperator</value> - <value>lcsb.mapviewer.model.map.reaction.AssociationOperator</value> - <value>lcsb.mapviewer.model.map.reaction.DissociationOperator</value> - <value>lcsb.mapviewer.model.map.reaction.Modifier</value> - <value>lcsb.mapviewer.model.map.reaction.NandOperator</value> - <value>lcsb.mapviewer.model.map.reaction.NodeOperator</value> - <value>lcsb.mapviewer.model.map.reaction.OrOperator</value> - <value>lcsb.mapviewer.model.map.reaction.Product</value> - <value>lcsb.mapviewer.model.map.reaction.Reactant</value> - <value>lcsb.mapviewer.model.map.reaction.Reaction</value> - <value>lcsb.mapviewer.model.map.reaction.ReactionNode</value> - <value>lcsb.mapviewer.model.map.reaction.SplitOperator</value> - <value>lcsb.mapviewer.model.map.reaction.TruncationOperator</value> - <value>lcsb.mapviewer.model.map.reaction.UnknownOperator</value> - - <value>lcsb.mapviewer.model.map.modifier.Catalysis</value> - <value>lcsb.mapviewer.model.map.modifier.Inhibition</value> - <value>lcsb.mapviewer.model.map.modifier.Modulation</value> - <value>lcsb.mapviewer.model.map.modifier.PhysicalStimulation</value> - <value>lcsb.mapviewer.model.map.modifier.Trigger</value> - <value>lcsb.mapviewer.model.map.modifier.UnknownCatalysis</value> - <value>lcsb.mapviewer.model.map.modifier.UnknownInhibition</value> - - <value>lcsb.mapviewer.model.map.agregator.Compartment</value> - - <value>lcsb.mapviewer.model.map.layout.ReferenceGenome</value> - <value>lcsb.mapviewer.model.map.layout.ReferenceGenomeGeneMapping</value> - - <value>lcsb.mapviewer.model.map.layout.alias.Alias</value> - <value>lcsb.mapviewer.model.map.layout.alias.ArtifitialCompartmentAlias</value> - <value>lcsb.mapviewer.model.map.layout.alias.BottomSquareCompartmentAlias</value> - <value>lcsb.mapviewer.model.map.layout.alias.CompartmentAlias</value> - <value>lcsb.mapviewer.model.map.layout.alias.ComplexAlias</value> - <value>lcsb.mapviewer.model.map.layout.alias.LeftSquareCompartmentAlias</value> - <value>lcsb.mapviewer.model.map.layout.alias.OvalCompartmentAlias</value> - <value>lcsb.mapviewer.model.map.layout.alias.RightSquareCompartmentAlias</value> - <value>lcsb.mapviewer.model.map.layout.alias.SpeciesAlias</value> - <value>lcsb.mapviewer.model.map.layout.alias.SearchIndex</value> - <value>lcsb.mapviewer.model.map.layout.alias.SquareCompartmentAlias</value> - <value>lcsb.mapviewer.model.map.layout.alias.TopSquareCompartmentAlias</value> - <value>lcsb.mapviewer.model.map.layout.graphics.Layer</value> - <value>lcsb.mapviewer.model.map.layout.graphics.LayerText</value> - <value>lcsb.mapviewer.model.map.layout.graphics.LayerRect</value> - <value>lcsb.mapviewer.model.map.layout.graphics.LayerOval</value> - - <value>lcsb.mapviewer.model.map.species.AntisenseRna</value> - <value>lcsb.mapviewer.model.map.species.ComplexSpecies</value> - <value>lcsb.mapviewer.model.map.species.Degraded</value> - <value>lcsb.mapviewer.model.map.species.Drug</value> - <value>lcsb.mapviewer.model.map.species.Gene</value> - <value>lcsb.mapviewer.model.map.species.GenericProtein</value> - <value>lcsb.mapviewer.model.map.species.Ion</value> - <value>lcsb.mapviewer.model.map.species.IonChannelProtein</value> - <value>lcsb.mapviewer.model.map.species.Phenotype</value> - <value>lcsb.mapviewer.model.map.species.Protein</value> - <value>lcsb.mapviewer.model.map.species.ReceptorProtein</value> - <value>lcsb.mapviewer.model.map.species.Rna</value> - <value>lcsb.mapviewer.model.map.species.SimpleMolecule</value> - <value>lcsb.mapviewer.model.map.species.Species</value> - <value>lcsb.mapviewer.model.map.species.TruncatedProtein</value> - <value>lcsb.mapviewer.model.map.species.Unknown</value> - - <value>lcsb.mapviewer.model.map.species.fields.AntisenseRnaRegion</value> - <value>lcsb.mapviewer.model.map.species.fields.AssociatedElement</value> - <value>lcsb.mapviewer.model.map.species.fields.ModificationResidue</value> - <value>lcsb.mapviewer.model.map.species.fields.RnaRegion</value> - - <value>lcsb.mapviewer.model.map.MiriamData</value> - </list> - </property> - <property name="hibernateProperties"> - <props> - <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop> - <!--<prop key="hibernate.show_sql">true</prop>--> - <!--<prop key="hibernate.current_session_context_class">thread</prop>--> - - <!--<prop key="hibernate.hbm2ddl.auto">create</prop> --> - </props> - </property> - </bean> - - <tx:annotation-driven/> - - <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> - <property name="sessionFactory" ref="SessionFactory"/> - </bean> - - <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> - <property name="sessionFactory" ref="SessionFactory"/> - </bean> - - <!-- Encoder used for hashing passwords --> - <bean id="PasswordEncoder" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder"/> - - -<!-- These beans are responsible for statistics (used for debuging) --> -<!-- - <bean id="hibernateStatisticsMBean" class="org.hibernate.jmx.StatisticsService"> - <property name="statisticsEnabled" value="true" /> - <property name="sessionFactory" value="#{SessionFactory}" /> - </bean> - - <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"> - <property name="locateExistingServerIfPossible" value="true" /> - </bean> - - <bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter" - lazy-init="false"> - <property name="server" ref="mbeanServer" /> - <property name="registrationBehaviorName" value="REGISTRATION_REPLACE_EXISTING"/> - <property name="beans"> - <map> - <entry key="yourkey:name=hibernateStatistics" value-ref="hibernateStatisticsMBean" /> - </map> - </property> - </bean> ---> - -</beans> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:tx="http://www.springframework.org/schema/tx" + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation="http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans-4.0.xsd + http://www.springframework.org/schema/tx + http://www.springframework.org/schema/tx/spring-tx-4.0.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context-4.0.xsd"> + +<!-- Data Source Declaration --> + <bean id="DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> + <property name="driverClass" value="org.postgresql.Driver" /> + <property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/map_viewer" /> + <property name="user" value="map_viewer" /> + <property name="password" value="123qweasdzxc" /> + <property name="maxPoolSize" value="100" /> + <property name="maxStatements" value="5" /> + <property name="minPoolSize" value="5" /> + </bean> + + + <bean id="BaseDao" class="lcsb.mapviewer.persist.dao.BaseDao" abstract="true"> + </bean> + + <bean id="ExternalUserDao" class="lcsb.mapviewer.persist.dao.user.ExternalUserDao" parent="BaseDao"/> + <bean id="ExternalProjectDao" class="lcsb.mapviewer.persist.dao.user.ExternalProjectDao" parent="BaseDao"/> + <bean id="UserDao" class="lcsb.mapviewer.persist.dao.user.UserDao" parent="BaseDao"/> + <bean id="PrivilegeDao" class="lcsb.mapviewer.persist.dao.user.PrivilegeDao" parent="BaseDao"/> + + <bean id="LogDao" class="lcsb.mapviewer.persist.dao.log.LogDao" parent="BaseDao"/> + + + <bean id="BigFileEntryDao" class="lcsb.mapviewer.persist.dao.cache.BigFileEntryDao" parent="BaseDao"/> + <bean id="UploadedFileEntryDao" class="lcsb.mapviewer.persist.dao.cache.UploadedFileEntryDao" parent="BaseDao"/> + <bean id="ConfigurationDao" class="lcsb.mapviewer.persist.dao.ConfigurationDao" parent="BaseDao"/> + <bean id="CacheQueryDao" class="lcsb.mapviewer.persist.dao.cache.CacheQueryDao" parent="BaseDao"/> + <bean id="CacheTypeDao" class="lcsb.mapviewer.persist.dao.cache.CacheTypeDao" parent="BaseDao"/> + + <bean id="DataMiningDao" class="lcsb.mapviewer.persist.dao.map.graph.DataMiningDao" parent="BaseDao"/> + <bean id="DataMiningSetDao" class="lcsb.mapviewer.persist.dao.map.graph.DataMiningSetDao" parent="BaseDao"/> + + <bean id="AliasDao" class="lcsb.mapviewer.persist.dao.map.layout.alias.AliasDao" parent="BaseDao"/> + + <bean id="ReferenceGenomeDao" class="lcsb.mapviewer.persist.dao.map.layout.ReferenceGenomeDao" parent="BaseDao"/> + <bean id="ReferenceGenomeGeneMappingDao" class="lcsb.mapviewer.persist.dao.map.layout.ReferenceGenomeGeneMappingDao" parent="BaseDao"/> + + <bean id="SpeciesDao" class="lcsb.mapviewer.persist.dao.map.species.SpeciesDao" parent="BaseDao"/> + <bean id="ReactionDao" class="lcsb.mapviewer.persist.dao.map.species.ReactionDao" parent="BaseDao"/> + + <bean id="DbUtils" class="lcsb.mapviewer.persist.DbUtils"> + <property name="sessionFactory" ref="SessionFactory" /> + </bean> + <bean id="SpringApplicationContext" class="lcsb.mapviewer.persist.SpringApplicationContext"/> + + <bean id="SearchHistoryDao" class="lcsb.mapviewer.persist.dao.map.statistics.SearchHistoryDao" parent="BaseDao"/> + + <bean id="PolylineDao" class="lcsb.mapviewer.persist.dao.graphics.PolylineDao" parent="BaseDao"/> + <bean id="ModelDao" class="lcsb.mapviewer.persist.dao.map.ModelDao" parent="BaseDao"/> + <bean id="CommentDao" class="lcsb.mapviewer.persist.dao.map.CommentDao" parent="BaseDao"/> + <bean id="LayoutDao" class="lcsb.mapviewer.persist.dao.map.LayoutDao" parent="BaseDao"/> + <bean id="ProjectDao" class="lcsb.mapviewer.persist.dao.ProjectDao" parent="BaseDao"/> + + + <bean id="SessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> + <property name="dataSource" ref="DataSource" /> + <property name="annotatedClasses"> + <list> + + <value>lcsb.mapviewer.model.map.graph.DataMining</value> + <value>lcsb.mapviewer.model.map.graph.DataMiningSet</value> + + <value>lcsb.mapviewer.model.map.reaction.type.BooleanLogicGateReaction</value> + <value>lcsb.mapviewer.model.map.reaction.type.DissociationReaction</value> + <value>lcsb.mapviewer.model.map.reaction.type.HeterodimerAssociationReaction</value> + <value>lcsb.mapviewer.model.map.reaction.type.KnownTransitionOmittedReaction</value> + <value>lcsb.mapviewer.model.map.reaction.type.NegativeInfluenceReaction</value> + <value>lcsb.mapviewer.model.map.reaction.type.PhysicalStimulationReaction</value> + <value>lcsb.mapviewer.model.map.reaction.type.PositiveInfluenceReaction</value> + <value>lcsb.mapviewer.model.map.reaction.type.ReducedModulationReaction</value> + <value>lcsb.mapviewer.model.map.reaction.type.ReducedPhysicalStimulationReaction</value> + <value>lcsb.mapviewer.model.map.reaction.type.ReducedTriggerReaction</value> + <value>lcsb.mapviewer.model.map.reaction.type.StateTransitionReaction</value> + <value>lcsb.mapviewer.model.map.reaction.type.TranscriptionReaction</value> + <value>lcsb.mapviewer.model.map.reaction.type.TranslationReaction</value> + <value>lcsb.mapviewer.model.map.reaction.type.TransportReaction</value> + <value>lcsb.mapviewer.model.map.reaction.type.TriggerReaction</value> + <value>lcsb.mapviewer.model.map.reaction.type.TruncationReaction</value> + <value>lcsb.mapviewer.model.map.reaction.type.UnknownNegativeInfluenceReaction</value> + <value>lcsb.mapviewer.model.map.reaction.type.UnknownPositiveInfluenceReaction</value> + <value>lcsb.mapviewer.model.map.reaction.type.UnknownReducedModulationReaction</value> + <value>lcsb.mapviewer.model.map.reaction.type.UnknownReducedPhysicalStimulationReaction</value> + <value>lcsb.mapviewer.model.map.reaction.type.UnknownReducedTriggerReaction</value> + <value>lcsb.mapviewer.model.map.reaction.type.UnknownTransitionReaction</value> + + <value>lcsb.mapviewer.model.graphics.ArrowTypeData</value> + <value>lcsb.mapviewer.model.graphics.PolylineData</value> + + <value>lcsb.mapviewer.model.log.GenericLog</value> + <value>lcsb.mapviewer.model.log.ObjectLog</value> + <value>lcsb.mapviewer.model.log.SystemLog</value> + + <value>lcsb.mapviewer.model.user.BasicPrivilege</value> + <value>lcsb.mapviewer.model.user.Configuration</value> + <value>lcsb.mapviewer.model.user.ExternalProject</value> + <value>lcsb.mapviewer.model.user.ExternalUser</value> + <value>lcsb.mapviewer.model.user.ObjectPrivilege</value> + <value>lcsb.mapviewer.model.user.User</value> + <value>lcsb.mapviewer.model.user.UserAnnotationSchema</value> + <value>lcsb.mapviewer.model.user.UserClassAnnotators</value> + <value>lcsb.mapviewer.model.user.UserClassValidAnnotations</value> + <value>lcsb.mapviewer.model.user.UserClassRequiredAnnotations</value> + + <value>lcsb.mapviewer.model.Project</value> + + <value>lcsb.mapviewer.model.map.Comment</value> + <value>lcsb.mapviewer.model.map.Element</value> + <value>lcsb.mapviewer.model.map.OverviewImage</value> + <value>lcsb.mapviewer.model.map.OverviewImageLink</value> + <value>lcsb.mapviewer.model.map.OverviewLink</value> + <value>lcsb.mapviewer.model.map.OverviewModelLink</value> + <value>lcsb.mapviewer.model.map.OverviewSearchLink</value> + + <value>lcsb.mapviewer.model.map.layout.Layout</value> + + <value>lcsb.mapviewer.model.map.model.ModelData</value> + + <value>lcsb.mapviewer.model.map.model.AliasSubmodelConnection</value> + <value>lcsb.mapviewer.model.map.model.ModelSubmodelConnection</value> + <value>lcsb.mapviewer.model.map.model.SubmodelConnection</value> + + <value>lcsb.mapviewer.model.map.statistics.SearchHistory</value> + + <value>lcsb.mapviewer.model.cache.BigFileEntry</value> + <value>lcsb.mapviewer.model.cache.CacheQuery</value> + <value>lcsb.mapviewer.model.cache.CacheType</value> + <value>lcsb.mapviewer.model.cache.UploadedFileEntry</value> + + <value>lcsb.mapviewer.model.map.reaction.AbstractNode</value> + <value>lcsb.mapviewer.model.map.reaction.AndOperator</value> + <value>lcsb.mapviewer.model.map.reaction.AssociationOperator</value> + <value>lcsb.mapviewer.model.map.reaction.DissociationOperator</value> + <value>lcsb.mapviewer.model.map.reaction.Modifier</value> + <value>lcsb.mapviewer.model.map.reaction.NandOperator</value> + <value>lcsb.mapviewer.model.map.reaction.NodeOperator</value> + <value>lcsb.mapviewer.model.map.reaction.OrOperator</value> + <value>lcsb.mapviewer.model.map.reaction.Product</value> + <value>lcsb.mapviewer.model.map.reaction.Reactant</value> + <value>lcsb.mapviewer.model.map.reaction.Reaction</value> + <value>lcsb.mapviewer.model.map.reaction.ReactionNode</value> + <value>lcsb.mapviewer.model.map.reaction.SplitOperator</value> + <value>lcsb.mapviewer.model.map.reaction.TruncationOperator</value> + <value>lcsb.mapviewer.model.map.reaction.UnknownOperator</value> + + <value>lcsb.mapviewer.model.map.modifier.Catalysis</value> + <value>lcsb.mapviewer.model.map.modifier.Inhibition</value> + <value>lcsb.mapviewer.model.map.modifier.Modulation</value> + <value>lcsb.mapviewer.model.map.modifier.PhysicalStimulation</value> + <value>lcsb.mapviewer.model.map.modifier.Trigger</value> + <value>lcsb.mapviewer.model.map.modifier.UnknownCatalysis</value> + <value>lcsb.mapviewer.model.map.modifier.UnknownInhibition</value> + + <value>lcsb.mapviewer.model.map.agregator.Compartment</value> + + <value>lcsb.mapviewer.model.map.layout.ReferenceGenome</value> + <value>lcsb.mapviewer.model.map.layout.ReferenceGenomeGeneMapping</value> + + <value>lcsb.mapviewer.model.map.layout.alias.Alias</value> + <value>lcsb.mapviewer.model.map.layout.alias.ArtifitialCompartmentAlias</value> + <value>lcsb.mapviewer.model.map.layout.alias.BottomSquareCompartmentAlias</value> + <value>lcsb.mapviewer.model.map.layout.alias.CompartmentAlias</value> + <value>lcsb.mapviewer.model.map.layout.alias.ComplexAlias</value> + <value>lcsb.mapviewer.model.map.layout.alias.LeftSquareCompartmentAlias</value> + <value>lcsb.mapviewer.model.map.layout.alias.OvalCompartmentAlias</value> + <value>lcsb.mapviewer.model.map.layout.alias.RightSquareCompartmentAlias</value> + <value>lcsb.mapviewer.model.map.layout.alias.SpeciesAlias</value> + <value>lcsb.mapviewer.model.map.layout.alias.SearchIndex</value> + <value>lcsb.mapviewer.model.map.layout.alias.SquareCompartmentAlias</value> + <value>lcsb.mapviewer.model.map.layout.alias.TopSquareCompartmentAlias</value> + <value>lcsb.mapviewer.model.map.layout.graphics.Layer</value> + <value>lcsb.mapviewer.model.map.layout.graphics.LayerText</value> + <value>lcsb.mapviewer.model.map.layout.graphics.LayerRect</value> + <value>lcsb.mapviewer.model.map.layout.graphics.LayerOval</value> + + <value>lcsb.mapviewer.model.map.species.AntisenseRna</value> + <value>lcsb.mapviewer.model.map.species.ComplexSpecies</value> + <value>lcsb.mapviewer.model.map.species.Degraded</value> + <value>lcsb.mapviewer.model.map.species.Drug</value> + <value>lcsb.mapviewer.model.map.species.Gene</value> + <value>lcsb.mapviewer.model.map.species.GenericProtein</value> + <value>lcsb.mapviewer.model.map.species.Ion</value> + <value>lcsb.mapviewer.model.map.species.IonChannelProtein</value> + <value>lcsb.mapviewer.model.map.species.Phenotype</value> + <value>lcsb.mapviewer.model.map.species.Protein</value> + <value>lcsb.mapviewer.model.map.species.ReceptorProtein</value> + <value>lcsb.mapviewer.model.map.species.Rna</value> + <value>lcsb.mapviewer.model.map.species.SimpleMolecule</value> + <value>lcsb.mapviewer.model.map.species.Species</value> + <value>lcsb.mapviewer.model.map.species.TruncatedProtein</value> + <value>lcsb.mapviewer.model.map.species.Unknown</value> + + <value>lcsb.mapviewer.model.map.species.fields.AntisenseRnaRegion</value> + <value>lcsb.mapviewer.model.map.species.fields.AssociatedElement</value> + <value>lcsb.mapviewer.model.map.species.fields.ModificationResidue</value> + <value>lcsb.mapviewer.model.map.species.fields.RnaRegion</value> + + <value>lcsb.mapviewer.model.map.MiriamData</value> + </list> + </property> + <property name="hibernateProperties"> + <props> + <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop> + <!--<prop key="hibernate.show_sql">true</prop>--> + <!--<prop key="hibernate.current_session_context_class">thread</prop>--> + + <!--<prop key="hibernate.hbm2ddl.auto">create</prop> --> + </props> + </property> + </bean> + + <tx:annotation-driven/> + + <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> + <property name="sessionFactory" ref="SessionFactory"/> + </bean> + + <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> + <property name="sessionFactory" ref="SessionFactory"/> + </bean> + + <!-- Encoder used for hashing passwords --> + <bean id="PasswordEncoder" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder"/> + + +<!-- These beans are responsible for statistics (used for debuging) --> +<!-- + <bean id="hibernateStatisticsMBean" class="org.hibernate.jmx.StatisticsService"> + <property name="statisticsEnabled" value="true" /> + <property name="sessionFactory" value="#{SessionFactory}" /> + </bean> + + <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"> + <property name="locateExistingServerIfPossible" value="true" /> + </bean> + + <bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter" + lazy-init="false"> + <property name="server" ref="mbeanServer" /> + <property name="registrationBehaviorName" value="REGISTRATION_REPLACE_EXISTING"/> + <property name="beans"> + <map> + <entry key="yourkey:name=hibernateStatistics" value-ref="hibernateStatisticsMBean" /> + </map> + </property> + </bean> +--> + +</beans> diff --git a/persist/src/test/java/lcsb/mapviewer/persist/dao/log/AllLogTests.java b/persist/src/test/java/lcsb/mapviewer/persist/dao/log/AllLogTests.java index 817ee1fab4..e8ee5a7b57 100644 --- a/persist/src/test/java/lcsb/mapviewer/persist/dao/log/AllLogTests.java +++ b/persist/src/test/java/lcsb/mapviewer/persist/dao/log/AllLogTests.java @@ -1,14 +1,12 @@ -package lcsb.mapviewer.persist.dao.log; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -@RunWith(Suite.class) -@SuiteClasses({ FrameworkVersionChangelogEntryDaoTest.class, // - FrameworkVersionDaoTest.class, // - LogDaoTest.class,// -}) -public class AllLogTests { - -} +package lcsb.mapviewer.persist.dao.log; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({ LogDaoTest.class,// +}) +public class AllLogTests { + +} diff --git a/persist/src/test/java/lcsb/mapviewer/persist/dao/log/FrameworkVersionChangelogEntryDaoTest.java b/persist/src/test/java/lcsb/mapviewer/persist/dao/log/FrameworkVersionChangelogEntryDaoTest.java deleted file mode 100644 index 1f400c9453..0000000000 --- a/persist/src/test/java/lcsb/mapviewer/persist/dao/log/FrameworkVersionChangelogEntryDaoTest.java +++ /dev/null @@ -1,102 +0,0 @@ -package lcsb.mapviewer.persist.dao.log; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.List; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.annotation.Rollback; - -import lcsb.mapviewer.model.log.ChangelogType; -import lcsb.mapviewer.model.log.FrameworkVersionChangelogEntry; -import lcsb.mapviewer.model.user.ExternalProject; -import lcsb.mapviewer.model.user.ExternalUser; -import lcsb.mapviewer.persist.PersistTestFunctions; -import lcsb.mapviewer.persist.dao.user.ExternalProjectDao; -import lcsb.mapviewer.persist.dao.user.ExternalUserDao; - -@Rollback(true) -public class FrameworkVersionChangelogEntryDaoTest extends PersistTestFunctions { - @Autowired - FrameworkVersionChangelogEntryDao dao; - - @Autowired - ExternalProjectDao epDao; - - @Autowired - ExternalUserDao euDao; - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testAdd() throws Exception { - try { - - ExternalUser user = new ExternalUser(); - user.setName("John"); - user.setSurname("Doe"); - ExternalProject project = new ExternalProject(); - - epDao.add(project); - euDao.add(user); - - FrameworkVersionChangelogEntry fw = new FrameworkVersionChangelogEntry(); - fw.setSvnVersion(-1); - fw.setType(ChangelogType.BUG_FIX); - fw.setRequestProject(project); - fw.setRequestUser(user); - fw.setDescription("test"); - - long count = dao.getCount(); - - dao.add(fw); - - long count2 = dao.getCount(); - - assertEquals(count + 1, count2); - - dao.delete(fw); - epDao.delete(project); - euDao.delete(user); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetAll() throws Exception { - try { - List<FrameworkVersionChangelogEntry> list = dao.getAll(); - assertNotNull(list); - for (FrameworkVersionChangelogEntry frameworkVersionChangelogEntry : list) { - assertNotNull(frameworkVersionChangelogEntry.getType()); - } - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetChangelogBetweenSvnVersions() throws Exception { - try { - List<FrameworkVersionChangelogEntry> list = dao.getChangelogBetweenSvnVersions(0, -1); - assertEquals(0, list.size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} diff --git a/persist/src/test/java/lcsb/mapviewer/persist/dao/log/FrameworkVersionDaoTest.java b/persist/src/test/java/lcsb/mapviewer/persist/dao/log/FrameworkVersionDaoTest.java deleted file mode 100644 index 6f0a1a32c6..0000000000 --- a/persist/src/test/java/lcsb/mapviewer/persist/dao/log/FrameworkVersionDaoTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package lcsb.mapviewer.persist.dao.log; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.util.Calendar; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; - -import lcsb.mapviewer.model.log.FrameworkVersion; -import lcsb.mapviewer.persist.PersistTestFunctions; - -public class FrameworkVersionDaoTest extends PersistTestFunctions { - @Autowired - FrameworkVersionDao dao; - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testAdd() throws Exception { - try { - FrameworkVersion fw = new FrameworkVersion(); - fw.setSvnVersion(-1); - fw.setVersion(-1); - fw.setTime(Calendar.getInstance()); - - long count = dao.getCount(); - - dao.add(fw); - - long count2 = dao.getCount(); - - assertEquals(count + 1, count2); - - dao.delete(fw); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetVersionForSvnVersion() throws Exception { - try { - FrameworkVersion fw = dao.getVersionForSvnVersion(0); - assertNull(fw); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetVersionForSvnVersionOk() throws Exception { - try { - FrameworkVersion fw = dao.getVersionForSvnVersion(100); - assertNotNull(fw); - assertEquals(2, fw.getVersion()); - fw = dao.getVersionForSvnVersion(117); - assertNotNull(fw); - assertEquals(3, fw.getVersion()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetByVersion() throws Exception { - try { - assertNotNull(dao.getByVersion(7)); - assertNull(dao.getByVersion(-7)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} diff --git a/service/src/main/java/lcsb/mapviewer/services/impl/ConfigurationService.java b/service/src/main/java/lcsb/mapviewer/services/impl/ConfigurationService.java index c4df9fa810..0490328b47 100644 --- a/service/src/main/java/lcsb/mapviewer/services/impl/ConfigurationService.java +++ b/service/src/main/java/lcsb/mapviewer/services/impl/ConfigurationService.java @@ -1,245 +1,146 @@ -package lcsb.mapviewer.services.impl; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.transaction.annotation.Transactional; - -import lcsb.mapviewer.model.log.FrameworkVersion; -import lcsb.mapviewer.model.log.FrameworkVersionChangelogEntry; -import lcsb.mapviewer.model.user.Configuration; -import lcsb.mapviewer.model.user.ConfigurationElementType; -import lcsb.mapviewer.persist.dao.ConfigurationDao; -import lcsb.mapviewer.persist.dao.log.FrameworkVersionChangelogEntryDao; -import lcsb.mapviewer.persist.dao.log.FrameworkVersionDao; -import lcsb.mapviewer.services.interfaces.IConfigurationService; -import lcsb.mapviewer.services.view.ChangelogView; -import lcsb.mapviewer.services.view.ChangelogViewFactory; -import lcsb.mapviewer.services.view.ConfigurationView; -import lcsb.mapviewer.services.view.ConfigurationViewFactory; -import lcsb.mapviewer.services.view.FrameworkVersionView; -import lcsb.mapviewer.services.view.FrameworkVersionViewFactory; - -/** - * Service implementation used for accessing and modifing configuration - * parameters. - * - * @author Piotr Gawron - * - */ -@Transactional(value = "txManager") -public class ConfigurationService implements IConfigurationService { - - /** - * Number of bytes in a megabyte. - */ - private static final int MEGABYTE_SIZE = 1024 * 1024; - - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private final Logger logger = Logger.getLogger(ConfigurationService.class); - - /** - * Data access object for configuration parameters. - */ - @Autowired - private ConfigurationDao configurationDao; - - /** - * Data access object for {@link FrameworkVersion} objects. - */ - @Autowired - private FrameworkVersionDao frameworkVersionDao; - - /** - * Data access object for {@link FrameworkVersionChangelogEntry} objects. - */ - @Autowired - private FrameworkVersionChangelogEntryDao frameworkVersionChangelogEntryDao; - - /** - * Factory for {@link ConfigurationView} elements. - */ - @Autowired - private ConfigurationViewFactory configurationViewFactory; - - /** - * Factory for {@link FrameworkVersionView} elements. - */ - @Autowired - private FrameworkVersionViewFactory frameworkVersionViewFactory; - - /** - * Factory for {@link ChangelogView} elements. - */ - @Autowired - private ChangelogViewFactory changelogViewFactory; - - @Override - public String getConfigurationValue(ConfigurationElementType type) { - Configuration result = configurationDao.getByType(type); - if (result == null) { - result = new Configuration(); - result.setType(type); - result.setValue(type.getDefaultValue()); - configurationDao.add(result); - } - return result.getValue(); - } - - @Override - public void setConfigurationValue(ConfigurationElementType type, String value) { - Configuration configuration = configurationDao.getByType(type); - if (configuration == null) { - configuration = new Configuration(); - configuration.setType(type); - } - configuration.setValue(value); - configurationDao.add(configuration); - } - - @Override - public void deleteConfigurationValue(ConfigurationElementType type) { - configurationDao.delete(configurationDao.getByType(type)); - } - - @Override - public List<ConfigurationView> getAllValues() { - List<ConfigurationView> result = new ArrayList<ConfigurationView>(); - - for (ConfigurationElementType type : ConfigurationElementType.values()) { - Configuration configuration = configurationDao.getByType(type); - if (configuration == null) { - getConfigurationValue(type); - configuration = configurationDao.getByType(type); - } - ConfigurationView element = configurationViewFactory.create(configuration); - result.add(element); - } - return result; - } - - @Override - public void updateConfiguration(List<ConfigurationView> values) { - for (ConfigurationView configurationElement : values) { - setConfigurationValue(configurationElement.getType(), configurationElement.getValue()); - } - } - - /** - * @return the configurationDao - */ - public ConfigurationDao getConfigurationDao() { - return configurationDao; - } - - /** - * @param configurationDao - * the configurationDao to set - */ - public void setConfigurationDao(ConfigurationDao configurationDao) { - this.configurationDao = configurationDao; - } - - @Override - public String getSystemSvnVersion(String baseDir) { - return lcsb.mapviewer.common.Configuration.getSystemVersion(baseDir); - } - - @Override - public String getSystemBuild(String baseDir) { - return lcsb.mapviewer.common.Configuration.getSystemBuild(baseDir); - } - - /** - * Extracts integer representing svn version from the string that contains - * information about svn version of the file/directory. Source string can look - * like: - * <ul> - * <li>123</li> - * <li>123M</li> - * <li>123:124</li> - * <li>123:124M</li> - * </ul> - * - * @param svnString - * string that contains information about svn version of the - * file/directory - * @return integer with svn version - * @throws InvalidSvnVersionException - * thrown when the input string is invalid - */ - private Integer extractSvnVersion(String svnString) throws InvalidSvnVersionException { - String originalSvnVersion = svnString; - - if (!StringUtils.isNumeric(svnString)) { // not clean svn commit - - // first handle "123:124" - String[] tmp = svnString.split(":"); - svnString = tmp[tmp.length - 1]; - - if (!StringUtils.isNumeric(svnString)) { // now handle 123M - svnString = svnString.replaceAll("M", ""); - if (!StringUtils.isNumeric(svnString)) { - throw new InvalidSvnVersionException("Problem with parsing svn version: " + originalSvnVersion); - } - } - } - Integer version = Integer.valueOf(svnString); - return version; - } - - @Override - public FrameworkVersionView getSystemVersion(String baseDir) throws InvalidSvnVersionException { - String svnString = lcsb.mapviewer.common.Configuration.getSystemVersion(baseDir, true); - Integer version = extractSvnVersion(svnString); - FrameworkVersion fw = frameworkVersionDao.getVersionForSvnVersion(version); - FrameworkVersionView view = frameworkVersionViewFactory.create(fw); - if (fw.getSvnVersion() != version) { - view.setDevel(true); - } else { - view.setDevel(false); - } - view.setSvnVersion(svnString); - return view; - } - - @Override - public List<ChangelogView> getChangelogForFrameworkVersion(FrameworkVersionView version) throws InvalidSvnVersionException { - Integer startSvnVersion = 0; - if (version.getDevel()) { - startSvnVersion = frameworkVersionDao.getById(version.getIdObject()).getSvnVersion(); - } else { - Integer previousVersion = Integer.valueOf(version.getVersion()) - 1; - FrameworkVersion fw = frameworkVersionDao.getByVersion(previousVersion); - startSvnVersion = fw.getSvnVersion(); - } - Integer endSvnVersion = extractSvnVersion(version.getSvnVersion()); - List<FrameworkVersionChangelogEntry> list = frameworkVersionChangelogEntryDao.getChangelogBetweenSvnVersions(startSvnVersion, endSvnVersion); - List<ChangelogView> result = new ArrayList<ChangelogView>(); - for (FrameworkVersionChangelogEntry frameworkVersionChangelogEntry : list) { - result.add(changelogViewFactory.create(frameworkVersionChangelogEntry)); - } - return result; - } - - @Override - public Long getMemoryUsage() { - Runtime runtime = Runtime.getRuntime(); - - return (runtime.totalMemory() - runtime.freeMemory()) / MEGABYTE_SIZE; - } - - @Override - public Long getMaxMemory() { - Runtime runtime = Runtime.getRuntime(); - - return runtime.maxMemory() / MEGABYTE_SIZE; - } - -} +package lcsb.mapviewer.services.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import lcsb.mapviewer.common.FrameworkVersion; +import lcsb.mapviewer.model.user.Configuration; +import lcsb.mapviewer.model.user.ConfigurationElementType; +import lcsb.mapviewer.persist.dao.ConfigurationDao; +import lcsb.mapviewer.services.interfaces.IConfigurationService; +import lcsb.mapviewer.services.view.ConfigurationView; +import lcsb.mapviewer.services.view.ConfigurationViewFactory; + +/** + * Service implementation used for accessing and modifing configuration + * parameters. + * + * @author Piotr Gawron + * + */ +@Transactional(value = "txManager") +public class ConfigurationService implements IConfigurationService { + + /** + * Number of bytes in a megabyte. + */ + private static final int MEGABYTE_SIZE = 1024 * 1024; + + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private final Logger logger = Logger.getLogger(ConfigurationService.class); + + /** + * Data access object for configuration parameters. + */ + @Autowired + private ConfigurationDao configurationDao; + + /** + * Factory for {@link ConfigurationView} elements. + */ + @Autowired + private ConfigurationViewFactory configurationViewFactory; + + @Override + public String getConfigurationValue(ConfigurationElementType type) { + Configuration result = configurationDao.getByType(type); + if (result == null) { + result = new Configuration(); + result.setType(type); + result.setValue(type.getDefaultValue()); + configurationDao.add(result); + } + return result.getValue(); + } + + @Override + public void setConfigurationValue(ConfigurationElementType type, String value) { + Configuration configuration = configurationDao.getByType(type); + if (configuration == null) { + configuration = new Configuration(); + configuration.setType(type); + } + configuration.setValue(value); + configurationDao.add(configuration); + } + + @Override + public void deleteConfigurationValue(ConfigurationElementType type) { + configurationDao.delete(configurationDao.getByType(type)); + } + + @Override + public List<ConfigurationView> getAllValues() { + List<ConfigurationView> result = new ArrayList<ConfigurationView>(); + + for (ConfigurationElementType type : ConfigurationElementType.values()) { + Configuration configuration = configurationDao.getByType(type); + if (configuration == null) { + getConfigurationValue(type); + configuration = configurationDao.getByType(type); + } + ConfigurationView element = configurationViewFactory.create(configuration); + result.add(element); + } + return result; + } + + @Override + public void updateConfiguration(List<ConfigurationView> values) { + for (ConfigurationView configurationElement : values) { + setConfigurationValue(configurationElement.getType(), configurationElement.getValue()); + } + } + + /** + * @return the configurationDao + */ + public ConfigurationDao getConfigurationDao() { + return configurationDao; + } + + /** + * @param configurationDao + * the configurationDao to set + */ + public void setConfigurationDao(ConfigurationDao configurationDao) { + this.configurationDao = configurationDao; + } + + @Override + public String getSystemSvnVersion(String baseDir) { + return lcsb.mapviewer.common.Configuration.getSystemVersion(baseDir); + } + + @Override + public String getSystemBuild(String baseDir) { + return lcsb.mapviewer.common.Configuration.getSystemBuild(baseDir); + } + + @Override + public FrameworkVersion getSystemVersion(String baseDir) { + return lcsb.mapviewer.common.Configuration.getFrameworkVersion(baseDir); + } + + @Override + public Long getMemoryUsage() { + Runtime runtime = Runtime.getRuntime(); + + return (runtime.totalMemory() - runtime.freeMemory()) / MEGABYTE_SIZE; + } + + @Override + public Long getMaxMemory() { + Runtime runtime = Runtime.getRuntime(); + + return runtime.maxMemory() / MEGABYTE_SIZE; + } + +} diff --git a/service/src/main/java/lcsb/mapviewer/services/impl/InvalidSvnVersionException.java b/service/src/main/java/lcsb/mapviewer/services/impl/InvalidSvnVersionException.java deleted file mode 100644 index 6dd148d83a..0000000000 --- a/service/src/main/java/lcsb/mapviewer/services/impl/InvalidSvnVersionException.java +++ /dev/null @@ -1,26 +0,0 @@ -package lcsb.mapviewer.services.impl; - -/** - * Exception thrown when invalid svn version is encountered. - * - * @author Piotr Gawron - * - */ -public class InvalidSvnVersionException extends Exception { - - /** - * Default constructor. - * - * @param message - * error message - */ - public InvalidSvnVersionException(String message) { - super(message); - } - - /** - * - */ - private static final long serialVersionUID = 1L; - -} diff --git a/service/src/main/java/lcsb/mapviewer/services/interfaces/IConfigurationService.java b/service/src/main/java/lcsb/mapviewer/services/interfaces/IConfigurationService.java index b6ee731585..3a9ba4dae7 100644 --- a/service/src/main/java/lcsb/mapviewer/services/interfaces/IConfigurationService.java +++ b/service/src/main/java/lcsb/mapviewer/services/interfaces/IConfigurationService.java @@ -1,117 +1,104 @@ -package lcsb.mapviewer.services.interfaces; - -import java.util.List; - -import lcsb.mapviewer.model.user.ConfigurationElementType; -import lcsb.mapviewer.services.impl.InvalidSvnVersionException; -import lcsb.mapviewer.services.view.ChangelogView; -import lcsb.mapviewer.services.view.ConfigurationView; -import lcsb.mapviewer.services.view.FrameworkVersionView; - -/** - * Service used for accessing and modifing configuration parameters. - * - * @author Piotr Gawron - * - */ -public interface IConfigurationService { - - /** - * Returns value of the configuration parameter. - * - * @param type - * configuration parameter - * @return value of the configuration parameter given in type - */ - String getConfigurationValue(ConfigurationElementType type); - - /** - * Sets configuration parameter. - * - * @param type - * which configuration parameter - * @param value - * what value - */ - void setConfigurationValue(ConfigurationElementType type, String value); - - /** - * Removes configuration parameter. - * - * @param type - * which configuration parameter - */ - void deleteConfigurationValue(ConfigurationElementType type); - - /** - * Returns information about all configuration parameters with current values. - * - * @return list of all configuration parameters with current values - */ - List<ConfigurationView> getAllValues(); - - /** - * Updates configuration parameters. - * - * @param values - * new values of the parameters - */ - void updateConfiguration(List<ConfigurationView> values); - - /** - * Returns {@link lcsb.mapviewer.common.Configuration#systemVersion svn - * version} from which the system was built. - * - * @param baseDir - * directory where the system is placed - * @return svn version - */ - String getSystemSvnVersion(String baseDir); - - /** - * Returns estimated current memory usage (in MB). - * - * @return estimated current memory usage (in MB) - */ - Long getMemoryUsage(); - - /** - * Returns max memory available to JVM (in MB). - * - * @return max memory available to JVM (in MB) - */ - Long getMaxMemory(); - - /** - * Returns currently build framework version. - * - * @param baseDir - * directory where the system is placed - * @return currently build {@link FrameworkVersionView framework version} - * @throws InvalidSvnVersionException - * thrown when the svn version of the build system is invalid - */ - FrameworkVersionView getSystemVersion(String baseDir) throws InvalidSvnVersionException; - - /** - * Returns changelog entries for given framework version. - * - * @param version - * version of the framework. - * @return changelog entries for given framework version - * @throws InvalidSvnVersionException - * thrown when the version is invalid - */ - List<ChangelogView> getChangelogForFrameworkVersion(FrameworkVersionView version) throws InvalidSvnVersionException; - - /** - * Returns system {@link lcsb.mapviewer.common.Configuration#systemBuild build - * date}. - * - * @param baseDir - * directory where the system is placed - * @return system build date - */ - String getSystemBuild(String baseDir); - -} +package lcsb.mapviewer.services.interfaces; + +import java.util.List; + +import lcsb.mapviewer.common.FrameworkVersion; +import lcsb.mapviewer.model.user.ConfigurationElementType; +import lcsb.mapviewer.services.view.ConfigurationView; + +/** + * Service used for accessing and modifing configuration parameters. + * + * @author Piotr Gawron + * + */ +public interface IConfigurationService { + + /** + * Returns value of the configuration parameter. + * + * @param type + * configuration parameter + * @return value of the configuration parameter given in type + */ + String getConfigurationValue(ConfigurationElementType type); + + /** + * Sets configuration parameter. + * + * @param type + * which configuration parameter + * @param value + * what value + */ + void setConfigurationValue(ConfigurationElementType type, String value); + + /** + * Removes configuration parameter. + * + * @param type + * which configuration parameter + */ + void deleteConfigurationValue(ConfigurationElementType type); + + /** + * Returns information about all configuration parameters with current values. + * + * @return list of all configuration parameters with current values + */ + List<ConfigurationView> getAllValues(); + + /** + * Updates configuration parameters. + * + * @param values + * new values of the parameters + */ + void updateConfiguration(List<ConfigurationView> values); + + /** + * Returns {@link lcsb.mapviewer.common.Configuration#systemVersion git + * version} from which the system was built. + * + * @param baseDir + * directory where the system is placed + * @return git version + */ + String getSystemSvnVersion(String baseDir); + + /** + * Returns estimated current memory usage (in MB). + * + * @return estimated current memory usage (in MB) + */ + Long getMemoryUsage(); + + /** + * Returns max memory available to JVM (in MB). + * + * @return max memory available to JVM (in MB) + */ + Long getMaxMemory(); + + /** + * Returns currently build framework version. + * + * @param baseDir + * directory where the system is placed + * @return currently build {@link FrameworkVersion framework version} + * @throws InvalidSvnVersionException + * thrown when the git version of the build system is invalid + */ + FrameworkVersion getSystemVersion(String baseDir); + + /** + * Returns system {@link lcsb.mapviewer.common.Configuration#systemBuild build + * date}. + * + * @param baseDir + * directory where the system is placed + * @return system build date + */ + String getSystemBuild(String baseDir); + +} diff --git a/service/src/main/java/lcsb/mapviewer/services/view/ChangelogView.java b/service/src/main/java/lcsb/mapviewer/services/view/ChangelogView.java deleted file mode 100644 index c4582d5b80..0000000000 --- a/service/src/main/java/lcsb/mapviewer/services/view/ChangelogView.java +++ /dev/null @@ -1,103 +0,0 @@ -package lcsb.mapviewer.services.view; - -import java.io.Serializable; - -import lcsb.mapviewer.model.log.FrameworkVersionChangelogEntry; - -/** - * View representation of the {@link FrameworkVersionChangelogEntry}. Contains - * information about single changelog entry. - * - * @author Piotr Gawron - * - */ -public class ChangelogView extends AbstractView<FrameworkVersionChangelogEntry> implements Serializable { - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Version of svn where the changlog entry appeard. - */ - private String svnVersion; - - /** - * Description of changelog. - */ - private String description; - - /** - * Type of the change. - */ - private String type; - - - /** - * Default constructor. - * - * @param object - * {@link FrameworkVersionChangelogEntry} representing original information - */ - protected ChangelogView(FrameworkVersionChangelogEntry object) { - super(object); - } - - /** - * Default constructor. Should be used only for deserialization. - */ - protected ChangelogView() { - } - - /** - * @return the svnVersion - * @see #svnVersion - */ - public String getSvnVersion() { - return svnVersion; - } - - /** - * @param svnVersion - * the svnVersion to set - * @see #svnVersion - */ - public void setSvnVersion(String svnVersion) { - this.svnVersion = svnVersion; - } - - /** - * @return the description - * @see #description - */ - public String getDescription() { - return description; - } - - /** - * @param description - * the description to set - * @see #description - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * @return the type - * @see #type - */ - public String getType() { - return type; - } - - /** - * @param type - * the type to set - * @see #type - */ - public void setType(String type) { - this.type = type; - } - -} diff --git a/service/src/main/java/lcsb/mapviewer/services/view/ChangelogViewFactory.java b/service/src/main/java/lcsb/mapviewer/services/view/ChangelogViewFactory.java deleted file mode 100644 index ff8297ab71..0000000000 --- a/service/src/main/java/lcsb/mapviewer/services/view/ChangelogViewFactory.java +++ /dev/null @@ -1,44 +0,0 @@ -package lcsb.mapviewer.services.view; - -import org.apache.log4j.Logger; - -import com.google.gson.Gson; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.log.FrameworkVersionChangelogEntry; - -/** - * Factory class for {@link ChangelogView} class. - * - * @author Piotr Gawron - * - */ -public class ChangelogViewFactory extends AbstractViewFactory<FrameworkVersionChangelogEntry, ChangelogView> { - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(ChangelogViewFactory.class); - - @Override - public ChangelogView create(FrameworkVersionChangelogEntry object) { - ChangelogView result = new ChangelogView(object); - if (object != null) { - result.setDescription(object.getDescription()); - result.setSvnVersion(object.getSvnVersion() + ""); - result.setType(object.getType().getCommonName()); - } - return result; - } - - @Override - public String createGson(ChangelogView object) { - return new Gson().toJson(object); - } - - @Override - public FrameworkVersionChangelogEntry viewToObject(ChangelogView view) { - throw new NotImplementedException(); - } - -} diff --git a/service/src/main/java/lcsb/mapviewer/services/view/FrameworkVersionView.java b/service/src/main/java/lcsb/mapviewer/services/view/FrameworkVersionView.java deleted file mode 100644 index 76305b300f..0000000000 --- a/service/src/main/java/lcsb/mapviewer/services/view/FrameworkVersionView.java +++ /dev/null @@ -1,146 +0,0 @@ -package lcsb.mapviewer.services.view; - -import java.io.Serializable; - -import lcsb.mapviewer.model.log.FrameworkVersion; - -/** - * View representation of the {@link FrameworkVersion}. Contains information - * about single framework version. - * - * @author Piotr Gawron - * - */ -public class FrameworkVersionView extends AbstractView<FrameworkVersion> implements Serializable { - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Version of the framework. - */ - private String version; - - /** - * When this version was committed to svn. - */ - private String svnVersion; - - /** - * Description (optional). - */ - private String description; - - /** - * When the framework was built. - */ - private String time; - - /** - * Is this a devel version of framework. - */ - private Boolean devel; - - /** - * Default constructor. - * - * @param object - * {@link FrameworkVersion} representing original information - */ - protected FrameworkVersionView(FrameworkVersion object) { - super(object); - } - - /** - * Default constructor. Should be used only for deserialization. - */ - protected FrameworkVersionView() { - } - - /** - * @return the version - * @see #version - */ - public String getVersion() { - return version; - } - - /** - * @param version - * the version to set - * @see #version - */ - public void setVersion(String version) { - this.version = version; - } - - /** - * @return the svnVersion - * @see #svnVersion - */ - public String getSvnVersion() { - return svnVersion; - } - - /** - * @param svnVersion - * the svnVersion to set - * @see #svnVersion - */ - public void setSvnVersion(String svnVersion) { - this.svnVersion = svnVersion; - } - - /** - * @return the description - * @see #description - */ - public String getDescription() { - return description; - } - - /** - * @param description - * the description to set - * @see #description - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * @return the time - * @see #time - */ - public String getTime() { - return time; - } - - /** - * @param time - * the time to set - * @see #time - */ - public void setTime(String time) { - this.time = time; - } - - /** - * @return the devel - * @see #devel - */ - public Boolean getDevel() { - return devel; - } - - /** - * @param devel - * the devel to set - * @see #devel - */ - public void setDevel(Boolean devel) { - this.devel = devel; - } - -} diff --git a/service/src/main/java/lcsb/mapviewer/services/view/FrameworkVersionViewFactory.java b/service/src/main/java/lcsb/mapviewer/services/view/FrameworkVersionViewFactory.java deleted file mode 100644 index 52a20b197c..0000000000 --- a/service/src/main/java/lcsb/mapviewer/services/view/FrameworkVersionViewFactory.java +++ /dev/null @@ -1,44 +0,0 @@ -package lcsb.mapviewer.services.view; - -import java.text.SimpleDateFormat; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.log.FrameworkVersion; - -import com.google.gson.Gson; - -/** - * Factory class for {@link FrameworkVersionView} class. - * - * @author Piotr Gawron - * - */ -public class FrameworkVersionViewFactory extends AbstractViewFactory<FrameworkVersion, FrameworkVersionView> { - /** - * Date formatter. - */ - private final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd"); - - @Override - public FrameworkVersionView create(FrameworkVersion object) { - FrameworkVersionView view = new FrameworkVersionView(object); - if (object != null) { - view.setDescription(object.getDescription()); - view.setSvnVersion(object.getSvnVersion() + ""); - view.setTime(dateFormatter.format(object.getTime().getTime())); - view.setVersion(object.getVersion() + ""); - } - return view; - } - - @Override - public String createGson(FrameworkVersionView object) { - return new Gson().toJson(object); - } - - @Override - public FrameworkVersion viewToObject(FrameworkVersionView view) { - throw new NotImplementedException(); - } - -} diff --git a/service/src/main/resources/applicationContext-service.xml b/service/src/main/resources/applicationContext-service.xml index 70a4259eee..1094ff0b42 100644 --- a/service/src/main/resources/applicationContext-service.xml +++ b/service/src/main/resources/applicationContext-service.xml @@ -1,78 +1,76 @@ -<beans - xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:tx="http://www.springframework.org/schema/tx" - xmlns:context="http://www.springframework.org/schema/context" - xsi:schemaLocation="http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans-4.0.xsd - http://www.springframework.org/schema/tx - http://www.springframework.org/schema/tx/spring-tx-4.0.xsd - http://www.springframework.org/schema/context - http://www.springframework.org/schema/context/spring-context.xsd"> - - - <bean id="CommentService" class="lcsb.mapviewer.services.impl.CommentService"/> - - <bean id="ConfigurationService" class="lcsb.mapviewer.services.impl.ConfigurationService"/> - - <bean id="ChemicalService" class="lcsb.mapviewer.services.search.db.chemical.ChemicalService"/> - - <bean id="DrugService" class="lcsb.mapviewer.services.search.db.drug.DrugService"/> - - <bean id="ExporterService" class="lcsb.mapviewer.services.impl.ExporterService"/> - - <bean id="ExternalServicesService" class="lcsb.mapviewer.services.impl.ExternalServicesService"/> - - <bean id="LayoutService" class="lcsb.mapviewer.services.impl.LayoutService"/> - - <bean id="LogService" class="lcsb.mapviewer.services.impl.LogService"/> - - <bean id="DataMiningService" class="lcsb.mapviewer.services.impl.DataMiningService"/> - - <bean id="MiriamService" class="lcsb.mapviewer.services.impl.MiriamService"/> - - <bean id="MiRNAService" class="lcsb.mapviewer.services.search.db.mirna.MiRNAService"/> - - <bean id="ModelService" class="lcsb.mapviewer.services.impl.ModelService"/> - - <bean id="ProjectService" class="lcsb.mapviewer.services.impl.ProjectService"/> - - <bean id="ReferenceGenomeService" class="lcsb.mapviewer.services.impl.ReferenceGenomeService"/> - - <bean id="SearchHistoryService" class="lcsb.mapviewer.services.impl.SearchHistoryService"/> - - <bean id="SearchService" class="lcsb.mapviewer.services.impl.SearchService"/> - - <bean id="UserService" class="lcsb.mapviewer.services.impl.UserService"/> - - <!-- Encoder used for hashing passwords --> - <bean id="PasswordEncoder" class="lcsb.mapviewer.services.impl.Md5PasswordEncoder"/> - - <!-- View factories --> - <bean id="AnnotationViewFactory" class="lcsb.mapviewer.services.view.AnnotationViewFactory"/> - <bean id="ChangelogViewFactory" class="lcsb.mapviewer.services.view.ChangelogViewFactory"/> - <bean id="CommentViewFactory" class="lcsb.mapviewer.services.view.CommentViewFactory"/> - <bean id="ConfigurationViewFactory" class="lcsb.mapviewer.services.view.ConfigurationViewFactory"/> - <bean id="DataMiningViewFactory" class="lcsb.mapviewer.services.view.DataMiningViewFactory"/> - <bean id="FrameworkVersionViewFactory" class="lcsb.mapviewer.services.view.FrameworkVersionViewFactory"/> - <bean id="LayoutViewFactory" class="lcsb.mapviewer.services.view.LayoutViewFactory"/> - <bean id="ModelViewFactory" class="lcsb.mapviewer.services.view.ModelViewFactory"/> - <bean id="OverviewImageViewFactory" class="lcsb.mapviewer.services.view.OverviewImageViewFactory"/> - <bean id="OverviewLinkViewFactory" class="lcsb.mapviewer.services.view.OverviewLinkViewFactory"/> - <bean id="PrivilegeViewFactory" class="lcsb.mapviewer.services.view.PrivilegeViewFactory"/> - <bean id="ProjectViewFactory" class="lcsb.mapviewer.services.view.ProjectViewFactory"/> - <bean id="PubmedAnnotatedElementsViewFactory" class="lcsb.mapviewer.services.view.PubmedAnnotatedElementsViewFactory"/> - <bean id="ReferenceGenomeViewFactory" class="lcsb.mapviewer.services.view.ReferenceGenomeViewFactory"/> - <bean id="ReferenceGenomeGeneMappingViewFactory" class="lcsb.mapviewer.services.view.ReferenceGenomeGeneMappingViewFactory"/> - <bean id="UserViewFactory" class="lcsb.mapviewer.services.view.UserViewFactory"/> - - <bean id="FullAliasViewFactory" class="lcsb.mapviewer.services.search.data.FullAliasViewFactory"/> - <bean id="FullReactionViewFactory" class="lcsb.mapviewer.services.search.data.FullReactionViewFactory"/> - <bean id="LightAliasViewFactory" class="lcsb.mapviewer.services.search.data.LightAliasViewFactory"/> - - <bean id="ChemicalViewFactory" class="lcsb.mapviewer.services.search.db.chemical.ChemicalViewFactory"/> - <bean id="DrugViewFactory" class="lcsb.mapviewer.services.search.db.drug.DrugViewFactory"/> - <bean id="MiRNAViewFactory" class="lcsb.mapviewer.services.search.db.mirna.MiRNAViewFactory"/> - <bean id="TargetViewFactory" class="lcsb.mapviewer.services.search.db.TargetViewFactory"/> - +<beans + xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:tx="http://www.springframework.org/schema/tx" + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation="http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans-4.0.xsd + http://www.springframework.org/schema/tx + http://www.springframework.org/schema/tx/spring-tx-4.0.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context.xsd"> + + + <bean id="CommentService" class="lcsb.mapviewer.services.impl.CommentService"/> + + <bean id="ConfigurationService" class="lcsb.mapviewer.services.impl.ConfigurationService"/> + + <bean id="ChemicalService" class="lcsb.mapviewer.services.search.db.chemical.ChemicalService"/> + + <bean id="DrugService" class="lcsb.mapviewer.services.search.db.drug.DrugService"/> + + <bean id="ExporterService" class="lcsb.mapviewer.services.impl.ExporterService"/> + + <bean id="ExternalServicesService" class="lcsb.mapviewer.services.impl.ExternalServicesService"/> + + <bean id="LayoutService" class="lcsb.mapviewer.services.impl.LayoutService"/> + + <bean id="LogService" class="lcsb.mapviewer.services.impl.LogService"/> + + <bean id="DataMiningService" class="lcsb.mapviewer.services.impl.DataMiningService"/> + + <bean id="MiriamService" class="lcsb.mapviewer.services.impl.MiriamService"/> + + <bean id="MiRNAService" class="lcsb.mapviewer.services.search.db.mirna.MiRNAService"/> + + <bean id="ModelService" class="lcsb.mapviewer.services.impl.ModelService"/> + + <bean id="ProjectService" class="lcsb.mapviewer.services.impl.ProjectService"/> + + <bean id="ReferenceGenomeService" class="lcsb.mapviewer.services.impl.ReferenceGenomeService"/> + + <bean id="SearchHistoryService" class="lcsb.mapviewer.services.impl.SearchHistoryService"/> + + <bean id="SearchService" class="lcsb.mapviewer.services.impl.SearchService"/> + + <bean id="UserService" class="lcsb.mapviewer.services.impl.UserService"/> + + <!-- Encoder used for hashing passwords --> + <bean id="PasswordEncoder" class="lcsb.mapviewer.services.impl.Md5PasswordEncoder"/> + + <!-- View factories --> + <bean id="AnnotationViewFactory" class="lcsb.mapviewer.services.view.AnnotationViewFactory"/> + <bean id="CommentViewFactory" class="lcsb.mapviewer.services.view.CommentViewFactory"/> + <bean id="ConfigurationViewFactory" class="lcsb.mapviewer.services.view.ConfigurationViewFactory"/> + <bean id="DataMiningViewFactory" class="lcsb.mapviewer.services.view.DataMiningViewFactory"/> + <bean id="LayoutViewFactory" class="lcsb.mapviewer.services.view.LayoutViewFactory"/> + <bean id="ModelViewFactory" class="lcsb.mapviewer.services.view.ModelViewFactory"/> + <bean id="OverviewImageViewFactory" class="lcsb.mapviewer.services.view.OverviewImageViewFactory"/> + <bean id="OverviewLinkViewFactory" class="lcsb.mapviewer.services.view.OverviewLinkViewFactory"/> + <bean id="PrivilegeViewFactory" class="lcsb.mapviewer.services.view.PrivilegeViewFactory"/> + <bean id="ProjectViewFactory" class="lcsb.mapviewer.services.view.ProjectViewFactory"/> + <bean id="PubmedAnnotatedElementsViewFactory" class="lcsb.mapviewer.services.view.PubmedAnnotatedElementsViewFactory"/> + <bean id="ReferenceGenomeViewFactory" class="lcsb.mapviewer.services.view.ReferenceGenomeViewFactory"/> + <bean id="ReferenceGenomeGeneMappingViewFactory" class="lcsb.mapviewer.services.view.ReferenceGenomeGeneMappingViewFactory"/> + <bean id="UserViewFactory" class="lcsb.mapviewer.services.view.UserViewFactory"/> + + <bean id="FullAliasViewFactory" class="lcsb.mapviewer.services.search.data.FullAliasViewFactory"/> + <bean id="FullReactionViewFactory" class="lcsb.mapviewer.services.search.data.FullReactionViewFactory"/> + <bean id="LightAliasViewFactory" class="lcsb.mapviewer.services.search.data.LightAliasViewFactory"/> + + <bean id="ChemicalViewFactory" class="lcsb.mapviewer.services.search.db.chemical.ChemicalViewFactory"/> + <bean id="DrugViewFactory" class="lcsb.mapviewer.services.search.db.drug.DrugViewFactory"/> + <bean id="MiRNAViewFactory" class="lcsb.mapviewer.services.search.db.mirna.MiRNAViewFactory"/> + <bean id="TargetViewFactory" class="lcsb.mapviewer.services.search.db.TargetViewFactory"/> + </beans> \ No newline at end of file diff --git a/service/src/test/java/lcsb/mapviewer/services/impl/ConfigurationServiceTest.java b/service/src/test/java/lcsb/mapviewer/services/impl/ConfigurationServiceTest.java index fa9d4ba376..0dc9a70203 100644 --- a/service/src/test/java/lcsb/mapviewer/services/impl/ConfigurationServiceTest.java +++ b/service/src/test/java/lcsb/mapviewer/services/impl/ConfigurationServiceTest.java @@ -1,161 +1,131 @@ -package lcsb.mapviewer.services.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.apache.log4j.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.test.annotation.Rollback; - -import lcsb.mapviewer.common.Configuration; -import lcsb.mapviewer.model.user.ConfigurationElementType; -import lcsb.mapviewer.services.ServiceTestFunctions; -import lcsb.mapviewer.services.view.ChangelogView; -import lcsb.mapviewer.services.view.ConfigurationView; -import lcsb.mapviewer.services.view.FrameworkVersionView; - -@Rollback(true) -public class ConfigurationServiceTest extends ServiceTestFunctions { - Logger logger = Logger.getLogger(ConfigurationServiceTest.class); - - @Before - public void setUp() throws Exception { - // clear information about svn version - Configuration.getSystemVersion(null, true); - } - - @After - public void tearDown() throws Exception { - // clear information about svn version - Configuration.getSystemVersion(null, true); - } - - @Test - public void testGetUpdate() throws Exception { - try { - String address = configurationService.getConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS); - configurationService.deleteConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS); - String newAddress = configurationService.getConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS); - assertEquals(ConfigurationElementType.EMAIL_ADDRESS.getDefaultValue(), newAddress); - configurationService.setConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS, "hello@world"); - newAddress = configurationService.getConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS); - assertEquals("hello@world", newAddress); - - configurationService.setConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS, address); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testList() throws Exception { - try { - List<ConfigurationView> list = configurationService.getAllValues(); - assertEquals(ConfigurationElementType.values().length, list.size()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetSystemVersion() throws Exception { - try { - FrameworkVersionView view = configurationService.getSystemVersion("testFiles/svnVersionTest/testNormal/"); - assertNotNull(view); - assertEquals("2", view.getVersion()); - assertTrue(view.getDevel()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetSystemVersion2() throws Exception { - try { - FrameworkVersionView view = configurationService.getSystemVersion("testFiles/svnVersionTest/testModified/"); - assertNotNull(view); - assertEquals("2", view.getVersion()); - assertTrue(view.getDevel()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetSystemVersion3() throws Exception { - try { - FrameworkVersionView view = configurationService.getSystemVersion("testFiles/svnVersionTest/testCorrectSvn/"); - assertNotNull(view); - assertEquals("3", view.getVersion()); - assertFalse(view.getDevel()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetChangelogForFrameworkVersion() throws Exception { - try { - FrameworkVersionView view = configurationService.getSystemVersion("testFiles/svnVersionTest/testModified/"); - List<ChangelogView> list = configurationService.getChangelogForFrameworkVersion(view); - assertNotNull(list); - assertEquals(2, list.size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetChangelogForFrameworkVersionForFullVersion() throws Exception { - try { - FrameworkVersionView view = configurationService.getSystemVersion("testFiles/svnVersionTest/testCorrectSvn/"); - List<ChangelogView> list = configurationService.getChangelogForFrameworkVersion(view); - assertNotNull(list); - assertEquals(5, list.size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetMemoryUsage() throws Exception { - try { - Long size = configurationService.getMemoryUsage(); - Long maxMem = configurationService.getMaxMemory(); - int len = 10000000; - int t[]; - Integer x = (int) (Math.random() * 1000); - t = new int[len + x]; - for (int i = 0; i < len; i++) { - t[i] = (int) Math.random() * 1000 + x; - x += t[i]; - } - Long size2 = configurationService.getMemoryUsage(); - Long maxMem2 = configurationService.getMaxMemory(); - - assertNotNull(x); - assertEquals(maxMem, maxMem2); - assertTrue(size2 >= size); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } -} +package lcsb.mapviewer.services.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.apache.log4j.Logger; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.test.annotation.Rollback; + +import lcsb.mapviewer.common.Configuration; +import lcsb.mapviewer.common.FrameworkVersion; +import lcsb.mapviewer.model.user.ConfigurationElementType; +import lcsb.mapviewer.services.ServiceTestFunctions; +import lcsb.mapviewer.services.view.ConfigurationView; + +@Rollback(true) +public class ConfigurationServiceTest extends ServiceTestFunctions { + Logger logger = Logger.getLogger(ConfigurationServiceTest.class); + + @Before + public void setUp() throws Exception { + // clear information about git version + Configuration.getSystemBuildVersion(null, true); + } + + @After + public void tearDown() throws Exception { + // clear information about git version + Configuration.getSystemBuildVersion(null, true); + } + + @Test + public void testGetUpdate() throws Exception { + try { + String address = configurationService.getConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS); + configurationService.deleteConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS); + String newAddress = configurationService.getConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS); + assertEquals(ConfigurationElementType.EMAIL_ADDRESS.getDefaultValue(), newAddress); + configurationService.setConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS, "hello@world"); + newAddress = configurationService.getConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS); + assertEquals("hello@world", newAddress); + + configurationService.setConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS, address); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testList() throws Exception { + try { + List<ConfigurationView> list = configurationService.getAllValues(); + assertEquals(ConfigurationElementType.values().length, list.size()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetSystemVersion() throws Exception { + try { + FrameworkVersion view = configurationService.getSystemVersion("testFiles/gitVersionTest/testNormal/"); + assertNotNull(view); + assertEquals("100", view.getGitVersion()); + assertEquals("202", view.getVersion()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetSystemVersion2() throws Exception { + try { + FrameworkVersion view = configurationService.getSystemVersion("testFiles/gitVersionTest/testModified/"); + assertNotNull(view); + assertEquals("100:105", view.getGitVersion()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetSystemVersion3() throws Exception { + try { + FrameworkVersion view = configurationService.getSystemVersion("testFiles/gitVersionTest/testCorrectSvn/"); + assertNotNull(view); + assertEquals("117", view.getGitVersion()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetMemoryUsage() throws Exception { + try { + Long size = configurationService.getMemoryUsage(); + Long maxMem = configurationService.getMaxMemory(); + int len = 10000000; + int t[]; + Integer x = (int) (Math.random() * 1000); + t = new int[len + x]; + for (int i = 0; i < len; i++) { + t[i] = (int) Math.random() * 1000 + x; + x += t[i]; + } + Long size2 = configurationService.getMemoryUsage(); + Long maxMem2 = configurationService.getMaxMemory(); + + assertNotNull(x); + assertEquals(maxMem, maxMem2); + assertTrue(size2 >= size); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } +} diff --git a/service/src/test/java/lcsb/mapviewer/services/view/AllViewTests.java b/service/src/test/java/lcsb/mapviewer/services/view/AllViewTests.java index 845c40e3cb..ed4fc8b5b6 100644 --- a/service/src/test/java/lcsb/mapviewer/services/view/AllViewTests.java +++ b/service/src/test/java/lcsb/mapviewer/services/view/AllViewTests.java @@ -1,41 +1,40 @@ -package lcsb.mapviewer.services.view; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -import lcsb.mapviewer.services.search.db.drug.DrugViewTest; - -@RunWith(Suite.class) -@SuiteClasses({ AnnotationViewFactoryTest.class, // - AnnotationViewTest.class, // - ChangelogViewTest.class, // - CommentViewFactoryTest.class, // - CommentViewTest.class, // - ConfigurationViewFactoryTest.class, // - ConfigurationViewTest.class, // - DataMiningSetViewTest.class, // - DataMiningViewFactoryTest.class, // - DataMiningViewTest.class, // - DrugViewTest.class, // - FrameworkVersionViewTest.class, // - LayoutViewFactoryTest.class, // - LayoutViewTest.class, // - ModelViewFactoryTest.class, // - ModelViewTest.class, // - OverviewImageViewFactoryTest.class, // - OverviewImageViewTest.class, // - OverviewLinkViewFactoryTest.class, // - OverviewLinkViewTest.class, // - PrivilegeViewFactoryTest.class, // - PrivilegeViewTest.class, // - ProjectViewFactoryTest.class, // - ProjectViewTest.class, // - ReferenceGenomeViewFactoryTest.class, // - ReferenceGenomeGeneMappingViewFactoryTest.class, // - UserViewFactoryTest.class, // - UserViewTest.class, // -}) -public class AllViewTests { - -} +package lcsb.mapviewer.services.view; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +import lcsb.mapviewer.services.search.db.drug.DrugViewTest; + +@RunWith(Suite.class) +@SuiteClasses({ AnnotationViewFactoryTest.class, // + AnnotationViewTest.class, // + CommentViewFactoryTest.class, // + CommentViewTest.class, // + ConfigurationViewFactoryTest.class, // + ConfigurationViewTest.class, // + DataMiningSetViewTest.class, // + DataMiningViewFactoryTest.class, // + DataMiningViewTest.class, // + DrugViewTest.class, // + FrameworkVersionViewTest.class, // + LayoutViewFactoryTest.class, // + LayoutViewTest.class, // + ModelViewFactoryTest.class, // + ModelViewTest.class, // + OverviewImageViewFactoryTest.class, // + OverviewImageViewTest.class, // + OverviewLinkViewFactoryTest.class, // + OverviewLinkViewTest.class, // + PrivilegeViewFactoryTest.class, // + PrivilegeViewTest.class, // + ProjectViewFactoryTest.class, // + ProjectViewTest.class, // + ReferenceGenomeViewFactoryTest.class, // + ReferenceGenomeGeneMappingViewFactoryTest.class, // + UserViewFactoryTest.class, // + UserViewTest.class, // +}) +public class AllViewTests { + +} diff --git a/service/src/test/java/lcsb/mapviewer/services/view/ChangelogViewTest.java b/service/src/test/java/lcsb/mapviewer/services/view/ChangelogViewTest.java deleted file mode 100644 index 87fe58496f..0000000000 --- a/service/src/test/java/lcsb/mapviewer/services/view/ChangelogViewTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package lcsb.mapviewer.services.view; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class ChangelogViewTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new ChangelogView()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } -} diff --git a/service/src/test/java/lcsb/mapviewer/services/view/FrameworkVersionViewTest.java b/service/src/test/java/lcsb/mapviewer/services/view/FrameworkVersionViewTest.java index 6c102fd62d..9def2c948b 100644 --- a/service/src/test/java/lcsb/mapviewer/services/view/FrameworkVersionViewTest.java +++ b/service/src/test/java/lcsb/mapviewer/services/view/FrameworkVersionViewTest.java @@ -1,27 +1,29 @@ -package lcsb.mapviewer.services.view; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class FrameworkVersionViewTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new FrameworkVersionView()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } -} +package lcsb.mapviewer.services.view; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.FrameworkVersion; + +public class FrameworkVersionViewTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new FrameworkVersion()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } +} diff --git a/service/testFiles/svnVersionTest/testCorrectSvn/svnversion.txt b/service/testFiles/gitVersionTest/testCorrectSvn/version.txt similarity index 100% rename from service/testFiles/svnVersionTest/testCorrectSvn/svnversion.txt rename to service/testFiles/gitVersionTest/testCorrectSvn/version.txt diff --git a/service/testFiles/svnVersionTest/testModified/svnversion.txt b/service/testFiles/gitVersionTest/testModified/version.txt similarity index 100% rename from service/testFiles/svnVersionTest/testModified/svnversion.txt rename to service/testFiles/gitVersionTest/testModified/version.txt diff --git a/service/testFiles/gitVersionTest/testNormal/CHANGELOG b/service/testFiles/gitVersionTest/testNormal/CHANGELOG new file mode 100644 index 0000000000..f86f534f90 --- /dev/null +++ b/service/testFiles/gitVersionTest/testNormal/CHANGELOG @@ -0,0 +1,6 @@ +minerva (202) stable; urgency=medium + + * Initial release + + -- Piotr Gawron <piotr.gawron@uni.lu> Wed, 4 Dec 2013 22:00:00 +0200 + \ No newline at end of file diff --git a/service/testFiles/svnVersionTest/testNormal/svnversion.txt b/service/testFiles/gitVersionTest/testNormal/version.txt similarity index 100% rename from service/testFiles/svnVersionTest/testNormal/svnversion.txt rename to service/testFiles/gitVersionTest/testNormal/version.txt diff --git a/web/.settings/org.eclipse.wst.common.component b/web/.settings/org.eclipse.wst.common.component index 9977752238..6ef850217d 100644 --- a/web/.settings/org.eclipse.wst.common.component +++ b/web/.settings/org.eclipse.wst.common.component @@ -1,43 +1,43 @@ -<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> - <wb-module deploy-name="MapViewer-web"> - <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/> - <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> - <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> - <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> - <dependent-module archiveName="service-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-service/MapViewer-service"> - <dependency-type>uses</dependency-type> - </dependent-module> - <dependent-module archiveName="model-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-model/MapViewer-model"> - <dependency-type>uses</dependency-type> - </dependent-module> - <dependent-module archiveName="commons-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-commons/MapViewer-commons"> - <dependency-type>uses</dependency-type> - </dependent-module> - <dependent-module archiveName="persist-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-persist/MapViewer-persist"> - <dependency-type>uses</dependency-type> - </dependent-module> - <dependent-module archiveName="model-command-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-model-command/MapViewer-model-command"> - <dependency-type>uses</dependency-type> - </dependent-module> - <dependent-module archiveName="annotation-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-annotation/MapViewer-annotation"> - <dependency-type>uses</dependency-type> - </dependent-module> - <dependent-module archiveName="converter-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-converter/MapViewer-converter"> - <dependency-type>uses</dependency-type> - </dependent-module> - <dependent-module archiveName="converter-CellDesigner-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-converter-CellDesigner/MapViewer-converter-CellDesigner"> - <dependency-type>uses</dependency-type> - </dependent-module> - <dependent-module archiveName="converter-SBGNML-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-converter-SBGNML/MapViewer-converter-SBGNML"> - <dependency-type>uses</dependency-type> - </dependent-module> - <dependent-module archiveName="converter-graphics-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-converter-graphics/MapViewer-converter-graphics"> - <dependency-type>uses</dependency-type> - </dependent-module> - <dependent-module archiveName="rest-api-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-rest-api/MapViewer-rest-api"> - <dependency-type>uses</dependency-type> - </dependent-module> - <property name="java-output-path" value="/MapViewer-web/target/classes"/> - <property name="context-root" value="MapViewer-web"/> - </wb-module> -</project-modules> +<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> + <wb-module deploy-name="MapViewer-web"> + <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/> + <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> + <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> + <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> + <dependent-module archiveName="service-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-service/MapViewer-service"> + <dependency-type>uses</dependency-type> + </dependent-module> + <dependent-module archiveName="model-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-model/MapViewer-model"> + <dependency-type>uses</dependency-type> + </dependent-module> + <dependent-module archiveName="commons-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-commons/MapViewer-commons"> + <dependency-type>uses</dependency-type> + </dependent-module> + <dependent-module archiveName="persist-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-persist/MapViewer-persist"> + <dependency-type>uses</dependency-type> + </dependent-module> + <dependent-module archiveName="model-command-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-model-command/MapViewer-model-command"> + <dependency-type>uses</dependency-type> + </dependent-module> + <dependent-module archiveName="annotation-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-annotation/MapViewer-annotation"> + <dependency-type>uses</dependency-type> + </dependent-module> + <dependent-module archiveName="converter-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-converter/MapViewer-converter"> + <dependency-type>uses</dependency-type> + </dependent-module> + <dependent-module archiveName="converter-CellDesigner-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-converter-CellDesigner/MapViewer-converter-CellDesigner"> + <dependency-type>uses</dependency-type> + </dependent-module> + <dependent-module archiveName="converter-SBGNML-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-converter-SBGNML/MapViewer-converter-SBGNML"> + <dependency-type>uses</dependency-type> + </dependent-module> + <dependent-module archiveName="converter-graphics-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-converter-graphics/MapViewer-converter-graphics"> + <dependency-type>uses</dependency-type> + </dependent-module> + <dependent-module archiveName="rest-api-1.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/MapViewer-rest-api/MapViewer-rest-api"> + <dependency-type>uses</dependency-type> + </dependent-module> + <property name="java-output-path" value="/MapViewer-web/target/classes"/> + <property name="context-root" value="MapViewer-web"/> + </wb-module> +</project-modules> diff --git a/web/src/main/java/lcsb/mapviewer/bean/ConfigurationBean.java b/web/src/main/java/lcsb/mapviewer/bean/ConfigurationBean.java index 35633a8756..e4bcd60cfe 100644 --- a/web/src/main/java/lcsb/mapviewer/bean/ConfigurationBean.java +++ b/web/src/main/java/lcsb/mapviewer/bean/ConfigurationBean.java @@ -1,527 +1,474 @@ -package lcsb.mapviewer.bean; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyVetoException; -import java.beans.VetoableChangeListener; -import java.io.Serializable; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.faces.bean.ManagedBean; -import javax.faces.bean.ManagedProperty; -import javax.faces.bean.ViewScoped; -import javax.faces.event.ActionEvent; - -import org.apache.commons.validator.routines.UrlValidator; -import org.apache.log4j.Logger; - -import lcsb.mapviewer.common.Configuration; -import lcsb.mapviewer.model.user.ConfigurationElementType; -import lcsb.mapviewer.model.user.PrivilegeType; -import lcsb.mapviewer.model.user.User; -import lcsb.mapviewer.services.impl.InvalidSvnVersionException; -import lcsb.mapviewer.services.interfaces.IConfigurationService; -import lcsb.mapviewer.services.interfaces.IProjectService; -import lcsb.mapviewer.services.interfaces.IUserService; -import lcsb.mapviewer.services.view.ChangelogView; -import lcsb.mapviewer.services.view.ConfigurationView; -import lcsb.mapviewer.services.view.FrameworkVersionView; - -/** - * Bean used for managing configuration (configurable parameters of the system). - * - * @author Piotr Gawron - * - */ -@ManagedBean(name = "configurationMB") -@ViewScoped -public class ConfigurationBean extends AbstractManagedBean implements Serializable { - - /** - * String representing {@link ConfigurationElementType#DEFAULT_MAP} system - * property used by {@link #firePropertyChange(String, Object, Object)}. - */ - public static final String DEFAULT_MODEL_PROPERTY = "DEFAULT_MODEL"; - - /** - * String representing {@link ConfigurationElementType#X_FRAME_DOMAIN} system - * property used by {@link #firePropertyChange(String, Object, Object)}. - */ - public static final String X_FRAME_PROPERTY = "X_FRAME"; - - /** - * String representing {@link #logoImg} property used by - * {@link #firePropertyChange(String, Object, Object)}. - */ - public static final String LOGO_IMG_PROPERTY = "LOGO_IMG"; - - /** - * String representing {@link #logoLink} property used by - * {@link #firePropertyChange(String, Object, Object)}. - */ - public static final String LOGO_LINK_PROPERTY = "LOGO_LINK"; - - /** - * String representing {@link #logoText} property used by - * {@link #firePropertyChange(String, Object, Object)}. - */ - public static final String LOGO_TEXT_PROPERTY = "LOGO_TEXT"; - - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(ConfigurationBean.class); - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * List of values for all possible configurable parameters. - */ - private List<ConfigurationView> values = new ArrayList<ConfigurationView>(); - - /** - * Release version of the framework. - */ - private FrameworkVersionView version; - - /** - * List of {@link ChangelogView changlog} entries for the current version of - * the framework. - */ - private List<ChangelogView> changelogs = new ArrayList<ChangelogView>(); - - /** - * When the system was built. - */ - private String buildDate; - - /** - * When the system was built. - */ - private Map<ConfigurationElementType, String> valueMap = new HashMap<>(); - - /** - * Bean used for communication with the client side about the data related to - * users (including information about currently logged user). - * - * @see UserBean - */ - @ManagedProperty(value = "#{userMB}") - private transient UserBean userBean; - - /** - * Service used to access configuration parameters. - * - * @see IConfigurationService - */ - @ManagedProperty(value = "#{ConfigurationService}") - private transient IConfigurationService configurationService; - - /** - * Service used to access information about users. - * - * @see IUserService - */ - @ManagedProperty(value = "#{UserService}") - private transient IUserService userService; - - /** - * Service used to access information about projects. - * - * @see IProjectService - */ - @ManagedProperty(value = "#{ProjectService}") - private transient IProjectService projectService; - - @Override - public final void init() { - // listener that checks if the new default map exists in the system - VetoableChangeListener selectedMapVetoChanged = new VetoableChangeListener() { - @Override - public void vetoableChange(final PropertyChangeEvent arg0) throws PropertyVetoException { - if ((DEFAULT_MODEL_PROPERTY).equals(arg0.getPropertyName())) { - if (!projectService.projectExists((String) arg0.getNewValue())) { - throw new PropertyVetoException("Project " + arg0.getNewValue() + " doesn't exist", arg0); - } - } - } - }; - addVetoablePropertyChangeListener(selectedMapVetoChanged); - - PropertyChangeListener xFrameChanged = new PropertyChangeListener() { - - @Override - public void propertyChange(PropertyChangeEvent arg0) { - if ((X_FRAME_PROPERTY).equals(arg0.getPropertyName())) { - Configuration.setxFrameDomain((String) arg0.getNewValue()); - } - } - }; - addPropertyChangeListener(xFrameChanged); - - // listener that checks if the new x-fram address is valid - VetoableChangeListener xFrameVetoChanged = new VetoableChangeListener() { - @Override - public void vetoableChange(final PropertyChangeEvent arg0) throws PropertyVetoException { - if ((X_FRAME_PROPERTY).equals(arg0.getPropertyName())) { - String domain = (String) arg0.getNewValue(); - if (!new UrlValidator().isValid(domain) && !(domain != null && domain.contains("localhost"))) { - throw new PropertyVetoException("Invalid address: " + domain, arg0); - } - } - } - }; - addVetoablePropertyChangeListener(xFrameVetoChanged); - - try { - version = configurationService.getSystemVersion(getProjectDeployPath()); - changelogs = configurationService.getChangelogForFrameworkVersion(version); - } catch (InvalidSvnVersionException e) { - logger.error(e, e); - } - buildDate = configurationService.getSystemBuild(getProjectDeployPath()); - - refreshValues(null); - - Configuration.setWebAppDir(getPrimefacesUtils().getPath() + "../"); - } - - /** - * Refresh values from the database. - * - * @param actionEvent - * event from thefrom the client - */ - public final void refreshValues(final ActionEvent actionEvent) { - values = configurationService.getAllValues(); - for (ConfigurationView view : values) { - valueMap.put(view.getType(), view.getValue()); - } - } - - /** - * Save values to the database. - * - * @param actionEvent - * event from thefrom the client - */ - public final void saveValues(final ActionEvent actionEvent) { - // first check if we have privileges - if (getUserHasConfigurationView()) { - setValues(values); - configurationService.updateConfiguration(values); - values = configurationService.getAllValues(); - } - } - - /** - * Checks if logged user can manage the configuration of the system. - * - * @return <code>true</code> if logged user can manage the configuration, - * <code>false</code> otherwise - */ - public final boolean getUserHasConfigurationView() { - User user = userBean.getLoggedUser(); - boolean result = userService.userHasPrivilege(user, PrivilegeType.CONFIGURATION_MANAGE); - return result; - } - - /** - * - * @return list of all configuration values - * @see #values - */ - public final List<ConfigurationView> getValues() { - if (getUserHasConfigurationView()) { - return values; - } else { - return new ArrayList<>(); - } - } - - /** - * Sets the new list of configurable parameters. - * - * @param values - * list of configurable parameters with new values - */ - public final void setValues(final List<ConfigurationView> values) { - // when we set new values we should: - // 1) check if they are correct (vchs listeners) - // 2) notify apropriate listeners - - // for the naming convention of parameters take a look at {@link #vchs} - - // remember the old values from the system (!! not from the bean !!) - List<ConfigurationView> old = configurationService.getAllValues(); - this.values = values; - for (ConfigurationView el : values) { - String newVal = el.getValue(); - String oldVal = null; - for (ConfigurationView oldEl : old) { - if (oldEl.getType().equals(el.getType())) { - oldVal = oldEl.getValue(); - } - } - try { - if (el.getType().equals(ConfigurationElementType.DEFAULT_MAP)) { - fireVetoableChange(DEFAULT_MODEL_PROPERTY, oldVal, newVal); - } - } catch (PropertyVetoException e) { // if there was a veto then rollback - // to system parameters - this.values = old; - logger.debug("Rollback because parameter " + el.getType().name() + " contains inproper value: " + newVal); - sendError(e.getMessage()); - return; - } - } - for (ConfigurationView el : values) { - String newVal = el.getValue(); - String oldVal = null; - for (ConfigurationView oldEl : old) { - if (oldEl.getType().equals(el.getType())) { - oldVal = oldEl.getValue(); - } - } - if (el.getType().equals(ConfigurationElementType.DEFAULT_MAP)) { - firePropertyChange(DEFAULT_MODEL_PROPERTY, oldVal, newVal); - } else if (el.getType().equals(ConfigurationElementType.X_FRAME_DOMAIN)) { - firePropertyChange(X_FRAME_PROPERTY, oldVal, newVal); - } - - } - } - - @Override - public void clear() { - setValues(new ArrayList<ConfigurationView>()); - } - - /** - * @return the userBean - * @see #userBean - */ - public UserBean getUserBean() { - return userBean; - } - - /** - * @param userBean - * the userBean to set - * @see #userBean - */ - public void setUserBean(UserBean userBean) { - this.userBean = userBean; - } - - /** - * @return the configurationService - * @see #configurationService - */ - public IConfigurationService getConfigurationService() { - return configurationService; - } - - /** - * @param configurationService - * the configurationService to set - * @see #configurationService - */ - public void setConfigurationService(IConfigurationService configurationService) { - this.configurationService = configurationService; - } - - /** - * @return the userService - * @see #userService - */ - public IUserService getUserService() { - return userService; - } - - /** - * @param userService - * the userService to set - * @see #userService - */ - public void setUserService(IUserService userService) { - this.userService = userService; - } - - /** - * @return the projectService - * @see #projectService - */ - public IProjectService getProjectService() { - return projectService; - } - - /** - * @param projectService - * the projectService to set - * @see #projectService - */ - public void setProjectService(IProjectService projectService) { - this.projectService = projectService; - } - - /** - * @return the buildDate - * @see #buildDate - */ - public String getBuildDate() { - return buildDate; - } - - /** - * @param buildDate - * the buildDate to set - * @see #buildDate - */ - public void setBuildDate(String buildDate) { - this.buildDate = buildDate; - } - - /** - * @return the version - * @see #version - */ - public FrameworkVersionView getVersion() { - return version; - } - - /** - * @param version - * the version to set - * @see #version - */ - public void setVersion(FrameworkVersionView version) { - this.version = version; - } - - /** - * @return the changelogs - * @see #changelogs - */ - public List<ChangelogView> getChangelogs() { - return changelogs; - } - - /** - * @param changelogs - * the changelogs to set - * @see #changelogs - */ - public void setChangelogs(List<ChangelogView> changelogs) { - this.changelogs = changelogs; - } - - /** - * Returns {@link ConfigurationElementType#GOOGLE_ANALYTICS_IDENTIFIER google - * analytics identifier} used for tracking web-service usage. - * - * @return {@link ConfigurationElementType#GOOGLE_ANALYTICS_IDENTIFIER google - * analytics identifier} used for tracking web-service usage - */ - public String getGoogleAnalyticsIdentifier() { - return valueMap.get(ConfigurationElementType.GOOGLE_ANALYTICS_IDENTIFIER); - } - - /** - * Returns {@link ConfigurationElementType#LOGO_IMG logo image}. - * - * @return {@link ConfigurationElementType#LOGO_IMG logo image} - */ - public String getLogoImg() { - return valueMap.get(ConfigurationElementType.LOGO_IMG); - } - - /** - * Returns {@link ConfigurationElementType#LOGO_LINK logo link}. - * - * @return {@link ConfigurationElementType#LOGO_LINK logo link} - */ - public String getLogoLink() { - return valueMap.get(ConfigurationElementType.LOGO_LINK); - } - - /** - * Returns {@link ConfigurationElementType#LOGO_TEXT alt text for logo}. - * - * @return {@link ConfigurationElementType#LOGO_TEXT alt text for logo} - */ - public String getLogoText() { - return valueMap.get(ConfigurationElementType.LOGO_TEXT); - } - - /** - * Returns {@link ConfigurationElementType#LENGEND_FILE_1 legend file 1}. - * - * @return {@link ConfigurationElementType#LENGEND_FILE_1 legend file 1} - */ - public String getLegendFile1() { - return valueMap.get(ConfigurationElementType.LENGEND_FILE_1); - } - - /** - * Returns {@link ConfigurationElementType#LENGEND_FILE_2 legend file 2}. - * - * @return {@link ConfigurationElementType#LENGEND_FILE_2 legend file 2} - */ - public String getLegendFile2() { - return valueMap.get(ConfigurationElementType.LENGEND_FILE_2); - } - - /** - * Returns {@link ConfigurationElementType#LENGEND_FILE_3 legend file 3}. - * - * @return {@link ConfigurationElementType#LENGEND_FILE_3 legend file 3} - */ - public String getLegendFile3() { - return valueMap.get(ConfigurationElementType.LENGEND_FILE_3); - } - - /** - * Returns {@link ConfigurationElementType#LENGEND_FILE_4 legend file 4}. - * - * @return {@link ConfigurationElementType#LENGEND_FILE_4 legend file 4} - */ - public String getLegendFile4() { - return valueMap.get(ConfigurationElementType.LENGEND_FILE_4); - } - - /** - * Returns {@link ConfigurationElementType#USER_MANUAL_FILE user manual file}. - * - * @return {@link ConfigurationElementType#USER_MANUAL_FILE user manual file} - */ - public String getUserManual() { - return valueMap.get(ConfigurationElementType.USER_MANUAL_FILE); - } - - /** - * Returns {@link String} with estimated current memory usage (in MB). - * - * @return estimated current memory usage (in MB) - */ - public String getMemoryUsage() { - return NumberFormat.getInstance().format(configurationService.getMemoryUsage()) + " MB"; - } - - /** - * Returns {@link String} with max memory available to JVM (in MB). - * - * @return max memory available to JVM (in MB) - */ - public String getMaxMemory() { - return NumberFormat.getInstance().format(configurationService.getMaxMemory()) + " MB"; - } - -} +package lcsb.mapviewer.bean; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.beans.PropertyVetoException; +import java.beans.VetoableChangeListener; +import java.io.Serializable; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.faces.bean.ManagedBean; +import javax.faces.bean.ManagedProperty; +import javax.faces.bean.ViewScoped; +import javax.faces.event.ActionEvent; + +import org.apache.commons.validator.routines.UrlValidator; +import org.apache.log4j.Logger; + +import lcsb.mapviewer.common.Configuration; +import lcsb.mapviewer.common.FrameworkVersion; +import lcsb.mapviewer.model.user.ConfigurationElementType; +import lcsb.mapviewer.model.user.PrivilegeType; +import lcsb.mapviewer.model.user.User; +import lcsb.mapviewer.services.interfaces.IConfigurationService; +import lcsb.mapviewer.services.interfaces.IProjectService; +import lcsb.mapviewer.services.interfaces.IUserService; +import lcsb.mapviewer.services.view.ConfigurationView; + +/** + * Bean used for managing configuration (configurable parameters of the system). + * + * @author Piotr Gawron + * + */ +@ManagedBean(name = "configurationMB") +@ViewScoped +public class ConfigurationBean extends AbstractManagedBean implements Serializable { + + /** + * String representing {@link ConfigurationElementType#DEFAULT_MAP} system + * property used by {@link #firePropertyChange(String, Object, Object)}. + */ + public static final String DEFAULT_MODEL_PROPERTY = "DEFAULT_MODEL"; + + /** + * String representing {@link ConfigurationElementType#X_FRAME_DOMAIN} system + * property used by {@link #firePropertyChange(String, Object, Object)}. + */ + public static final String X_FRAME_PROPERTY = "X_FRAME"; + + /** + * String representing {@link #logoImg} property used by + * {@link #firePropertyChange(String, Object, Object)}. + */ + public static final String LOGO_IMG_PROPERTY = "LOGO_IMG"; + + /** + * String representing {@link #logoLink} property used by + * {@link #firePropertyChange(String, Object, Object)}. + */ + public static final String LOGO_LINK_PROPERTY = "LOGO_LINK"; + + /** + * String representing {@link #logoText} property used by + * {@link #firePropertyChange(String, Object, Object)}. + */ + public static final String LOGO_TEXT_PROPERTY = "LOGO_TEXT"; + + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(ConfigurationBean.class); + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * List of values for all possible configurable parameters. + */ + private List<ConfigurationView> values = new ArrayList<ConfigurationView>(); + + /** + * Release version of the framework. + */ + private FrameworkVersion version; + + /** + * Configrutaion params value. + */ + private Map<ConfigurationElementType, String> valueMap = new HashMap<>(); + + /** + * Bean used for communication with the client side about the data related to + * users (including information about currently logged user). + * + * @see UserBean + */ + @ManagedProperty(value = "#{userMB}") + private transient UserBean userBean; + + /** + * Service used to access configuration parameters. + * + * @see IConfigurationService + */ + @ManagedProperty(value = "#{ConfigurationService}") + private transient IConfigurationService configurationService; + + /** + * Service used to access information about users. + * + * @see IUserService + */ + @ManagedProperty(value = "#{UserService}") + private transient IUserService userService; + + /** + * Service used to access information about projects. + * + * @see IProjectService + */ + @ManagedProperty(value = "#{ProjectService}") + private transient IProjectService projectService; + + @Override + public final void init() { + // listener that checks if the new default map exists in the system + VetoableChangeListener selectedMapVetoChanged = new VetoableChangeListener() { + @Override + public void vetoableChange(final PropertyChangeEvent arg0) throws PropertyVetoException { + if ((DEFAULT_MODEL_PROPERTY).equals(arg0.getPropertyName())) { + if (!projectService.projectExists((String) arg0.getNewValue())) { + throw new PropertyVetoException("Project " + arg0.getNewValue() + " doesn't exist", arg0); + } + } + } + }; + addVetoablePropertyChangeListener(selectedMapVetoChanged); + + PropertyChangeListener xFrameChanged = new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent arg0) { + if ((X_FRAME_PROPERTY).equals(arg0.getPropertyName())) { + Configuration.setxFrameDomain((String) arg0.getNewValue()); + } + } + }; + addPropertyChangeListener(xFrameChanged); + + // listener that checks if the new x-fram address is valid + VetoableChangeListener xFrameVetoChanged = new VetoableChangeListener() { + @Override + public void vetoableChange(final PropertyChangeEvent arg0) throws PropertyVetoException { + if ((X_FRAME_PROPERTY).equals(arg0.getPropertyName())) { + String domain = (String) arg0.getNewValue(); + if (!new UrlValidator().isValid(domain) && !(domain != null && domain.contains("localhost"))) { + throw new PropertyVetoException("Invalid address: " + domain, arg0); + } + } + } + }; + addVetoablePropertyChangeListener(xFrameVetoChanged); + + version = configurationService.getSystemVersion(getProjectDeployPath()); + + refreshValues(null); + + Configuration.setWebAppDir(getPrimefacesUtils().getPath() + "../"); + } + + /** + * Refresh values from the database. + * + * @param actionEvent + * event from thefrom the client + */ + public final void refreshValues(final ActionEvent actionEvent) { + values = configurationService.getAllValues(); + for (ConfigurationView view : values) { + valueMap.put(view.getType(), view.getValue()); + } + } + + /** + * Save values to the database. + * + * @param actionEvent + * event from thefrom the client + */ + public final void saveValues(final ActionEvent actionEvent) { + // first check if we have privileges + if (getUserHasConfigurationView()) { + setValues(values); + configurationService.updateConfiguration(values); + values = configurationService.getAllValues(); + } + } + + /** + * Checks if logged user can manage the configuration of the system. + * + * @return <code>true</code> if logged user can manage the configuration, + * <code>false</code> otherwise + */ + public final boolean getUserHasConfigurationView() { + User user = userBean.getLoggedUser(); + boolean result = userService.userHasPrivilege(user, PrivilegeType.CONFIGURATION_MANAGE); + return result; + } + + /** + * + * @return list of all configuration values + * @see #values + */ + public final List<ConfigurationView> getValues() { + if (getUserHasConfigurationView()) { + return values; + } else { + return new ArrayList<>(); + } + } + + /** + * Sets the new list of configurable parameters. + * + * @param values + * list of configurable parameters with new values + */ + public final void setValues(final List<ConfigurationView> values) { + // when we set new values we should: + // 1) check if they are correct (vchs listeners) + // 2) notify apropriate listeners + + // for the naming convention of parameters take a look at {@link #vchs} + + // remember the old values from the system (!! not from the bean !!) + List<ConfigurationView> old = configurationService.getAllValues(); + this.values = values; + for (ConfigurationView el : values) { + String newVal = el.getValue(); + String oldVal = null; + for (ConfigurationView oldEl : old) { + if (oldEl.getType().equals(el.getType())) { + oldVal = oldEl.getValue(); + } + } + try { + if (el.getType().equals(ConfigurationElementType.DEFAULT_MAP)) { + fireVetoableChange(DEFAULT_MODEL_PROPERTY, oldVal, newVal); + } + } catch (PropertyVetoException e) { // if there was a veto then rollback + // to system parameters + this.values = old; + logger.debug("Rollback because parameter " + el.getType().name() + " contains inproper value: " + newVal); + sendError(e.getMessage()); + return; + } + } + for (ConfigurationView el : values) { + String newVal = el.getValue(); + String oldVal = null; + for (ConfigurationView oldEl : old) { + if (oldEl.getType().equals(el.getType())) { + oldVal = oldEl.getValue(); + } + } + if (el.getType().equals(ConfigurationElementType.DEFAULT_MAP)) { + firePropertyChange(DEFAULT_MODEL_PROPERTY, oldVal, newVal); + } else if (el.getType().equals(ConfigurationElementType.X_FRAME_DOMAIN)) { + firePropertyChange(X_FRAME_PROPERTY, oldVal, newVal); + } + + } + } + + @Override + public void clear() { + setValues(new ArrayList<ConfigurationView>()); + } + + /** + * @return the userBean + * @see #userBean + */ + public UserBean getUserBean() { + return userBean; + } + + /** + * @param userBean + * the userBean to set + * @see #userBean + */ + public void setUserBean(UserBean userBean) { + this.userBean = userBean; + } + + /** + * @return the configurationService + * @see #configurationService + */ + public IConfigurationService getConfigurationService() { + return configurationService; + } + + /** + * @param configurationService + * the configurationService to set + * @see #configurationService + */ + public void setConfigurationService(IConfigurationService configurationService) { + this.configurationService = configurationService; + } + + /** + * @return the userService + * @see #userService + */ + public IUserService getUserService() { + return userService; + } + + /** + * @param userService + * the userService to set + * @see #userService + */ + public void setUserService(IUserService userService) { + this.userService = userService; + } + + /** + * @return the projectService + * @see #projectService + */ + public IProjectService getProjectService() { + return projectService; + } + + /** + * @param projectService + * the projectService to set + * @see #projectService + */ + public void setProjectService(IProjectService projectService) { + this.projectService = projectService; + } + + /** + * @return the version + * @see #version + */ + public FrameworkVersion getVersion() { + return version; + } + + /** + * @param version + * the version to set + * @see #version + */ + public void setVersion(FrameworkVersion version) { + this.version = version; + } + + /** + * Returns {@link ConfigurationElementType#GOOGLE_ANALYTICS_IDENTIFIER google + * analytics identifier} used for tracking web-service usage. + * + * @return {@link ConfigurationElementType#GOOGLE_ANALYTICS_IDENTIFIER google + * analytics identifier} used for tracking web-service usage + */ + public String getGoogleAnalyticsIdentifier() { + return valueMap.get(ConfigurationElementType.GOOGLE_ANALYTICS_IDENTIFIER); + } + + /** + * Returns {@link ConfigurationElementType#LOGO_IMG logo image}. + * + * @return {@link ConfigurationElementType#LOGO_IMG logo image} + */ + public String getLogoImg() { + return valueMap.get(ConfigurationElementType.LOGO_IMG); + } + + /** + * Returns {@link ConfigurationElementType#LOGO_LINK logo link}. + * + * @return {@link ConfigurationElementType#LOGO_LINK logo link} + */ + public String getLogoLink() { + return valueMap.get(ConfigurationElementType.LOGO_LINK); + } + + /** + * Returns {@link ConfigurationElementType#LOGO_TEXT alt text for logo}. + * + * @return {@link ConfigurationElementType#LOGO_TEXT alt text for logo} + */ + public String getLogoText() { + return valueMap.get(ConfigurationElementType.LOGO_TEXT); + } + + /** + * Returns {@link ConfigurationElementType#LENGEND_FILE_1 legend file 1}. + * + * @return {@link ConfigurationElementType#LENGEND_FILE_1 legend file 1} + */ + public String getLegendFile1() { + return valueMap.get(ConfigurationElementType.LENGEND_FILE_1); + } + + /** + * Returns {@link ConfigurationElementType#LENGEND_FILE_2 legend file 2}. + * + * @return {@link ConfigurationElementType#LENGEND_FILE_2 legend file 2} + */ + public String getLegendFile2() { + return valueMap.get(ConfigurationElementType.LENGEND_FILE_2); + } + + /** + * Returns {@link ConfigurationElementType#LENGEND_FILE_3 legend file 3}. + * + * @return {@link ConfigurationElementType#LENGEND_FILE_3 legend file 3} + */ + public String getLegendFile3() { + return valueMap.get(ConfigurationElementType.LENGEND_FILE_3); + } + + /** + * Returns {@link ConfigurationElementType#LENGEND_FILE_4 legend file 4}. + * + * @return {@link ConfigurationElementType#LENGEND_FILE_4 legend file 4} + */ + public String getLegendFile4() { + return valueMap.get(ConfigurationElementType.LENGEND_FILE_4); + } + + /** + * Returns {@link ConfigurationElementType#USER_MANUAL_FILE user manual file}. + * + * @return {@link ConfigurationElementType#USER_MANUAL_FILE user manual file} + */ + public String getUserManual() { + return valueMap.get(ConfigurationElementType.USER_MANUAL_FILE); + } + + /** + * Returns {@link String} with estimated current memory usage (in MB). + * + * @return estimated current memory usage (in MB) + */ + public String getMemoryUsage() { + return NumberFormat.getInstance().format(configurationService.getMemoryUsage()) + " MB"; + } + + /** + * Returns {@link String} with max memory available to JVM (in MB). + * + * @return max memory available to JVM (in MB) + */ + public String getMaxMemory() { + return NumberFormat.getInstance().format(configurationService.getMaxMemory()) + " MB"; + } + +} diff --git a/web/src/main/java/lcsb/mapviewer/bean/utils/VersionResourceHandler.java b/web/src/main/java/lcsb/mapviewer/bean/utils/VersionResourceHandler.java index 7269dc310f..a6732a85ce 100644 --- a/web/src/main/java/lcsb/mapviewer/bean/utils/VersionResourceHandler.java +++ b/web/src/main/java/lcsb/mapviewer/bean/utils/VersionResourceHandler.java @@ -1,112 +1,112 @@ -package lcsb.mapviewer.bean.utils; - -import javax.faces.application.Resource; -import javax.faces.application.ResourceHandler; -import javax.faces.application.ResourceHandlerWrapper; -import javax.faces.application.ResourceWrapper; - -import lcsb.mapviewer.services.impl.ConfigurationService; - -import org.apache.log4j.Logger; - -/** - * This class is used to provide url for jsf resource files with "?v=version" - * addition that will make sure that when we update files from svn repository - * browser will reload them. - * - * @author Piotr Gawron - * - */ -public class VersionResourceHandler extends ResourceHandlerWrapper { - /** - * Default class logger. - */ - private final Logger logger = Logger.getLogger(VersionResourceHandler.class); - - /** - * SVN version of the system. - */ - private static String version = null; - - /** - * Resource for which we generate modified url. - */ - private ResourceHandler wrapped; - - /** - * Default constructor. - * - * @param wrapped - * {@link #wrapped} - */ - public VersionResourceHandler(ResourceHandler wrapped) { - this.wrapped = wrapped; - } - - @Override - public Resource createResource(String resourceName) { - return createResource(resourceName, null, null); - } - - @Override - public Resource createResource(String resourceName, String libraryName) { - return createResource(resourceName, libraryName, null); - } - - @Override - public Resource createResource(String resourceName, String libraryName, String contentType) { - final Resource resource = super.createResource(resourceName, libraryName, contentType); - - if (resource == null) { - return null; - } - - return new ResourceWrapper() { - - @Override - public String getRequestPath() { - return super.getRequestPath() + "&m_version=" + getVersion(); - } - - @Override - public Resource getWrapped() { - return resource; - } - @Override - public String getContentType() { - return getWrapped().getContentType(); - } - @Override - public String getResourceName() { - return getWrapped().getResourceName(); - } - @Override - public String getLibraryName() { - return getWrapped().getLibraryName(); - } - }; - } - - @Override - public ResourceHandler getWrapped() { - return wrapped; - } - - /** - * This method returns svn version of the framework. - * - * @return svn version of the framework - */ - private String getVersion() { - if (version == null) { - try { - version = new ConfigurationService().getSystemSvnVersion(new PrimefacesUtils().getPath()); - } catch (Exception e) { - logger.error(e, e); - version = "UNKNOWN"; - } - } - return version; - } - +package lcsb.mapviewer.bean.utils; + +import javax.faces.application.Resource; +import javax.faces.application.ResourceHandler; +import javax.faces.application.ResourceHandlerWrapper; +import javax.faces.application.ResourceWrapper; + +import lcsb.mapviewer.services.impl.ConfigurationService; + +import org.apache.log4j.Logger; + +/** + * This class is used to provide url for jsf resource files with "?v=version" + * addition that will make sure that when we update files from git repository + * browser will reload them. + * + * @author Piotr Gawron + * + */ +public class VersionResourceHandler extends ResourceHandlerWrapper { + /** + * Default class logger. + */ + private final Logger logger = Logger.getLogger(VersionResourceHandler.class); + + /** + * SVN version of the system. + */ + private static String version = null; + + /** + * Resource for which we generate modified url. + */ + private ResourceHandler wrapped; + + /** + * Default constructor. + * + * @param wrapped + * {@link #wrapped} + */ + public VersionResourceHandler(ResourceHandler wrapped) { + this.wrapped = wrapped; + } + + @Override + public Resource createResource(String resourceName) { + return createResource(resourceName, null, null); + } + + @Override + public Resource createResource(String resourceName, String libraryName) { + return createResource(resourceName, libraryName, null); + } + + @Override + public Resource createResource(String resourceName, String libraryName, String contentType) { + final Resource resource = super.createResource(resourceName, libraryName, contentType); + + if (resource == null) { + return null; + } + + return new ResourceWrapper() { + + @Override + public String getRequestPath() { + return super.getRequestPath() + "&m_version=" + getVersion(); + } + + @Override + public Resource getWrapped() { + return resource; + } + @Override + public String getContentType() { + return getWrapped().getContentType(); + } + @Override + public String getResourceName() { + return getWrapped().getResourceName(); + } + @Override + public String getLibraryName() { + return getWrapped().getLibraryName(); + } + }; + } + + @Override + public ResourceHandler getWrapped() { + return wrapped; + } + + /** + * This method returns git version of the framework. + * + * @return git version of the framework + */ + private String getVersion() { + if (version == null) { + try { + version = new ConfigurationService().getSystemSvnVersion(new PrimefacesUtils().getPath()); + } catch (Exception e) { + logger.error(e, e); + version = "UNKNOWN"; + } + } + return version; + } + } \ No newline at end of file diff --git a/web/src/main/webapp/.gitignore b/web/src/main/webapp/.gitignore new file mode 100644 index 0000000000..ebdc1c438d --- /dev/null +++ b/web/src/main/webapp/.gitignore @@ -0,0 +1,2 @@ +/CHANGELOG +/version.txt diff --git a/web/src/main/webapp/WEB-INF/components/admin/footer.xhtml b/web/src/main/webapp/WEB-INF/components/admin/footer.xhtml index 32246cb4fd..3d995f9d32 100644 --- a/web/src/main/webapp/WEB-INF/components/admin/footer.xhtml +++ b/web/src/main/webapp/WEB-INF/components/admin/footer.xhtml @@ -1,25 +1,22 @@ -<html xmlns="http://www.w3.org/1999/xhtml" - xmlns:h="http://java.sun.com/jsf/html" - xmlns:f="http://java.sun.com/jsf/core" - xmlns:ui="http://java.sun.com/jsf/facelets" - xmlns:p="http://primefaces.org/ui"> - - -<div id="footerTable"> -<table width="100%" border="0" cellspacing="0" cellpadding="0"> - <tr> - <td align="left"><a href="#{configurationMB.logoLink}" title="#{configurationMB.logoText}" target="_blank"> - <h:graphicImage library="images" name="#{configurationMB.logoImg}" width="80" height="80" border="0" alt="#{configurationMB.logoText}"/> - </a></td> - <td align="center" class="footerText">MiNERVA version #{configurationMB.version.svnVersion}; build #{configurationMB.buildDate}</td> - <td align="right"><a href="http://wwwen.uni.lu/lcsb/" title="LCSB - Luxembourg Centre for Systems Biomedicine" target="_blank"> - <h:graphicImage library="images" name="lcsb.png" width="80" height="80" border="0" alt="LCSB - Luxembourg Centre for Systems Biomedicine"/> - </a></td> - </tr> -</table> -</div> - - - -</html> - +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:h="http://java.sun.com/jsf/html" + xmlns:f="http://java.sun.com/jsf/core" + xmlns:ui="http://java.sun.com/jsf/facelets" + xmlns:p="http://primefaces.org/ui"> + + +<div id="footerTable"> +<table width="100%" border="0" cellspacing="0" cellpadding="0"> + <tr> + <td align="left"><a href="#{configurationMB.logoLink}" title="#{configurationMB.logoText}" target="_blank"> + <h:graphicImage library="images" name="#{configurationMB.logoImg}" width="80" height="80" border="0" alt="#{configurationMB.logoText}"/> + </a></td> + <td align="center" class="footerText">MiNERVA version #{configurationMB.version.version};<br/> build #{configurationMB.version.time};<br/>git: #{configurationMB.version.gitVersion}</td> + <td align="right"><a href="http://wwwen.uni.lu/lcsb/" title="LCSB - Luxembourg Centre for Systems Biomedicine" target="_blank"> + <h:graphicImage library="images" name="lcsb.png" width="80" height="80" border="0" alt="LCSB - Luxembourg Centre for Systems Biomedicine"/> + </a></td> + </tr> +</table> +</div> +</html> + diff --git a/web/src/main/webapp/admin/configuration.xhtml b/web/src/main/webapp/admin/configuration.xhtml index a7b049a1b8..9202732b32 100644 --- a/web/src/main/webapp/admin/configuration.xhtml +++ b/web/src/main/webapp/admin/configuration.xhtml @@ -1,85 +1,70 @@ -<ui:composition template="/WEB-INF/components/admin/template.xhtml" - xmlns="http://www.w3.org/1999/xhtml" - xmlns:f="http://java.sun.com/jsf/core" - xmlns:h="http://java.sun.com/jsf/html" - xmlns:p="http://primefaces.org/ui" - xmlns:cc="http://java.sun.com/jsf/composite/pfcomp" - xmlns:ui="http://java.sun.com/jsf/facelets"> - - <ui:define name="css"> - </ui:define> - - <ui:define name="title"> - Admin panel - Configuration - </ui:define> - - <ui:param name="access" value="#{configurationMB.userHasConfigurationView}"/> - - <ui:define name="content"> - <cc:helpButton style="float:right" helpText='Configuration tab provides a summary of the current version of your MINERVA instance. Moreover, it allows privileged users to configure -global parameters of the MINERVA instance. More information can be found in the <a href="#{request.contextPath}/javax.faces.resource/admin_guide.pdf.xhtml?ln=other" target="_admin_manual_" >manual</a>.'/> - - <h1>CONFIGURATION</h1> - - <h:form id="configurationForm"> - <h:outputText value="System version: " class="text"/> - <h:outputText value="#{configurationMB.version.version}" class="text"/> - <h:outputText value=" UNSTABLE DEVEL VERSION" class="text" - rendered="#{configurationMB.version.devel}"/> - <br/> - <h:outputText value="Svn build version: " /> - <h:outputText value="#{configurationMB.version.svnVersion}" class="bold"/> - <br/> - <h:outputText value="Build date: " /> - <h:outputText value="#{configurationMB.buildDate}" class="bold"/> - <br/> - <br/> - <h:outputText value="PrimeFaces version: " /> - <h:outputText value="#{configurationMB.primefacesVersion}" class="bold"/> - <br/> - <br/> - <h:outputText value="Memory usage: " /> - <h:outputText value="#{configurationMB.memoryUsage}" class="bold"/> - <br/> - <h:outputText value="Max memory available: " /> - <h:outputText value="#{configurationMB.maxMemory}" class="bold"/> - <br/> - <br/> - - <h:outputText value="Changelog: " class="textLighter"/> - <p:dataTable id="changelogDataTable" var="changelog" value="#{configurationMB.changelogs}"> - <p:column headerText="Type" sortBy="type"> - <h:outputText id="type" value="#{changelog.type}" /> - </p:column> - - <p:column headerText="Description" sortBy="description"> - <h:outputText value="#{changelog.description}" /> - </p:column> - </p:dataTable> - <br/> - <br/> - - <h:outputText value="System parameters: " class="textLighter"/> - <p:dataTable id="configurationDataTable" var="configuration" value="#{configurationMB.values}"> - <p:column sortBy="idObject" headerText="Id"> - <h:outputText id="configurationId" value="#{configuration.idObject}" /> - </p:column> - - <p:column sortBy="title" headerText="Title"> - <h:outputText value="#{configuration.type.commonName}" /> - </p:column> - - <p:column sortBy="value" headerText="Value"> - <p:inputText value="#{configuration.value}" /> - </p:column> - - </p:dataTable> - <center> - <p:commandButton id="refreshConfigurationButton" actionListener="#{configurationMB.refreshValues}" - icon="ui-icon-refresh" update="configurationDataTable"/> - <p:commandButton id="saveConfigurationButton" actionListener="#{configurationMB.saveValues}" - icon="ui-icon-disk" update="configurationDataTable"/> - </center> - </h:form> - </ui:define> -</ui:composition> +<ui:composition template="/WEB-INF/components/admin/template.xhtml" + xmlns="http://www.w3.org/1999/xhtml" + xmlns:f="http://java.sun.com/jsf/core" + xmlns:h="http://java.sun.com/jsf/html" + xmlns:p="http://primefaces.org/ui" + xmlns:cc="http://java.sun.com/jsf/composite/pfcomp" + xmlns:ui="http://java.sun.com/jsf/facelets"> + + <ui:define name="css"> + </ui:define> + + <ui:define name="title"> + Admin panel - Configuration + </ui:define> + + <ui:param name="access" value="#{configurationMB.userHasConfigurationView}"/> + + <ui:define name="content"> + <cc:helpButton style="float:right" helpText='Configuration tab provides a summary of the current version of your MINERVA instance. Moreover, it allows privileged users to configure +global parameters of the MINERVA instance. More information can be found in the <a href="#{request.contextPath}/javax.faces.resource/admin_guide.pdf.xhtml?ln=other" target="_admin_manual_" >manual</a>.'/> + + <h1>CONFIGURATION</h1> + + <h:form id="configurationForm"> + <h:outputText value="System version: " class="text"/> + <h:outputText value="#{configurationMB.version.version}" class="text"/> + <br/> + <h:outputText value="Git build version: " /> + <h:outputText value="#{configurationMB.version.gitVersion}" class="bold"/> + <br/> + <h:outputText value="Build date: " /> + <h:outputText value="#{configurationMB.version.time}" class="bold"/> + <br/> + <br/> + <h:outputText value="PrimeFaces version: " /> + <h:outputText value="#{configurationMB.primefacesVersion}" class="bold"/> + <br/> + <br/> + <h:outputText value="Memory usage: " /> + <h:outputText value="#{configurationMB.memoryUsage}" class="bold"/> + <br/> + <h:outputText value="Max memory available: " /> + <h:outputText value="#{configurationMB.maxMemory}" class="bold"/> + <br/> + <br/> + + <h:outputText value="System parameters: " class="textLighter"/> + <p:dataTable id="configurationDataTable" var="configuration" value="#{configurationMB.values}"> + <p:column sortBy="idObject" headerText="Id"> + <h:outputText id="configurationId" value="#{configuration.idObject}" /> + </p:column> + + <p:column sortBy="title" headerText="Title"> + <h:outputText value="#{configuration.type.commonName}" /> + </p:column> + + <p:column sortBy="value" headerText="Value"> + <p:inputText value="#{configuration.value}" /> + </p:column> + + </p:dataTable> + <center> + <p:commandButton id="refreshConfigurationButton" actionListener="#{configurationMB.refreshValues}" + icon="ui-icon-refresh" update="configurationDataTable"/> + <p:commandButton id="saveConfigurationButton" actionListener="#{configurationMB.saveValues}" + icon="ui-icon-disk" update="configurationDataTable"/> + </center> + </h:form> + </ui:define> +</ui:composition> -- GitLab