Commit cef0a5a7 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '253_loading_page_time' into 'devel_11.0.x'

253 loading page time, ensembl API, pubmed API

See merge request piotr.gawron/minerva!152
parents 2ea26116 ead8f3a5
......@@ -19,8 +19,8 @@ import org.apache.log4j.Logger;
import lcsb.mapviewer.annotation.services.WrongResponseCodeIOException;
/**
* This class helps to download webpages. The pages are downloaded in separate
* thred, due to the fact that sometimes java socket can hang (related JVM bug:
* This class helps to download web pages. The pages are downloaded in separate
* thread, due to the fact that sometimes java socket can hang (related JVM bug:
* https://bugs.openjdk.java.net/browse/JDK-8075484 ).
*
* @author Piotr Gawron
......@@ -35,13 +35,13 @@ public class WebPageDownloader {
/**
* Hard timeout (threads are terminated) of http connection that access data
* across internet.
* across Internet.
*/
private static final int HTTP_CONNECTION_TIMEOUT_SEC = 120;
/**
* How much time should the thread sleep before another try to access the
* webpage that thrown INTERNAL SERVER ERROR http response.
* web page that thrown INTERNAL SERVER ERROR http response.
*/
private static final int HTTP_INTERNAL_ERROR_RECONNECT_SLEEP_TIME = 2000;
......@@ -52,18 +52,18 @@ public class WebPageDownloader {
private static final int HTTP_INTERNAL_ERROR_RECONNECT_TIMES = 2;
/**
* Returns content of the webpage identified by url.
* Returns content of the web page identified by url.
*
* @param accessUrl
* url of a webpage
* @return content of the webpage identified by url
* url of a web page
* @return content of the web page identified by url
* @throws IOException
* thrown when there is any problem with accesing webpage
* thrown when there is any problem with accessing web page
*/
public String getFromNetwork(String accessUrl) throws IOException {
/**
* Tasks that retrieves content from webpage
* Tasks that retrieves content from web page
*
* @author Piotr Gawron
*
......@@ -139,7 +139,7 @@ public class WebPageDownloader {
* argument.
*
* @param accessUrl
* url to the webpagae
* url to the web page
* @return {@link HttpURLConnection connection} to the url given in the
* argument
* @throws MalformedURLException
......
......@@ -55,7 +55,7 @@ public class PubmedParser extends CachableInterface implements IExternalService
/**
* Version of the remote API thnat is supported by this connecting class.
*/
static final String SUPPORTED_VERSION = "5.2.1";
static final String SUPPORTED_VERSION = "5.2.2";
/**
* Connector used for accessing data from miriam registry.
......
......@@ -41,10 +41,10 @@ public class EnsemblAnnotator extends ElementAnnotator implements IExternalServi
/**
* Version of the rest API that is supported by this annotator.
*/
static final String SUPPORTED_VERSION = "6.1";
static final String SUPPORTED_VERSION = "6.2";
/**
* Url address of ensembl restfull service.
* Url address of ensembl restful service.
*/
private static final String REST_SERVICE_URL = "http://rest.ensembl.org/xrefs/id/";
......
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
......@@ -63,7 +63,7 @@ public class Layout implements Serializable {
private String title;
/**
* Is the layout publically available.
* Is the layout publicly available.
*/
private boolean publicLayout = false;
......@@ -80,13 +80,13 @@ public class Layout implements Serializable {
private Integer hierarchyViewLevel;
/**
* ModelData to which layout is assigend.
* ModelData to which layout is assigned.
*/
@ManyToOne(fetch = FetchType.LAZY)
private ModelData model;
/**
* Whou created the layout.
* Who created the layout.
*/
@ManyToOne(fetch = FetchType.LAZY)
private User creator;
......
......@@ -3,11 +3,13 @@ package lcsb.mapviewer.persist.dao;
import java.util.List;
import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.persist.DbUtils;
/**
......@@ -21,273 +23,302 @@ import lcsb.mapviewer.persist.DbUtils;
*/
public abstract class BaseDao<T> {
/**
* Default class logger.
*/
private static Logger logger = Logger.getLogger(BaseDao.class);
/**
* Default class logger.
*/
private static Logger logger = Logger.getLogger(BaseDao.class);
/**
* Sometimes objects have a flag that indicate that the object was removed
* from the system (but is still there because of foreign keys etc). This
* column determines the name of the column. If its set to null then such
* column doesn't exist.
*/
private String removableColumn = null;
/**
* Sometimes objects have a flag that indicate that the object was removed from
* the system (but is still there because of foreign keys etc). This column
* determines the name of the column. If its set to null then such column
* doesn't exist.
*/
private String removableColumn = null;
/**
* Class of the object that DAO works on.
*/
private Class<? extends T> clazz;
/**
* Class of the object that DAO works on.
*/
private Class<? extends T> clazz;
/**
* Default constructor.
*
* @param theClass
* class of the object that DAO will work on
*/
public BaseDao(Class<? extends T> theClass) {
this.clazz = theClass;
}
/**
* Default constructor.
*
* @param theClass
* class of the object that DAO will work on
*/
public BaseDao(Class<? extends T> theClass) {
this.clazz = theClass;
}
/**
* Default constructor.
*
* @param theClass
* class of the object that DAO will work on
* @param removableColumn
* determines the column in the object table that indicates if object
* should be considered as removed or not (see also:
* {@link #removableColumn}.
*
*/
public BaseDao(Class<? extends T> theClass, String removableColumn) {
this(theClass);
this.removableColumn = removableColumn;
}
/**
* Default constructor.
*
* @param theClass
* class of the object that DAO will work on
* @param removableColumn
* determines the column in the object table that indicates if object
* should be considered as removed or not (see also:
* {@link #removableColumn}.
*
*/
public BaseDao(Class<? extends T> theClass, String removableColumn) {
this(theClass);
this.removableColumn = removableColumn;
}
/**
* Utils that help to manage the sessions in custom multithreaded
* implementation.
*/
@Autowired
private DbUtils dbUtils;
/**
* Utils that help to manage the sessions in custom multithreaded
* implementation.
*/
@Autowired
private DbUtils dbUtils;
/**
* Adds object to the database.
*
* @param object
* object to add to database
*/
public void add(T object) {
getSession().save(object);
if (dbUtils.isAutoFlush()) {
getSession().flush();
}
}
/**
* Adds object to the database.
*
* @param object
* object to add to database
*/
public void add(T object) {
getSession().save(object);
if (dbUtils.isAutoFlush()) {
getSession().flush();
}
}
/**
* Flush connection with database.
*/
public void flush() {
getSession().flush();
}
/**
* Flush connection with database.
*/
public void flush() {
getSession().flush();
}
/**
* Commit current transaction.
*/
public void commit() {
if (!dbUtils.isCustomSessionForCurrentThread()) {
logger.warn("Manual commit with spring managed session!", new Exception());
}
/**
* Commit current transaction.
*/
public void commit() {
if (!dbUtils.isCustomSessionForCurrentThread()) {
logger.warn("Manual commit with spring managed session!", new Exception());
}
getSession().getTransaction().commit();
getSession().beginTransaction();
}
getSession().getTransaction().commit();
getSession().beginTransaction();
}
/**
* Returns current session.
*
* @return session for current thread
*/
protected Session getSession() {
return dbUtils.getSessionForCurrentThread();
}
/**
* Returns current session.
*
* @return session for current thread
*/
protected Session getSession() {
return dbUtils.getSessionForCurrentThread();
}
/**
* Update object in the database.
*
* @param object
* object to be updated
*/
public void update(T object) {
getSession().update(object);
if (dbUtils.isAutoFlush()) {
getSession().flush();
}
}
/**
* Update object in the database.
*
* @param object
* object to be updated
*/
public void update(T object) {
getSession().update(object);
if (dbUtils.isAutoFlush()) {
getSession().flush();
}
}
/**
* Removes object from the database.
*
* @param object
* object to be removed from database
*/
public void delete(T object) {
getSession().delete(object);
if (dbUtils.isAutoFlush()) {
getSession().flush();
}
}
/**
* Removes object from the database.
*
* @param object
* object to be removed from database
*/
public void delete(T object) {
getSession().delete(object);
if (dbUtils.isAutoFlush()) {
getSession().flush();
}
}
/**
* "Disconnects" object with the element in database. From this point on we
* cannot update/delete it in the database.
*
* @param object
* object that should be evicted
*/
public void evict(T object) {
getSession().evict(object);
if (dbUtils.isAutoFlush()) {
getSession().flush();
}
}
/**
* "Disconnects" object with the element in database. From this point on we
* cannot update/delete it in the database.
*
* @param object
* object that should be evicted
*/
public void evict(T object) {
getSession().evict(object);
if (dbUtils.isAutoFlush()) {
getSession().flush();
}
}
/**
* Returns number of elements in the table for this object.
*
* @return number of all elements in database
*/
public long getCount() {
if (removableColumn == null) {
return (Long) getSession().createCriteria(this.clazz).setProjection(Projections.rowCount()).uniqueResult();
} else {
return (Long) getSession().createCriteria(this.clazz).add(Restrictions.eq(removableColumn, false)).setProjection(Projections.rowCount()).uniqueResult();
}
}
/**
* Returns number of elements in the table for this object.
*
* @return number of all elements in database
*/
public long getCount() {
if (removableColumn == null) {
return (Long) getSession().createCriteria(this.clazz).setProjection(Projections.rowCount()).uniqueResult();
} else {
return (Long) getSession().createCriteria(this.clazz).add(Restrictions.eq(removableColumn, false))
.setProjection(Projections.rowCount()).uniqueResult();
}
}
/**
* Returns an element that has a key parameter equal to value. If there is
* more than one element than one of them will be returned. If there is no
* such element then <code>null</code> is returned.
*
* @param key
* which parameter will filter the data
* @param value
* what must be the value of parameter key
* @return element that fulfill T.key=value criteria
*/
@SuppressWarnings("unchecked")
protected T getByParameter(String key, Object value) {
List<?> list = getSession()
.createQuery(" from " + this.clazz.getSimpleName() + " where " + key + " = :param_val " + removableAndStatemant()).setParameter("param_val", value)
.list();
if (list.size() == 0) {
return null;
} else {
return (T) list.get(0);
}
}
/**
* Returns an element that has a key parameter equal to value. If there is more
* than one element than one of them will be returned. If there is no such
* element then <code>null</code> is returned.
*
* @param key
* which parameter will filter the data
* @param value
* what must be the value of parameter key
* @return element that fulfill T.key=value criteria
*/
@SuppressWarnings("unchecked")
protected T getByParameter(String key, Object value) {
List<?> list = getSession()
.createQuery(
" from " + this.clazz.getSimpleName() + " where " + key + " = :param_val " + removableAndStatemant())
.setParameter("param_val", value).list();
if (list.size() == 0) {
return null;
} else {
return (T) list.get(0);
}
}
/**
* Returns the list of elements that havae a key parameter equal to value.
*
* @param key
* which parameter will filter the data
* @param value
* what must be the value of parameter key
* @return list of elements that fulfill T.key=value criteria
*/
@SuppressWarnings("unchecked")
protected List<T> getElementsByParameter(String key, Object value) {
List<?> list = getSession()
.createQuery(" from " + this.clazz.getSimpleName() + " where " + key + " = :param_val " + removableAndStatemant()).setParameter("param_val", value)
.list();
return (List<T>) list;
}
/**
* Returns the list of elements that have a key parameter equal to value.
*
* @param key
* which parameter will filter the data
* @param value
* what must be the value of parameter key
* @return list of elements that fulfill T.key=value criteria
*/
@SuppressWarnings("unchecked")
protected List<T> getElementsByParameter(String key, Object value) {
List<?> list = getSession()
.createQuery(
" from " + this.clazz.getSimpleName() + " where " + key + " = :param_val " + removableAndStatemant())
.setParameter("param_val", value).list();
return (List<T>) list;
}
/**
* Returns element with the id given as parameter.
*
* @param id
* database identifier
* @return object width identifier given as parameter
*/
@SuppressWarnings("unchecked")
public T getById(int id) {
List<?> list = getSession().createQuery(" from " + this.clazz.getSimpleName() + " where id=? " + removableAndStatemant()).setParameter(0, id).list();
if (list.size() == 0) {
return null;
} else {
return (T) list.get(0);
}
}
@SuppressWarnings("unchecked")
protected List<T> getElementsByParameters(List<Pair<String, Object>> params) {
String queryString = " from " + this.clazz.getSimpleName() + " where ";
boolean firstParam = true;
for (Pair<String, Object> param : params) {
String key = param.getLeft();
if (!firstParam) {
queryString += " AND ";
}
queryString += key + " = :param_val_" + key + " ";
/**
* Returns list of all object in db.
*