You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2014/05/14 09:02:20 UTC
svn commit: r1594490 - in /stanbol/branches/release-0.12/enhancer:
generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/
generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/helper/
jersey/src/main/java/o...
Author: rwesten
Date: Wed May 14 07:02:20 2014
New Revision: 1594490
URL: http://svn.apache.org/r1594490
Log:
STANBOL-488: all methods, utilities and variables dealing with request scoped EnhancementProperties now use request properties in their name. This allows a better distinguish between properties as parsed with request (using the '[{engine-name}:]{key}' encoding for keys) and EnhancementProperties as extracted for the current engine. This introduces no functional changes
Added:
stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/utils/RequestPropertiesHelper.java (with props)
Modified:
stanbol/branches/release-0.12/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ContentItemHelper.java
stanbol/branches/release-0.12/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/EnhancementEngineHelper.java
stanbol/branches/release-0.12/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/helper/EnhancementPropertyTest.java
stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/reader/ContentItemReader.java
stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerResource.java
stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerUiResource.java
stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ContentItemResource.java
stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/utils/EnhancementPropertiesHelper.java
stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/writers/ContentItemWriter.java
stanbol/branches/release-0.12/enhancer/jersey/src/test/java/org/apache/stanbol/enhancer/jersey/ContentItemReaderWriterTest.java
Modified: stanbol/branches/release-0.12/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ContentItemHelper.java
URL: http://svn.apache.org/viewvc/stanbol/branches/release-0.12/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ContentItemHelper.java?rev=1594490&r1=1594489&r2=1594490&view=diff
==============================================================================
--- stanbol/branches/release-0.12/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ContentItemHelper.java (original)
+++ stanbol/branches/release-0.12/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/ContentItemHelper.java Wed May 14 07:02:20 2014
@@ -368,12 +368,12 @@ public final class ContentItemHelper {
"urn:apache.org:stanbol.web:enhancement.properties");
/**
- * Getter for the EnhancementProperties content part
+ * Getter for the content part holding the request scoped EnhancementProperties.
* @param ci the content item
* @return the content part or <code>null</code> if not present.
*/
@SuppressWarnings("unchecked")
- public static Map<String,Object> getEnhancementPropertiesContentPart(ContentItem ci){
+ public static Map<String,Object> getRequestPropertiesContentPart(ContentItem ci){
if(ci == null){
throw new IllegalArgumentException("The parsed ContentItem MUST NOT be NULL!");
}
@@ -389,7 +389,7 @@ public final class ContentItemHelper {
}
/**
- * Initialises the EnhancementProperties ContentPart for an {@link ContentItem}.
+ * Initialises the ContentPart holding the request scoped EnhancementProperties.
* If the content part is already present it will just return the existing. If
* not it will register an empty one. The content part is registered with
* the URI {@link #ENHANCEMENT_PROPERTIES_URI}
@@ -398,7 +398,7 @@ public final class ContentItemHelper {
* @throws IllegalArgumentException if <code>null</code> is parsed as {@link ContentItem}.
*/
@SuppressWarnings("unchecked")
- public static Map<String,Object> initEnhancementPropertiesContentPart(ContentItem ci){
+ public static Map<String,Object> initRequestPropertiesContentPart(ContentItem ci){
if(ci == null){
throw new IllegalArgumentException("The parsed ContentItem MUST NOT be NULL!");
}
@@ -424,6 +424,45 @@ public final class ContentItemHelper {
} //else was already present
return enhancementProperties;
}
-
+ /**
+ * Sets a request scoped EnhancementProperty to the parsed contentItem. If
+ * <code>null</code> is parsed as value the property is removed.<p>
+ * This Method will retrieve the RequestProperties contentPart from the
+ * parsed {@link ContentItem} and adds the parsed property by applying the
+ * <code>[{engine-name}:]{key}</code> encoding to the key.<p>
+ * This method acquires a write lock on the ContentItem when writing
+ * the enhancement property.
+ * @param ci the ContentItem to set the enhancement property. MUST NOT be
+ * <code>null</code>
+ * @param engineName the engine or <code>null</code> to set the property for the
+ * chain.
+ * @param key the key of the property. MUST NOT be <code>null</code>
+ * @param value the value or <code>null</code> to remove the property
+ * @return the old value or <code>null</code> if the property was not present
+ * @throws IllegalArgumentException if <code>null</code> is parsed as
+ * {@link ContentItem} or key.
+ */
+ public static Object setRequestProperty(ContentItem ci, String engineName, String key, Object value){
+ if(ci == null){
+ throw new IllegalArgumentException("The parsed ContentItem MUST NOT be NULL!");
+ }
+ if(key == null || key.isEmpty()){
+ throw new IllegalArgumentException("The parsed Enhancement Property key MUST NOT be NULL nor empty!");
+ }
+ Map<String,Object> enhProp = initRequestPropertiesContentPart(ci);
+ if(engineName != null){
+ key = new StringBuilder(engineName).append(':').append(key).toString();
+ }
+ ci.getLock().writeLock().lock();
+ try {
+ if(value == null){
+ return enhProp.remove(key);
+ } else {
+ return enhProp.put(key, value);
+ }
+ } finally {
+ ci.getLock().writeLock().unlock();
+ }
+ }
}
Modified: stanbol/branches/release-0.12/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/EnhancementEngineHelper.java
URL: http://svn.apache.org/viewvc/stanbol/branches/release-0.12/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/EnhancementEngineHelper.java?rev=1594490&r1=1594489&r2=1594490&view=diff
==============================================================================
--- stanbol/branches/release-0.12/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/EnhancementEngineHelper.java (original)
+++ stanbol/branches/release-0.12/enhancer/generic/servicesapi/src/main/java/org/apache/stanbol/enhancer/servicesapi/helper/EnhancementEngineHelper.java Wed May 14 07:02:20 2014
@@ -873,7 +873,7 @@ public final class EnhancementEngineHelp
// with the `em:ChainExecution` node and engine specific properties
// with the `em:EngineExecution` node.
// So this code will need to be refactored similar to the above one
- Map<String,Object> epContentPart = ContentItemHelper.getEnhancementPropertiesContentPart(ci);
+ Map<String,Object> epContentPart = ContentItemHelper.getRequestPropertiesContentPart(ci);
Map<String,Object> chainProperties = new HashMap<String,Object>();
Map<String,Object> engineProperties = new HashMap<String,Object>();
if(epContentPart != null){
Modified: stanbol/branches/release-0.12/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/helper/EnhancementPropertyTest.java
URL: http://svn.apache.org/viewvc/stanbol/branches/release-0.12/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/helper/EnhancementPropertyTest.java?rev=1594490&r1=1594489&r2=1594490&view=diff
==============================================================================
--- stanbol/branches/release-0.12/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/helper/EnhancementPropertyTest.java (original)
+++ stanbol/branches/release-0.12/enhancer/generic/servicesapi/src/test/java/org/apache/stanbol/enhancer/serviceapi/helper/EnhancementPropertyTest.java Wed May 14 07:02:20 2014
@@ -245,7 +245,7 @@ public class EnhancementPropertyTest {
initExecutionMetadata(new TestChain("test", engines));
//(1) test a a enhancement property overridden with a engine specific one
- Map<String,Object> ep = ContentItemHelper.initEnhancementPropertiesContentPart(contentItem);
+ Map<String,Object> ep = ContentItemHelper.initRequestPropertiesContentPart(contentItem);
assertNotNull("EnhancementProperties ContentPart was not initialised",ep);
ep.put(PROPERTY_MAX_SUGGESTIONS, "5"); //global property
@@ -264,7 +264,7 @@ public class EnhancementPropertyTest {
Collection<String> derefernceLanguages = Arrays.asList("en","de");
//(1) test a a enhancement property overridden with a engine specific one
- Map<String,Object> ep = ContentItemHelper.initEnhancementPropertiesContentPart(contentItem);
+ Map<String,Object> ep = ContentItemHelper.initRequestPropertiesContentPart(contentItem);
assertNotNull("EnhancementProperties ContentPart was not initialised",ep);
ep.put(PROPERTY_DEREFERENCE_LANGUAGES, derefernceLanguages); //global property
@@ -284,7 +284,7 @@ public class EnhancementPropertyTest {
Collection<String> derefernceLanguages = Arrays.asList("en","de");
String maxSuggestions = "5";
//(1) test a a enhancement property overridden with a engine specific one
- Map<String,Object> ep = ContentItemHelper.initEnhancementPropertiesContentPart(contentItem);
+ Map<String,Object> ep = ContentItemHelper.initRequestPropertiesContentPart(contentItem);
assertNotNull("EnhancementProperties ContentPart was not initialised",ep);
ep.put(linking.getName()+':'+PROPERTY_MAX_SUGGESTIONS, maxSuggestions);
ep.put(dereference.getName()+':'+PROPERTY_DEREFERENCE_LANGUAGES, derefernceLanguages);
@@ -317,7 +317,7 @@ public class EnhancementPropertyTest {
//(1) test a a enhancement property overridden with a engine specific one
String specific = linking.getName();
- Map<String,Object> ep = ContentItemHelper.initEnhancementPropertiesContentPart(contentItem);
+ Map<String,Object> ep = ContentItemHelper.initRequestPropertiesContentPart(contentItem);
assertNotNull("EnhancementProperties ContentPart was not initialised",ep);
ep.put(PROPERTY_MAX_SUGGESTIONS, "5"); //global property
ep.put(specific+':'+PROPERTY_MAX_SUGGESTIONS, "10");//engine specific
@@ -518,7 +518,7 @@ public class EnhancementPropertyTest {
initExecutionMetadata(new TestChain("test", engines, enhancementProperties));
- Map<String,Object> ep = ContentItemHelper.initEnhancementPropertiesContentPart(contentItem);
+ Map<String,Object> ep = ContentItemHelper.initRequestPropertiesContentPart(contentItem);
assertNotNull("EnhancementProperties ContentPart was not initialised",ep);
ep.put(linking.getName()+':'+PROPERTY_MAX_SUGGESTIONS, requestMaySuggestion);
ep.put(dereference.getName()+':'+PROPERTY_DEREFERENCE_LANGUAGES, requestDerefLang);
Modified: stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/reader/ContentItemReader.java
URL: http://svn.apache.org/viewvc/stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/reader/ContentItemReader.java?rev=1594490&r1=1594489&r2=1594490&view=diff
==============================================================================
--- stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/reader/ContentItemReader.java (original)
+++ stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/reader/ContentItemReader.java Wed May 14 07:02:20 2014
@@ -17,9 +17,8 @@
package org.apache.stanbol.enhancer.jersey.reader;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.ENHANCEMENT_PROPERTIES_URI;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.PARSED_CONTENT_URIS;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.getEnhancementProperties;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.ENHANCEMENT_PROPERTIES_URI;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.PARSED_CONTENT_URIS;
import static org.apache.stanbol.enhancer.servicesapi.helper.EnhancementEngineHelper.randomUUID;
import java.io.IOException;
@@ -62,6 +61,7 @@ import org.apache.stanbol.commons.web.ba
import org.apache.stanbol.enhancer.servicesapi.Blob;
import org.apache.stanbol.enhancer.servicesapi.ContentItem;
import org.apache.stanbol.enhancer.servicesapi.ContentItemFactory;
+import org.apache.stanbol.enhancer.servicesapi.helper.ContentItemHelper;
import org.apache.stanbol.enhancer.servicesapi.impl.StreamSource;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
@@ -180,12 +180,12 @@ public class ContentItemReader implement
contentItem = createContentItem(contentItemId, metadata, fis, parsedContentIds);
} else if(fis.getFieldName().equals("properties") ||
fis.getFieldName().equals(ENHANCEMENT_PROPERTIES_URI.getUnicodeString())){
- //parse the enhancementProperties
+ //parse the RequestProperties
if(contentItem == null){
throw new WebApplicationException(
Response.status(Response.Status.BAD_REQUEST)
.entity("Multipart MIME parts for " +
- "EnhancementProperties MUST BE after the " +
+ "Request Properties MUST BE after the " +
"MIME parts for 'metadata' AND 'content'")
.build());
}
@@ -193,7 +193,7 @@ public class ContentItemReader implement
if(!APPLICATION_JSON_TYPE.isCompatible(propMediaType)){
throw new WebApplicationException(
Response.status(Response.Status.BAD_REQUEST)
- .entity("EnhancementProperties (Multipart MIME parts" +
+ .entity("Request Properties (Multipart MIME parts" +
"with the name '"+fis.getFieldName()+"') MUST " +
"BE encoded as 'appicaltion/json' (encountered: '" +
fis.getContentType()+"')!")
@@ -203,14 +203,15 @@ public class ContentItemReader implement
if(propCharset == null){
propCharset = "UTF-8";
}
- Map<String,Object> enhancementProperties = getEnhancementProperties(contentItem);
+ Map<String,Object> reqProp =
+ ContentItemHelper.initRequestPropertiesContentPart(contentItem);
try {
- enhancementProperties.putAll(toMap(new JSONObject(
+ reqProp.putAll(toMap(new JSONObject(
IOUtils.toString(fis.openStream(),propCharset))));
} catch (JSONException e) {
throw new WebApplicationException(e,
Response.status(Response.Status.BAD_REQUEST)
- .entity("Unable to parse EnhancementProperties from" +
+ .entity("Unable to parse Request Properties from" +
"Multipart MIME parts with the name 'properties'!")
.build());
}
@@ -267,7 +268,7 @@ public class ContentItemReader implement
parsedContentIds.add(contentItem.getPartUri(0).getUnicodeString());
}
//set the parsed contentIDs to the EnhancementProperties
- Map<String,Object> ep = getEnhancementProperties(contentItem);
+ Map<String,Object> ep = ContentItemHelper.initRequestPropertiesContentPart(contentItem);
parseEnhancementPropertiesFromParameters(ep);
ep.put(PARSED_CONTENT_URIS, Collections.unmodifiableSet(parsedContentIds));
return contentItem;
Modified: stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerResource.java
URL: http://svn.apache.org/viewvc/stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerResource.java?rev=1594490&r1=1594489&r2=1594490&view=diff
==============================================================================
--- stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerResource.java (original)
+++ stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerResource.java Wed May 14 07:02:20 2014
@@ -27,13 +27,12 @@ import static org.apache.clerezza.rdf.co
import static org.apache.stanbol.commons.web.base.utils.MediaTypeUtil.JSON_LD;
import static org.apache.stanbol.commons.web.base.CorsHelper.addCORSOrigin;
import static org.apache.stanbol.commons.web.base.CorsHelper.enableCORS;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.INCLUDE_EXECUTION_METADATA;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.OMIT_METADATA;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.OMIT_PARSED_CONTENT;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.OUTPUT_CONTENT;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.OUTPUT_CONTENT_PART;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.RDF_FORMAT;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.getEnhancementProperties;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.INCLUDE_EXECUTION_METADATA;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.OMIT_METADATA;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.OMIT_PARSED_CONTENT;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.OUTPUT_CONTENT;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.OUTPUT_CONTENT_PART;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.RDF_FORMAT;
import java.io.IOException;
import java.util.HashSet;
@@ -62,7 +61,7 @@ import org.apache.clerezza.rdf.core.UriR
import org.apache.stanbol.commons.web.base.ContextHelper;
import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
import org.apache.stanbol.commons.web.base.utils.MediaTypeUtil;
-import org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper;
+import org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper;
import org.apache.stanbol.enhancer.servicesapi.Chain;
import org.apache.stanbol.enhancer.servicesapi.ChainException;
import org.apache.stanbol.enhancer.servicesapi.ChainManager;
@@ -73,6 +72,7 @@ import org.apache.stanbol.enhancer.servi
import org.apache.stanbol.enhancer.servicesapi.EnhancementException;
import org.apache.stanbol.enhancer.servicesapi.EnhancementJobManager;
import org.apache.stanbol.enhancer.servicesapi.NoSuchPartException;
+import org.apache.stanbol.enhancer.servicesapi.helper.ContentItemHelper;
import org.apache.stanbol.enhancer.servicesapi.rdf.ExecutionMetadata;
/**
@@ -182,12 +182,12 @@ public abstract class AbstractEnhancerRe
@QueryParam(value = "omitMetadata") boolean omitMetadata,
@QueryParam(value = "rdfFormat") String rdfFormat,
@Context HttpHeaders headers) throws EnhancementException, IOException {
- Map<String,Object> enhancementProperties = getEnhancementProperties(ci);
- enhancementProperties.put(INCLUDE_EXECUTION_METADATA, inclExecMetadata);
+ Map<String,Object> reqProp = ContentItemHelper.initRequestPropertiesContentPart(ci);
+ reqProp.put(INCLUDE_EXECUTION_METADATA, inclExecMetadata);
if(mediaTypes != null && !mediaTypes.isEmpty()){
- enhancementProperties.put(OUTPUT_CONTENT, mediaTypes);
+ reqProp.put(OUTPUT_CONTENT, mediaTypes);
}
- enhancementProperties.put(OMIT_PARSED_CONTENT, omitParsed);
+ reqProp.put(OMIT_PARSED_CONTENT, omitParsed);
if(contentParts != null && !contentParts.isEmpty()){
Set<UriRef> outputContentParts = new HashSet<UriRef>();
for(String contentPartUri : contentParts){
@@ -199,12 +199,12 @@ public abstract class AbstractEnhancerRe
}
}
}
- enhancementProperties.put(OUTPUT_CONTENT_PART, outputContentParts);
+ reqProp.put(OUTPUT_CONTENT_PART, outputContentParts);
}
- enhancementProperties.put(OMIT_METADATA, omitMetadata);
+ reqProp.put(OMIT_METADATA, omitMetadata);
if(rdfFormat != null && !rdfFormat.isEmpty()){
try {
- enhancementProperties.put(RDF_FORMAT,MediaType.valueOf(rdfFormat).toString());
+ reqProp.put(RDF_FORMAT,MediaType.valueOf(rdfFormat).toString());
} catch (IllegalArgumentException e) {
throw new WebApplicationException(e,
Response.status(Response.Status.BAD_REQUEST)
@@ -213,7 +213,7 @@ public abstract class AbstractEnhancerRe
.build());
}
}
- enhance(ci);
+ enhance(ci,reqProp);
ResponseBuilder rb = Response.ok(ci);
MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
if (mediaType != null) {
@@ -226,15 +226,15 @@ public abstract class AbstractEnhancerRe
/**
* Enhances the parsed ContentItem
* @param ci the content item to enhance
+ * @param reqProp the request properties or <code>null</code> if none
* @throws EnhancementException
*/
- protected void enhance(ContentItem ci) throws EnhancementException {
- Map<String,Object> enhancementPropertis = EnhancementPropertiesHelper.getEnhancementProperties(ci);
+ protected void enhance(ContentItem ci, Map<String,Object> reqProp) throws EnhancementException {
if (jobManager != null) {
jobManager.enhanceContent(ci, getChain());
}
MGraph graph = ci.getMetadata();
- Boolean includeExecutionMetadata = (Boolean)enhancementPropertis.get(INCLUDE_EXECUTION_METADATA);
+ Boolean includeExecutionMetadata = RequestPropertiesHelper.isIncludeExecutionMetadata(reqProp);
if (includeExecutionMetadata != null && includeExecutionMetadata.booleanValue()) {
try {
graph.addAll(ci.getPart(ExecutionMetadata.CHAIN_EXECUTION, TripleCollection.class));
Modified: stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerUiResource.java
URL: http://svn.apache.org/viewvc/stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerUiResource.java?rev=1594490&r1=1594489&r2=1594490&view=diff
==============================================================================
--- stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerUiResource.java (original)
+++ stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/AbstractEnhancerUiResource.java Wed May 14 07:02:20 2014
@@ -123,7 +123,7 @@ public abstract class AbstractEnhancerUi
} else { //enhance and build the AJAX response
EnhancementException enhancementException;
try {
- enhance(ci);
+ enhance(ci, null);
enhancementException = null;
} catch (EnhancementException e){
enhancementException = e;
Modified: stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ContentItemResource.java
URL: http://svn.apache.org/viewvc/stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ContentItemResource.java?rev=1594490&r1=1594489&r2=1594490&view=diff
==============================================================================
--- stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ContentItemResource.java (original)
+++ stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ContentItemResource.java Wed May 14 07:02:20 2014
@@ -38,7 +38,6 @@ import static org.apache.stanbol.enhance
import static org.apache.stanbol.enhancer.servicesapi.rdf.Properties.GEO_LONG;
import static org.apache.stanbol.enhancer.servicesapi.rdf.TechnicalClasses.ENHANCER_ENTITYANNOTATION;
import static org.apache.stanbol.enhancer.servicesapi.rdf.TechnicalClasses.ENHANCER_TEXTANNOTATION;
-import static org.apache.stanbol.enhancer.servicesapi.rdf.TechnicalClasses.ENHANCER_TOPICANNOTATION;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -98,11 +97,8 @@ import org.apache.stanbol.enhancer.servi
import org.apache.stanbol.enhancer.servicesapi.helper.execution.ChainExecution;
import org.apache.stanbol.enhancer.servicesapi.helper.execution.Execution;
import org.apache.stanbol.enhancer.servicesapi.rdf.ExecutionMetadata;
-import org.apache.stanbol.enhancer.servicesapi.rdf.NamespaceEnum;
import org.apache.stanbol.enhancer.servicesapi.rdf.OntologicalClasses;
import org.apache.stanbol.enhancer.servicesapi.rdf.Properties;
-import org.apache.stanbol.enhancer.servicesapi.rdf.TechnicalClasses;
-import org.apache.stanbol.enhancer.servicesapi.rdf.TechnicalClasses.CONFIDENCE_LEVEL_ENUM;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Modified: stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/utils/EnhancementPropertiesHelper.java
URL: http://svn.apache.org/viewvc/stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/utils/EnhancementPropertiesHelper.java?rev=1594490&r1=1594489&r2=1594490&view=diff
==============================================================================
--- stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/utils/EnhancementPropertiesHelper.java (original)
+++ stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/utils/EnhancementPropertiesHelper.java Wed May 14 07:02:20 2014
@@ -35,20 +35,23 @@ import org.apache.stanbol.enhancer.servi
/**
* Defines Constants and utilities for using EnhancementProperties
+ * @deprecated unse the {@link RequestPropertiesHelper} instead
*/
public final class EnhancementPropertiesHelper {
private EnhancementPropertiesHelper(){/* no instances allowed*/}
/**
* @see ContentItemHelper#ENHANCEMENT_PROPERTIES_URI
+ * @deprecated use {@link RequestPropertiesHelper#ENHANCEMENT_PROPERTIES_URI}
*/
public static final UriRef ENHANCEMENT_PROPERTIES_URI =
- ContentItemHelper.ENHANCEMENT_PROPERTIES_URI;
+ RequestPropertiesHelper.ENHANCEMENT_PROPERTIES_URI;
/**
* Boolean switch parsed as {@link QueryParam} tha allows to deactivate the
* inclusion of the {@link ContentItem#getMetadata()} in the Response
+ * @deprecated use {@link RequestPropertiesHelper#OMIT_METADATA} instead
*/
- public static final String OMIT_METADATA = "stanbol.enhancer.web.omitMetadata";
+ public static final String OMIT_METADATA = RequestPropertiesHelper.OMIT_METADATA;
/**
* {@link Set Set<String>} containing all the URIs of the
* {@link ContentItem#getPart(UriRef, Class) ContentParts} representing
@@ -57,20 +60,23 @@ public final class EnhancementProperties
* NOTE: This can also be used to include the EnhancementProperties
* as "applciation/json" in the Response by adding this
* {@link EnhancementPropertiesHelper#ENHANCEMENT_PROPERTIES_URI uri}.
+ * @deprecated use {@link RequestPropertiesHelper#OUTPUT_CONTENT_PART} instead
*/
- public static final String OUTPUT_CONTENT_PART = "stanbol.enhancer.web.outputContentPart";
+ public static final String OUTPUT_CONTENT_PART = RequestPropertiesHelper.OUTPUT_CONTENT_PART;
/**
* Allows to omit all parsed content parts regardless of the {@link #OUTPUT_CONTENT_PART}
* configuration
+ * @deprecated use {@link RequestPropertiesHelper#OMIT_PARSED_CONTENT} instead
*/
- public static final String OMIT_PARSED_CONTENT = "stanbol.enhancer.web.omitParsed";
+ public static final String OMIT_PARSED_CONTENT = RequestPropertiesHelper.OMIT_PARSED_CONTENT;
/**
* {@link Collection Collection<String>} containing mime types. This
* allows to specify what versions of the parsed content to be included in
* the response. e.g. ["text/*","application/pdf"] would include all text
* formats and PDF.
+ * @deprecated use {@link RequestPropertiesHelper#OUTPUT_CONTENT} instead
*/
- public static final String OUTPUT_CONTENT = "stanbol.enhancer.web.outputContent";
+ public static final String OUTPUT_CONTENT = RequestPropertiesHelper.OUTPUT_CONTENT;
/**
* This allows to copy the {@link ExecutionMetadata} and {@link ExecutionPlan}
* data stored in a {@link ContentItem#getPart(UriRef, Class) contentPart} with
@@ -78,122 +84,124 @@ public final class EnhancementProperties
* {@link ContentItem#getMetadata() metadata} of the content item.<p>
* This feature is intended to allow users to retrieve such meta information
* without the need to use parse Multipart MIME responses.
+ * @deprecated use {@link RequestPropertiesHelper#INCLUDE_EXECUTION_METADATA} instead
*/
- public static final String INCLUDE_EXECUTION_METADATA = "stanbol.enhancer.web.executionmetadata";
+ public static final String INCLUDE_EXECUTION_METADATA = RequestPropertiesHelper.INCLUDE_EXECUTION_METADATA;
/**
* The used format to encode RDF graphs for "multipart/*" responses. This
* needs to be parsed separately, because the Accept header needs to be
* set to "multipart/from-data" in such cases
+ * @deprecated use {@link RequestPropertiesHelper#RDF_FORMAT} instead
*/
- public static final String RDF_FORMAT = "stanbol.enhancer.web.rdfFormat";
+ public static final String RDF_FORMAT = RequestPropertiesHelper.RDF_FORMAT;
/**
* {@link Set Set<String>} containing all the {@link UriRef}s of
* {@link ContentItem#getPart(int, Class) ContentItem.getPart}(uri,{@link Blob})
* that where parsed with the request.
+ * @deprecated use {@link RequestPropertiesHelper#PARSED_CONTENT_URIS} instead
*/
- public static final String PARSED_CONTENT_URIS = "stanbol.enhancer.web.parsedContentURIs";
+ public static final String PARSED_CONTENT_URIS = RequestPropertiesHelper.PARSED_CONTENT_URIS;
/**
* Inits (get or creates) the content part holding the EnhancementProperties
* @param ci the contentItem MUST NOT be NULL
* @return the enhancement properties
* @throws IllegalArgumentException if <code>null</code> is parsed as {@link ContentItem}.
- * @see ContentItemHelper#initEnhancementPropertiesContentPart(ContentItem)
+ * @see ContentItemHelper#initRequestPropertiesContentPart(ContentItem)
+ * @deprecated use {@link ContentItemHelper#initRequestPropertiesContentPart(ContentItem)}
+ * or {@link ContentItemHelper#getRequestPropertiesContentPart(ContentItem)}
+ * instead
*/
public static Map<String,Object> getEnhancementProperties(ContentItem ci){
- return ContentItemHelper.initEnhancementPropertiesContentPart(ci);
+ return ContentItemHelper.initRequestPropertiesContentPart(ci);
}
-
- private static Object get(Map<String,Object> enhancementProperties,String key){
- return enhancementProperties == null ? null : enhancementProperties.get(key);
- }
/**
* Getter for the value of the parsed type for a given key.
- * @param enhancementProperties the enhancement properties
+ * @param reqProp the request properties
* @param key the key
* @param type the type MUST NOT be <code>null</code>
* @return the values
* @throws ClassCastException if the value is not compatible to the
* parsed type
+ * @deprecated use {@link RequestPropertiesHelper#get(Map, String, Class)} instead
*/
@SuppressWarnings("unchecked")
- public static <T> T get(Map<String,Object> enhancementProperties,String key,Class<T> type){
- if(type == null){
- throw new IllegalArgumentException("The parsed type MUST NOT be NULL!");
- }
- Object value = get(enhancementProperties, key);
- if(value == null){
- return null;
- } else if(type.isAssignableFrom(value.getClass())){
- return (T)value;
- } else {
- throw new ClassCastException("EnhancementProperties value for key '"
- + key +"' is not of the expected type "+type+" but was"
- + value.getClass());
- }
+ public static <T> T get(Map<String,Object> reqProp,String key,Class<T> type){
+ return RequestPropertiesHelper.get(reqProp, key, type);
}
/**
* Getter for the boolean state based on the value of the parsed key.
* If the value is not of type {@link Boolean} the
* {@link Boolean#parseBoolean(String)} is used on the {@link Object#toString()}
* method of the value.
- * @param enhancementProperties the enhancementProperties
+ * @param reqProp the request properties
* @param key the key
* @return the state
+ * @deprecated use {@link RequestPropertiesHelper#getState(Map, String)} instead
*/
- public static boolean getState(Map<String,Object> enhancementProperties,String key){
- Object state = get(enhancementProperties, key);
- return state == null ? false :
- state instanceof Boolean ? ((Boolean)state).booleanValue() :
- Boolean.parseBoolean(state.toString());
+ public static boolean getState(Map<String,Object> reqProp,String key){
+ return RequestPropertiesHelper.getState(reqProp, key);
}
- public static boolean isOmitParsedContent(Map<String,Object> enhancementProperties){
- return getState(enhancementProperties, OMIT_PARSED_CONTENT);
+ /**
+ * Checks the request properties for the {@link #OMIT_PARSED_CONTENT} state
+ * @deprecated use {@link RequestPropertiesHelper#isOmitParsedContent(Map)} instead
+ */
+ public static boolean isOmitParsedContent(Map<String,Object> reqProp){
+ return RequestPropertiesHelper.isOmitParsedContent(reqProp);
}
- public static boolean isIncludeExecutionMetadata(Map<String,Object> enhancementProperties){
- return getState(enhancementProperties, INCLUDE_EXECUTION_METADATA);
+ /**
+ * Checks the request properties for the {@link #INCLUDE_EXECUTION_METADATA} state
+ * @deprecated use {@link RequestPropertiesHelper#isIncludeExecutionMetadata(Map)} instead
+ */
+ public static boolean isIncludeExecutionMetadata(Map<String,Object> reqProp){
+ return RequestPropertiesHelper.isIncludeExecutionMetadata(reqProp);
}
- public static boolean isOmitMetadata(Map<String,Object> enhancementProperties){
- return getState(enhancementProperties, OMIT_METADATA);
+ /**
+ * Checks the request properties for the {@link #OMIT_METADATA} state
+ * @deprecated use {@link RequestPropertiesHelper#isOmitMetadata(Map)} instead
+ */
+ public static boolean isOmitMetadata(Map<String,Object> reqProp){
+ return RequestPropertiesHelper.isOmitMetadata(reqProp);
}
/**
*
- * @param enhancementProperties
+ * @param reqProp
* @return
* @throws ClassCastException if the value is not an Set
+ * @deprecated use {@link RequestPropertiesHelper#getParsedContentURIs(Map)} instead
*/
- @SuppressWarnings("unchecked")
- public static Collection<String> getParsedContentURIs(Map<String,Object> enhancementProperties){
- return (Collection<String>)get(enhancementProperties, PARSED_CONTENT_URIS, Collection.class);
+ public static Collection<String> getParsedContentURIs(Map<String,Object> reqProp){
+ return RequestPropertiesHelper.getParsedContentURIs(reqProp);
}
/**
*
- * @param enhancementProperties
+ * @param reqProp
* @return
* @throws ClassCastException if the value is not an {@link Set}
+ * @deprecated use {@link RequestPropertiesHelper#getOutputContentParts(Map)} instead
*/
- @SuppressWarnings("unchecked")
- public static Collection<String> getOutputContentParts(Map<String,Object> enhancementProperties){
- return (Collection<String>)get(enhancementProperties, OUTPUT_CONTENT_PART, Collection.class);
+ public static Collection<String> getOutputContentParts(Map<String,Object> reqProp){
+ return RequestPropertiesHelper.getOutputContentParts(reqProp);
}
/**
*
- * @param enhancementProperties
+ * @param reqProp
* @return
* @throws ClassCastException if the value is not an {@link Collections}
+ * @deprecated use {@link RequestPropertiesHelper#getOutputContent(Map)} instead
*/
- @SuppressWarnings("unchecked")
- public static Collection<String> getOutputContent(Map<String,Object> enhancementProperties){
- return (Collection<String>)get(enhancementProperties, OUTPUT_CONTENT, Collection.class);
+ public static Collection<String> getOutputContent(Map<String,Object> reqProp){
+ return RequestPropertiesHelper.getOutputContent(reqProp);
}
/**
*
- * @param enhancementProperties
+ * @param reqProp
* @return
* @throws ClassCastException if the value is not an {@link Collections}
+ * @deprecated use {@link RequestPropertiesHelper#getRdfFormat(Map)} instead
*/
- public static String getRdfFormat(Map<String,Object> enhancementProperties){
- return get(enhancementProperties,RDF_FORMAT,String.class);
+ public static String getRdfFormat(Map<String,Object> reqProp){
+ return RequestPropertiesHelper.getRdfFormat(reqProp);
}
}
\ No newline at end of file
Added: stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/utils/RequestPropertiesHelper.java
URL: http://svn.apache.org/viewvc/stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/utils/RequestPropertiesHelper.java?rev=1594490&view=auto
==============================================================================
--- stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/utils/RequestPropertiesHelper.java (added)
+++ stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/utils/RequestPropertiesHelper.java Wed May 14 07:02:20 2014
@@ -0,0 +1,214 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.stanbol.enhancer.jersey.utils;
+
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import javax.ws.rs.QueryParam;
+
+import org.apache.clerezza.rdf.core.TripleCollection;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.stanbol.enhancer.servicesapi.Blob;
+import org.apache.stanbol.enhancer.servicesapi.ContentItem;
+import org.apache.stanbol.enhancer.servicesapi.helper.ContentItemHelper;
+import org.apache.stanbol.enhancer.servicesapi.rdf.ExecutionMetadata;
+import org.apache.stanbol.enhancer.servicesapi.rdf.ExecutionPlan;
+
+/**
+ * Defines Constants and utilities for using request scoped EnhancementProperties.
+ * Especially those internally used by the enhancer.jersey module.<p>
+ * This replaces the {@link EnhancementPropertiesHelper}
+ * @since 0.12.1
+ */
+public final class RequestPropertiesHelper {
+
+ private RequestPropertiesHelper(){/* no instances allowed*/}
+ /**
+ * @see ContentItemHelper#ENHANCEMENT_PROPERTIES_URI
+ */
+ public static final UriRef ENHANCEMENT_PROPERTIES_URI =
+ ContentItemHelper.ENHANCEMENT_PROPERTIES_URI;
+ /**
+ * Boolean switch parsed as {@link QueryParam} tha allows to deactivate the
+ * inclusion of the {@link ContentItem#getMetadata()} in the Response
+ */
+ public static final String OMIT_METADATA = "stanbol.enhancer.web.omitMetadata";
+ /**
+ * {@link Set Set<String>} containing all the URIs of the
+ * {@link ContentItem#getPart(UriRef, Class) ContentParts} representing
+ * RDF data (compatible to Clerezza {@link TripleCollection}). If the
+ * returned set contains '*' than all such content parts need to be returned.<p>
+ * NOTE: This can also be used to include the Request Properties
+ * as "applciation/json" in the Response by adding this
+ * {@link RequestPropertiesHelper#ENHANCEMENT_PROPERTIES_URI uri}.
+ */
+ public static final String OUTPUT_CONTENT_PART = "stanbol.enhancer.web.outputContentPart";
+ /**
+ * Allows to omit all parsed content parts regardless of the {@link #OUTPUT_CONTENT_PART}
+ * configuration
+ */
+ public static final String OMIT_PARSED_CONTENT = "stanbol.enhancer.web.omitParsed";
+ /**
+ * {@link Collection Collection<String>} containing mime types. This
+ * allows to specify what versions of the parsed content to be included in
+ * the response. e.g. ["text/*","application/pdf"] would include all text
+ * formats and PDF.
+ */
+ public static final String OUTPUT_CONTENT = "stanbol.enhancer.web.outputContent";
+ /**
+ * This allows to copy the {@link ExecutionMetadata} and {@link ExecutionPlan}
+ * data stored in a {@link ContentItem#getPart(UriRef, Class) contentPart} with
+ * the URI {@link ExecutionMetadata#CHAIN_EXECUTION} over to the
+ * {@link ContentItem#getMetadata() metadata} of the content item.<p>
+ * This feature is intended to allow users to retrieve such meta information
+ * without the need to use parse Multipart MIME responses.
+ */
+ public static final String INCLUDE_EXECUTION_METADATA = "stanbol.enhancer.web.executionmetadata";
+ /**
+ * The used format to encode RDF graphs for "multipart/*" responses. This
+ * needs to be parsed separately, because the Accept header needs to be
+ * set to "multipart/from-data" in such cases
+ */
+ public static final String RDF_FORMAT = "stanbol.enhancer.web.rdfFormat";
+ /**
+ * {@link Set Set<String>} containing all the {@link UriRef}s of
+ * {@link ContentItem#getPart(int, Class) ContentItem.getPart}(uri,{@link Blob})
+ * that where parsed with the request.
+ */
+ public static final String PARSED_CONTENT_URIS = "stanbol.enhancer.web.parsedContentURIs";
+
+ private static Object get(Map<String,Object> reqProp,String key){
+ return reqProp == null ? null : reqProp.get(key);
+ }
+ /**
+ * Getter for the value of the parsed type for a given key.
+ * @param reqProp the request properties
+ * @param key the key
+ * @param type the type MUST NOT be <code>null</code>
+ * @return the values or <code>null</code> if the parsed request properties
+ * where <code>null</code> or the parsed key was not present.
+ * @throws ClassCastException if the value is not compatible to the
+ * parsed type
+ * @throws NullPointerException if the parsed key or type is <code>null</code>
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> T get(Map<String,Object> reqProp,String key,Class<T> type){
+ if(reqProp == null){
+ return null;
+ }
+ if(type == null){
+ throw new NullPointerException("The parsed type MUST NOT be NULL!");
+ }
+ if(key == null){
+ throw new NullPointerException("The parsed key MUST NOT be NULL!");
+ }
+ Object value = get(reqProp, key);
+ if(value == null){
+ return null;
+ } else if(type.isAssignableFrom(value.getClass())){
+ return (T)value;
+ } else {
+ throw new ClassCastException("RequestProperties value for key '"
+ + key +"' is not of the expected type "+type+" but was"
+ + value.getClass());
+ }
+ }
+ /**
+ * Getter for the boolean state based on the value of the parsed key.
+ * If the value is not of type {@link Boolean} the
+ * {@link Boolean#parseBoolean(String)} is used on the {@link Object#toString()}
+ * method of the value.
+ * @param reqProp the request properties
+ * @param key the key
+ * @return the state. <code>false</code> if the parsed request property
+ * map was <code>null</code> or the key was not present.
+ * @throw {@link NullPointerException} if <code>null</code> is parsed as key
+ */
+ public static boolean getState(Map<String,Object> reqProp,String key){
+ if(key == null){
+ throw new NullPointerException("The parsed key MUST NOT be NULL!");
+ }
+ if(reqProp == null){
+ return Boolean.FALSE;
+ } else {
+ Object state = get(reqProp, key);
+ return state == null ? false :
+ state instanceof Boolean ? ((Boolean)state).booleanValue() :
+ Boolean.parseBoolean(state.toString());
+ }
+ }
+ /**
+ * Checks the request properties for the {@link #OMIT_PARSED_CONTENT} state
+ */
+ public static boolean isOmitParsedContent(Map<String,Object> reqProp){
+ return getState(reqProp, OMIT_PARSED_CONTENT);
+ }
+ /**
+ * Checks the request properties for the {@link #INCLUDE_EXECUTION_METADATA} state
+ */
+ public static boolean isIncludeExecutionMetadata(Map<String,Object> reqProp){
+ return getState(reqProp, INCLUDE_EXECUTION_METADATA);
+ }
+ /**
+ * Checks the request properties for the {@link #OMIT_METADATA} state
+ */
+ public static boolean isOmitMetadata(Map<String,Object> reqProp){
+ return getState(reqProp, OMIT_METADATA);
+ }
+ /**
+ * Getter for the {@link #PARSED_CONTENT_URIS}
+ * @param reqProp
+ * @return
+ * @throws ClassCastException if the value is not a {@link Collection}
+ */
+ @SuppressWarnings("unchecked")
+ public static Collection<String> getParsedContentURIs(Map<String,Object> reqProp){
+ return (Collection<String>)get(reqProp, PARSED_CONTENT_URIS, Collection.class);
+ }
+ /**
+ * Getter for the {@link #OUTPUT_CONTENT_PART}
+ * @param reqProp
+ * @return
+ * @throws ClassCastException if the value is not an {@link Collection}
+ */
+ @SuppressWarnings("unchecked")
+ public static Collection<String> getOutputContentParts(Map<String,Object> reqProp){
+ return (Collection<String>)get(reqProp, OUTPUT_CONTENT_PART, Collection.class);
+ }
+ /**
+ * Getter for the {@link #OUTPUT_CONTENT}
+ * @param reqProp
+ * @return
+ * @throws ClassCastException if the value is not a {@link Collection}
+ */
+ @SuppressWarnings("unchecked")
+ public static Collection<String> getOutputContent(Map<String,Object> reqProp){
+ return (Collection<String>)get(reqProp, OUTPUT_CONTENT, Collection.class);
+ }
+ /**
+ * Getter for the {@link #RDF_FORMAT}
+ * @param reqProp
+ * @return
+ * @throws ClassCastException if the value is not a {@link String}
+ */
+ public static String getRdfFormat(Map<String,Object> reqProp){
+ return get(reqProp,RDF_FORMAT,String.class);
+ }
+}
\ No newline at end of file
Propchange: stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/utils/RequestPropertiesHelper.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/writers/ContentItemWriter.java
URL: http://svn.apache.org/viewvc/stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/writers/ContentItemWriter.java?rev=1594490&r1=1594489&r2=1594490&view=diff
==============================================================================
--- stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/writers/ContentItemWriter.java (original)
+++ stanbol/branches/release-0.12/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/writers/ContentItemWriter.java Wed May 14 07:02:20 2014
@@ -20,13 +20,13 @@ import static javax.ws.rs.core.MediaType
import static javax.ws.rs.core.MediaType.MULTIPART_FORM_DATA_TYPE;
import static javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE;
import static javax.ws.rs.core.MediaType.WILDCARD_TYPE;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.ENHANCEMENT_PROPERTIES_URI;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.getEnhancementProperties;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.getOutputContent;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.getOutputContentParts;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.getParsedContentURIs;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.isOmitMetadata;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.isOmitParsedContent;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.ENHANCEMENT_PROPERTIES_URI;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.getOutputContent;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.getOutputContentParts;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.getParsedContentURIs;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.getRdfFormat;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.isOmitMetadata;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.isOmitParsedContent;
import static org.apache.stanbol.enhancer.servicesapi.helper.ContentItemHelper.getBlob;
import static org.apache.stanbol.enhancer.servicesapi.helper.ContentItemHelper.getContentParts;
@@ -72,9 +72,9 @@ import org.apache.http.entity.mime.conte
import org.apache.http.entity.mime.content.ContentDescriptor;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.stanbol.commons.web.base.ContextHelper;
-import org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper;
import org.apache.stanbol.enhancer.servicesapi.Blob;
import org.apache.stanbol.enhancer.servicesapi.ContentItem;
+import org.apache.stanbol.enhancer.servicesapi.helper.ContentItemHelper;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
@@ -155,8 +155,8 @@ public class ContentItemWriter implement
OutputStream entityStream) throws IOException, WebApplicationException {
//(0) handle default dataType
- Map<String,Object> properties = getEnhancementProperties(ci);
- boolean omitMetadata = isOmitMetadata(properties);
+ Map<String,Object> reqProp = ContentItemHelper.getRequestPropertiesContentPart(ci);
+ boolean omitMetadata = isOmitMetadata(reqProp);
if(!MULTIPART.isCompatible(mediaType)){ //two possible cases
if(!omitMetadata){ // (1) just return the RDF data
//(1.a) Backward support for default dataType if no Accept header is set
@@ -218,7 +218,7 @@ public class ContentItemWriter implement
final String charsetName = mediaType.getParameters().get("charset");
final Charset charset = charsetName != null ? Charset.forName(charsetName) : UTF8;
MediaType rdfFormat;
- String rdfFormatString = EnhancementPropertiesHelper.getRdfFormat(properties);
+ String rdfFormatString = getRdfFormat(reqProp);
if(rdfFormatString == null || rdfFormatString.isEmpty()){
rdfFormat = DEFAULT_RDF_FORMAT;
} else {
@@ -245,14 +245,14 @@ public class ContentItemWriter implement
httpHeaders.putSingle(HttpHeaders.CONTENT_TYPE,contentType);
HttpMultipart entity = new HttpMultipart("from-data", charset ,CONTENT_ITEM_BOUNDARY);
//(2) serialising the metadata
- if(!isOmitMetadata(properties)){
+ if(!isOmitMetadata(reqProp)){
entity.addBodyPart(new FormBodyPart("metadata", new ClerezzaContentBody(
ci.getUri().getUnicodeString(), ci.getMetadata(),
rdfFormat)));
}
//(3) serialising the Content (Bloby)
//(3.a) Filter based on parameter
- List<Entry<UriRef,Blob>> includedBlobs = filterBlobs(ci, properties);
+ List<Entry<UriRef,Blob>> includedBlobs = filterBlobs(ci, reqProp);
//(3.b) Serialise the filtered
if(!includedBlobs.isEmpty()) {
HttpMultipart content = new HttpMultipart("alternate", UTF8 ,"contentParts");
@@ -263,19 +263,19 @@ public class ContentItemWriter implement
//add all the blobs
entity.addBodyPart(new FormBodyPart("content",new MultipartContentBody(content, null)));
} //else no content to include
- Set<String> includeContentParts = getIncludedContentPartURIs(properties);
+ Set<String> includeContentParts = getIncludedContentPartURIs(reqProp);
if(includeContentParts != null){
- //(4) serialise EnhancementProperties
+ //(4) serialise the Request Properties
if(includeContentParts.isEmpty() || includeContentParts.contains(
ENHANCEMENT_PROPERTIES_URI.getUnicodeString())) {
JSONObject object;
try {
- object = toJson(properties);
+ object = toJson(reqProp);
} catch (JSONException e) {
throw new WebApplicationException(e,
Response.status(Response.Status.INTERNAL_SERVER_ERROR)
- .entity("Unable to convert EnhancementProperties to " +
- "JSON (values : "+properties+")!").build());
+ .entity("Unable to convert Request Properties to " +
+ "JSON (values : "+reqProp+")!").build());
}
entity.addBodyPart(new FormBodyPart(
ENHANCEMENT_PROPERTIES_URI.getUnicodeString(),
Modified: stanbol/branches/release-0.12/enhancer/jersey/src/test/java/org/apache/stanbol/enhancer/jersey/ContentItemReaderWriterTest.java
URL: http://svn.apache.org/viewvc/stanbol/branches/release-0.12/enhancer/jersey/src/test/java/org/apache/stanbol/enhancer/jersey/ContentItemReaderWriterTest.java?rev=1594490&r1=1594489&r2=1594490&view=diff
==============================================================================
--- stanbol/branches/release-0.12/enhancer/jersey/src/test/java/org/apache/stanbol/enhancer/jersey/ContentItemReaderWriterTest.java (original)
+++ stanbol/branches/release-0.12/enhancer/jersey/src/test/java/org/apache/stanbol/enhancer/jersey/ContentItemReaderWriterTest.java Wed May 14 07:02:20 2014
@@ -16,14 +16,14 @@
*/
package org.apache.stanbol.enhancer.jersey;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.ENHANCEMENT_PROPERTIES_URI;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.OUTPUT_CONTENT;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.OUTPUT_CONTENT_PART;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.PARSED_CONTENT_URIS;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.RDF_FORMAT;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.getEnhancementProperties;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.getOutputContent;
-import static org.apache.stanbol.enhancer.jersey.utils.EnhancementPropertiesHelper.getParsedContentURIs;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.ENHANCEMENT_PROPERTIES_URI;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.OUTPUT_CONTENT;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.OUTPUT_CONTENT_PART;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.PARSED_CONTENT_URIS;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.RDF_FORMAT;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.getOutputContent;
+import static org.apache.stanbol.enhancer.jersey.utils.RequestPropertiesHelper.getParsedContentURIs;
+import static org.apache.stanbol.enhancer.servicesapi.helper.ContentItemHelper.initRequestPropertiesContentPart;
import static org.apache.stanbol.enhancer.servicesapi.helper.ExecutionMetadataHelper.initExecutionMetadata;
import static org.apache.stanbol.enhancer.servicesapi.helper.ExecutionMetadataHelper.initExecutionMetadataContentPart;
import static org.apache.stanbol.enhancer.servicesapi.helper.ExecutionPlanHelper.createExecutionPlan;
@@ -107,14 +107,14 @@ public class ContentItemReaderWriterTest
new UriRef("urn:test"), RDF.type, new UriRef("urn:types:Document")));
//mark the main content as parsed and also that all
//contents and contentparts should be included
- Map<String,Object> properties = getEnhancementProperties(contentItem);
+ Map<String,Object> properties = initRequestPropertiesContentPart(contentItem);
properties.put(PARSED_CONTENT_URIS, Collections.singleton(contentItem.getPartUri(0).getUnicodeString()));
properties.put(OUTPUT_CONTENT, Collections.singleton("*/*"));
properties.put(OUTPUT_CONTENT_PART, Collections.singleton("*"));
properties.put(RDF_FORMAT, "application/rdf+xml");
MGraph em = initExecutionMetadataContentPart(contentItem);
- NonLiteral ep = createExecutionPlan(em, "testChain");
- writeExecutionNode(em, ep, "testEngine", true, null);
+ NonLiteral ep = createExecutionPlan(em, "testChain",null);
+ writeExecutionNode(em, ep, "testEngine", true, null,null);
initExecutionMetadata(em, em, contentItem.getUri(), "testChain", false);
final Serializer serializer = new Serializer();
serializer.bindSerializingProvider(new JenaSerializerProvider());
@@ -239,10 +239,11 @@ public class ContentItemReaderWriterTest
assertNotNull(readExecutionMetadata);
assertEquals(executionMetadata.size(), readExecutionMetadata.size());
//validate EnhancemetnProperties
- Map<String,Object> properties = getEnhancementProperties(ci);
+ Map<String,Object> reqProp = ContentItemHelper.getRequestPropertiesContentPart(ci);
+ assertNotNull(reqProp);
//the parsed value MUST BE overridden by the two content parts parsed
- assertEquals(expectedParsedContentIds, getParsedContentURIs(properties));
- Collection<String> outputContent = getOutputContent(properties);
+ assertEquals(expectedParsedContentIds, getParsedContentURIs(reqProp));
+ Collection<String> outputContent = getOutputContent(reqProp);
assertEquals(1, outputContent.size());
assertEquals(outputContent.iterator().next(), "*/*");
Collection<String> outputContentPart = Collections.singleton("*");