Commit 71dd4f11 authored by Paul-Christian Volkmer's avatar Paul-Christian Volkmer
Browse files

Added internal databases to hold config and internal category information

parent 7d8f2474
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.thm.arsnova.connector</groupId>
<artifactId>connector</artifactId>
<version>0.41.0-SNAPSHOT</version>
</parent>
<artifactId>connector-client</artifactId>
<packaging>jar</packaging>
<name>Connector Client Library</name>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.thm.arsnova.connector</groupId>
<artifactId>connector-model</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.thm.arsnova.connector</groupId>
<artifactId>connector</artifactId>
<version>0.41.0-SNAPSHOT</version>
</parent>
<artifactId>connector-model</artifactId>
<packaging>jar</packaging>
<name>Connector Model</name>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.3.1</version>
<configuration>
<schemaDirectory>${basedir}/src/main/resources/</schemaDirectory>
<bindingDirectory>${basedir}/src/main/resources/</bindingDirectory>
<packageName>de.thm.arsnova.connector.model</packageName>
<outputDirectory>${basedir}/src/main/jaxb/</outputDirectory>
<clearOutputDir>false</clearOutputDir>
</configuration>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-lgpl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
<version>0.9.0.RELEASE</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -19,6 +19,8 @@ dependencies {
compile group: 'org.springframework', name: 'spring-webmvc', version: springVersion
compile group: 'org.springframework', name: 'spring-jdbc', version: springVersion
compile group: 'org.springframework', name: 'spring-tx', version: springVersion
compile group: 'org.springframework', name: 'spring-orm', version: springVersion
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.4.2.RELEASE'
compile group: 'org.springframework.security', name: 'spring-security-web', version: springSecurityVersion
compile group: 'org.springframework.security', name: 'spring-security-config', version: springSecurityVersion
compile group: 'org.springframework.security', name: 'spring-security-ldap', version: springSecurityVersion
......@@ -26,6 +28,7 @@ dependencies {
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
compile group: 'org.hsqldb', name: 'hsqldb', version: '2.3.2'
compile group: 'cglib', name: 'cglib', version: '3.1'
compile group: 'org.apache.openjpa', name: 'openjpa', version: '2.3.0'
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile group: 'org.mockito', name: 'mockito-core', version: '1.9.5'
......
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.thm.arsnova.connector</groupId>
<artifactId>connector</artifactId>
<version>0.41.0-SNAPSHOT</version>
</parent>
<artifactId>connector-service</artifactId>
<packaging>war</packaging>
<name>Connector Service WebApp</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.22</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.2.9</version>
</dependency>
<dependency>
<groupId>org.dbunit</groupId>
<artifactId>dbunit</artifactId>
<version>2.4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.thm.arsnova.connector</groupId>
<artifactId>connector-model</artifactId>
<version>[0.12,)</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-lgpl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
<version>0.9.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>de.thm.arsnova.connector</groupId>
<artifactId>connector-client</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package de.thm.arsnova.connector.config;
import java.sql.SQLException;
import java.util.Properties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -10,6 +11,11 @@ import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import de.thm.arsnova.connector.dao.ConnectorDao;
import de.thm.arsnova.connector.dao.IliasConnectorDaoImpl;
......@@ -56,6 +62,34 @@ public class AppConfig {
return dataSource;
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws SQLException {
LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
lef.setDataSource(configDataSource());
lef.setJpaVendorAdapter(jpaVendorAdapter());
lef.setPackagesToScan("de.thm.arsnova.connector.persistence.domain");
Properties jpaProperties = new Properties();
jpaProperties.put("openjpa.RuntimeUnenhancedClasses", "supported");
lef.setJpaProperties(jpaProperties);
lef.afterPropertiesSet();
return lef;
}
@Bean
public JpaVendorAdapter jpaVendorAdapter() {
OpenJpaVendorAdapter jpaVendorAdapter = new OpenJpaVendorAdapter();
jpaVendorAdapter.setShowSql(false);
jpaVendorAdapter.setGenerateDdl(true);
return jpaVendorAdapter;
}
@Bean
public PlatformTransactionManager transactionManager() throws SQLException {
JpaTransactionManager txManager = new JpaTransactionManager();
txManager.setEntityManagerFactory(entityManagerFactory().getObject());
return txManager;
}
@Bean
public ConnectorDao connectorDao() throws InstantiationException, IllegalAccessException, ClassNotFoundException {
return (ConnectorDao) Class.forName(env.getProperty("dao.implementation")).newInstance();
......
package de.thm.arsnova.connector.persistence.domain;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "configuration")
public class Configuration {
@Id
private String key;
private String value;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (obj == this) return true;
if (obj instanceof Configuration) {
Configuration other = (Configuration) obj;
if (
(this.key != null && this.key.equals(other.getKey()))
&& (this.value != null && this.value.equals(other.getValue()))
) return true;
}
return false;
}
}
package de.thm.arsnova.connector.persistence.domain;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import org.apache.openjpa.persistence.jdbc.Unique;
@Entity
@Table(name = "enabled_category")
public class EnabledCategory {
@Id
@Unique
int refId;
public int getRefId() {
return refId;
}
public void setRefId(int refId) {
this.refId = refId;
}
}
/**
* @author pcvolkmer
*
*/
package de.thm.arsnova.connector.persistence.domain;
\ No newline at end of file
package de.thm.arsnova.connector.persistence.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import de.thm.arsnova.connector.persistence.domain.Configuration;
@Repository
public interface ConfigurationRepository extends JpaRepository<Configuration, String> {
}
package de.thm.arsnova.connector.persistence.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import de.thm.arsnova.connector.persistence.domain.EnabledCategory;
@Repository
public interface EnabledCategoryRepository extends JpaRepository<EnabledCategory, Integer> {
}
package de.thm.arsnova.connector.services;
import de.thm.arsnova.connector.persistence.domain.Configuration;
public interface ConfigurationService {
Configuration getConfigurationElement(String key);
void setConfigurationElement(Configuration config);
}
package de.thm.arsnova.connector.services;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.thm.arsnova.connector.persistence.domain.Configuration;
import de.thm.arsnova.connector.persistence.repository.ConfigurationRepository;
@Service
public class ConfigurationServiceImpl implements ConfigurationService {
@Autowired
ConfigurationRepository repo;
@Override
public Configuration getConfigurationElement(String key) {
return repo.findOne(key);
}
@Override
public void setConfigurationElement(Configuration config) {
repo.save(config);
}
}
package de.thm.arsnova.connector.services;
import java.util.List;
import de.thm.arsnova.connector.persistence.domain.EnabledCategory;
public interface EnabledCategoryService {
public void enableCategory(int refId);
public void disableCategory(int refId);
public List<EnabledCategory> getEnabledCategories();
}
package de.thm.arsnova.connector.services;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import de.thm.arsnova.connector.persistence.domain.EnabledCategory;
import de.thm.arsnova.connector.persistence.repository.EnabledCategoryRepository;
@Service
public class EnabledCategoryServiceImpl implements EnabledCategoryService {
@Autowired
EnabledCategoryRepository repo;
@Override
public void enableCategory(int refId) {
EnabledCategory cat = new EnabledCategory();
cat.setRefId(refId);
repo.save(cat);
}
@Override
public void disableCategory(int refId) {
repo.delete(refId);
}
@Override
public List<EnabledCategory> getEnabledCategories() {
return repo.findAll();
}
}
package de.thm.arsnova.connector.config;
import java.sql.SQLException;
import java.util.Properties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import de.thm.arsnova.connector.services.ConfigurationService;
import de.thm.arsnova.connector.services.ConfigurationServiceImpl;
import de.thm.arsnova.connector.services.EnabledCategoryService;
import de.thm.arsnova.connector.services.EnabledCategoryServiceImpl;
@Configuration
@EnableJpaRepositories("de.thm.arsnova.connector.persistence.repository")
public class RepositoryTestConfig {
@Bean
public ConfigurationService configurationService() {
return new ConfigurationServiceImpl();
}
@Bean
public EnabledCategoryService enabledCategoryService() {
return new EnabledCategoryServiceImpl();
}
@Bean(name = "configDataSource")
public DriverManagerDataSource configDataSource() throws SQLException {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
dataSource.setUrl("jdbc:hsqldb:mem:testdb");
dataSource.setUsername("test");
dataSource.setPassword("");
return dataSource;
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws SQLException {
LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
lef.setDataSource(configDataSource());
lef.setJpaVendorAdapter(jpaVendorAdapter());
lef.setPackagesToScan("de.thm.arsnova.connector.persistence.domain");
Properties jpaProperties = new Properties();
jpaProperties.put("openjpa.RuntimeUnenhancedClasses", "supported");
lef.setJpaProperties(jpaProperties);
lef.afterPropertiesSet();
return lef;
}
@Bean
public OpenJpaVendorAdapter jpaVendorAdapter() {
OpenJpaVendorAdapter jpaVendorAdapter = new OpenJpaVendorAdapter();
jpaVendorAdapter.setShowSql(true);
jpaVendorAdapter.setGenerateDdl(true);
return jpaVendorAdapter;
}
@Bean
public PlatformTransactionManager transactionManager() throws SQLException {
JpaTransactionManager txManager = new JpaTransactionManager();
txManager.setEntityManagerFactory(entityManagerFactory().getObject());
return txManager;
}
}
package de.thm.arsnova.connector.services;
import static org.junit.Assert.assertEquals;
import javax.sql.DataSource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import de.thm.arsnova.connector.config.RepositoryTestConfig;
import de.thm.arsnova.connector.persistence.domain.Configuration;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( classes = {RepositoryTestConfig.class} )
public class ConfigurationServiceTest {
@Autowired
private ConfigurationService configurationService;
@Autowired
private DataSource dataSource;
@Test
public void testShouldNotReturnCourseForNotEnroledUser() {
Configuration config = new Configuration();
config.setKey("Testkey");
config.setValue("Testvalue");
configurationService.setConfigurationElement(config);
Configuration actual = configurationService.getConfigurationElement("Testkey");
assertEquals(config, actual);
}
}
\ No newline at end of file