From 68fc46f6f75643109aa9e4fc1bd1688b4adcd87b Mon Sep 17 00:00:00 2001 From: Andreas Meier Date: Fri, 19 Sep 2025 11:49:21 +0200 Subject: [PATCH] Update quickstart examples --- 0.2.x/examples/quickstart/QuickStartRead.java | 42 +++++++++++++++++++ .../{Quickstart.java => QuickStartWrite.java} | 25 +++++++---- 2 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 0.2.x/examples/quickstart/QuickStartRead.java rename 0.2.x/examples/quickstart/{Quickstart.java => QuickStartWrite.java} (87%) diff --git a/0.2.x/examples/quickstart/QuickStartRead.java b/0.2.x/examples/quickstart/QuickStartRead.java new file mode 100644 index 0000000..9e827c9 --- /dev/null +++ b/0.2.x/examples/quickstart/QuickStartRead.java @@ -0,0 +1,42 @@ +package ch.eth.sis.rocrate.example.doc; + +import ch.eth.sis.rocrate.SchemaFacade; +import ch.eth.sis.rocrate.facade.IMetadataEntry; +import ch.eth.sis.rocrate.facade.IPropertyType; +import ch.eth.sis.rocrate.facade.IType; +import com.fasterxml.jackson.core.JsonProcessingException; +import edu.kit.datamanager.ro_crate.RoCrate; +import edu.kit.datamanager.ro_crate.reader.FolderReader; +import edu.kit.datamanager.ro_crate.reader.RoCrateReader; + +import java.util.List; + +public class QuickStartRead +{ + + public static void main(String[] args) throws JsonProcessingException + { + RoCrateReader reader = new RoCrateReader(new FolderReader()); + RoCrate crate = reader.readCrate(QuickStartWrite.TMP_EXAMPLE_CRATE); + SchemaFacade schemaFacade = SchemaFacade.of(crate); + + List types = schemaFacade.getTypes(); + + + /* Writes out all types with their entries */ + for (IType type : types) + { + System.out.println(type); + for (IMetadataEntry entry : schemaFacade.getEntries(type.getId())) + { + System.out.println(entry); + } + } + /* Writes out all property types */ + for (IPropertyType propertyType : schemaFacade.getPropertyTypes()) + { + System.out.println(propertyType); + } + + } +} diff --git a/0.2.x/examples/quickstart/Quickstart.java b/0.2.x/examples/quickstart/QuickStartWrite.java similarity index 87% rename from 0.2.x/examples/quickstart/Quickstart.java rename to 0.2.x/examples/quickstart/QuickStartWrite.java index 6211f4d..35adeb6 100644 --- a/0.2.x/examples/quickstart/Quickstart.java +++ b/0.2.x/examples/quickstart/QuickStartWrite.java @@ -1,3 +1,4 @@ +package ch.eth.sis.rocrate.example.doc; import ch.eth.sis.rocrate.SchemaFacade; import ch.eth.sis.rocrate.facade.*; @@ -7,14 +8,17 @@ import java.io.Serializable; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; -public class QuickStart +public class QuickStartWrite { - private static final String PREFIX = ""; + private static final String PREFIX = "Example"; private static final String SEPARATOR = ":"; + public static final String TMP_EXAMPLE_CRATE = "/tmp/example-crate"; + public static void main(String[] args) { /* Setting up an RO-Crate with the schema facade */ @@ -59,10 +63,10 @@ public class QuickStart } + Type experimentType = new Type(); /* Building our Experiment type */ { - Type experimentType = new Type(); experimentType.setId(PREFIX + SEPARATOR + "Experiment"); { @@ -98,36 +102,41 @@ public class QuickStart MetadataEntry personAndreas = new MetadataEntry(); personAndreas.setId("PERSON1"); Map properties = new LinkedHashMap<>(); + personAndreas.setTypes(Set.of(personType.getId())); properties.put("givenname", "Andreas"); properties.put("lastname", "Meier"); properties.put("identifier", "https://orcid.org/0009-0002-6541-4637"); personAndreas.setProps(properties); + personAndreas.setReferences(new LinkedHashMap<>()); schemaFacade.addEntry(personAndreas); MetadataEntry personJuan = new MetadataEntry(); - personAndreas.setId("PERSON2"); + personJuan.setId("PERSON2"); + personJuan.setTypes(Set.of(personType.getId())); Map properties2 = new LinkedHashMap<>(); properties2.put("givenname", "Andreas"); properties2.put("lastname", "Meier"); properties2.put("identifier", "https://orcid.org/0009-0002-6541-4637"); - personAndreas.setProps(properties2); + personJuan.setProps(properties2); + personJuan.setReferences(new LinkedHashMap<>()); + schemaFacade.addEntry(personJuan); MetadataEntry experiment1 = new MetadataEntry(); experiment1.setId("EXPERIMENT1"); experiment1.setReferences(Map.of("creator", List.of(personAndreas.getId()))); + experiment1.setTypes(Set.of(experimentType.getId())); Map propertiesExperiment = new LinkedHashMap<>(); propertiesExperiment.put("name", "Example Experiment"); - propertiesExperiment.put("date", "2025-09-08 08:41:50.000"); // ISO 8601 + propertiesExperiment.put("date", "2025-09-08 08:41:50.000"); experiment1.setProps(propertiesExperiment); schemaFacade.addEntry(experiment1); } FolderWriter folderWriter = new FolderWriter(); - folderWriter.save(schemaFacade.getCrate(), "/tmp/example-crate"); + folderWriter.save(schemaFacade.getCrate(), TMP_EXAMPLE_CRATE); } } -