diff --git a/lyo-client-samples/pom.xml b/lyo-client-samples/pom.xml index d7365fe..8e50b35 100644 --- a/lyo-client-samples/pom.xml +++ b/lyo-client-samples/pom.xml @@ -243,9 +243,8 @@ httpclient - - org.eclipse.lyo.clients - oslc-java-client-resources + org.eclipse.lyo + oslc-domains ${v.lyo} diff --git a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/ERMSample.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/ERMSample.java index 0757a86..5ff2021 100644 --- a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/ERMSample.java +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/ERMSample.java @@ -49,13 +49,12 @@ 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.Requirement; -import org.eclipse.lyo.client.oslc.resources.RequirementCollection; -import org.eclipse.lyo.client.oslc.resources.RmConstants; 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.client.resources.RmUtil; +import org.eclipse.lyo.oslc.domains.rm.Requirement; +import org.eclipse.lyo.oslc.domains.rm.RequirementCollection; import org.eclipse.lyo.oslc4j.core.OSLC4JUtils; import org.eclipse.lyo.oslc4j.core.model.*; import org.glassfish.jersey.apache.connector.ApacheClientProperties; @@ -75,10 +74,21 @@ @Slf4j public class ERMSample { + // Constants not present in standard oslc-domains or need replacement + // RmConstants were in oslc-java-client-resources. + // JAZZ_RM_NAMESPACE = "http://jazz.net/xmlns/prod/jazz/rm/1.0/" + // PROPERTY_PRIMARY_TEXT = new QName(JAZZ_RM_NAMESPACE, "primaryText") + // PROPERTY_PARENT_FOLDER = new QName(JAZZ_RM_NAMESPACE, "parent") + // NAMESPACE_URI_XHTML = "http://www.w3.org/1999/xhtml" + + public static final String JAZZ_RM_NAMESPACE = "http://jazz.net/ns/rm#"; + public static final QName PROPERTY_PRIMARY_TEXT = new QName(JAZZ_RM_NAMESPACE, "primaryText"); + public static final QName PROPERTY_PARENT_FOLDER = new QName(JAZZ_RM_NAMESPACE, "parent"); + public static final String NAMESPACE_URI_XHTML = "http://www.w3.org/1999/xhtml"; + // Following is a workaround for primaryText issue in DNG ( it is PrimaryText instead of // primaryText - private static final QName PROPERTY_PRIMARY_TEXT_WORKAROUND = - new QName(RmConstants.JAZZ_RM_NAMESPACE, "PrimaryText"); + private static final QName PROPERTY_PRIMARY_TEXT_WORKAROUND = new QName(JAZZ_RM_NAMESPACE, "PrimaryText"); @lombok.Data public static class Report { @@ -104,9 +114,7 @@ public static class Report { * @throws ParseException */ public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addOption("url", true, "url"); options.addOption("user", true, "user ID"); options.addOption("password", true, "password"); @@ -114,8 +122,6 @@ public static void main(String[] args) throws Exception { options.addOption("b", "basic", false, "Use Basic auth (use if JAS is enabled)"); CommandLineParser cliParser = new GnuParser(); - - // Parse the command line CommandLine cmd = cliParser.parse(options, args); if (!validateOptions(cmd)) { @@ -155,66 +161,40 @@ public static Report run( String webContextUrl, String userId, String password, String projectArea, boolean useBasicAuth) throws Exception { Report report = new Report(); - - // STEP 1: Configure the ClientBuilder as needed for your client application - - // Use HttpClient instead of the default HttpUrlConnection ClientConfig clientConfig = new ClientConfig().connectorProvider(new ApacheConnectorProvider()); - if (Boolean.getBoolean("lyo.record.fixtures")) { clientConfig.register(new FixtureRecorderFilter()); } - - // Fixes Invalid cookie header: ... Invalid 'expires' attribute: Thu, 01 Dec 1994 - // 16:00:00 GMT clientConfig.property( ApacheClientProperties.REQUEST_CONFIG, RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build()); clientConfig.register(MultiPartFeature.class); ClientBuilder clientBuilder = ClientBuilder.newBuilder(); - - // IBM jazz-apps use JEE Form based authentication - // except the Jazz sandbox, it uses Basic/JAS auth. USE ONLY ONE if (useBasicAuth) { clientConfig.register(HttpAuthenticationFeature.basic(userId, password)); log.info("Using Basic authentication"); } clientBuilder.withConfig(clientConfig); - // Setup SSL support to ignore self-assigned SSL certificates - for testing only!! SSLContextBuilder sslContextBuilder = new SSLContextBuilder(); sslContextBuilder.loadTrustMaterial(TrustSelfSignedStrategy.INSTANCE); clientBuilder.sslContext(sslContextBuilder.build()); clientBuilder.hostnameVerifier(NoopHostnameVerifier.INSTANCE); - // do not merge the two if's: order of registration is important if (!useBasicAuth) { clientBuilder.register(new JEEFormAuthenticator(webContextUrl, userId, password)); log.info("Using JAS (Forms) authentication"); } - // STEP 3: Create a new OslcClient OslcClient client = new OslcClient(clientBuilder); - - // STEP 4: Get the URL of the OSLC ChangeManagement service from the rootservices - // document String catalogUrl = new RootServicesHelper(webContextUrl, OSLCConstants.OSLC_RM_V2, client).getCatalogUrl(); - - // STEP 5: Find the OSLC Service Provider for the project area we want to work with String serviceProviderUrl = client.lookupServiceProviderUrl(catalogUrl, projectArea); - - // STEP 6: Get the Query Capabilities URL so that we can run some OSLC queries String queryCapability = client.lookupQueryCapability( serviceProviderUrl, OSLCConstants.OSLC_RM_V2, OSLCConstants.RM_REQUIREMENT_TYPE); - - // STEP 7: Create base requirements - // Get the Creation Factory URL for change requests so that we can create one - String requirementFactory = client.lookupCreationFactory( serviceProviderUrl, OSLCConstants.OSLC_RM_V2, OSLCConstants.RM_REQUIREMENT_TYPE); - // Get Feature Requirement Type URL ResourceShape featureInstanceShape = null; ResourceShape collectionInstanceShape = null; try { @@ -229,7 +209,6 @@ public static Report run( } catch (IOException | URISyntaxException | OAuthException e) { throw e; } catch (ResourceNotFoundException e) { - // Feature shape is not defined if SAFe framework is used featureInstanceShape = lookupRequirementsInstanceShapes( serviceProviderUrl, OSLCConstants.OSLC_RM_V2, @@ -246,9 +225,6 @@ public static Report run( client, "Collection"); - // We need to use Resource shapes to properly handle date attributes, - // so they aren't interpreted as dateTime. - // The following 4 lines will enable the logic to properly handle date attributes List shapes = new ArrayList<>(); shapes.add(featureInstanceShape); shapes.add(collectionInstanceShape); @@ -257,8 +233,7 @@ public static Report run( } catch (IOException | URISyntaxException | OAuthException e) { throw new RuntimeException(e); } catch (ResourceNotFoundException e) { - // throw new RuntimeException(e); - log.warn("OSLC Server does not provide Collection and Feature (or User Requirement)" + " instance shapes"); + log.warn("OSLC Server does not provide Collection and Feature (or User Requirement) instance shapes"); log.debug("Exception", e); } @@ -277,19 +252,16 @@ public static Report run( if (featureInstanceShape == null) { log.warn("Cannot create resources without access to shapes, skipping"); } else { - // Create REQ01 requirement = new Requirement(); - requirement.setInstanceShape(featureInstanceShape.getAbout()); + requirement.setInstanceShape(Collections.singleton(new Link(featureInstanceShape.getAbout()))); requirement.setTitle("Req01"); - // Decorate the PrimaryText primaryText = "My Primary Text"; org.w3c.dom.Element obj = convertStringToHTML(primaryText); - requirement.getExtendedProperties().put(RmConstants.PROPERTY_PRIMARY_TEXT, obj); + requirement.getExtendedProperties().put(PROPERTY_PRIMARY_TEXT, obj); requirement.setDescription("Created By EclipseLyo"); requirement.addImplementedBy(new Link(new URI("http://google.com"), "Link in REQ01")); - // Create the Requirement try (Response creationResponse = client.createResource( requirementFactory, requirement, @@ -302,13 +274,11 @@ public static Report run( report.setReq01Url(relativize(req01URL, webContextUrl)); } - // Create REQ02 requirement = new Requirement(); - requirement.setInstanceShape(featureInstanceShape.getAbout()); + requirement.setInstanceShape(Collections.singleton(new Link(featureInstanceShape.getAbout()))); requirement.setTitle("Req02"); requirement.setDescription("Created By EclipseLyo"); requirement.addValidatedBy(new Link(new URI("http://bancomer.com"), "Link in REQ02")); - // Create the change request try (Response creationResponse = client.createResource( requirementFactory, requirement, @@ -321,13 +291,11 @@ public static Report run( report.setReq02Url(relativize(req02URL, webContextUrl)); } - // Create REQ03 requirement = new Requirement(); - requirement.setInstanceShape(featureInstanceShape.getAbout()); + requirement.setInstanceShape(Collections.singleton(new Link(featureInstanceShape.getAbout()))); requirement.setTitle("Req03"); requirement.setDescription("Created By EclipseLyo"); requirement.addValidatedBy(new Link(new URI("http://outlook.com"), "Link in REQ03")); - // Create the change request try (Response creationResponse = client.createResource( requirementFactory, requirement, @@ -340,13 +308,10 @@ public static Report run( report.setReq03Url(relativize(req03URL, webContextUrl)); } - // Create REQ04 requirement = new Requirement(); - requirement.setInstanceShape(featureInstanceShape.getAbout()); + requirement.setInstanceShape(Collections.singleton(new Link(featureInstanceShape.getAbout()))); requirement.setTitle("Req04"); requirement.setDescription("Created By EclipseLyo"); - - // Create the Requirement try (Response creationResponse = client.createResource( requirementFactory, requirement, @@ -359,19 +324,14 @@ public static Report run( report.setReq04Url(relativize(req04URL, webContextUrl)); } - // Now create a collection - // Create REQ04 collection = new RequirementCollection(); - - collection.addUses(new URI(req03URL)); - collection.addUses(new URI(req04URL)); - + collection.addUses(new Link(new URI(req03URL))); + collection.addUses(new Link(new URI(req04URL))); if (collectionInstanceShape != null) { - collection.setInstanceShape(collectionInstanceShape.getAbout()); + collection.setInstanceShape(Collections.singleton(new Link(collectionInstanceShape.getAbout()))); } collection.setTitle("Collection01"); collection.setDescription("Created By EclipseLyo"); - // Create the collection try (Response creationResponse = client.createResource( requirementFactory, collection, @@ -384,7 +344,6 @@ public static Report run( report.setReqColl01Url(relativize(reqcoll01URL, webContextUrl)); } - // Check that everything was properly created if (req01URL == null || req02URL == null || req03URL == null @@ -395,11 +354,9 @@ public static Report run( } } - // GET the root folder based on First requirement created Response getResponse = client.getResource(req01URL, OslcMediaType.APPLICATION_RDF_XML); requirement = getResponse.readEntity(Requirement.class); - // Display attributes based on the Resource shape Map requestExtProperties = requirement.getExtendedProperties(); for (QName qname : requestExtProperties.keySet()) { Property attr = featureInstanceShape.getProperty(new URI(qname.getNamespaceURI() + qname.getLocalPart())); @@ -413,25 +370,20 @@ public static Report run( } } - // Save the URI of the root folder in order to used it easily - rootFolder = (URI) requirement.getExtendedProperties().get(RmConstants.PROPERTY_PARENT_FOLDER); - Object changedPrimaryText = (Object) requirement.getExtendedProperties().get(RmConstants.PROPERTY_PRIMARY_TEXT); + rootFolder = (URI) requirement.getExtendedProperties().get(PROPERTY_PARENT_FOLDER); + Object changedPrimaryText = (Object) requirement.getExtendedProperties().get(PROPERTY_PRIMARY_TEXT); if (changedPrimaryText == null) { - // Check with the workaround changedPrimaryText = (Object) requirement.getExtendedProperties().get(PROPERTY_PRIMARY_TEXT_WORKAROUND); } String primarytextString = null; if (changedPrimaryText != null) { - primarytextString = changedPrimaryText.toString(); // Handle the case where Primary Text is returned as - // XMLLiteral + primarytextString = changedPrimaryText.toString(); } if ((primarytextString != null) && (!primarytextString.contains(primaryText))) { log.error("Error getting primary Text"); } - // QUERIES - // SCENARIO 01 Do a query for type= Requirement OslcQueryParameters queryParams = new OslcQueryParameters(); queryParams.setPrefix("rdf="); queryParams.setWhere("rdf:type="); @@ -444,8 +396,6 @@ public static Report run( System.out.println("\n------------------------------\n"); System.out.println("Number of Results for SCENARIO 01 = " + resultsSize + "\n"); - // SCENARIO 02 Do a query for type= Requirements and for it folder container = - // rootFolder queryParams = new OslcQueryParameters(); queryParams.setPrefix("nav=,rdf="); queryParams.setWhere( @@ -459,7 +409,6 @@ public static Report run( System.out.println("\n------------------------------\n"); System.out.println("Number of Results for SCENARIO 02 = " + resultsSize + "\n"); - // SCENARIO 03 Do a query for title queryParams = new OslcQueryParameters(); queryParams.setPrefix("dcterms="); queryParams.setWhere("dcterms:title=\"Req04\""); @@ -472,7 +421,6 @@ public static Report run( System.out.println("\n------------------------------\n"); System.out.println("Number of Results for SCENARIO 03 = " + resultsSize + "\n"); - // SCENARIO 04 Do a query for the link that is implemented queryParams = new OslcQueryParameters(); queryParams.setPrefix("oslc_rm="); queryParams.setWhere("oslc_rm:implementedBy="); @@ -485,7 +433,6 @@ public static Report run( System.out.println("\n------------------------------\n"); System.out.println("Number of Results for SCENARIO 04 = " + resultsSize + "\n"); - // SCENARIO 05 Do a query for the links that is validated queryParams = new OslcQueryParameters(); queryParams.setPrefix("oslc_rm="); queryParams.setWhere("oslc_rm:validatedBy in [,]"); @@ -498,7 +445,6 @@ public static Report run( System.out.println("\n------------------------------\n"); System.out.println("Number of Results for SCENARIO 05 = " + resultsSize + "\n"); - // SCENARIO 06 Do a query for it container folder and for the link that is implemented queryParams = new OslcQueryParameters(); queryParams.setPrefix("nav=,oslc_rm="); queryParams.setWhere("nav:parent=<" + rootFolder + "> and oslc_rm:validatedBy="); @@ -511,22 +457,16 @@ public static Report run( System.out.println("\n------------------------------\n"); System.out.println("Number of Results for SCENARIO 06 = " + resultsSize + "\n"); - // GET resources from req03 in order edit its values getResponse = client.getResource(req03URL, OslcMediaType.APPLICATION_RDF_XML); requirement = getResponse.readEntity(Requirement.class); - // Get the eTAG, we need it to update String etag = getResponse.getStringHeaders().getFirst(OSLCConstants.ETAG); requirement.setTitle("My new Title"); requirement.addImplementedBy(new Link(new URI("http://google.com"), "Link created by an Eclipse Lyo user")); - // Update the requirement with the proper etag Response updateResponse = client.updateResource( req03URL, requirement, OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_RDF_XML, etag); - updateResponse.readEntity(String.class); - /*Do a query in order to see if the requirement have changed*/ - // SCENARIO 07 Do a query for the new title just changed queryParams = new OslcQueryParameters(); queryParams.setPrefix("dcterms="); queryParams.setWhere("dcterms:title=\"My new Title\""); @@ -539,7 +479,6 @@ public static Report run( System.out.println("\n------------------------------\n"); System.out.println("Number of Results for SCENARIO 07 = " + resultsSize + "\n"); - // SCENARIO 08 Do a query for implementedBy links queryParams = new OslcQueryParameters(); queryParams.setPrefix("oslc_rm="); queryParams.setWhere("oslc_rm:implementedBy="); @@ -559,7 +498,6 @@ private static String relativize(String url, String webContextUrl) { if (url.startsWith(webContextUrl)) { return url.substring(webContextUrl.length()); } - // Also handle the case where webContextUrl might have a trailing slash or not String base = webContextUrl.endsWith("/") ? webContextUrl : webContextUrl + "/"; if (url.startsWith(base)) { return url.substring(base.length()); @@ -571,7 +509,7 @@ private static Element convertStringToHTML(String primaryText) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); - Element divElement = document.createElementNS(RmConstants.NAMESPACE_URI_XHTML, "div"); + Element divElement = document.createElementNS(NAMESPACE_URI_XHTML, "div"); divElement.setTextContent(primaryText); return divElement; } catch (ParserConfigurationException e) { @@ -581,7 +519,6 @@ private static Element convertStringToHTML(String primaryText) { private static void processPagedQueryResults(OslcQueryResult result, OslcClient client, boolean asJavaObjects) { int page = 1; - // For now, just show first 5 pages do { System.out.println("\nPage " + page + ":\n"); processCurrentPage(result, client, asJavaObjects); @@ -599,15 +536,12 @@ private static void processCurrentPage(OslcQueryResult result, OslcClient client System.out.println(resultsUrl); try (Response response = client.getResource(resultsUrl, OSLCConstants.CT_RDF)) { - // Get a single artifact by its URL if (response != null) { response.bufferEntity(); - // De-serialize it as a Java object if (asJavaObjects) { Requirement req = response.readEntity(Requirement.class); - printRequirementInfo(req); // print a few attributes + printRequirementInfo(req); } else { - // Just print the raw RDF/XML (or process the XML as desired) processRawResponse(response); } } @@ -631,9 +565,7 @@ private static void processRawResponse(Response response) throws IOException { private static boolean validateOptions(CommandLine cmd) { boolean isValid = true; - if (!(cmd.hasOption("url") && cmd.hasOption("user") && cmd.hasOption("password") && cmd.hasOption("project"))) { - isValid = false; } return isValid; diff --git a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/ETMSample.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/ETMSample.java index e317112..3c88823 100644 --- a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/ETMSample.java +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/ETMSample.java @@ -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; @@ -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; @@ -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()); Response creationResponse = client.createResource( testcaseCreation, testcase, OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_RDF_XML); String testcaseLocation = creationResponse.getStringHeaders().getFirst(HttpHeaders.LOCATION); diff --git a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/EWMSample.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/EWMSample.java index e970f70..2ce3208 100644 --- a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/EWMSample.java +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/EWMSample.java @@ -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(), OSLCConstants.OSLC_CM_V2 + "defect"); factoryUrl = defectCreation.getCreation().toString(); diff --git a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/automation/ETMAutomationSample.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/automation/ETMAutomationSample.java index 71f0a0e..e9fd755 100644 --- a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/automation/ETMAutomationSample.java +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/automation/ETMAutomationSample.java @@ -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,11 +203,11 @@ 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())); @@ -214,7 +215,10 @@ public AutomationResult handleAutomationRequest(AutomationRequest request, Autom // 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 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. + // 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. + String paramStr = "\tParameter Link: " + parameterLink.getValue(); + if (parameterLink.getLabel() != null) { + paramStr += " (" + parameterLink.getLabel() + ")"; + } + log.info(paramStr); + } } /* diff --git a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/automation/impl/AutomationAdapter.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/automation/impl/AutomationAdapter.java index abfc86b..646b724 100644 --- a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/automation/impl/AutomationAdapter.java +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/automation/impl/AutomationAdapter.java @@ -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 + request.setState(new java.util.HashSet<>(Arrays.asList(new Link(URI.create(STATE_COMPLETE))))); request.getExtendedProperties().remove(PROPERTY_RQM_PROGRESS); @@ -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(); @@ -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"); @@ -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); @@ -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); @@ -882,7 +892,8 @@ private void populateResultFromRequest(AutomationRequest request, AutomationResu Link automationPlan = request.getExecutesAutomationPlan(); - result.setInputParameters(request.getInputParameters()); + // oslc-domains AutomationResult uses Set for inputParameter + result.setInputParameter(request.getInputParameter()); Map requestExtProperties = request.getExtendedProperties(); @@ -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"); @@ -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) + Set 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); } diff --git a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/automation/impl/AutomationRequestCanceledException.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/automation/impl/AutomationRequestCanceledException.java index 92872f6..a5dd015 100644 --- a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/automation/impl/AutomationRequestCanceledException.java +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/automation/impl/AutomationRequestCanceledException.java @@ -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 { diff --git a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/automation/impl/IAutomationRequestHandler.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/automation/impl/IAutomationRequestHandler.java index b1654d7..98cdbd8 100644 --- a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/automation/impl/IAutomationRequestHandler.java +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/automation/impl/IAutomationRequestHandler.java @@ -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 { diff --git a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/automation/impl/IConstants.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/automation/impl/IConstants.java index 12f1a83..8c28a57 100644 --- a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/automation/impl/IConstants.java +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/jazz/automation/impl/IConstants.java @@ -17,6 +17,8 @@ import javax.xml.namespace.QName; import org.eclipse.lyo.client.OSLCConstants; +import org.eclipse.lyo.oslc.domains.auto.Oslc_autoDomainConstants; +import org.eclipse.lyo.oslc.domains.qm.Oslc_qmDomainConstants; public interface IConstants { @@ -28,13 +30,33 @@ public interface IConstants { String TYPE_STATUS_RESPONSE = NAMESPACE_URI_JAZZ_AUTO_RQM + "StatusResponse"; String TYPE_MESSAGE = NAMESPACE_URI_JAZZ_AUTO_RQM + "Message"; + // OSLC Automation Constants + String AUTOMATION_DOMAIN = Oslc_autoDomainConstants.AUTOMATION_DOMAIN; + String TYPE_AUTOMATION_REQUEST = Oslc_autoDomainConstants.AUTOMATIONREQUEST_TYPE; + String TYPE_AUTOMATION_RESULT = Oslc_autoDomainConstants.AUTOMATIONRESULT_TYPE; + // Constants for States and Verdicts are not in Oslc_autoDomainConstants, but defined in spec. + // We keep them here or use hardcoded strings if not available in domains library. + // The constants AUTOMATION_NAMSPACE is available. + String STATE_COMPLETE = Oslc_autoDomainConstants.AUTOMATION_NAMSPACE + "Complete"; + String STATE_IN_PROGRESS = Oslc_autoDomainConstants.AUTOMATION_NAMSPACE + "InProgress"; + String STATE_CANCELED = Oslc_autoDomainConstants.AUTOMATION_NAMSPACE + "Canceled"; + String VERDICT_PASSED = Oslc_autoDomainConstants.AUTOMATION_NAMSPACE + "Passed"; + QName PROPERTY_DC_RELATION = new QName(OSLCConstants.DC, "relation"); - QName PROPERTY_QM_REPORTS_ON_TEST_CASE = new QName(OSLCConstants.OSLC_QM_V2, "reportsOnTestCase"); - QName PROPERTY_QM_RUNS_TEST_CASE = new QName(OSLCConstants.OSLC_QM_V2, "runsTestCase"); - QName PROPERTY_QM_EXECUTES_TEST_SCRIPT = new QName(OSLCConstants.OSLC_QM_V2, "executesTestScript"); - QName PROPERTY_QM_REPORTS_ON_TEST_PLAN = new QName(OSLCConstants.OSLC_QM_V2, "reportsOnTestPlan"); - QName PROPERTY_QM_PRODUCES_TEST_RESULT = new QName(OSLCConstants.OSLC_QM_V2, "producesTestResult"); + // OSLC QM constants from Oslc_qmDomainConstants where possible + // Oslc_qmDomainConstants.QUALITY_MANAGEMENT_NAMSPACE is http://open-services.net/ns/qm# + // OSLCConstants.OSLC_QM_V2 is http://open-services.net/ns/qm# + + QName PROPERTY_QM_REPORTS_ON_TEST_CASE = + new QName(Oslc_qmDomainConstants.QUALITY_MANAGEMENT_NAMSPACE, "reportsOnTestCase"); + QName PROPERTY_QM_RUNS_TEST_CASE = new QName(Oslc_qmDomainConstants.QUALITY_MANAGEMENT_NAMSPACE, "runsTestCase"); + QName PROPERTY_QM_EXECUTES_TEST_SCRIPT = + new QName(Oslc_qmDomainConstants.QUALITY_MANAGEMENT_NAMSPACE, "executesTestScript"); + QName PROPERTY_QM_REPORTS_ON_TEST_PLAN = + new QName(Oslc_qmDomainConstants.QUALITY_MANAGEMENT_NAMSPACE, "reportsOnTestPlan"); + QName PROPERTY_QM_PRODUCES_TEST_RESULT = + new QName(Oslc_qmDomainConstants.QUALITY_MANAGEMENT_NAMSPACE, "producesTestResult"); QName PROPERTY_RQM_TAKEN = new QName(IConstants.NAMESPACE_URI_JAZZ_AUTO_RQM, "taken"); QName PROPERTY_RQM_PROGRESS = new QName(IConstants.NAMESPACE_URI_JAZZ_AUTO_RQM, "progress"); diff --git a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/oslc4j/CMSample.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/oslc4j/CMSample.java index b40d90b..971222f 100644 --- a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/oslc4j/CMSample.java +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/oslc4j/CMSample.java @@ -33,10 +33,10 @@ import org.apache.http.ssl.SSLContextBuilder; import org.eclipse.lyo.client.OSLCConstants; import org.eclipse.lyo.client.OslcClient; -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.glassfish.jersey.apache.connector.ApacheConnectorProvider; import org.glassfish.jersey.client.ClientConfig; import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; @@ -157,7 +157,7 @@ public static void main(String[] args) throws ParseException { // SCENARIO C: ChangeRequest creation and update ChangeRequest newChangeRequest = new ChangeRequest(); newChangeRequest.setTitle("Update database schema"); - newChangeRequest.setTitle("Need to update the database schema to reflect the data model changes"); + newChangeRequest.setDescription("Need to update the database schema to reflect the data model changes"); rawResponse = client.createResource(creationFactory, newChangeRequest, OSLCConstants.CT_RDF); int statusCode = rawResponse.getStatus(); diff --git a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/oslc4j/RMSample.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/oslc4j/RMSample.java index 9ce41b3..5cffae6 100644 --- a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/oslc4j/RMSample.java +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/oslc4j/RMSample.java @@ -29,10 +29,10 @@ import org.apache.http.HttpStatus; import org.eclipse.lyo.client.OSLCConstants; import org.eclipse.lyo.client.OslcClient; -import org.eclipse.lyo.client.oslc.resources.Requirement; 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.rm.Requirement; /** * Samples of accessing a generic Requirements Management provider and running OSLC operations. @@ -115,7 +115,7 @@ public static void main(String[] args) throws ParseException { // SCENARIO C: Requirement creation and update Requirement newRequirement = new Requirement(); newRequirement.setTitle("Database schema needs new attributes"); - newRequirement.setTitle("The data model needs to support new attributes"); + newRequirement.setDescription("The data model needs to support new attributes"); rawResponse = client.createResource(creationFactory, newRequirement, OSLCConstants.CT_RDF); int statusCode = rawResponse.getStatus(); diff --git a/lyo-client-samples/src/test/java/org/eclipse/lyo/samples/client/jazz/JazzSnapshotTest.ss b/lyo-client-samples/src/test/java/org/eclipse/lyo/samples/client/jazz/JazzSnapshotTest.ss index f3f9abc..28fd0ab 100644 --- a/lyo-client-samples/src/test/java/org/eclipse/lyo/samples/client/jazz/JazzSnapshotTest.ss +++ b/lyo-client-samples/src/test/java/org/eclipse/lyo/samples/client/jazz/JazzSnapshotTest.ss @@ -300,7 +300,7 @@ _:Bb1 "An error occurred when I tried to _:Bb1 "Error logging in"^^ . _:Bb1 "defect" . _:Bb1 . -_:Bb2 "Global Verifcation Test" . +_:Bb2 "Global Verification Test" . _:Bb2 . _:Bb2 . _:Bb2 _:Bb1 .