Modified: incubator/stanbol/trunk/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/search/solr/SolrSearch.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/search/solr/SolrSearch.java?rev=1238518&r1=1238517&r2=1238518&view=diff ============================================================================== --- incubator/stanbol/trunk/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/search/solr/SolrSearch.java (original) +++ incubator/stanbol/trunk/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/search/solr/SolrSearch.java Tue Jan 31 13:43:54 2012 @@ -18,16 +18,64 @@ package org.apache.stanbol.contenthub.se import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.common.params.SolrParams; +import org.apache.stanbol.contenthub.servicesapi.ldpath.LDProgramManager; import org.apache.stanbol.contenthub.servicesapi.search.SearchException; +/** + * Apache Solr based search interface of Stanbol Contenthub. It makes use of SolrJ API in the provided + * services such that it is possible to provide queries passed in {@link SolrParams} and response are returned + * in the form of {@link QueryResponse}s. This interface also allows querying different Solr cores which are + * created based on the LDPath programs submitted through the {@link LDProgramManager}. + * + * @author anil.sinaci + * + */ public interface SolrSearch { + /** + * Queries the default Solr core of Contenthub with the given <code>queryTerm</code>. + * + * @param queryTerm + * Query term to be searched + * @return the {@link QueryResponse} as is obtained from Solr. + * @throws SearchException + */ QueryResponse search(String queryTerm) throws SearchException; - + + /** + * Queries the Solr core corresponding to the given <code>ldProgramName</code> of Contenthub with the + * given <code>queryTerm</code>. + * + * @param queryTerm + * Query term to be searched + * @param ldProgramName + * LDPath program name to obtain the corresponding Solr core to be searched + * @return the {@link QueryResponse} as is obtained from Solr. + * @throws SearchException + */ QueryResponse search(String queryTerm, String ldProgramName) throws SearchException; - + + /** + * Executes the given <code>solrQuery</code> on the default Solr core of Contenthub. + * + * @param solrQuery + * {@link SolrParams} to be executed + * @return the {@link QueryResponse} as is obtained from Solr. + * @throws SearchException + */ QueryResponse search(SolrParams solrQuery) throws SearchException; - + + /** + * Executes the given <code>solrQuery</code> on the Solr core corresponding to the given + * <code>ldProgramName</code> of Contenthub. + * + * @param solrQuery + * {@link SolrParams} to be executed + * @param ldProgramName + * LDPath program name to obtain the corresponding Solr core to be searched + * @return the {@link QueryResponse} as is obtained from Solr. + * @throws SearchException + */ QueryResponse search(SolrParams solrQuery, String ldProgramName) throws SearchException; - + }
Modified: incubator/stanbol/trunk/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/store/StoreException.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/store/StoreException.java?rev=1238518&r1=1238517&r2=1238518&view=diff ============================================================================== --- incubator/stanbol/trunk/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/store/StoreException.java (original) +++ incubator/stanbol/trunk/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/store/StoreException.java Tue Jan 31 13:43:54 2012 @@ -16,7 +16,7 @@ */ package org.apache.stanbol.contenthub.servicesapi.store; -import org.apache.stanbol.contenthub.servicesapi.AbstractContenthubException; +import org.apache.stanbol.contenthub.servicesapi.exception.AbstractContenthubException; /** * @author anil.sinaci Modified: incubator/stanbol/trunk/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/store/solr/SolrStore.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/store/solr/SolrStore.java?rev=1238518&r1=1238517&r2=1238518&view=diff ============================================================================== --- incubator/stanbol/trunk/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/store/solr/SolrStore.java (original) +++ incubator/stanbol/trunk/contenthub/servicesapi/src/main/java/org/apache/stanbol/contenthub/servicesapi/store/solr/SolrStore.java Tue Jan 31 13:43:54 2012 @@ -59,37 +59,95 @@ public interface SolrStore extends Store /** * Sends the {@link SolrContentItem} to the {@link EnhancementJobManager} to enhance the content. - * Afterwards saves the item to Solr. + * Afterwards saves the item in the default Solr core of the Contenthub. * * @param sci * The {@link SolrContentItem} to be enhanced and saved. * @return The unique ID of the {@link SolrContentItem}. + * @throws StoreException */ String enhanceAndPut(SolrContentItem sci) throws StoreException; + /** + * Sends the {@link SolrContentItem} to the {@link EnhancementJobManager} to enhance the content. + * Afterwards saves the item in the Solr core corresponding to the given <code>ldProgramName</code>. + * + * @param sci + * The {@link SolrContentItem} to be enhanced and saved + * @param ldProgramName + * LDPath program name to obtain the corresponding Solr core to store the content item + * @return The unique ID of the {@link SolrContentItem}. + * @throws StoreException + */ String enhanceAndPut(SolrContentItem sci, String ldProgramName) throws StoreException; + /** + * Stores the passed {@link SolrContentItem} in the Solr core corresponding to the specified + * <code>ldProgramName</code>. If <code>null</code> is passed as the LDPath program name, the default Solr + * core of Contenthub is used. + * + * @param ci + * {@link SolrContentItem} to be stored + * @param ldProgramName + * LDPath program name to obtain the corresponding Solr core to store the content item + * @return The unique ID of the {@link SolrContentItem}. + * @throws StoreException + */ String put(SolrContentItem ci, String ldProgramName) throws StoreException; + /** + * Retrieves the {@link SolrContentItem} from the Solr core corresponding to the specified + * <code>ldProgramName</code>. If <code>null</code> is passed as the LDPath program name, the default Solr + * core of Contenthub is used. + * + * @param id + * The ID of {@link SolrContentItem} to be retrieved. + * @param ldProgramName + * LDPath program name to obtain the corresponding Solr core from which the content item will + * be retrieved + * @return {@link SolrContentItem} having the specified id + * @throws StoreException + */ SolrContentItem get(String id, String ldProgramName) throws StoreException; - + /** - * Deletes the {@link ContentItem} from the {@link SolrStore}. + * Deletes the {@link ContentItem} from the default Solr core of Contenthub. * * @param id * The ID of the item to be deleted. */ - void deleteById(String id) throws StoreException ; + void deleteById(String id) throws StoreException; - void deleteById(String id, String ldProgramName) throws StoreException ; + /** + * Deletes the {@link ContentItem} from the default Solr core corresponding to the given + * <code>ldProgramName</code> of the Contenthub. + * + * @param id + * The ID of the item to be deleted. + * @param ldProgramName + * LDPath program name to obtain the corresponding Solr core from which the content item will + * be deleted + * @throws StoreException + */ + void deleteById(String id, String ldProgramName) throws StoreException; /** - * Deletes the {@link ContentItem}s from the {@link SolrStore}. + * Deletes the {@link ContentItem}s from the default Solr core of Contenthub. * * @param id * The list of IDs of the items to be deleted. */ - void deleteById(List<String> idList) throws StoreException ; + void deleteById(List<String> idList) throws StoreException; - void deleteById(List<String> idList, String ldProgramName) throws StoreException ; + /** + * Deletes the {@link ContentItem}s from the Solr core corresponding to the given + * <code>ldProgramName</code>. + * + * @param idList + * The list of IDs of the items to be deleted. + * @param ldProgramName + * LDPath program name to obtain the corresponding Solr core from which the content items will + * be deleted + */ + void deleteById(List<String> idList, String ldProgramName) throws StoreException; } Modified: incubator/stanbol/trunk/contenthub/store/solr/src/main/java/org/apache/stanbol/contenthub/store/solr/SolrStoreImpl.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/store/solr/src/main/java/org/apache/stanbol/contenthub/store/solr/SolrStoreImpl.java?rev=1238518&r1=1238517&r2=1238518&view=diff ============================================================================== --- incubator/stanbol/trunk/contenthub/store/solr/src/main/java/org/apache/stanbol/contenthub/store/solr/SolrStoreImpl.java (original) +++ incubator/stanbol/trunk/contenthub/store/solr/src/main/java/org/apache/stanbol/contenthub/store/solr/SolrStoreImpl.java Tue Jan 31 13:43:54 2012 @@ -58,7 +58,6 @@ import org.apache.solr.common.SolrDocume import org.apache.solr.common.SolrInputDocument; import org.apache.stanbol.commons.solr.managed.ManagedSolrServer; import org.apache.stanbol.contenthub.servicesapi.Constants; -import org.apache.stanbol.contenthub.servicesapi.enhancements.vocabulary.EnhancementGraphVocabulary; import org.apache.stanbol.contenthub.servicesapi.ldpath.LDPathException; import org.apache.stanbol.contenthub.servicesapi.ldpath.LDProgramManager; import org.apache.stanbol.contenthub.servicesapi.store.StoreException; @@ -102,9 +101,9 @@ public class SolrStoreImpl implements So @Reference private LDProgramManager ldProgramManager; - + private BundleContext bundleContext; - + @Activate protected void activate(ComponentContext context) throws IllegalArgumentException, IOException, @@ -129,7 +128,7 @@ public class SolrStoreImpl implements So @Override public MGraph getEnhancementGraph() { - final UriRef graphUri = new UriRef(EnhancementGraphVocabulary.ENHANCEMENTS_GRAPH_URI); + final UriRef graphUri = new UriRef(Constants.ENHANCEMENTS_GRAPH_URI); MGraph enhancementGraph = null; try { enhancementGraph = tcManager.getMGraph(graphUri); @@ -271,7 +270,8 @@ public class SolrStoreImpl implements So @Override public String put(SolrContentItem sci, String ldProgramName) throws StoreException { - if(ldProgramName == null || ldProgramName.isEmpty() || ldProgramName.equals(SolrCoreManager.CONTENTHUB_SOLR_SERVER_NAME)) { + if (ldProgramName == null || ldProgramName.isEmpty() + || ldProgramName.equals(SolrCoreManager.CONTENTHUB_SOLR_SERVER_NAME)) { return put(sci); } SolrInputDocument doc = new SolrInputDocument(); @@ -328,12 +328,13 @@ public class SolrStoreImpl implements So } doc.addField(SolrFieldName.ENHANCEMENTCOUNT.toString(), enhancementCount); } - + private void addSolrSpecificFields(SolrContentItem sci, SolrInputDocument doc, String ldProgramName) { doc.addField(SolrFieldName.TITLE.toString(), sci.getTitle()); try { - Map<String,Collection<?>> results = ldProgramManager.executeProgram(ldProgramName, sci.getMetadata()); - for(Entry<String,Collection<?>> entry : results.entrySet()) { + Map<String,Collection<?>> results = ldProgramManager.executeProgram(ldProgramName, + sci.getMetadata()); + for (Entry<String,Collection<?>> entry : results.entrySet()) { doc.addField(entry.getKey(), entry.getValue()); } } catch (LDPathException e) { @@ -414,7 +415,8 @@ public class SolrStoreImpl implements So @Override public SolrContentItem get(String id, String ldProgramName) throws StoreException { id = ContentItemIDOrganizer.attachBaseURI(id); - SolrServer solrServer = SolrCoreManager.getInstance(bundleContext, managedSolrServer).getServer(ldProgramName); + SolrServer solrServer = SolrCoreManager.getInstance(bundleContext, managedSolrServer).getServer( + ldProgramName); String content = null; String mimeType = null; String title = null; Modified: incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/CNNImporterResource.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/CNNImporterResource.java?rev=1238518&r1=1238517&r2=1238518&view=diff ============================================================================== --- incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/CNNImporterResource.java (original) +++ incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/CNNImporterResource.java Tue Jan 31 13:43:54 2012 @@ -40,6 +40,7 @@ import org.apache.stanbol.contenthub.web import com.sun.jersey.api.view.Viewable; /** + * This is the web resource for CNN Crawler. * * @author cihan * @@ -73,12 +74,29 @@ public class CNNImporterResource extends return tn; } + /** + * For HTML view only. + * + * @return Returns the HTML view for CNN News Crawler. + */ @GET @Produces(TEXT_HTML) public Response importCNNNewsHTML() { return Response.ok(new Viewable("index", this), TEXT_HTML).build(); } + /** + * + * @param topic + * The topic which will be crawled. + * @param max + * Maximum number of news to be retrieved from CNN about the {@link topic} + * @param full + * If {@code yes}, the topic will be crawled in detail to retrieve all information from CNN + * about the {@link topic}. If {@code no}, only summary of the news will be crawled and + * imported. + * @return Returns the HTML view as the result of importing news from CNN. + */ @POST @Produces(TEXT_HTML) public Response importCNNNewsHTMLPOST(@FormParam("topic") String topic, Modified: incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/FeaturedSearchResource.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/FeaturedSearchResource.java?rev=1238518&r1=1238517&r2=1238518&view=diff ============================================================================== --- incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/FeaturedSearchResource.java (original) +++ incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/FeaturedSearchResource.java Tue Jan 31 13:43:54 2012 @@ -53,6 +53,7 @@ import org.apache.stanbol.contenthub.ser import org.apache.stanbol.contenthub.servicesapi.search.SearchException; import org.apache.stanbol.contenthub.servicesapi.search.featured.FeaturedSearch; import org.apache.stanbol.contenthub.servicesapi.search.featured.SearchResult; +import org.apache.stanbol.contenthub.servicesapi.search.related.RelatedKeywordSearchManager; import org.apache.stanbol.contenthub.web.util.JSONUtils; import org.apache.stanbol.contenthub.web.util.RestUtil; import org.osgi.framework.InvalidSyntaxException; @@ -62,6 +63,8 @@ import org.slf4j.LoggerFactory; import com.sun.jersey.api.view.Viewable; /** + * This class is the web resource which provides RESTful and HTTP interfaces for {@link FeaturedSearch} + * services. * * @author anil.sinaci * @author suat @@ -81,6 +84,44 @@ public class FeaturedSearchResource exte tcManager = ContextHelper.getServiceFromContext(TcManager.class, context); } + /** + * HTTP POST method to make a featured search over Contenthub. This method directly calls the + * corresponding {{@link #get(String, String, String, String, String, int, int, String, HttpHeaders)} + * method of this class. + * + * @param queryTerm + * A keyword a statement or a set of keywords which can be regarded as the query term. + * @param solrQuery + * Solr query string. This is the string format which is accepted by a Solr server. For + * example, {@code q="john doe"&fl=score} is a valid value for this parameter. If this + * parameter exists, search is performed based on this solrQuery and any queryTerms are + * neglected. + * @param ldProgram + * The name of the LDPath program (actually name of the Solr core/index) to be searched over. + * @param jsonCons + * Constrainst in JSON format. These constraints are tranformed to corresponding Solr queries + * to enable faceted search. Each constraint is a facet field and values of the constraints + * maps to the values of the facet fields in Solr queries. + * @param graphURI + * URI of the ontology in which related keywords will be searched by + * {@link RelatedKeywordSearchManager#getRelatedKeywordsFromOntology(String, String)} + * @param offset + * The offset of the document from which the resultant documents will start as the search + * result. {@link offset} and {@link limit} parameters can be used to make a pagination + * mechanism for search results. + * @param limit + * Maximum number of resultant documents to be returned as the search result. {@link offset} + * and {@link limit} parameters can be used to make a pagination mechanism for search results. + * @param headers + * HTTP headers + * @return + * @throws IllegalArgumentException + * @throws InstantiationException + * @throws IllegalAccessException + * @throws SolrServerException + * @throws SearchException + * @throws IOException + */ @POST @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @@ -100,6 +141,44 @@ public class FeaturedSearchResource exte return get(queryTerm, solrQuery, ldProgram, jsonCons, graphURI, offset, limit, null, headers); } + /** + * HTTP GET method to make a featured search over Contenthub. + * + * @param queryTerm + * A keyword a statement or a set of keywords which can be regarded as the query term. + * @param solrQuery + * Solr query string. This is the string format which is accepted by a Solr server. For + * example, {@code q="john doe"&fl=score} is a valid value for this parameter. If this + * parameter exists, search is performed based on this solrQuery and any queryTerms are + * neglected. + * @param ldProgram + * The name of the LDPath program (actually name of the Solr core/index) to be searched over. + * @param jsonCons + * Constrainst in JSON format. These constraints are tranformed to corresponding Solr queries + * to enable faceted search. Each constraint is a facet field and values of the constraints + * maps to the values of the facet fields in Solr queries. + * @param graphURI + * URI of the ontology in which related keywords will be searched by + * {@link RelatedKeywordSearchManager#getRelatedKeywordsFromOntology(String, String)} + * @param offset + * The offset of the document from which the resultant documents will start as the search + * result. {@link offset} and {@link limit} parameters can be used to make a pagination + * mechanism for search results. + * @param limit + * Maximum number of resultant documents to be returned as the search result. {@link offset} + * and {@link limit} parameters can be used to make a pagination mechanism for search results. + * @param fromStore + * Special parameter for HTML view only. + * @param headers + * HTTP headers + * @return HTML view or JSON representation of the search results or HTTP BAD REQUEST(400) + * @throws IllegalArgumentException + * @throws SearchException + * @throws InstantiationException + * @throws IllegalAccessException + * @throws SolrServerException + * @throws IOException + */ @GET @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON}) public final Response get(@QueryParam("queryTerm") String queryTerm, @@ -127,7 +206,7 @@ public class FeaturedSearchResource exte this.pageSize = limit; if (acceptedHeader.isCompatible(MediaType.TEXT_HTML_TYPE)) { - if(fromStore != null) { + if (fromStore != null) { return Response.ok(new Viewable("index", this), MediaType.TEXT_HTML).build(); } if (queryTerm == null && solrQuery == null) { @@ -175,7 +254,7 @@ public class FeaturedSearchResource exte } else if (queryTerm != null) { Map<String,List<Object>> constraintsMap = JSONUtils.convertToMap(jsonCons); this.chosenFacets = JSONUtils.convertToString(constraintsMap); - List<String> allAvailableFacetNames = featuredSearch.getFacetNames(ldProgramName); + List<String> allAvailableFacetNames = featuredSearch.getFieldNames(ldProgramName); if (this.chosenFacets != null) { SolrQuery sq = SolrQueryUtil.prepareFacetedSolrQuery(queryTerm, allAvailableFacetNames, constraintsMap); @@ -213,9 +292,9 @@ public class FeaturedSearchResource exte // Data holders for HTML view private List<String> ontologies = null; private String queryTerm = null; -// private String solrQuery = null; -// private String ldProgram = null; -// private String graphURI = null; + // private String solrQuery = null; + // private String ldProgram = null; + // private String graphURI = null; private SearchResult searchResults = null; private String chosenFacets = null; private int offset = 0; @@ -226,7 +305,7 @@ public class FeaturedSearchResource exte /* * Helper methods for HTML view */ - + public Object getMoreRecentItems() { if (offset >= pageSize) { return new Object(); @@ -242,11 +321,11 @@ public class FeaturedSearchResource exte return new Object(); } } - + public int getOffset() { return this.offset; } - + public int getPageSize() { return this.pageSize; } @@ -254,7 +333,7 @@ public class FeaturedSearchResource exte public Object getSearchResults() { return this.searchResults; } - + public Object getResultantDocuments() { if (searchResults.getResultantDocuments().size() > pageSize) { return searchResults.getResultantDocuments().subList(0, pageSize); Modified: incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/LDProgramManagerResource.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/LDProgramManagerResource.java?rev=1238518&r1=1238517&r2=1238518&view=diff ============================================================================== --- incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/LDProgramManagerResource.java (original) +++ incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/LDProgramManagerResource.java Tue Jan 31 13:43:54 2012 @@ -47,6 +47,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** + * This class the the web resource to handle the RESTful requests and HTML view of the LDProgram management + * facilities within Contenthub. + * * @author anil.pacaci * @author anil.sinaci * @@ -73,7 +76,7 @@ public class LDProgramManagerResource ex enableCORS(servletContext, res, headers); return res.build(); } - + @OPTIONS @Path("/program") public Response handleCorsPreflightProgram(@Context HttpHeaders headers) { @@ -81,7 +84,7 @@ public class LDProgramManagerResource ex enableCORS(servletContext, res, headers); return res.build(); } - + @OPTIONS @Path("/exists") public Response handleCorsPreflightExists(@Context HttpHeaders headers) { @@ -89,7 +92,16 @@ public class LDProgramManagerResource ex enableCORS(servletContext, res, headers); return res.build(); } - + + /** + * HTTP GET method which returns all LDPath programs residing in Contenthub. LDPath programs are uniquely + * identified by their names. Returning JSON string presents each LDPath program in string format aligned + * with its name. + * + * @param headers + * HTTP headers + * @return JSON string of {@code name:program} pairs. + */ @GET @Produces(APPLICATION_JSON) public Response retrieveAllPrograms(@Context HttpHeaders headers) { @@ -99,6 +111,18 @@ public class LDProgramManagerResource ex return rb.build(); } + /** + * HTTP POST method which saves an LDPath program into the persistent store of Contenthub. + * + * @param programName + * Unique name to identify the LDPath program + * @param program + * The LDPath program. + * @param headers + * HTTP Headers + * @return HTTP OK(200) or BAD REQUEST(400) + * @throws LDPathException + */ @POST @Path("/program") @Consumes(APPLICATION_FORM_URLENCODED) @@ -117,7 +141,16 @@ public class LDProgramManagerResource ex addCORSOrigin(servletContext, rb, headers); return rb.build(); } - + + /** + * HTTP GET method to retrieve an LDPath program, given its name. + * + * @param programName + * The name of the LDPath program to be retrieved. + * @param headers + * HTTP headers + * @return LDPath program in {@link String} format or HTTP NOT FOUND(404) + */ @GET @Path("/program") public Response getProgramByName(@QueryParam("name") String programName, @Context HttpHeaders headers) { @@ -130,7 +163,16 @@ public class LDProgramManagerResource ex return rb.build(); } } - + + /** + * HTTP DELETE method to delete an LDPath program. + * + * @param programName + * The name of the LDPath program. + * @param headers + * HTTP headers + * @return HTTP OK(200) + */ @DELETE @Path("/program") @Consumes(APPLICATION_FORM_URLENCODED) @@ -141,6 +183,15 @@ public class LDProgramManagerResource ex return rb.build(); } + /** + * HTTP GET method to check whether an LDPath program exists in Contenthub or not. + * + * @param programName + * The name of the LDPath program. + * @param headers + * HTTP headers + * @return HTTP OK(200) or HTTP NOT FOUND(404) + */ @GET @Path("/exists") public Response isManagedProgram(@QueryParam("name") String programName, @Context HttpHeaders headers) { @@ -154,5 +205,5 @@ public class LDProgramManagerResource ex return rb.build(); } } - + } Modified: incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/RelatedKeywordResource.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/RelatedKeywordResource.java?rev=1238518&r1=1238517&r2=1238518&view=diff ============================================================================== --- incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/RelatedKeywordResource.java (original) +++ incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/RelatedKeywordResource.java Tue Jan 31 13:43:54 2012 @@ -42,6 +42,7 @@ import org.apache.stanbol.contenthub.ser import org.apache.stanbol.contenthub.servicesapi.search.featured.SearchResult; import org.apache.stanbol.contenthub.servicesapi.search.related.RelatedKeywordSearchManager; import org.apache.stanbol.contenthub.web.util.RestUtil; +import org.apache.stanbol.contenthub.web.writers.SearchResultWriter; import org.apache.stanbol.entityhub.core.query.DefaultQueryFactory; import org.apache.stanbol.entityhub.servicesapi.model.Representation; import org.apache.stanbol.entityhub.servicesapi.query.FieldQuery; @@ -54,6 +55,13 @@ import org.codehaus.jettison.json.JSONOb import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * This is the web resourceclass which implements the search functionality of Contenthub to look for related + * keywords, given a keyword. + * + * @author anil.sinaci + * + */ @Path("/contenthub/search/related") public class RelatedKeywordResource extends BaseStanbolResource { @@ -73,6 +81,22 @@ public class RelatedKeywordResource exte context); } + /** + * HTTP GET method to retrieve related keywords from all resources defined within Contenthub. + * + * @param keyword + * The keyword whose related keywords will be retrieved. + * @param ontologyURI + * URI of the ontology to be used during the step in which related keywords are searched in + * ontology resources. If this parameter is {@code null}, then no related keywords are returned + * from ontology resources. + * @param headers + * HTTP headers + * @return JSON string which is constructed by {@link SearchResultWriter}. {@link SearchResult} returned + * by {@link RelatedKeywordSearchManager#getRelatedKeywordsFromAllSources(String, String)} only contains related keywords (no resultant documents + * or facet fields are returned within the {@link SearchResult}). + * @throws SearchException + */ @GET @Produces(MediaType.APPLICATION_JSON) public final Response findAllRelatedKeywords(@QueryParam("keyword") String keyword, @@ -97,6 +121,19 @@ public class RelatedKeywordResource exte return prepareResponse(searchResult, headers); } + /** + * HTTP GET method to retrieve related keywords from Wordnet. If a Wordnet database is not installed into + * Contenthub, this method cannot find any related keywords. + * + * @param keyword + * The keyword whose related keywords will be retrieved from Wordnet. + * @param headers + * HTTP headers + * @return JSON string which is constructed by {@link SearchResultWriter}. {@link SearchResult} returned + * by {@link RelatedKeywordSearchManager#getRelatedKeywordsFromWordnet(String)} contains only related keywords from Wordnet. (No + * resultant documents or facet fields are returned within the {@link SearchResult}). + * @throws SearchException + */ @GET @Produces(MediaType.APPLICATION_JSON) @Path("/wordnet") @@ -117,6 +154,22 @@ public class RelatedKeywordResource exte return prepareResponse(searchResult, headers); } + /** + * HTTP GET method to retrieve related keywords from ontology resources. Given the ontology URI, this + * method looks for subsumption/hierarchy relations among the concepts to come up with related keywords. + * + * @param keyword + * The keyword whose related keywords will be retrieved from ontology resources. + * @param ontologyURI + * URI of the ontology in which related keywords will be searched. The ontology should be + * available in the Contenthub system. + * @param headers + * HTTP headers + * @return JSON string which is constructed by {@link SearchResultWriter}. {@link SearchResult} returned + * by {@link RelatedKeywordSearchManager#getRelatedKeywordsFromOntology(String, String)} contains only related keywords from ontology resources. + * (No resultant documents or facet fields are returned within the {@link SearchResult}). + * @throws SearchException + */ @GET @Produces(MediaType.APPLICATION_JSON) @Path("/ontology") @@ -146,6 +199,20 @@ public class RelatedKeywordResource exte return prepareResponse(searchResult, headers); } + /** + * + * HTTP GET method to retrieve related keywords from the referenced sites. + * + * @param keyword + * The keyword whose related keywords will be retrieved from referenced sites. + * @param headers + * HTTP headers + * @return JSON string which is constructed by {@link SearchResultWriter}. {@link SearchResult} returned + * by {@link RelatedKeywordSearchManager#getRelatedKeywordsFromReferencedSites(String)} contains + * only related keywords from referenced sites. (No resultant documents or facet fields are + * returned within the {@link SearchResult}). + * @throws SearchException + */ @GET @Produces(MediaType.APPLICATION_JSON) @Path("/referencedsite") @@ -163,7 +230,7 @@ public class RelatedKeywordResource exte } SearchResult searchResult = relatedKeywordSearchManager - .getRelatedKeywordsFromReferencedCites(keyword); + .getRelatedKeywordsFromReferencedSites(keyword); return prepareResponse(searchResult, headers); } @@ -175,6 +242,7 @@ public class RelatedKeywordResource exte } /** + * TODO: Not completed yet. * This method is used to provide data to autocomplete component. It queries entityhub with the provided * query term. */ Modified: incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/RootResource.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/RootResource.java?rev=1238518&r1=1238517&r2=1238518&view=diff ============================================================================== --- incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/RootResource.java (original) +++ incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/RootResource.java Tue Jan 31 13:43:54 2012 @@ -25,6 +25,12 @@ import javax.ws.rs.core.Response; import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource; +/** + * Base resource which automatically redirects to "contenthub/store" + * + * @author anil.sinaci + * + */ @Path("/contenthub") public class RootResource extends BaseStanbolResource { 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=1238518&r1=1238517&r2=1238518&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 Tue Jan 31 13:43:54 2012 @@ -82,6 +82,7 @@ import org.apache.stanbol.commons.web.ba import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource; import org.apache.stanbol.contenthub.search.featured.util.SolrContentItemConverter; import org.apache.stanbol.contenthub.search.solr.SolrSearchImpl; +import org.apache.stanbol.contenthub.servicesapi.ldpath.LDProgramManager; import org.apache.stanbol.contenthub.servicesapi.search.SearchException; import org.apache.stanbol.contenthub.servicesapi.search.featured.ResultantDocument; import org.apache.stanbol.contenthub.servicesapi.search.solr.SolrSearch; @@ -173,16 +174,17 @@ public class StoreResource extends BaseS /** * Cool URI handler for the uploaded resource. * - * @param localId - * the local id of the resource in the Stanbol Enhancer store + * @param contentURI + * The URI of the resource in the Stanbol Contenthub store * @param headers + * HTTP headers * @return a redirection to either a browser view, the RDF metadata or the raw binary content */ @GET - @Path("/content/{localId:.+}") - public Response getContent(@PathParam(value = "localId") String localId, @Context HttpHeaders headers) throws StoreException { + @Path("/content/{uri:.+}") + public Response getContent(@PathParam(value = "uri") String contentURI, @Context HttpHeaders headers) throws StoreException { - ContentItem ci = solrStore.get(localId); + ContentItem ci = solrStore.get(contentURI); if (ci == null) { throw new WebApplicationException(404); } @@ -190,8 +192,7 @@ 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(localId) - .build(); + URI pageUri = uriInfo.getBaseUriBuilder().path("/contenthub/store/page").path(contentURI).build(); return Response.temporaryRedirect(pageUri).build(); } } @@ -199,29 +200,42 @@ 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(localId).build(); + URI metadataUri = uriInfo.getBaseUriBuilder().path("/contenthub/store/metadata").path(contentURI) + .build(); return Response.temporaryRedirect(metadataUri).build(); } } - URI rawUri = uriInfo.getBaseUriBuilder().path("/contenthub/store/raw").path(localId).build(); + URI rawUri = uriInfo.getBaseUriBuilder().path("/contenthub/store/raw").path(contentURI).build(); return Response.temporaryRedirect(rawUri).build(); } + /** + * HTTP GET method specific for download operations. Raw data (content item) or only metadata of the + * content item can be downloaded. + * + * @param type + * Type can be {@code "metadata"} or {@code "raw"}. Based on the type, related parts of the + * content item will be prepared for download. + * @param contentURI + * URI of the resource in the Stanbol Contenthub store + * @return Raw content item or metadata of the content item. + * @throws IOException + * @throws StoreException + */ @GET - @Path("/download/{type}/{localId:.+}") + @Path("/download/{type}/{uri:.+}") public Response downloadContentItem(@PathParam(value = "type") String type, - @PathParam(value = "localId") String localId) throws IOException, - StoreException { + @PathParam(value = "uri") String contentURI) throws IOException, + StoreException { - ContentItem ci = solrStore.get(localId); + ContentItem ci = solrStore.get(contentURI); if (ci == null) { throw new WebApplicationException(404); } if (type.equals("metadata")) { ByteArrayOutputStream out = new ByteArrayOutputStream(); serializer.serialize(out, ci.getMetadata(), SupportedFormat.RDF_XML); - String fileName = localId + "-metadata"; + String fileName = contentURI + "-metadata"; File file = new File(fileName); boolean success = file.createNewFile(); if (success) { @@ -238,7 +252,7 @@ public class StoreResource extends BaseS return response.build(); } else if (type.equals("raw")) { // TODO: It is only for text content - String fileName = localId + "-raw"; + String fileName = contentURI + "-raw"; File file = new File(fileName); boolean success = file.createNewFile(); if (success) { @@ -259,11 +273,21 @@ public class StoreResource extends BaseS } + /** + * HTTP GET method to retrieve the metadata of the content item. Generally, metadata contains the + * enhancements of the content item. + * + * @param contentURI + * URI id of the resource in the Stanbol Contenthub store + * @return RDF representation of the metadata of the content item. + * @throws IOException + * @throws StoreException + */ @GET - @Path("/metadata/{localId:.+}") - public Response getContentItemMetaData(@PathParam(value = "localId") String localId) throws IOException, - StoreException { - ContentItem ci = solrStore.get(localId); + @Path("/metadata/{uri:.+}") + public Response getContentItemMetaData(@PathParam(value = "uri") String contentURI) throws IOException, + StoreException { + ContentItem ci = solrStore.get(contentURI); if (ci == null) { throw new WebApplicationException(404); } @@ -274,11 +298,19 @@ public class StoreResource extends BaseS return Response.ok(out.toString(), "text/plain").build(); } + /** + * HTTP GET method to retrieve the raw content item. + * + * @param contentURI + * URI of the resource in the Stanbol Contenthub store + * @return Raw data of the content item. + * @throws IOException + * @throws StoreException + */ @GET - @Path("/raw/{localId:.+}") - public Response getRawContent(@PathParam(value = "localId") String localId) throws IOException, - StoreException { - ContentItem ci = solrStore.get(localId); + @Path("/raw/{uri:.+}") + public Response getRawContent(@PathParam(value = "uri") String contentURI) throws IOException, StoreException { + ContentItem ci = solrStore.get(contentURI); if (ci == null) { throw new WebApplicationException(404); } @@ -287,16 +319,17 @@ public class StoreResource extends BaseS } /** - * This method creates the Json string of an edited content item to display it in the HTML view. + * This method creates the JSON string of a content item (to be edited) to display it in the HTML view. * - * @param localid - * @return + * @param contentURI + * URI id of the resource in the Stanbol Contenthub store + * @return JSON representation of the {@link SolrContentItem} * @throws StoreException */ @GET - @Path("/edit/{localid:.+}") - public String editContentItem(@PathParam(value = "localid") String localid) throws StoreException { - SolrContentItem sci = (SolrContentItem) solrStore.get(localid); + @Path("/edit/{uri:.+}") + public String editContentItem(@PathParam(value = "uri") String contentURI) throws StoreException { + SolrContentItem sci = (SolrContentItem) solrStore.get(contentURI); if (sci == null) { throw new WebApplicationException(404); } @@ -314,6 +347,20 @@ public class StoreResource extends BaseS * Services for content item creation */ // TODO other parameters like title, ldprogram should be considered for this service + /** + * HTTP POST method to create a content item in Contenthub. This is the very basic method to create the + * content item. The payload of the POST method should include the raw data of the content item to be + * created. This method stores the content in the default Solr index ("contenthub"). + * + * @param data + * Raw data of the content item + * @param headers + * HTTP Headers (optional) + * @return Redirects to "contenthub/store/content/localId" which shows the content item in the HTML view. + * @throws URISyntaxException + * @throws EngineException + * @throws StoreException + */ @POST @Consumes(WILDCARD + ";qs=0.5") public Response createContentItem(byte[] data, @Context HttpHeaders headers) throws URISyntaxException, @@ -323,12 +370,45 @@ public class StoreResource extends BaseS return createEnhanceAndRedirect(data, headers.getMediaType(), uri, null); } + /** + * HTTP POST method to create a content item in Contenthub. This method requires the content to be + * text-based. + * + * @param content + * Actual content in text format. If this parameter is supplied, {@link url} is ommitted. + * @param url + * URL where the actual content resides. If this parameter is supplied (and {@link content} is + * {@code null}, then the content is retrieved from this url. + * @param jsonCons + * Constraints in JSON format. Constraints are used to add supplementary metadata to the + * content item. For example, author of the content item may be supplied as {author: + * "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 contentURI + * URI for the content item. If not supplied, Contenthub automatically assigns a URI to the + * content item. + * @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. + * @param ldprogram + * Name of the LDPath program to be used while storing this content item. LDPath programs can + * be managed through {@link LDProgramManagerResource} or {@link LDProgramManager} + * @param headers + * HTTP headers (optional) + * @return Redirects to "contenthub/store/content/localId" which shows the content item in the HTML view. + * @throws URISyntaxException + * @throws EngineException + * @throws MalformedURLException + * @throws IOException + * @throws StoreException + */ @POST @Consumes(APPLICATION_FORM_URLENCODED) public Response createContentItemFromForm(@FormParam("content") String content, @FormParam("url") String url, @FormParam("constraints") String jsonCons, - @FormParam("contentId") String contentId, + @FormParam("uri") String contentURI, @FormParam("title") String title, @FormParam("ldprogram") String ldprogram, @Context HttpHeaders headers) throws URISyntaxException, @@ -340,10 +420,41 @@ public class StoreResource extends BaseS if (jsonCons != null) { constraints = JSONUtils.convertToMap(jsonCons); } - return createContentItemFromForm(content, contentId, url, null, null, headers, constraints, title, + return createContentItemFromForm(content, contentURI, url, null, null, headers, constraints, title, ldprogram); } + /** + * HTTP POST method to create a content item from file. File is read and loaded as the actual content. + * + * @param file + * {@link File} which contains the content for the content item. + * @param disposition + * Additional information about the {@link file} parameter + * @param jsonCons + * Constraints in JSON format. Constraints are used to add supplementary metadata to the + * content item. For example, author of the content item may be supplied as {author: + * "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 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. + * @param ldprogram + * Name of the LDPath program to be used while storing this content item. LDPath programs can + * be managed through {@link LDProgramManagerResource} or {@link LDProgramManager} + * @param headers + * HTTP headers (optional) + * @return Redirects to "contenthub/store/content/localId" which shows the content item in the HTML view. + * @throws URISyntaxException + * @throws EngineException + * @throws MalformedURLException + * @throws IOException + * @throws StoreException + */ @POST @Consumes(MULTIPART_FORM_DATA) public Response createContentItemFromForm(@FormDataParam("file") File file, @@ -366,19 +477,32 @@ public class StoreResource extends BaseS } // TODO other parameters like title, ldprogram should be considered for this service + /** + * 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. + * @param data + * @param headers + * @return + * @throws URISyntaxException + * @throws EngineException + * @throws StoreException + */ @PUT - @Path("/content/{localId:.+}") + @Path("/content/{uri:.+}") @Consumes(WILDCARD) - public Response createContentItemWithId(@PathParam(value = "localId") String localId, + public Response createContentItemWithId(@PathParam(value = "uri") String contentURI, byte[] data, @Context HttpHeaders headers) throws URISyntaxException, EngineException, StoreException { - return createEnhanceAndRedirect(data, headers.getMediaType(), localId, null); + return createEnhanceAndRedirect(data, headers.getMediaType(), contentURI, null); } private Response createContentItemFromForm(String content, - String contentId, + String contentURI, String url, File file, FormDataContentDisposition disposition, @@ -414,8 +538,8 @@ public class StoreResource extends BaseS if (data != null && mt != null) { String uri = ContentItemHelper.makeDefaultUrn(data).getUnicodeString(); - if (contentId != null && !contentId.isEmpty() && !uri.equals(contentId)) { - deleteContentItem(contentId); + if (contentURI != null && !contentURI.isEmpty() && !uri.equals(contentURI)) { + deleteContentItem(contentURI); } return createEnhanceAndRedirect(data, mt, uri, true, constraints, title, ldProgram); } else { @@ -455,13 +579,16 @@ public class StoreResource extends BaseS return new URI(uriInfo.getBaseUri() + "contenthub/store/content/" + localId); } - /* - * Content item deletion service + /** + * HTTP DELETE method to delete a content item from Contenhub. + * @param contentURI URI of the content item to be deleted. + * @return HTTP OK + * @throws StoreException */ @DELETE - @Path("/content/{localid:.+}") - public Response deleteContentItem(@PathParam(value = "localid") String localid) throws StoreException { - solrStore.deleteById(localid); + @Path("/content/{uri:.+}") + public Response deleteContentItem(@PathParam(value = "uri") String contentURI) throws StoreException { + solrStore.deleteById(contentURI); return Response.ok().build(); }
