You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by sf...@apache.org on 2010/12/12 16:13:37 UTC
svn commit: r1044832 [4/14] - in /incubator/stanbol/trunk/rick:
indexing/dbPedia/src/main/java/eu/iksproject/rick/indexing/dbPedia/cli/
indexing/genericRdf/src/main/java/eu/iksproject/rick/indexing/rdf/
indexing/geonames/src/main/java/eu/iksproject/ric...
Modified: incubator/stanbol/trunk/rick/indexing/geonames/src/main/java/eu/iksproject/rick/indexing/geonames/cli/CommandLineRunner.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/indexing/geonames/src/main/java/eu/iksproject/rick/indexing/geonames/cli/CommandLineRunner.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/indexing/geonames/src/main/java/eu/iksproject/rick/indexing/geonames/cli/CommandLineRunner.java (original)
+++ incubator/stanbol/trunk/rick/indexing/geonames/src/main/java/eu/iksproject/rick/indexing/geonames/cli/CommandLineRunner.java Sun Dec 12 15:13:35 2010
@@ -23,23 +23,23 @@ import eu.iksproject.rick.yard.solr.impl
import static eu.iksproject.rick.indexing.geonames.GeoNamesIndexer.*;
public class CommandLineRunner {
-
- protected static final Logger log = LoggerFactory.getLogger(CommandLineRunner.class);
-
- private static final String header;
- static {
- StringBuilder builder = new StringBuilder();
- builder.append("Description:\nThis Utility creates a full Yard for geonames.org by using the SolrYard implementation.\n");
- builder.append("\nParameter:\n");
- builder.append(" - \"-Xmx\": This implementation loads alternate labels into memory. Therefore it needs a lot of memory during indexing. Parse at least \"-Xmx1024M\" to provide 1GByte memory to the Java Vm. In case of OutOfMemory errors you need to increase this value!");
- builder.append(" - solrServerUri : The URL of the Solr Server used to index the data. Make sure to use the schema.xml as needed by the SolrYard!\n");
- builder.append(" - geonamesDataDumpDir: The relative or absolute path to the Dir with the geonames.org data required for indexing\n");
- builder.append("\nOptions:\n");
- header = builder.toString();
- builder = null;
- }
- private static final Options options;
- static {
+
+ protected static final Logger log = LoggerFactory.getLogger(CommandLineRunner.class);
+
+ private static final String header;
+ static {
+ StringBuilder builder = new StringBuilder();
+ builder.append("Description:\nThis Utility creates a full Yard for geonames.org by using the SolrYard implementation.\n");
+ builder.append("\nParameter:\n");
+ builder.append(" - \"-Xmx\": This implementation loads alternate labels into memory. Therefore it needs a lot of memory during indexing. Parse at least \"-Xmx1024M\" to provide 1GByte memory to the Java Vm. In case of OutOfMemory errors you need to increase this value!");
+ builder.append(" - solrServerUri : The URL of the Solr Server used to index the data. Make sure to use the schema.xml as needed by the SolrYard!\n");
+ builder.append(" - geonamesDataDumpDir: The relative or absolute path to the Dir with the geonames.org data required for indexing\n");
+ builder.append("\nOptions:\n");
+ header = builder.toString();
+ builder = null;
+ }
+ private static final Options options;
+ static {
options = new Options();
options.addOption("h", "help", false, "display this help and exit");
options.addOption("d", "debug", false, "show debug stacktrace upon error");
@@ -51,20 +51,20 @@ public class CommandLineRunner {
options.addOption("io","indexOnt",false, "index also the geonames ontology");
options.addOption("c","chunksize",true, "the number of documents stored in one chunk (default: 1000");
options.addOption("s","start",true, "the line number of the geonames table to start(default: 0");
- }
- private static final String footer;
- static {
- StringBuilder builder = new StringBuilder();
- builder.append("Required data:\n");
- builder.append(" - archive with the toponyms (default 'allCountries.zip', see option 'a'\n");
- builder.append(" - countryInfo.txt : additional infos for country codes\n");
- builder.append(" - admin1CodesASCII.txt : leval 1 administrative regions\n");
- builder.append(" - admin2Codes.txt: Level 2 administrative regions\n");
- builder.append(" - alternateNames.zip or .txt: names of features in different languages\n");
- builder.append(" - geonames ontology: only needed if '-io' (default 'ontology_v2.2.1.rdf', see option 'o')\n");
- footer = builder.toString();
- builder = null;
- }
+ }
+ private static final String footer;
+ static {
+ StringBuilder builder = new StringBuilder();
+ builder.append("Required data:\n");
+ builder.append(" - archive with the toponyms (default 'allCountries.zip', see option 'a'\n");
+ builder.append(" - countryInfo.txt : additional infos for country codes\n");
+ builder.append(" - admin1CodesASCII.txt : leval 1 administrative regions\n");
+ builder.append(" - admin2Codes.txt: Level 2 administrative regions\n");
+ builder.append(" - alternateNames.zip or .txt: names of features in different languages\n");
+ builder.append(" - geonames ontology: only needed if '-io' (default 'ontology_v2.2.1.rdf', see option 'o')\n");
+ footer = builder.toString();
+ builder = null;
+ }
public static void main(String[] args) throws IOException, ParseException, YardException {
CommandLineParser parser = new PosixParser();
CommandLine line = parser.parse(options, args);
@@ -81,7 +81,7 @@ public class CommandLineRunner {
}
String yardName = line.getOptionValue("n");
if(yardName == null){
- yardName = "geonames";
+ yardName = "geonames";
}
URL solrServer = new URL(line.getArgs()[0]);
SolrYardConfig yardConfig = new SolrYardConfig(yardName, solrServer);
@@ -90,36 +90,36 @@ public class CommandLineRunner {
indexingConfig.put(KEY_YARD, yard);
indexingConfig.put(KEY_DATA_DIR, line.getArgs()[1]);
indexingConfig.put(KEY_INDEX_ONTOLOGY_STATE, line.hasOption("io"));
- indexingConfig.put(KEY_GEONAMES_ONTOLOGY,
- line.getOptionValue("o", "ontology_v2.2.1.rdf"));
- indexingConfig.put(KEY_GEONAMES_ARCHIVE,
- line.getOptionValue("a","allCountries.zip"));
+ indexingConfig.put(KEY_GEONAMES_ONTOLOGY,
+ line.getOptionValue("o", "ontology_v2.2.1.rdf"));
+ indexingConfig.put(KEY_GEONAMES_ARCHIVE,
+ line.getOptionValue("a","allCountries.zip"));
Long start;
try {
- start = Long.valueOf(line.getOptionValue("s", "0"));
- } catch (NumberFormatException e) {
- throw new IllegalArgumentException("Value for option \"start\" need to be a valid Integer");
- }
- if(start<0){
- log.warn("Negative number parsed for option \"start\". Use '0' as default.");
- start = 0l;
- }
+ start = Long.valueOf(line.getOptionValue("s", "0"));
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("Value for option \"start\" need to be a valid Integer");
+ }
+ if(start<0){
+ log.warn("Negative number parsed for option \"start\". Use '0' as default.");
+ start = 0l;
+ }
indexingConfig.put(KEY_START_INDEX, start);
Integer chunkSize;
try {
- chunkSize = Integer.valueOf(line.getOptionValue("c", "1000"));
- } catch (NumberFormatException e) {
- throw new IllegalArgumentException("Value for option \"chunkSize\" need to be a valid Integer");
- }
- if(chunkSize<0){
- log.warn("Negative number parsed for option \"chunkSize\". Use '1000' as default.");
- chunkSize = 1000;
- }
+ chunkSize = Integer.valueOf(line.getOptionValue("c", "1000"));
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("Value for option \"chunkSize\" need to be a valid Integer");
+ }
+ if(chunkSize<0){
+ log.warn("Negative number parsed for option \"chunkSize\". Use '1000' as default.");
+ chunkSize = 1000;
+ }
indexingConfig.put(KEY_CHUNK_SIZE, chunkSize);
GeoNamesIndexer indexer = new GeoNamesIndexer(indexingConfig);
indexer.index();
}
-
-
+
+
}
Modified: incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/JerseyEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/JerseyEndpoint.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/JerseyEndpoint.java (original)
+++ incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/JerseyEndpoint.java Sun Dec 12 15:13:35 2010
@@ -29,9 +29,9 @@ import eu.iksproject.rick.servicesapi.si
*
* This OSGi component serves as a bridge between the OSGi context and the
* Servlet context available to JAX-RS resources.
- *
- * NOTE: Original Code taken from the FISE
- * @author Rupert Westenthaler
+ *
+ * NOTE: Original Code taken from the FISE
+ * @author Rupert Westenthaler
*/
@Component(immediate = true, metatype = true)
@@ -167,4 +167,4 @@ public class JerseyEndpoint {
this.httpService = null;
}
-}
\ No newline at end of file
+}
Modified: incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/JerseyEndpointApplication.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/JerseyEndpointApplication.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/JerseyEndpointApplication.java (original)
+++ incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/JerseyEndpointApplication.java Sun Dec 12 15:13:35 2010
@@ -29,15 +29,15 @@ import eu.iksproject.rick.jersey.writers
* providers.
*/
public class JerseyEndpointApplication extends Application {
-
- Logger log = LoggerFactory.getLogger(getClass());
- public JerseyEndpointApplication() {
- log.info("JerseyEndpointApplication instanceiated");
- }
+
+ Logger log = LoggerFactory.getLogger(getClass());
+ public JerseyEndpointApplication() {
+ log.info("JerseyEndpointApplication instanceiated");
+ }
@Override
public Set<Class<?>> getClasses() {
- log.info("JerseyEndpointApplication getClasses called ...");
+ log.info("JerseyEndpointApplication getClasses called ...");
Set<Class<?>> classes = new HashSet<Class<?>>();
// resources
classes.add(RickRootResource.class);
@@ -49,8 +49,8 @@ public class JerseyEndpointApplication e
classes.add(QueryResultListWriter.class);
classes.add(SignWriter.class);
//TODO: somehow writing of Json has not worked because of
- // A message body writer for Java class org.codehaus.jettison.json.JSONArray,
- // and Java type class org.codehaus.jettison.json.JSONArray, and MIME media
+ // A message body writer for Java class org.codehaus.jettison.json.JSONArray,
+ // and Java type class org.codehaus.jettison.json.JSONArray, and MIME media
// type application/json was not found
// As a workaround I have implemented this small workaround!
classes.add(JettisonWriter.class);
Modified: incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/JettyServer.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/JettyServer.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/JettyServer.java (original)
+++ incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/JettyServer.java Sun Dec 12 15:13:35 2010
@@ -28,7 +28,7 @@ public class JettyServer {
private final Logger log = LoggerFactory.getLogger(getClass());
- public static String DEFAUL_BASE_URI = "http://localhost:9998/";
+ public static String DEFAULT_BASE_URI = "http://localhost:9998/";
protected Server server = new Server();
@@ -85,10 +85,10 @@ public class JettyServer {
*/
public static void main(String[] args) throws Exception {
JettyServer server = new JettyServer();
- server.start(DEFAUL_BASE_URI);
+ server.start(DEFAULT_BASE_URI);
System.out.println("Hit enter to stop it...");
System.in.read();
server.stop();
}
-}
\ No newline at end of file
+}
Modified: incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/resource/NavigationMixin.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/resource/NavigationMixin.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/resource/NavigationMixin.java (original)
+++ incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/resource/NavigationMixin.java Sun Dec 12 15:13:35 2010
@@ -9,19 +9,22 @@ import javax.ws.rs.core.UriInfo;
public class NavigationMixin {
- protected NavigationMixin(){
- }
- /**
- * Some subclasses set the uriInfo property. If that is necessary, than it's
- * best to do it when calling the super constructor (rw, 20101015)
- * @param uriInfo
- */
- protected NavigationMixin(UriInfo uriInfo){
- if(uriInfo == null){
- throw new IllegalArgumentException("Parameter uriInfo MUST NOT be NULL");
- }
- this.uriInfo = uriInfo;
- }
+ protected NavigationMixin() {
+ }
+
+ /**
+ * Some subclasses set the uriInfo property. If that is necessary, than it's
+ * best to do it when calling the super constructor (rw, 20101015)
+ *
+ * @param uriInfo
+ */
+ protected NavigationMixin(UriInfo uriInfo) {
+ if (uriInfo == null) {
+ throw new IllegalArgumentException("Parameter uriInfo MUST NOT be NULL");
+ }
+ this.uriInfo = uriInfo;
+ }
+
@Context
protected UriInfo uriInfo;
@@ -30,10 +33,8 @@ public class NavigationMixin {
}
public List<MenuItem> getMainMenuItems() {
- return Arrays.asList(
- new MenuItem("RICK", "/rick", uriInfo),
- new MenuItem("Referenced Site Manager", "/site", uriInfo)
- );
+ return Arrays.asList(new MenuItem("RICK", "/rick", uriInfo),
+ new MenuItem("Referenced Site Manager", "/site", uriInfo));
}
public static class MenuItem {
@@ -46,9 +47,9 @@ public class NavigationMixin {
protected final String label;
- protected final String link;
+ protected final String link;
- protected final String cssClass;
+ protected final String cssClass;
public String getLabel() {
return label;
Modified: incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/resource/ReferencedSiteRootResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/resource/ReferencedSiteRootResource.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/resource/ReferencedSiteRootResource.java (original)
+++ incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/resource/ReferencedSiteRootResource.java Sun Dec 12 15:13:35 2010
@@ -40,173 +40,159 @@ import eu.iksproject.rick.servicesapi.si
/**
* Resource to provide a REST API for the {@link ReferencedSiteManager}
- *
+ * <p/>
* TODO: add description
- *
*/
@Path("/site/{site}")
public class ReferencedSiteRootResource extends NavigationMixin {
private final Logger log = LoggerFactory.getLogger(getClass());
- public static final Set<String> RDF_MEDIA_TYPES = new TreeSet<String>(
- Arrays.asList(SupportedFormat.N3, SupportedFormat.N_TRIPLE,
- SupportedFormat.RDF_XML, SupportedFormat.TURTLE,
- SupportedFormat.X_TURTLE, SupportedFormat.RDF_JSON));
+ public static final Set<String> RDF_MEDIA_TYPES = new TreeSet<String>(Arrays.asList(SupportedFormat.N3, SupportedFormat.N_TRIPLE, SupportedFormat.RDF_XML, SupportedFormat.TURTLE, SupportedFormat.X_TURTLE, SupportedFormat.RDF_JSON));
/**
* The Field used for find requests if not specified
* TODO: Make configurable via the {@link ConfiguredSite} interface!
*/
- private static final String DEFAULT_FIND_FIELD = RDFS.label.getUnicodeString();
- /**
- * The Field used as default as selected fields for find requests
+ private static final String DEFAULT_FIND_FIELD = RDFS.label.getUnicodeString();
+ /**
+ * The Field used as default as selected fields for find requests
* TODO: Make configurable via the {@link ConfiguredSite} interface!
- */
- private static final Collection<String> DEFAULT_FIND_SELECTED_FIELDS =
- Arrays.asList(RDFS.comment.getUnicodeString());
- /**
- * The default number of maximal results.
- */
- private static final int DEFAULT_FIND_RESULT_LIMIT = 5;
+ */
+ private static final Collection<String> DEFAULT_FIND_SELECTED_FIELDS = Arrays.asList(RDFS.comment.getUnicodeString());
+ /**
+ * The default number of maximal results.
+ */
+ private static final int DEFAULT_FIND_RESULT_LIMIT = 5;
protected Serializer serializer;
protected ReferencedSite site;
- public ReferencedSiteRootResource(
- @Context ServletContext context,
- @PathParam(value="site")String siteId) {
- super();
- log.info("... init ReferencedSiteRootResource for Site {}",siteId);
- ReferencedSiteManager referencedSiteManager =
- (ReferencedSiteManager) context.getAttribute(ReferencedSiteManager.class.getName());
+ public ReferencedSiteRootResource(@Context ServletContext context, @PathParam(value = "site") String siteId) {
+ super();
+ log.info("... init ReferencedSiteRootResource for Site {}", siteId);
+ ReferencedSiteManager referencedSiteManager = (ReferencedSiteManager) context.getAttribute(ReferencedSiteManager.class.getName());
serializer = (Serializer) context.getAttribute(Serializer.class.getName());
if (referencedSiteManager == null) {
log.error("Missing referencedSiteManager={}", referencedSiteManager);
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
- if(siteId == null || siteId.isEmpty()){
+ if (siteId == null || siteId.isEmpty()) {
log.error("Missing path parameter site={}", siteId);
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
site = referencedSiteManager.getReferencedSite(siteId);
- if(site == null){
+ if (site == null) {
log.error("Site {} not found (No referenced site with that ID is present within the RICK", siteId);
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
}
+
@GET
- @Path(value="/")
+ @Path(value = "/")
@Produces(MediaType.TEXT_HTML)
- public String getInfo(){
- return "<html><head>"+site.getName()+"</head><body>"+
- "<h1>Referenced Site "+site.getName()+":</h1></body></html>";
+ public String getInfo() {
+ return "<html><head>" + site.getName() + "</head><body>" + "<h1>Referenced Site " + site.getName() + ":</h1></body></html>";
}
+
/**
- * Cool URI handler for Signs.
+ * Cool URI handler for Signs.
*
- * @param siteId A specific {@link ReferencedSite} to search the parsed id or
- * <code>null</code> to search all referenced sites for the requested
- * entity id. The {@link ReferencedSite#getId()} property is used to map
- * the path to the site!
- * @param id The id of the entity (required)
+ * @param siteId A specific {@link ReferencedSite} to search the parsed id or
+ * <code>null</code> to search all referenced sites for the requested
+ * entity id. The {@link ReferencedSite#getId()} property is used to map
+ * the path to the site!
+ * @param id The id of the entity (required)
* @param headers the request headers used to get the requested {@link MediaType}
* @return a redirection to either a browser view, the RDF meta data or the
* raw binary content
*/
@GET
@Path("/entity")
- public Response getSignById(
- @QueryParam(value= "id") String id,
- @Context HttpHeaders headers) {
- log.info("site/"+site.getId()+"/entity Request");
- log.info(" > id : "+id);
- log.info(" > accept : "+headers.getAcceptableMediaTypes());
- log.info(" > mediaType: "+headers.getMediaType());
- if(id == null || id.isEmpty()){
- log.error("No or emptpy ID was parsd as query parameter (id={})",id);
- throw new WebApplicationException(Response.Status.BAD_REQUEST);
- }
- log.info("handle Request for Entity {} of Site {}",id,site.getId());
- Sign sign;
- try {
- sign = site.getSign(id);
- } catch (ReferencedSiteException e) {
- log.error("ReferencedSiteException while accessing Site "+site.getName()+" (id="+site.getId()+")",e);
- throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
- }
- final MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers,MediaType.APPLICATION_JSON_TYPE);
- if(sign != null){
- return Response.ok(sign, acceptedMediaType).build();
- } else {
- //TODO: How to parse an ErrorMessage?
- // create an Response with the the Error?
- log.info(" ... Entity {} not found on referenced site {}",id,site.getId());
- throw new WebApplicationException(Response.Status.NOT_FOUND);
- }
+ public Response getSignById(@QueryParam(value = "id") String id, @Context HttpHeaders headers) {
+ log.info("site/" + site.getId() + "/entity Request");
+ log.info(" > id : " + id);
+ log.info(" > accept : " + headers.getAcceptableMediaTypes());
+ log.info(" > mediaType: " + headers.getMediaType());
+ if (id == null || id.isEmpty()) {
+ log.error("No or emptpy ID was parsd as query parameter (id={})", id);
+ throw new WebApplicationException(Response.Status.BAD_REQUEST);
+ }
+ log.info("handle Request for Entity {} of Site {}", id, site.getId());
+ Sign sign;
+ try {
+ sign = site.getSign(id);
+ } catch (ReferencedSiteException e) {
+ log.error("ReferencedSiteException while accessing Site " + site.getName() + " (id=" + site.getId() + ")", e);
+ throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
+ }
+ final MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers, MediaType.APPLICATION_JSON_TYPE);
+ if (sign != null) {
+ return Response.ok(sign, acceptedMediaType).build();
+ } else {
+ //TODO: How to parse an ErrorMessage?
+ // create an Response with the the Error?
+ log.info(" ... Entity {} not found on referenced site {}", id, site.getId());
+ throw new WebApplicationException(Response.Status.NOT_FOUND);
+ }
}
@GET
@Path("/find")
- public Response findEntitybyGet(
- @QueryParam(value="name") String name,
- //@QueryParam(value="field") String field,
- @QueryParam(value="lang") String language,
- //@QueryParam(value="select") String select,
- @QueryParam(value="limit") @DefaultValue(value="-1")int limit,
- @QueryParam(value="offset") @DefaultValue(value="0") int offset,
- @Context HttpHeaders headers) {
- return findEntity(name, language, limit, offset, headers);
+ public Response findEntitybyGet(@QueryParam(value = "name") String name,
+ //@QueryParam(value="field") String field,
+ @QueryParam(value = "lang") String language,
+ //@QueryParam(value="select") String select,
+ @QueryParam(value = "limit") @DefaultValue(value = "-1") int limit, @QueryParam(value = "offset") @DefaultValue(value = "0") int offset, @Context HttpHeaders headers) {
+ return findEntity(name, language, limit, offset, headers);
}
+
@POST
@Path("/find")
- public Response findEntity(
- @FormParam(value="name") String name,
- //@FormParam(value="field") String field,
- @FormParam(value="lang") String language,
- //@FormParam(value="select") String select,
- @FormParam(value="limit") @DefaultValue(value="-1")int limit,
- @FormParam(value="offset") @DefaultValue(value="0") int offset,
- @Context HttpHeaders headers) {
- log.info("site/"+site.getId()+"/find Request");
- log.info(" > name : "+name);
- log.info(" > lang : "+language);
- log.info(" > limit : "+limit);
- log.info(" > offset: "+offset);
- log.info(" > accept: "+headers.getAcceptableMediaTypes());
- if(name == null || name.isEmpty()){
- log.error("/find Request with invalied name={}!",name);
- }
- String field = DEFAULT_FIND_FIELD;
- FieldQuery query = new FieldQueryImpl();
- if(language == null){
- query.setConstraint(field, new TextConstraint(name,PatternType.wildcard,false));
- } else {
- query.setConstraint(field, new TextConstraint(name,PatternType.wildcard,false,language));
- }
- Collection<String> selectedFields = new ArrayList<String>();
- selectedFields.add(field); //select also the field used to find entities
-// if(select == null ||select.isEmpty()){
-// selectedFields.addAll(DEFAULT_FIND_SELECTED_FIELDS);
-// } else {
-// for(String selected : select.trim().split(" ")){
-// if(selected != null && !selected.isEmpty()){
-// selectedFields.add(selected);
-// }
-// }
-// }
- query.addSelectedFields(selectedFields);
- if(limit < 1){
- limit = DEFAULT_FIND_RESULT_LIMIT;
- }
- query.setLimit(limit);
- query.setOffset(offset);
- final MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers,MediaType.APPLICATION_JSON_TYPE);
- try {
- return Response.ok(site.find(query),acceptedMediaType).build();
- } catch (ReferencedSiteException e) {
- log.error("ReferencedSiteException while accessing Site "+site.getName()+" (id="+site.getId()+")",e);
- throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
- }
+ public Response findEntity(@FormParam(value = "name") String name,
+ //@FormParam(value="field") String field,
+ @FormParam(value = "lang") String language,
+ //@FormParam(value="select") String select,
+ @FormParam(value = "limit") @DefaultValue(value = "-1") int limit, @FormParam(value = "offset") @DefaultValue(value = "0") int offset, @Context HttpHeaders headers) {
+ log.info("site/" + site.getId() + "/find Request");
+ log.info(" > name : " + name);
+ log.info(" > lang : " + language);
+ log.info(" > limit : " + limit);
+ log.info(" > offset: " + offset);
+ log.info(" > accept: " + headers.getAcceptableMediaTypes());
+ if (name == null || name.isEmpty()) {
+ log.error("/find Request with invalied name={}!", name);
+ }
+ String field = DEFAULT_FIND_FIELD;
+ FieldQuery query = new FieldQueryImpl();
+ if (language == null) {
+ query.setConstraint(field, new TextConstraint(name, PatternType.wildcard, false));
+ } else {
+ query.setConstraint(field, new TextConstraint(name, PatternType.wildcard, false, language));
+ }
+ Collection<String> selectedFields = new ArrayList<String>();
+ selectedFields.add(field); //select also the field used to find entities
+// if(select == null ||select.isEmpty()){
+// selectedFields.addAll(DEFAULT_FIND_SELECTED_FIELDS);
+// } else {
+// for(String selected : select.trim().split(" ")){
+// if(selected != null && !selected.isEmpty()){
+// selectedFields.add(selected);
+// }
+// }
+// }
+ query.addSelectedFields(selectedFields);
+ if (limit < 1) {
+ limit = DEFAULT_FIND_RESULT_LIMIT;
+ }
+ query.setLimit(limit);
+ query.setOffset(offset);
+ final MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers, MediaType.APPLICATION_JSON_TYPE);
+ try {
+ return Response.ok(site.find(query), acceptedMediaType).build();
+ } catch (ReferencedSiteException e) {
+ log.error("ReferencedSiteException while accessing Site " + site.getName() + " (id=" + site.getId() + ")", e);
+ throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
+ }
}
}
Modified: incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/resource/RickEntityMappingResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/resource/RickEntityMappingResource.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/resource/RickEntityMappingResource.java (original)
+++ incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/resource/RickEntityMappingResource.java Sun Dec 12 15:13:35 2010
@@ -27,8 +27,17 @@ import eu.iksproject.rick.servicesapi.Ri
import eu.iksproject.rick.servicesapi.model.EntityMapping;
import eu.iksproject.rick.servicesapi.query.QueryResultList;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
+import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
+import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
+import static org.apache.clerezza.rdf.core.serializedform.SupportedFormat.*;
+import static org.apache.clerezza.rdf.core.serializedform.SupportedFormat.N_TRIPLE;
+import static org.apache.clerezza.rdf.core.serializedform.SupportedFormat.RDF_JSON;
+
/**
* RESTful interface for the {@link EntityMapping}s defined by the {@link Rick}.
+ *
* @author Rupert Westenthaler
*/
@Path("/mapping")
@@ -39,11 +48,11 @@ public class RickEntityMappingResource e
// * The default result fields for /find queries is the reference to the
// * mapped symbol and the mapped entity
// */
-// private static final Collection<? extends String> DEFAULT_FIND_SELECTED_FIELDS =
-// Arrays.asList(
-// RdfResourceEnum.mappedEntity.getUri(),
-// RdfResourceEnum.mappedSymbol.getUri());
-
+// private static final Collection<? extends String> DEFAULT_FIND_SELECTED_FIELDS =
+// Arrays.asList(
+// RdfResourceEnum.mappedEntity.getUri(),
+// RdfResourceEnum.mappedSymbol.getUri());
+
private final Logger log = LoggerFactory.getLogger(getClass());
@@ -57,99 +66,87 @@ public class RickEntityMappingResource e
// bind the job manager by looking it up from the servlet request context
public RickEntityMappingResource(@Context ServletContext context) {
- super();
+ super();
rick = (Rick) context.getAttribute(Rick.class.getName());
tcManager = (TcManager) context.getAttribute(TcManager.class.getName());
serializer = (Serializer) context.getAttribute(Serializer.class.getName());
}
+
@GET
@Path("/")
- @Produces({MediaType.APPLICATION_JSON,SupportedFormat.RDF_XML,SupportedFormat.N3,
- SupportedFormat.TURTLE,SupportedFormat.X_TURTLE,SupportedFormat.RDF_JSON,
- SupportedFormat.N_TRIPLE})
- public Response getMapping(
- @QueryParam("id") String reference,
- @Context HttpHeaders headers)
- throws WebApplicationException{
- log.info("/symbol/ POST Request");
- log.info(" > id : "+reference);
- log.info(" > accept: "+headers.getAcceptableMediaTypes());
- if(reference == null || reference.isEmpty()){
- //TODO: how to parse an error message
- throw new WebApplicationException(Response.Status.BAD_REQUEST);
- }
- EntityMapping mapping;
- try {
- mapping = rick.getMappingById(reference);
- } catch (RickException e) {
- throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
- }
- if(mapping == null){
- throw new WebApplicationException(404);
- } else {
- MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers,MediaType.APPLICATION_JSON_TYPE);
- return Response.ok(mapping,acceptedMediaType).build();
- }
+ @Produces({APPLICATION_JSON, RDF_XML, N3, TURTLE, X_TURTLE, RDF_JSON, N_TRIPLE})
+ public Response getMapping(@QueryParam("id") String reference, @Context HttpHeaders headers) throws WebApplicationException {
+ log.info("/symbol/ POST Request");
+ log.info(" > id : " + reference);
+ log.info(" > accept: " + headers.getAcceptableMediaTypes());
+ if (reference == null || reference.isEmpty()) {
+ //TODO: how to parse an error message
+ throw new WebApplicationException(BAD_REQUEST);
+ }
+ EntityMapping mapping;
+ try {
+ mapping = rick.getMappingById(reference);
+ } catch (RickException e) {
+ throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
+ }
+ if (mapping == null) {
+ throw new WebApplicationException(404);
+ } else {
+ MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers, APPLICATION_JSON_TYPE);
+ return Response.ok(mapping, acceptedMediaType).build();
+ }
}
+
@GET
@Path("/entity")
- @Produces({MediaType.APPLICATION_JSON,SupportedFormat.RDF_XML,SupportedFormat.N3,
- SupportedFormat.TURTLE,SupportedFormat.X_TURTLE,SupportedFormat.RDF_JSON,
- SupportedFormat.N_TRIPLE})
- public Response getEntityMapping(
- @QueryParam("id") String entity,
- @Context HttpHeaders headers)
- throws WebApplicationException{
- log.info("/symbol/ POST Request");
- log.info(" > entity: "+entity);
- log.info(" > accept: "+headers.getAcceptableMediaTypes());
- if(entity == null || entity.isEmpty()){
- //TODO: how to parse an error message
- throw new WebApplicationException(Response.Status.BAD_REQUEST);
- }
- EntityMapping mapping;
- try {
- mapping = rick.getMappingByEntity(entity);
- } catch (RickException e) {
- throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
- }
- if(mapping == null){
- throw new WebApplicationException(404);
- } else {
- MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers,MediaType.APPLICATION_JSON_TYPE);
- return Response.ok(mapping,acceptedMediaType).build();
- }
+ @Produces({APPLICATION_JSON, RDF_XML, N3, TURTLE, X_TURTLE, RDF_JSON, N_TRIPLE})
+ public Response getEntityMapping(@QueryParam("id") String entity, @Context HttpHeaders headers) throws WebApplicationException {
+ log.info("/symbol/ POST Request");
+ log.info(" > entity: " + entity);
+ log.info(" > accept: " + headers.getAcceptableMediaTypes());
+ if (entity == null || entity.isEmpty()) {
+ //TODO: how to parse an error message
+ throw new WebApplicationException(BAD_REQUEST);
+ }
+ EntityMapping mapping;
+ try {
+ mapping = rick.getMappingByEntity(entity);
+ } catch (RickException e) {
+ throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
+ }
+ if (mapping == null) {
+ throw new WebApplicationException(404);
+ } else {
+ MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers, APPLICATION_JSON_TYPE);
+ return Response.ok(mapping, acceptedMediaType).build();
+ }
}
+
@GET
@Path("/symbol")
- @Produces({MediaType.APPLICATION_JSON,SupportedFormat.RDF_XML,SupportedFormat.N3,
- SupportedFormat.TURTLE,SupportedFormat.X_TURTLE,SupportedFormat.RDF_JSON,
- SupportedFormat.N_TRIPLE})
- public Response getSymbolMappings(
- @QueryParam("id") String symbol,
- @Context HttpHeaders headers)
- throws WebApplicationException{
- log.info("/symbol/ POST Request");
- log.info(" > symbol: "+symbol);
- log.info(" > accept: "+headers.getAcceptableMediaTypes());
- if(symbol == null || symbol.isEmpty()){
- //TODO: how to parse an error message
- throw new WebApplicationException(Response.Status.BAD_REQUEST);
- }
- Collection<EntityMapping> mappings;
- try {
- mappings = rick.getMappingsBySymbol(symbol);
- } catch (RickException e) {
- throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
- }
- if(mappings == null || mappings.isEmpty()){
- throw new WebApplicationException(404);
- } else {
- MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers,MediaType.APPLICATION_JSON_TYPE);
- //TODO: Implement Support for list of Signs, Representations and Strings
- // For now use a pseudo QueryResultList
- QueryResultList<EntityMapping> mappingResultList = new QueryResultListImpl<EntityMapping>(null, mappings, EntityMapping.class);
- return Response.ok(mappingResultList,acceptedMediaType).build();
- }
+ @Produces({APPLICATION_JSON, RDF_XML, N3, TURTLE, X_TURTLE, RDF_JSON, N_TRIPLE})
+ public Response getSymbolMappings(@QueryParam("id") String symbol, @Context HttpHeaders headers) throws WebApplicationException {
+ log.info("/symbol/ POST Request");
+ log.info(" > symbol: " + symbol);
+ log.info(" > accept: " + headers.getAcceptableMediaTypes());
+ if (symbol == null || symbol.isEmpty()) {
+ //TODO: how to parse an error message
+ throw new WebApplicationException(BAD_REQUEST);
+ }
+ Collection<EntityMapping> mappings;
+ try {
+ mappings = rick.getMappingsBySymbol(symbol);
+ } catch (RickException e) {
+ throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
+ }
+ if (mappings == null || mappings.isEmpty()) {
+ throw new WebApplicationException(404);
+ } else {
+ MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers, APPLICATION_JSON_TYPE);
+ //TODO: Implement Support for list of Signs, Representations and Strings
+ // For now use a pseudo QueryResultList
+ QueryResultList<EntityMapping> mappingResultList = new QueryResultListImpl<EntityMapping>(null, mappings, EntityMapping.class);
+ return Response.ok(mappingResultList, acceptedMediaType).build();
+ }
}
}
Modified: incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/resource/RickSymbolResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/resource/RickSymbolResource.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/resource/RickSymbolResource.java (original)
+++ incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/resource/RickSymbolResource.java Sun Dec 12 15:13:35 2010
@@ -35,28 +35,31 @@ import eu.iksproject.rick.servicesapi.qu
import eu.iksproject.rick.servicesapi.query.TextConstraint;
import eu.iksproject.rick.servicesapi.query.TextConstraint.PatternType;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
+import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
+import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
+import static javax.ws.rs.core.Response.Status.NOT_FOUND;
+import static org.apache.clerezza.rdf.core.serializedform.SupportedFormat.*;
+
/**
* RESTful interface for The {@link Rick}. To access referenced sites directly
* see {@link ReferencedSiteRootResource}.
- *
*/
@Path("/symbol")
//@ImplicitProduces(MediaType.TEXT_HTML + ";qs=2")
public class RickSymbolResource extends NavigationMixin {
- /**
- * The default search field for /find queries is the rick-maodel:label
- */
+ /**
+ * The default search field for /find queries is the rick-maodel:label
+ */
private static final String DEFAULT_FIND_FIELD = RdfResourceEnum.label.getUri();
/**
* The default result fields for /find queries is the rick-maodel:label and the
* rick-maodel:description.
*/
- private static final Collection<? extends String> DEFAULT_FIND_SELECTED_FIELDS =
- Arrays.asList(
- RdfResourceEnum.label.getUri(),
- RdfResourceEnum.description.getUri());
-
+ private static final Collection<? extends String> DEFAULT_FIND_SELECTED_FIELDS = Arrays.asList(RdfResourceEnum.label.getUri(), RdfResourceEnum.description.getUri());
+
private final Logger log = LoggerFactory.getLogger(getClass());
@@ -70,127 +73,114 @@ public class RickSymbolResource extends
// bind the job manager by looking it up from the servlet request context
public RickSymbolResource(@Context ServletContext context) {
- super();
+ super();
rick = (Rick) context.getAttribute(Rick.class.getName());
tcManager = (TcManager) context.getAttribute(TcManager.class.getName());
serializer = (Serializer) context.getAttribute(Serializer.class.getName());
}
+
@GET
@Path("/")
- @Produces({MediaType.APPLICATION_JSON,SupportedFormat.RDF_XML,SupportedFormat.N3,
- SupportedFormat.TURTLE,SupportedFormat.X_TURTLE,SupportedFormat.RDF_JSON,
- SupportedFormat.N_TRIPLE})
- public Response getSymbol(
- @QueryParam("id") String symbolId,
- @Context HttpHeaders headers)
- throws WebApplicationException{
- log.info("/symbol/lookup Request");
- log.info(" > id: "+symbolId);
- log.info(" > accept: "+headers.getAcceptableMediaTypes());
- if(symbolId == null || symbolId.isEmpty()){
- //TODO: how to parse an error message
- throw new WebApplicationException(Response.Status.BAD_REQUEST);
- }
- Symbol symbol;
- try {
- symbol = rick.getSymbol(symbolId);
- } catch (RickException e) {
- throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
- }
- if(symbol == null){
- throw new WebApplicationException(Response.Status.NOT_FOUND);
- } else {
- MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers,MediaType.APPLICATION_JSON_TYPE);
- return Response.ok(symbol,acceptedMediaType).build();
- }
+ @Produces({APPLICATION_JSON, RDF_XML, N3, TURTLE, X_TURTLE, RDF_JSON, N_TRIPLE})
+ public Response getSymbol(@QueryParam("id") String symbolId, @Context HttpHeaders headers)
+ throws WebApplicationException {
+ log.info("/symbol/lookup Request");
+ log.info(" > id: " + symbolId);
+ log.info(" > accept: " + headers.getAcceptableMediaTypes());
+ if (symbolId == null || symbolId.isEmpty()) {
+ //TODO: how to parse an error message
+ throw new WebApplicationException(BAD_REQUEST);
+ }
+ Symbol symbol;
+ try {
+ symbol = rick.getSymbol(symbolId);
+ } catch (RickException e) {
+ throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
+ }
+ if (symbol == null) {
+ throw new WebApplicationException(NOT_FOUND);
+ } else {
+ MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers, APPLICATION_JSON_TYPE);
+ return Response.ok(symbol, acceptedMediaType).build();
+ }
}
+
@GET
@Path("/lookup")
- @Produces({MediaType.APPLICATION_JSON,SupportedFormat.RDF_XML,SupportedFormat.N3,
- SupportedFormat.TURTLE,SupportedFormat.X_TURTLE,SupportedFormat.RDF_JSON,
- SupportedFormat.N_TRIPLE})
- public Response lookupSymbol(
- @QueryParam("id") String reference,
- @QueryParam("create") boolean create,
- @Context HttpHeaders headers)
- throws WebApplicationException{
- log.info("/symbol/lookup Request");
- log.info(" > id: "+reference);
- log.info(" > create : "+create);
- log.info(" > accept: "+headers.getAcceptableMediaTypes());
- if(reference == null || reference.isEmpty()){
- //TODO: how to parse an error message
- throw new WebApplicationException(Response.Status.BAD_REQUEST);
- }
- Symbol symbol;
- try {
- symbol = rick.lookupSymbol(reference,create);
- } catch (RickException e) {
- throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
- }
- if(symbol == null){
- throw new WebApplicationException(404);
- } else {
- MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers,MediaType.APPLICATION_JSON_TYPE);
- return Response.ok(symbol,acceptedMediaType).build();
- }
+ @Produces({APPLICATION_JSON, RDF_XML, N3, TURTLE, X_TURTLE, RDF_JSON, N_TRIPLE})
+ public Response lookupSymbol(@QueryParam("id") String reference, @QueryParam("create") boolean create,
+ @Context HttpHeaders headers) throws WebApplicationException {
+ log.info("/symbol/lookup Request");
+ log.info(" > id: " + reference);
+ log.info(" > create : " + create);
+ log.info(" > accept: " + headers.getAcceptableMediaTypes());
+ if (reference == null || reference.isEmpty()) {
+ //TODO: how to parse an error message
+ throw new WebApplicationException(BAD_REQUEST);
+ }
+ Symbol symbol;
+ try {
+ symbol = rick.lookupSymbol(reference, create);
+ } catch (RickException e) {
+ throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
+ }
+ if (symbol == null) {
+ throw new WebApplicationException(404);
+ } else {
+ MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers, APPLICATION_JSON_TYPE);
+ return Response.ok(symbol, acceptedMediaType).build();
+ }
}
+
@POST
@Path("/find")
- @Produces({MediaType.APPLICATION_JSON,SupportedFormat.RDF_XML,SupportedFormat.N3,
- SupportedFormat.TURTLE,SupportedFormat.X_TURTLE,SupportedFormat.RDF_JSON,
- SupportedFormat.N_TRIPLE})
- public Response findEntity(
- @FormParam(value="name") String name,
- @FormParam(value="field") String field,
- @FormParam(value="lang") String language,
- @FormParam(value="select") String select,
- @Context HttpHeaders headers) {
- log.info("symbol/find Request");
- log.info(" > name : "+name);
- log.info(" > field : "+field);
- log.info(" > lang : "+language);
- log.info(" > select: "+select);
- log.info(" > accept: "+headers.getAcceptableMediaTypes());
- //TODO: Implement by using EntityQuery as soon as implemented
- if(name == null || name.isEmpty()){
- log.error("/find Request with invalied name={}!",name);
- }
- if(field == null || field.isEmpty()){
- field = DEFAULT_FIND_FIELD;
- }
- FieldQuery query = new FieldQueryImpl();
- if(language == null){
- query.setConstraint(field, new TextConstraint(name,PatternType.wildcard,false));
- } else {
- query.setConstraint(field, new TextConstraint(name,PatternType.wildcard,false,language));
- }
- Collection<String> selectedFields = new ArrayList<String>();
- selectedFields.add(field); //select also the field used to find entities
- if(select == null ||select.isEmpty()){
- selectedFields.addAll(DEFAULT_FIND_SELECTED_FIELDS);
- } else {
- for(String selected : select.trim().split(" ")){
- if(selected != null && !selected.isEmpty()){
- selectedFields.add(selected);
- }
- }
- }
- query.addSelectedFields(selectedFields);
- final MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers,MediaType.APPLICATION_JSON_TYPE);
- try {
- return Response.ok(rick.find(query),acceptedMediaType).build();
- } catch (Exception e) {
- log.error("Error while accessing RickYard "+rick.getRickYard().getName()+" (id="+rick.getRickYard().getId()+")",e);
- throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
- }
+ @Produces({APPLICATION_JSON, RDF_XML, N3, TURTLE, X_TURTLE, RDF_JSON, N_TRIPLE})
+ public Response findEntity(@FormParam(value = "name") String name, @FormParam(value = "field") String field,
+ @FormParam(value = "lang") String language, @FormParam(value = "select") String select, @Context HttpHeaders headers) {
+ log.info("symbol/find Request");
+ log.info(" > name : " + name);
+ log.info(" > field : " + field);
+ log.info(" > lang : " + language);
+ log.info(" > select: " + select);
+ log.info(" > accept: " + headers.getAcceptableMediaTypes());
+ //TODO: Implement by using EntityQuery as soon as implemented
+ if (name == null || name.isEmpty()) {
+ log.error("/find Request with invalied name={}!", name);
+ }
+ if (field == null || field.isEmpty()) {
+ field = DEFAULT_FIND_FIELD;
+ }
+ FieldQuery query = new FieldQueryImpl();
+ if (language == null) {
+ query.setConstraint(field, new TextConstraint(name, PatternType.wildcard, false));
+ } else {
+ query.setConstraint(field, new TextConstraint(name, PatternType.wildcard, false, language));
+ }
+ Collection<String> selectedFields = new ArrayList<String>();
+ selectedFields.add(field); //select also the field used to find entities
+ if (select == null || select.isEmpty()) {
+ selectedFields.addAll(DEFAULT_FIND_SELECTED_FIELDS);
+ } else {
+ for (String selected : select.trim().split(" ")) {
+ if (selected != null && !selected.isEmpty()) {
+ selectedFields.add(selected);
+ }
+ }
+ }
+ query.addSelectedFields(selectedFields);
+ final MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers, APPLICATION_JSON_TYPE);
+ try {
+ return Response.ok(rick.find(query), acceptedMediaType).build();
+ } catch (Exception e) {
+ log.error("Error while accessing RickYard " + rick.getRickYard().getName() + " (id=" + rick.getRickYard().getId() + ")", e);
+ throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
+ }
}
+
@DELETE
@Path("/{id}")
- @Produces({MediaType.APPLICATION_JSON,SupportedFormat.RDF_XML,SupportedFormat.N3,
- SupportedFormat.TURTLE,SupportedFormat.X_TURTLE,SupportedFormat.RDF_JSON,
- SupportedFormat.N_TRIPLE})
- public Response removeSymbol(){
- return null;
+ @Produces({APPLICATION_JSON, RDF_XML, N3, TURTLE, X_TURTLE, RDF_JSON, N_TRIPLE})
+ public Response removeSymbol() {
+ return null;
}
}
Modified: incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/resource/SiteManagerRootResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/resource/SiteManagerRootResource.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/resource/SiteManagerRootResource.java (original)
+++ incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/resource/SiteManagerRootResource.java Sun Dec 12 15:13:35 2010
@@ -22,7 +22,6 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.apache.clerezza.rdf.core.serializedform.Serializer;
-import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
import org.apache.clerezza.rdf.ontologies.RDFS;
import org.codehaus.jettison.json.JSONArray;
import org.slf4j.Logger;
@@ -36,11 +35,16 @@ import eu.iksproject.rick.servicesapi.qu
import eu.iksproject.rick.servicesapi.query.TextConstraint.PatternType;
import eu.iksproject.rick.servicesapi.site.ReferencedSiteManager;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
+import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
+import static javax.ws.rs.core.Response.Status.NOT_FOUND;
+import static org.apache.clerezza.rdf.core.serializedform.SupportedFormat.*;
+
/**
- * Resource to provide a REST API for the {@link ReferencedSiteManager}
+ * Resource to provide a REST API for the {@link ReferencedSiteManager}.
*
* TODO: add description
- *
*/
@Path("/sites")
public class SiteManagerRootResource extends NavigationMixin {
@@ -48,150 +52,149 @@ public class SiteManagerRootResource ext
private final Logger log = LoggerFactory.getLogger(getClass());
public static final Set<String> RDF_MEDIA_TYPES = new TreeSet<String>(
- Arrays.asList(SupportedFormat.N3, SupportedFormat.N_TRIPLE,
- SupportedFormat.RDF_XML, SupportedFormat.TURTLE,
- SupportedFormat.X_TURTLE, SupportedFormat.RDF_JSON));
+ Arrays.asList(N3, N_TRIPLE, RDF_XML, TURTLE, X_TURTLE, RDF_JSON));
+
/**
* The Field used for find requests if not specified
* TODO: Will be depreciated as soon as EntityQuery is implemented
*/
- private static final String DEFAULT_FIND_FIELD = RDFS.label.getUnicodeString();
+ private static final String DEFAULT_FIND_FIELD = RDFS.label.getUnicodeString();
+
+ /**
+ * The default number of maximal results of searched sites.
+ */
+ private static final int DEFAULT_FIND_RESULT_LIMIT = 5;
- /**
- * The default number of maximal results of searched sites.
- */
- private static final int DEFAULT_FIND_RESULT_LIMIT = 5;
-
protected Serializer serializer;
- private ReferencedSiteManager referencedSiteManager;
+ private ReferencedSiteManager referencedSiteManager;
- public SiteManagerRootResource(
- @Context ServletContext context) {
- super();
- log.info("... init SiteManagerRootResource");
+ public SiteManagerRootResource(@Context ServletContext context) {
+ super();
+ log.info("... init SiteManagerRootResource");
referencedSiteManager = (ReferencedSiteManager) context.getAttribute(ReferencedSiteManager.class.getName());
serializer = (Serializer) context.getAttribute(Serializer.class.getName());
if (referencedSiteManager == null) {
log.error("Missing referencedSiteManager={}", referencedSiteManager);
- throw new WebApplicationException(Response.Status.NOT_FOUND);
+ throw new WebApplicationException(NOT_FOUND);
}
}
+
/**
* Getter for the id's of all referenced sites
+ *
* @return the id's of all referenced sites.
*/
@GET
- @Path(value="/referenced")
- @Produces(MediaType.APPLICATION_JSON)
- public JSONArray getReferencedSites(@Context UriInfo uriInfo){
- log.info("sites/referenced Request");
- JSONArray referencedSites = new JSONArray();
- for(String site : referencedSiteManager.getReferencedSiteIds()){
- referencedSites.put(String.format("%ssite/%s/",uriInfo.getBaseUri(),site));
- }
- log.info(" ... return "+referencedSites.toString());
- return referencedSites;
+ @Path(value = "/referenced")
+ @Produces(APPLICATION_JSON)
+ public JSONArray getReferencedSites(@Context UriInfo uriInfo) {
+ log.info("sites/referenced Request");
+ JSONArray referencedSites = new JSONArray();
+ for (String site : referencedSiteManager.getReferencedSiteIds()) {
+ referencedSites.put(String.format("%ssite/%s/", uriInfo.getBaseUri(), site));
+ }
+ log.info(" ... return " + referencedSites.toString());
+ return referencedSites;
}
+
/**
- * Cool URI handler for Signs.
+ * Cool URI handler for Signs.
*
- * @param id The id of the entity (required)
+ * @param id The id of the entity (required)
* @param headers the request headers used to get the requested {@link MediaType}
* @return a redirection to either a browser view, the RDF meta data or the
* raw binary content
*/
@GET
@Path("/entity")
- public Response getSignById(
- @QueryParam(value= "id") String id,
- @Context HttpHeaders headers) {
- log.info("sites/entity Request");
- log.info(" > id : "+id);
- log.info(" > accept : "+headers.getAcceptableMediaTypes());
- log.info(" > mediaType: "+headers.getMediaType());
- if(id == null || id.isEmpty()){
- log.error("No or emptpy ID was parsd as query parameter (id={})",id);
- throw new WebApplicationException(Response.Status.BAD_REQUEST);
- }
- Sign sign;
-// try {
- sign = referencedSiteManager.getSign(id);
-// } catch (IOException e) {
-// log.error("IOException while accessing ReferencedSiteManager",e);
-// throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
-// }
- final MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers,MediaType.APPLICATION_JSON_TYPE);
- if(sign != null){
- return Response.ok(sign, acceptedMediaType).build();
- } else {
- //TODO: How to parse an ErrorMessage?
- // create an Response with the the Error?
- log.info(" ... Entity {} not found on any referenced site");
- throw new WebApplicationException(Response.Status.NOT_FOUND);
- }
+ public Response getSignById(@QueryParam(value = "id") String id, @Context HttpHeaders headers) {
+ log.info("sites/entity Request");
+ log.info(" > id : " + id);
+ log.info(" > accept : " + headers.getAcceptableMediaTypes());
+ log.info(" > mediaType: " + headers.getMediaType());
+ if (id == null || id.isEmpty()) {
+ log.error("No or emptpy ID was parsed as query parameter (id={})", id);
+ throw new WebApplicationException(BAD_REQUEST);
+ }
+ Sign sign;
+// try {
+ sign = referencedSiteManager.getSign(id);
+// } catch (IOException e) {
+// log.error("IOException while accessing ReferencedSiteManager",e);
+// throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
+// }
+ final MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers, APPLICATION_JSON_TYPE);
+ if (sign != null) {
+ return Response.ok(sign, acceptedMediaType).build();
+ } else {
+ //TODO: How to parse an ErrorMessage?
+ // create an Response with the the Error?
+ log.info(" ... Entity {} not found on any referenced site");
+ throw new WebApplicationException(NOT_FOUND);
+ }
}
+
@GET
@Path("/find")
- public Response findEntityfromGet(
- @QueryParam(value="name") String name,
- //@FormParam(value="field") String field,
- @QueryParam(value="lang") String language,
- //@FormParam(value="select") String select,
- @QueryParam(value="limit") @DefaultValue(value="-1")int limit,
- @QueryParam(value="offset") @DefaultValue(value="0") int offset,
- @Context HttpHeaders headers) {
- return findEntity(name, language, limit, offset, headers);
+ public Response findEntityfromGet(@QueryParam(value = "name") String name,
+ //@FormParam(value="field") String field,
+ @QueryParam(value = "lang") String language,
+ //@FormParam(value="select") String select,
+ @QueryParam(value = "limit") @DefaultValue(value = "-1") int limit,
+ @QueryParam(value = "offset") @DefaultValue(value = "0") int offset,
+ @Context HttpHeaders headers) {
+ return findEntity(name, language, limit, offset, headers);
}
+
@POST
@Path("/find")
- public Response findEntity(
- @FormParam(value="name") String name,
- //@FormParam(value="field") String field,
- @FormParam(value="lang") String language,
- //@FormParam(value="select") String select,
- @FormParam(value="limit") @DefaultValue(value="-1")int limit,
- @FormParam(value="offset") @DefaultValue(value="0") int offset,
+ public Response findEntity(@FormParam(value = "name") String name,
+ //@FormParam(value="field") String field,
+ @FormParam(value = "lang") String language,
+ //@FormParam(value="select") String select,
+ @FormParam(value = "limit") @DefaultValue(value = "-1") int limit,
+ @FormParam(value = "offset") @DefaultValue(value = "0") int offset,
@Context HttpHeaders headers) {
- log.info("sites/find Request");
- log.info(" > name : "+name);
- log.info(" > lang : "+language);
- log.info(" > limit : "+limit);
- log.info(" > offset: "+offset);
- log.info(" > accept: "+headers.getAcceptableMediaTypes());
- if(name == null || name.isEmpty()){
- log.error("/find Request with invalied name={}!",name);
- }
- String field = DEFAULT_FIND_FIELD;
- FieldQuery query = new FieldQueryImpl();
- if(language == null){
- query.setConstraint(field, new TextConstraint(name,PatternType.wildcard,false));
- } else {
- query.setConstraint(field, new TextConstraint(name,PatternType.wildcard,false,language));
- }
- Collection<String> selectedFields = new ArrayList<String>();
- selectedFields.add(field); //select also the field used to find entities
-// if(select == null ||select.isEmpty()){
-// selectedFields.addAll(DEFAULT_FIND_SELECTED_FIELDS);
-// } else {
-// for(String selected : select.trim().split(" ")){
-// if(selected != null && !selected.isEmpty()){
-// selectedFields.add(selected);
-// }
-// }
-// }
- query.addSelectedFields(selectedFields);
- if(limit < 1){
- limit = DEFAULT_FIND_RESULT_LIMIT;
- }
- query.setLimit(limit);
- query.setOffset(offset);
- final MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers,MediaType.APPLICATION_JSON_TYPE);
-// try {
- return Response.ok(referencedSiteManager.find(query),acceptedMediaType).build();
-// } catch (IOException e) {
-// log.error("IOException while accessing Referenced Site Manager",e);
-// throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
-// }
+ log.info("sites/find Request");
+ log.info(" > name : " + name);
+ log.info(" > lang : " + language);
+ log.info(" > limit : " + limit);
+ log.info(" > offset: " + offset);
+ log.info(" > accept: " + headers.getAcceptableMediaTypes());
+ if (name == null || name.isEmpty()) {
+ log.error("/find Request with invalid name={}!", name);
+ }
+ String field = DEFAULT_FIND_FIELD;
+ FieldQuery query = new FieldQueryImpl();
+ if (language == null) {
+ query.setConstraint(field, new TextConstraint(name, PatternType.wildcard, false));
+ } else {
+ query.setConstraint(field, new TextConstraint(name, PatternType.wildcard, false, language));
+ }
+ Collection<String> selectedFields = new ArrayList<String>();
+ selectedFields.add(field); //select also the field used to find entities
+// if(select == null ||select.isEmpty()){
+// selectedFields.addAll(DEFAULT_FIND_SELECTED_FIELDS);
+// } else {
+// for(String selected : select.trim().split(" ")){
+// if(selected != null && !selected.isEmpty()){
+// selectedFields.add(selected);
+// }
+// }
+// }
+ query.addSelectedFields(selectedFields);
+ if (limit < 1) {
+ limit = DEFAULT_FIND_RESULT_LIMIT;
+ }
+ query.setLimit(limit);
+ query.setOffset(offset);
+ final MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers, APPLICATION_JSON_TYPE);
+// try {
+ return Response.ok(referencedSiteManager.find(query), acceptedMediaType).build();
+// } catch (IOException e) {
+// log.error("IOException while accessing Referenced Site Manager",e);
+// throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
+// }
}
}
Modified: incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/utils/JerseyUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/utils/JerseyUtils.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/utils/JerseyUtils.java (original)
+++ incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/utils/JerseyUtils.java Sun Dec 12 15:13:35 2010
@@ -4,31 +4,33 @@ import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
public final class JerseyUtils {
- private JerseyUtils() {/* do not create instance of Util Classes */}
- /**
- * Searches the Header for acceptable media types and returns the first found
- * that is not the wildcard type. If no one is found the parsed default type
- * is returned.
- * @param headers the request headers
- * @param defaultType the default type if no or only the wildcard type was found in
- * the header
- * @return the acceptable media type
- */
- public static MediaType getAcceptableMediaType(HttpHeaders headers, MediaType defaultType) {
- MediaType acceptedMediaType = null;
- if(!headers.getAcceptableMediaTypes().isEmpty()){
- for(MediaType accepted : headers.getAcceptableMediaTypes()){
- if(!accepted.isWildcardType()){
- acceptedMediaType = accepted;
- break;
- }
- }
- }
- if(acceptedMediaType == null){
- acceptedMediaType = defaultType;
- }
- return acceptedMediaType;
- }
+ private JerseyUtils() {/* do not create instance of Util Classes */}
+
+ /**
+ * Searches the Header for acceptable media types and returns the first found
+ * that is not the wildcard type. If no one is found the parsed default type
+ * is returned.
+ *
+ * @param headers the request headers
+ * @param defaultType the default type if no or only the wildcard type was found in
+ * the header
+ * @return the acceptable media type
+ */
+ public static MediaType getAcceptableMediaType(HttpHeaders headers, MediaType defaultType) {
+ MediaType acceptedMediaType = null;
+ if (!headers.getAcceptableMediaTypes().isEmpty()) {
+ for (MediaType accepted : headers.getAcceptableMediaTypes()) {
+ if (!accepted.isWildcardType()) {
+ acceptedMediaType = accepted;
+ break;
+ }
+ }
+ }
+ if (acceptedMediaType == null) {
+ acceptedMediaType = defaultType;
+ }
+ return acceptedMediaType;
+ }
}
Modified: incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/writers/FieldQueryToJSON.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/writers/FieldQueryToJSON.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/writers/FieldQueryToJSON.java (original)
+++ incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/writers/FieldQueryToJSON.java Sun Dec 12 15:13:35 2010
@@ -16,70 +16,74 @@ import eu.iksproject.rick.servicesapi.qu
final class FieldQueryToJSON {
- private FieldQueryToJSON() { /* do not create instances of utility classes */}
+ private FieldQueryToJSON() { /* do not create instances of utility classes */}
- private static Logger log = LoggerFactory.getLogger(FieldQueryToJSON.class);
- /**
- * Converts a {@link FieldQuery} to it's JSON representation
- * @param query the Query
- * @return the {@link JSONObject}
- * @throws JSONException
- */
- static JSONObject toJSON(FieldQuery query) throws JSONException{
- JSONObject jQuery = new JSONObject();
- jQuery.put("selected", new JSONArray(query.getSelectedFields()));
- JSONArray constraints = new JSONArray();
- jQuery.put("constraints", constraints);
- for(Entry<String,Constraint> fieldConstraint:query){
- JSONObject jFieldConstraint = convertConstraintToJSON(fieldConstraint.getValue());
- jFieldConstraint.put("field", fieldConstraint.getKey()); //add the field
- constraints.put(jFieldConstraint); //add fieldConstraint
- }
- return jQuery;
- }
- /**
- * Converts a {@link Constraint} to JSON
- * @param constraint the {@link Constraint}
- * @return the JSON representation
- * @throws JSONException
- */
- private static JSONObject convertConstraintToJSON(Constraint constraint) throws JSONException {
- JSONObject jConstraint = new JSONObject();
- jConstraint.put("type", constraint.getType().name());
- switch (constraint.getType()) {
- case value:
- ValueConstraint valueConstraint = ((ValueConstraint)constraint);
- if(valueConstraint.getValue()!=null){
- jConstraint.put("vakue", valueConstraint.getValue());
- }
- if(valueConstraint.getDataTypes() != null && !valueConstraint.getDataTypes().isEmpty()){
- jConstraint.put("dataTypes", valueConstraint.getDataTypes());
- }
- break;
- case text:
- TextConstraint textConstraint = (TextConstraint)constraint;
- if(textConstraint.getLanguages() != null && !textConstraint.getLanguages().isEmpty()){
- jConstraint.put("languages", new JSONArray(textConstraint.getLanguages()));
- }
- jConstraint.put("patternType", textConstraint.getPatternType().name());
- if(textConstraint.getText() != null && !textConstraint.getText().isEmpty()){
- jConstraint.put("text", textConstraint.getText());
- }
- break;
- case range:
- RangeConstraint rangeConstraint = (RangeConstraint)constraint;
- if(rangeConstraint.getLowerBound() != null){
- jConstraint.put("lowerBound", rangeConstraint.getLowerBound().toString());
- }
- if(rangeConstraint.getUpperBound() != null){
- jConstraint.put("upperBound", rangeConstraint.getUpperBound().toString());
- }
- jConstraint.put("inclusive", rangeConstraint.isInclusive());
- default:
- //unknown constraint type
- log.warn("Unsupported Constriant Type "+constraint.getType()+" (implementing class="+constraint.getClass()+"| toString="+constraint+") -> skiped");
- break;
- }
- return jConstraint;
- }
+ private static Logger log = LoggerFactory.getLogger(FieldQueryToJSON.class);
+
+ /**
+ * Converts a {@link FieldQuery} to it's JSON representation
+ *
+ * @param query the Query
+ * @return the {@link JSONObject}
+ * @throws JSONException
+ */
+ static JSONObject toJSON(FieldQuery query) throws JSONException {
+ JSONObject jQuery = new JSONObject();
+ jQuery.put("selected", new JSONArray(query.getSelectedFields()));
+ JSONArray constraints = new JSONArray();
+ jQuery.put("constraints", constraints);
+ for (Entry<String, Constraint> fieldConstraint : query) {
+ JSONObject jFieldConstraint = convertConstraintToJSON(fieldConstraint.getValue());
+ jFieldConstraint.put("field", fieldConstraint.getKey()); //add the field
+ constraints.put(jFieldConstraint); //add fieldConstraint
+ }
+ return jQuery;
+ }
+
+ /**
+ * Converts a {@link Constraint} to JSON
+ *
+ * @param constraint the {@link Constraint}
+ * @return the JSON representation
+ * @throws JSONException
+ */
+ private static JSONObject convertConstraintToJSON(Constraint constraint) throws JSONException {
+ JSONObject jConstraint = new JSONObject();
+ jConstraint.put("type", constraint.getType().name());
+ switch (constraint.getType()) {
+ case value:
+ ValueConstraint valueConstraint = ((ValueConstraint) constraint);
+ if (valueConstraint.getValue() != null) {
+ jConstraint.put("vakue", valueConstraint.getValue());
+ }
+ if (valueConstraint.getDataTypes() != null && !valueConstraint.getDataTypes().isEmpty()) {
+ jConstraint.put("dataTypes", valueConstraint.getDataTypes());
+ }
+ break;
+ case text:
+ TextConstraint textConstraint = (TextConstraint) constraint;
+ if (textConstraint.getLanguages() != null && !textConstraint.getLanguages().isEmpty()) {
+ jConstraint.put("languages", new JSONArray(textConstraint.getLanguages()));
+ }
+ jConstraint.put("patternType", textConstraint.getPatternType().name());
+ if (textConstraint.getText() != null && !textConstraint.getText().isEmpty()) {
+ jConstraint.put("text", textConstraint.getText());
+ }
+ break;
+ case range:
+ RangeConstraint rangeConstraint = (RangeConstraint) constraint;
+ if (rangeConstraint.getLowerBound() != null) {
+ jConstraint.put("lowerBound", rangeConstraint.getLowerBound().toString());
+ }
+ if (rangeConstraint.getUpperBound() != null) {
+ jConstraint.put("upperBound", rangeConstraint.getUpperBound().toString());
+ }
+ jConstraint.put("inclusive", rangeConstraint.isInclusive());
+ default:
+ //unknown constraint type
+ log.warn("Unsupported Constriant Type " + constraint.getType() + " (implementing class=" + constraint.getClass() + "| toString=" + constraint + ") -> skiped");
+ break;
+ }
+ return jConstraint;
+ }
}
Modified: incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/writers/JettisonWriter.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/writers/JettisonWriter.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/writers/JettisonWriter.java (original)
+++ incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/writers/JettisonWriter.java Sun Dec 12 15:13:35 2010
@@ -15,24 +15,24 @@ import org.codehaus.jettison.json.JSONOb
public class JettisonWriter implements MessageBodyWriter<Object> {
- @Override
+ @Override
public long getSize(Object result, Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType) {
- return -1;
- }
+ return -1;
+ }
- @Override
+ @Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
- return (type.equals(JSONArray.class) || type.equals(JSONObject.class)) &&
- mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE);
- }
+ return (type.equals(JSONArray.class) || type.equals(JSONObject.class)) &&
+ mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE);
+ }
- @Override
- public void writeTo(Object value, Class<?> __doNotUse, Type genericType,
- Annotation[] annotations, MediaType mediaType,
- MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
- throws IOException, WebApplicationException {
- entityStream.write(value.toString().getBytes("UTF-8"));
- }
+ @Override
+ public void writeTo(Object value, Class<?> __doNotUse, Type genericType,
+ Annotation[] annotations, MediaType mediaType,
+ MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
+ throws IOException, WebApplicationException {
+ entityStream.write(value.toString().getBytes("UTF-8"));
+ }
}
Modified: incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/writers/QueryResultListWriter.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/writers/QueryResultListWriter.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/writers/QueryResultListWriter.java (original)
+++ incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/writers/QueryResultListWriter.java Sun Dec 12 15:13:35 2010
@@ -25,76 +25,78 @@ import org.slf4j.LoggerFactory;
import eu.iksproject.rick.servicesapi.query.QueryResultList;
-/**
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
+import static org.apache.clerezza.rdf.core.serializedform.SupportedFormat.*;
+import static org.apache.clerezza.rdf.core.serializedform.SupportedFormat.RDF_JSON;
+import static org.apache.clerezza.rdf.core.serializedform.SupportedFormat.X_TURTLE;
+
+/**
* TODO: Replace with Serializer infrastructure similar to {@link Serializer}
*/
@Provider
-@Produces({ MediaType.APPLICATION_JSON, SupportedFormat.N3,
- SupportedFormat.N_TRIPLE, SupportedFormat.RDF_XML,
- SupportedFormat.TURTLE, SupportedFormat.X_TURTLE,
- SupportedFormat.RDF_JSON })
+@Produces({APPLICATION_JSON, N3, N_TRIPLE, RDF_XML, TURTLE, X_TURTLE, RDF_JSON})
public class QueryResultListWriter implements MessageBodyWriter<QueryResultList<?>> {
- private final Logger log = LoggerFactory.getLogger(QueryResultListWriter.class);
+ private final Logger log = LoggerFactory.getLogger(QueryResultListWriter.class);
@Context
protected ServletContext servletContext;
protected Serializer getSerializer() {
return (Serializer) servletContext.getAttribute(Serializer.class.getName());
}
- @Override
- public long getSize(QueryResultList<?> result, Class<?> type, Type genericType,
- Annotation[] annotations, MediaType mediaType) {
+
+ @Override
+ public long getSize(QueryResultList<?> result, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return -1;
}
- @Override
+ @Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
- //TODO: The type is also parsed as genericType ... so we can only check
- //for the type :(
- return QueryResultList.class.isAssignableFrom(type);
+ //TODO: The type is also parsed as genericType ... so we can only check
+ //for the type :(
+ return QueryResultList.class.isAssignableFrom(type);
// if(QueryResultList.class.isAssignableFrom(type) &&
-// genericType != null && //QueryResult is always a generic Type
-// genericType instanceof Class<?>){ //and such types do not use generics
-// //This writer supports String, Representation and all types of Signs
-// Class<?> genericClass = (Class<?>) genericType;
-//
-// if(String.class.isAssignableFrom(genericClass) ||
-// Representation.class.isAssignableFrom(genericClass) ||
-// Sign.class.isAssignableFrom(genericClass)){
-// //maybe we need further checks if we do not support all data types
-// //for all generic types! But currently all different types of
-// //QueryResultList support all the different MediaTypes!
-// return true;
-// }
+// genericType != null && //QueryResult is always a generic Type
+// genericType instanceof Class<?>){ //and such types do not use generics
+// //This writer supports String, Representation and all types of Signs
+// Class<?> genericClass = (Class<?>) genericType;
+//
+// if(String.class.isAssignableFrom(genericClass) ||
+// Representation.class.isAssignableFrom(genericClass) ||
+// Sign.class.isAssignableFrom(genericClass)){
+// //maybe we need further checks if we do not support all data types
+// //for all generic types! But currently all different types of
+// //QueryResultList support all the different MediaTypes!
+// return true;
+// }
// }
-// log.info("Request for not writeable combination: type="+type+"|genericType="+genericType+"|mediaType="+mediaType);
-// return false;
+// log.info("Request for not writeable combination: type="+type+"|genericType="+genericType+"|mediaType="+mediaType);
+// return false;
}
- @Override
- public void writeTo(QueryResultList<?> resultList, Class<?> __doNotUse, Type genericType,
- Annotation[] annotations, MediaType mediaType,
- MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
- throws IOException, WebApplicationException {
- Class<?> genericClass = (Class<?>) genericType;
- if(MediaType.APPLICATION_JSON.equals(mediaType.toString())){
- try {
- IOUtils.write(QueryResultsToJSON.toJSON(resultList).toString(4),entityStream);
- } catch (JSONException e) {
- throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
- }
- } else { //RDF
- /*
- * TODO: We would need to add the query to the RDF Result.
- * Currently not implemented, because I do not want to create
- * a triple version of the query and there is not yet String
- * representation defined for FieldQuery
- */
- MGraph resultGraph = QueryResultsToRDF.toRDF(resultList);
- getSerializer().serialize(entityStream, resultGraph, mediaType.toString());
- }
- }
-
-
+ @Override
+ public void writeTo(QueryResultList<?> resultList, Class<?> __doNotUse, Type genericType,
+ Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders,
+ OutputStream entityStream) throws IOException, WebApplicationException {
+ Class<?> genericClass = (Class<?>) genericType;
+ if (APPLICATION_JSON.equals(mediaType.toString())) {
+ try {
+ IOUtils.write(QueryResultsToJSON.toJSON(resultList).toString(4), entityStream);
+ } catch (JSONException e) {
+ throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
+ }
+ } else { //RDF
+ /*
+ * TODO: We would need to add the query to the RDF Result.
+ * Currently not implemented, because I do not want to create
+ * a triple version of the query and there is not yet String
+ * representation defined for FieldQuery
+ */
+ MGraph resultGraph = QueryResultsToRDF.toRDF(resultList);
+ getSerializer().serialize(entityStream, resultGraph, mediaType.toString());
+ }
+ }
+
+
}
Modified: incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/writers/QueryResultsToJSON.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/writers/QueryResultsToJSON.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/writers/QueryResultsToJSON.java (original)
+++ incubator/stanbol/trunk/rick/jersey/src/main/java/eu/iksproject/rick/jersey/writers/QueryResultsToJSON.java Sun Dec 12 15:13:35 2010
@@ -9,33 +9,33 @@ import eu.iksproject.rick.servicesapi.mo
import eu.iksproject.rick.servicesapi.query.QueryResultList;
final class QueryResultsToJSON {
-
- private QueryResultsToJSON() { /* do not create instances of utility classes */}
- static <T> JSONObject toJSON(QueryResultList<?> resultList) throws JSONException{
- JSONObject jResultList = new JSONObject();
- if(resultList.getQuery() != null){
- jResultList.put("query", FieldQueryToJSON.toJSON(resultList.getQuery()));
- }
- jResultList.put("results", convertResultsToJSON(resultList,resultList.getType()));
- return jResultList;
- }
-
- private static <T> JSONArray convertResultsToJSON(Iterable<?> results,Class<?> type) throws JSONException{
- JSONArray jResults = new JSONArray();
- if(String.class.isAssignableFrom(type)){
- for(Object result : results){
- jResults.put(result);
- }
- } else if(Representation.class.isAssignableFrom(type)){
- for(Object result : results){
- jResults.put(SignToJSON.toJSON((Representation)result));
- }
- } else if(Sign.class.isAssignableFrom(type)){
- for(Object result : results){
- jResults.put(SignToJSON.toJSON((Sign)result));
- }
- }
- return jResults;
- }
+ private QueryResultsToJSON() { /* do not create instances of utility classes */}
+
+ static <T> JSONObject toJSON(QueryResultList<?> resultList) throws JSONException{
+ JSONObject jResultList = new JSONObject();
+ if(resultList.getQuery() != null){
+ jResultList.put("query", FieldQueryToJSON.toJSON(resultList.getQuery()));
+ }
+ jResultList.put("results", convertResultsToJSON(resultList,resultList.getType()));
+ return jResultList;
+ }
+
+ private static <T> JSONArray convertResultsToJSON(Iterable<?> results,Class<?> type) throws JSONException{
+ JSONArray jResults = new JSONArray();
+ if(String.class.isAssignableFrom(type)){
+ for(Object result : results){
+ jResults.put(result);
+ }
+ } else if(Representation.class.isAssignableFrom(type)){
+ for(Object result : results){
+ jResults.put(SignToJSON.toJSON((Representation)result));
+ }
+ } else if(Sign.class.isAssignableFrom(type)){
+ for(Object result : results){
+ jResults.put(SignToJSON.toJSON((Sign)result));
+ }
+ }
+ return jResults;
+ }
}