Commit c1ae4f4d authored by akucera's avatar akucera
Browse files

added support for data access API to the server

parent c7f45bfe
Loading
Loading
Loading
Loading

DataAccessAPI/pom.xml

0 → 100644
+86 −0
Original line number Diff line number Diff line
<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>cz.muni.fi.lasaris</groupId>
  <artifactId>DataAccessAPI</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>DataAccessAPI</name>
  <url>http://maven.apache.org</url>

  <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.glassfish.jersey</groupId>
                <artifactId>jersey-bom</artifactId>
                <version>${jersey.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-grizzly2-http</artifactId>
        </dependency>
       
         <dependency>
    		<groupId>org.glassfish.jersey.media</groupId>
    		<artifactId>jersey-media-json-jackson</artifactId>
    		<!--  <version>${jersey.version}</version> -->
		 </dependency>
        
        <dependency>
    		<groupId>org.apache.jena</groupId>
    		<artifactId>apache-jena-libs</artifactId>
    		<type>pom</type>
    		<version>3.0.0</version>
  		</dependency>
        
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.9</version>
            <scope>test</scope>
        </dependency>
  
  </dependencies>
	
	<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>cz.muni.fi.lasaris.sbms.Main</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
	
    <properties>
        <jersey.version>2.22.1</jersey.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>
+62 −0
Original line number Diff line number Diff line
package cz.muni.fi.lasaris.sbms.data;

import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.glassfish.jersey.server.ResourceConfig;
//import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature;

//import cz.muni.fi.lasaris.sbms.semantics.api.auth.AuthenticationFilter;

public class Application extends ResourceConfig {
	final static Logger logger = Logger.getLogger(Application.class);
	private Properties prop;
	
	private static Application instance;

	public static Application getInstance() {
		if(instance == null) {
			instance = new Application();
		}
		return instance;
	}
	
	protected Application() {
		super();
		// http://crunchify.com/java-properties-file-how-to-read-config-properties-values-in-java/
		this.prop = new Properties();
		try {
			String propFileName = "data.properties";

			InputStream inputStream = Application.class.getClassLoader().getResourceAsStream(propFileName);

			if (inputStream != null) {
				this.prop.load(inputStream);
			} else {
				logger.error("property file '" + propFileName + "' not found in the classpath");
			}
		} catch (Exception ex) {
			logger.error(ex);
			logger.error("Error occured when reading properties");
		}
		
		packages("cz.muni.fi.lasaris.sbms.data.api");
		/*
		register(RolesAllowedDynamicFeature.class);
		if (prop.getProperty("api.customAuth.enable") != null && Boolean.parseBoolean(prop.getProperty("api.customAuth.enable"))) {
			register(AuthenticationFilter.class);
		}
		*/
	}
	
	public Properties getSBMSProperties() {
		
		return prop;
	}
	
	public void close() {
		
	}

}
+28 −0
Original line number Diff line number Diff line
package cz.muni.fi.lasaris.sbms.data.api;

import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.apache.log4j.Logger;


@Path("presentValues")
@PermitAll
public class PresentValuesEndpoint {
final static Logger logger = Logger.getLogger(PresentValuesEndpoint.class);
	
	
	@RolesAllowed({"user","admin"})
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public String getPresentValues(
			@QueryParam("json") String json
			) {
		return "0.8";
	}
}
+0 −0

Empty file added.

+8 −12
Original line number Diff line number Diff line
@@ -11,27 +11,27 @@ import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature;
import cz.muni.fi.lasaris.sbms.semantics.api.auth.AuthenticationFilter;
import cz.muni.fi.lasaris.sbms.semantics.model.TdbConnector;

public class SBMSApplication extends ResourceConfig {
	final static Logger logger = Logger.getLogger(SBMSApplication.class);
public class Application extends ResourceConfig {
	final static Logger logger = Logger.getLogger(Application.class);
	private Properties prop;
	
	private static SBMSApplication instance;
	private static Application instance;

	public static SBMSApplication getInstance() {
	public static Application getInstance() {
		if(instance == null) {
			instance = new SBMSApplication();
			instance = new Application();
		}
		return instance;
	}
	
	protected SBMSApplication() {
	protected Application() {
		super();
		// http://crunchify.com/java-properties-file-how-to-read-config-properties-values-in-java/
		this.prop = new Properties();
		try {
			String propFileName = "sbms.properties";
			String propFileName = "semantics.properties";

			InputStream inputStream = TdbConnector.class.getClassLoader().getResourceAsStream(propFileName);
			InputStream inputStream = Application.class.getClassLoader().getResourceAsStream(propFileName);

			if (inputStream != null) {
				this.prop.load(inputStream);
@@ -59,10 +59,6 @@ public class SBMSApplication extends ResourceConfig {
		return prop;
	}
	
	public String getURI() {
		return prop.getProperty("api.uri");
	}
	
	public void close() {
		TdbConnector.close();
	}
Loading