File tree Expand file tree Collapse file tree 3 files changed +26
-256
lines changed
main/java/edu/kit/datamanager/ro_crate/context
test/java/edu/kit/datamanager/ro_crate/context Expand file tree Collapse file tree 3 files changed +26
-256
lines changed Original file line number Diff line number Diff line change 12
12
import java .io .IOException ;
13
13
import java .util .*;
14
14
import java .util .function .Consumer ;
15
+ import java .util .function .Function ;
15
16
16
17
import edu .kit .datamanager .ro_crate .special .IdentifierUtils ;
17
18
import org .apache .http .client .methods .CloseableHttpResponse ;
@@ -117,6 +118,11 @@ public boolean checkEntity(AbstractEntity entity) {
117
118
entity .getProperties ().path ("@type" ),
118
119
new TypeReference <>() {}
119
120
);
121
+
122
+ final Function <String , Boolean > isFail = checkMeStr -> this .contextMap .get (checkMeStr ) == null
123
+ && this .contextMap .keySet ().stream ()
124
+ .noneMatch (key -> checkMeStr .startsWith (key + ":" ));
125
+
120
126
// check if the items in the array of types are present in the context
121
127
for (String s : types ) {
122
128
// special cases:
@@ -134,7 +140,7 @@ public boolean checkEntity(AbstractEntity entity) {
134
140
continue ;
135
141
}
136
142
137
- if (this . contextMap . get (s ) == null ) {
143
+ if (isFail . apply (s )) {
138
144
System .err .println ("type " + s + " is missing from the context!" );
139
145
return false ;
140
146
}
@@ -147,7 +153,7 @@ public boolean checkEntity(AbstractEntity entity) {
147
153
// full URLs are considered fine
148
154
continue ;
149
155
}
150
- if (this . contextMap . get (s ) == null ) {
156
+ if (isFail . apply (s )) {
151
157
System .err .println ("attribute name " + s + " is missing from context;" );
152
158
return false ;
153
159
}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 6
6
import com .fasterxml .jackson .databind .node .ObjectNode ;
7
7
8
8
import edu .kit .datamanager .ro_crate .HelpFunctions ;
9
+ import edu .kit .datamanager .ro_crate .RoCrate ;
9
10
import edu .kit .datamanager .ro_crate .entities .AbstractEntity ;
10
11
import edu .kit .datamanager .ro_crate .entities .contextual .ContextualEntity ;
11
12
import edu .kit .datamanager .ro_crate .entities .data .DataEntity ;
@@ -278,4 +279,21 @@ void testReadPairs() {
278
279
// prove immutability
279
280
assertThrows (UnsupportedOperationException .class , () -> given .put ("newKey" , "newValue" ));
280
281
}
282
+
283
+ @ Test
284
+ void checkEntity_withDefinedPrefixedType_succeeds () throws IOException {
285
+ // assume we read a crate just for demonstration
286
+ RoCrate crate = new RoCrate ();
287
+ // and we extend the context
288
+ RoCrateMetadataContext context = new RoCrateMetadataContext ();
289
+ context .addToContext ("rdfs" , "https://www.w3.org/2000/01/rdf-schema#" );
290
+ crate .setMetadataContext (context );
291
+ // then we use the new context
292
+ DataEntity entity = new DataEntity .DataEntityBuilder ()
293
+ .addType ("rdfs:Property" )
294
+ .build ();
295
+ crate .addDataEntity (entity );
296
+ // Then we expect this to work
297
+ assertTrue (context .checkEntity (entity ));
298
+ }
281
299
}
You can’t perform that action at this time.
0 commit comments