refs 3772: SAI - Create a github project importer

https://support.d4science.org/issues/3772

Initial Import

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/github-connector@128861 82a268e6-3cf1-43bd-a215-b396298e98cf
master
Giancarlo Panichi 8 years ago
parent a354f250f0
commit cb8a01f33e

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/github-connector-1.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry including="**/*.java" kind="src" path="src/main/resources"/>
<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 including="**/*.java" kind="src" path="src/test/resources"/>
<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"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="target/github-connector-1.0.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>github-connector</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.google.gdt.eclipse.core.webAppProjectValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.google.gwt.eclipse.core.gwtProjectValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>com.google.gwt.eclipse.core.gwtNature</nature>
</natures>
</projectDescription>

@ -0,0 +1 @@
${gcube.license}

@ -0,0 +1,68 @@
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
--------------------------------------------------
* Giancarlo Panichi (giancarlo.panichi-AT-isti.cnr.it),
Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" CNR, Pisa IT
Maintainers
-----------
* Giancarlo Panichi (giancarlo.panichi-AT-isti.cnr.it),
Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" CNR, Pisa IT
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:
https://gcube.wiki.gcube-system.org/gcube/Data_Miner_Manager
Documentation
--------------------------------------------------
Documentation is available on-line in the gCube Wiki:
https://gcube.wiki.gcube-system.org/gcube/Data_Miner_Manager
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,6 @@
<ReleaseNotes>
<Changeset component="org.gcube.portlets.widgets.githubconnector.1-0-0"
date="2016-07-01">
<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,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource>
<ID></ID>
<Type>Service</Type>
<Profile>
<Description>${project.description}</Description>
<Class>PortletsUser</Class>
<Name>${project.artifactId}</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Description>${project.description}</Description>
<Name>${project.artifactId}</Name>
<Version>${version}</Version>
<MavenCoordinates>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</MavenCoordinates>
<Type>webapplication</Type>
<Files>
<File>${project.build.finalName}.${project.packaging}</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

@ -0,0 +1,405 @@
<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>
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.0.0</version>
<relativePath />
</parent>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>github-connector</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<description>github-connector</description>
<scm>
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/github-connector</url>
</scm>
<developers>
<developer>
<name>Giancarlo Panichi</name>
<email>g.panichi@isti.cnr.it</email>
<organization>CNR Pisa, Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo"</organization>
<roles>
<role>architect</role>
<role>developer</role>
</roles>
</developer>
</developers>
<properties>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<distroDirectory>distro</distroDirectory>
<configDirectory>config</configDirectory>
<!-- Java Version -->
<javaVersion>1.7</javaVersion>
<!-- GWT configuration -->
<gwtVersion>2.7.0</gwtVersion>
<KEYS>${env.KEYS}</KEYS>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<profiles>
<profile>
<id>localRun</id>
<dependencies>
<!-- <dependency> <groupId>xerces</groupId> <artifactId>xercesImpl</artifactId>
<version>2.7.1</version> </dependency> -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Storage -->
<dependency>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-core</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-wrapper</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Home Library -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library-jcr</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library-model</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-authorization</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
</profiles>
<dependencies>
<!-- GWT -->
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwtVersion}</version>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>accesslogger</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>xalan</artifactId>
<groupId>xalan</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- Authorization -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-authorization</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
<scope>provided</scope>
</dependency>
<!-- GCube Widget -->
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-widgets</artifactId>
<scope>compile</scope>
</dependency>
<!-- Session Checker -->
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>session-checker</artifactId>
<version>[0.0.0-SNAPSHOT,1.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslsocial</artifactId>
</dependency>
<!-- Storage -->
<dependency>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-wrapper</artifactId>
<scope>provided</scope>
</dependency>
<!-- Information System Client IC-Client <dependency> <groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId> </dependency> -->
<!-- Home Library -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library-jcr</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library-model</artifactId>
<scope>provided</scope>
</dependency>
<!-- http://mvnrepository.com/artifact/org.eclipse.mylyn.github/org.eclipse.egit.github.core -->
<dependency>
<groupId>org.eclipse.mylyn.github</groupId>
<artifactId>org.eclipse.egit.github.core</artifactId>
<version>2.1.5</version>
</dependency>
<!-- http://mvnrepository.com/artifact/com.jcabi/jcabi-github -->
<!-- <dependency> <groupId>com.jcabi</groupId> <artifactId>jcabi-github</artifactId>
<version>0.27</version> </dependency> -->
<!-- http://mvnrepository.com/artifact/org.kohsuke/github-api -->
<!-- <dependency> <groupId>org.kohsuke</groupId> <artifactId>github-api</artifactId>
<version>1.75</version> </dependency> -->
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>5.0.4</version>
<scope>provided</scope>
</dependency>
<!-- LOGGING -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>provided</scope>
</dependency>
<!-- JUnit TEST -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<!-- Generate compiled stuff in the folder used for developing mode -->
<outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
<plugins>
<!-- GWT Maven Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwtVersion}</version>
<executions>
<execution>
<configuration>
<extraJvmArgs>-Xss512m -Xmx3072m -XX:MaxPermSize=2048m</extraJvmArgs>
</configuration>
<goals>
<goal>compile</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<runTarget>GitHubConnector.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<module>org.gcube.portlets.widgets.githubconnector.githubman</module>
</configuration>
</plugin>
<!-- Copy static web files before executing gwt:run -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<phase>compile</phase>
</execution>
</executions>
<configuration>
<webappDirectory>${webappDirectory}</webappDirectory>
<warName>${project.build.finalName}</warName>
</configuration>
</plugin>
<!-- Maven Compiler Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${javaVersion}</source>
<target>${javaVersion}</target>
</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>
<repositories>
<repository>
<id>gCubeExternal</id>
<name>gcube-externals</name>
<url>http://maven.research-infrastructures.eu/nexus/content/repositories/gcube-externals/</url>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>2.6.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<name>github-connector</name>
</project>

@ -0,0 +1,98 @@
package org.gcube.portlets.widgets.githubconnector.client;
import org.gcube.portlets.widgets.githubconnector.client.rpc.GitHubConnectorServiceAsync;
import org.gcube.portlets.widgets.githubconnector.client.util.GWTMessages;
import org.gcube.portlets.widgets.githubconnector.shared.exception.ExpiredSessionServiceException;
import org.gcube.portlets.widgets.githubconnector.shared.session.UserInfo;
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class GitHubConnectorController {
private UserInfo userInfo;
public GitHubConnectorController() {
init();
}
public UserInfo getUserInfo() {
return userInfo;
}
private void init() {
bind();
callHello();
checkSession();
}
private void checkSession() {
// if you do not need to something when the session expire
CheckSession.getInstance().startPolling();
}
private void sessionExpiredShow() {
CheckSession.showLogoutDialog();
}
private void sessionExpiredShowDelayed() {
Timer timeoutTimer = new Timer() {
public void run() {
sessionExpiredShow();
}
};
int TIMEOUT = 3; // 3 second timeout
timeoutTimer.schedule(TIMEOUT * 1000); // timeout is in milliseconds
}
private void callHello() {
GitHubConnectorServiceAsync.INSTANCE
.hello(new AsyncCallback<UserInfo>() {
@Override
public void onFailure(Throwable caught) {
GWT.log("No valid user found: " + caught.getMessage());
if (caught instanceof ExpiredSessionServiceException) {
GWTMessages.alert("Error", "Expired Session");
sessionExpiredShowDelayed();
} else {
GWTMessages.alert(
"Error",
"No user found: "
+ caught.getLocalizedMessage());
}
}
@Override
public void onSuccess(UserInfo result) {
userInfo = result;
GWT.log("Hello: " + userInfo.getUsername());
}
});
}
private void bind() {
}
}

@ -0,0 +1,95 @@
package org.gcube.portlets.widgets.githubconnector.client;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.i18n.client.Constants;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.TextBox;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class GitHubConnectorDialog extends DialogBox implements ClickHandler {
public static interface GitHubConnectorDialogConstants extends Constants {
@DefaultStringValue("Owner:")
String gitCDecoratorPanelFormOwner();
@DefaultStringValue("Repository Name:")
String gitCDecoratorPanelFormRepository();
@DefaultStringValue("Repository")
String gitCDecoratorPanelFormTitle();
}
/**
* An instance of the constants.
*/
private final GitHubConnectorDialogConstants gitHubConnectorDialogConstants = GWT
.create(GitHubConnectorDialogConstants.class);
public GitHubConnectorDialog() {
setText("GitHub Connector");
setGlassEnabled(true);
setAnimationEnabled(true);
// Form
FlexTable layout = new FlexTable();
layout.setCellSpacing(10);
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
// Add a title to the form
layout.setHTML(0, 0,
"<b>"+gitHubConnectorDialogConstants.gitCDecoratorPanelFormTitle()+"</b>");
cellFormatter.setColSpan(0, 0, 2);
cellFormatter.setHorizontalAlignment(0, 0,
HasHorizontalAlignment.ALIGN_CENTER);
// Add some standard form options
layout.setHTML(1, 0,
gitHubConnectorDialogConstants.gitCDecoratorPanelFormOwner());
layout.setWidget(1, 1, new TextBox());
layout.setHTML(2, 0, gitHubConnectorDialogConstants
.gitCDecoratorPanelFormRepository());
layout.setWidget(2, 1, new TextBox());
// Wrap the content in a DecoratorPanel
DecoratorPanel decPanel = new DecoratorPanel();
decPanel.setWidget(layout);
Button closeButton = new Button("Close", this);
/*HTML msg = new HTML(
"<center>A standard dialog box component.</center>", true);*/
DockPanel dock = new DockPanel();
dock.setSpacing(4);
dock.add(closeButton, DockPanel.SOUTH);
dock.add(decPanel, DockPanel.CENTER);
//dock.add(new HTML("images/yourImage.jpg"), DockPanel.CENTER);
dock.setCellHorizontalAlignment(closeButton, DockPanel.ALIGN_CENTER);
dock.setWidth("100%");
setWidget(dock);
}
@Override
public void onClick(ClickEvent event) {
hide();
}
}

@ -0,0 +1,114 @@
package org.gcube.portlets.widgets.githubconnector.client;
import org.gcube.portlets.user.gcubewidgets.client.ClientScopeHelper;
import org.gcube.portlets.widgets.githubconnector.client.util.GWTMessages;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.user.client.Window.Location;
import com.google.gwt.user.client.rpc.AsyncCallback;
//import com.google.gwt.event.logical.shared.ResizeEvent;
//import com.google.gwt.event.logical.shared.ResizeHandler;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class GitHubConnectorManager implements EntryPoint {
//private static final String SM_DIV = "contentDiv";
@SuppressWarnings("unused")
private GitHubConnectorController TestController;
/**
* {@inheritDoc}
*/
public void onModuleLoad() {
/*
* Install an UncaughtExceptionHandler which will produce
* <code>FATAL</code> log messages
*/
// use deferred command to catch initialization exceptions in
// onModuleLoad2
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
loadScope();
}
});
}
private void loadScope() {
ClientScopeHelper.getService().setScope(Location.getHref(),
new AsyncCallback<Boolean>() {
@Override
public void onSuccess(Boolean result) {
if (result) {
loadMainPanel();
} else {
GWTMessages.alert("Attention",
"ClientScopeHelper has returned a false value!");
}
}
@Override
public void onFailure(Throwable caught) {
GWTMessages.alert("Error", "Error setting scope: "
+ caught.getLocalizedMessage());
caught.printStackTrace();
}
});
}
private void loadMainPanel() {
TestController = new GitHubConnectorController();
GitHubConnectorDialog dialog=new GitHubConnectorDialog();
dialog.show();
}
/*
private void bind() {
}
/**
*
* @param mainWidget
*/
/*
private void bindWindow(Widget mainWidget) {
try {
RootPanel root = RootPanel.get(SM_DIV);
Log.info("Root Panel: " + root);
if (root == null) {
Log.info("Div with id " + SM_DIV
+ " not found, starting in dev mode");
Viewport viewport = new Viewport();
viewport.setWidget(mainWidget);
viewport.onResize();
RootPanel.get().add(viewport);
} else {
Log.info("Application div with id " + SM_DIV
+ " found, starting in portal mode");
PortalViewport viewport = new PortalViewport();
Log.info("Created Viewport");
viewport.setEnableScroll(false);
viewport.setWidget(mainWidget);
Log.info("Set Widget");
Log.info("getOffsetWidth(): " + viewport.getOffsetWidth());
Log.info("getOffsetHeight(): " + viewport.getOffsetHeight());
viewport.onResize();
root.add(viewport);
Log.info("Added viewport to root");
}
} catch (Exception e) {
e.printStackTrace();
Log.error("Error in attach viewport:" + e.getLocalizedMessage());
}
}
*/
}

@ -0,0 +1,24 @@
package org.gcube.portlets.widgets.githubconnector.client.rpc;
import java.util.List;
import org.gcube.portlets.widgets.githubconnector.shared.exception.ServiceException;
import org.gcube.portlets.widgets.githubconnector.shared.git.GitHubRepository;
import org.gcube.portlets.widgets.githubconnector.shared.session.UserInfo;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
/**
* The client side stub for the RPC service.
*/
@RemoteServiceRelativePath("githubconnectorservice")
public interface GitHubConnectorService extends RemoteService {
public UserInfo hello() throws ServiceException;
public List<GitHubRepository> getRepositories(String owner) throws ServiceException;
}

@ -0,0 +1,26 @@
package org.gcube.portlets.widgets.githubconnector.client.rpc;
import java.util.List;
import org.gcube.portlets.widgets.githubconnector.shared.git.GitHubRepository;
import org.gcube.portlets.widgets.githubconnector.shared.session.UserInfo;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public interface GitHubConnectorServiceAsync {
public static GitHubConnectorServiceAsync INSTANCE = (GitHubConnectorServiceAsync) GWT
.create(GitHubConnectorService.class);
void hello(AsyncCallback<UserInfo> callback);
void getRepositories(String owner, AsyncCallback<List<GitHubRepository>> callback);
}

@ -0,0 +1,40 @@
package org.gcube.portlets.widgets.githubconnector.client.util;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HTML;
/**
*
* @author Giancarlo Panichi
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class AlertDialog extends DialogBox implements ClickHandler {
public AlertDialog(String title, String text) {
setText(title);
Button closeButton = new Button("Close", this);
HTML msg = new HTML(
text, true);
DockPanel dock = new DockPanel();
dock.setSpacing(4);
dock.add(closeButton, DockPanel.SOUTH);
dock.add(msg, DockPanel.CENTER);
dock.setCellHorizontalAlignment(closeButton, DockPanel.ALIGN_CENTER);
dock.setWidth("100%");
setWidget(dock);
}
@Override
public void onClick(ClickEvent event) {
hide();
}
}

@ -0,0 +1,17 @@
package org.gcube.portlets.widgets.githubconnector.client.util;
/**
*
* @author Giancarlo Panichi
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class GWTMessages {
public static void alert(String title, String text) {
AlertDialog alertDialgo = new AlertDialog(title, text);
alertDialgo.show();
}
}

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='githubman'>
<inherits name='com.google.gwt.user.User' />
<inherits name="com.google.gwt.http.HTTP" />
<inherits name='com.google.gwt.user.theme.clean.Clean' />
<!-- <inherits name="com.google.gwt.logging.Logging" /> -->
<!-- <inherits name="com.allen_sauer.gwt.log.gwt-log-TRACE" /> -->
<inherits name="com.google.gwt.logging.Logging" />
<!-- Debug CSS style -->
<set-configuration-property name="CssResource.style"
value="pretty" />
<!-- <inherits name="org.gcube.portlets.user.tdw.TabularDataWidget" /> <inherits
name='org.gcube.portlets.user.gcubewidgets.WidgetFactory' /> <inherits name='org.gcube.portlets.user.csvimportwizard.CSVImportWizard'
/> -->
<inherits name='org.gcube.portlets.widgets.sessionchecker.SessionChecker' />
<!-- <inherits name="org.gcube.portlets.user.csvimportwizard.ws.CSVImportWizardWorkspace"
/> -->
<entry-point
class='org.gcube.portlets.widgets.githubconnector.client.GitHubConnectorManager' />
<set-property name="gwt.logging.logLevel" value="SEVERE" />
<set-property name="gwt.logging.enabled" value="TRUE" />
<set-property name="gwt.logging.consoleHandler" value="ENABLED" />
<source path='client' />
<source path='shared' />
</module>

@ -0,0 +1,57 @@
/**
*
*/
package org.gcube.portlets.widgets.githubconnector.portlet;
import java.io.IOException;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author giancarlo
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class GitHubConnectorPortlet extends GenericPortlet {
protected Logger logger = LoggerFactory.getLogger(GitHubConnectorPortlet.class);
/**
* JSP folder name
*/
public static final String JSP_FOLDER = "/WEB-INF/jsp/";
/**
*
*/
public static final String VIEW_JSP = JSP_FOLDER + "GitHubConnector_view.jsp";
/**
* @param request .
* @param response .
* @throws IOException .
* @throws PortletException .
*/
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
logger.trace("Loading from JSP: "+VIEW_JSP);
logger.trace("setting context using ScopeHelper");
ScopeHelper.setContext(request);
logger.trace("passing to the render");
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(VIEW_JSP);
logger.trace("Call: "+VIEW_JSP);
rd.include(request,response);
}
}

@ -0,0 +1,73 @@
package org.gcube.portlets.widgets.githubconnector.server;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;
import org.gcube.application.framework.accesslogger.library.impl.AccessLogger;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.portlets.widgets.githubconnector.client.rpc.GitHubConnectorService;
import org.gcube.portlets.widgets.githubconnector.shared.exception.ServiceException;
import org.gcube.portlets.widgets.githubconnector.shared.git.GitHubRepository;
import org.gcube.portlets.widgets.githubconnector.shared.session.UserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/**
* The server side implementation of the RPC service.
*/
@SuppressWarnings("serial")
public class GitHubConnectorServiceImpl extends RemoteServiceServlet implements
GitHubConnectorService {
public static AccessLogger accountinglog = AccessLogger.getAccessLogger();
private static Logger logger = LoggerFactory.getLogger(GitHubConnectorServiceImpl.class);
@Override
public void init() throws ServletException {
super.init();
logger.info("GitHubConnectorServiceImpl started!");
}
/**
*
* {@inheritDoc}
*
*/
@Override
public UserInfo hello() throws ServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
UserInfo userInfo = new UserInfo(aslSession.getUsername(),
aslSession.getGroupId(), aslSession.getGroupName(),
aslSession.getScope(), aslSession.getScopeName(),
aslSession.getUserEmailAddress(),
aslSession.getUserFullName());
logger.debug("UserInfo: " + userInfo);
return userInfo;
} catch (ServiceException e) {
e.printStackTrace();
throw e;
} catch (Throwable e) {
e.printStackTrace();
logger.error("Hello(): " + e.getLocalizedMessage(), e);
throw new ServiceException(e.getLocalizedMessage(), e);
}
}
@Override
public List<GitHubRepository> getRepositories(String owner)
throws ServiceException {
return null;
}
}

@ -0,0 +1,85 @@
/**
*
*/
package org.gcube.portlets.widgets.githubconnector.server;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.widgets.githubconnector.shared.Constants;
import org.gcube.portlets.widgets.githubconnector.shared.exception.ExpiredSessionServiceException;
import org.gcube.portlets.widgets.githubconnector.shared.exception.ServiceException;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class SessionUtil {
private static final Logger logger = Logger.getLogger(SessionUtil.class);
public static ASLSession getASLSession(HttpSession httpSession)
throws ServiceException {
String username = (String) httpSession
.getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
ASLSession aslSession;
if (username == null) {
if (Constants.DEBUG_MODE) {
logger.info("no user found in session, use test user");
username = Constants.DEFAULT_USER;
String scope = Constants.DEFAULT_SCOPE;
httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE,
username);
aslSession = SessionManager.getInstance().getASLSession(
httpSession.getId(), username);
aslSession.setScope(scope);
} else {
logger.info("no user found in session!");
throw new ExpiredSessionServiceException("Session Expired!");
}
} else {
aslSession = SessionManager.getInstance().getASLSession(
httpSession.getId(), username);
}
logger.info("SessionUtil: aslSession " + aslSession.getUsername() + " "
+ aslSession.getScope());
return aslSession;
}
public static String getToken(ASLSession aslSession) {
String token = null;
if (Constants.DEBUG_MODE) {
List<String> userRoles = new ArrayList<>();
userRoles.add(Constants.DEFAULT_ROLE);
/*
* if (aslSession.getUsername().compareTo("lucio.lelii") == 0)
* userRoles.add("VRE-Manager");
*/
token = authorizationService().build().generate(
aslSession.getUsername(), userRoles);
} else {
token = aslSession.getSecurityToken();
}
logger.info("received token: " + token);
return token;
}
}

@ -0,0 +1,212 @@
package org.gcube.portlets.widgets.githubconnector.server.git;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.codec.binary.Base64;
import org.eclipse.egit.github.core.Blob;
import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.RepositoryContents;
import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.service.ContentsService;
import org.eclipse.egit.github.core.service.DataService;
import org.eclipse.egit.github.core.service.RepositoryService;
import org.gcube.portlets.widgets.githubconnector.server.storage.StorageUtil;
import org.gcube.portlets.widgets.githubconnector.shared.exception.ServiceException;
import org.gcube.portlets.widgets.githubconnector.shared.git.GitHubRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class GitConnectorService {
private static Logger logger = LoggerFactory
.getLogger(GitConnectorService.class);
private GitHubClient gitHubClient;
private String userName;
public GitConnectorService(String userName) {
this.userName = userName;
}
/**
*
* @param userGitHub
* @param passwordGitHub
*/
public GitConnectorService(String userName, String userGitHub,
String passwordGitHub) {
this.userName = userName;
gitHubClient = new GitHubClient();
gitHubClient.setCredentials(userGitHub, passwordGitHub);
}
/**
*
* @param oauth2Token
*/
public GitConnectorService(String userName, String oauth2Token) {
this.userName = userName;
gitHubClient = new GitHubClient();
gitHubClient.setOAuth2Token(oauth2Token);
}
public ArrayList<GitHubRepository> getRepositories(String repositoryOwner)
throws ServiceException {
try {
RepositoryService service;
if (gitHubClient == null) {
service = new RepositoryService();
} else {
service = new RepositoryService(gitHubClient);
}
List<Repository> repositories = service
.getRepositories(repositoryOwner);
ArrayList<GitHubRepository> gitHubRepositories = GitHubRepositoryBuilder
.build(repositories);
logger.debug("Repositories: "+gitHubRepositories);
return gitHubRepositories;
} catch (Throwable e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage(), e);
}
}
public void cloneRepository(String destinationFolderId,
String repositoryOwner, String repositoryName)
throws ServiceException {
try {
RepositoryService service;
if (gitHubClient == null) {
service = new RepositoryService();
} else {
service = new RepositoryService(gitHubClient);
}
Repository repository = service.getRepository(repositoryOwner,
repositoryName);
logger.debug("Repository: [Name=" + repository.getName()
+ ", Watcher=" + repository.getWatchers() + ", GitUrl="
+ repository.getGitUrl() + "]");
createContent(destinationFolderId, repository, null);
} catch (ServiceException e) {
throw e;
} catch (Throwable e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage(), e);
}
}
private void createContent(String destinationFolderId, Repository repo,
String path) throws ServiceException {
try {
ContentsService contentsService;
if (gitHubClient == null) {
contentsService = new ContentsService();
} else {
contentsService = new ContentsService(gitHubClient);
}
List<RepositoryContents> listRepositoryContents;
if (path == null) {
listRepositoryContents = contentsService.getContents(repo);
} else {
listRepositoryContents = contentsService
.getContents(repo, path);
}
for (RepositoryContents contents : listRepositoryContents) {
logger.debug("Contents: [name=" + contents.getName()
+ ", type=" + contents.getType() + ", encoding="
+ contents.getEncoding() + ", path="
+ contents.getPath() + ", sha=" + contents.getSha()
+ "]");
if (contents.getType() != null) {
if (contents.getType().compareToIgnoreCase(
RepositoryContents.TYPE_FILE) == 0) {
createFile(destinationFolderId, repo, contents);
} else {
if (contents.getType().compareToIgnoreCase(
RepositoryContents.TYPE_DIR) == 0) {
createDirectory(destinationFolderId, repo, contents);
} else {
}
}
}
}
} catch (ServiceException e) {
throw e;
} catch (Throwable e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage(), e);
}
}
private void createDirectory(String destinationFolderId,
Repository repository, RepositoryContents contents)
throws ServiceException {
try {
logger.debug("Directory: [destinationFolderId="
+ destinationFolderId + ", folderName="
+ contents.getName() + ", folderDescription="
+ contents.getName() + "]");
StorageUtil.createFolderOnWorkspace(userName, destinationFolderId,
contents.getName(), contents.getName());
createContent(destinationFolderId, repository, contents.getPath());
} catch (ServiceException e) {
throw e;
} catch (Throwable e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage(), e);
}
}
private void createFile(String destinationFolderId, Repository repository,
RepositoryContents contents) throws ServiceException {
try {
DataService dataService;
if (gitHubClient == null) {
dataService = new DataService();
} else {
dataService = new DataService(gitHubClient);
}
Blob blob = dataService.getBlob(repository, contents.getSha());
logger.debug("Blob: [encoding=" + blob.getEncoding() + "]");
if (blob.getEncoding().compareToIgnoreCase(
RepositoryContents.ENCODING_BASE64) == 0) {
byte[] decodedBytes = Base64.decodeBase64(blob.getContent()
.getBytes());
InputStream is = new ByteArrayInputStream(decodedBytes);
StorageUtil.saveOnWorkspace(userName, destinationFolderId,
contents.getName(), contents.getName(), is);
// logger.debug(new String(decodedBytes));
}
} catch (Throwable e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage(), e);
}
}
}

@ -0,0 +1,70 @@
package org.gcube.portlets.widgets.githubconnector.server.git;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.eclipse.egit.github.core.Repository;
import org.gcube.portlets.widgets.githubconnector.shared.exception.ServiceException;
import org.gcube.portlets.widgets.githubconnector.shared.git.GitHubRepository;
import org.gcube.portlets.widgets.githubconnector.shared.git.GitHubUser;
public class GitHubRepositoryBuilder {
private static Logger logger = Logger
.getLogger(GitHubRepositoryBuilder.class);
public static GitHubRepository build(Repository repository)
throws ServiceException {
try {
if (repository != null) {
if (repository.getOwner() != null) {
GitHubUser gitHubUser = new GitHubUser(repository
.getOwner().getId(), repository.getOwner()
.getName(), repository.getOwner().getLogin(),
repository.getOwner().getCompany(), repository
.getOwner().getLocation(), repository
.getOwner().getUrl(), repository.getOwner()
.getEmail());
GitHubRepository gitHubRepository = new GitHubRepository(
repository.getId(), repository.getName(),
gitHubUser, repository.getDescription(),
repository.getGitUrl(), repository.getWatchers(),
repository.getCreatedAt(),
repository.getUpdatedAt());
return gitHubRepository;
} else {
logger.error("Invalid owner for repository: "
+ repository.getName());
throw new ServiceException("Invalid owner for repository: "
+ repository.getName());
}
} else {
logger.error("Invalid repository: null");
throw new ServiceException("Invalid repository: null");
}
} catch (Throwable e) {
e.printStackTrace();
logger.error(e.getLocalizedMessage());
throw new ServiceException(e.getLocalizedMessage(), e);
}
}
public static ArrayList<GitHubRepository> build(
List<Repository> repositories) throws ServiceException {
if (repositories != null) {
ArrayList<GitHubRepository> gitHubRepositories = new ArrayList<>();
for (Repository repository : repositories) {
GitHubRepository gitHubRepository = build(repository);
gitHubRepositories.add(gitHubRepository);
}
return gitHubRepositories;
} else {
logger.error("Invalid list of repositories: null!");
throw new ServiceException("Invalid list of repositories: null!");
}
}
}

@ -0,0 +1,128 @@
package org.gcube.portlets.widgets.githubconnector.server.storage;
import java.io.InputStream;
import org.apache.log4j.Logger;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.homelibrary.home.workspace.exceptions.InsufficientPrivilegesException;
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException;
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.common.homelibrary.home.workspace.exceptions.WrongDestinationException;
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
import org.gcube.portlets.widgets.githubconnector.shared.exception.ServiceException;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class StorageUtil {
private static Logger logger = Logger.getLogger(StorageUtil.class);
/**
*
* @param user
* @param itemId
* @throws ServiceException
*/
public static void deleteItem(String user, String itemId)
throws ServiceException {
Workspace ws;
try {
logger.debug("User: " + user + ", ItemId:" + itemId);
ws = HomeLibrary.getUserWorkspace(user);
ws.removeItems(itemId);
return;
} catch (InsufficientPrivilegesException
| WorkspaceFolderNotFoundException | InternalErrorException
| HomeNotFoundException | ItemNotFoundException e) {
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage(), e);
}
}
/**
*
* @param user
* @param destinationFolderId
* @param folderName
* @param folderDescription
* @return
* @throws ServiceException
*/
public static String createFolderOnWorkspace(String user,
String destinationFolderId, String folderName,
String folderDescription) throws ServiceException {
try {
logger.debug("CreateFolderOnWorkspace: [User=" + user
+ ", FolderId:" + destinationFolderId + ", folderName="
+ folderName + ", folderDescription=" + folderDescription
+ "]");
Workspace ws = HomeLibrary.getUserWorkspace(user);
WorkspaceFolder workspaceFolder=ws.createFolder(folderName, folderDescription, destinationFolderId);
return workspaceFolder.getId();
} catch (WorkspaceFolderNotFoundException | InternalErrorException
| HomeNotFoundException | InsufficientPrivilegesException | ItemAlreadyExistException | WrongDestinationException | ItemNotFoundException e) {
logger.error("CreateFolderOnWorkspace: " + e.getLocalizedMessage());
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage(), e);
}
}
/**
*
* @param user
* @param destinationFolderId
* @param fileName
* @param fileDescription
* @param mimeType
* @param is
* @return
* @throws ServiceException
*/
public static String saveOnWorkspace(String user,
String destinationFolderId, String fileName,
String fileDescription, InputStream is)
throws ServiceException {
try {
logger.debug("saveOnWorkspace: [User=" + user + ", FolderId:"
+ destinationFolderId + ", fileName=" + fileName
+ ", fileDescription=" + fileDescription + "]");
Workspace ws = HomeLibrary.getUserWorkspace(user);
WorkspaceItem workspaceItem = ws.getItem(destinationFolderId);
if (workspaceItem.isFolder()) {
ExternalFile externalfile = ws.createExternalFile(fileName,
fileDescription, null, is, destinationFolderId);
return externalfile.getId();
} else {
throw new ServiceException("Invalid destination folder!");
}
} catch (WorkspaceFolderNotFoundException | InternalErrorException
| HomeNotFoundException | InsufficientPrivilegesException
| ItemAlreadyExistException | WrongDestinationException
| ItemNotFoundException e) {
logger.error("SaveOnWorkspace: " + e.getLocalizedMessage());
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage(), e);
}
}
}

@ -0,0 +1,25 @@
package org.gcube.portlets.widgets.githubconnector.shared;
/**
*
* @author Giancarlo Panichi
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class Constants {
public static final boolean DEBUG_MODE = true;
public static final boolean TEST_ENABLE = false;
public static final String APPLICATION_ID = "org.gcube.portlets.widgets.githubconnector.portlet.GitHubConnectorPortlet";
public static final String GITHUB_CONNECTOR_ID = "GitHubConnectorId";
public static final String GITHUB_CONNECTOR_LANG_COOKIE = "GitHubConnectorLangCookie";
public static final String GITHUB_CONNECTOR_LANG = "GitHubConnectorLang";
public static final String DEFAULT_USER = "giancarlo.panichi";
public static final String DEFAULT_ROLE = "OrganizationMember";
public final static String DEFAULT_SCOPE = "/gcube/devsec/devVRE";
public static final String DEFAULT_FOLDER_ID = "";
}

@ -0,0 +1,37 @@
package org.gcube.portlets.widgets.githubconnector.shared.exception;
/**
* ASL Session Expired Exception
*
* @author "Giancarlo Panichi"
*
*/
public class ExpiredSessionServiceException extends
ServiceException {
private static final long serialVersionUID = -4831171355042165166L;
/**
*
*/
public ExpiredSessionServiceException() {
super();
}
/**
* @param message
*/
public ExpiredSessionServiceException(String message) {
super(message);
}
/**
*
* @param message
* @param t
*/
public ExpiredSessionServiceException(String message, Throwable t) {
super(message, t);
}
}

@ -0,0 +1,38 @@
/**
*
*/
package org.gcube.portlets.widgets.githubconnector.shared.exception;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class ServiceException extends Exception {
private static final long serialVersionUID = -2255657546267656458L;
/**
*
*/
public ServiceException() {
super();
}
/**
* @param message
*/
public ServiceException(String message) {
super(message);
}
public ServiceException(String message,Throwable t) {
super(message,t);
}
}

@ -0,0 +1,107 @@
package org.gcube.portlets.widgets.githubconnector.shared.git;
import java.io.Serializable;
import java.util.Date;
public class GitHubRepository implements Serializable {
private static final long serialVersionUID = 3024419362503115243L;
private long id;
private String name;
private GitHubUser owner;
private String description;
private String gitUrl;
private int watchers;
private Date createdAt;
private Date updatedAt;
public GitHubRepository() {
super();
}
public GitHubRepository(long id, String name, GitHubUser owner,
String description, String gitUrl, int watchers, Date createdAt,
Date updatedAt) {
super();
this.id = id;
this.name = name;
this.owner = owner;
this.description = description;
this.gitUrl = gitUrl;
this.watchers = watchers;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public GitHubUser getOwner() {
return owner;
}
public void setOwner(GitHubUser owner) {
this.owner = owner;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getGitUrl() {
return gitUrl;
}
public void setGitUrl(String gitUrl) {
this.gitUrl = gitUrl;
}
public int getWatchers() {
return watchers;
}
public void setWatchers(int watchers) {
this.watchers = watchers;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
@Override
public String toString() {
return "GitHubRepository [id=" + id + ", name=" + name + ", owner="
+ owner + ", description=" + description + ", gitUrl=" + gitUrl
+ ", watchers=" + watchers + ", createdAt=" + createdAt
+ ", updatedAt=" + updatedAt + "]";
}
}

@ -0,0 +1,103 @@
package org.gcube.portlets.widgets.githubconnector.shared.git;
import java.io.Serializable;
/**
*
* @author Giancarlo Panichi
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class GitHubUser implements Serializable {
private static final long serialVersionUID = -2781665528432877646L;
private int id;
private String name;
private String login;
private String company;
private String location;
private String url;
private String email;
public GitHubUser(){
super();
}
public GitHubUser(int id, String name, String login, String company,
String location, String url, String email) {
super();
this.id = id;
this.name = name;
this.login = login;
this.company = company;
this.location = location;
this.url = url;
this.email = email;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return "GitHubUser [id=" + id + ", name=" + name + ", login=" + login
+ ", company=" + company + ", location=" + location + ", url="
+ url + ", email=" + email + "]";
}
}

@ -0,0 +1,114 @@
package org.gcube.portlets.widgets.githubconnector.shared.session;
import java.io.Serializable;
/**
*
* @author giancarlo
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class UserInfo implements Serializable {
private static final long serialVersionUID = -2826549639677017234L;
private String username;
private long groupId;
private String groupName;
private String scope;
private String scopeName;
private String userEmailAddress;
private String userFullName;
public UserInfo() {
super();
}
/**
*
* @param username
* @param groupId
* @param groupName
* @param scope
* @param scopeName
* @param userEmailAddress
* @param userFullName
*/
public UserInfo(String username, long groupId, String groupName,
String scope, String scopeName, String userEmailAddress,
String userFullName) {
super();
this.username = username;
this.groupId = groupId;
this.groupName = groupName;
this.scope = scope;
this.scopeName = scopeName;
this.userEmailAddress = userEmailAddress;
this.userFullName = userFullName;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public long getGroupId() {
return groupId;
}
public void setGroupId(long groupId) {
this.groupId = groupId;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
public String getScopeName() {
return scopeName;
}
public void setScopeName(String scopeName) {
this.scopeName = scopeName;
}
public String getUserEmailAddress() {
return userEmailAddress;
}
public void setUserEmailAddress(String userEmailAddress) {
this.userEmailAddress = userEmailAddress;
}
public String getUserFullName() {
return userFullName;
}
public void setUserFullName(String userFullName) {
this.userFullName = userFullName;
}
@Override
public String toString() {
return "UserInfo [username=" + username + ", groupId=" + groupId
+ ", groupName=" + groupName + ", scope=" + scope
+ ", scopeName=" + scopeName + ", userEmailAddress="
+ userEmailAddress + ", userFullName=" + userFullName + "]";
}
}

@ -0,0 +1 @@
< ャ@Qaj、F÷gク<67>

@ -0,0 +1 @@
6 4Z<34>/U<><55> C<><43>ߘ

@ -0,0 +1 @@
6 4Z<34>/U<><55> C<><43>ߘ

@ -0,0 +1 @@
< ャ@Qaj、F÷gク<67>

@ -0,0 +1 @@
6 4Z<34>/U<><55> C<><43>ߘ

@ -0,0 +1,6 @@
You should put the infrastructure decrypt keys here.
the keys must be in named "<scope name>.gcubekey", e.g. "gcube.gcubekey" or "devsec.gcubekey"
The content of this folder is automatically loaded in the classpath when tomcat starts up.

@ -0,0 +1,20 @@
# A default log4j configuration for log4j users.
#
# To use this configuration, deploy it into your application's WEB-INF/classes
# directory. You are also encouraged to edit it as you like.
log4j.rootLogger=DEBUG, stdout, rollingFile
# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender
log4j.appender.rollingFile.File=test.log
log4j.appender.rollingFile.MaxFileSize=20MB
log4j.appender.rollingFile.MaxBackupIndex=2
log4j.appender.rollingFile.layout = org.apache.log4j.PatternLayout
log4j.appender.rollingFile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='githubman'>
<inherits name='com.google.gwt.user.User' />
<inherits name="com.google.gwt.http.HTTP" />
<inherits name='com.google.gwt.user.theme.clean.Clean' />
<!-- <inherits name="com.google.gwt.logging.Logging" /> -->
<!-- <inherits name="com.allen_sauer.gwt.log.gwt-log-TRACE" /> -->
<inherits name="com.google.gwt.logging.Logging" />
<!-- Debug CSS style -->
<set-configuration-property name="CssResource.style"
value="pretty" />
<!-- <inherits name="org.gcube.portlets.user.tdw.TabularDataWidget" /> <inherits
name='org.gcube.portlets.user.gcubewidgets.WidgetFactory' /> <inherits name='org.gcube.portlets.user.csvimportwizard.CSVImportWizard'
/> -->
<inherits name='org.gcube.portlets.widgets.sessionchecker.SessionChecker' />
<!-- <inherits name="org.gcube.portlets.user.csvimportwizard.ws.CSVImportWizardWorkspace"
/> -->
<entry-point
class='org.gcube.portlets.widgets.githubconnector.client.GitHubConnectorManager' />
<set-property name="gwt.logging.logLevel" value="SEVERE" />
<set-property name="gwt.logging.enabled" value="TRUE" />
<set-property name="gwt.logging.consoleHandler" value="ENABLED" />
<source path='client' />
<source path='shared' />
</module>

@ -0,0 +1 @@
6 4Z<34>/U<><55> C<><43>ߘ

@ -0,0 +1,29 @@
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="githubman/reset.css">
<link type="text/css" rel="stylesheet" href="GitHubConnector.css">
<link type="text/css" rel="stylesheet" href="gxt/css/gxt-all.css">
<title>Data Miner Manager</title>
<script type="text/javascript" src="githubman/js/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="githubman/githubman.nocache.js"></script>
</head>
<body>
<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1'
style="position: absolute; width: 0; height: 0; border: 0"></iframe>
<noscript>
<div
style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
Your web browser must have JavaScript enabled in order for this
application to display correctly.</div>
</noscript>
<!-- <div id="contentDiv"></div> -->
</body>
</html>

@ -0,0 +1,14 @@
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!-- -->
<!-- The module reference below is the link -->
<!-- between html and your Web Toolkit module -->
<link rel="stylesheet" href="<%= request.getContextPath()%>/githubman/reset.css" type="text/css"/>
<link rel="stylesheet" href="<%= request.getContextPath()%>/GitHubConnector.css" type="text/css">
<link rel="stylesheet" href="<%= request.getContextPath()%>/gxt/css/gxt-all.css" type="text/css">
<script src='<%=request.getContextPath()%>/githubman/js/jquery-1.10.1.min.js'></script>
<script src='<%=request.getContextPath()%>/githubman/githubman.nocache.js'></script>
<div class="contentDiv" id="contentDiv"></div>

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!DOCTYPE display PUBLIC "-//Liferay//DTD Display 5.2.0//EN" "http://www.liferay.com/dtd/liferay-display_5_2_0.dtd">
<display>
<category name="gCube Applications">
<portlet id="GitHubConnector" />
</category>
</display>

@ -0,0 +1,9 @@
name=GitHubConnector
module-group-id=liferay
module-incremental-version=1
tags=
short-description=
change-log=
page-url=http://www.d4science.eu
author=D4Science EU
licenses=

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 5.2.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_5_2_0.dtd">
<liferay-portlet-app>
<portlet>
<portlet-name>GitHubConnector</portlet-name>
<layout-cacheable>false</layout-cacheable>
<instanceable>false</instanceable>
<ajaxable>false</ajaxable>
</portlet>
</liferay-portlet-app>

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns='http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd' version='2.0'>
<portlet>
<description>GitHubConnector</description>
<portlet-name>GitHubConnector</portlet-name>
<display-name>GitHubConnector</display-name>
<portlet-class>org.gcube.portlets.widgets.githubconnector.portlet.GitHubConnectorPortlet</portlet-class>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
</supports>
<portlet-info>
<title>GitHubConnector</title>
<short-title>GitHubConnector</short-title>
</portlet-info>
</portlet>
</portlet-app>

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>GitHubConnectorServlet</servlet-name>
<servlet-class>org.gcube.portlets.widgets.githubconnector.server.GitHubConnectorServiceImpl</servlet-class>
</servlet>
<servlet>
<servlet-name>jUnitHostImpl</servlet-name>
<servlet-class>com.google.gwt.junit.server.JUnitHostImpl</servlet-class>
</servlet>
<servlet>
<servlet-name>checkServlet</servlet-name>
<servlet-class>org.gcube.portlets.widgets.sessionchecker.server.SessionCheckerServiceImpl</servlet-class>
</servlet>
<servlet>
<servlet-name>scopeService</servlet-name>
<servlet-class>org.gcube.portlets.user.gcubewidgets.server.ScopeServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>GitHubConnectorServlet</servlet-name>
<url-pattern>/githubman/githubconnectorservice</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jUnitHostImpl</servlet-name>
<url-pattern>/githubman/junithost/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>checkServlet</servlet-name>
<url-pattern>/githubman/checksession</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>scopeService</servlet-name>
<url-pattern>/githubman/scopeService</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>GitHubConnector.html</welcome-file>
</welcome-file-list>
</web-app>

@ -0,0 +1,135 @@
package org.gcube.portlets.widgets.githubconnector;
import java.util.List;
import junit.framework.TestCase;
import org.apache.commons.codec.binary.Base64;
import org.eclipse.egit.github.core.Blob;
import org.eclipse.egit.github.core.Milestone;
import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.RepositoryContents;
import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.service.ContentsService;
import org.eclipse.egit.github.core.service.DataService;
import org.eclipse.egit.github.core.service.MilestoneService;
import org.eclipse.egit.github.core.service.RepositoryService;
import org.gcube.portlets.widgets.githubconnector.server.git.GitConnectorService;
import org.gcube.portlets.widgets.githubconnector.shared.Constants;
import org.gcube.portlets.widgets.githubconnector.shared.exception.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class GitHubConnectorTest extends TestCase {
private static Logger logger = LoggerFactory.getLogger(GitHubConnectorTest.class);
public void testExecuteProcess() {
if (Constants.TEST_ENABLE) {
executeProcess();
} else {
assertTrue(true);
}
}
public void testGitHubConnectorService() {
if (Constants.TEST_ENABLE) {
GitConnectorService gitConnectorService=new GitConnectorService(Constants.DEFAULT_USER);
try {
gitConnectorService.cloneRepository(Constants.DEFAULT_FOLDER_ID,"jonan", "jonan.github.io");
} catch (ServiceException e) {
assertFalse(true);
e.printStackTrace();
}
assertTrue(true);
} else {
assertTrue(true);
}
}
private void executeProcess() {
try {
logger.debug("Connect to GitHub");
// Basic authentication
GitHubClient client = new GitHubClient();
client.setCredentials("giamak@gmail.com", "1qaz2wsx$");
/*
* GitHubRequest req = new GitHubRequest();
* req.setUri("git://github.com/jonan/flingbox.git"); GitHubResponse
* resp = client.get(req); logger.debug(resp.toString());
*/
/*
* RepositoryService service = new RepositoryService(); for
* (Repository repo : service.getRepositories("jonan")) {
*/
RepositoryService service = new RepositoryService();
Repository repo = service.getRepository("jonan", "jonan.github.io");
logger.debug("Repository: [Name=" + repo.getName()
+ ", Watcher=" + repo.getWatchers() + ", GitUrl="
+ repo.getGitUrl() + "]");
MilestoneService milestoneService = new MilestoneService(client);
List<Milestone> listMilestone = milestoneService.getMilestones(
repo, null);
for (Milestone milestone : listMilestone) {
logger.debug("Milestone: [Title=" + milestone.getTitle()
+ ", Number=" + milestone.getNumber() + ", URL="
+ milestone.getUrl() + "]");
}
ContentsService contentsService = new ContentsService(client);
List<RepositoryContents> listRepositoryContents = contentsService
.getContents(repo);
for (RepositoryContents contents : listRepositoryContents) {
logger.debug("Contents: [name=" + contents.getName()
+ ", type=" + contents.getType() + ", encoding="
+ contents.getEncoding() + ", path="
+ contents.getPath() + ", sha=" + contents.getSha()
+ "]");
DataService dataService = new DataService(client);
if (contents.getName().compareTo("README.md") == 0) {
Blob blob = dataService.getBlob(repo, contents.getSha());
logger.debug("Blob: [encoding=" + blob.getEncoding()
+ ", content=" + blob.getContent() + "]");
if (blob.getEncoding().compareToIgnoreCase("base64") == 0) {
byte[] content = Base64.decodeBase64(blob.getContent()
.getBytes());
logger.debug(new String(content));
}
}
}
//DeployKeyService deployKeyService=new DeployKeyService(client);
/*
PullRequestService pullRequetService=new PullRequestService(client);
CommitService commitService=new CommitService(client);
RepositoryCommit repoCommit=new RepositoryCommit();
CommitFile commitFile=new CommitFile();
*/
logger.debug("---------------------------------------------");
// }
} catch (Exception e) {
logger.debug(e.getLocalizedMessage());
e.printStackTrace();
fail(e.getLocalizedMessage());
}
}
}
Loading…
Cancel
Save