Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lyo-client-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,8 @@
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<!-- legacy, not planned for BOM -->
<groupId>org.eclipse.lyo.clients</groupId>
<artifactId>oslc-java-client-resources</artifactId>
<groupId>org.eclipse.lyo</groupId>
<artifactId>oslc-domains</artifactId>
<version>${v.lyo}</version>
</dependency>
<dependency>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.util.Collections;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
Expand All @@ -40,11 +41,11 @@
import org.eclipse.lyo.client.OslcClient;
import org.eclipse.lyo.client.RootServicesHelper;
import org.eclipse.lyo.client.exception.RootServicesException;
import org.eclipse.lyo.client.oslc.resources.TestCase;
import org.eclipse.lyo.client.oslc.resources.TestResult;
import org.eclipse.lyo.client.query.OslcQuery;
import org.eclipse.lyo.client.query.OslcQueryParameters;
import org.eclipse.lyo.client.query.OslcQueryResult;
import org.eclipse.lyo.oslc.domains.qm.TestCase;
import org.eclipse.lyo.oslc.domains.qm.TestResult;
import org.eclipse.lyo.oslc4j.core.model.Link;
import org.eclipse.lyo.oslc4j.core.model.OslcMediaType;
import org.glassfish.jersey.apache.connector.ApacheClientProperties;
Expand Down Expand Up @@ -188,9 +189,12 @@ public static Report run(
+ " content fully complies with accessibility standards");
testcase.addTestsChangeRequest(new Link(
new URI("http://cmprovider/changerequest/1"), "Implement accessibility in Pet Store application"));
testcase.setTypes(Collections.singleton(URI.create(OSLCConstants.OSLC_QM_V2 + "TestCase")));

String testcaseCreation = client.lookupCreationFactory(
serviceProviderUrl, OSLCConstants.OSLC_QM_V2, testcase.getRdfTypes()[0].toString());
serviceProviderUrl,
OSLCConstants.OSLC_QM_V2,
testcase.getTypes().iterator().next().toString());
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

The code calls getTypes().iterator().next() without first checking if the Set is empty. If setTypes was never called or was called with an empty Set, this will throw a NoSuchElementException. Add a null/empty check before accessing the iterator, or ensure setTypes is always called with a non-empty Set.

Suggested change
testcase.getTypes().iterator().next().toString());
OSLCConstants.OSLC_QM_V2 + "TestCase");

Copilot uses AI. Check for mistakes.
Response creationResponse = client.createResource(
testcaseCreation, testcase, OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_RDF_XML);
String testcaseLocation = creationResponse.getStringHeaders().getFirst(HttpHeaders.LOCATION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import javax.xml.namespace.QName;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -45,10 +46,10 @@
import org.eclipse.lyo.client.OslcClient;
import org.eclipse.lyo.client.RootServicesHelper;
import org.eclipse.lyo.client.exception.RootServicesException;
import org.eclipse.lyo.client.oslc.resources.ChangeRequest;
import org.eclipse.lyo.client.query.OslcQuery;
import org.eclipse.lyo.client.query.OslcQueryParameters;
import org.eclipse.lyo.client.query.OslcQueryResult;
import org.eclipse.lyo.oslc.domains.cm.ChangeRequest;
import org.eclipse.lyo.oslc4j.core.model.AllowedValues;
import org.eclipse.lyo.oslc4j.core.model.CreationFactory;
import org.eclipse.lyo.oslc4j.core.model.Link;
Expand All @@ -73,6 +74,9 @@ public class EWMSample {

private static final String RTC_NAMESPACE = "http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/";
private static final String RTC_FILED_AGAINST = "filedAgainst";
private static final String DCTERMS_NAMESPACE = "http://purl.org/dc/terms/";
private static final QName PROPERTY_DCTERMS_TYPE = new QName(DCTERMS_NAMESPACE, "type");
private static final QName PROPERTY_TESTED_BY_TEST_CASE = new QName(OSLCConstants.OSLC_CM_V2, "testedByTestCase");

@lombok.Data
public static class Report {
Expand Down Expand Up @@ -241,15 +245,20 @@ public static Report run(
task.setTitle("Implement accessibility in Pet Store application");
task.setDescription("Image elements must provide a description in the 'alt' attribute for"
+ " consumption by screen readers.");
task.addTestedByTestCase(
new Link(new URI("http://qmprovider/testcase/1"), "Accessibility verification using a screen reader"));
task.addDctermsType("task");
task.getExtendedProperties()
.put(
PROPERTY_TESTED_BY_TEST_CASE,
new Link(
new URI("http://qmprovider/testcase/1"),
"Accessibility verification using a screen reader"));
task.getExtendedProperties().put(PROPERTY_DCTERMS_TYPE, "task");
task.setTypes(Collections.singleton(URI.create(OSLCConstants.CM_CHANGE_REQUEST_TYPE)));

// Get the Creation Factory URL for task change requests so that we can create one
CreationFactory taskCreation = client.lookupCreationFactoryResource(
serviceProviderUrl,
OSLCConstants.OSLC_CM_V2,
task.getRdfTypes()[0].toString(),
task.getTypes().iterator().next().toString(),
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

The code calls getTypes().iterator().next() without first checking if the Set is empty. If setTypes was never called or was called with an empty Set, this will throw a NoSuchElementException. Add a null/empty check before accessing the iterator, or ensure setTypes is always called with a non-empty Set.

Copilot uses AI. Check for mistakes.
OSLCConstants.OSLC_CM_V2 + "task");
String factoryUrl = taskCreation.getCreation().toString();

Expand Down Expand Up @@ -325,16 +334,20 @@ public static Report run(
defect.setDescription(
"An error occurred when I tried to log in with a user ID that contained the '@'" + " symbol.");

defect.addTestedByTestCase(new Link(new URI("http://qmprovider/testcase/3"), "Global Verifcation Test"));
defect.getExtendedProperties()
.put(
PROPERTY_TESTED_BY_TEST_CASE,
new Link(new URI("http://qmprovider/testcase/3"), "Global Verification Test"));

defect.addDctermsType("defect");
defect.getExtendedProperties().put(PROPERTY_DCTERMS_TYPE, "defect");
defect.setTypes(Collections.singleton(URI.create(OSLCConstants.CM_CHANGE_REQUEST_TYPE)));

// Get the Creation Factory URL for change requests so that we can create one

CreationFactory defectCreation = client.lookupCreationFactoryResource(
serviceProviderUrl,
OSLCConstants.OSLC_CM_V2,
defect.getRdfTypes()[0].toString(),
defect.getTypes().iterator().next().toString(),
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

The code calls getTypes().iterator().next() without first checking if the Set is empty. If setTypes was never called or was called with an empty Set, this will throw a NoSuchElementException. Add a null/empty check before accessing the iterator, or ensure setTypes is always called with a non-empty Set.

Suggested change
defect.getTypes().iterator().next().toString(),
OSLCConstants.CM_CHANGE_REQUEST_TYPE,

Copilot uses AI. Check for mistakes.
OSLCConstants.OSLC_CM_V2 + "defect");

factoryUrl = defectCreation.getCreation().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.net.URL;
import java.util.Date;
import java.util.Properties;
import java.util.Set;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
Expand All @@ -33,10 +34,10 @@
import org.apache.http.ssl.SSLContextBuilder;
import org.eclipse.lyo.client.JEEFormAuthenticator;
import org.eclipse.lyo.client.OslcClient;
import org.eclipse.lyo.client.oslc.resources.AutomationConstants;
import org.eclipse.lyo.client.oslc.resources.AutomationRequest;
import org.eclipse.lyo.client.oslc.resources.AutomationResult;
import org.eclipse.lyo.client.oslc.resources.ParameterInstance;
import org.eclipse.lyo.oslc.domains.auto.AutomationRequest;
import org.eclipse.lyo.oslc.domains.auto.AutomationResult;
import org.eclipse.lyo.oslc.domains.auto.Oslc_autoDomainConstants;
import org.eclipse.lyo.oslc4j.core.model.Link;
import org.eclipse.lyo.samples.client.jazz.automation.impl.AutomationAdapter;
import org.eclipse.lyo.samples.client.jazz.automation.impl.AutomationException;
import org.eclipse.lyo.samples.client.jazz.automation.impl.AutomationRequestCanceledException;
Expand Down Expand Up @@ -191,7 +192,7 @@ public AutomationResult handleAutomationRequest(AutomationRequest request, Autom
adapter.sendProgressForRequest(50, request);

// execute the script with the parameters from the Automation Request
executeScript(script, request.getInputParameters(), adapter, request);
executeScript(script, request.getInputParameter(), adapter, request);

// Upload an attachment for the result
File attachment = getSampleFile();
Expand All @@ -202,19 +203,22 @@ public AutomationResult handleAutomationRequest(AutomationRequest request, Autom

// Add some rich text to the result
Element xhtmlTableElement = createXhtmlTable();
QName contributionQname = new QName(AutomationConstants.AUTOMATION_DOMAIN, "contribution");
QName contributionQname = new QName(Oslc_autoDomainConstants.AUTOMATION_NAMSPACE, "contribution");
result.getExtendedProperties().put(contributionQname, xhtmlTableElement);

// Set the verdict for the result
result.addVerdict(new URI(AutomationConstants.VERDICT_PASSED));
result.addVerdict(new Link(new URI(VERDICT_PASSED)));

// Save the end time in the result
result.getExtendedProperties().put(PROPERTY_RQM_END_TIME, new Date(System.currentTimeMillis()));

// update progress indication
adapter.sendProgressForRequest(99, request);

log.info("Returning a result with verdict {}", result.getVerdicts()[0]);
Link[] verdicts = result.getVerdict().toArray(new Link[0]);
if (verdicts.length > 0) {
log.info("Returning a result with verdict {}", verdicts[0]);
}

} catch (AutomationRequestCanceledException e) {

Expand Down Expand Up @@ -248,7 +252,7 @@ public AutomationResult handleAutomationRequest(AutomationRequest request, Autom
* @throws IOException
*/
private void executeScript(
Document script, ParameterInstance[] inputParameters, AutomationAdapter adapter, AutomationRequest request)
Document script, Set<Link> inputParameters, AutomationAdapter adapter, AutomationRequest request)
throws InterruptedException, AutomationException, IOException, URISyntaxException {

String scriptTitle = script.getDocumentElement()
Expand All @@ -259,9 +263,18 @@ private void executeScript(
log.info("Running script named '{}'", scriptTitle);

log.info("Input parameters:");
for (ParameterInstance parameter : inputParameters) {
String paramStr = "\t" + parameter.getName() + ": " + parameter.getValue();
log.info(paramStr);
if (inputParameters != null) {
for (Link parameterLink : inputParameters) {
// Note: The new oslc-domains AutomationRequest maps inputParameter to Set<Link>.
// If the parameter is an inline resource (as is common in Automation), the Link might
// not contain the detailed properties (name, value) unless we fetch it or parse the model manually.
// For now, we log the link.
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

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

[nitpick] This comment clearly explains a limitation in the migration. However, consider adding a TODO or FIXME to indicate this is incomplete functionality that should be addressed in the future.

Suggested change
// For now, we log the link.
// TODO: For now, we log the link. Improve this to fetch or parse inline resource properties if needed.

Copilot uses AI. Check for mistakes.
String paramStr = "\tParameter Link: " + parameterLink.getValue();
if (parameterLink.getLabel() != null) {
paramStr += " (" + parameterLink.getLabel() + ")";
}
log.info(paramStr);
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@
import org.eclipse.lyo.client.RootServicesHelper;
import org.eclipse.lyo.client.exception.ResourceNotFoundException;
import org.eclipse.lyo.client.exception.RootServicesException;
import org.eclipse.lyo.client.oslc.resources.AutomationConstants;
import org.eclipse.lyo.client.oslc.resources.AutomationPlan;
import org.eclipse.lyo.client.oslc.resources.AutomationRequest;
import org.eclipse.lyo.client.oslc.resources.AutomationResult;
import org.eclipse.lyo.client.oslc.resources.TestScript;
import org.eclipse.lyo.oslc.domains.auto.AutomationPlan;
import org.eclipse.lyo.oslc.domains.auto.AutomationRequest;
import org.eclipse.lyo.oslc.domains.auto.AutomationResult;
import org.eclipse.lyo.oslc.domains.qm.TestScript;
import org.eclipse.lyo.oslc4j.core.annotation.OslcDescription;
import org.eclipse.lyo.oslc4j.core.annotation.OslcName;
import org.eclipse.lyo.oslc4j.core.annotation.OslcNamespace;
Expand Down Expand Up @@ -474,10 +473,8 @@ private void saveResult(AutomationResult result, AutomationRequest request)
e.printStackTrace();
}

resultCreationFactoryUrl = client.lookupCreationFactory(
serviceProviderUrl,
AutomationConstants.AUTOMATION_DOMAIN,
AutomationConstants.TYPE_AUTOMATION_RESULT);
resultCreationFactoryUrl =
client.lookupCreationFactory(serviceProviderUrl, AUTOMATION_DOMAIN, TYPE_AUTOMATION_RESULT);
}

response = client.createResource(resultCreationFactoryUrl, result, OslcMediaType.APPLICATION_RDF_XML);
Expand Down Expand Up @@ -509,7 +506,8 @@ private void completeRequest(AutomationRequest request)

assertNotCanceled(request);

request.setStates(new URI[] {URI.create(AutomationConstants.STATE_COMPLETE)});
// oslc-domains AutomationRequest.setState uses Set<Link>
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

The comment references "oslc-domains AutomationRequest.setState uses Set<Link>" but doesn't mention that the old API used URI[]. While the comment is helpful, consider clarifying that this is a migration from the previous API (e.g., "The old API used URI[], but oslc-domains AutomationRequest.setState uses Set<Link>").

Suggested change
// oslc-domains AutomationRequest.setState uses Set<Link>
// Migration note: the old API used URI[], but oslc-domains AutomationRequest.setState now uses Set<Link>

Copilot uses AI. Check for mistakes.
request.setState(new java.util.HashSet<>(Arrays.asList(new Link(URI.create(STATE_COMPLETE)))));

request.getExtendedProperties().remove(PROPERTY_RQM_PROGRESS);

Expand Down Expand Up @@ -565,8 +563,7 @@ private String getNextAssignmentUrl() throws AutomationException, IOException, U
model.read(is, assignedWorkUrl.toString());
}

StmtIterator stmtIter =
model.listStatements(null, RDF.type, model.createResource(AutomationConstants.TYPE_AUTOMATION_REQUEST));
StmtIterator stmtIter = model.listStatements(null, RDF.type, model.createResource(TYPE_AUTOMATION_REQUEST));

if (stmtIter.hasNext()) {
return stmtIter.next().getSubject().getURI();
Expand Down Expand Up @@ -597,7 +594,7 @@ private AutomationRequest takeAssignment(String requestUrl)

request.getExtendedProperties().put(PROPERTY_RQM_TAKEN, Boolean.TRUE);

request.setStates(new URI[] {URI.create(AutomationConstants.STATE_IN_PROGRESS)});
request.setState(new java.util.HashSet<>(Arrays.asList(new Link(URI.create(STATE_IN_PROGRESS)))));

updateUri = appendOslcProperties(URI.create(requestUrl), "oslc_auto:state", "rqm_auto:taken");

Expand Down Expand Up @@ -657,8 +654,8 @@ public void register() throws AutomationException, IOException, URISyntaxExcepti
e.printStackTrace();
}

adapterCreationFactoryUrl = client.lookupCreationFactory(
serviceProviderUrl, AutomationConstants.AUTOMATION_DOMAIN, TYPE_AUTOMATION_ADAPTER);
adapterCreationFactoryUrl =
client.lookupCreationFactory(serviceProviderUrl, AUTOMATION_DOMAIN, TYPE_AUTOMATION_ADAPTER);

response = client.createResource(adapterCreationFactoryUrl, this, OslcMediaType.APPLICATION_RDF_XML);

Expand Down Expand Up @@ -824,7 +821,20 @@ public Document getScriptDocument(AutomationRequest request)
TestScript script = client.getResource(scriptURI.toString(), OslcMediaType.APPLICATION_RDF_XML)
.readEntity(TestScript.class);

URI scriptUri = (URI) script.getExtendedProperties().get(PROPERTY_DC_RELATION);
// Access dcterms:relation via extended properties because TestScript does not provide a direct getter for
// this property.
Object relationObj = script.getExtendedProperties().get(PROPERTY_DC_RELATION);
URI scriptUri = null;
if (relationObj instanceof URI rI) {
scriptUri = rI;
} else if (relationObj instanceof Link link) {
scriptUri = link.getValue();
}

if (scriptUri == null) {
// Try to find if it's mapped to a field? No easy way.
throw new AutomationException("TestScript relation property not found.");
}

is = client.getResource(scriptUri.toString(), OslcMediaType.APPLICATION_XML)
.readEntity(InputStream.class);
Expand Down Expand Up @@ -882,7 +892,8 @@ private void populateResultFromRequest(AutomationRequest request, AutomationResu

Link automationPlan = request.getExecutesAutomationPlan();

result.setInputParameters(request.getInputParameters());
// oslc-domains AutomationResult uses Set<Link> for inputParameter
result.setInputParameter(request.getInputParameter());

Map<QName, Object> requestExtProperties = request.getExtendedProperties();

Expand Down Expand Up @@ -1177,10 +1188,10 @@ public void cancel(AutomationRequest request) throws AutomationException {
throw new AutomationException("The adapter has not logged into the server.");
}

request.setDesiredState(URI.create(AutomationConstants.STATE_CANCELED));
request.setDesiredState(new Link(URI.create(STATE_CANCELED)));

// Some automation providers require the client to set the state to canceled
request.setStates(new URI[] {URI.create(AutomationConstants.STATE_CANCELED)});
request.setState(new java.util.HashSet<>(Arrays.asList(new Link(URI.create(STATE_CANCELED)))));

URI updateUri = appendOslcProperties(request.getAbout(), "oslc_auto:state");

Expand Down Expand Up @@ -1224,10 +1235,14 @@ private void assertNotCanceled(AutomationRequest request)
.readEntity(AutomationRequest.class);
}

// oslc_auto:state is defined as one-or-many in the specification
URI stateUri = requestAtServiceProvider.getStates()[0];
// oslc_auto:state is defined as zero-or-many in oslc-domains (Set<Link>)
Set<Link> states = requestAtServiceProvider.getState();
URI stateUri = null;
if (states != null && !states.isEmpty()) {
stateUri = states.iterator().next().getValue();
}

if (URI.create(AutomationConstants.STATE_CANCELED).equals(stateUri)) {
if (URI.create(STATE_CANCELED).equals(stateUri)) {

throw new AutomationRequestCanceledException(request);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package org.eclipse.lyo.samples.client.jazz.automation.impl;

import java.io.Serial;
import org.eclipse.lyo.client.oslc.resources.AutomationRequest;
import org.eclipse.lyo.oslc.domains.auto.AutomationRequest;

/** An exception thrown when an AutomationRequest has been canceled */
public class AutomationRequestCanceledException extends AutomationException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package org.eclipse.lyo.samples.client.jazz.automation.impl;

import org.eclipse.lyo.client.oslc.resources.AutomationRequest;
import org.eclipse.lyo.client.oslc.resources.AutomationResult;
import org.eclipse.lyo.oslc.domains.auto.AutomationRequest;
import org.eclipse.lyo.oslc.domains.auto.AutomationResult;

public interface IAutomationRequestHandler {

Expand Down
Loading
Loading