diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 488d3b80..00000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,69 +0,0 @@ -server.servlet.context-path=/record-manager -management.endpoints.web.exposure.include=health - -# Driver to manage triple stores -persistenceDriver=cz.cvut.kbss.ontodriver.rdf4j.Rdf4jDataSource -# URL of repository that holds main data of the application -repositoryUrl=http://localhost:7200/repositories/record-manager-app -# URL of repository where output and configuration of form-generator should be held -formGenRepositoryUrl=http://localhost:7200/repositories/record-manager-formgen -# REST endpoint of form generator service -formGenServiceUrl=http://localhost:8080/s-pipes/service?_pId=transform&sgovRepositoryUrl=https%3A%2F%2Fgraphdb.onto.fel.cvut.cz%2Frepositories%2Fkodi-slovnik-gov-cz -# Option to pass sameSite attribute for set-cookie headers. Possible values are None,Lax,Strict. In case of None value also attribute "Secure;" is added. -security.sameSite= - -# Url of the website for password reset emails. e.g. https://study.com/ (must have "/" at the end) -appContext=http://localhost:3000/record-manager - -# SMTP host -smtp.host=smtp.gmail.com -# SMTP port -smtp.port=587 -# SMTP user -smtp.user=recordmanager@gmail.com -# SMTP password -smtp.password=AdminOrganization123 - -# Email display name -email.displayName=Record Manager -# if email.from is not entered, smtp.user is used instead -email.from= -# Email cc addresses where all invitations will be sent. For more use delimiter "," (can remain empty) -email.replyTo= -email.cc= -email.bcc= - -# You can use variables in email contents by using {{variable}}, available variables are listed before email content property -# Password Reset email subject -email.passwordResetSubject=Password Reset -# PasswordReset email html content, variables: username, link, appContext -email.passwordResetContent=

Dear user {{username}},

please set your new password here: {{link}}

Best regards,
StudyManager

- -# UserInvite email subject -email.invitationSubject=Welcome to study -# UserInvite email html content, variables: username, link, name, appContext -email.invitationContent=

Dear {{name}},

you have been invited to a study running at {{appContext}}.

Your username is: {{username}}.

\ -

Please set your password here: {{link}}

Best regards,
StudyManager

- -# Password change email -email.passwordChangeSubject=Password Change -# PasswordReset email html content, variables: username, appContext -email.passwordChangeContent=

Dear user {{username}},

your password has been changed.

Best regards,
RecordManager

- -# Profile update email -email.profileUpdateSubject=Profile updated by a study coordinator -# PasswordReset email html content, variables: username, appContext -email.profileUpdateContent=

Dear user {{username}},

your profile at {{appContext}} has been updated by a study coordinator.

Best regards,
RecordManager

- -# Provider of application security. Possible values are 'internal' for internally stored users and 'oidc' for using an -# OIDC-compatible authentication service. Its URL is configured via Spring Boot configuration parameters -security.provider=internal - -# Claim containing user roles in the OIDC access token (applies only when 'oidc' security provider is selected). Use -# dot notation for nested objects -security.oidc.roleClaim=realm_access.roles - -# Configures allowed origins for CORS (e.g. http://localhost:3000). Use a comma to separate multiple values -security.cors.allowedOrigins= - -records.allowedRejectReason=true diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 00000000..8663ead7 --- /dev/null +++ b/src/main/resources/application.yml @@ -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: recordmanager@gmail.com + password: AdminOrganization123 + +email: + displayName: Record Manager + from: "" + replyTo: "" + cc: "" + bcc: "" + passwordResetSubject: Password Reset + passwordResetContent: >- +

Dear user {{username}},

please set your new password here: {{link}}

Best regards,
StudyManager

+ invitationSubject: Welcome to study + invitationContent: >- +

Dear {{name}},

you have been invited to a study running at {{appContext}}.

Your username is: {{username}}.

\ +

Please set your password here: {{link}}

Best regards,
StudyManager

+ passwordChangeSubject: Password Change + passwordChangeContent: >- +

Dear user {{username}},

your password has been changed.

Best regards,
RecordManager

+ profileUpdateSubject: Profile updated by a study coordinator + profileUpdateContent: >- +

Dear user {{username}},

your profile at {{appContext}} has been updated by a study coordinator.

Best regards,
RecordManager

+ +records: + allowedRejectReason: true diff --git a/src/test/java/cz/cvut/kbss/study/persistence/BaseDaoTestRunner.java b/src/test/java/cz/cvut/kbss/study/persistence/BaseDaoTestRunner.java index 2edd1a47..bc116282 100644 --- a/src/test/java/cz/cvut/kbss/study/persistence/BaseDaoTestRunner.java +++ b/src/test/java/cz/cvut/kbss/study/persistence/BaseDaoTestRunner.java @@ -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 { diff --git a/src/test/java/cz/cvut/kbss/study/persistence/ConfigDataApplicationContextInitializer.java b/src/test/java/cz/cvut/kbss/study/persistence/ConfigDataApplicationContextInitializer.java new file mode 100644 index 00000000..cd92431c --- /dev/null +++ b/src/test/java/cz/cvut/kbss/study/persistence/ConfigDataApplicationContextInitializer.java @@ -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 { + 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); + } +} \ No newline at end of file diff --git a/src/test/java/cz/cvut/kbss/study/persistence/TestFormGenPersistenceFactory.java b/src/test/java/cz/cvut/kbss/study/persistence/TestFormGenPersistenceFactory.java index 5cdf8c3d..6925b19b 100644 --- a/src/test/java/cz/cvut/kbss/study/persistence/TestFormGenPersistenceFactory.java +++ b/src/test/java/cz/cvut/kbss/study/persistence/TestFormGenPersistenceFactory.java @@ -9,6 +9,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.Profile; @@ -16,15 +17,12 @@ 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; @@ -36,8 +34,8 @@ public EntityManagerFactory getEntityManagerFactory() { @PostConstruct private void init() { final Map 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); } diff --git a/src/test/java/cz/cvut/kbss/study/persistence/TestPersistenceFactory.java b/src/test/java/cz/cvut/kbss/study/persistence/TestPersistenceFactory.java index 9510fde3..7145480f 100644 --- a/src/test/java/cz/cvut/kbss/study/persistence/TestPersistenceFactory.java +++ b/src/test/java/cz/cvut/kbss/study/persistence/TestPersistenceFactory.java @@ -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; @@ -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; @@ -47,8 +49,8 @@ public EntityManagerFactory getEntityManagerFactory() { @PostConstruct private void init() { final Map 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)); diff --git a/src/test/java/cz/cvut/kbss/study/service/BaseServiceTestRunner.java b/src/test/java/cz/cvut/kbss/study/service/BaseServiceTestRunner.java index 68a0777e..9b655a7b 100644 --- a/src/test/java/cz/cvut/kbss/study/service/BaseServiceTestRunner.java +++ b/src/test/java/cz/cvut/kbss/study/service/BaseServiceTestRunner.java @@ -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; @@ -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 { diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties deleted file mode 100644 index 00a0e2dd..00000000 --- a/src/test/resources/application.properties +++ /dev/null @@ -1,6 +0,0 @@ -test.repositoryUrl=study-test-repository -test.persistenceDriver=cz.cvut.kbss.ontodriver.rdf4j.Rdf4jDataSource -test.formGenRepositoryUrl=test-formGen-repository -repositoryUrl=study-test-repository -formGenRepositoryUrl=test-formGen-repository -formGenServiceUrl=http://localhost:8081/formGenerator \ No newline at end of file diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml new file mode 100644 index 00000000..506ae0b5 --- /dev/null +++ b/src/test/resources/application.yml @@ -0,0 +1,4 @@ +persistenceDriver: cz.cvut.kbss.ontodriver.rdf4j.Rdf4jDataSource +repositoryUrl: study-test-repository +formGenRepositoryUrl: test-formGen-repository +formGenServiceUrl: http://localhost:8081/formGenerator \ No newline at end of file