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

Bug 531986 - Change isQueryResult logic #88

Merged
merged 1 commit into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
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;
}
}
}