summaryrefslogtreecommitdiff
path: root/src/main/java/DNPM/services/DefaultFormService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/DNPM/services/DefaultFormService.java')
-rw-r--r--src/main/java/DNPM/services/DefaultFormService.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/main/java/DNPM/services/DefaultFormService.java b/src/main/java/DNPM/services/DefaultFormService.java
new file mode 100644
index 0000000..c7fb042
--- /dev/null
+++ b/src/main/java/DNPM/services/DefaultFormService.java
@@ -0,0 +1,34 @@
+package DNPM.services;
+
+import DNPM.exceptions.FormException;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+
+import javax.sql.DataSource;
+import java.util.List;
+
+@Service
+public class DefaultFormService implements FormService {
+
+ private final JdbcTemplate jdbcTemplate;
+
+ public DefaultFormService(final DataSource dataSource) {
+ this.jdbcTemplate = new JdbcTemplate(dataSource);
+ }
+
+ @Override
+ public int getMainFormProcedureId(int procedureId) throws FormException {
+ var sql = "SELECT hauptprozedur_id FROM prozedur WHERE id = ?";
+ try {
+ return jdbcTemplate.queryForObject(sql, (resultSet, i) -> resultSet.getInt("hauptprozedur_id"), procedureId);
+ } catch (Exception e) {
+ throw new FormException(String.format("No main form found for subform with ID '%d'", procedureId));
+ }
+ }
+
+ @Override
+ public List<Integer> getSubFormProcedureIds(int procedureId) {
+ var sql = "SELECT id FROM prozedur WHERE hauptprozedur_id = ?";
+ return jdbcTemplate.queryForList(sql, Integer.class, procedureId);
+ }
+}