Skip to content

Commit c9de0c0

Browse files
committed
fix: do not make implicit changes when adding a data entity in the crate reading process
1 parent 9e9891e commit c9de0c0

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/main/java/edu/kit/datamanager/ro_crate/RoCrate.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@
4040
*/
4141
public class RoCrate implements Crate {
4242

43-
private final CratePayload roCratePayload;
44-
private CrateMetadataContext metadataContext;
45-
private CratePreview roCratePreview;
46-
private RootDataEntity rootDataEntity;
47-
private ContextualEntity jsonDescriptor;
43+
protected final CratePayload roCratePayload;
44+
protected CrateMetadataContext metadataContext;
45+
protected CratePreview roCratePreview;
46+
protected RootDataEntity rootDataEntity;
47+
protected ContextualEntity jsonDescriptor;
4848

49-
private Collection<File> untrackedFiles;
49+
protected Collection<File> untrackedFiles;
5050

5151
@Override
5252
public CratePreview getPreview() {

src/main/java/edu/kit/datamanager/ro_crate/reader/RoCrateReader.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@
3131
*/
3232
public class RoCrateReader {
3333

34+
/**
35+
* This is a private inner class that shall not be exposed.
36+
* **Do not make it public or protected.** It serves only the
37+
* purpose of unsafe operations while reading a crate and
38+
* may be specific to this implementation.
39+
*/
40+
private static class RoCrateUnsafe extends RoCrate {
41+
public void addDataEntityWithoutRootHasPart(DataEntity entity) {
42+
this.metadataContext.checkEntity(entity);
43+
this.roCratePayload.addDataEntity(entity);
44+
}
45+
}
46+
3447
/**
3548
* If the number of JSON entities in the crate is larger than this number,
3649
* parallelization will be used.
@@ -78,7 +91,7 @@ public RoCrate readCrate(String location) {
7891
JsonNode context = metadataJson.get(PROP_CONTEXT);
7992

8093
CrateMetadataContext crateContext = new RoCrateMetadataContext(context);
81-
RoCrate crate = new RoCrate();
94+
RoCrateUnsafe crate = new RoCrateUnsafe();
8295
crate.setMetadataContext(crateContext);
8396
JsonNode graph = metadataJson.get(PROP_GRAPH);
8497

@@ -101,7 +114,7 @@ public RoCrate readCrate(String location) {
101114
.setId(file.getName());
102115
});
103116

104-
crate.addDataEntity(dataEntity.build());
117+
crate.addDataEntityWithoutRootHasPart(dataEntity.build());
105118
} else {
106119
// contextual entity
107120
crate.addContextualEntity(

0 commit comments

Comments
 (0)