Commit e5651383 authored by Bruno López Trigo's avatar Bruno López Trigo

Engadida estrutura de directorios para gestión de configuración e código da API

parent 519323e2
#Thu, 05 Apr 2018 19:37:12 +0200
/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2=
========================
BUILD OUTPUT DESCRIPTION
========================
When you build an Java application project that has a main class, the IDE
automatically copies all of the JAR
files on the projects classpath to your projects dist/lib folder. The IDE
also adds each of the JAR files to the Class-Path element in the application
JAR files manifest file (MANIFEST.MF).
To run the project from the command line, go to the dist folder and
type the following:
java -jar "WekaParser-v2.jar"
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
Notes:
* If two JAR files on the project classpath have the same name, only the first
JAR file is copied to the lib folder.
* Only JAR files are copied to the lib folder.
If the classpath contains other types of files or folders, these files (folders)
are not copied.
* If a library on the projects classpath also has a Class-Path element
specified in the manifest,the content of the Class-Path element has to be on
the projects runtime path.
* To set a main class in a standard Java project, right-click the project node
in the Projects window and choose Properties. Then click Run and enter the
class name in the Main Class field. Alternatively, you can manually type the
class name in the manifest Main-Class element.
application.args="/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/properties.xsd" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/beer.xml" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/entry.xsd" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/config.xsd" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/config.xml" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/log.xml" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/inputexample.xml" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/ALL-infer.txt" "/home/brilemau/Documents/repos/ExpliClas-TFG/codigo/WekaParser-v2/resources/explanation.html"
compile.on.save=true
do.depend=false
do.jar=true
javac.debug=true
javadoc.preview=true
user.properties.file=/home/brilemau/.netbeans/8.2/build.properties
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group/>
</open-files>
</project-private>
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>1.7-web</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>Tomcat</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
<org-netbeans-modules-maven-jaxws.rest_2e_config_2e_type>ide</org-netbeans-modules-maven-jaxws.rest_2e_config_2e_type>
</properties>
</project-shared-configuration>
<?xml version="1.0" encoding="UTF-8"?>
<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>brunolopez</groupId>
<artifactId>expliclas-api</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<name>expliclas-api</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<!--JERSEY 2.x-->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.26</version>
</dependency>
<!-- Solventar problemas con tomcat -->
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.26</version>
</dependency>
<!-- Soporte JSON -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.26</version>
</dependency>
<!-- Soporte multipart -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.26</version>
</dependency>
<!-- JAXB -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<!-- Dependencia local detección de ciclos -->
<dependency>
<groupId>expliclas</groupId>
<artifactId>cycles</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/cycles.jar</systemPath>
</dependency>
<!-- SimpleNLG -->
<dependency>
<groupId>uk.ac.abdn</groupId>
<artifactId>SimpleNLG</artifactId>
<version>4.4.8</version>
</dependency>
<!-- Weka -->
<dependency>
<groupId>nz.ac.waikato.cms.weka</groupId>
<artifactId>weka-stable</artifactId>
<version>3.8.0</version>
</dependency>
<!-- JJWT -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.0</version>
</dependency>
<!-- TESTING -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-grizzly2</artifactId>
<version>2.26</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<!-- Swagger -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey2-jaxrs</artifactId>
<version>1.5.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
package brunolopez.expliclas;
import brunolopez.expliclas.exceptions.InvalidProblemEx;
import brunolopez.expliclas.exceptions.TreeFormatEx;
import brunolopez.expliclas.exceptions.XMLFormatEx;
import brunolopez.expliclas.explainer.Explanation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import java.io.FileNotFoundException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
@Path("/classification")
@Api(value = "/classification")
public class Clasificacion {
@Path("{problem}/{classifier}")
@ApiOperation(value = "Gets the classification explanation based on indicated values for the attributes of the problem",
notes = "The values must be indicated for all the attributes of the problem, try it using beer problem",
response = Explanation.class)
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Invalid request"),
@ApiResponse(code = 500, message = "Could not build explanation")
})
@ApiImplicitParams({
@ApiImplicitParam(value = "Authorization token", name = "authorization" , dataType = "string", paramType = "header"),
@ApiImplicitParam(value = "First problem attribute", name = "Color" , dataType = "string", paramType = "query"),
@ApiImplicitParam(value = "Second problem attribute", name = "Bitterness" , dataType = "string", paramType = "query"),
@ApiImplicitParam(value = "Third problem attribute", name = "Strength" , dataType = "string", paramType = "query")
})
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response explicacionClas(@Context HttpHeaders httpheaders,
@ApiParam(value = "Problem type to get the explanation", required = true) @PathParam("problem") String problem_type,
@ApiParam(value = "Classifier algorithm to build explanation", required = true) @PathParam("classifier") String classifier, @Context UriInfo uriInfo) {
try {
String header = httpheaders.getHeaderString(HttpHeaders.AUTHORIZATION);
String token = (header==null) ? "":header.substring("Bearer".length()).trim();
Controller ctrl;
ctrl = new Controller(token, problem_type, classifier);
MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
if(queryParams.isEmpty())
return Response.status(400).entity(new InvalidProblemEx("No attributes specified")).build();
Explanation explanation = ctrl.buildClassificationExplanation(problem_type, classifier, queryParams);
return Response.status(Response.Status.OK).entity(explanation).build();
} catch (InvalidProblemEx ex) {
return Response.status(Response.Status.BAD_REQUEST).entity(ex).build();
} catch (XMLFormatEx | TreeFormatEx | FileNotFoundException ex) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex).build();
}
}
}
package brunolopez.expliclas;
import brunolopez.expliclas.exceptions.InvalidProblemEx;
import brunolopez.expliclas.exceptions.XMLFormatEx;
import brunolopez.expliclas.explainer.Explanation;
import brunolopez.expliclas.interpreter.problembuilder.Problem;
import brunolopez.expliclas.logbuilder.Views;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import java.io.File;
import java.io.FileNotFoundException;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Path("/global")
@Api(value = "/global")
public class Clasificador {
@Path("{problem}/{classifier}")
@ApiOperation(value = "Gets the global explanation based on selected problem and algorithm",
response = Explanation.class)
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Invalid request"),
@ApiResponse(code = 500, message = "Could not build explanation")
})
@ApiImplicitParams({
@ApiImplicitParam(value = "Authorization token", name = "authorization" , dataType = "string", paramType = "header")
})
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response explicacionGlob(@Context HttpHeaders httpheaders,