14
14
* Handles the creation and updating of ro-crate-java entity and its actions.
15
15
*/
16
16
public class ProvenanceManager {
17
+ /**
18
+ * A record to hold the prefix for the ro-crate-java ID.
19
+ * This is used to ensure that the ID is consistent across different versions of the library.
20
+ * Having a type for the prefix avoids using it by accident as a full ID.
21
+ */
17
22
protected record IdPrefix (String prefix ) {
23
+ /**
24
+ * Constructs a String with the given suffix.
25
+ *
26
+ * @param suffix The suffix to append to the prefix.
27
+ * @return A String combining the prefix and suffix, separated by a hyphen.
28
+ * Like this: "$prefix-$suffix".
29
+ */
18
30
public String withSuffix (String suffix ) {
19
31
return prefix + "-" + suffix ;
20
32
}
@@ -25,8 +37,16 @@ public String toString() {
25
37
}
26
38
}
27
39
40
+ /**
41
+ * The prefix for the ro-crate-java ID.
42
+ * This is used to identify the ro-crate-java entity in the crate.
43
+ */
28
44
protected static final IdPrefix RO_CRATE_JAVA_ID_PREFIX = new IdPrefix ("#ro-crate-java" );
29
45
46
+ /**
47
+ * The VersionProvider used to retrieve the version of ro-crate-java.
48
+ * This allows for flexibility in how the version is determined, e.g., from a properties file.
49
+ */
30
50
protected VersionProvider versionProvider ;
31
51
32
52
/**
@@ -45,11 +65,25 @@ public ProvenanceManager(VersionProvider versionProvider) {
45
65
this .versionProvider = versionProvider ;
46
66
}
47
67
68
+ /**
69
+ * Returns the full ID for the ro-crate-java entity of this library version
70
+ * to be used for an entity describing it.
71
+ * <p>
72
+ * The ID is constructed using the RO_CRATE_JAVA_ID_PREFIX and the version from the VersionProvider.
73
+ *
74
+ * @return The ID for the ro-crate-java entity.
75
+ */
48
76
public String getLibraryId () {
49
77
return RO_CRATE_JAVA_ID_PREFIX .withSuffix (versionProvider .getVersion ().toLowerCase ());
50
78
}
51
79
52
- protected void addProvenanceInformation (Crate crate ) {
80
+ /**
81
+ * Adds provenance information to the given crate.
82
+ * This includes creating or updating the ro-crate-java entity and its associated action entity.
83
+ *
84
+ * @param crate The crate to which provenance information will be added.
85
+ */
86
+ public void addProvenanceInformation (Crate crate ) {
53
87
// Determine if this is the first write
54
88
boolean isFirstWrite = crate .getAllContextualEntities ().stream ().noneMatch (
55
89
entity -> entity .getId ().startsWith (RO_CRATE_JAVA_ID_PREFIX .toString ()))
@@ -58,7 +92,7 @@ protected void addProvenanceInformation(Crate crate) {
58
92
String libraryId = this .getLibraryId ();
59
93
60
94
// Create action entity first
61
- ContextualEntity actionEntity = createActionEntity (isFirstWrite , libraryId );
95
+ ContextualEntity actionEntity = buildNewActionEntity (isFirstWrite , libraryId );
62
96
63
97
// Create or update ro-crate-java entity
64
98
ContextualEntity roCrateJavaEntity = buildRoCrateJavaEntity (crate , actionEntity .getId (), libraryId );
@@ -68,7 +102,7 @@ protected void addProvenanceInformation(Crate crate) {
68
102
crate .addContextualEntity (actionEntity );
69
103
}
70
104
71
- protected ContextualEntity createActionEntity (boolean isFirstWrite , String libraryId ) {
105
+ protected ContextualEntity buildNewActionEntity (boolean isFirstWrite , String libraryId ) {
72
106
return new ContextualEntityBuilder ()
73
107
.addType (isFirstWrite ? "CreateAction" : "UpdateAction" )
74
108
.addIdProperty ("result" , "./" )
0 commit comments