-
Notifications
You must be signed in to change notification settings - Fork 8
Migrate lyo-client-samples to oslc-domains #274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
66dec0a
078782d
85ae15d
9404d8f
6e84347
7da4b09
d864f50
30df4a0
553c222
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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; | ||||||
|
|
@@ -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; | ||||||
|
|
@@ -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 { | ||||||
|
|
@@ -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(), | ||||||
|
||||||
| OSLCConstants.OSLC_CM_V2 + "task"); | ||||||
| String factoryUrl = taskCreation.getCreation().toString(); | ||||||
|
|
||||||
|
|
@@ -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(), | ||||||
|
||||||
| defect.getTypes().iterator().next().toString(), | |
| OSLCConstants.CM_CHANGE_REQUEST_TYPE, |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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; | ||||||
|
|
@@ -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; | ||||||
|
|
@@ -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(); | ||||||
|
|
@@ -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) { | ||||||
|
|
||||||
|
|
@@ -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() | ||||||
|
|
@@ -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. | ||||||
|
||||||
| // For now, we log the link. | |
| // TODO: For now, we log the link. Improve this to fetch or parse inline resource properties if needed. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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; | ||||||
|
|
@@ -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); | ||||||
|
|
@@ -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> | ||||||
|
||||||
| // oslc-domains AutomationRequest.setState uses Set<Link> | |
| // Migration note: the old API used URI[], but oslc-domains AutomationRequest.setState now uses Set<Link> |
There was a problem hiding this comment.
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.