Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to yml #86

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 0 additions & 69 deletions src/main/resources/application.properties

This file was deleted.

56 changes: 56 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
server:
servlet:
context-path: /record-manager

management:
endpoints:
web:
exposure:
include: health

persistenceDriver: cz.cvut.kbss.ontodriver.rdf4j.Rdf4jDataSou# URL of repository that holds main data of the application

repositoryUrl: http://localhost:7200/repositories/record-manager-app

formGenRepositoryUrl: http://localhost:7200/repositories/record-manager-formgen

formGenServiceUrl: http://localhost:8080/s-pipes/service?_pId=transform&sgovRepositoryUrl=https%3A%2F%2Fgraphdb.onto.fel.cvut.cz%2Frepositories%2Fkodi-slovnik-gov-cz

security:
sameSite: ""
provider: internal
oidc:
roleClaim: realm_access.roles
cors:
allowedOrigins: ""

appContext: http://localhost:3000/record-manager

smtp:
host: smtp.gmail.com
port: 587
user: [email protected]
password: AdminOrganization123

email:
displayName: Record Manager
from: ""
replyTo: ""
cc: ""
bcc: ""
passwordResetSubject: Password Reset
passwordResetContent: >-
<div><p>Dear user {{username}}, </p><p>please set your new password here: {{link}} </p><p>Best regards, <br>StudyManager</p></div>
invitationSubject: Welcome to study
invitationContent: >-
<div><p>Dear {{name}}, </p><p>you have been invited to a study running at {{appContext}}. </p><p>Your username is: {{username}}. </p>\
<p>Please set your password here: {{link}} </p><p>Best regards, <br>StudyManager</p></div>
passwordChangeSubject: Password Change
passwordChangeContent: >-
<div><p>Dear user {{username}}, </p><p>your password has been changed. </p><p>Best regards, <br>RecordManager</p></div>
profileUpdateSubject: Profile updated by a study coordinator
profileUpdateContent: >-
<div><p>Dear user {{username}}, </p><p>your profile at {{appContext}} has been updated by a study coordinator. </p><p>Best regards, <br>RecordManager</p></div>

records:
allowedRejectReason: true
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.test.context.junit.jupiter.SpringExtension;

@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {TestPersistenceConfig.class})
@ContextConfiguration(classes = {TestPersistenceConfig.class}, initializers = {ConfigDataApplicationContextInitializer.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@ActiveProfiles("test")
abstract public class BaseDaoTestRunner extends TransactionalTestRunner {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cz.cvut.kbss.study.persistence;

import org.springframework.boot.DefaultBootstrapContext;
import org.springframework.boot.DefaultPropertiesPropertySource;
import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor;
import org.springframework.boot.env.RandomValuePropertySource;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

public class ConfigDataApplicationContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
public ConfigDataApplicationContextInitializer() {
}

public void initialize(ConfigurableApplicationContext applicationContext) {
ConfigurableEnvironment environment = applicationContext.getEnvironment();
RandomValuePropertySource.addToEnvironment(environment);
DefaultBootstrapContext bootstrapContext = new DefaultBootstrapContext();
ConfigDataEnvironmentPostProcessor.applyTo(environment, applicationContext, bootstrapContext, new String[0]);
bootstrapContext.close(applicationContext);
DefaultPropertiesPropertySource.moveToEnd(environment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,20 @@
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;

@Configuration
@PropertySource("classpath:application.properties")
@EnableConfigurationProperties(cz.cvut.kbss.study.util.Configuration.class)
@Profile("test")
public class TestFormGenPersistenceFactory {

private static final String URL_PROPERTY = "test." + ConfigParam.FORM_GEN_REPOSITORY_URL;
private static final String DRIVER_PROPERTY = "test." + ConfigParam.PERSISTENCE_DRIVER;

@Autowired
private Environment environment;
private cz.cvut.kbss.study.util.Configuration config;

private EntityManagerFactory emf;

Expand All @@ -36,8 +34,8 @@ public EntityManagerFactory getEntityManagerFactory() {
@PostConstruct
private void init() {
final Map<String, String> properties = TestPersistenceFactory.getDefaultProperties();
properties.put(JOPAPersistenceProperties.ONTOLOGY_PHYSICAL_URI_KEY, environment.getProperty(URL_PROPERTY));
properties.put(JOPAPersistenceProperties.DATA_SOURCE_CLASS, environment.getProperty(DRIVER_PROPERTY));
properties.put(JOPAPersistenceProperties.ONTOLOGY_PHYSICAL_URI_KEY, config.getFormGenRepositoryUrl());
properties.put(JOPAPersistenceProperties.DATA_SOURCE_CLASS, config.getPersistenceDriver());
this.emf = Persistence.createEntityManagerFactory("formGenTestPU", properties);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
Expand All @@ -24,14 +25,15 @@
import static cz.cvut.kbss.ontodriver.config.OntoDriverProperties.DATA_SOURCE_USERNAME;

@Configuration
@PropertySource("classpath:application.properties")
@EnableConfigurationProperties(cz.cvut.kbss.study.util.Configuration.class)
@Profile("test")
public class TestPersistenceFactory {

private static final String URL_PROPERTY = "test." + ConfigParam.REPOSITORY_URL;
private static final String DRIVER_PROPERTY = "test." + ConfigParam.PERSISTENCE_DRIVER;
private static final String USERNAME_PROPERTY = "test.username";
private static final String PASSWORD_PROPERTY = "test.password";
private static final String USERNAME_PROPERTY = "username";
private static final String PASSWORD_PROPERTY = "password";

@Autowired
private cz.cvut.kbss.study.util.Configuration config;

@Autowired
private Environment environment;
Expand All @@ -47,8 +49,8 @@ public EntityManagerFactory getEntityManagerFactory() {
@PostConstruct
private void init() {
final Map<String, String> properties = getDefaultProperties();
properties.put(JOPAPersistenceProperties.ONTOLOGY_PHYSICAL_URI_KEY, environment.getProperty(URL_PROPERTY));
properties.put(JOPAPersistenceProperties.DATA_SOURCE_CLASS, environment.getProperty(DRIVER_PROPERTY));
properties.put(JOPAPersistenceProperties.ONTOLOGY_PHYSICAL_URI_KEY, config.getRepositoryUrl());
properties.put(JOPAPersistenceProperties.DATA_SOURCE_CLASS,config.getPersistenceDriver());
if (environment.getProperty(USERNAME_PROPERTY) != null) {
properties.put(DATA_SOURCE_USERNAME, environment.getProperty(USERNAME_PROPERTY));
properties.put(DATA_SOURCE_PASSWORD, environment.getProperty(PASSWORD_PROPERTY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import cz.cvut.kbss.study.environment.generator.Generator;
import cz.cvut.kbss.study.model.Institution;
import cz.cvut.kbss.study.model.User;
import cz.cvut.kbss.study.persistence.ConfigDataApplicationContextInitializer;
import cz.cvut.kbss.study.persistence.dao.InstitutionDao;
import cz.cvut.kbss.study.persistence.dao.UserDao;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -19,7 +20,7 @@
import org.springframework.test.context.junit.jupiter.SpringExtension;

@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {TestServiceConfig.class, TestPersistenceConfig.class})
@ContextConfiguration(classes = {TestServiceConfig.class, TestPersistenceConfig.class}, initializers = {ConfigDataApplicationContextInitializer.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@ActiveProfiles("test")
public abstract class BaseServiceTestRunner extends TransactionalTestRunner {
Expand Down
6 changes: 0 additions & 6 deletions src/test/resources/application.properties

This file was deleted.

4 changes: 4 additions & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
persistenceDriver: cz.cvut.kbss.ontodriver.rdf4j.Rdf4jDataSource
repositoryUrl: study-test-repository
formGenRepositoryUrl: test-formGen-repository
formGenServiceUrl: http://localhost:8081/formGenerator
Loading