+1
-1
@@ -19,7 +19,7 @@ before_install:
|
|||||||
before_script:
|
before_script:
|
||||||
- mysql_upgrade --force -uroot
|
- mysql_upgrade --force -uroot
|
||||||
- mysql -u root -e 'CREATE DATABASE IF NOT EXISTS pandamonium;'
|
- mysql -u root -e 'CREATE DATABASE IF NOT EXISTS pandamonium;'
|
||||||
- mysql -u root -e "CREATE USER 'panda'@'localhost';"
|
- mysql -u root -e "CREATE USER 'panda'@'localhost' IDENTIFIED BY 'secret';"
|
||||||
- mysql -u root -e "GRANT ALL PRIVILEGES ON *.* to 'panda'@'localhost';"
|
- mysql -u root -e "GRANT ALL PRIVILEGES ON *.* to 'panda'@'localhost';"
|
||||||
- mysql -u root pandamonium < persistence/scripts/mysql/local_development.sql
|
- mysql -u root pandamonium < persistence/scripts/mysql/local_development.sql
|
||||||
|
|
||||||
|
|||||||
@@ -55,12 +55,13 @@ subprojects {
|
|||||||
compile 'org.slf4j:slf4j-api:1.7.21'
|
compile 'org.slf4j:slf4j-api:1.7.21'
|
||||||
compile "joda-time:joda-time:2.2"
|
compile "joda-time:joda-time:2.2"
|
||||||
compile('org.springframework:spring-context:5.0.9.RELEASE')
|
compile('org.springframework:spring-context:5.0.9.RELEASE')
|
||||||
|
|
||||||
|
compileOnly 'org.projectlombok:lombok:1.18.4'
|
||||||
|
|
||||||
testCompile group: 'junit', name: 'junit', version: '4.11'
|
testCompile group: 'junit', name: 'junit', version: '4.11'
|
||||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||||
testCompile('org.mockito:mockito-core:1.10.19') {exclude(group: 'org.hamcrest')}
|
testCompile('org.mockito:mockito-core:1.10.19') {exclude(group: 'org.hamcrest')}
|
||||||
|
|
||||||
compileOnly 'org.projectlombok:lombok:1.18.4'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
@@ -94,11 +95,10 @@ dependencies {
|
|||||||
compile 'org.codehaus.groovy:groovy-all:2.3.11'
|
compile 'org.codehaus.groovy:groovy-all:2.3.11'
|
||||||
compile 'org.apache.commons:commons-lang3:3.5'
|
compile 'org.apache.commons:commons-lang3:3.5'
|
||||||
// The production code uses the SLF4J logging API at compile time
|
// The production code uses the SLF4J logging API at compile time
|
||||||
compile 'org.slf4j:slf4j-api:1.7.21'
|
compile 'org.slf4j:slf4j-api:1.7.22'
|
||||||
compile "joda-time:joda-time:2.2"
|
compile "joda-time:joda-time:2.2"
|
||||||
compile("org.springframework.boot:spring-boot-starter-web")
|
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.0.5.RELEASE'
|
||||||
|
|
||||||
testCompile group: 'junit', name: 'junit', version: '4.11'
|
|
||||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||||
testCompile "org.springframework:spring-test:5.0.9.RELEASE"
|
testCompile "org.springframework:spring-test:5.0.9.RELEASE"
|
||||||
testCompile('org.mockito:mockito-core:1.10.19') {exclude(group: 'org.hamcrest')}
|
testCompile('org.mockito:mockito-core:1.10.19') {exclude(group: 'org.hamcrest')}
|
||||||
@@ -129,6 +129,6 @@ compileTestKotlin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wrapper {
|
wrapper {
|
||||||
gradleVersion = '4.10.2'
|
gradleVersion = '5.2.1'
|
||||||
distributionType = Wrapper.DistributionType.ALL
|
distributionType = Wrapper.DistributionType.ALL
|
||||||
}
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,5 +1,4 @@
|
|||||||
import org.gradle.internal.os.OperatingSystem;
|
import org.gradle.internal.os.OperatingSystem
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
}
|
}
|
||||||
@@ -10,23 +9,36 @@ version '1.0'
|
|||||||
|
|
||||||
sourceCompatibility = 1.8
|
sourceCompatibility = 1.8
|
||||||
|
|
||||||
|
sonarqube {
|
||||||
|
properties {
|
||||||
|
property "sonar.projectName", 'Pandamonium Persistence Tier'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '2.0.5.RELEASE'
|
||||||
|
compile group: 'org.apache.tomcat', name: 'tomcat-jdbc', version: '9.0.16'
|
||||||
|
compile group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '2.0.5.RELEASE'
|
||||||
|
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.0.5.RELEASE'
|
||||||
|
compile group: 'org.springframework', name: 'spring-aspects', version: '5.1.5.RELEASE'
|
||||||
|
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.4.1.Final'
|
||||||
|
compile group: 'com.vladmihalcea', name: 'hibernate-types-52', version: '2.4.1'
|
||||||
|
|
||||||
compile fileTree(dir: 'lib', include: '**/*.jar')
|
compile fileTree(dir: 'lib', include: '**/*.jar')
|
||||||
|
|
||||||
compile 'com.mchange:c3p0:0.9.5.2'
|
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.15'
|
||||||
compile 'mysql:mysql-connector-java:5.1.35'
|
|
||||||
compile 'org.hibernate:hibernate-validator:5.3.4.Final'
|
|
||||||
compile 'javax.validation:validation-api:1.1.0.Final'
|
|
||||||
compile('com.googlecode.log4jdbc:log4jdbc:1.2') {
|
compile('com.googlecode.log4jdbc:log4jdbc:1.2') {
|
||||||
exclude(group: 'org.slf4j')
|
exclude(group: 'org.slf4j')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.1.2.RELEASE'
|
||||||
|
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||||
testCompile 'javax.el:javax.el-api:3.0.0'
|
testCompile 'javax.el:javax.el-api:3.0.0'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task loadDb(type: Exec, group: 'Verification', description: 'Reloads the local database.') {
|
task loadDb(type: Exec, group: 'Verification', description: 'Reloads the local database.') {
|
||||||
@@ -35,6 +47,6 @@ task loadDb(type: Exec, group: 'Verification', description: 'Reloads the local d
|
|||||||
commandLine './loaddb.sh'
|
commandLine './loaddb.sh'
|
||||||
} else {
|
} else {
|
||||||
workingDir "./scripts/mysql"
|
workingDir "./scripts/mysql"
|
||||||
commandLine 'loaddb.bat'
|
commandLine=['cmd','/c','loaddb.bat']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
SET MYSQL_PWD=secret
|
set mysql_pwd = secret
|
||||||
FOR /R %%s IN (.\*.sql) do (
|
FOR /R %%s IN (*.sql) do (
|
||||||
echo **** %%s ****
|
echo **** %%s ****
|
||||||
echo mysql --batch --quick --raw --line-numbers --force --user=panda < %%s
|
mysql -u panda -psecret < %%s
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
export MYSQL_PWD=secret
|
|
||||||
|
|
||||||
for sqlScript in $( find . -name "*.sql" -print | sort);
|
for sqlScript in $( find . -name "*.sql" -print | sort);
|
||||||
do
|
do
|
||||||
echo "**** $sqlScript ****"
|
echo "**** $sqlScript ****"
|
||||||
mysql --batch --quick --raw --line-numbers --force --user=panda < $sqlScript
|
mysql -u panda -psecret < $sqlScript
|
||||||
done
|
done
|
||||||
+74
@@ -0,0 +1,74 @@
|
|||||||
|
package edu.msudenver.tsp.persistence;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.dto.Definition;
|
||||||
|
import edu.msudenver.tsp.persistence.dto.DefinitionDto;
|
||||||
|
import edu.msudenver.tsp.persistence.dto.Notation;
|
||||||
|
import edu.msudenver.tsp.persistence.repository.DefinitionRepository;
|
||||||
|
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 java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration(classes = PersistenceTestConfig.class)
|
||||||
|
public class DefinitionsIntegrationTest {
|
||||||
|
@Autowired private DefinitionRepository definitionRepository;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCRUDFunctionality() {
|
||||||
|
// Create a new definition
|
||||||
|
final DefinitionDto definitionDto = createDefinition();
|
||||||
|
final DefinitionDto savedDefinition = definitionRepository.save(definitionDto);
|
||||||
|
|
||||||
|
assertNotNull(savedDefinition);
|
||||||
|
assertEquals(Integer.valueOf(0), savedDefinition.getVersion());
|
||||||
|
|
||||||
|
final int id = savedDefinition.getId();
|
||||||
|
|
||||||
|
assertEquals("Test Name", savedDefinition.getName());
|
||||||
|
assertNotNull(savedDefinition.getDefinition());
|
||||||
|
assertNotNull(savedDefinition.getNotation());
|
||||||
|
|
||||||
|
final List<String> definitionsList = savedDefinition.getDefinition().getDefinitions();
|
||||||
|
final List<String> notationList = savedDefinition.getNotation().getNotations();
|
||||||
|
|
||||||
|
assertEquals(2, definitionsList.size());
|
||||||
|
assertEquals(1, notationList.size());
|
||||||
|
assertEquals("Test definition 1", definitionsList.get(0));
|
||||||
|
assertEquals("Test definition 2", definitionsList.get(1));
|
||||||
|
assertEquals("\\testLaTeX", notationList.get(0));
|
||||||
|
|
||||||
|
definitionRepository.delete(savedDefinition);
|
||||||
|
final Optional<DefinitionDto> deletedDefinition = definitionRepository.findById(id);
|
||||||
|
assertFalse(deletedDefinition.isPresent());
|
||||||
|
}
|
||||||
|
|
||||||
|
private DefinitionDto createDefinition() {
|
||||||
|
final List<String> definitionList = new ArrayList<>();
|
||||||
|
definitionList.add("Test definition 1");
|
||||||
|
definitionList.add("Test definition 2");
|
||||||
|
|
||||||
|
final Definition definition = new Definition();
|
||||||
|
definition.setDefinitions(definitionList);
|
||||||
|
|
||||||
|
final List<String> notationList = new ArrayList<>();
|
||||||
|
notationList.add("\\testLaTeX");
|
||||||
|
|
||||||
|
final Notation notation = new Notation();
|
||||||
|
notation.setNotations(notationList);
|
||||||
|
|
||||||
|
final DefinitionDto definitionDto = new DefinitionDto();
|
||||||
|
definitionDto.setName("Test Name");
|
||||||
|
definitionDto.setDefinition(definition);
|
||||||
|
definitionDto.setNotation(notation);
|
||||||
|
|
||||||
|
return definitionDto;
|
||||||
|
}
|
||||||
|
}
|
||||||
+93
@@ -0,0 +1,93 @@
|
|||||||
|
package edu.msudenver.tsp.persistence;
|
||||||
|
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.jpa.HibernatePersistenceProvider;
|
||||||
|
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||||
|
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
||||||
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||||
|
import org.springframework.jdbc.datasource.init.DataSourceInitializer;
|
||||||
|
import org.springframework.orm.hibernate5.HibernateTransactionManager;
|
||||||
|
import org.springframework.orm.hibernate5.LocalSessionFactoryBuilder;
|
||||||
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||||
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||||
|
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableJpaRepositories
|
||||||
|
@EnableJpaAuditing
|
||||||
|
@EntityScan(basePackages = "edu.msudenver.tsp.persistence")
|
||||||
|
public class PersistenceTestConfig {
|
||||||
|
@Bean
|
||||||
|
@Primary
|
||||||
|
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
|
||||||
|
final LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
|
||||||
|
entityManagerFactoryBean.setJpaVendorAdapter(vendorAdapter());
|
||||||
|
entityManagerFactoryBean.setDataSource(getDataSource());
|
||||||
|
entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class);
|
||||||
|
entityManagerFactoryBean.setPackagesToScan("edu.msudenver.tsp.persistence");
|
||||||
|
entityManagerFactoryBean.setJpaProperties(additionalProperties());
|
||||||
|
|
||||||
|
return entityManagerFactoryBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public JpaTransactionManager jpaTransactionManager() {
|
||||||
|
final JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
|
||||||
|
jpaTransactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
|
||||||
|
return jpaTransactionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HibernateJpaVendorAdapter vendorAdapter() {
|
||||||
|
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
|
||||||
|
vendorAdapter.setShowSql(true);
|
||||||
|
return vendorAdapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "dataSource")
|
||||||
|
public DataSource getDataSource(){
|
||||||
|
return DataSourceBuilder
|
||||||
|
.create()
|
||||||
|
.username("panda")
|
||||||
|
.password("secret")
|
||||||
|
.url("jdbc:mysql://127.0.0.1:3306/pandamonium?autoReconnect=true&useSSL=false")
|
||||||
|
.driverClassName("com.mysql.cj.jdbc.Driver")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "sessionFactory")
|
||||||
|
public SessionFactory getSessionFactory(final DataSource dataSource) {
|
||||||
|
final LocalSessionFactoryBuilder sessionFactoryBuilder = new LocalSessionFactoryBuilder(dataSource);
|
||||||
|
sessionFactoryBuilder.scanPackages("edu.msudenver.tsp.persistence.dto");
|
||||||
|
return sessionFactoryBuilder.buildSessionFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "transactionManager")
|
||||||
|
public HibernateTransactionManager getTransactionManager(final SessionFactory sessionFactory) {
|
||||||
|
return new HibernateTransactionManager(sessionFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public DataSourceInitializer dataSourceInitializer(final DataSource dataSource) {
|
||||||
|
final DataSourceInitializer initializer = new DataSourceInitializer();
|
||||||
|
initializer.setDataSource(dataSource);
|
||||||
|
return initializer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Properties additionalProperties() {
|
||||||
|
final Properties properties = new Properties();
|
||||||
|
properties.setProperty("hibernate.hbm2ddl.auto", "update");
|
||||||
|
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL8Dialect");
|
||||||
|
properties.setProperty("spring.jpa.show-sql", "true");
|
||||||
|
properties.setProperty("spring.datasource.tomcat.max-active", "1");
|
||||||
|
properties.setProperty("hibernate.id.new_generator_mappings","false");
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
}
|
||||||
+109
@@ -0,0 +1,109 @@
|
|||||||
|
package edu.msudenver.tsp.persistence;
|
||||||
|
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.jpa.HibernatePersistenceProvider;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||||
|
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
||||||
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||||
|
import org.springframework.jdbc.datasource.init.DataSourceInitializer;
|
||||||
|
import org.springframework.orm.hibernate5.HibernateTransactionManager;
|
||||||
|
import org.springframework.orm.hibernate5.LocalSessionFactoryBuilder;
|
||||||
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||||
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||||
|
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableJpaRepositories
|
||||||
|
@EnableJpaAuditing
|
||||||
|
@EntityScan
|
||||||
|
public class PersistenceApi {
|
||||||
|
|
||||||
|
@Value("${spring.datasource.username}") private String username;
|
||||||
|
@Value("${spring.datasource.password}") private String password;
|
||||||
|
@Value("${spring.jpa.hibernate.ddl-auto}") private String hibernateTablePolicy;
|
||||||
|
@Value("${spring.datasource.url}") private String databaseUrl;
|
||||||
|
@Value("${spring.jpa.properties.hibernate.dialect}") private String hibernateDialect;
|
||||||
|
@Value("${spring.jpa.show-sql}") private String showSql;
|
||||||
|
@Value("${spring.datasource.driver-class-name}") private String driverClassName;
|
||||||
|
@Value("${spring.datasource.tomcat.max-active}") private String tomcatPoolMaxActive;
|
||||||
|
|
||||||
|
public static void main(final String[] args) {
|
||||||
|
SpringApplication.run(PersistenceApi.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Primary
|
||||||
|
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
|
||||||
|
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
|
||||||
|
em.setJpaVendorAdapter(vendorAdapter());
|
||||||
|
em.setDataSource(getDataSource());
|
||||||
|
em.setPersistenceProviderClass(HibernatePersistenceProvider.class);
|
||||||
|
em.setPackagesToScan("edu.msudenver.tsp.persistence");
|
||||||
|
em.setJpaProperties(additionalProperties());
|
||||||
|
|
||||||
|
return em;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public JpaTransactionManager jpaTransactionManager() {
|
||||||
|
final JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
|
||||||
|
jpaTransactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
|
||||||
|
return jpaTransactionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HibernateJpaVendorAdapter vendorAdapter() {
|
||||||
|
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
|
||||||
|
vendorAdapter.setShowSql(true);
|
||||||
|
return vendorAdapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "dataSource")
|
||||||
|
public DataSource getDataSource(){
|
||||||
|
return DataSourceBuilder
|
||||||
|
.create()
|
||||||
|
.username(username)
|
||||||
|
.password(password)
|
||||||
|
.url(databaseUrl)
|
||||||
|
.driverClassName(driverClassName)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "sessionFactory")
|
||||||
|
public SessionFactory getSessionFactory(final DataSource dataSource) {
|
||||||
|
final LocalSessionFactoryBuilder sessionFactoryBuilder = new LocalSessionFactoryBuilder(dataSource);
|
||||||
|
sessionFactoryBuilder.scanPackages("edu.msudenver.tsp.persistence.dto");
|
||||||
|
return sessionFactoryBuilder.buildSessionFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "transactionManager")
|
||||||
|
public HibernateTransactionManager getTransactionManager(final SessionFactory sessionFactory) {
|
||||||
|
return new HibernateTransactionManager(sessionFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public DataSourceInitializer dataSourceInitializer(final DataSource dataSource) {
|
||||||
|
final DataSourceInitializer initializer = new DataSourceInitializer();
|
||||||
|
initializer.setDataSource(dataSource);
|
||||||
|
return initializer;
|
||||||
|
}
|
||||||
|
|
||||||
|
Properties additionalProperties() {
|
||||||
|
final Properties properties = new Properties();
|
||||||
|
properties.setProperty("hibernate.hbm2ddl.auto", "update");
|
||||||
|
properties.setProperty("hibernate.dialect", hibernateDialect);
|
||||||
|
properties.setProperty("spring.jpa.show-sql", showSql);
|
||||||
|
properties.setProperty("spring.datasource.tomcat.max-active", tomcatPoolMaxActive);
|
||||||
|
properties.setProperty("hibernate.id.new_generator_mappings","false");
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
}
|
||||||
-10
@@ -1,10 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@ComponentScan
|
|
||||||
public class PersistenceConfig {
|
|
||||||
|
|
||||||
}
|
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.dto.AccountsDto;
|
||||||
|
import edu.msudenver.tsp.persistence.repository.AccountsRepository;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@AllArgsConstructor
|
||||||
|
@RequestMapping("/accounts")
|
||||||
|
public class AccountController {
|
||||||
|
private final AccountsRepository accountsRepository;
|
||||||
|
|
||||||
|
@GetMapping("/")
|
||||||
|
public @ResponseBody Iterable<AccountsDto> getListOfAccounts() {
|
||||||
|
return accountsRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public @ResponseBody
|
||||||
|
Optional<AccountsDto> getAccountById(@PathVariable("id") final Integer id) {
|
||||||
|
return accountsRepository.findById(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
+126
@@ -0,0 +1,126 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.dto.DefinitionDto;
|
||||||
|
import edu.msudenver.tsp.persistence.repository.DefinitionRepository;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.util.StopWatch;
|
||||||
|
import org.springframework.validation.BindingResult;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.groups.Default;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@AllArgsConstructor
|
||||||
|
@RequestMapping(path = "/definitions/")
|
||||||
|
public class DefinitionController {
|
||||||
|
private final DefinitionRepository definitionRepository;
|
||||||
|
|
||||||
|
@GetMapping("/")
|
||||||
|
public @ResponseBody
|
||||||
|
ResponseEntity<Iterable<DefinitionDto>> getAllDefinitions() {
|
||||||
|
LOG.info("Received request to list all definitions");
|
||||||
|
|
||||||
|
LOG.debug("Querying for list of all definitions");
|
||||||
|
final StopWatch stopWatch = new StopWatch();
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
final List<DefinitionDto> listOfDefinitions = definitionRepository.findAll();
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
|
||||||
|
LOG.debug("Successfully completed query. Query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||||
|
LOG.info("Returning list of all definition with size " + listOfDefinitions.size());
|
||||||
|
|
||||||
|
return new ResponseEntity<>(listOfDefinitions, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public @ResponseBody
|
||||||
|
ResponseEntity<DefinitionDto> getDefinitionById(@PathVariable("id") final Integer id) {
|
||||||
|
LOG.info("Received request to query for definition with id " + id);
|
||||||
|
if (id == null) {
|
||||||
|
LOG.error("ERROR: ID was null");
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.debug("Querying for definition with id " + id);
|
||||||
|
|
||||||
|
final StopWatch stopWatch = new StopWatch();
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
final Optional<DefinitionDto> definition = definitionRepository.findById(id);
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
|
||||||
|
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||||
|
return definition.map(definitionDto -> {
|
||||||
|
LOG.info("Returning definition with id " + id);
|
||||||
|
return new ResponseEntity<>(definitionDto, HttpStatus.OK);
|
||||||
|
}).orElseGet(
|
||||||
|
() -> {
|
||||||
|
LOG.warn("No definition was found with id " + id);
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/")
|
||||||
|
@Validated({DefinitionDto.Insert.class, Default.class})
|
||||||
|
public @ResponseBody ResponseEntity<DefinitionDto> insertDefinition(
|
||||||
|
@Valid @RequestBody final DefinitionDto definitionDto,
|
||||||
|
final BindingResult bindingResult) {
|
||||||
|
LOG.info("Received request to insert a new definition");
|
||||||
|
if (bindingResult.hasErrors()) {
|
||||||
|
LOG.error("Binding result is unprocessable");
|
||||||
|
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (definitionDto == null) {
|
||||||
|
LOG.error("Passed entity is unprocessable");
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.debug("Saving new definition");
|
||||||
|
|
||||||
|
final StopWatch stopWatch = new StopWatch();
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
final DefinitionDto savedDefinition = definitionRepository.save(definitionDto);
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||||
|
|
||||||
|
LOG.info("Returning the newly created definition with id " + savedDefinition.getId());
|
||||||
|
return new ResponseEntity<>(savedDefinition, HttpStatus.CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public @ResponseBody ResponseEntity<Void> deleteDefinitionById(@PathVariable("id") final Integer id) {
|
||||||
|
LOG.info("Received request to delete definition with id " + id);
|
||||||
|
if (id == null) {
|
||||||
|
LOG.error("Specified id is null");
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.debug("Deleting definition with id " + id);
|
||||||
|
|
||||||
|
final StopWatch stopWatch = new StopWatch();
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
definitionRepository.deleteById(id);
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
|
||||||
|
LOG.debug("Received response from server: query took " + stopWatch.getTotalTimeMillis() + "ms to complete");
|
||||||
|
|
||||||
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.repository.NotationRepository;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class NotationController {
|
||||||
|
final private NotationRepository notationRepository;
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.repository.ProofRepository;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ProofController {
|
||||||
|
final private ProofRepository proofRepository;
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.repository.TheoremRepository;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class TheoremController {
|
||||||
|
final private TheoremRepository theoremRepository;
|
||||||
|
}
|
||||||
-28
@@ -1,28 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.dao;
|
|
||||||
|
|
||||||
class BaseDao {
|
|
||||||
|
|
||||||
// <T> T findById(final int id) {
|
|
||||||
// //TODO insert DB calls for finding objects by their ID's
|
|
||||||
// }
|
|
||||||
|
|
||||||
// <T> List<T> queryForList(final String query) {
|
|
||||||
// //TODO insert DB calls for querying for lists based on the specified query
|
|
||||||
// }
|
|
||||||
|
|
||||||
// <T> T save(final T t) {
|
|
||||||
// //TODO insert DB calls here for insert and update
|
|
||||||
// }
|
|
||||||
|
|
||||||
<T> void delete(final T t) {
|
|
||||||
//TODO insert DB calls here to delete
|
|
||||||
}
|
|
||||||
|
|
||||||
// private <T> T insert(final T object) {
|
|
||||||
// // TODO insert DB calls to insert records
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private <T> T update(final T object) {
|
|
||||||
// //TODO insert DB calls to update records
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
-4
@@ -1,4 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.dao;
|
|
||||||
|
|
||||||
public class DefinitionDao extends BaseDao {
|
|
||||||
}
|
|
||||||
-4
@@ -1,4 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.dao;
|
|
||||||
|
|
||||||
public class NotationDao extends BaseDao {
|
|
||||||
}
|
|
||||||
-4
@@ -1,4 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.dao;
|
|
||||||
|
|
||||||
public class ProofDao extends BaseDao {
|
|
||||||
}
|
|
||||||
-4
@@ -1,4 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.dao;
|
|
||||||
|
|
||||||
public class TheoremDao extends BaseDao {
|
|
||||||
}
|
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.EntityListeners;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Entity(name = "accounts")
|
||||||
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class AccountsDto extends BaseDto implements Serializable {
|
||||||
|
@Size(max = 50) private String username;
|
||||||
|
@Size(max = 256) private String password;
|
||||||
|
@NotNull @JsonProperty("administrator_status") private boolean administratorStatus;
|
||||||
|
@Temporal(TemporalType.DATE) @JsonProperty("last_login") private Date lastLogin;
|
||||||
|
|
||||||
|
public static final long serialVersionUID = 7095627971593953734L;
|
||||||
|
}
|
||||||
+34
-3
@@ -1,9 +1,40 @@
|
|||||||
package edu.msudenver.tsp.persistence.dto;
|
package edu.msudenver.tsp.persistence.dto;
|
||||||
|
|
||||||
|
import com.vladmihalcea.hibernate.type.array.IntArrayType;
|
||||||
|
import com.vladmihalcea.hibernate.type.array.StringArrayType;
|
||||||
|
import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
|
||||||
|
import com.vladmihalcea.hibernate.type.json.JsonNodeBinaryType;
|
||||||
|
import com.vladmihalcea.hibernate.type.json.JsonNodeStringType;
|
||||||
|
import com.vladmihalcea.hibernate.type.json.JsonStringType;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.hibernate.annotations.TypeDef;
|
||||||
|
import org.hibernate.annotations.TypeDefs;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
class BaseDto {
|
@AllArgsConstructor
|
||||||
private String id;
|
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||||
private int version;
|
@MappedSuperclass
|
||||||
|
@TypeDefs({
|
||||||
|
@TypeDef(name = "string-array", typeClass = StringArrayType.class),
|
||||||
|
@TypeDef(name = "int-array", typeClass = IntArrayType.class),
|
||||||
|
@TypeDef(name = "json", typeClass = JsonStringType.class),
|
||||||
|
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class),
|
||||||
|
@TypeDef(name = "jsonb-node", typeClass = JsonNodeBinaryType.class),
|
||||||
|
@TypeDef(name = "json-node", typeClass = JsonNodeStringType.class),
|
||||||
|
})
|
||||||
|
public class BaseDto implements Serializable {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private int id;
|
||||||
|
@Version
|
||||||
|
private Integer version;
|
||||||
|
|
||||||
|
public static final long serialVersionUID = -1686252381978213945L;
|
||||||
}
|
}
|
||||||
|
|||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.dto;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
public class Definition implements Serializable {
|
||||||
|
private List<String> definitions;
|
||||||
|
|
||||||
|
public static final long serialVersionUID = -2208496232532214840L;
|
||||||
|
}
|
||||||
+31
-1
@@ -1,4 +1,34 @@
|
|||||||
package edu.msudenver.tsp.persistence.dto;
|
package edu.msudenver.tsp.persistence.dto;
|
||||||
|
|
||||||
public class DefinitionDto extends BaseDto {
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.hibernate.annotations.Type;
|
||||||
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.EntityListeners;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Entity(name = "definitions")
|
||||||
|
@Table(name = "definitions")
|
||||||
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class DefinitionDto extends BaseDto implements Serializable {
|
||||||
|
@NotBlank(groups = Insert.class, message = "A name must be specified")
|
||||||
|
@Size(min = 1, max = 200, message = "Must be between 1 and 200 characters")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@NotBlank(groups = Insert.class, message = "At least one (1) definition must be specified")
|
||||||
|
@Type(type = "json") @Column(columnDefinition = "jsonb") private Definition definition;
|
||||||
|
|
||||||
|
@Type(type = "json") @Column(columnDefinition = "jsonb") private Notation notation;
|
||||||
|
|
||||||
|
public static final long serialVersionUID = -5314619286352932857L;
|
||||||
|
|
||||||
|
public interface Insert {}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.dto;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
public class Notation implements Serializable {
|
||||||
|
private List<String> notations;
|
||||||
|
public static final long serialVersionUID = 2301438318932336121L;
|
||||||
|
}
|
||||||
-11
@@ -1,11 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.manager;
|
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dao.DefinitionDao;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class DefinitionManager {
|
|
||||||
final private DefinitionDao definitionDao;
|
|
||||||
}
|
|
||||||
-10
@@ -1,10 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.manager;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@ComponentScan
|
|
||||||
public class ManagerConfig {
|
|
||||||
|
|
||||||
}
|
|
||||||
-11
@@ -1,11 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.manager;
|
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dao.NotationDao;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class NotationManager {
|
|
||||||
final private NotationDao notationDao;
|
|
||||||
}
|
|
||||||
-11
@@ -1,11 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.manager;
|
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dao.ProofDao;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class ProofManager {
|
|
||||||
final private ProofDao proofDao;
|
|
||||||
}
|
|
||||||
-11
@@ -1,11 +0,0 @@
|
|||||||
package edu.msudenver.tsp.persistence.manager;
|
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.dao.TheoremDao;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class TheoremManager {
|
|
||||||
final private TheoremDao theoremDao;
|
|
||||||
}
|
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.repository;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.dto.AccountsDto;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface AccountsRepository extends JpaRepository<AccountsDto, Integer> {
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.repository;
|
||||||
|
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.dto.DefinitionDto;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface DefinitionRepository extends JpaRepository<DefinitionDto, Integer> {
|
||||||
|
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.repository;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.dto.BaseDto;
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
|
public interface NotationRepository extends CrudRepository<BaseDto, Long> {
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.repository;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.dto.BaseDto;
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
|
public interface ProofRepository extends CrudRepository<BaseDto, Long> {
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.repository;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.dto.BaseDto;
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
|
public interface TheoremRepository extends CrudRepository<BaseDto, Long> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
spring.jpa.hibernate.ddl-auto = none
|
||||||
|
spring.jpa.database=mysql
|
||||||
|
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/pandamonium?autoReconnect=true&useSSL=false
|
||||||
|
spring.datasource.username=panda
|
||||||
|
spring.datasource.password=secret
|
||||||
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
|
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL8Dialect
|
||||||
|
spring.jpa.show-sql = true
|
||||||
|
spring.datasource.tomcat.test-while-idle=true
|
||||||
|
spring.datasource.tomcat.validation-query=SELECT 1
|
||||||
|
logging.level.org.springframework.web=DEBUG
|
||||||
|
spring.datasource.tomcat.max-active=5
|
||||||
|
server.port=8090
|
||||||
+169
@@ -0,0 +1,169 @@
|
|||||||
|
package edu.msudenver.tsp.persistence.controller;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.persistence.dto.Definition;
|
||||||
|
import edu.msudenver.tsp.persistence.dto.DefinitionDto;
|
||||||
|
import edu.msudenver.tsp.persistence.dto.Notation;
|
||||||
|
import edu.msudenver.tsp.persistence.repository.DefinitionRepository;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.validation.BindingResult;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static junit.framework.TestCase.assertTrue;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Matchers.anyInt;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
@WebMvcTest(controllers = DefinitionController.class)
|
||||||
|
public class DefinitionControllerTest {
|
||||||
|
@Mock private DefinitionRepository definitionRepository;
|
||||||
|
@InjectMocks private DefinitionController definitionController;
|
||||||
|
@Mock private BindingResult bindingResult;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllDefinitions() {
|
||||||
|
final DefinitionDto definitionDto = createDefinition();
|
||||||
|
final List<DefinitionDto> definitionDtoList = new ArrayList<>();
|
||||||
|
definitionDtoList.add(definitionDto);
|
||||||
|
definitionDtoList.add(definitionDto);
|
||||||
|
|
||||||
|
when(definitionRepository.findAll()).thenReturn(definitionDtoList);
|
||||||
|
|
||||||
|
final ResponseEntity<Iterable<DefinitionDto>> responseEntity = definitionController.getAllDefinitions();
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
|
assertTrue(responseEntity.hasBody());
|
||||||
|
assertNotNull(responseEntity.getBody());
|
||||||
|
|
||||||
|
responseEntity.getBody().forEach(definition -> assertEquals(definition, definitionDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDefinitionsById() {
|
||||||
|
final DefinitionDto definitionDto = createDefinition();
|
||||||
|
when(definitionRepository.findById(anyInt())).thenReturn(Optional.ofNullable(definitionDto));
|
||||||
|
|
||||||
|
final ResponseEntity<DefinitionDto> responseEntity = definitionController.getDefinitionById(1);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertTrue(responseEntity.hasBody());
|
||||||
|
assertNotNull(responseEntity.getBody());
|
||||||
|
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
||||||
|
assertEquals(definitionDto, responseEntity.getBody());
|
||||||
|
verify(definitionRepository).findById(anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDefinitionById_nullId() {
|
||||||
|
final ResponseEntity responseEntity = definitionController.getDefinitionById(null);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(definitionRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDefinitionById_noDefinitionFound() {
|
||||||
|
when(definitionRepository.findById(anyInt())).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
final ResponseEntity responseEntity = definitionController.getDefinitionById(1);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
|
||||||
|
verify(definitionRepository).findById(anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsertDefinition() {
|
||||||
|
final DefinitionDto definitionDto = createDefinition();
|
||||||
|
when(definitionRepository.save(any(DefinitionDto.class))).thenReturn(definitionDto);
|
||||||
|
|
||||||
|
final ResponseEntity<DefinitionDto> responseEntity = definitionController.insertDefinition(definitionDto, bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertTrue(responseEntity.hasBody());
|
||||||
|
assertNotNull(responseEntity.getBody());
|
||||||
|
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
|
||||||
|
assertEquals(definitionDto, responseEntity.getBody());
|
||||||
|
verify(definitionRepository).save(any(DefinitionDto.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsertDefinition_definitionDtoIsNull() {
|
||||||
|
final ResponseEntity responseEntity = definitionController.insertDefinition(null, bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(definitionRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsertDefinition_bindingResultHasErrors() {
|
||||||
|
final DefinitionDto definitionDto = createDefinition();
|
||||||
|
when(bindingResult.hasErrors()).thenReturn(true);
|
||||||
|
|
||||||
|
final ResponseEntity responseEntity = definitionController.insertDefinition(definitionDto, bindingResult);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(definitionRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteDefinitionById() {
|
||||||
|
doNothing().when(definitionRepository).deleteById(anyInt());
|
||||||
|
|
||||||
|
final ResponseEntity responseEntity = definitionController.deleteDefinitionById(1);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode());
|
||||||
|
verify(definitionRepository).deleteById(anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteDefinitionById_nullId() {
|
||||||
|
final ResponseEntity responseEntity = definitionController.deleteDefinitionById(null);
|
||||||
|
|
||||||
|
assertNotNull(responseEntity);
|
||||||
|
assertFalse(responseEntity.hasBody());
|
||||||
|
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
|
||||||
|
verifyZeroInteractions(definitionRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DefinitionDto createDefinition() {
|
||||||
|
final List<String> definitionList = new ArrayList<>();
|
||||||
|
definitionList.add("Test definition 1");
|
||||||
|
|
||||||
|
final Definition definition = new Definition();
|
||||||
|
definition.setDefinitions(definitionList);
|
||||||
|
|
||||||
|
final List<String> notationList = new ArrayList<>();
|
||||||
|
notationList.add("\\testLaTeX");
|
||||||
|
|
||||||
|
final Notation notation = new Notation();
|
||||||
|
notation.setNotations(notationList);
|
||||||
|
|
||||||
|
final DefinitionDto definitionDto = new DefinitionDto();
|
||||||
|
definitionDto.setName("Test Name");
|
||||||
|
definitionDto.setDefinition(definition);
|
||||||
|
definitionDto.setNotation(notation);
|
||||||
|
|
||||||
|
return definitionDto;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,12 @@ version '1.0'
|
|||||||
|
|
||||||
sourceCompatibility = 1.8
|
sourceCompatibility = 1.8
|
||||||
|
|
||||||
|
sonarqube {
|
||||||
|
properties {
|
||||||
|
property "sonar.projectName", 'Theorem Prover Services'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-14
@@ -1,26 +1,26 @@
|
|||||||
package edu.msudenver.tsp.services.parser;
|
package edu.msudenver.tsp.services.parser;
|
||||||
|
|
||||||
import edu.msudenver.tsp.persistence.manager.DefinitionManager;
|
import edu.msudenver.tsp.persistence.controller.DefinitionController;
|
||||||
import edu.msudenver.tsp.persistence.manager.NotationManager;
|
import edu.msudenver.tsp.persistence.controller.NotationController;
|
||||||
import edu.msudenver.tsp.persistence.manager.ProofManager;
|
import edu.msudenver.tsp.persistence.controller.ProofController;
|
||||||
import edu.msudenver.tsp.persistence.manager.TheoremManager;
|
import edu.msudenver.tsp.persistence.controller.TheoremController;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class ParserService {
|
class ParserService {
|
||||||
private final DefinitionManager definitionManager;
|
private final DefinitionController definitionController;
|
||||||
private final TheoremManager theoremManager;
|
private final TheoremController theoremController;
|
||||||
private final NotationManager notationManager;
|
private final NotationController notationController;
|
||||||
private final ProofManager proofManager;
|
private final ProofController proofController;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public ParserService(final DefinitionManager definitionManager, final TheoremManager theoremManager,
|
public ParserService(final DefinitionController definitionController, final TheoremController theoremController,
|
||||||
final NotationManager notationManager, final ProofManager proofManager) {
|
final NotationController notationController, final ProofController proofController) {
|
||||||
this.definitionManager = definitionManager;
|
this.definitionController = definitionController;
|
||||||
this.theoremManager = theoremManager;
|
this.theoremController = theoremController;
|
||||||
this.notationManager = notationManager;
|
this.notationController = notationController;
|
||||||
this.proofManager = proofManager;
|
this.proofController = proofController;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
package edu.msudenver.tsp.website;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class HelloController {
|
|
||||||
|
|
||||||
@RequestMapping("/")
|
|
||||||
public String index() {
|
|
||||||
return "Welcome to Project Pandamonium!";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package edu.msudenver.tsp.website;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@ComponentScan
|
|
||||||
//@PropertySource("classpath:development.properties")
|
|
||||||
public class WebsiteConfig {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
package edu.msudenver.tsp.website;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
public class HelloControllerTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test() {
|
|
||||||
assertEquals(3, 3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-15
@@ -1,15 +0,0 @@
|
|||||||
package edu.msudenver.tsp.website.integrationTest;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
public class HelloControllerIntegrationTest {
|
|
||||||
@Test
|
|
||||||
public void test() {
|
|
||||||
assertEquals(3,3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,6 +7,12 @@ version '1.0'
|
|||||||
|
|
||||||
sourceCompatibility = 1.8
|
sourceCompatibility = 1.8
|
||||||
|
|
||||||
|
sonarqube {
|
||||||
|
properties {
|
||||||
|
property "sonar.projectName", 'Parsing and Proofs Utilities'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user