You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by su...@apache.org on 2011/08/25 17:05:59 UTC
svn commit: r1161596 -
/incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/RDFMapperResource.java
Author: suat
Date: Thu Aug 25 15:05:59 2011
New Revision: 1161596
URL: http://svn.apache.org/viewvc?rev=1161596&view=rev
Log:
STANBOL 306:
-Added REST service which provides generating RDF from content repository
Modified:
incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/RDFMapperResource.java
Modified: incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/RDFMapperResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/RDFMapperResource.java?rev=1161596&r1=1161595&r2=1161596&view=diff
==============================================================================
--- incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/RDFMapperResource.java (original)
+++ incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/RDFMapperResource.java Thu Aug 25 15:05:59 2011
@@ -4,17 +4,17 @@ import java.io.ByteArrayInputStream;
import javax.servlet.ServletContext;
import javax.ws.rs.Consumes;
-import javax.ws.rs.DefaultValue;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
-import javax.ws.rs.QueryParam;
+import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.MGraph;
import org.apache.clerezza.rdf.core.serializedform.Parser;
import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
import org.apache.stanbol.cmsadapter.core.mapping.RDFBridgeManager;
@@ -30,10 +30,10 @@ import org.slf4j.LoggerFactory;
/**
* This resource is currently used to pass RDF data to CMS Adapter so that RDF data will be annotated with
* "CMS vocabulary" annotations according to {@link RDFBridge}s. Afterwards, this annotated RDF is transformed
- * into nodes/object in the repository.
+ * into nodes/object in the content repository.
*/
-@Path("/cmsadapter/rdfmap")
+@Path("/cmsadapter/map")
public class RDFMapperResource extends BaseStanbolResource {
private static final Logger logger = LoggerFactory.getLogger(RDFMapperResource.class);
private Parser clerezzaParser;
@@ -50,10 +50,10 @@ public class RDFMapperResource extends B
*
* @param connectionInfo
* is the object that holds all necessary information to connect repository. Example connection
- * info XML:<br>
- * <br>
+ * info XML:
*
* <pre>
+ * <font size="3">
* <?xml version="1.0" encoding="UTF-8"?>
* <connectionInfo
* xmlns="web.model.servicesapi.cmsadapter.stanbol.apache.org">
@@ -63,21 +63,20 @@ public class RDFMapperResource extends B
* <password>admin</password>
* <connectionType>JCR</connectionType>
* </connectionInfo>
+ * </font>
* </pre>
* @param serializedGraph
* is the serialized RDF graph that is desired to transformed into repository objects
- * @param rootPath
- * is the path in which root objects in the annotated graph will be created
*/
/*
* TODO: It would be wise to get as MGraph in request data. Before that connection info should be get in a
* different way.
*/
+ @Path("/rdf")
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response mapRDF(@FormParam("connectionInfo") ConnectionInfo connectionInfo,
- @FormParam("serializedGraph") String serializedGraph,
- @QueryParam("rootPath") @DefaultValue("/") String rootPath) {
+ @FormParam("serializedGraph") String serializedGraph) {
if (connectionInfo == null) {
logger.warn("There is no valid connection info specified");
@@ -92,7 +91,7 @@ public class RDFMapperResource extends B
Graph g = clerezzaParser.parse(new ByteArrayInputStream(serializedGraph.getBytes()),
SupportedFormat.RDF_XML);
try {
- bridgeManager.storeRDFToRepository(connectionInfo, rootPath, g);
+ bridgeManager.storeRDFToRepository(connectionInfo, g);
} catch (RepositoryAccessException e) {
logger.warn("Failed to obtain a session from repository", e);
return Response.status(Status.INTERNAL_SERVER_ERROR)
@@ -104,4 +103,52 @@ public class RDFMapperResource extends B
return Response.ok().build();
}
+ /**
+ * This service provides obtaining an RDF from the content repository based on the {@link RDFBridge}
+ * instances in the environment. Target content repository parts are determined according to path
+ * configurations of RDF Bridges.
+ *
+ * @param connectionInfo
+ * is the object that holds all necessary information to connect repository. Example connection
+ * info XML:
+ *
+ * <pre>
+ * <font size="3">
+ * <?xml version="1.0" encoding="UTF-8"?>
+ * <connectionInfo
+ * xmlns="web.model.servicesapi.cmsadapter.stanbol.apache.org">
+ * <repositoryURL>rmi://localhost:1099/crx</repositoryURL>
+ * <workspaceName>demo</workspaceName>
+ * <username>admin</username>
+ * <password>admin</password>
+ * <connectionType>JCR</connectionType>
+ * </connectionInfo>
+ * </font>
+ * </pre>
+ * @return generated {@link MGraph} wrapped in a {@link Response} in "application/rdf+xml" format
+ */
+ @Path("/cms")
+ @POST
+ @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
+ @Produces(SupportedFormat.RDF_XML)
+ public Response mapCMS(@FormParam("connectionInfo") ConnectionInfo connectionInfo) {
+ if (connectionInfo == null) {
+ logger.warn("There is no valid connection info specified");
+ return Response.status(Status.BAD_REQUEST).entity("There is no valid connection info specified")
+ .build();
+ }
+
+ try {
+ MGraph generatedGraph = bridgeManager.generateRDFFromRepository(connectionInfo);
+ return Response.ok(generatedGraph, SupportedFormat.RDF_XML).build();
+ } catch (RepositoryAccessException e) {
+ logger.warn("Failed to obtain a session from repository", e);
+ return Response.status(Status.INTERNAL_SERVER_ERROR)
+ .entity("Failed to obtain a session from repository").build();
+ } catch (RDFBridgeException e) {
+ logger.warn("Error while generating RDF from repository", e);
+ return Response.status(Status.INTERNAL_SERVER_ERROR)
+ .entity("Error while generating RDF from repository").build();
+ }
+ }
}