11package dev .synapse .plugins ;
22
33import dev .synapse .core .common .domain .StoreEntry ;
4+ import dev .synapse .core .common .repository .StoreEntryRepository ;
45import dev .synapse .core .infrastructure .logging .LogCategory ;
56import dev .synapse .core .infrastructure .logging .LogLevel ;
67import dev .synapse .core .infrastructure .logging .SystemLogService ;
7- import dev .synapse .core .common .repository .StoreEntryRepository ;
8- import org .springframework .cache .annotation .CacheEvict ;
9- import org .springframework .cache .annotation .Cacheable ;
8+ import java .io .File ;
9+ import java .io .FileInputStream ;
10+ import java .io .IOException ;
11+ import java .io .InputStream ;
12+ import java .util .ArrayList ;
13+ import java .util .List ;
14+ import java .util .Map ;
1015import org .slf4j .Logger ;
1116import org .slf4j .LoggerFactory ;
17+ import org .springframework .cache .annotation .CacheEvict ;
18+ import org .springframework .cache .annotation .Cacheable ;
1219import org .springframework .core .io .ClassPathResource ;
1320import org .springframework .data .domain .PageRequest ;
1421import org .springframework .data .domain .Sort ;
1522import org .springframework .stereotype .Service ;
1623import org .springframework .transaction .annotation .Transactional ;
1724import org .yaml .snakeyaml .Yaml ;
1825
19- import java .io .File ;
20- import java .io .FileInputStream ;
21- import java .io .IOException ;
22- import java .io .InputStream ;
23- import java .util .ArrayList ;
24- import java .util .List ;
25- import java .util .Map ;
26-
2726/**
2827 * Syncs store entries from local store/registry.yml into the database.
2928 */
3029@ Service
3130public class StoreRegistryService {
3231
33- private static final Logger log = LoggerFactory .getLogger (StoreRegistryService .class );
32+ private static final Logger log = LoggerFactory .getLogger (
33+ StoreRegistryService .class
34+ );
3435
3536 private final StoreEntryRepository storeEntryRepository ;
3637 private final SystemLogService logService ;
3738
38- public StoreRegistryService (StoreEntryRepository storeEntryRepository , SystemLogService logService ) {
39+ public StoreRegistryService (
40+ StoreEntryRepository storeEntryRepository ,
41+ SystemLogService logService
42+ ) {
3943 this .storeEntryRepository = storeEntryRepository ;
4044 this .logService = logService ;
4145 }
@@ -52,11 +56,15 @@ public int syncFromFile(String registryPath) {
5256
5357 storeEntryRepository .saveAll (entries );
5458
55- logService .log (LogLevel .INFO , LogCategory .STORE ,
59+ logService .log (
60+ LogLevel .INFO ,
61+ LogCategory .STORE ,
5662 Map .of ("component" , "StoreRegistryService" ),
5763 "STORE_SYNCED" ,
5864 Map .of ("count" , entries .size (), "path" , registryPath ),
59- null , null );
65+ null ,
66+ null
67+ );
6068
6169 return entries .size ();
6270 }
@@ -68,9 +76,16 @@ public List<StoreEntry> findAll() {
6876 }
6977
7078 @ Transactional (readOnly = true )
71- @ Cacheable (value = "plugin-metadata" , key = "'all:page:' + #page + ':' + #size" )
79+ @ Cacheable (
80+ value = "plugin-metadata" ,
81+ key = "'all:page:' + #page + ':' + #size"
82+ )
7283 public List <StoreEntry > findAll (int page , int size ) {
73- PageRequest pageRequest = PageRequest .of (page , size , Sort .by (Sort .Direction .ASC , "name" ));
84+ PageRequest pageRequest = PageRequest .of (
85+ page ,
86+ size ,
87+ Sort .by (Sort .Direction .ASC , "name" )
88+ );
7489 return storeEntryRepository .findAll (pageRequest ).getContent ();
7590 }
7691
@@ -81,12 +96,29 @@ public List<StoreEntry> findByType(StoreEntry.StoreEntryType type) {
8196 }
8297
8398 @ Transactional (readOnly = true )
84- @ Cacheable (value = "plugin-metadata" , key = "'type:' + #type.name() + ':page:' + #page + ':' + #size" )
85- public List <StoreEntry > findByType (StoreEntry .StoreEntryType type , int page , int size ) {
86- PageRequest pageRequest = PageRequest .of (page , size , Sort .by (Sort .Direction .ASC , "name" ));
99+ @ Cacheable (
100+ value = "plugin-metadata" ,
101+ key = "'type:' + #type.name() + ':page:' + #page + ':' + #size"
102+ )
103+ public List <StoreEntry > findByType (
104+ StoreEntry .StoreEntryType type ,
105+ int page ,
106+ int size
107+ ) {
108+ PageRequest pageRequest = PageRequest .of (
109+ page ,
110+ size ,
111+ Sort .by (Sort .Direction .ASC , "name" )
112+ );
87113 return storeEntryRepository .findByType (type , pageRequest );
88114 }
89115
116+ @ Transactional (readOnly = true )
117+ @ Cacheable (value = "plugin-metadata" , key = "'id:' + #id" )
118+ public StoreEntry findById (String id ) {
119+ return storeEntryRepository .findById (id ).orElse (null );
120+ }
121+
90122 @ SuppressWarnings ("unchecked" )
91123 private List <StoreEntry > parsePlugins (Map <String , Object > registry ) {
92124 Object pluginsObj = registry .get ("plugins" );
@@ -96,7 +128,10 @@ private List<StoreEntry> parsePlugins(Map<String, Object> registry) {
96128 for (Object item : list ) {
97129 if (!(item instanceof Map <?, ?> raw )) continue ;
98130 Map <String , Object > map = (Map <String , Object >) raw ;
99- StoreEntry entry = mapToEntry (map , StoreEntry .StoreEntryType .PLUGIN );
131+ StoreEntry entry = mapToEntry (
132+ map ,
133+ StoreEntry .StoreEntryType .PLUGIN
134+ );
100135 if (entry != null ) result .add (entry );
101136 }
102137 return result ;
@@ -111,23 +146,33 @@ private List<StoreEntry> parseBundles(Map<String, Object> registry) {
111146 for (Object item : list ) {
112147 if (!(item instanceof Map <?, ?> raw )) continue ;
113148 Map <String , Object > map = (Map <String , Object >) raw ;
114- StoreEntry entry = mapToEntry (map , StoreEntry .StoreEntryType .BUNDLE );
149+ StoreEntry entry = mapToEntry (
150+ map ,
151+ StoreEntry .StoreEntryType .BUNDLE
152+ );
115153 if (entry != null ) result .add (entry );
116154 }
117155 return result ;
118156 }
119157
120158 @ SuppressWarnings ("unchecked" )
121- private StoreEntry mapToEntry (Map <String , Object > map , StoreEntry .StoreEntryType type ) {
159+ private StoreEntry mapToEntry (
160+ Map <String , Object > map ,
161+ StoreEntry .StoreEntryType type
162+ ) {
122163 String id = str (map , "id" );
123164 if (id == null ) return null ;
124165
125166 StoreEntry entry = new StoreEntry ();
126167 entry .setId (id );
127168 entry .setName (str (map , "name" ) != null ? str (map , "name" ) : id );
128169 entry .setType (type );
129- entry .setSource (str (map , "source" ) != null ? str (map , "source" ) : "unknown" );
130- entry .setVersion (str (map , "version" ) != null ? str (map , "version" ) : "0.0.0" );
170+ entry .setSource (
171+ str (map , "source" ) != null ? str (map , "source" ) : "unknown"
172+ );
173+ entry .setVersion (
174+ str (map , "version" ) != null ? str (map , "version" ) : "0.0.0"
175+ );
131176 entry .setAuthor (str (map , "author" ));
132177 entry .setLicense (str (map , "license" ));
133178 entry .setDescription (str (map , "description" ));
@@ -152,14 +197,20 @@ private Map<String, Object> loadYaml(String path) {
152197 }
153198 }
154199 // fallback: classpath
155- ClassPathResource resource = new ClassPathResource ("store/registry.yml" );
200+ ClassPathResource resource = new ClassPathResource (
201+ "store/registry.yml"
202+ );
156203 if (resource .exists ()) {
157204 try (InputStream is = resource .getInputStream ()) {
158205 return yaml .load (is );
159206 }
160207 }
161208 } catch (IOException e ) {
162- log .warn ("Failed to load registry YAML from {}: {}" , path , e .getMessage ());
209+ log .warn (
210+ "Failed to load registry YAML from {}: {}" ,
211+ path ,
212+ e .getMessage ()
213+ );
163214 }
164215 return null ;
165216 }
0 commit comments