1
0
mirror of https://github.com/pcvolkmer/onkostar-plugin-dnpm.git synced 2025-07-02 01:02:55 +00:00

Issue #4: Service zum Ermitteln von Studien hinzugefügt

This commit is contained in:
2023-03-13 16:45:04 +01:00
parent 4a6055bc22
commit 90caad3041
3 changed files with 91 additions and 0 deletions

View File

@ -0,0 +1,49 @@
package DNPM.services;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.sql.DataSource;
import java.util.List;
@Service
public class DefaultStudienService implements StudienService {
private final JdbcTemplate jdbcTemplate;
public DefaultStudienService(final DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@Override
public List<Studie> findAll() {
var sql = "SELECT property_catalogue_version.version_number, pcve.code, pcve.shortdesc, pcve.description FROM property_catalogue "
+ "JOIN property_catalogue_version ON property_catalogue.id = property_catalogue_version.datacatalog_id "
+ "JOIN property_catalogue_version_entry pcve ON property_catalogue_version.id = pcve.property_version_id "
+ "WHERE property_catalogue.name = 'OS.Studien';";
return this.jdbcTemplate.query(sql, (resultSet, i) -> new Studie(
resultSet.getString(1),
resultSet.getString(2),
resultSet.getString(3),
resultSet.getInt(0)
));
}
@Override
public List<Studie> findByQuery(String query) {
var sql = "SELECT property_catalogue_version.version_number, pcve.code, pcve.shortdesc, pcve.description FROM property_catalogue "
+ "JOIN property_catalogue_version ON property_catalogue.id = property_catalogue_version.datacatalog_id "
+ "JOIN property_catalogue_version_entry pcve ON property_catalogue_version.id = pcve.property_version_id "
+ "WHERE property_catalogue.name = 'OS.Studien' AND (pcve.shortdesc LIKE ? OR pcve.description LIKE ?);";
var like = String.format("%%%s%%", query);
return this.jdbcTemplate.query(sql, new Object[]{like, like}, (resultSet, i) -> new Studie(
resultSet.getString(1),
resultSet.getString(2),
resultSet.getString(3),
resultSet.getInt(0)
));
}
}

View File

@ -0,0 +1,31 @@
package DNPM.services;
public class Studie {
private final String code;
private final String shortDesc;
private final String description;
private final int version;
public Studie(final String code, final String shortDesc, final String description, final int version) {
this.code = code;
this.shortDesc = shortDesc;
this.description = description;
this.version = version;
}
public String getCode() {
return code;
}
public String getShortDesc() {
return shortDesc;
}
public String getDescription() {
return description;
}
public int getVersion() {
return version;
}
}

View File

@ -0,0 +1,11 @@
package DNPM.services;
import java.util.List;
public interface StudienService {
List<Studie> findAll();
List<Studie> findByQuery(String query);
}