Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Lyo/LyoOSLC4J"
m (→What is OSLC4J?) |
|||
(17 intermediate revisions by the same user not shown) | |||
Line 11: | Line 11: | ||
* sample applications, including an OSLC Registry (catalog) application and a Change Management provider implementation | * sample applications, including an OSLC Registry (catalog) application and a Change Management provider implementation | ||
* Tests for the sample applications to complement the [[Lyo/LyoTestSuite|Lyo OSLC Test Suite]] | * Tests for the sample applications to complement the [[Lyo/LyoTestSuite|Lyo OSLC Test Suite]] | ||
+ | |||
+ | == Getting started with OSLC4J == | ||
+ | |||
+ | # [https://wiki.eclipse.org/Lyo/General_Setup_for_OSLC4J_Development Setup the Eclipse environment] for Lyo-based development | ||
+ | # [https://wiki.eclipse.org/Lyo/creating_OSLC4J_project Create an initial REST server application], ready for Lyo-based development | ||
+ | # Use [https://github.com/eclipse/lyo.designer Lyo Designer] to [https://github.com/eclipse/lyo.designer/wiki/User-Manual-for-Toolchain-Modelling model a single server or complete toolchain] and generate an initial code base | ||
+ | |||
+ | ''JARs are no longer available for download since Lyo 2.1.0. All artefacts are available through Eclipse Maven repos linked above. Lyo Designer is available through an Eclipse download site.'' | ||
+ | |||
+ | === Using in Maven === | ||
+ | |||
+ | Be sure to add Eclipse Maven repositories in your POM file before adding OSLC4J dependencies: | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <repositories> | ||
+ | <repository> | ||
+ | <id>lyo-releases</id> | ||
+ | <name>Eclipse Lyo Releases</name> | ||
+ | <url>https://repo.eclipse.org/content/repositories/lyo-releases/</url> | ||
+ | <snapshots> | ||
+ | <enabled>false</enabled> | ||
+ | </snapshots> | ||
+ | </repository> | ||
+ | <repository> | ||
+ | <id>lyo-snapshots</id> | ||
+ | <name>Eclipse Lyo Snapshots</name> | ||
+ | <url>https://repo.eclipse.org/content/repositories/lyo-snapshots/</url> | ||
+ | <releases> | ||
+ | <enabled>false</enabled> | ||
+ | </releases> | ||
+ | </repository> | ||
+ | </repositories> | ||
+ | </source> | ||
+ | |||
== Components == | == Components == | ||
− | * OSLC4J - The core component providing OSLC annotation and model support | + | * OSLC4J - The core component providing OSLC annotation and model support (<tt>org.eclipse.lyo.oslc4j.core / oslc4j-core</tt>) |
− | * Apache Jena Provider - A library to assist with serialization/de-serialization of OSLC-annotated Java objects to/from RDF XML. | + | * Apache Jena Provider - A library to assist with serialization/de-serialization of OSLC-annotated Java objects to/from RDF XML (<tt>org.eclipse.lyo.oslc4j.core / oslc4j-jena-provider</tt>). |
− | * Apache Wink Json4J Provider - A library to assist with serialization/de-serialization of OSLC-annotated Java objects to/from JSON. | + | * Apache Wink Json4J Provider - A library to assist with serialization/de-serialization of OSLC-annotated Java objects to/from JSON (<tt>org.eclipse.lyo.oslc4j.core / oslc4j-json4j-provider</tt>). |
* Apache Wink JAX-RS Provider - Utility classes, including an OSLC REST Client, to facilitate development using the Apache Wink JAX-RS implementation. | * Apache Wink JAX-RS Provider - Utility classes, including an OSLC REST Client, to facilitate development using the Apache Wink JAX-RS implementation. | ||
− | The Apache Jena and Apache Wink components are the built-in providers for RDF, RDF XML, JSON and JAX-RS. Additional providers could be implemented using technologies such as OpenRDF and Jersey. | + | The [http://incubator.apache.org/jena/ Apache Jena] and [http://incubator.apache.org/wink/ Apache Wink] components are the built-in providers for RDF, RDF XML, JSON and JAX-RS. Additional providers could be implemented using technologies such as OpenRDF and Jersey. |
== Sample code == | == Sample code == | ||
=== Annotation sample === | === Annotation sample === | ||
− | < | + | <source lang="java"> |
− | //sample simple string attribute (dcterms:description) | + | //sample simple string attribute (dcterms:description, as in http://open-services.net/bin/view/Main/OSLCCoreSpecAppendixA#Dublin_Core_Properties) |
@OslcDescription("Descriptive text (reference: Dublin Core) about resource represented as rich text in XHTML content.") | @OslcDescription("Descriptive text (reference: Dublin Core) about resource represented as rich text in XHTML content.") | ||
Line 36: | Line 70: | ||
} | } | ||
− | //sample relationship attribute (oslc_cm:affectsTestResult) | + | //sample relationship attribute (oslc_cm:affectsTestResult, as in http://open-services.net/bin/view/Main/CmSpecificationV2#Resource_ChangeRequest) |
@OslcDescription("Associated QM resource that is affected by this Change Request.") | @OslcDescription("Associated QM resource that is affected by this Change Request.") | ||
Line 48: | Line 82: | ||
return affectsTestResults.toArray(new URI[affectsTestResults.size()]); | return affectsTestResults.toArray(new URI[affectsTestResults.size()]); | ||
} | } | ||
− | </ | + | </source> |
=== JAX-RS method sample === | === JAX-RS method sample === | ||
+ | |||
+ | This illustrates implementation of an OSLC-CM (REST) server/provider | ||
+ | <source lang="java"> | ||
//support GET for a specific OSLC ChangeRequest | //support GET for a specific OSLC ChangeRequest | ||
Line 101: | Line 138: | ||
return Response.created(about).entity(changeRequest).build(); | return Response.created(about).entity(changeRequest).build(); | ||
} | } | ||
+ | </source> | ||
− | == | + | == See also == |
− | + | * [http://en.wikipedia.org/wiki/Java_annotation Java annotations] | |
− | * | + | |
− | + |
Latest revision as of 08:12, 9 August 2018
Contents
Lyo OSLC4J
What is OSLC4J?
OSLC4J is a Java toolkit for building Open Services for Lifecycle Collaboration providers and consumers. It includes:
- annotations to decorate Java objects with OSLC attributes
- annotations to assist with resource preview UIs (compact rendering)
- built-in support for service provider and resource shape documents
- libraries to simplify service provider and consumer development
- sample applications, including an OSLC Registry (catalog) application and a Change Management provider implementation
- Tests for the sample applications to complement the Lyo OSLC Test Suite
Getting started with OSLC4J
- Setup the Eclipse environment for Lyo-based development
- Create an initial REST server application, ready for Lyo-based development
- Use Lyo Designer to model a single server or complete toolchain and generate an initial code base
JARs are no longer available for download since Lyo 2.1.0. All artefacts are available through Eclipse Maven repos linked above. Lyo Designer is available through an Eclipse download site.
Using in Maven
Be sure to add Eclipse Maven repositories in your POM file before adding OSLC4J dependencies:
<repositories> <repository> <id>lyo-releases</id> <name>Eclipse Lyo Releases</name> <url>https://repo.eclipse.org/content/repositories/lyo-releases/</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>lyo-snapshots</id> <name>Eclipse Lyo Snapshots</name> <url>https://repo.eclipse.org/content/repositories/lyo-snapshots/</url> <releases> <enabled>false</enabled> </releases> </repository> </repositories>
Components
- OSLC4J - The core component providing OSLC annotation and model support (org.eclipse.lyo.oslc4j.core / oslc4j-core)
- Apache Jena Provider - A library to assist with serialization/de-serialization of OSLC-annotated Java objects to/from RDF XML (org.eclipse.lyo.oslc4j.core / oslc4j-jena-provider).
- Apache Wink Json4J Provider - A library to assist with serialization/de-serialization of OSLC-annotated Java objects to/from JSON (org.eclipse.lyo.oslc4j.core / oslc4j-json4j-provider).
- Apache Wink JAX-RS Provider - Utility classes, including an OSLC REST Client, to facilitate development using the Apache Wink JAX-RS implementation.
The Apache Jena and Apache Wink components are the built-in providers for RDF, RDF XML, JSON and JAX-RS. Additional providers could be implemented using technologies such as OpenRDF and Jersey.
Sample code
Annotation sample
//sample simple string attribute (dcterms:description, as in http://open-services.net/bin/view/Main/OSLCCoreSpecAppendixA#Dublin_Core_Properties) @OslcDescription("Descriptive text (reference: Dublin Core) about resource represented as rich text in XHTML content.") @OslcPropertyDefinition(OslcConstants.DCTERMS_NAMESPACE + "description") @OslcTitle("Description") @OslcValueType(ValueType.XMLLiteral) public String getDescription() { return description; } //sample relationship attribute (oslc_cm:affectsTestResult, as in http://open-services.net/bin/view/Main/CmSpecificationV2#Resource_ChangeRequest) @OslcDescription("Associated QM resource that is affected by this Change Request.") @OslcName("affectsTestResult") @OslcPropertyDefinition(Constants.CHANGE_MANAGEMENT_NAMESPACE + "affectsTestResult") @OslcRange(Constants.TYPE_TEST_RESULT) @OslcReadOnly(false) @OslcTitle("Affects Test Results") public URI[] getAffectsTestResults() { return affectsTestResults.toArray(new URI[affectsTestResults.size()]); }
JAX-RS method sample
This illustrates implementation of an OSLC-CM (REST) server/provider
//support GET for a specific OSLC ChangeRequest @GET @Path("{changeRequestId}") @Produces({OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_XML, OslcMediaType.APPLICATION_JSON}) public ChangeRequest getChangeRequest(@Context final HttpServletResponse httpServletResponse, @PathParam("changeRequestId") final String changeRequestId) { final ChangeRequest changeRequest = Persistence.getChangeRequest(changeRequestId); if (changeRequest != null) { changeRequest.setServiceProvider(ServiceProviderSingleton.getServiceProviderURI()); setETagHeader(getETagFromChangeRequest(changeRequest), httpServletResponse); return changeRequest; } throw new WebApplicationException(Status.NOT_FOUND); } //support POST to create a new ChangeRequest @POST @Consumes({OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_XML, OslcMediaType.APPLICATION_JSON}) @Produces({OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_XML, OslcMediaType.APPLICATION_JSON}) public Response addChangeRequest(@Context final HttpServletRequest httpServletRequest, @Context final HttpServletResponse httpServletResponse, final ChangeRequest changeRequest) throws URISyntaxException { final long identifier = Persistence.getNextIdentifier(); final URI about = new URI(httpServletRequest.getScheme(), null, httpServletRequest.getServerName(), httpServletRequest.getServerPort(), httpServletRequest.getContextPath() + "/changeRequests/" + identifier, null, null); changeRequest.setAbout(about); changeRequest.setIdentifier(String.valueOf(identifier)); changeRequest.setServiceProvider(ServiceProviderSingleton.getServiceProviderURI()); final Date date = new Date(); changeRequest.setCreated(date); changeRequest.setModified(date); Persistence.addChangeRequest(changeRequest); setETagHeader(getETagFromChangeRequest(changeRequest), httpServletResponse); return Response.created(about).entity(changeRequest).build(); }