1212 *
1313 */
1414
15- package org .eclipse .edc .jsonld .cache ;
16-
17- import org .eclipse .edc .jsonld .cache .spi .CachedJsonLdContext ;
18- import org .eclipse .edc .jsonld .cache .spi .CachedJsonLdContextService ;
19- import org .eclipse .edc .jsonld .cache .spi .PullStrategy ;
20- import org .eclipse .edc .jsonld .cache .spi .resolver .JsonLdContextResolver ;
21- import org .eclipse .edc .jsonld .cache .spi .store .CachedJsonLdContextStore ;
15+ package org .eclipse .edc .document .cache ;
16+
17+ import org .eclipse .edc .document .cache .spi .CachedDocument ;
18+ import org .eclipse .edc .document .cache .spi .CachedDocumentService ;
19+ import org .eclipse .edc .document .cache .spi .CachedDocumentType ;
20+ import org .eclipse .edc .document .cache .spi .PullStrategy ;
21+ import org .eclipse .edc .document .cache .spi .resolver .DocumentResolver ;
22+ import org .eclipse .edc .document .cache .spi .store .CachedDocumentStore ;
2223import org .eclipse .edc .jsonld .spi .JsonLd ;
2324import org .eclipse .edc .spi .monitor .Monitor ;
2425import org .eclipse .edc .spi .query .QuerySpec ;
3031import java .util .List ;
3132
3233import static java .lang .String .format ;
33- import static org .eclipse .edc .jsonld .cache .JsonLdContexts .toJsonObject ;
34- import static org .eclipse .edc .jsonld .cache .spi .store .CachedJsonLdContextStore .NOT_FOUND ;
34+ import static org .eclipse .edc .document .cache .CachedDocuments .toJsonObject ;
35+ import static org .eclipse .edc .document .cache .spi .store .CachedDocumentStore .NOT_FOUND ;
3536
36- public class CachedJsonLdContextServiceImpl implements CachedJsonLdContextService {
37+ public class CachedDocumentServiceImpl implements CachedDocumentService {
3738
3839 private final TransactionContext transactionContext ;
39- private final CachedJsonLdContextStore store ;
40- private final JsonLdContextResolver resolver ;
40+ private final CachedDocumentStore store ;
41+ private final DocumentResolver resolver ;
4142 private final JsonLd jsonLd ;
4243 private final Monitor monitor ;
4344 private final Clock clock ;
4445
45- public CachedJsonLdContextServiceImpl (TransactionContext transactionContext , CachedJsonLdContextStore store ,
46- JsonLdContextResolver resolver , JsonLd jsonLd , Monitor monitor , Clock clock ) {
46+ public CachedDocumentServiceImpl (TransactionContext transactionContext , CachedDocumentStore store ,
47+ DocumentResolver resolver , JsonLd jsonLd , Monitor monitor , Clock clock ) {
4748 this .transactionContext = transactionContext ;
4849 this .store = store ;
4950 this .resolver = resolver ;
@@ -53,12 +54,12 @@ public CachedJsonLdContextServiceImpl(TransactionContext transactionContext, Cac
5354 }
5455
5556 @ Override
56- public CachedJsonLdContext findById (String id ) {
57+ public CachedDocument findById (String id ) {
5758 return transactionContext .execute (() -> store .findById (id ));
5859 }
5960
6061 @ Override
61- public ServiceResult <List <CachedJsonLdContext >> search (QuerySpec query ) {
62+ public ServiceResult <List <CachedDocument >> search (QuerySpec query ) {
6263 return transactionContext .execute (() -> {
6364 try (var stream = store .findAll (query )) {
6465 return ServiceResult .success (stream .toList ());
@@ -67,25 +68,29 @@ public ServiceResult<List<CachedJsonLdContext>> search(QuerySpec query) {
6768 }
6869
6970 @ Override
70- public @ NotNull ServiceResult <CachedJsonLdContext > create (CachedJsonLdContext context ) {
71+ public @ NotNull ServiceResult <CachedDocument > create (CachedDocument context ) {
7172 return transactionContext .execute (() -> prepare (context )
7273 .compose (prepared -> ServiceResult .from (store .create (prepared )).onSuccess (this ::register )));
7374 }
7475
7576 @ Override
76- public @ NotNull ServiceResult <CachedJsonLdContext > update (CachedJsonLdContext context ) {
77+ public @ NotNull ServiceResult <CachedDocument > update (CachedDocument context ) {
7778 return transactionContext .execute (() -> prepare (context )
7879 .compose (prepared -> ServiceResult .from (store .update (prepared )).onSuccess (this ::register )));
7980 }
8081
8182 @ Override
82- public @ NotNull ServiceResult <CachedJsonLdContext > deleteById (String id ) {
83+ public @ NotNull ServiceResult <CachedDocument > deleteById (String id ) {
8384 return transactionContext .execute (() -> ServiceResult .from (store .delete (id ))
84- .onSuccess (deleted -> jsonLd .unregisterCachedDocument (deleted .getUrl ())));
85+ .onSuccess (deleted -> {
86+ if (deleted .getType () == CachedDocumentType .JSON_LD ) {
87+ jsonLd .unregisterCachedDocument (deleted .getUrl ());
88+ }
89+ }));
8590 }
8691
8792 @ Override
88- public @ NotNull ServiceResult <CachedJsonLdContext > refresh (String id ) {
93+ public @ NotNull ServiceResult <CachedDocument > refresh (String id ) {
8994 return transactionContext .execute (() -> {
9095 var existing = store .findById (id );
9196 if (existing == null ) {
@@ -111,7 +116,7 @@ public ServiceResult<List<CachedJsonLdContext>> search(QuerySpec query) {
111116 * {@code NEVER} requires content up front, {@code IF_NOT_PRESENT} pulls only when content is missing,
112117 * and {@code ALWAYS} pulls a fresh copy from the url.
113118 */
114- private ServiceResult <CachedJsonLdContext > prepare (CachedJsonLdContext context ) {
119+ private ServiceResult <CachedDocument > prepare (CachedDocument context ) {
115120 return switch (context .getPullStrategy ()) {
116121 case NEVER -> context .getContent () != null
117122 ? ServiceResult .success (context )
@@ -131,7 +136,15 @@ private ServiceResult<String> pull(String url) {
131136 return ServiceResult .success (result .getContent ().toString ());
132137 }
133138
134- private void register (CachedJsonLdContext context ) {
139+ /**
140+ * Registers the document so it can be resolved at runtime. Only {@link CachedDocumentType#JSON_LD} documents
141+ * are registered into the {@link JsonLd} service; {@link CachedDocumentType#JSON_SCHEMA} documents are served
142+ * to the management API schema validator directly from the store and therefore need no action here.
143+ */
144+ private void register (CachedDocument context ) {
145+ if (context .getType () != CachedDocumentType .JSON_LD ) {
146+ return ;
147+ }
135148 toJsonObject (context .getContent ())
136149 .onSuccess (json -> jsonLd .registerCachedDocument (context .getUrl (), json ))
137150 .onFailure (f -> monitor .warning ("Cannot register cached JSON-LD context '%s': %s"
0 commit comments