Commit ffcb184a authored by Gradl, Tobias's avatar Gradl, Tobias
Browse files

No commit message

No commit message
parent 8f83a377
CREATE TABLE db_version_history (
version varchar,
updated timestamp with time zone
);
CREATE SEQUENCE data_provider_id_seq INCREMENT 1 MINVALUE 1 START 1;
CREATE TABLE data_provider (
id bigint NOT NULL DEFAULT nextval('data_provider_id_seq'::regclass),
name character varying(100) NOT NULL,
description text,
endpoint_url character varying(1024) NOT NULL,
state int NOT NULL DEFAULT 0,
messages text,
last_crawl_completed timestamp with time zone,
date_time_format_pattern character varying(100) NOT NULL,
created timestamp with time zone NOT NULL,
modified timestamp with time zone NOT NULL,
CONSTRAINT pkey_data_provider PRIMARY KEY (id)
);
CREATE SEQUENCE data_provider_property_id_seq INCREMENT 1 MINVALUE 1 START 1;
CREATE TABLE data_provider_property (
id bigint NOT NULL DEFAULT nextval('data_provider_property_id_seq'::regclass),
provider_id bigint NOT NULL,
name character varying(100) NOT NULL,
description text,
value character varying(255) NOT NULL,
created timestamp with time zone NOT NULL,
modified timestamp with time zone NOT NULL,
CONSTRAINT pkey_data_provider_property PRIMARY KEY (id),
CONSTRAINT data_provider_property_data_provider_fkey FOREIGN KEY (provider_id) REFERENCES data_provider(id) ON UPDATE CASCADE ON DELETE CASCADE
);
CREATE SEQUENCE crawled_resource_id_seq INCREMENT 1 MINVALUE 1 START 1;
CREATE TABLE crawled_resource (
id bigint NOT NULL DEFAULT nextval('crawled_resource_id_seq'::regclass),
provider_id bigint NOT NULL,
ext_id character varying(1024),
created timestamp with time zone NOT NULL,
modified timestamp with time zone NOT NULL,
CONSTRAINT pkey_crawled_resource PRIMARY KEY (id),
CONSTRAINT crawled_resource_data_provider_fkey FOREIGN KEY (provider_id) REFERENCES data_provider(id) ON UPDATE CASCADE ON DELETE CASCADE
);
CREATE SEQUENCE crawled_resource_property_id_seq INCREMENT 1 MINVALUE 1 START 1;
CREATE TABLE crawled_resource_property (
id bigint NOT NULL DEFAULT nextval('crawled_resource_property_id_seq'::regclass),
resource_id bigint NOT NULL,
key character varying(4096) NOT NULL,
value text NOT NULL,
CONSTRAINT pkey_crawled_resource_property PRIMARY KEY (id),
CONSTRAINT crawled_resource_property_crawled_resource_fkey FOREIGN KEY (resource_id) REFERENCES crawled_resource(id) ON UPDATE CASCADE ON DELETE CASCADE
);
INSERT INTO db_version_history(version, updated) VALUES ('1.00', NOW());
\ No newline at end of file
-- Version 1.01
CREATE SEQUENCE crawl_id_seq INCREMENT 1 MINVALUE 1 START 1;
CREATE TABLE crawl (
id bigint NOT NULL DEFAULT nextval('crawl_id_seq'::regclass),
provider_id bigint NOT NULL,
state int NOT NULL DEFAULT 0,
created timestamp with time zone NOT NULL,
modified timestamp with time zone NOT NULL,
CONSTRAINT pkey_crawl PRIMARY KEY (id),
CONSTRAINT crawl_data_provider_fkey FOREIGN KEY (provider_id) REFERENCES data_provider(id) ON UPDATE CASCADE ON DELETE CASCADE
);
INSERT INTO db_version_history(version, updated) VALUES ('1.01', NOW());
-- End Update (Version 1.01)
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.dariah</groupId>
<artifactId>genericsearch</artifactId>
<name>search</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
<maven.test.failure.ignore>true</maven.test.failure.ignore>
<java-version>1.7</java-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<org.springframework-version>3.1.2.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.7.2</org.slf4j-version>
<ch.qos.logback.version>1.0.9</ch.qos.logback.version>
<!-- Tiles > 3.0 not supported in Spring 3 -->
<org.apache.tiles-version>2.2.2</org.apache.tiles-version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${ch.qos.logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${ch.qos.logback.version}</version>
</dependency>
<!-- @Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- Apache Tiles -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>${org.apache.tiles-version}</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>${org.apache.tiles-version}</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-api</artifactId>
<version>${org.apache.tiles-version}</version>
</dependency>
<!-- <dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
<version>${org.apache.tiles-version}</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-template</artifactId>
<version>${org.apache.tiles-version}</version>
</dependency> -->
<!-- DB/ORM -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.1.9.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.3.1.Final</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>
<!-- Joda-Time -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time-jsptags</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>3.0.0.GA</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<!-- Util -->
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<!-- IR -->
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>0.20.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>false</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.test.int1.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
package de.dariah.base.context;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.FatalBeanException;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.PropertiesLoaderUtils;
public class ContextService implements ApplicationContextAware, ResourceLoaderAware {
private static final Logger logger = LoggerFactory.getLogger(ContextService.class);
private Properties props;
private static final String PROPERTIES_SUFFIX = ".properties";
private ResourceLoader resourceLoader = new DefaultResourceLoader();
private List<String> languages;
private String localizationBasename;
public String getLocalizationBasename() {
return localizationBasename;
}
public void setLocalizationBasename(String localizationBasename) {
this.localizationBasename = localizationBasename;
}
public List<String> getLanguages() {
return languages;
}
private static class ContextSingletonHolder {
static ContextService instance = new ContextService();
}
public static ContextService getInstance() {
return ContextSingletonHolder.instance;
}
private ApplicationContext applicationContext;
private TreeMap<String, Object> beanCache;
private ContextService() {
this.beanCache = new TreeMap<String, Object>();
}
public SessionFactory getSessionFactory() {
return (SessionFactory) getBean("sessionFactory");
}
public Object getBean(Class<?> clazz) {
return applicationContext.getBean(clazz);
}
public <T> Map<String, T> getBeansOfType(Class<T> type) {
return applicationContext.getBeansOfType(type);
}
public Object getBean(String name) {
if (!beanCache.containsKey(name)) {
Object bean = applicationContext.getBean(name);
if (bean==null) {
throw new BeanInitializationException(String.format("Bean %s could not be retrieved from ApplicationContext", name));
}
beanCache.put(name, bean);
}
return beanCache.get(name);
}
public ApplicationContext getApplicationContext() {
return this.applicationContext;
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
logger.info("*****************************************************");
logger.info("DARIAH Generic Search - Application Context set");
/*cleanupApacheDSWorkDir();*/
loadProperties();
loadAvailableLocales();
}
private void loadAvailableLocales() {
logger.info("Scanning for available i18n resource files in basename: " + localizationBasename);
languages = new ArrayList<String>();
int i = 0;
String language, country, variant;
StringBuilder localeCodeBuilder;
// Loop over all the available locales and see if there is a resource file available
for (Locale locale : Locale.getAvailableLocales()) {
language = locale.getLanguage();
country = locale.getCountry();
variant = locale.getVariant();
localeCodeBuilder = new StringBuilder();
if (language.length() > 0) {
localeCodeBuilder.append(language);
addIfLocaleDefined(localeCodeBuilder.toString(), languages);
}
localeCodeBuilder.append('_');
if (country.length() > 0) {
localeCodeBuilder.append(country);
addIfLocaleDefined(localeCodeBuilder.toString(), languages);
}
if (variant.length() > 0 && (language.length() > 0 || country.length() > 0)) {
localeCodeBuilder.append('_').append(variant);
addIfLocaleDefined(localeCodeBuilder.toString(), languages);
}
i++;
}
logger.info(String.format("Scanned for %s language codes, identified %s i18n resources.", i, languages.size()));
}
private void addIfLocaleDefined(String languageCode, List<String> languages) {
String resourcePath = String.format("%s_%s%s", localizationBasename, languageCode, PROPERTIES_SUFFIX);
Resource resource = this.resourceLoader.getResource(resourcePath);
if (!languages.contains(languageCode) && resource.exists()) {
Locale locale = Locale.forLanguageTag(languageCode);
if (locale!=null) {
languages.add(languageCode);
logger.info(String.format("Found i18n resource for [%s: %s]", languageCode, locale.getDisplayLanguage()));
}
}
}
private void loadProperties() {
try {
logger.info("Attempting to load main configuration properties.");
String configLocation = (String)this.getBean("configLocation");
Resource resource = new ClassPathResource(configLocation);
props = PropertiesLoaderUtils.loadProperties(resource);
logger.info("Properties loaded.");
} catch (IOException e) {
logger.error(String.format("Attempting to load main configuration properties failed: ", e.getMessage()), e);
throw new FatalBeanException("Attempting to load main configuration properties failed", e);
}
}
public String getPropertyValue(String key, String defaultResult) {
return props.getProperty(key, defaultResult);
}
public Map<String, String> getPropertiesByPrefix(String prefix) {
Map<String, String> result = new HashMap<String, String>();
for (Object key : props.keySet()) {
if (key!=null && key.toString().startsWith(prefix)) {
result.put(key.toString().substring(prefix.length()), props.get(key).toString());
}
}
return result;
}
/*private void cleanupApacheDSWorkDir() {
String apacheWorkDir = System.getProperty("apacheDSWorkDir");
if (apacheWorkDir == null) {
apacheWorkDir = System.getProperty("java.io.tmpdir") + File.separator + "apacheds-spring-security";
}
File workDir = new File(apacheWorkDir);
if (workDir.exists() && workDir.isDirectory()) {
logger.warn("Apache Directory Server needs to be cleaned up due to improper shutdown...");
try {
FileUtils.deleteDirectory(workDir);
logger.info(String.format("Directory [%s] deleted", apacheWorkDir));
} catch (IOException e) {
logger.error(String.format("Failed to delete directory [%s]", apacheWorkDir));
}
}
}*/
@Override
public void setResourceLoader(ResourceLoader resourceLoader) {
this.resourceLoader = (resourceLoader != null ? resourceLoader : new DefaultResourceLoader());
}
public static String humanReadableByteCount(long bytes, boolean si) {
int unit = si ? 1000 : 1024;
if (bytes < unit) return bytes + " B";
int exp = (int) (Math.log(bytes) / Math.log(unit));
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i");
return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
}
}
package de.dariah.base.context;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;
import org.apache.commons.dbcp.BasicDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class WrappedBasicDataSource extends BasicDataSource {
private static Logger logger = LoggerFactory.getLogger(WrappedBasicDataSource.class);;
@Override
public synchronized void close() throws SQLException {
Enumeration<Driver> drivers = DriverManager.getDrivers();
while (drivers.hasMoreElements()) {
Driver driver = drivers.nextElement();
try {
DriverManager.deregisterDriver(driver);
logger.info(String.format("deregistering jdbc driver: %s", driver));
} catch (SQLException e) {
logger.error(String.format("Error deregistering driver %s", driver), e);
}
}
}
}
package de.dariah.base.dao;
import java.util.Collection;
import java.util.List;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;