Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Commit

Permalink
Bug 531986 - Change isQueryResult logic (#88)
Browse files Browse the repository at this point in the history
Previously, all arrays were treated as OSLC Query results unless the
array type was explicitly marked with @OslcNotQueryResult annotation.
This prevented from returning arrays of mixed-typed OSLC resources (as
Object[] or IResource[]) because there is no way to annotate those
classes accordingly.

From now on, only arrays returned from JAX-RS methods annotated with
@OslcQueryCapability will be automatically treated as OSLC Query results
(again, unless the returned array type is annotated with the
@OslcNotQueryResult).

Signed-off-by: Andrew Berezovskyi <andriib@kth.se>
  • Loading branch information
berezovskyi authored and jadelkhoury committed Apr 23, 2019
1 parent dd371dd commit 631c78a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
Expand Up @@ -207,10 +207,12 @@ protected void writeTo(final boolean queryResult,
}

String descriptionURI = null;
// TODO Andrew@2019-04-18: stop using responseInfoURI nullity to detect Query results
String responseInfoURI = null;

if (queryResult && ! isClientSide)
{
log.trace("Marshalling response objects as OSLC Query result (server-side only)");

final String method = httpServletRequest.getMethod();
if ("GET".equals(method))
Expand Down
@@ -0,0 +1,34 @@
package org.eclipse.lyo.oslc4j.provider.jena;

import java.lang.annotation.Annotation;
import org.eclipse.lyo.oslc4j.core.annotation.OslcNotQueryResult;
import org.eclipse.lyo.oslc4j.core.annotation.OslcQueryCapability;

/**
* TODO
*
* @since TODO
*/
public class JenaProviderHelper {
static boolean hasNotQueryResultTypeAnnot(final Class<?> type) {
OslcNotQueryResult notQueryResult = type.getComponentType()
.getAnnotation(OslcNotQueryResult.class);
return (notQueryResult != null && notQueryResult.value());
}

static boolean hasOslcQueryCapabilityMethodAnnot(final Annotation[] annotations) {
if (annotations != null) {
for (int i = 0; i < annotations.length; i++) {
if (annotations[i] != null && annotations[i] instanceof OslcQueryCapability) {
return true;
}
}
}
return false;
}

static boolean isQueryResult(final Class<?> type, final Annotation[] annotations) {
return hasOslcQueryCapabilityMethodAnnot(annotations) &&
!hasNotQueryResultTypeAnnot(type);
}
}
@@ -1,4 +1,4 @@
/*******************************************************************************
/*!*****************************************************************************
* Copyright (c) 2012, 2013 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
Expand All @@ -15,6 +15,7 @@
* Alberto Giammaria - initial API and implementation
* Chris Peters - initial API and implementation
* Gianluca Bernardini - initial API and implementation
* Andrew Berezovskyi - change isQueryResult logic
*******************************************************************************/
package org.eclipse.lyo.oslc4j.provider.jena;

Expand All @@ -33,7 +34,6 @@
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;

import org.eclipse.lyo.oslc4j.core.annotation.OslcNotQueryResult;
import org.eclipse.lyo.oslc4j.core.model.OslcMediaType;

@Provider
Expand Down Expand Up @@ -85,14 +85,9 @@ public void writeTo(final Object[] objects,
final MultivaluedMap<String, Object> map,
final OutputStream outputStream)
throws IOException,
WebApplicationException
{
OslcNotQueryResult notQueryResult = type.getComponentType().getAnnotation(OslcNotQueryResult.class);

writeTo(notQueryResult != null && notQueryResult.value() ? false : true,
objects,
mediaType,
map,
WebApplicationException {

writeTo(JenaProviderHelper.isQueryResult(type, annotations), objects, mediaType, map,
outputStream);
}

Expand Down Expand Up @@ -126,4 +121,4 @@ public Object[] readFrom(final Class<Object[]> type,
map,
inputStream);
}
}
}
Expand Up @@ -123,10 +123,9 @@ public void writeTo(final Collection<Object> collection,
{
final ParameterizedType parameterizedType = (ParameterizedType) genericType;
final Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
OslcNotQueryResult notQueryResult = ((Class<?>)actualTypeArguments[0]).getAnnotation(OslcNotQueryResult.class);

writeTo(notQueryResult != null && notQueryResult.value() ? false : true,
collection.toArray(new Object[collection.size()]),

writeTo(JenaProviderHelper.isQueryResult((Class<?>)actualTypeArguments[0], annotations),
collection.toArray(new Object[0]),
mediaType,
map,
outputStream);
Expand Down Expand Up @@ -257,4 +256,4 @@ else if ((SortedSet.class.equals(type)) ||

return null;
}
}
}

0 comments on commit 631c78a

Please sign in to comment.