You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by al...@apache.org on 2011/03/31 12:36:50 UTC

svn commit: r1087240 - in /incubator/stanbol/trunk/kres: ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/io/ reasoners/base/ rules/base/ rules/manager/ rules/refactor/ rules/web/src/main/java/org/apache/stanbol/rul...

Author: alexdma
Date: Thu Mar 31 10:36:50 2011
New Revision: 1087240

URL: http://svn.apache.org/viewvc?rev=1087240&view=rev
Log:
STANBOL-129 STANBOL-134 :
- ontology storage now manages Clerezza runtime exceptions with replacement policies
- rules/web RESTful resources moved to own java package
- reduced dependencies in rules POMs
- explicitated Stanbol dependencies in reasoners/base

Added:
    incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/
    incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RefactorerResource.java
    incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RestRecipe.java
    incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RestRule.java
    incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RuleStoreResource.java
Modified:
    incubator/stanbol/trunk/kres/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/io/ClerezzaOntologyStorage.java
    incubator/stanbol/trunk/kres/reasoners/base/pom.xml
    incubator/stanbol/trunk/kres/rules/base/pom.xml
    incubator/stanbol/trunk/kres/rules/manager/pom.xml
    incubator/stanbol/trunk/kres/rules/refactor/pom.xml

Modified: incubator/stanbol/trunk/kres/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/io/ClerezzaOntologyStorage.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/io/ClerezzaOntologyStorage.java?rev=1087240&r1=1087239&r2=1087240&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/io/ClerezzaOntologyStorage.java (original)
+++ incubator/stanbol/trunk/kres/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/io/ClerezzaOntologyStorage.java Thu Mar 31 10:36:50 2011
@@ -7,6 +7,7 @@ import java.util.Set;
 
 import org.apache.clerezza.rdf.core.MGraph;
 import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.EntityAlreadyExistsException;
 import org.apache.clerezza.rdf.core.access.TcManager;
 import org.apache.clerezza.rdf.core.access.WeightedTcProvider;
 import org.apache.clerezza.rdf.core.impl.SimpleGraph;
@@ -178,8 +179,16 @@ public class ClerezzaOntologyStorage {
 		OntModel om = converter.ModelOwlToJenaConvert(o, "RDF/XML");
 		MGraph mg = JenaToClerezzaConverter.jenaModelToClerezzaMGraph(om);
 		// MGraph mg = OWLAPIToClerezzaConverter.owlOntologyToClerezzaMGraph(o);
-		MGraph mg2 = tcManager.createMGraph(new UriRef(o.getOntologyID()
-				.getOntologyIRI().toString()));
+		MGraph mg2 = null;
+UriRef ref = new UriRef(o.getOntologyID()
+    .getOntologyIRI().toString());
+		try {
+		mg2 = tcManager.createMGraph(ref);
+		} catch (EntityAlreadyExistsException ex) {
+		    log.info("Entity "+ref+" already exists in store. Replacing...");
+		    mg2 = tcManager.getMGraph(ref);
+		}
+		
 		mg2.addAll(mg);
 	}
 	

Modified: incubator/stanbol/trunk/kres/reasoners/base/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/reasoners/base/pom.xml?rev=1087240&r1=1087239&r2=1087240&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/reasoners/base/pom.xml (original)
+++ incubator/stanbol/trunk/kres/reasoners/base/pom.xml Thu Mar 31 10:36:50 2011
@@ -162,8 +162,21 @@
 		</dependency>
 		<dependency>
 			<groupId>org.apache.stanbol</groupId>
+			<artifactId>org.apache.stanbol.ontologymanager.ontonet</artifactId>
+			<version>${stanbol-version}</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.stanbol</groupId>
+			<artifactId>org.apache.stanbol.rules.base</artifactId>
+			<version>${stanbol-version}</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.stanbol</groupId>
 			<artifactId>org.apache.stanbol.rules.refactor</artifactId>
 			<version>${stanbol-version}</version>
+			<scope>provided</scope>
 		</dependency>
 
 		<!-- Diagnostics deps -->

Modified: incubator/stanbol/trunk/kres/rules/base/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/rules/base/pom.xml?rev=1087240&r1=1087239&r2=1087240&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/rules/base/pom.xml (original)
+++ incubator/stanbol/trunk/kres/rules/base/pom.xml Thu Mar 31 10:36:50 2011
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
+<!-- 
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
@@ -73,62 +73,33 @@
 		</plugins>
 	</build>
 
-	<dependencies>
 
-		<dependency>
-			<groupId>org.apache.stanbol</groupId>
-			<artifactId>org.apache.stanbol.owlapi</artifactId>
-			<version>${stanbol-version}</version>
-		</dependency>
-		<dependency>
-			<groupId>owlapi</groupId>
-			<artifactId>owlapi</artifactId>
-			<version>3.0.0</version>
-		</dependency>
+	<dependencies>
 
 		<!-- OSGi deps -->
 		<dependency>
-			<groupId>org.osgi</groupId>
-			<artifactId>org.osgi.core</artifactId>
-			<version>4.1.0</version>
-			<scope>provided</scope>
-		</dependency>
-		<dependency>
-			<groupId>org.osgi</groupId>
-			<artifactId>org.osgi.compendium</artifactId>
-			<version>4.1.0</version>
-			<scope>provided</scope>
-		</dependency>
-		<dependency>
 			<groupId>org.apache.felix</groupId>
 			<artifactId>org.apache.felix.scr.annotations</artifactId>
 			<version>1.2.0</version>
 			<scope>provided</scope>
 		</dependency>
 
-		<!-- Persistence deps -->
+		<!-- OWL deps -->
 		<dependency>
-			<groupId>org.apache.clerezza</groupId>
-			<artifactId>org.apache.clerezza.rdf.core</artifactId>
-			<version>0.12-incubating-SNAPSHOT</version>
+			<groupId>com.hp.hpl.jena</groupId>
+			<artifactId>jena</artifactId>
+			<version>2.6.2</version>
 			<scope>provided</scope>
 		</dependency>
 
-		<!-- WebService deps -->
+		<!-- Stanbol deps -->
 		<dependency>
-			<groupId>com.sun.jersey</groupId>
-			<artifactId>jersey-client</artifactId>
-			<version>${jersey-version}</version>
-			<scope>provided</scope>
+			<groupId>org.apache.stanbol</groupId>
+			<artifactId>org.apache.stanbol.owlapi</artifactId>
+			<version>${stanbol-version}</version>
 		</dependency>
 
-		<!-- Testing deps -->
-		<dependency>
-			<groupId>junit</groupId>
-			<artifactId>junit</artifactId>
-			<version>4.4</version>
-			<scope>test</scope>
-		</dependency>
+		<!-- Diagnostics deps -->
 		<dependency>
 			<groupId>org.slf4j</groupId>
 			<artifactId>slf4j-api</artifactId>
@@ -136,25 +107,23 @@
 			<type>jar</type>
 			<scope>provided</scope>
 		</dependency>
+
+		<!-- Testing deps -->
 		<dependency>
-			<groupId>org.slf4j</groupId>
-			<artifactId>slf4j-simple</artifactId>
-			<version>1.5.2</version>
-			<type>jar</type>
-			<scope>provided</scope>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.4</version>
+			<scope>test</scope>
 		</dependency>
-	 <dependency>
-	  <groupId>com.hp.hpl.jena</groupId>
-	  <artifactId>jena</artifactId>
-	  <version>2.6.2</version>
-	 </dependency>
+
 	</dependencies>
 
+
 	<repositories>
-                <repository>
-                    <id>stlab-cnr-repo</id>
-                    <url>http://stlab.istc.cnr.it/software/maven/repo</url>
-                </repository>
-        </repositories>
+		<repository>
+			<id>stlab-cnr-repo</id>
+			<url>http://stlab.istc.cnr.it/software/maven/repo</url>
+		</repository>
+	</repositories>
 
 </project>

Modified: incubator/stanbol/trunk/kres/rules/manager/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/rules/manager/pom.xml?rev=1087240&r1=1087239&r2=1087240&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/rules/manager/pom.xml (original)
+++ incubator/stanbol/trunk/kres/rules/manager/pom.xml Thu Mar 31 10:36:50 2011
@@ -1,15 +1,19 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!-- 
-	Licensed to the Apache Software Foundation (ASF) under one or more contributor 
-	license agreements. See the NOTICE file distributed with this work for additional 
-	information regarding copyright ownership. The ASF licenses this file to 
-	You under the Apache License, Version 2.0 (the "License"); you may not use 
-	this file except in compliance with the License. You may obtain a copy of 
-	the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required 
-	by applicable law or agreed to in writing, software distributed under the 
-	License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 
-	OF ANY KIND, either express or implied. See the License for the specific 
-	language governing permissions and limitations under the License. 
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
 -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
@@ -71,11 +75,15 @@
 	</build>
 
 	<dependencies>
+	
+		<!-- OSGi deps -->
 		<dependency>
 			<groupId>org.apache.felix</groupId>
 			<artifactId>org.apache.felix.scr.annotations</artifactId>
 			<version>1.2.0</version>
 		</dependency>
+		
+		<!-- OWL deps -->
 		<dependency>
 			<groupId>com.hp.hpl.jena</groupId>
 			<artifactId>jena</artifactId>
@@ -95,16 +103,24 @@
 			<scope>provided</scope>
 		</dependency>
 		<dependency>
+			<groupId>owlapi</groupId>
+			<artifactId>owlapi</artifactId>
+			<version>3.0.0</version>
+			<scope>provided</scope>
+		</dependency>
+
+		<!-- Persistence deps -->
+		<dependency>
 			<groupId>org.apache.clerezza</groupId>
 			<artifactId>org.apache.clerezza.rdf.core</artifactId>
 			<version>0.12-incubating-SNAPSHOT</version>
 			<scope>provided</scope>
 		</dependency>
 		<dependency>
-			<groupId>owlapi</groupId>
-			<artifactId>owlapi</artifactId>
-			<version>3.0.0</version>
-			<scope>provided</scope>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.rdf.jena.serializer</artifactId>
+			<version>0.9-incubating-SNAPSHOT</version>
+			<type>bundle</type>
 		</dependency>
 
 		<!-- Stanbol deps -->
@@ -112,11 +128,13 @@
 			<groupId>org.apache.stanbol</groupId>
 			<artifactId>org.apache.stanbol.ontologymanager.ontonet</artifactId>
 			<version>${stanbol-version}</version>
+			<scope>provided</scope>
 		</dependency>
 		<dependency>
 			<groupId>org.apache.stanbol</groupId>
 			<artifactId>org.apache.stanbol.rules.base</artifactId>
 			<version>${stanbol-version}</version>
+			<scope>provided</scope>
 		</dependency>
 
 		<!-- Diagnostics deps -->
@@ -146,12 +164,7 @@
 				</exclusion>
 			</exclusions>
 		</dependency>
-		<dependency>
-			<groupId>org.apache.clerezza</groupId>
-			<artifactId>org.apache.clerezza.rdf.jena.serializer</artifactId>
-			<version>0.9-incubating-SNAPSHOT</version>
-			<type>bundle</type>
-		</dependency>
+
 	</dependencies>
 
 	<repositories>

Modified: incubator/stanbol/trunk/kres/rules/refactor/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/rules/refactor/pom.xml?rev=1087240&r1=1087239&r2=1087240&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/rules/refactor/pom.xml (original)
+++ incubator/stanbol/trunk/kres/rules/refactor/pom.xml Thu Mar 31 10:36:50 2011
@@ -1,19 +1,20 @@
 <?xml version="1.0" encoding="UTF-8"?>
-	<!--
-		Licensed to the Apache Software Foundation (ASF) under one or more
-		contributor license agreements. See the NOTICE file distributed with
-		this work for additional information regarding copyright ownership.
-		The ASF licenses this file to You under the Apache License, Version
-		2.0 (the "License"); you may not use this file except in compliance
-		with the License. You may obtain a copy of the License at
-
-		http://www.apache.org/licenses/LICENSE-2.0 Unless required by
-		applicable law or agreed to in writing, software distributed under the
-		License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-		CONDITIONS OF ANY KIND, either express or implied. See the License for
-		the specific language governing permissions and limitations under the
-		License.
-	-->
+<!-- 
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
@@ -74,34 +75,6 @@
 
 	<dependencies>
 
-		<!-- Stanbol deps -->
-		<dependency>
-			<groupId>org.apache.stanbol</groupId>
-			<artifactId>org.apache.stanbol.owlapi</artifactId>
-			<version>${stanbol-version}</version>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.stanbol</groupId>
-			<artifactId>org.apache.stanbol.ontologymanager.ontonet</artifactId>
-			<version>${stanbol-version}</version>
-			<scope>provided</scope>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.stanbol</groupId>
-			<artifactId>org.apache.stanbol.rules.base</artifactId>
-			<version>${stanbol-version}</version>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.stanbol</groupId>
-			<artifactId>org.apache.stanbol.rules.manager</artifactId>
-			<version>${stanbol-version}</version>
-		</dependency>
-		<dependency>
-			<groupId>owlapi</groupId>
-			<artifactId>owlapi</artifactId>
-			<version>3.0.0</version>
-		</dependency>
-
 		<!-- OSGi deps -->
 		<dependency>
 			<groupId>org.osgi</groupId>
@@ -122,15 +95,25 @@
 			<scope>provided</scope>
 		</dependency>
 
-		<!-- Jena deps -->
+		<!-- OWL deps -->
 		<dependency>
 			<groupId>com.hp.hpl.jena</groupId>
 			<artifactId>arq</artifactId>
 			<version>2.8.3</version>
 			<scope>provided</scope>
 		</dependency>
+		<dependency>
+			<groupId>com.hp.hpl.jena</groupId>
+			<artifactId>jena</artifactId>
+			<version>2.6.2</version>
+		</dependency>
+		<dependency>
+			<groupId>owlapi</groupId>
+			<artifactId>owlapi</artifactId>
+			<version>3.0.0</version>
+		</dependency>
 
-		<!-- Clerezza deps -->
+		<!-- Persistence deps -->
 		<dependency>
 			<groupId>org.apache.clerezza</groupId>
 			<artifactId>org.apache.clerezza.rdf.core</artifactId>
@@ -139,15 +122,15 @@
 		</dependency>
 		<dependency>
 			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.rdf.jena.parser</artifactId>
+			<version>0.10-incubating-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
 			<artifactId>org.apache.clerezza.rdf.jena.sparql</artifactId>
 			<version>0.5-incubating-SNAPSHOT</version>
 			<scope>provided</scope>
 		</dependency>
-                <dependency>
-			<groupId>org.apache.clerezza</groupId>
-			<artifactId>org.apache.clerezza.rdf.jena.parser</artifactId>
-			<version>0.10-incubating-SNAPSHOT</version>
-		</dependency>
 		<dependency>
 			<groupId>org.apache.clerezza</groupId>
 			<artifactId>org.apache.clerezza.rdf.simple.storage</artifactId>
@@ -155,14 +138,34 @@
 			<scope>provided</scope>
 		</dependency>
 
-		<!-- Testing deps -->
+		<!-- Stanbol deps -->
 		<dependency>
-			<groupId>junit</groupId>
-			<artifactId>junit</artifactId>
-			<version>4.4</version>
-			<scope>test</scope>
+			<groupId>org.apache.stanbol</groupId>
+			<artifactId>org.apache.stanbol.owlapi</artifactId>
+			<version>${stanbol-version}</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.stanbol</groupId>
+			<artifactId>org.apache.stanbol.ontologymanager.ontonet</artifactId>
+			<version>${stanbol-version}</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.stanbol</groupId>
+			<artifactId>org.apache.stanbol.rules.base</artifactId>
+			<version>${stanbol-version}</version>
+			<scope>provided</scope>
 		</dependency>
 		<dependency>
+			<groupId>org.apache.stanbol</groupId>
+			<artifactId>org.apache.stanbol.rules.manager</artifactId>
+			<version>${stanbol-version}</version>
+			<scope>provided</scope>
+		</dependency>
+
+		<!-- Diagnostics deps -->
+		<dependency>
 			<groupId>org.slf4j</groupId>
 			<artifactId>slf4j-api</artifactId>
 			<version>1.5.2</version>
@@ -176,13 +179,18 @@
 			<type>jar</type>
 			<scope>provided</scope>
 		</dependency>
-	 <dependency>
-	  <groupId>com.hp.hpl.jena</groupId>
-	  <artifactId>jena</artifactId>
-	  <version>2.6.2</version>
-	 </dependency>
+
+		<!-- Testing deps -->
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.4</version>
+			<scope>test</scope>
+		</dependency>
+
 	</dependencies>
 
+
 	<repositories>
 		<repository>
 			<id>stlab-cnr-repo</id>

Added: incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RefactorerResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RefactorerResource.java?rev=1087240&view=auto
==============================================================================
--- incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RefactorerResource.java (added)
+++ incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RefactorerResource.java Thu Mar 31 10:36:50 2011
@@ -0,0 +1,124 @@
+package org.apache.stanbol.rules.web.resources;
+
+import java.io.InputStream;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.stanbol.kres.jersey.format.KRFormat;
+import org.apache.stanbol.kres.jersey.resource.NavigationMixin;
+import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
+import org.apache.stanbol.rules.base.api.NoSuchRecipeException;
+import org.apache.stanbol.rules.refactor.api.Refactorer;
+import org.apache.stanbol.rules.refactor.api.RefactoringException;
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.OWLOntologyCreationException;
+import org.semanticweb.owlapi.model.OWLOntologyManager;
+
+import com.sun.jersey.api.view.ImplicitProduces;
+
+/**
+ * 
+ * @author andrea.nuzzolese
+ * 
+ */
+
+@Path("/refactorer")
+@ImplicitProduces(MediaType.TEXT_HTML + ";qs=2")
+public class RefactorerResource extends NavigationMixin {
+
+    protected ONManager onManager;
+    protected Refactorer semionRefactorer;
+    // protected SemionManager semionManager;
+    protected TcManager tcManager;
+
+    public RefactorerResource(@Context ServletContext servletContext) {
+        semionRefactorer = (Refactorer) (servletContext.getAttribute(Refactorer.class.getName()));
+
+        onManager = (ONManager) (servletContext.getAttribute(ONManager.class.getName()));
+
+        tcManager = (TcManager) (servletContext.getAttribute(TcManager.class.getName()));
+        if (semionRefactorer == null) {
+            throw new IllegalStateException("SemionRefactorer missing in ServletContext");
+        }
+
+    }
+
+    public String getNamespace() {
+        return onManager.getKReSNamespace();
+    }
+
+    @POST
+    @Path("/lazy")
+    @Consumes(MediaType.MULTIPART_FORM_DATA)
+    @Produces(value = {KRFormat.TURTLE, KRFormat.FUNCTIONAL_OWL, KRFormat.MANCHESTER_OWL, KRFormat.RDF_XML,
+                       KRFormat.OWL_XML, KRFormat.RDF_JSON})
+    public Response performRefactoring(@FormParam("recipe") String recipe,
+                                       @FormParam("input") InputStream input) {
+
+        // Refactorer semionRefactorer = semionManager.getRegisteredRefactorer();
+
+        IRI recipeIRI = IRI.create(recipe);
+
+        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
+        OWLOntology inputOntology;
+        try {
+            inputOntology = manager.loadOntologyFromOntologyDocument(input);
+
+            OWLOntology outputOntology;
+            try {
+                outputOntology = semionRefactorer.ontologyRefactoring(inputOntology, recipeIRI);
+            } catch (RefactoringException e) {
+                e.printStackTrace();
+                return Response.status(500).build();
+            } catch (NoSuchRecipeException e) {
+                return Response.status(204).build();
+            }
+
+            return Response.ok(outputOntology).build();
+        } catch (OWLOntologyCreationException e) {
+            e.printStackTrace();
+            return Response.status(404).build();
+        }
+
+    }
+
+    @GET
+    @Path("/lazy")
+    public Response performRefactoringLazyCreateGraph(@QueryParam("recipe") String recipe,
+                                                      @QueryParam("input-graph") String inputGraph,
+                                                      @QueryParam("output-graph") String outputGraph) {
+
+        System.out.println("recipe: " + recipe);
+        System.out.println("input-graph: " + inputGraph);
+        System.out.println("output-graph: " + outputGraph);
+        IRI recipeIRI = IRI.create(recipe);
+        IRI inputGraphIRI = IRI.create(inputGraph);
+        IRI outputGraphIRI = IRI.create(outputGraph);
+
+        // Refactorer semionRefactorer = semionManager.getRegisteredRefactorer();
+
+        try {
+            semionRefactorer.ontologyRefactoring(outputGraphIRI, inputGraphIRI, recipeIRI);
+            return Response.ok().build();
+        } catch (RefactoringException e) {
+            return Response.status(500).build();
+        } catch (NoSuchRecipeException e) {
+            return Response.status(204).build();
+        }
+
+    }
+
+}

Added: incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RestRecipe.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RestRecipe.java?rev=1087240&view=auto
==============================================================================
--- incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RestRecipe.java (added)
+++ incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RestRecipe.java Thu Mar 31 10:36:50 2011
@@ -0,0 +1,335 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.apache.stanbol.rules.web.resources;
+
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.Vector;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+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.access.TcManager;
+import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
+import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerImpl;
+import org.apache.stanbol.ontologymanager.ontonet.impl.io.ClerezzaOntologyStorage;
+import org.apache.stanbol.rules.base.api.RuleStore;
+import org.apache.stanbol.rules.manager.changes.AddRecipe;
+import org.apache.stanbol.rules.manager.changes.GetRecipe;
+import org.apache.stanbol.rules.manager.changes.RemoveRecipe;
+import org.apache.stanbol.rules.manager.changes.RuleStoreImpl;
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.model.AddImport;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLDataFactory;
+import org.semanticweb.owlapi.model.OWLIndividual;
+import org.semanticweb.owlapi.model.OWLIndividualAxiom;
+import org.semanticweb.owlapi.model.OWLNamedIndividual;
+import org.semanticweb.owlapi.model.OWLObjectProperty;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.OWLOntologyChange;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.stanbol.kres.jersey.format.KRFormat;
+import org.apache.stanbol.kres.jersey.resource.NavigationMixin;
+
+/**
+ * 
+ * @author elvio
+ */
+@Path("/recipe")
+// /{uri:.+}")
+// @ImplicitProduces(MediaType.TEXT_HTML + ";qs=2")
+public class RestRecipe extends NavigationMixin {
+
+    protected ONManager onm;
+
+    private Logger log = LoggerFactory.getLogger(getClass());
+
+    private RuleStore kresRuleStore;
+    private ClerezzaOntologyStorage storage;
+
+    /**
+     * To get the RuleStoreImpl where are stored the rules and the recipes
+     * 
+     * @param servletContext
+     *            {To get the context where the REST service is running.}
+     */
+    public RestRecipe(@Context ServletContext servletContext) {
+        this.kresRuleStore = (RuleStore) servletContext.getAttribute(RuleStore.class.getName());
+        this.onm = (ONManager) servletContext.getAttribute(ONManager.class.getName());
+//      this.storage = (OntologyStorage) servletContext
+//      .getAttribute(OntologyStorage.class.getName());
+// Contingency code for missing components follows.
+/*
+ * FIXME! The following code is required only for the tests. This should
+ * be removed and the test should work without this code.
+ */
+if (onm == null) {
+    log
+            .warn("No KReSONManager in servlet context. Instantiating manually...");
+    onm = new ONManagerImpl(new TcManager(), null,
+            new Hashtable<String, Object>());
+}
+this.storage = onm.getOntologyStore();
+if (storage == null) {
+    log.warn("No OntologyStorage in servlet context. Instantiating manually...");
+    storage = new ClerezzaOntologyStorage(new TcManager(),null);
+}
+        if (kresRuleStore == null) {
+            log
+                    .warn("No KReSRuleStore with stored rules and recipes found in servlet context. Instantiating manually with default values...");
+//            String iri = "http://www.ontologydesignpatterns.org/ont/iks/kres/rmi_config.owl";
+//            OWLOntology o;
+//            try {
+//                o = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(IRI.create(iri));
+//                this.kresRuleStore = new RuleStoreImpl(onm, new Hashtable<String,Object>(), "");
+//                log.debug("PATH TO OWL FILE LOADED: " + kresRuleStore.getFilePath());
+//            } catch (OWLOntologyCreationException e) {
+//
+//            }
+            
+            this.kresRuleStore = new RuleStoreImpl(onm, new Hashtable<String,Object>(), "");
+
+        }
+    }
+
+    /**
+     * Get a recipe with its rules from the rule base (that is the ontology that contains the rules and the
+     * recipe).
+     * 
+     * @param uri
+     *            {A string contains the IRI full name of the recipe.}
+     * @return Return: <br/>
+     *         200 The recipe is retrieved (import declarations point to KReS Services) <br/>
+     *         404 The recipe does not exists in the manager <br/>
+     *         500 Some error occurred
+     * 
+     */
+    @GET
+    @Path("/{uri:.+}")
+    @Produces(value = {KRFormat.RDF_XML, KRFormat.TURTLE, KRFormat.OWL_XML, KRFormat.FUNCTIONAL_OWL,
+                       KRFormat.MANCHESTER_OWL, KRFormat.RDF_JSON})
+    public Response getRecipe(@PathParam("uri") String uri) {
+        try {
+
+            GetRecipe rule = new GetRecipe(kresRuleStore);
+
+            // String ID =
+            // kresRuleStore.getOntology().getOntologyID().toString().replace(">","").replace("<","")+"#";
+
+            if (uri.equals("all")) {
+
+                Vector<IRI> recipe = rule.getGeneralRecipes();
+
+                if (recipe == null) {
+                    // The recipe does not exists in the manager
+                    return Response.status(Status.NOT_FOUND).build();
+                } else {
+
+                    // The recipe is retrieved (import declarations point to
+                    // KReS Services)
+                    OWLOntology onto = kresRuleStore.getOntology();
+                    OWLOntology newmodel = OWLManager.createOWLOntologyManager().createOntology(
+                        onto.getOntologyID());
+                    OWLDataFactory factory = onto.getOWLOntologyManager().getOWLDataFactory();
+
+                    Iterator<OWLOntology> importedonto = onto.getDirectImports().iterator();
+                    List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>();
+                    OWLDataFactory auxfactory = onto.getOWLOntologyManager().getOWLDataFactory();
+
+                    while (importedonto.hasNext()) {
+                        OWLOntology auxonto = importedonto.next();
+                        additions.add(new AddImport(newmodel, auxfactory.getOWLImportsDeclaration(auxonto
+                                .getOWLOntologyManager().getOntologyDocumentIRI(auxonto))));
+                    }
+
+                    if (!additions.isEmpty()) newmodel.getOWLOntologyManager().applyChanges(additions);
+
+                    for (int i = 0; i < recipe.size(); i++) {
+                        OWLNamedIndividual ind = factory.getOWLNamedIndividual(recipe.get(i));
+                        Set<OWLIndividualAxiom> ax = onto.getAxioms(ind);
+                        newmodel.getOWLOntologyManager().addAxioms(newmodel, ax);
+
+                    }
+
+                    // try {
+                    // OWLManager.createOWLOntologyManager().saveOntology(
+                    // newmodel,
+                    // newmodel.getOWLOntologyManager()
+                    // .getOntologyFormat(newmodel),
+                    // System.out);
+                    // } catch (OWLOntologyStorageException e) {
+                    // // TODO Auto-generated catch block
+                    // e.printStackTrace();
+                    // }
+
+                    return Response.ok(newmodel).build();
+                }
+
+            } else {
+
+                HashMap<IRI,String> recipe = rule.getRecipe(IRI.create(uri));
+
+                if (recipe == null) {
+                    // The recipe deos not exists in the manager
+                    return Response.status(Status.NOT_FOUND).build();
+                } else {
+                    // The recipe is retrieved (import declarations point to
+                    // KReS Services)
+                    OWLOntology onto = kresRuleStore.getOntology();
+
+                    OWLDataFactory factory = onto.getOWLOntologyManager().getOWLDataFactory();
+                    OWLObjectProperty prop = factory.getOWLObjectProperty(IRI
+                            .create("http://kres.iks-project.eu/ontology/meta/rmi.owl#hasRule"));
+                    OWLNamedIndividual ind = factory.getOWLNamedIndividual(IRI.create(uri));
+                    Set<OWLIndividual> value = ind.getObjectPropertyValues(prop, onto);
+                    Set<OWLIndividualAxiom> ax = onto.getAxioms(ind);
+
+                    Iterator<OWLIndividual> iter = value.iterator();
+
+                    OWLOntology newmodel = OWLManager.createOWLOntologyManager().createOntology(
+                        onto.getOntologyID());
+
+                    Iterator<OWLOntology> importedonto = onto.getDirectImports().iterator();
+                    List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>();
+                    OWLDataFactory auxfactory = onto.getOWLOntologyManager().getOWLDataFactory();
+
+                    while (importedonto.hasNext()) {
+                        OWLOntology auxonto = importedonto.next();
+                        additions.add(new AddImport(newmodel, auxfactory.getOWLImportsDeclaration(auxonto
+                                .getOWLOntologyManager().getOntologyDocumentIRI(auxonto))));
+                    }
+
+                    if (!additions.isEmpty()) newmodel.getOWLOntologyManager().applyChanges(additions);
+
+                    newmodel.getOWLOntologyManager().addAxioms(newmodel, ax);
+
+                    while (iter.hasNext()) {
+
+                        ind = (OWLNamedIndividual) iter.next();
+                        ax = onto.getAxioms(ind);
+
+                        newmodel.getOWLOntologyManager().addAxioms(newmodel, ax);
+                    }
+
+                    // try {
+                    // OWLManager.createOWLOntologyManager().saveOntology(
+                    // newmodel,
+                    // newmodel.getOWLOntologyManager()
+                    // .getOntologyFormat(newmodel),
+                    // System.out);
+                    // } catch (OWLOntologyStorageException e) {
+                    // // TODO Auto-generated catch block
+                    // e.printStackTrace();
+                    // }
+
+                    return Response.ok(newmodel).build();
+                }
+            }
+        } catch (Exception e) {
+            // Some error occurred
+            throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
+        }
+
+    }
+
+    /**
+     * To add a recipe without rules.
+     * 
+     * @param recipe
+     *            {A string contains the IRI of the recipe to be added}
+     * @param description
+     *            {A string contains a description of the rule}
+     * @return Return: <br/>
+     *         200 The recipe has been added<br/>
+     *         409 The recipe has not been added<br/>
+     *         500 Some error occurred
+     */
+    @POST
+    @Consumes(MediaType.MULTIPART_FORM_DATA)
+    @Produces(value = {KRFormat.RDF_XML, KRFormat.TURTLE, KRFormat.OWL_XML, KRFormat.FUNCTIONAL_OWL,
+                       KRFormat.MANCHESTER_OWL, KRFormat.RDF_JSON})
+    public Response addRecipe(@FormParam(value = "recipe") String recipe,
+                              @FormParam(value = "description") String description) {
+
+        try {
+
+            AddRecipe instance = new AddRecipe(kresRuleStore);
+
+            // String ID =
+            // kresRuleStore.getOntology().getOntologyID().toString().replace(">","").replace("<","")+"#";
+
+            boolean ok = instance.addSimpleRecipe(IRI.create(recipe), description);
+
+            if (!ok) {
+
+                return Response.status(Status.CONFLICT).build();
+
+            } else {
+                kresRuleStore.saveOntology();
+                return Response.status(Status.OK).build();
+            }
+
+        } catch (Exception e) {
+            throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    /**
+     * To delete a recipe
+     * 
+     * @param recipe
+     *            {A tring contains an IRI of the recipe}
+     * @return 200 The recipe has been deleted<br/>
+     *         409 The recipe has not been deleted<br/>
+     *         500 Some error occurred
+     */
+    @DELETE
+    // @Consumes(MediaType.TEXT_PLAIN)
+    @Produces("text/plain")
+    public Response removeRecipe(@QueryParam(value = "recipe") String recipe) {
+
+        try {
+
+            RemoveRecipe instance = new RemoveRecipe(kresRuleStore);
+
+            // String ID =
+            // kresRuleStore.getOntology().getOntologyID().toString().replace(">","").replace("<","")+"#";
+
+            boolean ok = instance.removeRecipe(IRI.create(recipe));
+
+            if (!ok) {
+                return Response.status(Status.CONFLICT).build();
+            } else {
+                kresRuleStore.saveOntology();
+                return Response.ok().build();
+            }
+
+        } catch (Exception e) {
+            throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+}

Added: incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RestRule.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RestRule.java?rev=1087240&view=auto
==============================================================================
--- incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RestRule.java (added)
+++ incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RestRule.java Thu Mar 31 10:36:50 2011
@@ -0,0 +1,531 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.apache.stanbol.rules.web.resources;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.Vector;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+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.access.TcManager;
+import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
+import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerImpl;
+import org.apache.stanbol.ontologymanager.ontonet.impl.io.ClerezzaOntologyStorage;
+import org.apache.stanbol.rules.base.api.RuleStore;
+import org.apache.stanbol.rules.manager.changes.AddRecipe;
+import org.apache.stanbol.rules.manager.changes.AddRule;
+import org.apache.stanbol.rules.manager.changes.GetRecipe;
+import org.apache.stanbol.rules.manager.changes.GetRule;
+import org.apache.stanbol.rules.manager.changes.RemoveRecipe;
+import org.apache.stanbol.rules.manager.changes.RemoveRule;
+import org.apache.stanbol.rules.manager.changes.RuleStoreImpl;
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.model.AddImport;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLDataFactory;
+import org.semanticweb.owlapi.model.OWLIndividualAxiom;
+import org.semanticweb.owlapi.model.OWLNamedIndividual;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.OWLOntologyChange;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.stanbol.kres.jersey.format.KRFormat;
+import org.apache.stanbol.kres.jersey.resource.NavigationMixin;
+
+/**
+ *
+ * @author elvio
+ * @author andrea.nuzzolese
+ * 
+ */
+@Path("/rule")
+public class RestRule extends NavigationMixin{
+
+	protected ONManager onm;
+	protected ClerezzaOntologyStorage storage;
+
+	private Logger log = LoggerFactory.getLogger(getClass());
+
+	private RuleStore kresRuleStore;
+    private HashMap<IRI, String> map;
+    private String desc;
+
+   /**
+     * To get the RuleStoreImpl where are stored the rules and the recipes
+     *
+	 * @param servletContext
+	 *            {To get the context where the REST service is running.}
+     */
+    public RestRule(@Context ServletContext servletContext){
+		this.kresRuleStore = (RuleStore) servletContext
+				.getAttribute(RuleStore.class.getName());
+		this.onm = (ONManager) servletContext
+				.getAttribute(ONManager.class.getName());
+//		this.storage = (OntologyStorage) servletContext
+//				.getAttribute(OntologyStorage.class.getName());
+		// Contingency code for missing components follows.
+		/*
+		 * FIXME! The following code is required only for the tests. This should
+		 * be removed and the test should work without this code.
+		 */
+        if (onm == null) {
+            log
+                    .warn("No KReSONManager in servlet context. Instantiating manually...");
+            onm = new ONManagerImpl(new TcManager(), null,
+                    new Hashtable<String, Object>());
+        }
+        this.storage = onm.getOntologyStore();
+		if (storage == null) {
+            log.warn("No OntologyStorage in servlet context. Instantiating manually...");
+            storage = new ClerezzaOntologyStorage(new TcManager(),null);
+		}
+
+       if (kresRuleStore == null) {
+			log
+					.warn("No KReSRuleStore with stored rules and recipes found in servlet context. Instantiating manually with default values...");
+			this.kresRuleStore = new RuleStoreImpl(onm,
+					new Hashtable<String, Object>(), "");
+			log
+					.debug("PATH TO OWL FILE LOADED: "
+							+ kresRuleStore.getFilePath());
+        }
+    }
+
+   /**
+	 * Get a rule from the rule base (that is the ontology that contains the
+	 * rules and the recipe). curl -v -X GET
+	 * http://localhost:8080/kres/rule/http
+	 * ://kres.iks-project.eu/ontology/meta/rmi.owl#ProvaParentRule
+	 * 
+	 * @param uri
+	 *            {A string contains the IRI full name of the rule.}
+     * @return Return: <br/>
+	 *         200 The rule is retrieved (import declarations point to KReS
+	 *         Services) <br/>
+     *       404 The rule does not exists in the manager <br/>
+     *       500 Some error occurred
+     *
+     */
+    @GET
+    @Path("/{uri:.+}")
+	@Produces(value = { KRFormat.RDF_XML, KRFormat.TURTLE,
+			KRFormat.OWL_XML })
+    public Response getRule(@PathParam("uri") String uri){
+ 
+      try{
+
+       GetRule recipe = new GetRule(kresRuleStore);
+       if(uri.equals("all")){
+
+           HashMap<IRI, String> rule = recipe.getAllRules();
+           Iterator<IRI> keys = rule.keySet().iterator();
+          
+        if(rule==null){
+            return Response.status(Status.NOT_FOUND).build();
+        }else{
+
+            OWLOntology onto = kresRuleStore.getOntology();
+					OWLOntology newmodel = OWLManager
+							.createOWLOntologyManager().createOntology(
+									onto.getOntologyID());
+					OWLDataFactory factory = onto.getOWLOntologyManager()
+							.getOWLDataFactory();
+
+					Iterator<OWLOntology> importedonto = onto
+							.getDirectImports().iterator();
+            List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>();
+					OWLDataFactory auxfactory = onto.getOWLOntologyManager()
+							.getOWLDataFactory();
+
+            while(importedonto.hasNext()){
+                OWLOntology auxonto = importedonto.next();
+						additions.add(new AddImport(newmodel, auxfactory
+								.getOWLImportsDeclaration(auxonto
+										.getOWLOntologyManager()
+										.getOntologyDocumentIRI(auxonto))));
+            }
+
+            if(!additions.isEmpty())
+						newmodel.getOWLOntologyManager()
+								.applyChanges(additions);
+
+            while(keys.hasNext()){
+						OWLNamedIndividual ind = factory
+								.getOWLNamedIndividual(keys.next());
+                Set<OWLIndividualAxiom> ax = onto.getAxioms(ind);
+						newmodel.getOWLOntologyManager()
+								.addAxioms(newmodel, ax);
+            }
+
+//            try {
+//						OWLManager.createOWLOntologyManager().saveOntology(
+//								newmodel,
+//								newmodel.getOWLOntologyManager()
+//										.getOntologyFormat(newmodel),
+//								System.out);
+//    		} catch (OWLOntologyStorageException e) {
+//    			// TODO Auto-generated catch block
+//    			e.printStackTrace();
+//    		}
+
+            return Response.ok(newmodel).build();
+        }
+
+       }else{
+
+        HashMap<IRI, String> rule = recipe.getRule(IRI.create(uri));
+       
+        if(rule==null){
+            return Response.status(Status.NOT_FOUND).build();
+        }else{
+            OWLOntology onto = kresRuleStore.getOntology();
+
+					OWLDataFactory factory = onto.getOWLOntologyManager()
+							.getOWLDataFactory();
+					OWLNamedIndividual ind = factory.getOWLNamedIndividual(IRI
+							.create(uri));
+            Set<OWLIndividualAxiom> ax = onto.getAxioms(ind);
+					OWLOntology newmodel = OWLManager
+							.createOWLOntologyManager().createOntology(
+									onto.getOntologyID());
+
+					Iterator<OWLOntology> importedonto = onto
+							.getDirectImports().iterator();
+            List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>();
+					OWLDataFactory auxfactory = onto.getOWLOntologyManager()
+							.getOWLDataFactory();
+
+            while(importedonto.hasNext()){
+                OWLOntology auxonto = importedonto.next();
+						additions.add(new AddImport(newmodel, auxfactory
+								.getOWLImportsDeclaration(auxonto
+										.getOWLOntologyManager()
+										.getOntologyDocumentIRI(auxonto))));
+            }
+
+            if(!additions.isEmpty())
+						newmodel.getOWLOntologyManager()
+								.applyChanges(additions);
+
+            newmodel.getOWLOntologyManager().addAxioms(newmodel,ax);
+
+//            try {
+//						OWLManager.createOWLOntologyManager().saveOntology(
+//								newmodel,
+//								newmodel.getOWLOntologyManager()
+//										.getOntologyFormat(newmodel),
+//								System.out);
+//    		} catch (OWLOntologyStorageException e) {
+//    			// TODO Auto-generated catch block
+//    			e.printStackTrace();
+//    		}
+
+            return Response.ok(newmodel).build();
+        }
+       }
+      }catch (Exception e){
+          //Some error occurred
+         throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
+      }
+
+    }
+    
+    @GET
+    @Path("/of-recipe/{uri:.+}")
+	@Produces(value = { KRFormat.RDF_XML, KRFormat.RDF_JSON })
+    public Response getRulesOfRecipe(@PathParam("uri") String recipeURI){
+    	
+    	GetRule kReSGetRule = new GetRule(kresRuleStore);
+    	String recipeURIEnc;
+		try {
+			recipeURIEnc = URLEncoder
+					.encode(
+							"http://kres.iks-project.eu/ontology/meta/rmi_config.owl#MyRecipeA",
+							"UTF-8");
+			System.out.println("RECIPE : "+recipeURIEnc);
+		} catch (UnsupportedEncodingException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+    	
+    	System.out.println("RECIPE IRI : "+IRI.create(recipeURI).toString());
+		OWLOntology ontology = kReSGetRule.getAllRulesOfARecipe(IRI
+				.create(recipeURI));
+		
+    	return Response.ok(ontology).build();
+			
+    }
+
+   /**
+	 * To add a rule to a recipe at the end of the sequence. curl -v -X POST -F
+	 * "recipe=http://kres.iks-project.eu/ontology/meta/rmi.owl%23ProvaParentRecipe"
+	 * -F "rule=http://kres.iks-project.eu/ontology/meta/rmi.owl%23ProvaRuleNEW"
+	 * -F "kres-syntax=body -> head" -F "description=prova di aggiunta regola"
+	 * http://localhost:8080/kres/rule
+	 * 
+	 * @param recipe
+	 *            {A string contains the IRI of the recipe where to add the
+	 *            rule}
+	 * @param rule
+	 *            {A string contains the IRI of the rule to be added at the
+	 *            recipe}
+	 * @param kres_syntax
+	 *            {A string contains the body and the head of the kres rule. If
+	 *            not specified the rule is search in the Ontology otherwise is
+	 *            added as new.}
+	 * @param description
+	 *            {A string contains a description of the rule}
+     * @return Return: <br/>
+     *      200 The rule has been added <br/>
+     *      204 The rule has not been added <br/>
+     *      400 The rule and recipe are not specified<br/>
+     *      404 Recipe or rule not found<br/>
+     *      409 The rule has not been added<br/>
+     *      500 Some error occurred
+     */
+    @POST
+    @Consumes(MediaType.MULTIPART_FORM_DATA)
+	public Response addRuleToRecipe(@FormParam(value = "recipe") String recipe,
+			@FormParam(value = "rule") String rule,
+			@FormParam(value = "kres-syntax") String kres_syntax,
+			@FormParam(value = "description") String description) {
+    
+//        System.err.println("recipe "+recipe);
+//        System.err.println("rule " + rule);
+//        System.err.println("kres-syntax "+kres_syntax);
+//        System.err.println("description "+description);
+//
+//        return Response.ok().build();
+           
+        try{
+
+         if((recipe==null)&&(rule==null)){
+                return Response.status(Status.BAD_REQUEST).build();
+         }
+
+         recipe = recipe.replace(" ","").trim();
+         rule = rule.replace(" ","").trim();
+
+         //The rule is already inside the rule store
+         if((kres_syntax==null)){
+            //Get the rule
+            GetRule inrule = new GetRule(kresRuleStore);
+            this.map = inrule.getRule(IRI.create(rule));
+            
+            if(map==null){
+                return Response.status(Status.NOT_FOUND).build();
+            }
+
+            //Get the recipe
+            GetRecipe getrecipe = new GetRecipe(kresRuleStore);
+            this.map = getrecipe.getRecipe(IRI.create(recipe));
+            if(map!=null){
+                this.desc = getrecipe.getDescription(IRI.create(recipe));
+                if(desc==null)
+                    Response.status(Status.NOT_FOUND).build();
+            }else{
+                return Response.status(Status.NOT_FOUND).build();
+            }
+
+            String[] sequence = map.get(IRI.create(recipe)).split(",");
+            Vector<IRI> ruleseq = new Vector();
+            if(!sequence[0].isEmpty())
+            for(String seq : sequence)
+                ruleseq.add(IRI.create(seq.replace(" ","").trim()));
+
+            //Add the new rule to the end
+            ruleseq.add(IRI.create(rule));
+            //Remove the old recipe
+            RemoveRecipe remove = new RemoveRecipe(kresRuleStore);
+            boolean ok = remove.removeRecipe(IRI.create(recipe));
+            
+            if(!ok)
+                return Response.status(Status.CONFLICT).build();
+
+            //Add the recipe with the new rule
+            AddRecipe newadd = new AddRecipe(kresRuleStore);
+            ok = newadd.addRecipe(IRI.create(recipe), ruleseq, desc);
+            
+            if(ok){
+                    kresRuleStore.saveOntology();
+                    return Response.ok().build();
+            }else{
+                    return Response.status(Status.NO_CONTENT).build();
+            }
+        }
+
+        //The rule is added to the store and to the recipe
+         if((kres_syntax!=null)&(description!=null)){
+            //Get the rule
+            AddRule inrule = new AddRule(kresRuleStore);
+				boolean ok = inrule.addRule(IRI.create(rule), kres_syntax,
+						description);
+            if(!ok){
+                System.err.println("PROBLEM TO ADD: "+rule);
+                return Response.status(Status.CONFLICT).build();
+            }
+            
+            //Get the recipe
+            GetRecipe getrecipe = new GetRecipe(kresRuleStore);
+            this.map = getrecipe.getRecipe(IRI.create(recipe));
+            System.out.println("RECIPE FOR RULE: "+recipe);
+            if(map!=null){
+                this.desc = getrecipe.getDescription(IRI.create(recipe));
+               
+                if(desc==null)
+                   return Response.status(Status.NOT_FOUND).build();
+            }else{
+                return Response.status(Status.NOT_FOUND).build();
+            }
+
+            String[] sequence = map.get(IRI.create(recipe)).split(",");
+            Vector<IRI> ruleseq = new Vector();
+            if(!sequence[0].isEmpty())
+            for(String seq : sequence)
+                ruleseq.add(IRI.create(seq.replace(" ","").trim()));
+
+            //Add the new rule to the end          
+            ruleseq.add(IRI.create(rule));
+            //Remove the old recipe
+            RemoveRecipe remove = new RemoveRecipe(kresRuleStore);
+            ok = remove.removeRecipe(IRI.create(recipe));
+            if(!ok){
+                System.err.println("ERROR TO REMOVE OLD RECIPE: "+recipe);
+                return Response.status(Status.CONFLICT).build();
+            }
+
+            //Add the recipe with the new rule
+            AddRecipe newadd = new AddRecipe(kresRuleStore);
+            ok = newadd.addRecipe(IRI.create(recipe), ruleseq, desc);
+            if(ok){
+                    kresRuleStore.saveOntology();
+                    return Response.ok().build();
+            }else{
+                    return Response.status(Status.NO_CONTENT).build();
+            }
+        }else{
+             return Response.status(Status.BAD_REQUEST).build();
+        }
+
+        }catch (Exception e){
+            throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+   /**
+	 * To delete a rule from a recipe or from the ontology. If the recipe is not
+	 * specified the rule is deleted from the ontology. curl -v -X DELETE -G \
+	 * -d recipe=
+	 * "http://kres.iks-project.eu/ontology/meta/rmi.owl#ProvaParentRecipe" \ -d
+	 * rule
+	 * ="http://kres.iks-project.eu/ontology/meta/rmi.owl#ProvaParentNewRule" \
+     * http://localhost:port/kres/rule
+    *
+     * @Param rule {A string contains an IRI of the rule to be removed}
+	 * @param recipe
+	 *            {A string contains an IRI of the recipe where remove the rule}
+     * @return Return: <br/>
+     *      200 The rule has been deleted<br/>
+     *      204 The rule has not been deleted<br/>
+     *      404 Recipe or rule not found<br/>
+     *      409 The recipe has not been deleted<br/>
+     *      500 Some error occurred
+     */
+    @DELETE
+    //@Consumes(MediaType.TEXT_PLAIN)
+    @Produces(KRFormat.TEXT_PLAIN)
+	public Response removeRule(@QueryParam(value = "rule") String rule,
+			@QueryParam(value = "recipe") String recipe) {
+
+        boolean ok;
+
+        try{
+         
+         //Delete from the recipe
+         if((recipe!=null)&&(rule!=null)){
+             recipe = recipe.replace(" ","").trim();
+             rule = rule.replace(" ","").trim();
+            //Get the rule
+            GetRule getrule = new GetRule(kresRuleStore);
+            this.map = getrule.getRule(IRI.create(rule));
+            if(map==null){
+                return Response.status(Status.NOT_FOUND).build();
+            }
+
+            //Get the recipe
+            GetRecipe getrecipe = new GetRecipe(kresRuleStore);
+            this.map = getrecipe.getRecipe(IRI.create(recipe));
+            if(map!=null){
+                this.desc = getrecipe.getDescription(IRI.create(recipe));
+                if(desc.isEmpty())
+                    return Response.status(Status.NOT_FOUND).build();
+            }else{
+                return Response.status(Status.NOT_FOUND).build();
+            }
+            
+            RemoveRule remove = new RemoveRule(kresRuleStore);
+				ok = remove.removeRuleFromRecipe(IRI.create(rule), IRI
+						.create(recipe));
+            if(ok){
+                kresRuleStore.saveOntology();
+                return Response.status(Status.OK).build();
+            }else{
+                return Response.status(Status.NO_CONTENT).build();
+            }
+         }
+
+         //Delete from the ontology
+         if((recipe==null)&&(rule!=null)){
+             rule = rule.replace(" ","").trim();
+            //Get the rule
+            GetRule getrule = new GetRule(kresRuleStore);
+            this.map = getrule.getRule(IRI.create(rule));
+            if(map==null){
+                return Response.status(Status.NOT_FOUND).build();
+            }
+
+            //Remove the old recipe
+            RemoveRule remove = new RemoveRule(kresRuleStore);
+            ok = remove.removeRule(IRI.create(rule));
+
+            if(ok){
+                kresRuleStore.saveOntology();
+                return Response.ok().build();
+            }else{
+                return Response.status(Status.NO_CONTENT).build();
+            }
+         }else{
+             return Response.status(Status.BAD_REQUEST).build();
+         }
+            
+        }catch(Exception e){
+           throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+}

Added: incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RuleStoreResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RuleStoreResource.java?rev=1087240&view=auto
==============================================================================
--- incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RuleStoreResource.java (added)
+++ incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RuleStoreResource.java Thu Mar 31 10:36:50 2011
@@ -0,0 +1,50 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.apache.stanbol.rules.web.resources;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+
+import org.apache.stanbol.rules.manager.changes.RuleStoreImpl;
+
+/**
+ *
+ * @author elvio
+ */
+@Path("/rulestore")
+public class RuleStoreResource {
+    
+    private RuleStoreImpl kresRuleStore;
+
+   /**
+     * To get the RuleStoreImpl where are stored the rules and the recipes
+     *
+     * @param servletContext {To get the context where the REST service is running.}
+     */
+    public RuleStoreResource(@Context ServletContext servletContext){
+       this.kresRuleStore = (RuleStoreImpl) servletContext.getAttribute(RuleStoreImpl.class.getName());
+       if (kresRuleStore == null) {
+            throw new IllegalStateException(
+                    "KReSRuleStore with stored rules and recipes is missing in ServletContext");
+        }
+    }
+
+   /**
+     * To get the RuleStoreImpl in the serveletContext.
+     * @return {An object of type RuleStoreImpl.}
+     */
+    @GET
+    //@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
+    @Produces("application/rdf+xml")
+    public Response getRuleStore(){
+        return Response.ok(this.kresRuleStore).build();
+    }
+
+}