1
2
3
4
5
6 package org.tailormap.api.repository;
7
8 import java.util.Optional;
9 import org.springframework.data.jpa.repository.JpaRepository;
10 import org.springframework.data.jpa.repository.Query;
11 import org.springframework.data.repository.query.Param;
12 import org.springframework.data.rest.core.annotation.RepositoryRestResource;
13 import org.springframework.security.access.prepost.PreAuthorize;
14 import org.tailormap.api.persistence.Configuration;
15 import org.tailormap.api.security.annotation.PreAuthorizeAdmin;
16
17 @PreAuthorizeAdmin
18 @RepositoryRestResource(
19 path = "configs",
20 collectionResourceRel = "configs",
21 itemResourceRel = "config")
22 public interface ConfigurationRepository extends JpaRepository<Configuration, String> {
23 @PreAuthorize("permitAll()")
24 Optional<Configuration> findByKey(String key);
25
26 @PreAuthorize("permitAll()")
27 default String get(String key) {
28 return get(key, null);
29 }
30
31 @PreAuthorize("permitAll()")
32 default String get(String key, String defaultValue) {
33 return findByKey(key).map(Configuration::getValue).orElse(defaultValue);
34 }
35
36 @PreAuthorize("permitAll()")
37 @Query("from Configuration c where c.key = :key and c.availableForViewer = true")
38 Optional<Configuration> getAvailableForViewer(@Param("key") String key);
39
40 void deleteConfigurationByKey(String configKey);
41 }