Commit 2e6257f2 authored by redmitry@list.ru's avatar redmitry@list.ru

moved from github

parents
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2020 ELIXIR ES, Spanish National Bioinformatics Institute (INB)
and Barcelona Supercomputing Center (BSC)
Modifications to the initial code base are copyright of their respective
authors, or their employers as appropriate.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301 USA
-->
<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>es.bsc.inb.elixir.elixibilitas</groupId>
<artifactId>elixibilitas-rest</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<description>
Tools Monitoring REST API
</description>
<organization>
<name>Barcelona Supercomputing Center</name>
<url>https://www.bsc.es/</url>
</organization>
<developers>
<developer>
<id>redmitry</id>
<name>Dmitry Repchevsky</name>
<email>redmitry@list.ru</email>
</developer>
</developers>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.enterprise.concurrent</groupId>
<artifactId>javax.enterprise.concurrent-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>es.elixir.bsc.json.schema</groupId>
<artifactId>jaronuinga</artifactId>
<version>0.4</version>
</dependency>
<dependency>
<groupId>es.bsc.inb.elixir.elixibilitas</groupId>
<artifactId>elixibilitas-dao</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>es.bsc.inb.elixir.elixibilitas</groupId>
<artifactId>elixibilitas-meta</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2</artifactId>
<version>2.0.10</version>
</dependency>
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-rio-rdfxml</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-sail-memory</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-sail-lucene</artifactId>
<version>2.2.2</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>inb-bsc-maven</id>
<url>https://gitlab.bsc.es/inb/maven/raw/master</url>
</repository>
<repository>
<id>jaronuinga</id>
<url>https://raw.github.com/inab/jaronuinga/maven/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<webResources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</webResources>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
/**
* *****************************************************************************
* Copyright (C) 2020 ELIXIR ES, Spanish National Bioinformatics Institute (INB)
* and Barcelona Supercomputing Center (BSC)
*
* Modifications to the initial code base are copyright of their respective
* authors, or their employers as appropriate.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*****************************************************************************
*/
package es.bsc.inb.elixir.elixibilitas.rest;
import java.io.IOException;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.container.PreMatching;
import javax.ws.rs.ext.Provider;
/**
* @author Dmitry Repchevsky
*/
@Provider
@PreMatching
public class CorsResponseFilter implements ContainerResponseFilter {
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {
responseContext.getHeaders().add("Access-Control-Allow-Origin","*");
responseContext.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT, PATCH, OPTIONS");
responseContext.getHeaders().add("Access-Control-Allow-Headers", "X-Requested-With");
}
}
\ No newline at end of file
/**
* *****************************************************************************
* Copyright (C) 2017 ELIXIR ES, Spanish National Bioinformatics Institute (INB)
* and Barcelona Supercomputing Center (BSC)
*
* Modifications to the initial code base are copyright of their respective
* authors, or their employers as appropriate.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*****************************************************************************
*/
package es.bsc.inb.elixir.elixibilitas.rest;
import java.io.IOException;
import java.util.List;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.PreMatching;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.Provider;
/**
* The filter that add "application/json" or "application/ld+json" content to be accepted.
* For instance some browsers expect "text/html" or "application/xml" what
* makes impossible to get JSON back from the REST services.
*
* @author Dmitry Repchevsky
*/
@Provider
@PreMatching
public class JSONContentTypeFilter implements ContainerRequestFilter {
@Override
public void filter(ContainerRequestContext rc) throws IOException {
boolean json = false;
final MultivaluedMap<String, String> headers = rc.getHeaders();
final List<String> list = headers.get("Accept");
if (list != null) {
for (String header : list) {
final String[] ranges = header.split(",");
for (String range : ranges) {
final String[] nodes = range.split(";");
final String mime = nodes[0].trim();
if (MediaType.APPLICATION_XML.equals(mime)) {
if (nodes.length <= 1) {
headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
} else {
final String qs = nodes[1].replace(" ", "");
if (qs.startsWith("q=")) {
try {
final Float q = Float.parseFloat(qs.substring(2));
headers.add(HttpHeaders.ACCEPT, q > 0.5 ?
MediaType.APPLICATION_JSON :
"application/ld+json");
} catch(NumberFormatException ex) {
}
}
}
return;
} else if (MediaType.APPLICATION_JSON.equals(mime)) {
json = true;
}
}
}
}
if (!json) {
headers.add(HttpHeaders.ACCEPT, "application/json;q=.5");
}
headers.add(HttpHeaders.ACCEPT, "application/ld+json;q=.9");
}
}
/**
* *****************************************************************************
* Copyright (C) 2017 ELIXIR ES, Spanish National Bioinformatics Institute (INB)
* and Barcelona Supercomputing Center (BSC)
*
* Modifications to the initial code base are copyright of their respective
* authors, or their employers as appropriate.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*****************************************************************************
*/
package es.bsc.inb.elixir.elixibilitas.rest;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.servlet.ServletContext;
/**
* MongoDB driver producer (allows MongoClient injection).
*
* @author Dmitry Repchevsky
*/
@ApplicationScoped
public class MongoDBProducer implements Serializable {
@Inject
private ServletContext ctx;
private MongoClient mc;
@PostConstruct
public void init() {
mc = new MongoClient(new MongoClientURI(ctx.getInitParameter("mongodb.url")));
}
@PreDestroy
public void destroy() {
mc.close();
}
@Produces
public MongoClient mongoClient() {
return mc;
}
}
\ No newline at end of file
/**
* *****************************************************************************
* Copyright (C) 2017 ELIXIR ES, Spanish National Bioinformatics Institute (INB)
* and Barcelona Supercomputing Center (BSC)
*
* Modifications to the initial code base are copyright of their respective
* authors, or their employers as appropriate.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*****************************************************************************
*/
package es.bsc.inb.elixir.elixibilitas.rest;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
/**
* Benchmarking JAX-RS configuration (match everything from the root).
*
* @author Dmitry Repchevsky
*/
@ApplicationPath("/")
public class OpenEBenchMonitorApplication extends Application {
}
/**
* *****************************************************************************
* Copyright (C) 2016 Spanish National Bioinformatics Institute (INB) and
* Barcelona Supercomputing Center
*
* Modifications to the initial code base are copyright of their respective
* authors, or their employers as appropriate.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*****************************************************************************
*/
package es.bsc.inb.elixir.elixibilitas.rest;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.NameBinding;
/**
* @author Dmitry Repchevsky
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@HttpMethod("PATCH")
@NameBinding
public @interface PATCH {
}
/**
* *****************************************************************************
* Copyright (C) 2017 ELIXIR ES, Spanish National Bioinformatics Institute (INB)
* and Barcelona Supercomputing Center (BSC)
*
* Modifications to the initial code base are copyright of their respective
* authors, or their employers as appropriate.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*****************************************************************************
*/
package es.bsc.inb.elixir.elixibilitas.rest;
import io.swagger.v3.oas.annotations.Hidden;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.servlet.ServletContext;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
/**
*
* @author Dmitry Repchevsky
*/
@Path("/")
@ApplicationScoped
public class WebProxyService {
@Inject
private ServletContext ctx;
/**
* Proxy method to return Tool JSON Schema.
*
* @return JSON Schema for the Tool
*/
@GET
@Path("/tools.owl")
@Hidden
public Response getToolsOntology() {
return Response.ok(ctx.getResourceAsStream("/META-INF/resources/tools.owl"), "application/rdf+xml").build();
}
// @GET
// @Path("/index.html")
// @Hidden
// public Response getHomePage() {
// return Response.ok(ctx.getResourceAsStream("/META-INF/resources/index.html"), "text/html").build();
// }
}
/**
* *****************************************************************************
* Copyright (C) 2018 ELIXIR ES, Spanish National Bioinformatics Institute (INB)
* and Barcelona Supercomputing Center (BSC)
*
* Modifications to the initial code base are copyright of their respective
* authors, or their employers as appropriate.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*****************************************************************************
*/
package es.bsc.inb.elixir.elixibilitas.rest;
import java.io.IOException;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.PreMatching;
import javax.ws.rs.ext.Provider;
/**
* @author Dmitry Repchevsky
*/
@Provider
@PreMatching
public class XHTTPMethodOverrideFilter implements ContainerRequestFilter {
@Override
public void filter(ContainerRequestContext rc) throws IOException {
String http_method = rc.getHeaderString("X-HTTP-Method-Override");
if (http_method != null && !http_method.isEmpty()) {
rc.setMethod(http_method);
}
}
}
/**
* *****************************************************************************
* Copyright (C) 2018 ELIXIR ES, Spanish National Bioinformatics Institute (INB)
* and Barcelona Supercomputing Center (BSC)
*
* Modifications to the initial code base are copyright of their respective
* authors, or their employers as appropriate.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*****************************************************************************
*/
package es.bsc.inb.elixir.elixibilitas.rest.ext;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author Dmitry Repchevsky
*/
public class ContentRange {
private final static Pattern PATTERN = Pattern.compile("^([a-zA-Z]+) (\\d+)-(\\d+)/(\\*|\\d+)$");
private String unit;
private long firstPos;
private long lastPos;
private long length;
protected ContentRange() {}
public ContentRange(Long firstPos, Long lastPos) {
this(null, firstPos, lastPos, Long.MIN_VALUE);
}
public ContentRange(String unit, Long firstPos, Long lastPos) {
this(unit, firstPos, lastPos, Long.MIN_VALUE);
}
public ContentRange(String unit, Long firstPos, Long lastPos, Long length) {
this.unit = unit;
this.firstPos = firstPos == null || firstPos < 0 ? Long.MIN_VALUE : firstPos;
this.lastPos = lastPos == null || lastPos < 0 ? Long.MIN_VALUE : lastPos;
this.length = length == null || length < 0 ? Long.MIN_VALUE : length;
}
public ContentRange(String contentRange) {
Matcher m = PATTERN.matcher(contentRange);
if (m.find()) {
final String g1 = m.group(1);
final String g2 = m.group(2);
final String g3 = m.group(3);
final String g4 = m.group(4);
unit = g1 == null || g1.isEmpty() ? "bytes" : g1;
firstPos = g2 == null || g2.isEmpty() ? Long.MIN_VALUE : Long.parseLong(g2);
lastPos = g3 == null || g3.isEmpty() ? Long.MIN_VALUE : Long.parseLong(g3);
length = g4 == null || g4.isEmpty() || "*".equals(g4) ? Long.MIN_VALUE : Long.parseLong(g4);
} else {
firstPos = Long.MIN_VALUE;
lastPos = Long.MIN_VALUE;
length = Long.MIN_VALUE;
}
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public Long getFirstPos() {
return firstPos >= 0 ? firstPos : null;
}
public Long getLastPos() {
return lastPos >= 0 ? lastPos : null;
}
public Long getLength() {
return length >= 0 ? length : null;
}
@Override
public String toString() {
return build(unit, firstPos, lastPos, length);
}
public static String build(String unit, long firstPos, long lastPos, long length) {
final StringBuilder sb = new StringBuilder();
sb.append(unit == null ? "bytes" : unit).append(' ');
sb.append(firstPos < 0 ? 0 : firstPos).append('-');
sb.append(lastPos < 0 ? '*' : Long.toString(lastPos)).append("/");
sb.append(length < 0 ? '*' : Long.toString(length));
return sb.toString();
}
}
/**
* *****************************************************************************
* Copyright (C) 2018 ELIXIR ES, Spanish National Bioinformatics Institute (INB)
* and Barcelona Supercomputing Center (BSC)
*
* Modifications to the initial code base are copyright of their respective