diff --git a/pom.xml b/pom.xml index d6ec640b..b7d9e79d 100644 --- a/pom.xml +++ b/pom.xml @@ -235,7 +235,7 @@ commons-lang3 - + junit junit @@ -251,6 +251,11 @@ spring-security-test test + + com.h2database + h2 + test + \ No newline at end of file diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/datalayer/batis/BatisConfig.java b/src/main/java/ch/ethz/seb/sebserver/webservice/datalayer/batis/BatisConfig.java index 92a20d80..613ac98b 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/datalayer/batis/BatisConfig.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/datalayer/batis/BatisConfig.java @@ -19,12 +19,13 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Lazy; -import org.springframework.context.annotation.Profile; import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile; + @Configuration @MapperScan(basePackages = "ch.ethz.seb.sebserver.webservice.batis") -@Profile("dev-ws") +@WebServiceProfile @Import(DataSourceAutoConfiguration.class) public class BatisConfig { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/ClientSessionWebSecurityConfig.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/ClientSessionWebSecurityConfig.java index cc40cad5..ee5450d5 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/ClientSessionWebSecurityConfig.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/ClientSessionWebSecurityConfig.java @@ -214,11 +214,8 @@ public class ClientSessionWebSecurityConfig extends WebSecurityConfigurerAdapter final HttpServletResponse response, final AuthenticationException authenticationException) throws IOException, ServletException { - response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); - response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); - log.warn("Unauthorized Request: {}", request, authenticationException); - log.info("Redirect to login after unauthorized request"); - + log.warn("Unauthorized Request: {} : Redirect to login after unauthorized request", + request.getRequestURI()); // TODO define login redirect response.sendRedirect("/gui/"); } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/oauth/WebResourceServerConfiguration.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/oauth/WebResourceServerConfiguration.java index 31b89d59..c7481f89 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/oauth/WebResourceServerConfiguration.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/oauth/WebResourceServerConfiguration.java @@ -107,7 +107,7 @@ public abstract class WebResourceServerConfiguration extends ResourceServerConfi .sessionManagement() .sessionCreationPolicy(SessionCreationPolicy.STATELESS) .and() - .antMatcher(this.apiEndpoint) + .antMatcher(this.apiEndpoint + "/**") .authorizeRequests() .anyRequest() .authenticated() diff --git a/src/main/resources/config/application-test.properties b/src/main/resources/config/application-test.properties deleted file mode 100644 index 864e1a77..00000000 --- a/src/main/resources/config/application-test.properties +++ /dev/null @@ -1,3 +0,0 @@ -TODO - - diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/AdminAPITestController.java b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/AdminAPITestController.java similarity index 74% rename from src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/AdminAPITestController.java rename to src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/AdminAPITestController.java index 80b48356..ecb40d52 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/AdminAPITestController.java +++ b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/AdminAPITestController.java @@ -6,25 +6,20 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package ch.ethz.seb.sebserver.webservice.weblayer; +package ch.ethz.seb.sebserver.webservice.integration.api; import java.security.Principal; +import org.springframework.context.annotation.Profile; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; -import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile; - @RestController @RequestMapping("${sebserver.webservice.api.admin.endpoint}") -@WebServiceProfile +@Profile("test") public class AdminAPITestController { - public AdminAPITestController() { - System.out.println("************** TestController webservice"); - } - @RequestMapping(value = "/hello", method = RequestMethod.GET) public String helloFromWebService(final Principal principal) { return "Hello From Admin-Web-Service"; diff --git a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/AdministrationAPIIntegrationTest.java b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/AdministrationAPIIntegrationTest.java new file mode 100644 index 00000000..f46e998d --- /dev/null +++ b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/AdministrationAPIIntegrationTest.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2018 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +package ch.ethz.seb.sebserver.webservice.integration.api; + +import static org.junit.Assert.assertEquals; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.json.JacksonJsonParser; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.security.web.FilterChainProxy; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.ResultActions; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.context.WebApplicationContext; + +import ch.ethz.seb.sebserver.SEBServer; +import ch.ethz.seb.sebserver.gbl.JSONMapper; + +@RunWith(SpringRunner.class) +@SpringBootTest( + classes = SEBServer.class, + webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@ActiveProfiles("test") +@AutoConfigureMockMvc +public class AdministrationAPIIntegrationTest { + + @Value("${sebserver.webservice.api.admin.clientId}") + private String clientId; + @Value("${sebserver.webservice.api.admin.clientSecret}") + private String clientSecret; + @Value("${sebserver.webservice.api.admin.endpoint}") + private String endpoint; + + @Autowired + protected WebApplicationContext wac; + @Autowired + protected JSONMapper jsonMapper; + @Autowired + protected FilterChainProxy springSecurityFilterChain; + + protected MockMvc mockMvc; + + @Before + public void setup() { + this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac) + .addFilter(this.springSecurityFilterChain).build(); + } + + protected String obtainAccessToken(final String username, final String password) throws Exception { + final MultiValueMap params = new LinkedMultiValueMap<>(); + params.add("grant_type", "password"); + params.add("client_id", this.clientId); + params.add("username", username); + params.add("password", password); + + final ResultActions result = this.mockMvc.perform(post("/oauth/token") + .params(params) + .with(httpBasic(this.clientId, this.clientSecret)) + .accept("application/json;charset=UTF-8")) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json;charset=UTF-8")); + + final String resultString = result.andReturn().getResponse().getContentAsString(); + + final JacksonJsonParser jsonParser = new JacksonJsonParser(); + return jsonParser.parseMap(resultString).get("access_token").toString(); + } + + @Test + public void getHello_givenNoToken_thenRedirect() throws Exception { + this.mockMvc.perform(get(this.endpoint + "/hello")) + .andExpect(status().is3xxRedirection()); + } + + @Test + public void getHello_givenToken_thenOK() { + try { + final String accessToken = obtainAccessToken("user", "test"); + final String contentAsString = this.mockMvc.perform(get(this.endpoint + "/hello") + .header("Authorization", "Bearer " + accessToken)) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(); + + assertEquals("Hello From Admin-Web-Service", contentAsString); + } catch (final Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/ExamAPIIntegrationTest.java b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/ExamAPIIntegrationTest.java new file mode 100644 index 00000000..b34f9a2f --- /dev/null +++ b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/ExamAPIIntegrationTest.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2018 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +package ch.ethz.seb.sebserver.webservice.integration.api; + +import static org.junit.Assert.assertEquals; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.json.JacksonJsonParser; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.security.web.FilterChainProxy; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.ResultActions; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.context.WebApplicationContext; + +import ch.ethz.seb.sebserver.SEBServer; +import ch.ethz.seb.sebserver.gbl.JSONMapper; + +@RunWith(SpringRunner.class) +@SpringBootTest( + classes = SEBServer.class, + webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@ActiveProfiles("test") +@AutoConfigureMockMvc +public class ExamAPIIntegrationTest { + + @Value("${sebserver.webservice.api.exam.endpoint}") + private String endpoint; + + @Autowired + protected WebApplicationContext wac; + @Autowired + protected JSONMapper jsonMapper; + @Autowired + protected FilterChainProxy springSecurityFilterChain; + + protected MockMvc mockMvc; + + @Before + public void setup() { + this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac) + .addFilter(this.springSecurityFilterChain).build(); + } + + protected String obtainAccessToken(final String clientId, final String clientSecret) throws Exception { + final MultiValueMap params = new LinkedMultiValueMap<>(); + params.add("grant_type", "client_credentials"); + params.add("client_id", clientId); + + final ResultActions result = this.mockMvc.perform(post("/oauth/token") + .params(params) + .with(httpBasic(clientId, clientSecret)) + .accept("application/json;charset=UTF-8")) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json;charset=UTF-8")); + + final String resultString = result.andReturn().getResponse().getContentAsString(); + + final JacksonJsonParser jsonParser = new JacksonJsonParser(); + return jsonParser.parseMap(resultString).get("access_token").toString(); + } + + @Test + public void getHello_givenNoToken_thenUnauthorized() throws Exception { + this.mockMvc.perform(get(this.endpoint + "/hello")) + .andExpect(status().isUnauthorized()); + } + + @Test + public void getHello_givenToken_thenOK() { + try { + final String accessToken = obtainAccessToken("test", "test"); + final String contentAsString = this.mockMvc.perform(get(this.endpoint + "/hello") + .header("Authorization", "Bearer " + accessToken)) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(); + + assertEquals("Hello From Exam-Web-Service", contentAsString); + } catch (final Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/ExamAPITestController.java b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/ExamAPITestController.java similarity index 91% rename from src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/ExamAPITestController.java rename to src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/ExamAPITestController.java index f5574767..b0b60735 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/ExamAPITestController.java +++ b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/ExamAPITestController.java @@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package ch.ethz.seb.sebserver.webservice.weblayer; +package ch.ethz.seb.sebserver.webservice.integration.api; import java.security.Principal; diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties new file mode 100644 index 00000000..5d200506 --- /dev/null +++ b/src/test/resources/application-test.properties @@ -0,0 +1,19 @@ +server.address=localhost +server.port=8080 +server.servlet.context-path=/ + +spring.h2.console.enabled=true +spring.datasource.platform=h2 +spring.datasource.url=jdbc:h2:mem:test;MODE=MySQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE +spring.datasource.driver-class-name=org.h2.Driver + +sebserver.webservice.api.admin.clientId=testClient +sebserver.webservice.api.admin.clientSecret=testClient +sebserver.webservice.api.admin.endpoint=/admin-api +sebserver.webservice.api.admin.accessTokenValiditySeconds=1800 +sebserver.webservice.api.admin.refreshTokenValiditySeconds=-1 +sebserver.webservice.api.exam.endpoint=/exam-api +sebserver.webservice.api.exam.accessTokenValiditySeconds=1800 +sebserver.webservice.api.exam.refreshTokenValiditySeconds=-1 + + diff --git a/src/test/resources/schema-h2.sql b/src/test/resources/schema-h2.sql new file mode 100644 index 00000000..58172e74 --- /dev/null +++ b/src/test/resources/schema-h2.sql @@ -0,0 +1,372 @@ + + +-- ----------------------------------------------------- +-- Table `institution` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `institution` ; + +CREATE TABLE IF NOT EXISTS `institution` ( + `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + `name` VARCHAR(255) NOT NULL, + `authType` VARCHAR(45) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE INDEX `name_UNIQUE` (`name` ASC)) +; + + +-- ----------------------------------------------------- +-- Table `lms_setup` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `lms_setup` ; + +CREATE TABLE IF NOT EXISTS `lms_setup` ( + `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + `institution_id` BIGINT UNSIGNED NOT NULL, + `name` VARCHAR(255) NOT NULL, + `lms_type` VARCHAR(45) NOT NULL, + `lms_url` VARCHAR(255) NULL, + `lms_clientname` VARCHAR(255) NOT NULL, + `lms_clientsecret` VARCHAR(255) NOT NULL, + `lms_rest_api_token` VARCHAR(4000) NULL, + `seb_clientname` VARCHAR(255) NOT NULL, + `seb_clientsecret` VARCHAR(255) NOT NULL, + PRIMARY KEY (`id`), + INDEX `setupInstitutionRef_idx` (`institution_id` ASC), + CONSTRAINT `setupInstitutionRef` + FOREIGN KEY (`institution_id`) + REFERENCES `institution` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +; + + +-- ----------------------------------------------------- +-- Table `exam` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `exam` ; + +CREATE TABLE IF NOT EXISTS `exam` ( + `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + `lms_setup_id` BIGINT UNSIGNED NOT NULL, + `external_uuid` VARCHAR(255) NOT NULL, + `owner` VARCHAR(255) NOT NULL, + `supporter` VARCHAR(4000) NULL COMMENT 'comma separated list of user_uuid', + `type` VARCHAR(45) NOT NULL, + PRIMARY KEY (`id`), + INDEX `lms_setup_key_idx` (`lms_setup_id` ASC), + CONSTRAINT `lms_setup_key` + FOREIGN KEY (`lms_setup_id`) + REFERENCES `lms_setup` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +; + + +-- ----------------------------------------------------- +-- Table `client_connection` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `client_connection` ; + +CREATE TABLE IF NOT EXISTS `client_connection` ( + `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + `exam_id` BIGINT UNSIGNED NULL, + `status` VARCHAR(45) NOT NULL, + `connection_token` VARCHAR(255) NOT NULL, + `user_name` VARCHAR(255) NOT NULL, + `VDI` BIT(1) NOT NULL, + `client_address` VARCHAR(45) NOT NULL, + `virtual_client_address` VARCHAR(45) NULL, + PRIMARY KEY (`id`), + INDEX `connection_exam_ref_idx` (`exam_id` ASC), + CONSTRAINT `clientConnectionExamRef` + FOREIGN KEY (`exam_id`) + REFERENCES `exam` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +; + + +-- ----------------------------------------------------- +-- Table `client_event` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `client_event` ; + +CREATE TABLE IF NOT EXISTS `client_event` ( + `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + `connection_id` BIGINT UNSIGNED NOT NULL, + `user_identifier` VARCHAR(255) NOT NULL, + `type` INT(2) UNSIGNED NOT NULL, + `timestamp` BIGINT UNSIGNED NOT NULL, + `numeric_value` DECIMAL(10,4) NULL, + `text` VARCHAR(255) NULL, + PRIMARY KEY (`id`), + INDEX `eventConnectionRef_idx` (`connection_id` ASC), + CONSTRAINT `eventConnectionRef` + FOREIGN KEY (`connection_id`) + REFERENCES `client_connection` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +; + + +-- ----------------------------------------------------- +-- Table `indicator` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `indicator` ; + +CREATE TABLE IF NOT EXISTS `indicator` ( + `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + `exam_id` BIGINT UNSIGNED NOT NULL, + `type` VARCHAR(45) NOT NULL, + `name` VARCHAR(45) NOT NULL, + `color` VARCHAR(45) NOT NULL, + INDEX `indicator_exam_idx` (`exam_id` ASC), + PRIMARY KEY (`id`), + CONSTRAINT `exam_ref` + FOREIGN KEY (`exam_id`) + REFERENCES `exam` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +; + + +-- ----------------------------------------------------- +-- Table `configuration_node` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `configuration_node` ; + +CREATE TABLE IF NOT EXISTS `configuration_node` ( + `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + `institution_id` BIGINT UNSIGNED NOT NULL, + `owner` VARCHAR(255) NOT NULL, + `name` VARCHAR(255) NOT NULL, + `description` VARCHAR(4000) NULL, + `type` VARCHAR(45) NULL, + `template` VARCHAR(255) NULL, + PRIMARY KEY (`id`), + INDEX `configurationInstitutionRef_idx` (`institution_id` ASC), + CONSTRAINT `configurationInstitutionRef` + FOREIGN KEY (`institution_id`) + REFERENCES `institution` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +; + + +-- ----------------------------------------------------- +-- Table `configuration` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `configuration` ; + +CREATE TABLE IF NOT EXISTS `configuration` ( + `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + `configuration_node_id` BIGINT UNSIGNED NOT NULL, + `version` VARCHAR(255) NULL, + `version_date` DATETIME NULL, + `followup` INT(1) NOT NULL, + PRIMARY KEY (`id`), + INDEX `configurationNodeRef_idx` (`configuration_node_id` ASC), + CONSTRAINT `configurationNodeRef` + FOREIGN KEY (`configuration_node_id`) + REFERENCES `configuration_node` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +; + + +-- ----------------------------------------------------- +-- Table `configuration_attribute` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `configuration_attribute` ; + +CREATE TABLE IF NOT EXISTS `configuration_attribute` ( + `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + `name` VARCHAR(45) NOT NULL, + `type` VARCHAR(45) NOT NULL, + `parent_id` BIGINT UNSIGNED NULL, + `resources` VARCHAR(255) NULL, + `validator` VARCHAR(45) NULL, + `dependencies` VARCHAR(255) NULL, + `default_value` VARCHAR(255) NULL, + PRIMARY KEY (`id`), + INDEX `parent_ref_idx` (`parent_id` ASC), + CONSTRAINT `parent_ref` + FOREIGN KEY (`parent_id`) + REFERENCES `configuration_attribute` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +; + + +-- ----------------------------------------------------- +-- Table `configuration_value` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `configuration_value` ; + +CREATE TABLE IF NOT EXISTS `configuration_value` ( + `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + `configuration_id` BIGINT UNSIGNED NOT NULL, + `configuration_attribute_id` BIGINT UNSIGNED NOT NULL, + `list_index` INT NOT NULL DEFAULT 0, + `value` VARCHAR(255) NULL, + `text` MEDIUMTEXT NULL, + PRIMARY KEY (`id`), + INDEX `configuration_value_ref_idx` (`configuration_id` ASC), + INDEX `configuration_attribute_ref_idx` (`configuration_attribute_id` ASC), + CONSTRAINT `configuration_ref` + FOREIGN KEY (`configuration_id`) + REFERENCES `configuration` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `configuration_value_attribute_ref` + FOREIGN KEY (`configuration_attribute_id`) + REFERENCES `configuration_attribute` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +; + + +-- ----------------------------------------------------- +-- Table `orientation` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `orientation` ; + +CREATE TABLE IF NOT EXISTS `orientation` ( + `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + `config_attribute_id` BIGINT UNSIGNED NOT NULL, + `template` VARCHAR(255) NULL, + `view` VARCHAR(45) NOT NULL, + `group` VARCHAR(45) NULL, + `x_position` INT UNSIGNED NOT NULL DEFAULT 0, + `y_position` INT UNSIGNED NOT NULL DEFAULT 0, + `width` INT UNSIGNED NULL, + `height` INT UNSIGNED NULL, + PRIMARY KEY (`id`), + INDEX `config_attribute_orientation_rev_idx` (`config_attribute_id` ASC), + CONSTRAINT `config_attribute_orientation_rev` + FOREIGN KEY (`config_attribute_id`) + REFERENCES `configuration_attribute` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +; + + +-- ----------------------------------------------------- +-- Table `exam_configuration_map` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `exam_configuration_map` ; + +CREATE TABLE IF NOT EXISTS `exam_configuration_map` ( + `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + `exam_id` BIGINT UNSIGNED NOT NULL, + `configuration_node_id` BIGINT UNSIGNED NOT NULL, + `user_names` VARCHAR(4000) NULL, + PRIMARY KEY (`id`), + INDEX `exam_ref_idx` (`exam_id` ASC), + INDEX `configuration_map_ref_idx` (`configuration_node_id` ASC), + CONSTRAINT `exam_map_ref` + FOREIGN KEY (`exam_id`) + REFERENCES `exam` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `configuration_map_ref` + FOREIGN KEY (`configuration_node_id`) + REFERENCES `configuration_node` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +; + + +-- ----------------------------------------------------- +-- Table `user` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `user` ; + +CREATE TABLE IF NOT EXISTS `user` ( + `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + `institution_id` BIGINT UNSIGNED NULL, + `uuid` VARCHAR(255) NOT NULL, + `name` VARCHAR(255) NOT NULL, + `user_name` VARCHAR(255) NOT NULL, + `password` VARCHAR(255) NOT NULL, + `email` VARCHAR(255) NOT NULL, + `creation_date` DATETIME NOT NULL, + `active` INT(1) NOT NULL, + `locale` VARCHAR(45) NOT NULL, + `timeZone` VARCHAR(45) NOT NULL, + PRIMARY KEY (`id`), + INDEX `institutionRef_idx` (`institution_id` ASC), + CONSTRAINT `institutionRef` + FOREIGN KEY (`institution_id`) + REFERENCES `institution` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +; + + +-- ----------------------------------------------------- +-- Table `user_role` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `user_role` ; + +CREATE TABLE IF NOT EXISTS `user_role` ( + `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + `user_id` BIGINT UNSIGNED NOT NULL, + `role_name` VARCHAR(45) NOT NULL, + PRIMARY KEY (`id`), + INDEX `user_ref_idx` (`user_id` ASC), + CONSTRAINT `user_ref` + FOREIGN KEY (`user_id`) + REFERENCES `user` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +; + + +-- ----------------------------------------------------- +-- Table `oauth_access_token` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `oauth_access_token` ; + +CREATE TABLE IF NOT EXISTS `oauth_access_token` ( + `token_id` VARCHAR(255) NULL, + `token` BLOB NULL, + `authentication_id` VARCHAR(255) NULL, + `user_name` VARCHAR(255) NULL, + `client_id` VARCHAR(255) NULL, + `authentication` BLOB NULL, + `refresh_token` VARCHAR(255) NULL) +; + + +-- ----------------------------------------------------- +-- Table `oauth_refresh_token` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `oauth_refresh_token` ; + +CREATE TABLE IF NOT EXISTS `oauth_refresh_token` ( + `token_id` VARCHAR(255) NULL, + `token` BLOB NULL, + `authentication` BLOB NULL) +; + + +-- ----------------------------------------------------- +-- Table `threshold` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `threshold` ; + +CREATE TABLE IF NOT EXISTS `threshold` ( + `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + `indicator_id` BIGINT UNSIGNED NOT NULL, + `value` DECIMAL(10,4) NOT NULL, + `color` VARCHAR(45) NOT NULL, + PRIMARY KEY (`id`), + INDEX `indicator_threshold_id_idx` (`indicator_id` ASC), + CONSTRAINT `indicator_threshold_id` + FOREIGN KEY (`indicator_id`) + REFERENCES `indicator` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +; +