Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Lyo/LyoOSLC4J"
< Lyo
Line 24: | Line 24: | ||
=== Annotation sample === | === Annotation sample === | ||
− | < | + | <code> |
//sample simple string attribute (dcterms:description) | //sample simple string attribute (dcterms:description) | ||
Line 48: | Line 48: | ||
return affectsTestResults.toArray(new URI[affectsTestResults.size()]); | return affectsTestResults.toArray(new URI[affectsTestResults.size()]); | ||
} | } | ||
− | </ | + | </code> |
=== JAX-RS method sample === | === JAX-RS method sample === | ||
− | |||
− | |||
//support GET for a specific OSLC ChangeRequest | //support GET for a specific OSLC ChangeRequest | ||
Line 62: | Line 60: | ||
{ | { | ||
final ChangeRequest changeRequest = Persistence.getChangeRequest(changeRequestId); | final ChangeRequest changeRequest = Persistence.getChangeRequest(changeRequestId); | ||
− | |||
if (changeRequest != null) | if (changeRequest != null) | ||
{ | { | ||
changeRequest.setServiceProvider(ServiceProviderSingleton.getServiceProviderURI()); | changeRequest.setServiceProvider(ServiceProviderSingleton.getServiceProviderURI()); | ||
− | |||
setETagHeader(getETagFromChangeRequest(changeRequest), httpServletResponse); | setETagHeader(getETagFromChangeRequest(changeRequest), httpServletResponse); | ||
− | |||
return changeRequest; | return changeRequest; | ||
} | } | ||
− | |||
throw new WebApplicationException(Status.NOT_FOUND); | throw new WebApplicationException(Status.NOT_FOUND); | ||
} | } | ||
Line 86: | Line 80: | ||
{ | { | ||
final long identifier = Persistence.getNextIdentifier(); | final long identifier = Persistence.getNextIdentifier(); | ||
− | |||
final URI about = new URI(httpServletRequest.getScheme(), | final URI about = new URI(httpServletRequest.getScheme(), | ||
null, | null, | ||
Line 94: | Line 87: | ||
null, | null, | ||
null); | null); | ||
− | |||
changeRequest.setAbout(about); | changeRequest.setAbout(about); | ||
changeRequest.setIdentifier(String.valueOf(identifier)); | changeRequest.setIdentifier(String.valueOf(identifier)); | ||
Line 109: | Line 101: | ||
return Response.created(about).entity(changeRequest).build(); | return Response.created(about).entity(changeRequest).build(); | ||
} | } | ||
− | |||
== Getting started with OSLC4J == | == Getting started with OSLC4J == |
Revision as of 09:54, 15 February 2012
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/LyoTestSuite Lyo OSLC Test Suite]
Components
- OSLC4J - The core component providing OSLC annotation and model support
- Apache Jena Provider - A library to assist with serialization/de-serialization of OSLC-annotated Java objects to/from RDF XML.
- Apache Wink Json4J Provider - A library to assist with serialization/de-serialization of OSLC-annotated Java objects to/from JSON.
- 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)
@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)
@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
//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(); }
Getting started with OSLC4J
- The Lyo OSLC4J project is currently provided as source code. We're working on getting jars built by the Eclipse build infrastructure
- See [Lyo/BuildingOSLC4J Setting up OSLC4J] for information on setting up a development environment.