1414 * Handles the creation and updating of ro-crate-java entity and its actions.
1515 */
1616public 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+ */
1722 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+ */
1830 public String withSuffix (String suffix ) {
1931 return prefix + "-" + suffix ;
2032 }
@@ -25,8 +37,16 @@ public String toString() {
2537 }
2638 }
2739
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+ */
2844 protected static final IdPrefix RO_CRATE_JAVA_ID_PREFIX = new IdPrefix ("#ro-crate-java" );
2945
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+ */
3050 protected VersionProvider versionProvider ;
3151
3252 /**
@@ -45,11 +65,25 @@ public ProvenanceManager(VersionProvider versionProvider) {
4565 this .versionProvider = versionProvider ;
4666 }
4767
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+ */
4876 public String getLibraryId () {
4977 return RO_CRATE_JAVA_ID_PREFIX .withSuffix (versionProvider .getVersion ().toLowerCase ());
5078 }
5179
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 ) {
5387 // Determine if this is the first write
5488 boolean isFirstWrite = crate .getAllContextualEntities ().stream ().noneMatch (
5589 entity -> entity .getId ().startsWith (RO_CRATE_JAVA_ID_PREFIX .toString ()))
@@ -58,7 +92,7 @@ protected void addProvenanceInformation(Crate crate) {
5892 String libraryId = this .getLibraryId ();
5993
6094 // Create action entity first
61- ContextualEntity actionEntity = createActionEntity (isFirstWrite , libraryId );
95+ ContextualEntity actionEntity = buildNewActionEntity (isFirstWrite , libraryId );
6296
6397 // Create or update ro-crate-java entity
6498 ContextualEntity roCrateJavaEntity = buildRoCrateJavaEntity (crate , actionEntity .getId (), libraryId );
@@ -68,7 +102,7 @@ protected void addProvenanceInformation(Crate crate) {
68102 crate .addContextualEntity (actionEntity );
69103 }
70104
71- protected ContextualEntity createActionEntity (boolean isFirstWrite , String libraryId ) {
105+ protected ContextualEntity buildNewActionEntity (boolean isFirstWrite , String libraryId ) {
72106 return new ContextualEntityBuilder ()
73107 .addType (isFirstWrite ? "CreateAction" : "UpdateAction" )
74108 .addIdProperty ("result" , "./" )
0 commit comments