Modified: incubator/stanbol/trunk/reengineer/web/pom.xml URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/reengineer/web/pom.xml?rev=1135631&r1=1135630&r2=1135631&view=diff ============================================================================== --- incubator/stanbol/trunk/reengineer/web/pom.xml (original) +++ incubator/stanbol/trunk/reengineer/web/pom.xml Tue Jun 14 15:03:40 2011 @@ -1,22 +1,22 @@ <?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"> - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -30,38 +30,112 @@ <artifactId>org.apache.stanbol.reengineer.web</artifactId> <packaging>bundle</packaging> - <name>Apache Stanbol Reengineer Web</name> + <name>Apache Stanbol Reengineer Web Home</name> <description>Set of rest services to deal with reengineer tasks</description> + + <build> + <!-- make it an OSGi bundle --> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-scr-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Export-Package> + org.apache.stanbol.reengineer.web.* + </Export-Package> + <Embed-Dependency>*;scope=compile|runtime;inline=false;artifactId=jersey-json|jettison|jackson-core-asl + </Embed-Dependency> + <Embed-Transitive>true</Embed-Transitive> + <Import-Package> + org.semanticweb.owlapi.*, + * + </Import-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> + + <!-- make it an OSGi bundle --> + <!-- <build> + + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Export-Package> + org.apache.stanbol.reengineer.web.*;version=${stanbol-version} + </Export-Package> + <Embed-Dependency>*;scope=compile|runtime;inline=false;artifactId=jersey-json|jettison|jackson-core-asl + </Embed-Dependency> + <Embed-Transitive>true</Embed-Transitive> + <Import-Package> + org.semanticweb.owlapi.*, + !javax.servlet.jsp.*, + !org.apache.tools.*, + !org.mortbay.*, + !org.apache.xpath.*, + !org.jdom.*, + !org.jaxen.*, + !org.apache.xml.*, + !org.mozilla.javascript.*, + !org.python.*, + !org.dom4j.*, + !org.apache.log.*, + * + </Import-Package> + <Embed-Dependency>freemarker</Embed-Dependency> + <_nouses>true</_nouses> + </instructions> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-scr-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.0.2</version> + <configuration> + <source>1.6</source> + <target>1.6</target> + </configuration> + </plugin> + </plugins> + </build>--> <dependencies> - <!-- dependencies on other IKS modules --> - <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>org.apache.clerezza</groupId> - <artifactId>org.apache.clerezza.rdf.rdfjson</artifactId> - <version>0.3-incubating-SNAPSHOT</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.clerezza</groupId> - <artifactId>org.apache.clerezza.jaxrs.rdf.providers</artifactId> - <version>0.13-incubating-SNAPSHOT</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.clerezza</groupId> - <artifactId>org.apache.clerezza.rdf.jena.serializer</artifactId> - <version>0.9-incubating-SNAPSHOT</version> - <scope>provided</scope> - </dependency> + <!-- Clerezza dependencies --> + <dependency> + <groupId>org.apache.clerezza</groupId> + <artifactId>org.apache.clerezza.rdf.core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.clerezza</groupId> + <artifactId>org.apache.clerezza.jaxrs.rdf.providers</artifactId> + </dependency> + <dependency> + <groupId>org.apache.clerezza</groupId> + <artifactId>org.apache.clerezza.rdf.jena.serializer</artifactId> + </dependency> + <dependency> + <groupId>org.apache.clerezza</groupId> + <artifactId>org.apache.clerezza.rdf.jena.parser</artifactId> + </dependency> <!-- specific deps for this project --> + <!-- Jersey, servlet and freemarker --> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-server</artifactId> @@ -76,33 +150,15 @@ <groupId>com.sun.jersey</groupId> <artifactId>jersey-json</artifactId> <version>${jersey-version}</version> - <exclusions> - <!-- jaxb is now part of java 6 --> - <exclusion> - <groupId>com.sun.xml.bind</groupId> - <artifactId>jaxb-api</artifactId> - </exclusion> - <exclusion> - <groupId>com.sun.xml.bind</groupId> - <artifactId>jaxb-impl</artifactId> - </exclusion> - </exclusions> - </dependency> - <!-- - <dependency> <groupId>com.sun.jersey.contribs</groupId> - <artifactId>jersey-multipart</artifactId> <version>1.4</version> - </dependency> - --> + </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> - <version>2.4</version> - <scope>provided</scope> </dependency> <dependency> <groupId>freemarker</groupId> <artifactId>freemarker</artifactId> - <version>2.3.9</version> + <version>2.3.9</version> </dependency> <!-- indirect dependency for freemarker --> <dependency> @@ -137,20 +193,14 @@ <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> <!-- for tests --> @@ -189,7 +239,6 @@ <dependency> <groupId>org.apache.stanbol</groupId> <artifactId>org.apache.stanbol.commons.web.base</artifactId> - <version>${stanbol-version}</version> <scope>provided</scope> </dependency> <dependency> @@ -205,19 +254,6 @@ <scope>provided</scope> </dependency> - <!-- OWL deps --> - <dependency> - <groupId>com.hp.hpl.jena</groupId> - <artifactId>jena</artifactId> - <version>2.6.2</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>owlapi</groupId> - <artifactId>owlapi</artifactId> - <version>3.0.0</version> - <scope>provided</scope> - </dependency> <!-- Diagnostics deps --> <dependency> <!-- we use log4j 1.2 --> @@ -270,55 +306,4 @@ </repository> </repositories> - <build> - <!-- make it an OSGi bundle --> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Export-Package> - >org.apache.stanbol.reengineer.web.*;version=${stanbol-version} - </Export-Package> - <Embed-Dependency>*;scope=compile|runtime;inline=false;artifactId=jersey-json|jettison|jackson-core-asl - </Embed-Dependency> - <Embed-Transitive>true</Embed-Transitive> - <Import-Package> - org.semanticweb.owlapi.*, - !javax.servlet.jsp.*, - !org.apache.tools.*, - !org.mortbay.*, - !org.apache.xpath.*, - !org.jdom.*, - !org.jaxen.*, - !org.apache.xml.*, - !org.mozilla.javascript.*, - !org.python.*, - !org.dom4j.*, - !org.apache.log.*, - * - </Import-Package> - <Embed-Dependency>freemarker</Embed-Dependency> - <_nouses>true</_nouses> - </instructions> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-scr-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>2.0.2</version> - <configuration> - <source>1.6</source> - <target>1.6</target> - </configuration> - </plugin> - </plugins> - </build> - </project>
Modified: incubator/stanbol/trunk/reengineer/web/src/main/java/org/apache/stanbol/reengineer/web/JerseyEndpoint.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/reengineer/web/src/main/java/org/apache/stanbol/reengineer/web/JerseyEndpoint.java?rev=1135631&r1=1135630&r2=1135631&view=diff ============================================================================== --- incubator/stanbol/trunk/reengineer/web/src/main/java/org/apache/stanbol/reengineer/web/JerseyEndpoint.java (original) +++ incubator/stanbol/trunk/reengineer/web/src/main/java/org/apache/stanbol/reengineer/web/JerseyEndpoint.java Tue Jun 14 15:03:40 2011 @@ -1,140 +0,0 @@ -package org.apache.stanbol.reengineer.web; - -import java.io.IOException; -import java.util.Dictionary; -import java.util.Hashtable; - -import javax.servlet.ServletContext; -import javax.servlet.ServletException; - -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Reference; -import org.apache.stanbol.reengineer.base.api.Reengineer; -import org.apache.stanbol.reengineer.base.api.ReengineerManager; -import org.osgi.framework.BundleContext; -import org.osgi.service.component.ComponentContext; -import org.osgi.service.http.HttpService; -import org.osgi.service.http.NamespaceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.sun.jersey.spi.container.servlet.ServletContainer; - - -/** - * Jersey-based RESTful endpoint for KReS. - * - * This OSGi component serves as a bridge between the OSGi context and the - * Servlet context available to JAX-RS resources. - * - * @author andrea.nuzzolese - */ - -@Component(immediate = true, metatype = true) -public class JerseyEndpoint { - - private final Logger log = LoggerFactory.getLogger(getClass()); - - @Property(value = "/reengineer") - public static final String ALIAS_PROPERTY = "org.apache.stanbol.reengineer.web.jersey.alias"; - - @Property(value = "/reengineer/static") - public static final String STATIC_RESOURCES_URL_ROOT_PROPERTY = "org.apache.stanbol.reengineer.web.jersey.static.url"; - - @Property(value = "/META-INF/static") - public static final String STATIC_RESOURCES_CLASSPATH_PROPERTY = "org.apache.stanbol.reengineer.web.jersey.static.classpath"; - - @Property(value = "/META-INF/templates") - public static final String FREEMARKER_TEMPLATE_CLASSPATH_PROPERTY = "org.apache.stanbol.reengineer.web.jersey.templates.classpath"; - - @Reference - HttpService httpService; - - @Reference - Reengineer semionReengineer; - - @Reference - ReengineerManager reengineeringManager; - - protected ServletContext servletContext; - - public Dictionary<String, String> getInitParams() { - // pass configuration for Jersey resource - // TODO: make the list of enabled JAX-RS resources and providers - // configurable using an OSGi service - Dictionary<String, String> initParams = new Hashtable<String, String>(); - initParams.put("javax.ws.rs.Application", - JerseyEndpointApplication.class.getName()); - - // make jersey automatically turn resources into Viewable models and - // hence lookup matching freemarker templates - initParams.put("com.sun.jersey.config.feature.ImplicitViewables", - "true"); - return initParams; - } - - protected void activate(ComponentContext ctx) throws IOException, - ServletException, NamespaceException { - - // register the JAX-RS resources as a servlet under configurable alias - ServletContainer container = new ServletContainer(); - String alias = (String) ctx.getProperties().get(ALIAS_PROPERTY); - String staticUrlRoot = (String) ctx.getProperties().get( - STATIC_RESOURCES_URL_ROOT_PROPERTY); - String staticClasspath = (String) ctx.getProperties().get( - STATIC_RESOURCES_CLASSPATH_PROPERTY); - String freemakerTemplates = (String) ctx.getProperties().get( - FREEMARKER_TEMPLATE_CLASSPATH_PROPERTY); - - log.info("Registering servlets with HTTP service " - + httpService.toString()); - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - Thread.currentThread().setContextClassLoader( - getClass().getClassLoader()); - try { - httpService.registerServlet(alias, container, getInitParams(), null); - httpService.registerResources(staticUrlRoot, staticClasspath, null); - } finally { - Thread.currentThread().setContextClassLoader(classLoader); - } - - // forward the main KReS OSGi components to the servlet context so that - // they can be looked up by the JAX-RS resources - servletContext = container.getServletContext(); - servletContext.setAttribute(BundleContext.class.getName(), - ctx.getBundleContext()); - servletContext.setAttribute(Reengineer.class.getName(), - semionReengineer); - -// servletContext.setAttribute(LinkDiscovery.class.getName(), -// linkDiscovery); - servletContext.setAttribute(ReengineerManager.class.getName(), - reengineeringManager); - - servletContext.setAttribute(STATIC_RESOURCES_URL_ROOT_PROPERTY, - staticUrlRoot); -// servletContext.setAttribute( -// ViewProcessorImpl.FREEMARKER_TEMPLATE_PATH_INIT_PARAM, -// freemakerTemplates); - - log.info("Jersey servlet registered at {}", alias); - } - - protected void deactivate(ComponentContext ctx) { - log.info("Deactivating jersey bundle"); - String alias = (String) ctx.getProperties().get(ALIAS_PROPERTY); - httpService.unregister(alias); - servletContext = null; - } - - - protected void bindHttpService(HttpService httpService) { - this.httpService = httpService; - } - - protected void unbindHttpService(HttpService httpService) { - this.httpService = null; - } - -} Modified: incubator/stanbol/trunk/reengineer/web/src/main/java/org/apache/stanbol/reengineer/web/JerseyEndpointApplication.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/reengineer/web/src/main/java/org/apache/stanbol/reengineer/web/JerseyEndpointApplication.java?rev=1135631&r1=1135630&r2=1135631&view=diff ============================================================================== --- incubator/stanbol/trunk/reengineer/web/src/main/java/org/apache/stanbol/reengineer/web/JerseyEndpointApplication.java (original) +++ incubator/stanbol/trunk/reengineer/web/src/main/java/org/apache/stanbol/reengineer/web/JerseyEndpointApplication.java Tue Jun 14 15:03:40 2011 @@ -1,48 +0,0 @@ -package org.apache.stanbol.reengineer.web; - -import java.util.HashSet; -import java.util.Set; - -import javax.ws.rs.core.Application; - -import org.apache.stanbol.commons.web.base.writers.GraphWriter; -import org.apache.stanbol.commons.web.base.writers.ResultSetWriter; -import org.apache.stanbol.owl.web.OWLOntologyWriter; - -/** - * Statically define the list of available resources and providers to be used by the KReS JAX-RS Endpoint. - * - * The jersey auto-scan mechanism does not seem to work when deployed through OSGi's HttpService - * initialization. - * - * In the future this class might get refactored as an OSGi service to allow for dynamic configuration and - * deployment of additional JAX-RS resources and providers. - * - * @author andrea.nuzzolese - */ - -public class JerseyEndpointApplication extends Application { - - @Override - public Set<Class<?>> getClasses() { - Set<Class<?>> classes = new HashSet<Class<?>>(); - - classes.add(ReengineerResource.class); - - // message body writers - classes.add(GraphWriter.class); - classes.add(ResultSetWriter.class); - // classes.add(OwlModelWriter.class); - classes.add(OWLOntologyWriter.class); - return classes; - } - - @Override - public Set<Object> getSingletons() { - Set<Object> singletons = new HashSet<Object>(); - // view processors -// singletons.add(new ViewProcessorImpl()); - return singletons; - } - -} Modified: incubator/stanbol/trunk/reengineer/web/src/main/java/org/apache/stanbol/reengineer/web/JettyServer.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/reengineer/web/src/main/java/org/apache/stanbol/reengineer/web/JettyServer.java?rev=1135631&r1=1135630&r2=1135631&view=diff ============================================================================== --- incubator/stanbol/trunk/reengineer/web/src/main/java/org/apache/stanbol/reengineer/web/JettyServer.java (original) +++ incubator/stanbol/trunk/reengineer/web/src/main/java/org/apache/stanbol/reengineer/web/JettyServer.java Tue Jun 14 15:03:40 2011 @@ -1,96 +0,0 @@ -package org.apache.stanbol.reengineer.web; - -import java.net.URI; -import java.util.Dictionary; -import java.util.Enumeration; - -import org.mortbay.jetty.Server; -import org.mortbay.jetty.servlet.Context; -import org.mortbay.jetty.servlet.ServletHolder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.sun.jersey.spi.container.servlet.ServletContainer; - -/** - * Standalone (OSGi independent) Jetty-based server with the KReS Jersey - * endpoint. The OSGi component need be injected manually to the ServletContext - * to make them available to the resources. - * - * This class is mainly useful for testing the JAX-RS resources without faking a - * complete OSGI runtime. - * - * For seamless OSGi deployments the JerseyEndpoint component should be - * automatically registered in the container and registers the JAXRS resources - * automatically. - * - * @author andrea.nuzzolese - */ -public class JettyServer { - - private final Logger log = LoggerFactory.getLogger(getClass()); - - public static String DEFAUL_BASE_URI = "http://localhost:9998/"; - - protected Server server = new Server(); - - private Context context; - - public void start(String baseUri) throws Exception { - log.info("starting the Jetty / Jersey endpoint"); - ServletHolder servletHolder = new ServletHolder(ServletContainer.class); - Dictionary<String, String> initParams = new JerseyEndpoint().getInitParams(); - Enumeration<String> keys = initParams.keys(); - while (keys.hasMoreElements()) { - String key = keys.nextElement(); - servletHolder.setInitParameter(key, initParams.get(key)); - } - - URI uri = new URI(baseUri); - // restart any previous server instance while keeping the previous - // attribute settings - if (server.isRunning()) { - server.stop(); - } - server = new Server(uri.getPort()); - context = new Context(server, "/", Context.SESSIONS); - context.addServlet(servletHolder, "/*"); - server.start(); - } - - public void stop() throws Exception { - log.info("stopping the Jetty / Jersey endpoint"); - server.stop(); - } - - public void setAttribute(String name, Object value) { - if (context != null) { - context.getServletContext().setAttribute(name, value); - } - } - - public Object getAttribute(String name) { - if (context != null) { - return context.getServletContext().getAttribute(name); - } - return null; - } - - public void removeAttribute(String name) { - if (context != null) { - context.getServletContext().removeAttribute(name); - } - } - - /** - * For starting manually. - */ - public static void main(String[] args) throws Exception { - JettyServer server = new JettyServer(); - server.start(DEFAUL_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/reengineer/web/src/main/java/org/apache/stanbol/reengineer/web/ReengineerResource.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/reengineer/web/src/main/java/org/apache/stanbol/reengineer/web/ReengineerResource.java?rev=1135631&r1=1135630&r2=1135631&view=diff ============================================================================== --- incubator/stanbol/trunk/reengineer/web/src/main/java/org/apache/stanbol/reengineer/web/ReengineerResource.java (original) +++ incubator/stanbol/trunk/reengineer/web/src/main/java/org/apache/stanbol/reengineer/web/ReengineerResource.java Tue Jun 14 15:03:40 2011 @@ -1,288 +0,0 @@ -package org.apache.stanbol.reengineer.web; - -import java.io.InputStream; -import java.util.Collection; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -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.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.apache.clerezza.rdf.core.Literal; -import org.apache.clerezza.rdf.core.LiteralFactory; -import org.apache.clerezza.rdf.core.MGraph; -import org.apache.clerezza.rdf.core.UriRef; -import org.apache.clerezza.rdf.core.access.TcManager; -import org.apache.clerezza.rdf.core.impl.SimpleMGraph; -import org.apache.clerezza.rdf.core.impl.TripleImpl; -import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource; -import org.apache.stanbol.ontologymanager.ontonet.impl.io.ClerezzaOntologyStorage; -import org.apache.stanbol.reengineer.base.api.DataSource; -import org.apache.stanbol.reengineer.base.api.Reengineer; -import org.apache.stanbol.reengineer.base.api.ReengineerManager; -import org.apache.stanbol.reengineer.base.api.ReengineeringException; -import org.apache.stanbol.reengineer.base.api.datasources.DataSourceFactory; -import org.apache.stanbol.reengineer.base.api.datasources.InvalidDataSourceForTypeSelectedException; -import org.apache.stanbol.reengineer.base.api.datasources.NoSuchDataSourceExpection; -import org.apache.stanbol.reengineer.base.api.datasources.RDB; -import org.apache.stanbol.reengineer.base.api.settings.ConnectionSettings; -import org.apache.stanbol.reengineer.base.api.settings.DBConnectionSettings; -import org.apache.stanbol.reengineer.base.api.util.ReengineerType; -import org.apache.stanbol.reengineer.base.api.util.UnsupportedReengineerException; -import org.semanticweb.owlapi.model.IRI; -import org.semanticweb.owlapi.model.OWLOntology; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.sun.jersey.api.view.ImplicitProduces; - - -@Path("/reengineer") -@ImplicitProduces("text/html") -public class ReengineerResource extends BaseStanbolResource { - - - - protected ReengineerManager reengineeringManager; - protected TcManager tcManager; - protected ClerezzaOntologyStorage storage; - - private final Logger log = LoggerFactory.getLogger(getClass()); - - - public ReengineerResource(@Context ServletContext servletContext) { - tcManager = (TcManager) servletContext.getAttribute(TcManager.class.getName()); - storage = (ClerezzaOntologyStorage) servletContext.getAttribute(ClerezzaOntologyStorage.class.getName()); - reengineeringManager = (ReengineerManager) (servletContext.getAttribute(ReengineerManager.class.getName())); - if (reengineeringManager == null) { - throw new IllegalStateException( - "ReengineeringManager missing in ServletContext"); - } - } - - - @POST - @Consumes(MediaType.MULTIPART_FORM_DATA) - public Response reengineering( - @FormParam("output-graph") String outputGraph, - @FormParam("input-type") String inputType, - @FormParam("input") InputStream input, - @Context HttpHeaders headers, @Context HttpServletRequest httpServletRequest){ - - - System.out.println("Reengineering: "+inputType); - int reengineerType = -1; - try { - reengineerType = ReengineerType.getType(inputType); - } catch (UnsupportedReengineerException e) { - Response.status(404).build(); - } - - try { - DataSource dataSource = DataSourceFactory.createDataSource(reengineerType, input); - - try { - OWLOntology ontology; - System.out.println("STORE PROVIDER : "+storage); - System.out.println("OUTGRAPH: "+outputGraph); - String servletPath = httpServletRequest.getLocalAddr(); - System.out.println("SERVER PATH : "+servletPath); - servletPath = "http://"+servletPath+"/kres/graphs/"+outputGraph+":"+httpServletRequest.getLocalPort(); - if(outputGraph == null || outputGraph.equals("")){ - ontology = reengineeringManager.performReengineering(servletPath, null, dataSource); - return Response.ok().build(); - } - else{ - ontology = reengineeringManager.performReengineering(servletPath, IRI.create(outputGraph), dataSource); - - storage.store(ontology); - return Response.ok(ontology).build(); - } - } catch (ReengineeringException e) { - e.printStackTrace(); - return Response.status(500).build(); - } - - } catch (NoSuchDataSourceExpection e) { - return Response.status(415).build(); - } catch (InvalidDataSourceForTypeSelectedException e) { - return Response.status(204).build(); - } - - } - - - @POST - @Consumes(MediaType.MULTIPART_FORM_DATA) - @Path("/schema") - public Response schemaReengineering( - @FormParam("output-graph") String outputGraph, - @FormParam("input-type") String inputType, - @FormParam("input") InputStream input, - @Context HttpHeaders headers, - @Context HttpServletRequest httpServletRequest){ - - int reengineerType = -1; - try { - reengineerType = ReengineerType.getType(inputType); - } catch (UnsupportedReengineerException e) { - Response.status(404).build(); - } - - try { - DataSource dataSource = DataSourceFactory.createDataSource(reengineerType, input); - - try { - OWLOntology ontology; - - String servletPath = httpServletRequest.getLocalAddr(); - servletPath = "http://"+servletPath+"/kres/graphs/"+outputGraph+":"+httpServletRequest.getLocalPort(); - if(outputGraph == null){ - ontology = reengineeringManager.performSchemaReengineering(servletPath, null, dataSource); - return Response.ok().build(); - } - else{ - ontology = reengineeringManager.performSchemaReengineering(servletPath, IRI.create(outputGraph), dataSource); - return Response.ok(ontology).build(); - } - } catch (ReengineeringException e) { - return Response.status(500).build(); - } - - } catch (NoSuchDataSourceExpection e) { - return Response.status(415).build(); - } catch (InvalidDataSourceForTypeSelectedException e) { - return Response.status(204).build(); - } - - } - - - - @GET - @Path("/reengineers") - public Response listReengineers(@Context HttpHeaders headers){ - Collection<Reengineer> reengineers = reengineeringManager.listReengineers(); - MGraph mGraph = new SimpleMGraph(); - UriRef semionRef = new UriRef("http://semion.kres.iksproject.eu#Semion"); - for(Reengineer semionReengineer : reengineers){ - UriRef hasReengineer = new UriRef("http://semion.kres.iksproject.eu#hasReengineer"); - Literal reenginnerLiteral = LiteralFactory.getInstance().createTypedLiteral(semionReengineer.getClass().getCanonicalName()); - mGraph.add(new TripleImpl(semionRef, hasReengineer, reenginnerLiteral)); - } - - return Response.ok(mGraph).build(); - } - - - @GET - @Path("/reengineers/count") - public Response countReengineers(@Context HttpHeaders headers){ - - return Response.ok(reengineeringManager.countReengineers()).build(); - } - - - - @POST - @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - @Path("/db/schema") - public Response reengineeringDBSchema( - @FormParam("output-graph") String outputGraph, - @FormParam("db") String physicalDBName, @FormParam("jdbc") String jdbcDriver, - @FormParam("protocol") String protocol, @FormParam("host") String host, - @FormParam("port") String port, @FormParam("username") String username, @FormParam("password") String password, - @Context HttpHeaders headers, - @Context HttpServletRequest httpServletRequest){ - - - log.info("There are " + tcManager.listMGraphs().size() + " mGraphs"); - System.out.println("There are " + tcManager.listMGraphs().size() + " mGraphs"); - - //UriRef uri = ContentItemHelper.makeDefaultUri(databaseURI, databaseURI.getBytes()); - ConnectionSettings connectionSettings = new DBConnectionSettings(protocol, host, port, physicalDBName, username, password, null, jdbcDriver); - DataSource dataSource = new RDB(connectionSettings); - - String servletPath = httpServletRequest.getLocalAddr(); - servletPath = "http://"+servletPath+"/kres/graphs/"+outputGraph+":"+httpServletRequest.getLocalPort(); - - if(outputGraph != null && !outputGraph.equals("")){ - OWLOntology ontology; - try { - ontology = reengineeringManager.performSchemaReengineering(servletPath, IRI.create(outputGraph), dataSource); - /*MediaType mediaType = headers.getMediaType(); - String res = OntologyRenderUtils.renderOntology(ontology, mediaType.getType());*/ - return Response.ok(ontology).build(); - } catch (ReengineeringException e) { - return Response.status(500).build(); - } - } - else{ - try { - reengineeringManager.performSchemaReengineering(servletPath, null, dataSource); - return Response.ok().build(); - } catch (ReengineeringException e) { - return Response.status(500).build(); - } - } - - - } - - - @POST - @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - @Path("/db") - public Response reengineeringDB( - @QueryParam("db") String physicalDBName, @QueryParam("jdbc") String jdbcDriver, - @QueryParam("protocol") String protocol, @QueryParam("host") String host, - @QueryParam("port") String port, @QueryParam("username") String username, @QueryParam("password") String password, - @QueryParam("output-graph") String outputGraph, - @Context HttpHeaders headers, - @Context HttpServletRequest httpServletRequest){ - - - log.info("There are " + tcManager.listMGraphs().size() + " mGraphs"); - System.out.println("There are " + tcManager.listMGraphs().size() + " mGraphs"); - - //UriRef uri = ContentItemHelper.makeDefaultUri(databaseURI, databaseURI.getBytes()); - ConnectionSettings connectionSettings = new DBConnectionSettings(protocol, host, port, physicalDBName, username, password, null, jdbcDriver); - DataSource dataSource = new RDB(connectionSettings); - - String servletPath = httpServletRequest.getLocalAddr(); - servletPath = "http://"+servletPath+"/kres/graphs/"+outputGraph+":"+httpServletRequest.getLocalPort(); - - if(outputGraph != null && !outputGraph.equals("")){ - OWLOntology ontology; - try { - ontology = reengineeringManager.performReengineering(servletPath, IRI.create(outputGraph), dataSource); - return Response.ok(ontology).build(); - } catch (ReengineeringException e) { - return Response.status(500).build(); - } - - } - else{ - try { - reengineeringManager.performReengineering(servletPath, null, dataSource); - return Response.ok().build(); - } catch (ReengineeringException e) { - return Response.status(500).build(); - } - } - - - } - - - - -} \ No newline at end of file
