Skip to content

Commit 5ea7a30

Browse files
authored
Merge pull request #233 from kit-data-manager/development
Version 2.1.0
2 parents 7ed4520 + 521ca55 commit 5ea7a30

File tree

74 files changed

+3437
-1860
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+3437
-1860
lines changed

.github/workflows/gradle.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ env:
1818
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
1919

2020
jobs:
21-
# avoid double CI runs on push and PR, from https://github.com/orgs/community/discussions/57827
2221
build:
23-
if: github.event_name != 'push' || github.event.push.head.repo.full_name != github.event.push.base.repo.full_name
2422
strategy:
2523
matrix:
2624
os: [ubuntu-latest, macos-latest, windows-latest]
@@ -49,3 +47,6 @@ jobs:
4947
- name: Do one Coveralls test report
5048
if: matrix.os == 'ubuntu-latest' && matrix.jdk == 21
5149
run: ./gradlew -Dprofile=release jacocoTestReport coveralls
50+
- name: Compile Javadoc
51+
if: matrix.os == 'ubuntu-latest' && matrix.jdk == 21
52+
run: ./gradlew javadoc

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,7 @@ gradle-app.setting
169169
# gradle/wrapper/gradle-wrapper.properties
170170

171171
### Gradle Patch ###
172+
.DS_Store
172173
**/build/
174+
**/jte-classes
175+
**/temp

README.md

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,24 @@ PersonEntity person = ORCIDProvider.getPerson("https://orcid.org/*")
117117
OrganizationEntity organization = RORProvider.getOrganization("https://ror.org/*");
118118
```
119119

120-
### Writing Crate to folder or zip file
120+
### Writing Crate to folder, zip file, or zip stream
121121

122122
Writing to folder:
123123
```java
124124
RoCrateWriter folderRoCrateWriter = new RoCrateWriter(new FolderWriter());
125-
folderRoCrateWriter.save(roCrate, "destination");
125+
folderRoCrateWriter.save(roCrate, "destinationFolder");
126126
```
127127

128128
Writing to zip file:
129129
```java
130130
RoCrateWriter roCrateZipWriter = new RoCrateWriter(new ZipWriter());
131-
roCrateZipWriter.save(roCrate, "destination");
131+
roCrateZipWriter.save(roCrate, "destinationFolder");
132+
```
133+
134+
Writing to zip stream:
135+
```java
136+
RoCrateWriter roCrateZipStreamWriter = new RoCrateWriter(new ZipStreamWriter());
137+
roCrateZipStreamWriter.save(roCrate, outputStream);
132138
```
133139

134140
More writing strategies can be implemented, if required.
@@ -138,25 +144,48 @@ More writing strategies can be implemented, if required.
138144
Reading from folder:
139145
```java
140146
RoCrateReader roCrateFolderReader = new RoCrateReader(new FolderReader());
141-
RoCrate res = roCrateFolderReader.readCrate("source");
147+
RoCrate res = roCrateFolderReader.readCrate("destinationFolder");
142148
```
143149

144150
Reading from zip file:
145151
```java
146152
RoCrateReader roCrateFolderReader = new RoCrateReader(new ZipReader());
147-
RoCrate crate = roCrateFolderReader.readCrate("source");
153+
RoCrate crate = roCrateFolderReader.readCrate("sourceZipFile");
154+
```
155+
156+
Reading from zip stream:
157+
```java
158+
RoCrateReader roCrateFolderReader = new RoCrateReader(new ZipStreamReader());
159+
RoCrate crate = roCrateFolderReader.readCrate(inputStream);
148160
```
149161

150162
### RO-Crate Website (HTML preview file)
151-
By setting the preview to an `AutomaticPreview`, the library will automatically create a preview using the [ro-crate-html-js](https://www.npmjs.com/package/ro-crate-html-js) tool.
152-
It has to be installed using `npm install --global ro-crate-html-js` in order to use it.
153-
If you want to use a custom-made preview, you can set it using the `CustomPreview` class. `AutomaticPreview` is currently **not** set by default.
163+
ro-crate-java offers tree different kinds of previews:
164+
165+
* AutomaticPreview: Uses third-party library [ro-crate-html-js](https://www.npmjs.com/package/ro-crate-html-js), which must be installed separately.
166+
* CustomPreview: Pure Java-based preview using an included template processed by the FreeMarker template engine. At the same time, CustomPreview is the fallback for AutomaticPreview if ro-crate-html-js is not installed.
167+
* StaticPreview: Allows to provide a static HTML page (including additional dependencies, e.g., CSS, JS) which is then shipped with the RO-Crate.
168+
169+
When creating a new RO-Crate using the builder, the default setting is to use CustomPreview. If you want to change this behaviour, thr preview method is set as follows:
170+
154171
```java
155172
RoCrate roCrate = new RoCrateBuilder("name", "description", "datePublished", "licenseIdentifier")
156173
.setPreview(new AutomaticPreview())
157174
.build();
158175
```
159176

177+
Keep in mind that, if you want to use AutomaticPreview, you have to install ro-crate-html-js via `npm install --global ro-crate-html-js` first.
178+
179+
For StaticPreview, the constuctor is a bit different, such that it looks as follows:
180+
181+
```java
182+
File pathToMainPreviewHtml = new File("localPath");
183+
File pathToAdditionalFiles = new File("localFolder");
184+
RoCrate roCrate = new RoCrateBuilder("name", "description", "datePublished", "licenseIdentifier")
185+
.setPreview(new StaticPreview(pathToMainPreviewHtml, pathToAdditionalFiles))
186+
.build();
187+
```
188+
160189
### RO-Crate validation (machine-readable crate profiles)
161190
Right now, the only implemented way of validating a RO-crate is to use a [JSON-Schema](https://json-schema.org/) that the crates metadata JSON file should match. JSON-Schema is an established standard and therefore a good choice for a crate profile. Example:
162191

@@ -395,8 +424,6 @@ The web resource does not use `.setSource()`, but uses the ID to indicate the fi
395424
{"@id": "data2.txt"}
396425
]
397426
},
398-
399-
400427
{
401428
"@id": "data1.txt",
402429
"@type": "File",
@@ -637,7 +664,6 @@ If there is no special method for including relative entities (ID properties) on
637664
.addIdProperty("additionalType", nucSec)
638665
.addIdProperty("encodingFormat", fasta)
639666
.build();
640-
641667
ContextualEntity clnParam = new ContextualEntity.ContextualEntityBuilder()
642668
.addType("FormalParameter")
643669
.setId("#6c703fee-6af7-4fdb-a57d-9e8bc4486044")
@@ -646,7 +672,6 @@ If there is no special method for including relative entities (ID properties) on
646672
.addIdProperty("additionalType", nucSec)
647673
.addIdProperty("encodingFormat", ban)
648674
.build();
649-
650675
ContextualEntity alignParam = new ContextualEntity.ContextualEntityBuilder()
651676
.addType("FormalParameter")
652677
.setId("#2f32b861-e43c-401f-8c42-04fd84273bdf")

build.gradle

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
id 'java'
33
id 'jvm-test-suite'
4-
4+
id 'application'
55
id 'jacoco'
66
// Adds coveralls task for CI to send results to the coveralls service.
77
id "com.github.kt3k.coveralls" version "2.12.2"
@@ -13,7 +13,7 @@ plugins {
1313
// Publishing of JAR to Nexus instances (e.g., OSSRH)
1414
// https://github.com/gradle-nexus/publish-plugin
1515
id "io.github.gradle-nexus.publish-plugin" version "2.0.0"
16-
id "io.freefair.maven-publish-java" version "8.13"
16+
id "io.freefair.maven-publish-java" version "8.13.1"
1717
}
1818

1919
group 'edu.kit.datamanager'
@@ -24,6 +24,9 @@ println "Building ${name} version: ${version}"
2424
println "JDK version: ${JavaVersion.current()}"
2525
println "Profile (system property): ${System.getProperty('profile')}"
2626

27+
sourceCompatibility = JavaVersion.VERSION_17
28+
targetCompatibility = JavaVersion.VERSION_17
29+
2730
if (JavaVersion.current() == JavaVersion.VERSION_17) {
2831
println "Setting encoding to UTF-8 manually"
2932
compileJava.options.encoding = "UTF-8"
@@ -40,7 +43,7 @@ ext {
4043

4144
dependencies {
4245
// JUnit setup for testing
43-
testImplementation(platform("org.junit:junit-bom:5.12.1"))
46+
testImplementation(platform("org.junit:junit-bom:5.12.2"))
4447
testImplementation('org.junit.jupiter:junit-jupiter')
4548
testRuntimeOnly('org.junit.platform:junit-platform-launcher')
4649
// JSON object mapping / (de-)serialization
@@ -49,11 +52,11 @@ dependencies {
4952
// http client
5053
implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.14'
5154
// common file system operations
52-
implementation group: 'commons-io', name: 'commons-io', version: '2.18.0'
55+
implementation group: 'commons-io', name: 'commons-io', version: '2.19.0'
5356
// read from and write to zip files
5457
implementation group: 'net.lingala.zip4j', name: 'zip4j', version: '2.11.5'
5558
// compare json documents in tests
56-
implementation 'com.github.fslev:json-compare:6.18'
59+
implementation 'com.github.fslev:json-compare:7.0'
5760
// url validator
5861
implementation group: 'commons-validator', name: 'commons-validator', version: '1.9.0'
5962
// logging
@@ -63,8 +66,13 @@ dependencies {
6366
// metadata validation, profiles based on JSON schema
6467
implementation group: "com.networknt", name: "json-schema-validator", version: "1.5.6"
6568
implementation 'org.glassfish:jakarta.json:2.0.1'
69+
//JTE for template processing
70+
implementation('gg.jte:jte:3.2.0')
71+
implementation("org.freemarker:freemarker:2.3.34")
6672
}
6773

74+
logging.captureStandardOutput LogLevel.INFO
75+
6876
def signingTasks = tasks.withType(Sign)
6977
tasks.withType(AbstractPublishToMaven).configureEach{
7078
mustRunAfter(signingTasks)
@@ -155,7 +163,7 @@ jacocoTestReport {
155163
}
156164

157165
jacoco {
158-
toolVersion = "0.8.12"
166+
toolVersion = "0.8.13"
159167
}
160168

161169
// maxParallelForks(2)

gradle.properties

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
version=2.0.3
1+
version=2.0.3
2+
action.custom-1=install
3+
action.custom-1.args=--configure-on-demand -w -x check clean publishToMavenLocal
4+
action.custom-2=jacoco
5+
action.custom-2.args=--configure-on-demand -w clean check jacocoTestReport
6+
action.custom-3=releaseNewVersion
7+
action.custom-3.args=--configure-on-demand -w -x check -Prelease release

ro-crate-metadata.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"@context" : "https://w3id.org/ro/crate/1.1/context",
3+
"@graph" : [ {
4+
"name" : "name",
5+
"description" : "description",
6+
"@id" : "./",
7+
"@type" : "Dataset",
8+
"license" : {
9+
"@id" : "https://creativecommons.org/licenses/by-nc-sa/3.0/au/"
10+
},
11+
"datePublished" : "2024"
12+
}, {
13+
"about" : {
14+
"@id" : "./"
15+
},
16+
"conformsTo" : {
17+
"@id" : "https://w3id.org/ro/crate/1.1"
18+
},
19+
"@id" : "ro-crate-metadata.json",
20+
"@type" : "CreativeWork"
21+
} ]
22+
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.File;
44
import java.util.Collection;
5+
import java.util.Map;
56
import java.util.Optional;
67
import java.util.Set;
78

@@ -51,6 +52,25 @@ public interface Crate {
5152

5253
void setMetadataContext(CrateMetadataContext metadataContext);
5354

55+
/**
56+
* Get the value of a key from the metadata context.
57+
* @param key the key to be searched
58+
* @return the value of the key, null if not found
59+
*/
60+
String getMetadataContextValueOf(String key);
61+
62+
/**
63+
* Get an immutable collection of the keys in the metadata context.
64+
* @return the keys in the metadata context
65+
*/
66+
Set<String> getMetadataContextKeys();
67+
68+
/**
69+
* Get an immutable map of the context.
70+
* @return an immutable map containing the context key-value pairs
71+
*/
72+
Map<String, String> getMetadataContextPairs();
73+
5474
RootDataEntity getRootDataEntity();
5575

5676
void setRootDataEntity(RootDataEntity rootDataEntity);

0 commit comments

Comments
 (0)