@@ -112,6 +112,19 @@ public JsonNode getProperty(String propertyKey) {
112112 return this .properties .get (propertyKey );
113113 }
114114
115+ /**
116+ * Returns the value of the property with the given key as a String.
117+ * If the property is not found, it returns null.
118+ *
119+ * @param propertyKey the key of the property.
120+ * @return the value of the property as a String or null if not found.
121+ */
122+ public String getIdProperty (String propertyKey ) {
123+ return Optional .ofNullable (this .properties .get (propertyKey ))
124+ .map (jsonNode -> jsonNode .path ("@id" ).asText (null ))
125+ .orElse (null );
126+ }
127+
115128 @ JsonIgnore
116129 public String getId () {
117130 JsonNode id = this .properties .get ("@id" );
@@ -241,9 +254,7 @@ private static boolean addProperty(ObjectNode whereToAdd, String key, JsonNode v
241254 public void addIdProperty (String name , String id ) {
242255 if (id == null || id .isBlank ()) { return ; }
243256 mergeIdIntoValue (id , this .properties .get (name ))
244- .ifPresent (newValue -> {
245- this .properties .set (name , newValue );
246- });
257+ .ifPresent (newValue -> this .properties .set (name , newValue ));
247258 this .linkedTo .add (id );
248259 this .notifyObservers ();
249260 }
@@ -356,7 +367,7 @@ private static void checkFormatISO8601(String date) throws IllegalArgumentExcept
356367 /**
357368 * Adds a property with date time format. The property should match the ISO 8601
358369 * date format.
359- *
370+ * <p>
360371 * Same as {@link #addProperty(String, String)} but with internal check.
361372 *
362373 * @param key key of the property (e.g. datePublished)
@@ -411,7 +422,7 @@ public T setId(String id) {
411422 if (IdentifierUtils .isValidUri (id )) {
412423 this .id = id ;
413424 } else {
414- this .id = IdentifierUtils .encode (id ).get ( );
425+ this .id = IdentifierUtils .encode (id ).orElse ( this . id );
415426 }
416427 }
417428 return self ();
@@ -448,7 +459,7 @@ public T addTypes(Collection<String> types) {
448459 /**
449460 * Adds a property with date time format. The property should match the ISO 8601
450461 * date format.
451- *
462+ * <p>
452463 * Same as {@link #addProperty(String, String)} but with internal check.
453464 *
454465 * @param key key of the property (e.g. datePublished)
@@ -508,7 +519,7 @@ public T addProperty(String key, boolean value) {
508519 /**
509520 * ID properties are often used when referencing other entities within
510521 * the ROCrate. This method adds automatically such one.
511- *
522+ * <p>
512523 * Instead of {@code "name": "id" }
513524 * this will add {@code "name" : {"@id": "id"} }
514525 *
0 commit comments