diff --git a/bin/test-jazz_net.sh b/bin/test-jazz_net.sh index 3d13c7b..1142649 100755 --- a/bin/test-jazz_net.sh +++ b/bin/test-jazz_net.sh @@ -17,7 +17,7 @@ mvn -B exec:java -Dexec.mainClass="org.eclipse.lyo.samples.client.EWMSample" -De -user ${JAZZ_NET_USERNAME} -password \"${JAZZ_NET_PASSWORD}\" \ -project \"${JAZZ_NET_PROJECT_NAME}\" --basic" -# ERM +# # ERM mvn -B exec:java -Dexec.mainClass="org.eclipse.lyo.samples.client.ERMSample" -Dexec.args="-url https://jazz.net/${JAZZ_NET_PROJECT_ID}-rm/ \ -user ${JAZZ_NET_USERNAME} -password \"${JAZZ_NET_PASSWORD}\" \ -project \"smarx721 Project (Requirements Management)\" --basic" diff --git a/lyo-client-samples/pom.xml b/lyo-client-samples/pom.xml index cf2291a..31cbc39 100644 --- a/lyo-client-samples/pom.xml +++ b/lyo-client-samples/pom.xml @@ -246,10 +246,8 @@ httpclient - - org.eclipse.lyo.clients - oslc-java-client-resources - ${v.lyo} + org.eclipse.lyo + oslc-domains org.eclipse.lyo.server @@ -266,6 +264,10 @@ slf4j-reload4j runtime + + org.slf4j + jul-to-slf4j + org.projectlombok lombok diff --git a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/CMSample.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/CMSample.java index 396730c..d1768bb 100644 --- a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/CMSample.java +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/CMSample.java @@ -33,10 +33,11 @@ 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.Oslc_cmVocabularyConstants; +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; @@ -118,11 +119,15 @@ public static void main(String[] args) throws ParseException { // STEP 3: Get the Query Capabilities and Creation Factory URLs so that we can run some // OSLC queries String queryCapability = client.lookupQueryCapability( - serviceProviderUrl, OSLCConstants.OSLC_CM_V2, OSLCConstants.CM_CHANGE_REQUEST_TYPE); + serviceProviderUrl, + Oslc_cmVocabularyConstants.CHANGE_MANAGEMENT_VOCAB_NAMSPACE, + Oslc_cmVocabularyConstants.TYPE_CHANGEREQUEST); System.out.println("queryCapability: " + queryCapability); String creationFactory = client.lookupCreationFactory( - serviceProviderUrl, OSLCConstants.OSLC_CM_V2, OSLCConstants.CM_CHANGE_REQUEST_TYPE); + serviceProviderUrl, + Oslc_cmVocabularyConstants.CHANGE_MANAGEMENT_VOCAB_NAMSPACE, + Oslc_cmVocabularyConstants.TYPE_CHANGEREQUEST); System.out.println("creationFactory: " + creationFactory); // SCENARIO A: Run a query for all ChangeRequests @@ -148,7 +153,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/ERMSample.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/ERMSample.java index 9a1d575..1bbe753 100644 --- a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/ERMSample.java +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/ERMSample.java @@ -26,7 +26,12 @@ import java.io.InputStreamReader; import java.net.URI; import java.net.URISyntaxException; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; import javax.xml.namespace.QName; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -49,13 +54,14 @@ 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.DctermsVocabularyConstants; +import org.eclipse.lyo.oslc.domains.Oslc_rmVocabularyConstants; +import org.eclipse.lyo.oslc.domains.RdfVocabularyConstants; +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 +81,10 @@ @Slf4j public class ERMSample { + private static final String JAZZ_RM_NAMESPACE = "http://jazz.net/xmlns/rm/1.0/"; // 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"); /** * Login to the ERM server and perform some OSLC actions @@ -158,20 +164,28 @@ public static void main(String[] args) throws Exception { // 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(); + String catalogUrl = new RootServicesHelper( + webContextUrl, + Oslc_rmVocabularyConstants.REQUIREMENTS_MANAGEMENT_VOCABULARY_NAMSPACE, + 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); + serviceProviderUrl, + Oslc_rmVocabularyConstants.REQUIREMENTS_MANAGEMENT_VOCABULARY_NAMSPACE, + Oslc_rmVocabularyConstants.TYPE_REQUIREMENT); // 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); + serviceProviderUrl, + Oslc_rmVocabularyConstants.REQUIREMENTS_MANAGEMENT_VOCABULARY_NAMSPACE, + Oslc_rmVocabularyConstants.TYPE_REQUIREMENT); // Get Feature Requirement Type URL ResourceShape featureInstanceShape = null; @@ -180,8 +194,8 @@ public static void main(String[] args) throws Exception { try { featureInstanceShape = lookupRequirementsInstanceShapes( serviceProviderUrl, - OSLCConstants.OSLC_RM_V2, - OSLCConstants.RM_REQUIREMENT_TYPE, + Oslc_rmVocabularyConstants.REQUIREMENTS_MANAGEMENT_VOCABULARY_NAMSPACE, + Oslc_rmVocabularyConstants.TYPE_REQUIREMENT, client, "Feature", null); @@ -191,19 +205,20 @@ public static void main(String[] args) throws Exception { // Feature shape is not defined if SAFe framework is used featureInstanceShape = lookupRequirementsInstanceShapes( serviceProviderUrl, - OSLCConstants.OSLC_RM_V2, - OSLCConstants.RM_REQUIREMENT_TYPE, + Oslc_rmVocabularyConstants.REQUIREMENTS_MANAGEMENT_VOCABULARY_NAMSPACE, + Oslc_rmVocabularyConstants.TYPE_REQUIREMENT, client, "User Requirement", null); } - collectionInstanceShape = RmUtil.lookupRequirementsInstanceShapes( + collectionInstanceShape = lookupRequirementsInstanceShapes( serviceProviderUrl, - OSLCConstants.OSLC_RM_V2, - OSLCConstants.RM_REQUIREMENT_COLLECTION_TYPE, + Oslc_rmVocabularyConstants.REQUIREMENTS_MANAGEMENT_VOCABULARY_NAMSPACE, + Oslc_rmVocabularyConstants.TYPE_REQUIREMENTCOLLECTION, client, - "Collection"); + "Collection", + null); // We need to use Resource shapes to properly handle date attributes, // so they aren't interpreted as dateTime. @@ -224,7 +239,7 @@ public static void main(String[] args) throws Exception { Requirement requirement = null; RequirementCollection collection = null; - URI rootFolder = null; + Optional rootFolder = Optional.empty(); String req01URL = null; String req02URL = null; @@ -239,13 +254,14 @@ public static void main(String[] args) throws Exception { } else { // Create REQ01 requirement = new Requirement(); - requirement.setInstanceShape(featureInstanceShape.getAbout()); + requirement.setInstanceShape( + new HashSet(Arrays.asList(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(new QName(JAZZ_RM_NAMESPACE, "primaryText"), obj); requirement.setDescription("Created By EclipseLyo"); requirement.addImplementedBy(new Link(new URI("http://google.com"), "Link in REQ01")); @@ -256,14 +272,16 @@ public static void main(String[] args) throws Exception { OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_RDF_XML)) { if (creationResponse.getStatus() == Response.Status.FORBIDDEN.getStatusCode()) { - throw new IllegalStateException("Server is refusing the requests on security grounds."); + throw new IllegalStateException("Server is refusing the requests on security grounds:\n" + + creationResponse.readEntity(String.class)); } req01URL = creationResponse.getStringHeaders().getFirst(HttpHeaders.LOCATION); } // Create REQ02 requirement = new Requirement(); - requirement.setInstanceShape(featureInstanceShape.getAbout()); + requirement.setInstanceShape( + new HashSet(Arrays.asList(new Link(featureInstanceShape.getAbout())))); requirement.setTitle("Req02"); requirement.setDescription("Created By EclipseLyo"); requirement.addValidatedBy(new Link(new URI("http://bancomer.com"), "Link in REQ02")); @@ -274,14 +292,16 @@ public static void main(String[] args) throws Exception { OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_RDF_XML)) { if (creationResponse.getStatus() == Response.Status.FORBIDDEN.getStatusCode()) { - throw new IllegalStateException("Server is refusing the requests on security grounds."); + throw new IllegalStateException("Server is refusing the requests on security grounds:\n" + + creationResponse.readEntity(String.class)); } req02URL = creationResponse.getStringHeaders().getFirst(HttpHeaders.LOCATION); } // Create REQ03 requirement = new Requirement(); - requirement.setInstanceShape(featureInstanceShape.getAbout()); + requirement.setInstanceShape( + new HashSet(Arrays.asList(new Link(featureInstanceShape.getAbout())))); requirement.setTitle("Req03"); requirement.setDescription("Created By EclipseLyo"); requirement.addValidatedBy(new Link(new URI("http://outlook.com"), "Link in REQ03")); @@ -299,7 +319,8 @@ public static void main(String[] args) throws Exception { // Create REQ04 requirement = new Requirement(); - requirement.setInstanceShape(featureInstanceShape.getAbout()); + requirement.setInstanceShape( + new HashSet(Arrays.asList(new Link(featureInstanceShape.getAbout())))); requirement.setTitle("Req04"); requirement.setDescription("Created By EclipseLyo"); @@ -319,11 +340,12 @@ public static void main(String[] args) throws Exception { // 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( + new HashSet(Arrays.asList(new Link(collectionInstanceShape.getAbout())))); } collection.setTitle("Collection01"); collection.setDescription("Created By EclipseLyo"); @@ -370,9 +392,10 @@ public static void main(String[] args) throws Exception { } // Save the URI of the root folder in order to used it easily - rootFolder = (URI) requirement.getExtendedProperties().get(RmConstants.PROPERTY_PARENT_FOLDER); + rootFolder = Optional.ofNullable( + ((Link) requirement.getExtendedProperties().get(new QName(JAZZ_RM_NAMESPACE, "parent")))); Object changedPrimaryText = - (Object) requirement.getExtendedProperties().get(RmConstants.PROPERTY_PRIMARY_TEXT); + (Object) requirement.getExtendedProperties().get(new QName(JAZZ_RM_NAMESPACE, "primaryText")); if (changedPrimaryText == null) { // Check with the workaround changedPrimaryText = @@ -391,8 +414,8 @@ public static void main(String[] args) throws Exception { // QUERIES // SCENARIO 01 Do a query for type= Requirement OslcQueryParameters queryParams = new OslcQueryParameters(); - queryParams.setPrefix("rdf="); - queryParams.setWhere("rdf:type="); + queryParams.setPrefix("rdf=<" + RdfVocabularyConstants.RDF_NAMSPACE + ">"); + queryParams.setWhere("rdf:type=<" + Oslc_rmVocabularyConstants.TYPE_REQUIREMENT + ">"); OslcQuery query = new OslcQuery(client, queryCapability, 10, queryParams); OslcQueryResult result = query.submit(); result.getRawResponse().bufferEntity(); @@ -406,9 +429,9 @@ public static void main(String[] args) throws Exception { // rootFolder queryParams = new OslcQueryParameters(); queryParams.setPrefix( - "nav=,rdf="); - queryParams.setWhere( - "rdf:type= and nav:parent=<" + rootFolder + ">"); + "nav=,rdf=<" + RdfVocabularyConstants.RDF_NAMSPACE + ">"); + queryParams.setWhere("rdf:type=<" + Oslc_rmVocabularyConstants.TYPE_REQUIREMENT + "> and nav:parent=<" + + rootFolder.map(link -> link.getValue().toString()).orElse(null) + ">"); query = new OslcQuery(client, queryCapability, 10, queryParams); result = query.submit(); processAsJavaObjects = false; @@ -420,7 +443,7 @@ public static void main(String[] args) throws Exception { // SCENARIO 03 Do a query for title queryParams = new OslcQueryParameters(); - queryParams.setPrefix("dcterms="); + queryParams.setPrefix("dcterms=<" + DctermsVocabularyConstants.DUBLIN_CORE_NAMSPACE + ">"); queryParams.setWhere("dcterms:title=\"Req04\""); query = new OslcQuery(client, queryCapability, 10, queryParams); result = query.submit(); @@ -433,7 +456,8 @@ public static void main(String[] args) throws Exception { // SCENARIO 04 Do a query for the link that is implemented queryParams = new OslcQueryParameters(); - queryParams.setPrefix("oslc_rm="); + queryParams.setPrefix( + "oslc_rm=<" + Oslc_rmVocabularyConstants.REQUIREMENTS_MANAGEMENT_VOCABULARY_NAMSPACE + ">"); queryParams.setWhere("oslc_rm:implementedBy="); query = new OslcQuery(client, queryCapability, 10, queryParams); result = query.submit(); @@ -446,7 +470,8 @@ public static void main(String[] args) throws Exception { // SCENARIO 05 Do a query for the links that is validated queryParams = new OslcQueryParameters(); - queryParams.setPrefix("oslc_rm="); + queryParams.setPrefix( + "oslc_rm=<" + Oslc_rmVocabularyConstants.REQUIREMENTS_MANAGEMENT_VOCABULARY_NAMSPACE + ">"); queryParams.setWhere("oslc_rm:validatedBy in [,]"); query = new OslcQuery(client, queryCapability, 10, queryParams); result = query.submit(); @@ -459,8 +484,11 @@ public static void main(String[] args) throws Exception { // 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="); + queryParams.setPrefix("nav=,oslc_rm=<" + + Oslc_rmVocabularyConstants.REQUIREMENTS_MANAGEMENT_VOCABULARY_NAMSPACE + ">"); + queryParams.setWhere("nav:parent=<" + + rootFolder.map(link -> link.getValue().toString()).orElse(null) + + "> and oslc_rm:validatedBy="); query = new OslcQuery(client, queryCapability, 10, queryParams); result = query.submit(); result.getRawResponse().bufferEntity(); @@ -487,7 +515,7 @@ public static void main(String[] args) throws Exception { /*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.setPrefix("dcterms=<" + DctermsVocabularyConstants.DUBLIN_CORE_NAMSPACE + ">"); queryParams.setWhere("dcterms:title=\"My new Title\""); query = new OslcQuery(client, queryCapability, 10, queryParams); result = query.submit(); @@ -500,7 +528,8 @@ public static void main(String[] args) throws Exception { // SCENARIO 08 Do a query for implementedBy links queryParams = new OslcQueryParameters(); - queryParams.setPrefix("oslc_rm="); + queryParams.setPrefix( + "oslc_rm=<" + Oslc_rmVocabularyConstants.REQUIREMENTS_MANAGEMENT_VOCABULARY_NAMSPACE + ">"); queryParams.setWhere("oslc_rm:implementedBy="); query = new OslcQuery(client, queryCapability, 10, queryParams); result = query.submit(); @@ -519,11 +548,13 @@ public static void main(String[] args) throws Exception { } } + private static final String NAMESPACE_URI_XHTML = "http://www.w3.org/1999/xhtml"; + 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) { diff --git a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/ETMSample.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/ETMSample.java index 6125526..e8e8d0f 100644 --- a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/ETMSample.java +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/ETMSample.java @@ -39,11 +39,12 @@ 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.Oslc_qmVocabularyConstants; +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; @@ -135,7 +136,9 @@ public static void main(String[] args) throws ParseException { // STEP 4: Get the URL of the OSLC ChangeManagement service from the rootservices // document - String catalogUrl = new RootServicesHelper(webContextUrl, OSLCConstants.OSLC_QM_V2, client).getCatalogUrl(); + String catalogUrl = new RootServicesHelper( + webContextUrl, Oslc_qmVocabularyConstants.QUALITY_MANAGEMENT_NAMSPACE, client) + .getCatalogUrl(); logger.info("Using %s catalog URI".formatted(catalogUrl)); // STEP 5: Find the OSLC Service Provider for the project area we want to work with @@ -143,7 +146,9 @@ public static void main(String[] args) throws ParseException { // STEP 6: Get the Query Capabilities URL so that we can run some OSLC queries String queryCapability = client.lookupQueryCapability( - serviceProviderUrl, OSLCConstants.OSLC_QM_V2, OSLCConstants.QM_TEST_RESULT_QUERY); + serviceProviderUrl, + Oslc_qmVocabularyConstants.QUALITY_MANAGEMENT_NAMSPACE, + Oslc_qmVocabularyConstants.TYPE_TESTRESULT); // SCENARIO A: Run a query for all TestResults with a status of passed with OSLC paging // of 10 items per @@ -154,7 +159,7 @@ public static void main(String[] args) throws ParseException { System.out.println("Running query: " + query.getQueryUrl()); OslcQueryResult result = query.submit(); - result.setMemberProperty(OSLCConstants.OSLC_QM_V2 + "testResult"); + result.setMemberProperty(Oslc_qmVocabularyConstants.QUALITY_MANAGEMENT_NAMSPACE + "testResult"); boolean processAsJavaObjects = true; processPagedQueryResults(result, client, processAsJavaObjects); @@ -170,7 +175,7 @@ public static void main(String[] args) throws ParseException { OslcQuery query2 = new OslcQuery(client, queryCapability, queryParams2); OslcQueryResult result2 = query2.submit(); - result2.setMemberProperty(OSLCConstants.OSLC_QM_V2 + "testResult"); + result2.setMemberProperty(Oslc_qmVocabularyConstants.QUALITY_MANAGEMENT_NAMSPACE + "testResult"); Response rawResponse = result2.getRawResponse(); processRawResponse(rawResponse); @@ -184,7 +189,9 @@ public static void main(String[] args) throws ParseException { // Get the Creation Factory URL for test cases so that we can create a test case String testcaseCreation = client.lookupCreationFactory( - serviceProviderUrl, OSLCConstants.OSLC_QM_V2, testcase.getRdfTypes()[0].toString()); + serviceProviderUrl, + Oslc_qmVocabularyConstants.QUALITY_MANAGEMENT_NAMSPACE, + Oslc_qmVocabularyConstants.TYPE_TESTCASE); // Create the test case Response creationResponse = diff --git a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/EWMSample.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/EWMSample.java index 2d3a0c6..cb9d4cb 100644 --- a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/EWMSample.java +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/EWMSample.java @@ -27,6 +27,7 @@ import java.io.InputStreamReader; import java.net.URI; import java.util.concurrent.TimeUnit; +import java.util.logging.Level; import javax.xml.namespace.QName; import lombok.extern.slf4j.Slf4j; import org.apache.commons.cli.CommandLine; @@ -43,14 +44,15 @@ import org.apache.http.conn.ssl.TrustSelfSignedStrategy; import org.apache.http.ssl.SSLContextBuilder; import org.eclipse.lyo.client.JEEFormAuthenticator; -import org.eclipse.lyo.client.OSLCConstants; 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.Oslc_cmVocabularyConstants; +import org.eclipse.lyo.oslc.domains.cm.ChangeRequest; +import org.eclipse.lyo.oslc.domains.cm.Defect; import org.eclipse.lyo.oslc4j.core.model.AllowedValues; import org.eclipse.lyo.oslc4j.core.model.CreationFactory; import org.eclipse.lyo.oslc4j.core.model.Link; @@ -58,12 +60,16 @@ import org.eclipse.lyo.oslc4j.core.model.Property; import org.eclipse.lyo.oslc4j.core.model.ResourceShape; import org.eclipse.lyo.oslc4j.provider.jena.AbstractOslcRdfXmlProvider; +import org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper; +import org.eclipse.lyo.samples.client.resources.JazzChangeRequest; import org.glassfish.jersey.apache.connector.ApacheClientProperties; import org.glassfish.jersey.apache.connector.ApacheConnectorProvider; import org.glassfish.jersey.client.ClientConfig; import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import org.glassfish.jersey.logging.LoggingFeature; import org.glassfish.jersey.media.multipart.MultiPartFeature; import org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException; +import org.slf4j.bridge.SLF4JBridgeHandler; /** * Samples of logging in to IBM Enterprise Workflow Manager and running OSLC operations @@ -85,6 +91,8 @@ public class EWMSample { */ public static void main(String[] args) throws ParseException { + SLF4JBridgeHandler.install(); + Options options = new Options(); options.addOption("url", true, "url"); @@ -163,6 +171,13 @@ public static void main(String[] args) throws ParseException { log.info("Using JAS (Forms) authentication"); } + if (log.isTraceEnabled()) { + var clientLogger = java.util.logging.Logger.getLogger(""); + clientLogger.setLevel(Level.FINEST); + clientBuilder.register( + new LoggingFeature(clientLogger, Level.INFO, LoggingFeature.Verbosity.PAYLOAD_ANY, null)); + } + // STEP 3: Create a new OslcClient log.debug("STEP 3: Create a new OslcClient"); OslcClient client = new OslcClient(clientBuilder); @@ -170,7 +185,9 @@ public static void main(String[] args) throws ParseException { // STEP 4: Get the URL of the OSLC ChangeManagement service from the rootservices // document log.debug("STEP 4: Get the URL of the OSLC ChangeManagement service from the rootservices" + " document"); - String catalogUrl = new RootServicesHelper(webContextUrl, OSLCConstants.OSLC_CM_V2, client).getCatalogUrl(); + String catalogUrl = new RootServicesHelper( + webContextUrl, Oslc_cmVocabularyConstants.CHANGE_MANAGEMENT_VOCAB_NAMSPACE, client) + .getCatalogUrl(); // STEP 5: Find the OSLC Service Provider for the project area we want to work with log.debug("STEP 5: Find the OSLC Service Provider for the project area we want to work" + " with"); @@ -179,7 +196,9 @@ public static void main(String[] args) throws ParseException { // STEP 6: Get the Query Capabilities URL so that we can run some OSLC queries log.debug("STEP 6: Get the Query Capabilities URL so that we can run some OSLC queries"); String queryCapability = client.lookupQueryCapability( - serviceProviderUrl, OSLCConstants.OSLC_CM_V2, OSLCConstants.CM_CHANGE_REQUEST_TYPE); + serviceProviderUrl, + Oslc_cmVocabularyConstants.CHANGE_MANAGEMENT_VOCAB_NAMSPACE, + Oslc_cmVocabularyConstants.TYPE_CHANGEREQUEST); // SCENARIO A: Run a query for all open ChangeRequests with OSLC paging of 10 items per // page turned on and list the members of the result @@ -209,20 +228,36 @@ public static void main(String[] args) throws ParseException { rawResponse.close(); // SCENARIO C: EWM task creation and update - ChangeRequest task = new ChangeRequest(); + var task = new JazzChangeRequest(); 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(new QName(DctermsDomainConstants.DUBLIN_CORE_NAMSPACE, "type"), Set.of("Task")); + + task.setDctermsTypes(new String[] {"Task"}); + + // TODO: clean up when https://github.com/eclipse-lyo/lyo/issues/783 is fixed + // task.getExtendedProperties() + // .put( + // new QName(Oslc_cmVocabularyConstants.CHANGE_MANAGEMENT_VOCAB_NAMSPACE, + // "testedByTestCase"), + // // new URI("http://qmprovider/testcase/1") + // Set.of(new Link( + // new URI("http://qmprovider/testcase/1"), + // "Accessibility verification using a screen reader"))); + + task.setTestedByTestCases(new Link[] { + new Link(new URI("http://qmprovider/testcase/1"), "Accessibility verification using a screen reader") + }); // 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(), - OSLCConstants.OSLC_CM_V2 + "task"); + Oslc_cmVocabularyConstants.CHANGE_MANAGEMENT_VOCAB_NAMSPACE, + Oslc_cmVocabularyConstants.TYPE_CHANGEREQUEST, + // not capital Task - this is a usage, not a type + Oslc_cmVocabularyConstants.CHANGE_MANAGEMENT_VOCAB_NAMSPACE + "task"); String factoryUrl = taskCreation.getCreation().toString(); // Determine what to use for the Filed Against attribute by requesting the resource @@ -240,6 +275,15 @@ public static void main(String[] args) throws ParseException { AllowedValues allowedValues = allowedValuesResponse.readEntity(AllowedValues.class); Object[] values = allowedValues.getValues().toArray(); task.getExtendedProperties().put(new QName(RTC_NAMESPACE, RTC_FILED_AGAINST), (URI) values[0]); + } else { + log.warn("RTC_FILED_AGAINST was not found in the shape for the creation factory for tasks"); + } + + if (log.isDebugEnabled()) { + var model = JenaModelHelper.createJenaModel(new Object[] {task}); + model.write(System.out, "RDFXML"); + + System.out.println(); } // Create the change request @@ -255,7 +299,7 @@ public static void main(String[] args) throws ParseException { System.out.println("Task created at location " + changeRequestLocation); // Get the change request from the service provider and update its title property - task = client.getResource(changeRequestLocation).readEntity(ChangeRequest.class); + task = client.getResource(changeRequestLocation).readEntity(JazzChangeRequest.class); task.setTitle(task.getTitle() + " (updated)"); // Create a partial update URL so that only the title will be updated. @@ -269,19 +313,21 @@ public static void main(String[] args) throws ParseException { updateResponse.readEntity(String.class); // SCENARIO D: RTC defect creation - ChangeRequest defect = new ChangeRequest(); + Defect defect = new Defect(); defect.setTitle("Error logging in"); 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.addDctermsType("defect"); + defect.getExtendedProperties() + .put( + new QName(Oslc_cmVocabularyConstants.CHANGE_MANAGEMENT_VOCAB_NAMSPACE, "testedByTestCase"), + new URI("http://qmprovider/testcase/3")); // 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(), - OSLCConstants.OSLC_CM_V2 + "defect"); + Oslc_cmVocabularyConstants.CHANGE_MANAGEMENT_VOCAB_NAMSPACE, + Oslc_cmVocabularyConstants.TYPE_DEFECT, + Oslc_cmVocabularyConstants.CHANGE_MANAGEMENT_VOCAB_NAMSPACE + Oslc_cmVocabularyConstants.DEFECT); factoryUrl = defectCreation.getCreation().toString(); // Determine what to use for the Filed Against attribute by requesting the resource diff --git a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/RMSample.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/RMSample.java index 56c9fbe..e5982fb 100644 --- a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/RMSample.java +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/RMSample.java @@ -29,10 +29,11 @@ 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.Oslc_rmVocabularyConstants; +import org.eclipse.lyo.oslc.domains.rm.Requirement; /** * Samples of accessing a generic Requirements Management provider and running OSLC operations. @@ -87,10 +88,14 @@ public static void main(String[] args) throws ParseException { // STEP 3: Get the Query Capabilities and Creation Factory URLs so that we can run some // OSLC queries String queryCapability = client.lookupQueryCapability( - serviceProviderUrl, OSLCConstants.OSLC_RM_V2, OSLCConstants.RM_REQUIREMENT_TYPE); + serviceProviderUrl, + Oslc_rmVocabularyConstants.REQUIREMENTS_MANAGEMENT_VOCABULARY_NAMSPACE, + Oslc_rmVocabularyConstants.TYPE_REQUIREMENT); String creationFactory = client.lookupCreationFactory( - serviceProviderUrl, OSLCConstants.OSLC_RM_V2, OSLCConstants.RM_REQUIREMENT_TYPE); + serviceProviderUrl, + Oslc_rmVocabularyConstants.REQUIREMENTS_MANAGEMENT_VOCABULARY_NAMSPACE, + Oslc_rmVocabularyConstants.TYPE_REQUIREMENT); // SCENARIO A: Run a query for all Requirements @@ -115,7 +120,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/main/java/org/eclipse/lyo/samples/client/automation/AutomationAdapter.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/AutomationAdapter.java index 02c4ed5..59a9365 100644 --- a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/AutomationAdapter.java +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/AutomationAdapter.java @@ -23,6 +23,7 @@ import java.net.URISyntaxException; import java.util.Arrays; import java.util.Date; +import java.util.HashSet; import java.util.Map; import java.util.Properties; import java.util.Set; @@ -45,11 +46,11 @@ 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.auto.Oslc_autoDomainConstants; +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; @@ -493,8 +494,8 @@ private void saveResult(AutomationResult result, AutomationRequest request) resultCreationFactoryUrl = client.lookupCreationFactory( serviceProviderUrl, - AutomationConstants.AUTOMATION_DOMAIN, - AutomationConstants.TYPE_AUTOMATION_RESULT); + Oslc_autoDomainConstants.AUTOMATION_NAMSPACE, + Oslc_autoDomainConstants.AUTOMATIONRESULT_TYPE); } response = client.createResource(resultCreationFactoryUrl, result, OslcMediaType.APPLICATION_RDF_XML); @@ -526,7 +527,8 @@ private void completeRequest(AutomationRequest request) assertNotCanceled(request); - request.setStates(new URI[] {URI.create(AutomationConstants.STATE_COMPLETE)}); + request.setState(new HashSet( + Arrays.asList(new Link(URI.create(Oslc_autoDomainConstants.AUTOMATION_NAMSPACE + "Complete"))))); request.getExtendedProperties().remove(PROPERTY_RQM_PROGRESS); @@ -582,8 +584,8 @@ 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(Oslc_autoDomainConstants.AUTOMATIONREQUEST_TYPE)); if (stmtIter.hasNext()) { return stmtIter.next().getSubject().getURI(); @@ -614,7 +616,8 @@ 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 HashSet( + Arrays.asList(new Link(URI.create(Oslc_autoDomainConstants.AUTOMATION_NAMSPACE + "inProgress"))))); updateUri = appendOslcProperties(URI.create(requestUrl), "oslc_auto:state", "rqm_auto:taken"); @@ -675,7 +678,7 @@ public void register() throws AutomationException, IOException, URISyntaxExcepti } adapterCreationFactoryUrl = client.lookupCreationFactory( - serviceProviderUrl, AutomationConstants.AUTOMATION_DOMAIN, TYPE_AUTOMATION_ADAPTER); + serviceProviderUrl, Oslc_autoDomainConstants.AUTOMATION_NAMSPACE, TYPE_AUTOMATION_ADAPTER); response = client.createResource(adapterCreationFactoryUrl, this, OslcMediaType.APPLICATION_RDF_XML); @@ -899,7 +902,7 @@ private void populateResultFromRequest(AutomationRequest request, AutomationResu Link automationPlan = request.getExecutesAutomationPlan(); - result.setInputParameters(request.getInputParameters()); + result.setInputParameter(request.getInputParameter()); Map requestExtProperties = request.getExtendedProperties(); @@ -1089,7 +1092,7 @@ public void sendProgressForRequest(int i, AutomationRequest request) * @throws AutomationException * @throws IOException */ - public void sendStatusForRequest(StatusResponse statusResponse, AutomationRequest request) + public void sendStatusForRequest(RqmStatusResponse statusResponse, AutomationRequest request) throws AutomationException, IOException, URISyntaxException { if (client == null) { @@ -1139,7 +1142,7 @@ public void sendStatusForRequest(StatusResponse statusResponse, AutomationReques * @throws AutomationException * @throws IOException */ - public void sendMessageForRequest(Message message, AutomationRequest request) + public void sendMessageForRequest(RqmMessage message, AutomationRequest request) throws AutomationException, IOException, URISyntaxException { if (client == null) { @@ -1194,10 +1197,11 @@ 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(Oslc_autoDomainConstants.AUTOMATION_NAMSPACE + "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 HashSet( + Arrays.asList(new Link(URI.create(Oslc_autoDomainConstants.AUTOMATION_NAMSPACE + "Canceled"))))); URI updateUri = appendOslcProperties(request.getAbout(), "oslc_auto:state"); @@ -1242,11 +1246,16 @@ private void assertNotCanceled(AutomationRequest request) } // oslc_auto:state is defined as one-or-many in the specification - URI stateUri = requestAtServiceProvider.getStates()[0]; + Set states = requestAtServiceProvider.getState(); - if (URI.create(AutomationConstants.STATE_CANCELED).equals(stateUri)) { + if (states != null) { + for (Link state : states) { + if (URI.create(Oslc_autoDomainConstants.AUTOMATION_NAMSPACE + "Canceled") + .equals(state.getValue())) { - throw new AutomationRequestCanceledException(request); + throw new AutomationRequestCanceledException(request); + } + } } } diff --git a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/AutomationRequestCanceledException.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/AutomationRequestCanceledException.java index 95d5c8e..b83c95a 100644 --- a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/AutomationRequestCanceledException.java +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/AutomationRequestCanceledException.java @@ -16,7 +16,7 @@ package org.eclipse.lyo.samples.client.automation; 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/automation/ETMAutomationSample.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/ETMAutomationSample.java index 61ff633..214bc2d 100644 --- a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/ETMAutomationSample.java +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/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,12 @@ 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.oslc.domains.auto.ParameterInstance; +import org.eclipse.lyo.oslc4j.core.model.Link; +import org.eclipse.lyo.oslc4j.core.model.OslcMediaType; import org.glassfish.jersey.client.ClientConfig; import org.glassfish.jersey.client.ClientProperties; import org.glassfish.jersey.client.HttpUrlConnectorProvider; @@ -173,17 +176,17 @@ public AutomationResult handleAutomationRequest(AutomationRequest request, Autom // An example of how to get the script for the AutomationRequest. // The script might contain references to resources needed to // execute the test. - adapter.sendMessageForRequest(new Message("LYO_1", "Downloading script document"), request); + adapter.sendMessageForRequest(new RqmMessage("LYO_1", "Downloading script document"), request); Document script = adapter.getScriptDocument(request); - adapter.sendMessageForRequest(new Message("LYO_2", "Script document successfully downloaded"), request); + adapter.sendMessageForRequest(new RqmMessage("LYO_2", "Script document successfully downloaded"), request); // update progress indication 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(); @@ -194,11 +197,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(Oslc_autoDomainConstants.AUTOMATION_NAMSPACE + "passed"))); // Save the end time in the result result.getExtendedProperties().put(PROPERTY_RQM_END_TIME, new Date(System.currentTimeMillis())); @@ -206,7 +209,9 @@ public AutomationResult handleAutomationRequest(AutomationRequest request, Autom // update progress indication adapter.sendProgressForRequest(99, request); - log.info("Returning a result with verdict {}", result.getVerdicts()[0]); + log.info( + "Returning a result with verdict {}", + result.getVerdict().iterator().next().getValue()); } catch (AutomationRequestCanceledException e) { @@ -240,7 +245,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() @@ -251,7 +256,10 @@ private void executeScript( log.info("Running script named '{}'", scriptTitle); log.info("Input parameters:"); - for (ParameterInstance parameter : inputParameters) { + for (Link parameterLink : inputParameters) { + ParameterInstance parameter = adapter.getClient() + .getResource(parameterLink.getValue().toString(), OslcMediaType.APPLICATION_RDF_XML) + .readEntity(ParameterInstance.class); String paramStr = "\t" + parameter.getName() + ": " + parameter.getValue(); log.info(paramStr); } @@ -262,8 +270,8 @@ private void executeScript( Thread.sleep(1000); // Update the request status - StatusResponse statusResponse = - new StatusResponse(StatusResponse.STATUS_OK, "Script '" + scriptTitle + "' was executed successfully."); + RqmStatusResponse statusResponse = new RqmStatusResponse( + RqmStatusResponse.STATUS_OK, "Script '" + scriptTitle + "' was executed successfully."); adapter.sendStatusForRequest(statusResponse, request); } diff --git a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/IAutomationRequestHandler.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/IAutomationRequestHandler.java index 2d14841..25d88f9 100644 --- a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/IAutomationRequestHandler.java +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/IAutomationRequestHandler.java @@ -15,8 +15,8 @@ */ package org.eclipse.lyo.samples.client.automation; -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/automation/Message.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/RqmMessage.java similarity index 94% rename from lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/Message.java rename to lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/RqmMessage.java index 30cbe5b..4117ef2 100644 --- a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/Message.java +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/RqmMessage.java @@ -29,7 +29,7 @@ @OslcResourceShape(title = "Message Resource Shape", describes = IConstants.TYPE_MESSAGE) @OslcNamespace(IConstants.NAMESPACE_URI_JAZZ_AUTO_RQM) -public class Message extends AbstractResource implements IConstants { +public class RqmMessage extends AbstractResource implements IConstants { @Setter private String name; @@ -43,7 +43,7 @@ public class Message extends AbstractResource implements IConstants { * @param name Name or ID of the message. Cannot be null. * @param value The actual message content. Cannot be null. */ - public Message(String name, String value) { + public RqmMessage(String name, String value) { assert name != null; assert value != null; diff --git a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/StatusResponse.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/RqmStatusResponse.java similarity index 83% rename from lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/StatusResponse.java rename to lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/RqmStatusResponse.java index 1544974..24ce3d5 100644 --- a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/StatusResponse.java +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/automation/RqmStatusResponse.java @@ -31,7 +31,7 @@ @Slf4j @OslcResourceShape(title = "Status Response Resource Shape", describes = IConstants.TYPE_STATUS_RESPONSE) @OslcNamespace(IConstants.NAMESPACE_URI_JAZZ_AUTO_RQM) -public class StatusResponse extends AbstractResource implements IConstants { +public class RqmStatusResponse extends AbstractResource implements IConstants { /** Starting value for normal informational status message */ public static final int STATUS_INFORMATIONAL = 100; @@ -56,12 +56,12 @@ public class StatusResponse extends AbstractResource implements IConstants { * * @param statusCode * @param status - * @see @link {@link StatusResponse#STATUS_INFORMATIONAL} - * @see @link {@link StatusResponse#STATUS_OK} - * @see @link {@link StatusResponse#STATUS_WARNING} - * @see @link {@link StatusResponse#STATUS_ERROR} + * @see @link {@link RqmStatusResponse#STATUS_INFORMATIONAL} + * @see @link {@link RqmStatusResponse#STATUS_OK} + * @see @link {@link RqmStatusResponse#STATUS_WARNING} + * @see @link {@link RqmStatusResponse#STATUS_ERROR} */ - public StatusResponse(int statusCode, String status) { + public RqmStatusResponse(int statusCode, String status) { this.status = status; setStatusCode(statusCode); } @@ -79,10 +79,10 @@ public int getStatusCode() { * Set the status code for this response. The expected range is 100-599. * * @param statusCode - * @see @link {@link StatusResponse#STATUS_INFORMATIONAL} - * @see @link {@link StatusResponse#STATUS_OK} - * @see @link {@link StatusResponse#STATUS_WARNING} - * @see @link {@link StatusResponse#STATUS_ERROR} + * @see @link {@link RqmStatusResponse#STATUS_INFORMATIONAL} + * @see @link {@link RqmStatusResponse#STATUS_OK} + * @see @link {@link RqmStatusResponse#STATUS_WARNING} + * @see @link {@link RqmStatusResponse#STATUS_ERROR} */ public void setStatusCode(int statusCode) { this.statusCode = statusCode; diff --git a/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/resources/JazzChangeRequest.java b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/resources/JazzChangeRequest.java new file mode 100644 index 0000000..b8fdbc0 --- /dev/null +++ b/lyo-client-samples/src/main/java/org/eclipse/lyo/samples/client/resources/JazzChangeRequest.java @@ -0,0 +1,64 @@ +package org.eclipse.lyo.samples.client.resources; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import org.eclipse.lyo.oslc.domains.Oslc_cmVocabularyConstants; +import org.eclipse.lyo.oslc.domains.Oslc_qmVocabularyConstants; +import org.eclipse.lyo.oslc.domains.cm.ChangeRequest; +import org.eclipse.lyo.oslc.domains.cm.Oslc_cmDomainConstants; +import org.eclipse.lyo.oslc4j.core.annotation.OslcAllowedValue; +import org.eclipse.lyo.oslc4j.core.annotation.OslcDescription; +import org.eclipse.lyo.oslc4j.core.annotation.OslcName; +import org.eclipse.lyo.oslc4j.core.annotation.OslcNamespace; +import org.eclipse.lyo.oslc4j.core.annotation.OslcPropertyDefinition; +import org.eclipse.lyo.oslc4j.core.annotation.OslcRange; +import org.eclipse.lyo.oslc4j.core.annotation.OslcReadOnly; +import org.eclipse.lyo.oslc4j.core.annotation.OslcResourceShape; +import org.eclipse.lyo.oslc4j.core.annotation.OslcTitle; +import org.eclipse.lyo.oslc4j.core.model.Link; +import org.eclipse.lyo.oslc4j.core.model.OslcConstants; + +@OslcNamespace(Oslc_cmDomainConstants.CHANGEREQUEST_NAMESPACE) +@OslcName(Oslc_cmDomainConstants.CHANGEREQUEST_LOCALNAME) +@OslcResourceShape(title = "ChangeRequest Shape", describes = Oslc_cmDomainConstants.CHANGEREQUEST_TYPE) +public class JazzChangeRequest extends ChangeRequest { + + private Set dctermsTypes = new HashSet<>(); + private final Set testedByTestCases = new HashSet<>(); + + public void setDctermsTypes(final String[] dctermsTypes) { + this.dctermsTypes.clear(); + + if (dctermsTypes != null) { + this.dctermsTypes.addAll(Arrays.asList(dctermsTypes)); + } + } + + @OslcAllowedValue({"Defect", "Task", "Story", "Bug Report", "Feature Request"}) + @OslcDescription("A short string representation for the type, example 'Defect'.") + @OslcName("type") + @OslcPropertyDefinition(OslcConstants.DCTERMS_NAMESPACE + "type") + @OslcTitle("Types") + public String[] getDctermsTypes() { + return dctermsTypes.toArray(new String[dctermsTypes.size()]); + } + + @OslcDescription("Test case by which this change request is tested.") + @OslcName("testedByTestCase") + @OslcPropertyDefinition(Oslc_cmVocabularyConstants.CHANGE_MANAGEMENT_VOCAB_NAMSPACE + "testedByTestCase") + @OslcRange(Oslc_qmVocabularyConstants.TYPE_TESTCASE) + @OslcReadOnly(false) + @OslcTitle("Tested by Test Cases") + public Link[] getTestedByTestCases() { + return testedByTestCases.toArray(new Link[testedByTestCases.size()]); + } + + public void setTestedByTestCases(final Link[] testedByTestCases) { + this.testedByTestCases.clear(); + + if (testedByTestCases != null) { + this.testedByTestCases.addAll(Arrays.asList(testedByTestCases)); + } + } +} diff --git a/lyo-client-samples/src/main/resources/log4j.properties b/lyo-client-samples/src/main/resources/log4j.properties index 855ca25..6de5b70 100644 --- a/lyo-client-samples/src/main/resources/log4j.properties +++ b/lyo-client-samples/src/main/resources/log4j.properties @@ -19,7 +19,7 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=[%5p] (%C) - %m%n -log4j.logger.org.eclipse.lyo=TRACE +log4j.logger.org.eclipse.lyo=DEBUG log4j.logger.org.eclipse.lyo.oslc4j.provider.jena.AbstractOslcRdfXmlProvider=DEBUG log4j.logger.org.eclipse.lyo.oslc4j.provider.jena.ordfm.ResourcePackages=INFO