branch for release 4.1
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/data-analysis/RConnector/2.1@132340 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
commit
93917d59c8
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>r-connector</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,5 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
|
@ -0,0 +1,4 @@
|
|||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
|
@ -0,0 +1,4 @@
|
|||
gCube System - License
|
||||
------------------------------------------------------------
|
||||
|
||||
${gcube.license}
|
|
@ -0,0 +1,66 @@
|
|||
The gCube System - ${name}
|
||||
--------------------------------------------------
|
||||
|
||||
${description}
|
||||
|
||||
|
||||
${gcube.description}
|
||||
|
||||
${gcube.funding}
|
||||
|
||||
|
||||
Version
|
||||
--------------------------------------------------
|
||||
|
||||
${version} (${buildDate})
|
||||
|
||||
Please see the file named "changelog.xml" in this directory for the release notes.
|
||||
|
||||
|
||||
Authors
|
||||
--------------------------------------------------
|
||||
|
||||
* Lucio Lelii (lucio.lelii@isti.cnr.it), CNR, Italy
|
||||
|
||||
|
||||
Maintainers
|
||||
-----------
|
||||
|
||||
* Lucio Lelii (lucio.lelii@isti.cnr.it), CNR, Italy
|
||||
|
||||
|
||||
Download information
|
||||
--------------------------------------------------
|
||||
|
||||
Source code is available from SVN:
|
||||
${scm.url}
|
||||
|
||||
Binaries can be downloaded from the gCube website:
|
||||
${gcube.website}
|
||||
|
||||
|
||||
Installation
|
||||
--------------------------------------------------
|
||||
|
||||
Installation documentation is available on-line in the gCube Wiki:
|
||||
${gcube.wikiRoot}/RConnector
|
||||
|
||||
|
||||
Documentation
|
||||
--------------------------------------------------
|
||||
|
||||
Documentation is available on-line in the gCube Wiki:
|
||||
${gcube.wikiRoot}/RConnector
|
||||
|
||||
|
||||
Support
|
||||
--------------------------------------------------
|
||||
|
||||
Bugs and support requests can be reported in the gCube issue tracking tool:
|
||||
${gcube.issueTracking}
|
||||
|
||||
|
||||
Licensing
|
||||
--------------------------------------------------
|
||||
|
||||
This software is licensed under the terms you may find in the file named "LICENSE" in this directory.
|
|
@ -0,0 +1,20 @@
|
|||
<ReleaseNotes>
|
||||
<Changeset component="org.gcube.data-analysis.r-connector.2.1.0" date="2016-10-03">
|
||||
<Change>porting to smartgears 2.0</Change>
|
||||
</Changeset>
|
||||
<Changeset component="org.gcube.data-analysis.r-connector.2.0.1" date="2016-05-13">
|
||||
<Change>algorithm for cookie encryption modified to support RStudio server 0.99</Change>
|
||||
</Changeset>
|
||||
<Changeset component="org.gcube.data-analysis.r-connector.2.0.0" date="2016-03-15">
|
||||
<Change>connect method with empty parameters added</Change>
|
||||
<Change>Authorization Framework integration</Change>
|
||||
</Changeset>
|
||||
<Changeset component="org.gcube.data-analysis.r-connector.1-0-1"
|
||||
date="2015-5-20">
|
||||
<Change>Bug fixing</Change>
|
||||
</Changeset>
|
||||
<Changeset component="org.gcube.data-analysis.r-connector.1-0-0"
|
||||
date="2014-11-02">
|
||||
<Change>First Release</Change>
|
||||
</Changeset>
|
||||
</ReleaseNotes>
|
|
@ -0,0 +1,32 @@
|
|||
<assembly
|
||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
|
||||
<id>servicearchive</id>
|
||||
<formats>
|
||||
<format>tar.gz</format>
|
||||
</formats>
|
||||
<baseDirectory>/</baseDirectory>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>${distroDirectory}</directory>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<useDefaultExcludes>true</useDefaultExcludes>
|
||||
<includes>
|
||||
<include>README</include>
|
||||
<include>LICENSE</include>
|
||||
<include>changelog.xml</include>
|
||||
<include>profile.xml</include>
|
||||
</includes>
|
||||
<fileMode>755</fileMode>
|
||||
<filtered>true</filtered>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
<files>
|
||||
<file>
|
||||
<source>target/${build.finalName}.${project.packaging}</source>
|
||||
<outputDirectory>/${artifactId}</outputDirectory>
|
||||
</file>
|
||||
|
||||
</files>
|
||||
</assembly>
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<ID />
|
||||
<Type>Service</Type>
|
||||
<Profile>
|
||||
<Description>${description}</Description>
|
||||
<Class>DataAnalysis</Class>
|
||||
<Name>${artifactId}</Name>
|
||||
<Version>1.0.0</Version>
|
||||
<Packages>
|
||||
<Software>
|
||||
<Name>${artifactId}</Name>
|
||||
<Version>${version}</Version>
|
||||
<MavenCoordinates>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${artifactId}</artifactId>
|
||||
<version>${version}</version>
|
||||
</MavenCoordinates>
|
||||
<Files>
|
||||
<File>${build.finalName}.jar</File>
|
||||
</Files>
|
||||
</Software>
|
||||
</Packages>
|
||||
</Profile>
|
||||
</Resource>
|
||||
|
|
@ -0,0 +1,170 @@
|
|||
<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>org.gcube.data.analysis</groupId>
|
||||
<artifactId>r-connector</artifactId>
|
||||
<version>2.1.0-SNAPSHOT</version>
|
||||
<name>RConnector</name>
|
||||
<description>makes R available in the infrastructure</description>
|
||||
|
||||
<packaging>war</packaging>
|
||||
|
||||
<properties>
|
||||
<distroDirectory>distro</distroDirectory>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>maven-smartgears-bom</artifactId>
|
||||
<version>LATEST</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>database-resource</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>database-resource-api</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<!-- smartgears -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-smartgears</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-smartgears-app</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.data.analysis.tabulardata</groupId>
|
||||
<artifactId>tabulardata-client-library</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<!-- jersey -->
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>javax.ws.rs-api</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.containers</groupId>
|
||||
<artifactId>jersey-container-servlet</artifactId>
|
||||
<version>2.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.containers.glassfish</groupId>
|
||||
<artifactId>jersey-gf-cdi</artifactId>
|
||||
<version>2.13</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.transaction</groupId>
|
||||
<artifactId>javax.transaction-api</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.0.13</version>
|
||||
</dependency>
|
||||
|
||||
<!-- weld -->
|
||||
<dependency>
|
||||
<groupId>javax.enterprise</groupId>
|
||||
<artifactId>cdi-api</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.weld.servlet</groupId>
|
||||
<artifactId>weld-servlet</artifactId>
|
||||
<version>2.2.4.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss</groupId>
|
||||
<artifactId>jandex</artifactId>
|
||||
<version>1.2.2.Final</version>
|
||||
</dependency>
|
||||
|
||||
<!-- lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>0.11.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
|
||||
<artifactId>jersey-test-framework-provider-simple</artifactId>
|
||||
<version>2.13</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<configuration>
|
||||
<warName>r-connector</warName>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>servicearchive</id>
|
||||
<phase>install</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,91 @@
|
|||
package org.gcube.data.analysis.rconnector;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Singleton
|
||||
@Slf4j
|
||||
public class ConfigFileWriter {
|
||||
|
||||
|
||||
public boolean write(Info info, String login, String usersHome, String fileName, String scriptToExecute){
|
||||
|
||||
if (!usersHome.endsWith("/"))
|
||||
usersHome=usersHome+"/";
|
||||
File userDir = new File(usersHome+login);
|
||||
File configFile= new File(userDir, fileName);
|
||||
checkDirectory(userDir, login, scriptToExecute);
|
||||
return writeFile(info, configFile);
|
||||
}
|
||||
|
||||
private void checkDirectory(File userDir, String login, String scriptToExecute){
|
||||
if ((!userDir.isDirectory() || !userDir.exists()))
|
||||
executeCommandLine(scriptToExecute,login);
|
||||
|
||||
}
|
||||
|
||||
private String executeCommandLine(String cmd, String login){
|
||||
log.debug("executing command "+cmd+" "+login);
|
||||
Process process = null;
|
||||
String lastline = "";
|
||||
try {
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder(cmd, login);
|
||||
process = pb.start();
|
||||
|
||||
try {
|
||||
process.waitFor();
|
||||
} catch (InterruptedException e) {
|
||||
log.warn("interrupt Exception on process",e);
|
||||
}
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(process.getErrorStream()));
|
||||
String line = br.readLine();
|
||||
while (line!=null){
|
||||
lastline += line;
|
||||
line = br.readLine();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("error executing command line",e);
|
||||
}
|
||||
log.debug("command result line is "+lastline);
|
||||
return lastline;
|
||||
}
|
||||
|
||||
private boolean writeFile(Info info, File pathToFile){
|
||||
log.debug("writing config file");
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(info.getTableName()+";");
|
||||
sb.append(info.getUserTableName()+";");
|
||||
|
||||
sb.append(info.getFields());
|
||||
if (!info.getFields().endsWith(";"))
|
||||
sb.append(";");
|
||||
sb.append(info.getQueryColumns());
|
||||
if (!info.getQueryColumns().endsWith(";"))
|
||||
sb.append(";");
|
||||
sb.append(info.getDatabase().getDatabaseAddress()+";");
|
||||
sb.append(info.getDatabase().getDatabaseName()+";");
|
||||
sb.append(info.getDatabase().getDatabaseUsername()+";");
|
||||
sb.append(info.getDatabase().getDatabasePassword()+"\n");
|
||||
|
||||
try{
|
||||
FileWriter fw = new FileWriter(pathToFile,false);
|
||||
fw.write(sb.toString());
|
||||
fw.close();
|
||||
log.debug("file written");
|
||||
}catch(Exception e){
|
||||
log.error("error writing config file",e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package org.gcube.data.analysis.rconnector;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
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.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Path("disconnect")
|
||||
@Slf4j
|
||||
public class DisconnectResource {
|
||||
|
||||
@Context ServletContext context;
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.TEXT_HTML)
|
||||
public Response disconnect(@Context HttpServletRequest req) {
|
||||
log.info("disconnect called ");
|
||||
new Throwable().printStackTrace();
|
||||
String rStudioServerAddress = context==null?"":context.getInitParameter("rStudioAddress");
|
||||
log.info(rStudioServerAddress);
|
||||
try{
|
||||
boolean found = false;
|
||||
for (Cookie cookie : req.getCookies())
|
||||
if (cookie.getName().equals("user-id")){
|
||||
found=true;
|
||||
break;
|
||||
}
|
||||
if (found)
|
||||
return Response.ok(context.getClassLoader().getResourceAsStream("logout.html"))
|
||||
.header(
|
||||
"Set-Cookie",
|
||||
String.format("user-id=deleted;Domain=.%s;Path=/;Expires=Thu, 01-Jan-1970 00:00:01 GMT",rStudioServerAddress)
|
||||
).build();
|
||||
else return Response.ok(context.getClassLoader().getResourceAsStream("inactivesession.html")).build();
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package org.gcube.data.analysis.rconnector;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Info {
|
||||
|
||||
private String username ="";
|
||||
private String tableName ="" ;
|
||||
private String userTableName ="" ;
|
||||
private String fields ="";
|
||||
private DataBaseInfo database = new DataBaseInfo();
|
||||
private String queryColumns= "";
|
||||
|
||||
@Data
|
||||
public static class DataBaseInfo{
|
||||
private String databaseAddress="" ;
|
||||
private String databaseName="" ;
|
||||
private String databaseUsername ="" ;
|
||||
private String databasePassword ="" ;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
package org.gcube.data.analysis.rconnector;
|
||||
|
||||
import static org.gcube.data.analysis.tabulardata.clientlibrary.plugin.AbstractPlugin.history;
|
||||
import static org.gcube.data.analysis.tabulardata.clientlibrary.plugin.AbstractPlugin.query;
|
||||
import static org.gcube.data.analysis.tabulardata.clientlibrary.plugin.AbstractPlugin.tabularResource;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.gcube.common.database.DatabaseEndpointIdentifier;
|
||||
import org.gcube.common.database.DatabaseProvider;
|
||||
import org.gcube.common.database.endpoint.DatabaseEndpoint;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.data.analysis.rconnector.Info.DataBaseInfo;
|
||||
import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationProvider;
|
||||
import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationToken;
|
||||
import org.gcube.data.analysis.tabulardata.commons.webservice.types.TabularResource;
|
||||
import org.gcube.data.analysis.tabulardata.model.column.Column;
|
||||
import org.gcube.data.analysis.tabulardata.model.column.type.IdColumnType;
|
||||
import org.gcube.data.analysis.tabulardata.model.datatype.GeometryType;
|
||||
import org.gcube.data.analysis.tabulardata.model.metadata.common.NamesMetadata;
|
||||
import org.gcube.data.analysis.tabulardata.model.metadata.table.DatasetViewTableMetadata;
|
||||
import org.gcube.data.analysis.tabulardata.model.table.Table;
|
||||
|
||||
@Slf4j
|
||||
@Singleton
|
||||
public class InfoRetriever {
|
||||
|
||||
@Inject
|
||||
DatabaseProvider databaseProvider;
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Info retrieve(String userName, Long tabularResourceId){
|
||||
try {
|
||||
AuthorizationProvider.instance.set(new AuthorizationToken(userName, ScopeProvider.instance.get()));
|
||||
TabularResource tr = tabularResource().build().getTabularResource(tabularResourceId);
|
||||
Table table = history().build().getLastTable(tabularResourceId);
|
||||
if (table.contains(DatasetViewTableMetadata.class))
|
||||
table= query().build().getTable(table.getMetadata(DatasetViewTableMetadata.class).getTargetDatasetViewTableId().getValue());
|
||||
|
||||
Info info =new Info();
|
||||
info.setTableName(table.getName());
|
||||
StringBuilder queryOrder = new StringBuilder();;
|
||||
StringBuilder fields = new StringBuilder();
|
||||
for (Column col:table.getColumnsExceptTypes(IdColumnType.class)){
|
||||
fields.append(col.getMetadata(NamesMetadata.class).getTextWithLocale("en").getValue()).append(",");
|
||||
if (col.getDataType().getClass().equals(GeometryType.class))
|
||||
queryOrder.append("ST_AsText(").append(col.getName()).append(")").append(",");
|
||||
else queryOrder.append(col.getName()).append(",");
|
||||
}
|
||||
fields.deleteCharAt(fields.lastIndexOf(","));
|
||||
queryOrder.deleteCharAt(queryOrder.lastIndexOf(","));
|
||||
|
||||
info.setFields(fields.toString());
|
||||
info.setQueryColumns(queryOrder.toString());
|
||||
info.setUsername(userName);
|
||||
info.setUserTableName(tr.getName());
|
||||
|
||||
info.setDatabase(retrievedatabaseInfo());
|
||||
|
||||
log.info("retrieved info are "+info);
|
||||
|
||||
return info;
|
||||
} catch (Exception e) {
|
||||
log.error("error retrieving info ",e);
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
DataBaseInfo retrievedatabaseInfo(){
|
||||
DatabaseEndpointIdentifier endpointId = new DatabaseEndpointIdentifier("TabularData Database",
|
||||
"Data-ReadOnly");
|
||||
DatabaseEndpoint endpoint = databaseProvider.get(endpointId);
|
||||
DataBaseInfo databaseInfo = new DataBaseInfo();
|
||||
databaseInfo.setDatabaseUsername(endpoint.getCredentials().getUsername());
|
||||
databaseInfo.setDatabasePassword(endpoint.getCredentials().getPassword());
|
||||
|
||||
Pattern pattern = Pattern.compile("[^/]*//([^:]*)[^/]*/(.*)");
|
||||
Matcher m = pattern.matcher(endpoint.getConnectionString());
|
||||
m.find();
|
||||
String databaseAddress = m.group(1);
|
||||
String databaseName = m.group(2);
|
||||
|
||||
databaseInfo.setDatabaseAddress(databaseAddress);
|
||||
databaseInfo.setDatabaseName(databaseName);
|
||||
return databaseInfo;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package org.gcube.data.analysis.rconnector;
|
||||
|
||||
import javax.ws.rs.ApplicationPath;
|
||||
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
|
||||
@ApplicationPath("/gcube/service/")
|
||||
public class RConnector extends ResourceConfig {
|
||||
|
||||
public RConnector(){
|
||||
packages("org.gcube.data.analysis.rconnector");
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
package org.gcube.data.analysis.rconnector;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.file.Files;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import javax.inject.Inject;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.NewCookie;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
|
||||
@Path("connect/")
|
||||
@Slf4j
|
||||
public class Resource {
|
||||
|
||||
@Inject
|
||||
ConfigFileWriter writer;
|
||||
|
||||
@Inject
|
||||
InfoRetriever infoRetriever;
|
||||
|
||||
@Context ServletContext context;
|
||||
|
||||
|
||||
@Path("/{trId}")
|
||||
@GET
|
||||
public Response connect(@PathParam("trId") Long tabularResourceId) {
|
||||
log.info("connect called with user {} and trID {} in scope {}",AuthorizationProvider.instance.get().getClient().getId(), tabularResourceId, ScopeProvider.instance.get());
|
||||
String usersHome = context.getInitParameter("usersHome");
|
||||
String filename = context.getInitParameter("filename");
|
||||
String scriptToExecute = context.getInitParameter("addUserScript");
|
||||
if (ScopeProvider.instance.get()==null || AuthorizationProvider.instance.get().getClient().getId() == null || tabularResourceId ==null ) return Response.serverError().build();
|
||||
Info info;
|
||||
try{
|
||||
info = infoRetriever.retrieve(AuthorizationProvider.instance.get().getClient().getId(), tabularResourceId);
|
||||
log.debug("retrieved info: "+info);
|
||||
}catch(Exception e){
|
||||
log.error("error connecting to r",e);
|
||||
return Response.serverError().build();
|
||||
}
|
||||
if (!writer.write(info, AuthorizationProvider.instance.get().getClient().getId(), usersHome, filename, scriptToExecute)) return Response.serverError().build();
|
||||
|
||||
return createResponse(AuthorizationProvider.instance.get().getClient().getId());
|
||||
}
|
||||
|
||||
|
||||
@GET
|
||||
public Response connect() {
|
||||
log.info("connect called with user {} in scope {}",AuthorizationProvider.instance.get().getClient().getId(), ScopeProvider.instance.get());
|
||||
String usersHome = context.getInitParameter("usersHome");
|
||||
String filename = context.getInitParameter("filename");
|
||||
String scriptToExecute = context.getInitParameter("addUserScript");
|
||||
if (AuthorizationProvider.instance.get().getClient().getId() == null ) return Response.serverError().build();
|
||||
Info info = new Info();
|
||||
if (!writer.write(info, AuthorizationProvider.instance.get().getClient().getId(), usersHome, filename, scriptToExecute)) return Response.serverError().build();
|
||||
return createResponse(AuthorizationProvider.instance.get().getClient().getId());
|
||||
}
|
||||
|
||||
private Response createResponse(String userName){
|
||||
try{
|
||||
String keyFilePath = context.getInitParameter("storedKeyPath");
|
||||
String rStudioServerAddress = context.getInitParameter("rStudioAddress");
|
||||
|
||||
log.debug("key file path: "+keyFilePath);
|
||||
log.debug("rstudio server address: "+rStudioServerAddress);
|
||||
|
||||
Calendar now = Calendar.getInstance();
|
||||
now.add(Calendar.YEAR, 10);
|
||||
now.add(Calendar.DAY_OF_YEAR, -1);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH);
|
||||
String format = sdf.format(now.getTime());
|
||||
|
||||
File keyFile = new File(keyFilePath);
|
||||
if (!keyFile.exists())
|
||||
return Response.serverError().build();
|
||||
|
||||
byte[] keyByte = Files.readAllBytes(keyFile.toPath());
|
||||
|
||||
SecretKeySpec keySpec = new SecretKeySpec(keyByte,
|
||||
"HmacSHA256");
|
||||
Mac mac = Mac.getInstance("HmacSHA256");
|
||||
mac.init(keySpec);
|
||||
byte[] result = mac.doFinal((userName+format).getBytes());
|
||||
|
||||
String encoded = URLEncoder.encode(DatatypeConverter.printBase64Binary(result));
|
||||
|
||||
String cookieValue = userName+"|"+URLEncoder.encode(format).replaceAll("\\+", "%20")+"|"+encoded;
|
||||
NewCookie cookie = new NewCookie("user-id",
|
||||
cookieValue,
|
||||
"/", rStudioServerAddress, "", -1, false, true );
|
||||
|
||||
|
||||
return Response.seeOther(new URI("http://"+rStudioServerAddress))
|
||||
.cookie(cookie).build();
|
||||
}catch(Exception e){
|
||||
log.error("error creating response", e);
|
||||
return Response.serverError().build();}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
||||
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd">
|
||||
</beans>
|
|
@ -0,0 +1,4 @@
|
|||
<body>
|
||||
<h2 style="text-align:center;">Rsutdio session inactive<h2>
|
||||
<h3 style="text-align:center;">log in using TabularData portlet from the i-marine portal<h3>
|
||||
</body>
|
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<body onload="window.setTimeout(function() {
|
||||
window.close();
|
||||
}, 2000);">
|
||||
<h1 style="text-align:center;">Successfully logged out from RStudio</h1>
|
||||
<h3 style="text-align:center;">this tab will close in 2 seconds</h2>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,13 @@
|
|||
<html>
|
||||
<head>
|
||||
<script type="text/javascript">
|
||||
function loaded() {
|
||||
myWindow = window.open("logout.html", "myWindow", ""); // Opens a new window
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body onLoad="loaded()">
|
||||
<h1>Opening</h1>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,12 @@
|
|||
<application mode='online'>
|
||||
<name>RConnector</name>
|
||||
<group>DataAnalysis</group>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<description>r connector webapp</description>
|
||||
<!-- <servlets>
|
||||
<servlet name="org.gcube.data.analysis.rconnector.RConnector" entryPointName="connector"/>
|
||||
</servlets> -->
|
||||
<local-persistence location='target' />
|
||||
<exclude>/disconnect/*</exclude>
|
||||
</application>
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<web-app>
|
||||
<context-param>
|
||||
<param-name>usersHome</param-name>
|
||||
<param-value>/home/</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>filename</param-name>
|
||||
<param-value>userconfig.csv</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>addUserScript</param-name>
|
||||
<param-value>/root/Ruseradd.sh</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>storedKeyPath</param-name>
|
||||
<param-value>/var/lib/rstudio-server/secure-cookie-key</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>rStudioAddress</param-name>
|
||||
<param-value>rstudio-dev.d4science.org</param-value>
|
||||
</context-param>
|
||||
<servlet>
|
||||
<servlet-name>org.gcube.data.analysis.rconnector.RConnector</servlet-name>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>org.gcube.data.analysis.rconnector.RConnector</servlet-name>
|
||||
<url-pattern>/gcube/service/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
</web-app>
|
|
@ -0,0 +1,22 @@
|
|||
package org.gcube.data.analysis.rconnector;
|
||||
|
||||
import javax.ws.rs.core.Application;
|
||||
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
import org.glassfish.jersey.test.JerseyTest;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestCall extends JerseyTest{
|
||||
|
||||
@Override
|
||||
protected Application configure() {
|
||||
return new ResourceConfig(Resource.class, DisconnectResource.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disconnect() {
|
||||
final String ret = target("disconnect").request().get(String.class);
|
||||
System.out.println("return is "+ret);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<configuration>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
|
||||
<logger name="org.gcube" level="TRACE" />
|
||||
|
||||
<root level="WARN">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
Loading…
Reference in New Issue