Skip to content

Conversation

@berezovskyi
Copy link
Contributor

@berezovskyi berezovskyi commented Jun 25, 2022

Description

Map RDF language to an exact format needed by https://jena.apache.org/documentation/io/rdf-output.html. This PR maps regular XML/RDF to RDFXML_PLAIN, which is NOT rdf/xml-ABBREV, unless ABBREV is chosen specifically:

https://github.com/eclipse/lyo/blob/b-jena-format-spec/core/oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/AbstractOslcRdfXmlProvider.java#L152-L158

Potentially, allow for more RDF/XML config as per https://jena.apache.org/documentation/io/rdfxml_howto.html

Checklist

  • This PR adds an entry to the CHANGELOG. See https://keepachangelog.com/en/1.0.0/ for instructions. Minor edits are exempt.
  • This PR was tested on at least one Lyo OSLC server or adds unit/integration tests.
  • This PR does NOT break the API

Issues

https://forum.open-services.net/t/doors-lyo-incompatibility/631/5

@berezovskyi
Copy link
Contributor Author

@jadelkhoury need your help here.

I just tested this PR on both refimpl and lyo-samples (against two live Jazz servers, which is relevant because this PR was trying to fix an issue for DNG).

lyo-samples build went just fine: https://github.com/OSLC/lyo-samples/actions/runs/4703021261/jobs/8341007496

But the refimpl fails in https://github.com/oslc-op/refimpl/actions/runs/4703012037/jobs/8340986025#step:7:224 due to a bunch of class-not-found errors:

image

There is no way this PR introduces this problem. Could you please check if this should be happening and where the fix is needed?

@berezovskyi
Copy link
Contributor Author

Scratch that, I just realized this branch has not been rebased for quite a while and master works just fine.

Refimpl test against lyo@b-jena-format-spec works fine after rebase: https://github.com/oslc-op/refimpl/actions/runs/4703438070/jobs/8341937611

The sample code for lyo-client still tests fine against 2 ELM installs: https://github.com/OSLC/lyo-samples/actions/runs/4703456458/jobs/8341977320

But hey, it was a good test of my new semi-automatic PR testing flow!

@berezovskyi berezovskyi added this to the 5.1 milestone Apr 14, 2023
@berezovskyi berezovskyi changed the title Control the output format manually Control the RDF output format manually Apr 14, 2023
@github-actions github-actions bot force-pushed the b-jena-format-spec branch 6 times, most recently from 3e44a71 to 14fee00 Compare May 2, 2023 07:43
@github-actions github-actions bot force-pushed the b-jena-format-spec branch 2 times, most recently from dddd698 to fae096f Compare May 24, 2023 07:43
@github-actions github-actions bot force-pushed the b-jena-format-spec branch from fae096f to 98fd159 Compare June 13, 2023 07:43
@berezovskyi
Copy link
Contributor Author

berezovskyi commented Jun 13, 2023

While I didn't see any breaking effect from the PR (labelling Breaking anyway, in case someone depends on this, cf. Hyrum's law), let's keep it until Lyo 6.0. I think we can aim for 6.0 release around Christmas because Jena plans to drop JDK 11 support in the fall and we will likely have to catch up before 2024.

@berezovskyi berezovskyi modified the milestones: 5.1, 6.0 Jun 13, 2023
@berezovskyi
Copy link
Contributor Author

Additionally, I think it would be good to add a switch (JVM property, potentially) to control pretty/fast output format. E.g. we could use RDFXML_PLAIN for performance/production and RDFXML_PRETTY for debug (same for TURTLE_BLOCKS vs TURTLE_PRETTY). I had this thought before but didn't want to consider breaking changes but now it's worth to revisit since we retarget the PR for 6.0.

@github-actions github-actions bot force-pushed the b-jena-format-spec branch 4 times, most recently from 9b1d7ba to 60946b8 Compare June 21, 2023 07:43
@github-actions github-actions bot force-pushed the b-jena-format-spec branch from 60946b8 to 94223a7 Compare June 30, 2023 07:44
@berezovskyi berezovskyi changed the title Control the RDF output format manually feat: Control the RDF output format manually Jun 30, 2023
@github-actions github-actions bot force-pushed the b-jena-format-spec branch 2 times, most recently from 4ef534e to 51cb26d Compare July 14, 2023 07:43
@github-actions github-actions bot force-pushed the b-jena-format-spec branch 2 times, most recently from b2cfc91 to 3a3f805 Compare August 5, 2023 07:43
Signed-off-by: Andrew Berezovskyi <andriib@kth.se>
@berezovskyi
Copy link
Contributor Author

@oslc-bot /test-all

@oslc-bot
Copy link

oslc-bot commented Jul 16, 2025

Downstream Build Status

Repository Lyo CI Job state Workflow
oslc-op/refimpl ✅ Pass completed Link
oslc/lyo-samples ✅ Pass completed Link
oslc/promcode-lyo-server ✅ Pass completed Link

# Conflicts:
#	core/oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/AbstractOslcRdfXmlProvider.java
Signed-off-by: Andrew Berezovskyi <andriib@kth.se>
@berezovskyi
Copy link
Contributor Author

@oslc-bot /test-all

@oslc-bot
Copy link

oslc-bot commented Nov 29, 2025

Downstream Build Status

Repository Lyo CI Job state Workflow
oslc-op/refimpl 🔴 Fail completed Link
oslc/lyo-samples ✅ Pass completed Link
oslc/promcode-lyo-server 🔴 Fail completed Link

Copilot AI review requested due to automatic review settings December 13, 2025 17:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds manual control over RDF output format by mapping RDF serialization languages to specific Jena RDFFormat types. The key change maps regular RDF/XML to RDFXML_PLAIN (not abbreviated) unless the abbreviated format is explicitly requested, addressing compatibility issues with IBM DOORS.

Key changes:

  • Introduces a resolveFormat() method to map serialization language strings to specific RDFFormat constants
  • Modifies the write path to use RDFDataMgr.write() with explicit formats for non-abbreviated serializations
  • Preserves the existing abbreviated RDF/XML behavior through conditional branching

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +154 to +160
if (writer instanceof RdfXmlAbbreviatedWriter) {
writer.write(model,
outputStream,
null);
} else {
RDFDataMgr.write(outputStream, model, resolveFormat(serializationLanguage));
}
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation of this code block is inconsistent with the rest of the file. The if-else block should use consistent indentation matching the surrounding code style (typically 2 or 4 spaces per level).

Suggested change
if (writer instanceof RdfXmlAbbreviatedWriter) {
writer.write(model,
outputStream,
null);
} else {
RDFDataMgr.write(outputStream, model, resolveFormat(serializationLanguage));
}
if (writer instanceof RdfXmlAbbreviatedWriter) {
writer.write(model,
outputStream,
null);
} else {
RDFDataMgr.write(outputStream, model, resolveFormat(serializationLanguage));
}

Copilot uses AI. Check for mistakes.
Comment on lines +170 to +183
private RDFFormat resolveFormat(String serializationLanguage) {
switch (serializationLanguage) {
case RDFLanguages.strLangRDFXML:
return RDFFormat.RDFXML_PLAIN;
case RDFLanguages.strLangTurtle:
return RDFFormat.TURTLE_PRETTY;
case RDFLanguages.strLangNTriples:
return RDFFormat.NTRIPLES_UTF8;
case RDFLanguages.strLangJSONLD:
return RDFFormat.JSONLD;
default:
throw new IllegalArgumentException();
}
}
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation of this method is inconsistent with the rest of the file. The method body and switch statement should use consistent indentation matching the surrounding code style (typically 2 or 4 spaces per level).

Suggested change
private RDFFormat resolveFormat(String serializationLanguage) {
switch (serializationLanguage) {
case RDFLanguages.strLangRDFXML:
return RDFFormat.RDFXML_PLAIN;
case RDFLanguages.strLangTurtle:
return RDFFormat.TURTLE_PRETTY;
case RDFLanguages.strLangNTriples:
return RDFFormat.NTRIPLES_UTF8;
case RDFLanguages.strLangJSONLD:
return RDFFormat.JSONLD;
default:
throw new IllegalArgumentException();
}
}
private RDFFormat resolveFormat(String serializationLanguage) {
switch (serializationLanguage) {
case RDFLanguages.strLangRDFXML:
return RDFFormat.RDFXML_PLAIN;
case RDFLanguages.strLangTurtle:
return RDFFormat.TURTLE_PRETTY;
case RDFLanguages.strLangNTriples:
return RDFFormat.NTRIPLES_UTF8;
case RDFLanguages.strLangJSONLD:
return RDFFormat.JSONLD;
default:
throw new IllegalArgumentException();
}
}

Copilot uses AI. Check for mistakes.
outputStream,
null);
} else {
RDFDataMgr.write(outputStream, model, resolveFormat(serializationLanguage));
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using RDFDataMgr.write() with RDFXML_PLAIN format, Jena may write its own XML declaration. Combined with the manual XML declaration written at lines 151-152 (for XML formats), this could result in duplicate XML declarations in the output. Consider either removing the manual XML declaration for non-abbreviated cases that use RDFDataMgr.write(), or configuring RDFDataMgr to suppress its XML declaration.

Copilot uses AI. Check for mistakes.
case RDFLanguages.strLangJSONLD:
return RDFFormat.JSONLD;
default:
throw new IllegalArgumentException();
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default case throws an IllegalArgumentException with no error message. This makes it difficult to debug when an unsupported serialization language is passed. Consider adding a descriptive error message that includes the unsupported serialization language value to help with troubleshooting.

Suggested change
throw new IllegalArgumentException();
throw new IllegalArgumentException("Unsupported serialization language: " + serializationLanguage);

Copilot uses AI. Check for mistakes.
@berezovskyi
Copy link
Contributor Author

@oslc-bot /test-all

@oslc-bot
Copy link

oslc-bot commented Dec 22, 2025

Downstream Build Status

Repository Lyo CI Job state Workflow
oslc-op/refimpl ✅ Pass completed Link
oslc/lyo-samples ✅ Pass completed Link
oslc/promcode-lyo-server ✅ Pass completed Link

@berezovskyi
Copy link
Contributor Author

In the current Lyo code, this should be enough to get things working with most Jazz tools, e.g. RRC:

System.setProperty("org.eclipse.lyo.oslc4j.alwaysXMLAbbrev", "true");

We will hold this patch until we are sure that the new approach still works with abbrev-dependent systems like Jazz.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants