1
0
mirror of https://github.com/pcvolkmer/onkostar-plugin-dnpm.git synced 2025-07-03 09:42:54 +00:00

Issue #11: Service und Spring Data JPA Repository für Systemeinstellungen

This commit is contained in:
2023-03-20 14:07:00 +01:00
parent a8a5e1be8a
commit ef5c91a352
10 changed files with 223 additions and 37 deletions

View File

@ -1,10 +1,12 @@
package DNPM.config;
import DNPM.database.SettingsRepository;
import DNPM.services.*;
import de.itc.onkostar.api.IOnkostarApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import javax.sql.DataSource;
@ -15,6 +17,7 @@ import javax.sql.DataSource;
*/
@Configuration
@ComponentScan(basePackages = "DNPM.analyzer")
@EnableJpaRepositories(basePackages = "DNPM.database")
public class PluginConfiguration {
@Bean
@ -28,8 +31,17 @@ public class PluginConfiguration {
}
@Bean
public TherapieplanServiceFactory therapieplanServiceFactory(final IOnkostarApi onkostarApi, final FormService formService) {
return new TherapieplanServiceFactory(onkostarApi, formService);
public SettingsService settingsService(final SettingsRepository settingsRepository) {
return new SettingsService(settingsRepository);
}
@Bean
public TherapieplanServiceFactory therapieplanServiceFactory(
final IOnkostarApi onkostarApi,
final SettingsService settingsService,
final FormService formService
) {
return new TherapieplanServiceFactory(onkostarApi, settingsService, formService);
}
}

View File

@ -0,0 +1,20 @@
package DNPM.database;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.Repository;
import java.io.Serializable;
import java.util.List;
/**
* Basis-Repository for ReadOnly Spring-Data-JPA Repositories
* <p>Entity-Klassen müssen in Package <code>de.itc.db.dnpm</code> liegen
* @param <T> Typ des Entities
* @param <ID> Typ der ID
*/
@NoRepositoryBean
public interface ReadOnlyRepository<T, ID extends Serializable> extends Repository<T, ID> {
List<T> findAll();
}

View File

@ -0,0 +1,14 @@
package DNPM.database;
import de.itc.db.dnpm.Setting;
import org.springframework.stereotype.Repository;
/**
* Spring Data JPA Repository zum Lesen von Einstellungen
*/
@Repository("dnpmSettingRepository")
public interface SettingsRepository extends ReadOnlyRepository<Setting, Long> {
Setting findByName(String name);
}

View File

@ -0,0 +1,47 @@
package DNPM.services;
import DNPM.database.SettingsRepository;
import java.util.Optional;
/**
* Implementiert den Dienst zur Ermittlung von Systemeinstellungen
*/
public class SettingsService {
private final SettingsRepository settingsRepository;
public SettingsService(final SettingsRepository settingsRepository) {
this.settingsRepository = settingsRepository;
}
/**
* Übergibt ein <code>Optional</code> für die Einstellung mit angegebenen Namen
* @param name Name der Einstellung
* @return Optional mit Wert der Einstellung oder ein leeres Optional, wenn Einstellung nicht gefunden
*/
public Optional<String> getSetting(String name) {
var sid = settingsRepository.findByName(name);
if (null == sid) {
return Optional.empty();
}
return Optional.of(sid.getValue());
}
/**
* Übergibt die SID als <code>Optional</code>
* @return Optional mit Wert der SID
*/
public Optional<String> getSID() {
return getSetting("SID");
}
/**
* Übergibt die Einstellung für <code>mehrere_mtb_in_mtbepisode</code>
* @return Übergibt <code>true</code>, wenn <code>mehrere_mtb_in_mtbepisode</code> auf "Ja" gesetzt ist.
*/
public boolean multipleMtbsInMtbEpisode() {
var setting = getSetting("SID");
return setting.isPresent() && setting.get().equals("true");
}
}

View File

@ -6,18 +6,22 @@ public class TherapieplanServiceFactory {
private final IOnkostarApi onkostarApi;
private final SettingsService settingsService;
private final FormService formService;
public TherapieplanServiceFactory(IOnkostarApi onkostarApi, FormService formService) {
public TherapieplanServiceFactory(
final IOnkostarApi onkostarApi,
final SettingsService settingsService,
final FormService formService
) {
this.onkostarApi = onkostarApi;
this.settingsService = settingsService;
this.formService = formService;
}
public TherapieplanService currentUsableInstance() {
if (
null != onkostarApi.getGlobalSetting("mehrere_mtb_in_mtbepisode")
&& onkostarApi.getGlobalSetting("mehrere_mtb_in_mtbepisode").equals("true")
) {
if (settingsService.multipleMtbsInMtbEpisode()) {
return new MultipleMtbTherapieplanService();
}

View File

@ -0,0 +1,43 @@
package de.itc.db.dnpm;
import org.hibernate.annotations.Immutable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Immutable
@Table(name = "einstellung")
public class Setting {
@Id
private Long id;
private String name;
@Column(name = "wert")
private String value;
protected Setting() {
// No content
}
public Setting(Long id, String name, String value) {
this.id = id;
this.name = name;
this.value = value;
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
public String getValue() {
return value;
}
}