Author: sinaci
Date: Wed Feb  1 14:55:53 2012
New Revision: 1239156

URL: http://svn.apache.org/viewvc?rev=1239156&view=rev
Log:
STANBOL-476

Removed the path "contenhub/store" from ContenItemResource by introducing a new 
parameter to its constructor.

Modified:
    
incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/StoreResource.java
    
incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ContentItemResource.java
    
incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/EnhancerRootResource.java

Modified: 
incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/StoreResource.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/StoreResource.java?rev=1239156&r1=1239155&r2=1239156&view=diff
==============================================================================
--- 
incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/StoreResource.java
 (original)
+++ 
incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/StoreResource.java
 Wed Feb  1 14:55:53 2012
@@ -192,7 +192,8 @@ public class StoreResource extends BaseS
         // handle smart redirection to browser view
         for (MediaType mt : headers.getAcceptableMediaTypes()) {
             if (mt.toString().startsWith(TEXT_HTML)) {
-                URI pageUri = 
uriInfo.getBaseUriBuilder().path("/contenthub/store/page").path(contentURI).build();
+                URI pageUri = 
uriInfo.getBaseUriBuilder().path("/contenthub/store/page").path(contentURI)
+                        .build();
                 return Response.temporaryRedirect(pageUri).build();
             }
         }
@@ -200,8 +201,8 @@ public class StoreResource extends BaseS
         // handle smart redirection to RDF metadata view
         for (MediaType mt : headers.getAcceptableMediaTypes()) {
             if (RDF_MEDIA_TYPES.contains(mt.toString())) {
-                URI metadataUri = 
uriInfo.getBaseUriBuilder().path("/contenthub/store/metadata").path(contentURI)
-                        .build();
+                URI metadataUri = 
uriInfo.getBaseUriBuilder().path("/contenthub/store/metadata")
+                        .path(contentURI).build();
                 return Response.temporaryRedirect(metadataUri).build();
             }
         }
@@ -226,7 +227,7 @@ public class StoreResource extends BaseS
     @Path("/download/{type}/{uri:.+}")
     public Response downloadContentItem(@PathParam(value = "type") String type,
                                         @PathParam(value = "uri") String 
contentURI) throws IOException,
-                                                                             
StoreException {
+                                                                               
     StoreException {
 
         ContentItem ci = solrStore.get(contentURI);
         if (ci == null) {
@@ -286,7 +287,7 @@ public class StoreResource extends BaseS
     @GET
     @Path("/metadata/{uri:.+}")
     public Response getContentItemMetaData(@PathParam(value = "uri") String 
contentURI) throws IOException,
-                                                                               
 StoreException {
+                                                                               
        StoreException {
         ContentItem ci = solrStore.get(contentURI);
         if (ci == null) {
             throw new WebApplicationException(404);
@@ -309,7 +310,8 @@ public class StoreResource extends BaseS
      */
     @GET
     @Path("/raw/{uri:.+}")
-    public Response getRawContent(@PathParam(value = "uri") String contentURI) 
throws IOException, StoreException {
+    public Response getRawContent(@PathParam(value = "uri") String contentURI) 
throws IOException,
+                                                                              
StoreException {
         ContentItem ci = solrStore.get(contentURI);
         if (ci == null) {
             throw new WebApplicationException(404);
@@ -386,8 +388,8 @@ public class StoreResource extends BaseS
      *            corresponding Solr schema includes the author field. Solr 
indexed can be created/adjusted
      *            through LDPath programs.
      * @param contentURI
-     *            URI for the content item. If not supplied, Contenthub 
automatically assigns a URI to the
-     *            content item.
+     *            URI for the content item if this post is an update action on 
an existing Content item.
+     *            Existing content item will first removed and a new URI will 
be assigned for the new content.
      * @param title
      *            The title for the content item. Titles can be used to 
present summary of the actual content.
      *            For example, search results are presented by showing the 
titles of resultant content items.
@@ -437,9 +439,9 @@ public class StoreResource extends BaseS
      *            "John Doe"}. Then, this constraint is added to the Solr and 
will be indexed if the
      *            corresponding Solr schema includes the author field. Solr 
indexed can be created/adjusted
      *            through LDPath programs.
-     * @param contentId
-     *            The unique ID for the content item. If not supplied, 
Contenthub automatically assigns an ID
-     *            to the content item.
+     * @param contentURI
+     *            URI for the content item if this post is an update action on 
an existing Content item.
+     *            Existing content item will first removed and a new URI will 
be assigned for the new content.
      * @param title
      *            The title for the content item. Titles can be used to 
present summary of the actual content.
      *            For example, search results are presented by showing the 
titles of resultant content items.
@@ -460,7 +462,7 @@ public class StoreResource extends BaseS
     public Response createContentItemFromForm(@FormDataParam("file") File file,
                                               @FormDataParam("file") 
FormDataContentDisposition disposition,
                                               @FormDataParam("constraints") 
String jsonCons,
-                                              @FormDataParam("contentId") 
String contentId,
+                                              @FormDataParam("uri") String 
contentURI,
                                               @FormDataParam("title") String 
title,
                                               @FormDataParam("ldprogram") 
String ldprogram,
                                               @Context HttpHeaders headers) 
throws URISyntaxException,
@@ -472,7 +474,7 @@ public class StoreResource extends BaseS
         if (jsonCons != null) {
             constraints = JSONUtils.convertToMap(jsonCons);
         }
-        return createContentItemFromForm(null, contentId, null, file, 
disposition, headers, constraints,
+        return createContentItemFromForm(null, contentURI, null, file, 
disposition, headers, constraints,
             title, ldprogram);
     }
 
@@ -481,8 +483,8 @@ public class StoreResource extends BaseS
      * HTTP PUT method to create a content item in Contenthub.
      * 
      * @param contentURI
-     *            URI for the content item. If not supplied, Contenthub 
automatically assigns an ID
-     *            to the content item.
+     *            URI for the content item. If not supplied, Contenthub 
automatically assigns an ID to the
+     *            content item.
      * @param data
      * @param headers
      * @return
@@ -581,7 +583,9 @@ public class StoreResource extends BaseS
 
     /**
      * HTTP DELETE method to delete a content item from Contenhub.
-     * @param contentURI URI of the content item to be deleted.
+     * 
+     * @param contentURI
+     *            URI of the content item to be deleted.
      * @return HTTP OK
      * @throws StoreException
      */
@@ -649,7 +653,8 @@ public class StoreResource extends BaseS
         if (ci == null) {
             throw new WebApplicationException(404);
         }
-        return new ContentItemResource(localId, ci, uriInfo, tcManager, 
serializer, servletContext);
+        return new ContentItemResource(localId, ci, uriInfo, 
uriInfo.getBaseUriBuilder().path(
+            "/contenthub/store"), tcManager, serializer, servletContext);
     }
 
     // Helper methods for HTML view

Modified: 
incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ContentItemResource.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ContentItemResource.java?rev=1239156&r1=1239155&r2=1239156&view=diff
==============================================================================
--- 
incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ContentItemResource.java
 (original)
+++ 
incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ContentItemResource.java
 Wed Feb  1 14:55:53 2012
@@ -60,6 +60,7 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
 import org.apache.clerezza.rdf.core.Language;
@@ -143,6 +144,7 @@ public class ContentItemResource extends
     public ContentItemResource(String localId,
                                ContentItem ci,
                                UriInfo uriInfo,
+                               UriBuilder uriBuilder,
                                TcManager tcManager,
                                Serializer serializer,
                                ServletContext servletContext) throws 
IOException {
@@ -154,7 +156,7 @@ public class ContentItemResource extends
         this.servletContext = servletContext;
 
         if (localId != null) {
-            URI rawURI = 
uriInfo.getBaseUriBuilder().path("/contenthub/store/raw").path(localId).build();
+            URI rawURI = uriBuilder.path("raw").path(localId).build();
             if (ci.getMimeType().equals("text/plain")) {
                 this.textContent = IOUtils.toString(ci.getStream(), "UTF-8");
             } else if (ci.getMimeType().startsWith("image/")) {
@@ -167,7 +169,7 @@ public class ContentItemResource extends
               }
             }
             this.downloadHref = rawURI;
-            this.metadataHref = 
uriInfo.getBaseUriBuilder().path("/contenthub/store/metadata").path(localId).build();
+            this.metadataHref = 
uriBuilder.path("metadata").path(localId).build();
         }
         defaultThumbnails.put(DBPEDIA_PERSON, getStaticRootUrl() + 
"/home/images/user_48.png");
         defaultThumbnails.put(DBPEDIA_ORGANISATION, getStaticRootUrl() + 
"/home/images/organization_48.png");

Modified: 
incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/EnhancerRootResource.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/EnhancerRootResource.java?rev=1239156&r1=1239155&r2=1239156&view=diff
==============================================================================
--- 
incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/EnhancerRootResource.java
 (original)
+++ 
incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/EnhancerRootResource.java
 Wed Feb  1 14:55:53 2012
@@ -1,26 +1,25 @@
 /*
-* 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.
-*/
+ * 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.resource;
 
 import static javax.ws.rs.core.MediaType.APPLICATION_FORM_URLENCODED;
 import static javax.ws.rs.core.MediaType.TEXT_HTML;
 import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
 import static javax.ws.rs.core.MediaType.WILDCARD;
-import static 
org.apache.clerezza.rdf.core.serializedform.SupportedFormat.RDF_XML;
 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.commons.web.base.utils.MediaTypeUtil.SUPPORTED_RDF_TYPES;
@@ -37,10 +36,7 @@ import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
 import javax.servlet.ServletContext;
@@ -61,16 +57,13 @@ import javax.ws.rs.core.Response.Respons
 import org.apache.clerezza.rdf.core.Graph;
 import org.apache.clerezza.rdf.core.MGraph;
 import org.apache.clerezza.rdf.core.NonLiteral;
-import org.apache.clerezza.rdf.core.Triple;
 import org.apache.clerezza.rdf.core.TripleCollection;
 import org.apache.clerezza.rdf.core.UriRef;
 import org.apache.clerezza.rdf.core.access.TcManager;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
 import org.apache.clerezza.rdf.core.serializedform.Serializer;
 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.resource.EnhancerRootResource.ExecutionNode;
 import org.apache.stanbol.enhancer.servicesapi.Chain;
 import org.apache.stanbol.enhancer.servicesapi.ChainException;
 import org.apache.stanbol.enhancer.servicesapi.ChainManager;
@@ -120,7 +113,6 @@ public class EnhancerRootResource extend
 
     protected Serializer serializer;
 
-    
     public EnhancerRootResource(@Context ServletContext context) {
         // bind the job manager by looking it up from the servlet request 
context
         jobManager = 
ContextHelper.getServiceFromContext(EnhancementJobManager.class, context);
@@ -130,64 +122,66 @@ public class EnhancerRootResource extend
         engineManager = 
ContextHelper.getServiceFromContext(EnhancementEngineManager.class, context);
         chain = chainManager.getDefault();
     }
-    
+
     public URI getServiceUrl(){
         return uriInfo.getAbsolutePath();
     }
     
     @OPTIONS
-    public Response handleCorsPreflight(@Context HttpHeaders headers){
+    public Response handleCorsPreflight(@Context HttpHeaders headers) {
         ResponseBuilder res = Response.ok();
-        enableCORS(servletContext,res, headers);
+        enableCORS(servletContext, res, headers);
         return res.build();
     }
 
     @GET
     @Produces(TEXT_HTML)
     public Response get(@Context HttpHeaders headers) {
-        ResponseBuilder res = Response.ok(new Viewable("index", 
this),TEXT_HTML);
-        addCORSOrigin(servletContext,res, headers);
+        ResponseBuilder res = Response.ok(new Viewable("index", this), 
TEXT_HTML);
+        addCORSOrigin(servletContext, res, headers);
         return res.build();
     }
 
-    public boolean isEngineActive(String name){
+    public boolean isEngineActive(String name) {
         return engineManager.isEngine(name);
     }
-    
+
     /**
-     * Getter for the executionNodes 
+     * Getter for the executionNodes
+     * 
      * @return
      */
     public Set<ExecutionNode> getExecutionNodes() {
-        if(_executionNodes == null){
+        if (_executionNodes == null) {
             Graph ep;
             try {
                 ep = chain.getExecutionPlan();
             } catch (ChainException e) {
                 ep = null;
             }
-            if(ep != null){
+            if (ep != null) {
                 _executionNodes = new LinkedHashSet<ExecutionNode>();
                 Set<NonLiteral> processed = new HashSet<NonLiteral>();
                 Set<NonLiteral> next;
                 do {
                     next = ExecutionPlanHelper.getExecutable(ep, processed);
-                    for(NonLiteral node : next){
+                    for (NonLiteral node : next) {
                         _executionNodes.add(new ExecutionNode(ep, node));
                     }
                     processed.addAll(next);
-                } while(!next.isEmpty());
+                } while (!next.isEmpty());
             }
         }
         return _executionNodes;
     }
+
     public Set<ExecutionNode> getActiveNodes() {
-        if(_activeNodes == null){
+        if (_activeNodes == null) {
             Set<ExecutionNode> ens = getExecutionNodes();
-            if(ens != null){
+            if (ens != null) {
                 _activeNodes = new LinkedHashSet<ExecutionNode>();
-                for(ExecutionNode en : ens){
-                    if(en.isEngineActive()){
+                for (ExecutionNode en : ens) {
+                    if (en.isEngineActive()) {
                         _activeNodes.add(en);
                     }
                 }
@@ -195,45 +189,46 @@ public class EnhancerRootResource extend
         }
         return _activeNodes;
     }
-//    public EnhancementEngine getEngine(String name){
-//        return engineManager.getEngine(name);
-//    }
-//    public Map<String,EnhancementEngine> getActiveEngines() {
-//        Graph ep;
-//        try {
-//            ep = chain.getExecutionPlan();
-//        } catch (ChainException e) {
-//            return null;
-//        }
-//        Map<String,EnhancementEngine> active;
-//        if(ep != null){
-//            active = new HashMap<String,EnhancementEngine>();
-//            for(EnhancementEngine engine :  
ExecutionPlanHelper.getActiveEngines(engineManager, ep)){
-//                active.put(engine.getName(), engine);
-//            }
-//        } else {
-//            active = null;
-//        }
-//        return active;
-//    }
-    
-    public Chain getChain(){
+
+    // public EnhancementEngine getEngine(String name){
+    // return engineManager.getEngine(name);
+    // }
+    // public Map<String,EnhancementEngine> getActiveEngines() {
+    // Graph ep;
+    // try {
+    // ep = chain.getExecutionPlan();
+    // } catch (ChainException e) {
+    // return null;
+    // }
+    // Map<String,EnhancementEngine> active;
+    // if(ep != null){
+    // active = new HashMap<String,EnhancementEngine>();
+    // for(EnhancementEngine engine : 
ExecutionPlanHelper.getActiveEngines(engineManager, ep)){
+    // active.put(engine.getName(), engine);
+    // }
+    // } else {
+    // active = null;
+    // }
+    // return active;
+    // }
+
+    public Chain getChain() {
         return chain;
     }
 
-    public boolean isChainAvailable(){
+    public boolean isChainAvailable() {
         Set<ExecutionNode> nodes = getExecutionNodes();
-        if(nodes == null){
+        if (nodes == null) {
             return false;
         }
-        for(ExecutionNode node : getExecutionNodes()){
-            if(!node.isOptional() && ! node.isEngineActive()){
+        for (ExecutionNode node : getExecutionNodes()) {
+            if (!node.isOptional() && !node.isEngineActive()) {
                 return false;
             }
         }
         return true;
     }
-    
+
     public static String makeEngineId(EnhancementEngine engine) {
         // TODO: add a property on engines to provided custom local ids and 
make
         // this static method a method of the interface EnhancementEngine
@@ -303,20 +298,20 @@ public class EnhancerRootResource extend
                                                boolean inclExecMetadata ,
                                                boolean buildAjaxview) throws 
EnhancementException, IOException {
         if (jobManager != null) {
-            jobManager.enhanceContent(ci,chain);
+            jobManager.enhanceContent(ci, chain);
         }
 
         if (buildAjaxview) {
-            ContentItemResource contentItemResource = new 
ContentItemResource(null, ci, uriInfo, tcManager,
-                    serializer, servletContext);
+            ContentItemResource contentItemResource = new 
ContentItemResource(null, ci, uriInfo,
+                    uriInfo.getBaseUriBuilder(), tcManager, serializer, 
servletContext);
             contentItemResource.setRdfSerializationFormat(format);
             Viewable ajaxView = new Viewable("/ajax/contentitem", 
contentItemResource);
-            ResponseBuilder rb =  Response.ok(ajaxView);
-            rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML+"; charset=UTF-8");
-            addCORSOrigin(servletContext,rb, headers);
+            ResponseBuilder rb = Response.ok(ajaxView);
+            rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=UTF-8");
+            addCORSOrigin(servletContext, rb, headers);
             return rb.build();
         }
-        
+
         MGraph graph = ci.getMetadata();
         if(inclExecMetadata){
             try {
@@ -326,55 +321,59 @@ public class EnhancerRootResource extend
             }
         }
         ResponseBuilder rb = Response.ok(graph);
-        List<String> accepted = headers.getRequestHeader(HttpHeaders.ACCEPT);
-        MediaType mediaType = 
MediaTypeUtil.getAcceptableMediaType(headers,null);
-        //This can be used to create a customised WebExection. Jersey will sent
-        //a 500er response code in any case
-//        if(isAcceptableMediaType(mediaType, SUPPORTED_RDF_TYPES)){
-//           //USE THIS for special error response    
-//        }
+        // List<String> accepted = 
headers.getRequestHeader(HttpHeaders.ACCEPT);
+        MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, 
null);
+        // This can be used to create a customised WebExection. Jersey will 
sent
+        // a 500er response code in any case
+        // if(isAcceptableMediaType(mediaType, SUPPORTED_RDF_TYPES)){
+        // //USE THIS for special error response
+        // }
         if (mediaType != null) {
             rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
         }
-        
-        addCORSOrigin(servletContext,rb, headers);
+
+        addCORSOrigin(servletContext, rb, headers);
         return rb.build();
     }
 
     public class ExecutionNode {
-        
+
         private final NonLiteral node;
         private final TripleCollection ep;
         private final boolean optional;
         private final String engineName;
-        
+
         public ExecutionNode(TripleCollection executionPlan, NonLiteral node) {
             this.node = node;
             this.ep = executionPlan;
             this.optional = ExecutionPlanHelper.isOptional(ep, node);
             this.engineName = ExecutionPlanHelper.getEngine(ep, node);
         }
-        
+
         public boolean isOptional() {
             return optional;
         }
+
         public String getEngineName() {
             return engineName;
         }
-        
-        public EnhancementEngine getEngine(){
+
+        public EnhancementEngine getEngine() {
             return engineManager.getEngine(engineName);
         }
-        public boolean isEngineActive(){
+
+        public boolean isEngineActive() {
             return engineManager.isEngine(engineName);
         }
+
         @Override
         public int hashCode() {
             return node.hashCode();
         }
+
         @Override
         public boolean equals(Object o) {
-            return o instanceof ExecutionNode && 
((ExecutionNode)o).node.equals(node);
+            return o instanceof ExecutionNode && ((ExecutionNode) 
o).node.equals(node);
         }
     }
 


Reply via email to