diff --git a/oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/AbstractOslcRdfXmlProvider.java b/oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/AbstractOslcRdfXmlProvider.java index 776ca63..6c5fe81 100644 --- a/oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/AbstractOslcRdfXmlProvider.java +++ b/oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/AbstractOslcRdfXmlProvider.java @@ -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)) diff --git a/oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/JenaProviderHelper.java b/oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/JenaProviderHelper.java new file mode 100644 index 0000000..95e5cff --- /dev/null +++ b/oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/JenaProviderHelper.java @@ -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); + } +} diff --git a/oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlArrayProvider.java b/oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlArrayProvider.java index e945733..9579176 100644 --- a/oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlArrayProvider.java +++ b/oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlArrayProvider.java @@ -1,4 +1,4 @@ -/******************************************************************************* +/*!***************************************************************************** * Copyright (c) 2012, 2013 IBM Corporation. * * All rights reserved. This program and the accompanying materials @@ -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; @@ -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 @@ -85,14 +85,9 @@ public void writeTo(final Object[] objects, final MultivaluedMap 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); } @@ -126,4 +121,4 @@ public Object[] readFrom(final Class type, map, inputStream); } -} \ No newline at end of file +} diff --git a/oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlCollectionProvider.java b/oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlCollectionProvider.java index 1f5bcd6..e42553e 100644 --- a/oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlCollectionProvider.java +++ b/oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlCollectionProvider.java @@ -123,10 +123,9 @@ public void writeTo(final Collection 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); @@ -257,4 +256,4 @@ else if ((SortedSet.class.equals(type)) || return null; } -} \ No newline at end of file +}