GCube Release 4.1

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/github-connector@133137 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2016-10-12 13:48:15 +00:00
parent ca90f62979
commit abd2a2df81
68 changed files with 4792 additions and 0 deletions

29
1.1/.classpath Normal file
View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/github-connector-1.1.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"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="target/github-connector-1.1.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

64
1.1/.project Normal file
View File

@ -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>

1
1.1/distro/LICENSE Normal file
View File

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

68
1.1/distro/README Normal file
View File

@ -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.

11
1.1/distro/changelog.xml Normal file
View File

@ -0,0 +1,11 @@
<ReleaseNotes>
<Changeset component="org.gcube.portlets.widgets.githubconnector.1-1-0"
date="2016-10-01">
<Change>Removed accesslogger dependency</Change>
<Change>Updated to Auth 2.0</Change>
</Changeset>
<Changeset component="org.gcube.portlets.widgets.githubconnector.1-0-0"
date="2016-07-01">
<Change>First release</Change>
</Changeset>
</ReleaseNotes>

32
1.1/distro/descriptor.xml Normal file
View File

@ -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>

29
1.1/distro/profile.xml Normal file
View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource>
<ID></ID>
<Type>Library</Type>
<Profile>
<Description>${project.description}</Description>
<Class>PortletsWidgets</Class>
<Name>${project.name}</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Description>${project.description}</Description>
<Name>${project.name}</Name>
<Version>${version}</Version>
<MavenCoordinates>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</MavenCoordinates>
<Type>library</Type>
<Files>
<File>${project.build.finalName}.${project.packaging}</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

412
1.1/pom.xml Normal file
View File

@ -0,0 +1,412 @@
<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.1.0-SNAPSHOT</version>
<packaging>jar</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>
<gwtLogVersion>3.3.2</gwtLogVersion>
<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>
<dependency>
<groupId>xerces</groupId>
<artifactId>xerces</artifactId>
<version>2.4.0</version>
</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>
<!-- Authorization -->
<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>
<!-- PORTAL -->
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId>
<scope>provided</scope>
</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 Widgets -->
<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>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</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>com.allen-sauer.gwt.log</groupId>
<artifactId>gwt-log</artifactId>
<version>${gwtLogVersion}</version>
</dependency>
<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>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<skipTests>true</skipTests>
<exclude>**/GwtTest*.java</exclude>
</configuration>
<!-- TODO check if needed -->
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.16</version>
</dependency>
</dependencies>
</plugin>
<!-- 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>test</goal> -->
<goal>resources</goal>
</goals>
</execution>
</executions>
<configuration>
<runTarget>GitHubConnector.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<module>org.gcube.portlets.widgets.githubconnector.githubman</module>
<includes>**/GwtTest*.java</includes>
</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>LATEST</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<name>github-connector</name>
</project>

View File

@ -0,0 +1,101 @@
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",-1);
sessionExpiredShowDelayed();
} else {
GWTMessages.alert(
"Error",
"No user found: "
+ caught.getLocalizedMessage(),-1);
}
}
@Override
public void onSuccess(UserInfo result) {
userInfo = result;
GWT.log("Hello: " + userInfo.getUsername());
}
});
}
private void bind() {
}
}

View File

@ -0,0 +1,207 @@
package org.gcube.portlets.widgets.githubconnector.client;
import org.gcube.portlets.widgets.githubconnector.client.util.GWTMessages;
import org.gcube.portlets.widgets.githubconnector.client.wizard.WizardCard;
import org.gcube.portlets.widgets.githubconnector.shared.git.data.credential.GitHubCredentialAnonymous;
import org.gcube.portlets.widgets.githubconnector.shared.git.data.credential.GitHubCredentialLogin;
import org.gcube.portlets.widgets.githubconnector.shared.git.data.credential.GitHubCredentialOAuth2;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.TabLayoutPanel;
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 GitHubConnectorCredentialCard extends WizardCard {
private TabLayoutPanel tabPanel;
private TextBox userName;
private TextBox password;
private TextBox token;
private CheckBox anonymousCheck;
// private DecoratorPanel decPanel;
public GitHubConnectorCredentialCard() {
super("Credential", "Select the credentials to use[OAuth2 for big repository]");
tabPanel = new TabLayoutPanel(2.5, Unit.EM);
tabPanel.setAnimationDuration(1000);
tabPanel.setAnimationVertical(true);
tabPanel.getElement().getStyle().setMarginBottom(10.0, Unit.PX);
tabPanel.setHeight("120px");
tabPanel.setWidth("265px");
// Add Login Tab
SimplePanel loginContainer = new SimplePanel();
userName = new TextBox();
userName.setWidth("166px");
userName.setEnabled(false);
password = new TextBox();
password.setWidth("166px");
password.setEnabled(false);
anonymousCheck = new CheckBox();
anonymousCheck.setValue(true);
anonymousCheck.ensureDebugId("credentialCheckBoxAnonymous");
anonymousCheck.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (anonymousCheck.getValue()) {
userName.setEnabled(false);
password.setEnabled(false);
userName.setValue("");
password.setValue("");
} else {
userName.setEnabled(true);
password.setEnabled(true);
userName.setValue("");
password.setValue("");
}
}
});
FlexTable loginFlexTable = new FlexTable();
loginFlexTable.setCellSpacing(16);
loginFlexTable.setHTML(1, 0, "Anonymous:");
loginFlexTable.setWidget(1, 1, anonymousCheck);
loginFlexTable.setHTML(2, 0, "User:");
loginFlexTable.setWidget(2, 1, userName);
loginFlexTable.setHTML(3, 0, "Password:");
loginFlexTable.setWidget(3, 1, password);
loginContainer.add(loginFlexTable);
tabPanel.add(loginContainer, "Login");
// Add OAuth2 Tab
SimplePanel oAuth2Container = new SimplePanel();
token = new TextBox();
token.setWidth("200px");
FlexTable oAuth2FlexTable = new FlexTable();
oAuth2FlexTable.setCellSpacing(16);
oAuth2FlexTable.setHTML(1, 0, "Token:");
oAuth2FlexTable.setWidget(1, 1, token);
oAuth2Container.add(oAuth2FlexTable);
tabPanel.add(oAuth2Container, "OAuth2");
tabPanel.selectTab(0);
tabPanel.ensureDebugId("credentialTabPanel");
setContent(tabPanel);
}
@Override
public void setup() {
Command sayNextCard = new Command() {
public void execute() {
checkData();
}
};
Command sayPreviousCard = new Command() {
public void execute() {
try {
GWT.log("PreviousCard");
getWizardWindow().previousCard();
} catch (Exception e) {
GWT.log("sayPreviousCard :" + e.getLocalizedMessage());
e.printStackTrace();
}
}
};
getWizardWindow().setPreviousButtonCommand(sayPreviousCard);
getWizardWindow().setNextButtonCommand(sayNextCard);
setEnableBackButton(false);
setBackButtonVisible(false);
setEnableNextButton(true);
setNextButtonVisible(true);
}
private void checkData() {
int selectedIndex = tabPanel.getSelectedIndex();
if (selectedIndex > -1) {
GWT.log("Selected Tab:" + selectedIndex);
if (selectedIndex == 0) {
if (anonymousCheck.getValue()) {
GitHubConnectorWizard wiz = (GitHubConnectorWizard) getWizardWindow();
wiz.getGitHubCloneSession().setGitHubCredential(
new GitHubCredentialAnonymous());
goNext();
} else {
String userN = userName.getValue();
if (userN == null || userN.isEmpty()) {
GWTMessages.alert("Attention", "Enter a user name!",getZIndex());
} else {
String pwd = password.getValue();
if (pwd == null || pwd.isEmpty()) {
GWTMessages.alert("Attention",
"Enter a user password!", getZIndex());
} else {
GitHubConnectorWizard wiz = (GitHubConnectorWizard) getWizardWindow();
wiz.getGitHubCloneSession().setGitHubCredential(
new GitHubCredentialLogin(userN, pwd));
goNext();
}
}
}
} else {
if (selectedIndex == 1) {
String tk = token.getValue();
if (tk == null || tk.isEmpty()) {
GWTMessages.alert("Attention", "Enter a token!",getZIndex());
} else {
GitHubConnectorWizard wiz = (GitHubConnectorWizard) getWizardWindow();
wiz.getGitHubCloneSession().setGitHubCredential(
new GitHubCredentialOAuth2(tk));
goNext();
}
} else {
GWTMessages.alert("Attention", "Select a valid tab!",getZIndex());
}
}
}
}
private void goNext() {
try {
GWT.log("NextCard: GitHubConnectorRepositorySelectionCard");
GitHubConnectorRepositorySelectionCard card = new GitHubConnectorRepositorySelectionCard();
getWizardWindow().addCard(card);
getWizardWindow().nextCard();
} catch (Throwable e) {
GWT.log("sayNextCard :" + e.getLocalizedMessage());
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,133 @@
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 org.gcube.portlets.widgets.githubconnector.client.wizard.event.WizardEvent;
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.core.shared.GWT;
import com.google.gwt.user.client.Window.Location;
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 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!",-1);
}
}
@Override
public void onFailure(Throwable caught) {
GWTMessages.alert("Error", "Error setting scope: "
+ caught.getLocalizedMessage(),-1);
caught.printStackTrace();
}
});
}
private void loadMainPanel() {
GWT.log("GitHubConnectorManager");
// Example
WizardEvent.WizardEventHandler handler = new WizardEvent.WizardEventHandler() {
@Override
public void onResponse(WizardEvent event) {
GWT.log("Wizard Response: " + event.getWizardEventType());
}
};
GitHubConnectorWizard wizard = new GitHubConnectorWizard(
"0cfde9e2-a6f0-451f-a048-adbd42d7d57f");
wizard.addWizardEventHandler(handler);
wizard.show();
/*
* WaitDialog progressDialog=new WaitDialog(); progressDialog.show();
*/
/*
* WizardWindow wizardWindow = new WizardWindow("TestWindow");
* SimpleWizardCard simple1=new
* SimpleWizardCard("Test Title 1","Test Footer 1", "This is 1 card");
* wizardWindow.addCard(simple1); SimpleWizardCard simple2=new
* SimpleWizardCard("Test Title 2","Test Footer 2", "This is 2 card");
* wizardWindow.addCard(simple2); SimpleWizardCard simple3=new
* SimpleWizardCard("Test Title 3","Test Footer 3", "This is 3 card");
* wizardWindow.addCard(simple3);
*
* wizardWindow.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()); } }
*/
}

View File

@ -0,0 +1,243 @@
package org.gcube.portlets.widgets.githubconnector.client;
import java.util.ArrayList;
import org.gcube.portlets.widgets.githubconnector.client.resource.GCResources;
import org.gcube.portlets.widgets.githubconnector.client.rpc.GitHubConnectorServiceAsync;
import org.gcube.portlets.widgets.githubconnector.client.util.GWTMessages;
import org.gcube.portlets.widgets.githubconnector.client.util.WaitDialog;
import org.gcube.portlets.widgets.githubconnector.client.wizard.WizardCard;
import org.gcube.portlets.widgets.githubconnector.client.wizard.event.WizardEvent;
import org.gcube.portlets.widgets.githubconnector.client.wizard.event.WizardEventType;
import org.gcube.portlets.widgets.githubconnector.shared.exception.ExpiredSessionServiceException;
import org.gcube.portlets.widgets.githubconnector.shared.git.data.GitHubRepository;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.SimplePanel;
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 GitHubConnectorRepositorySelectionCard extends WizardCard {
private TextBox repositoryOwner;
private ListBox repositoryName;
// private DecoratorPanel decPanel;
public GitHubConnectorRepositorySelectionCard() {
super("Repository", "Enter a owner for select repository");
try {
SimplePanel repositorySelectionPanel = new SimplePanel();
repositoryOwner = new TextBox();
repositoryName = new ListBox();
repositoryName.setWidth("176px");
repositoryName.setEnabled(false);
repositoryName.ensureDebugId("repositoryNameList");
repositorySelectionPanel.setStyleName(GCResources.INSTANCE
.wizardCSS().getCardPanel());
ClickHandler searchRepositoryClickHandler = new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
retrieveRepositories();
}
};
PushButton searchRepository = new PushButton(new Image(
GCResources.INSTANCE.search16()),
searchRepositoryClickHandler);
searchRepository.getElement().getStyle().setMargin(3, Unit.PX);
// Form
FlexTable layout = new FlexTable();
layout.setCellSpacing(10);
FlexTable loginFlexTable = new FlexTable();
loginFlexTable.setStyleName(GCResources.INSTANCE.wizardCSS()
.getCardPanelContent());
loginFlexTable.setCellSpacing(16);
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
loginFlexTable.setHTML(1, 0, "Owner:");
loginFlexTable.setWidget(1, 1, repositoryOwner);
loginFlexTable.setWidget(1, 2, searchRepository);
loginFlexTable.setHTML(2, 0, "Name:");
loginFlexTable.setWidget(2, 1, repositoryName);
cellFormatter.setColSpan(2, 1, 2);
repositorySelectionPanel.add(loginFlexTable);
setContent(repositorySelectionPanel);
} catch (Exception e) {
GWT.log("Error: " + e.getLocalizedMessage());
e.printStackTrace();
}
}
private void retrieveRepositories() {
String repOwner = repositoryOwner.getValue();
if (repOwner == null || repOwner.isEmpty()) {
GWTMessages.alert("Attention", "Enter a owner!",getZIndex());
} else {
final WaitDialog waitDialog = new WaitDialog(getZIndex());
waitDialog.show();
final GitHubConnectorWizard wiz = (GitHubConnectorWizard) getWizardWindow();
GitHubConnectorServiceAsync.INSTANCE.getRepositories(repOwner, wiz
.getGitHubCloneSession().getGitHubCredential(),
new AsyncCallback<ArrayList<GitHubRepository>>() {
@Override
public void onFailure(Throwable caught) {
waitDialog.hide();
GWT.log("Error retrieving repositories: "
+ caught.getMessage());
if (caught instanceof ExpiredSessionServiceException) {
showErrorAndHide("Error", "Expired Session");
wiz.sessionExpiredShowDelayed();
} else {
showErrorAndHide(
"Error",
"Retrieving repositories: "
+ caught.getLocalizedMessage());
}
}
@Override
public void onSuccess(
ArrayList<GitHubRepository> repositories) {
waitDialog.hide();
repositoryName.clear();
for (GitHubRepository repository : repositories) {
repositoryName.addItem(repository.getName());
}
repositoryName.setEnabled(true);
}
});
}
}
@Override
public void setup() {
Command sayNextCard = new Command() {
public void execute() {
checkData();
}
};
Command sayPreviousCard = new Command() {
public void execute() {
try {
GWT.log("PreviousCard");
getWizardWindow().setNextButtonToDefault();
getWizardWindow().previousCard();
} catch (Exception e) {
GWT.log("sayPreviousCard :" + e.getLocalizedMessage());
}
}
};
getWizardWindow().setPreviousButtonCommand(sayPreviousCard);
getWizardWindow().setNextButtonCommand(sayNextCard);
getWizardWindow().setNextButtonToFinish();
setEnableBackButton(true);
setBackButtonVisible(true);
setEnableNextButton(true);
setNextButtonVisible(true);
}
private void checkData() {
String repoOwner = repositoryOwner.getValue();
if (repoOwner == null || repoOwner.isEmpty()) {
GWTMessages.alert("Attention", "Enter a repository owner!",getZIndex());
} else {
int selected = repositoryName.getSelectedIndex();
if (selected >= 0) {
String repoName = repositoryName.getValue(selected);
if (repoName == null || repoName.isEmpty()) {
GWTMessages.alert("Attention", "Select a repository name!",getZIndex());
} else {
GitHubConnectorWizard wiz = (GitHubConnectorWizard) getWizardWindow();
wiz.getGitHubCloneSession().setRepositoryName(repoName);
wiz.getGitHubCloneSession().setRepositoryOwner(repoOwner);
callCloneForRepository();
}
} else {
GWTMessages.alert("Attention", "Select a repository name!",getZIndex());
}
}
}
private void callCloneForRepository() {
final WaitDialog waitDialog = new WaitDialog(getZIndex());
waitDialog.show();
final GitHubConnectorWizard wiz = (GitHubConnectorWizard) getWizardWindow();
GitHubConnectorServiceAsync.INSTANCE.cloneRepository(
wiz.getGitHubCloneSession(), new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable caught) {
waitDialog.hide();
GWT.log("Error in clone repository: "
+ caught.getMessage());
if (caught instanceof ExpiredSessionServiceException) {
showErrorAndHide("Error", "Expired Session");
wiz.sessionExpiredShowDelayed();
} else {
showErrorAndHide("Error", "In clone repository: "
+ caught.getLocalizedMessage());
}
}
@Override
public void onSuccess(Void result) {
waitDialog.hide();
goNext();
}
});
}
private void goNext() {
try {
GWT.log("NextCard");
WizardEvent event = new WizardEvent(WizardEventType.Completed);
getWizardWindow().fireEvent(event);
getWizardWindow().close(false);
} catch (Exception e) {
GWT.log("sayNextCard :" + e.getLocalizedMessage());
}
}
}

View File

@ -0,0 +1,62 @@
package org.gcube.portlets.widgets.githubconnector.client;
import org.gcube.portlets.widgets.githubconnector.client.wizard.WizardWindow;
import org.gcube.portlets.widgets.githubconnector.shared.git.GitHubCloneSession;
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Timer;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class GitHubConnectorWizard extends WizardWindow {
private GitHubCloneSession gitHubCloneSession;
public GitHubConnectorWizard(String destinationFolderId) {
super("GitHub Connector");
GWT.log("GitHubConnectorWizard: " + destinationFolderId);
checkSession();
gitHubCloneSession = new GitHubCloneSession(destinationFolderId);
create();
}
private void create() {
GitHubConnectorCredentialCard CredentialCard = new GitHubConnectorCredentialCard();
addCard(CredentialCard);
CredentialCard.setup();
}
public GitHubCloneSession getGitHubCloneSession() {
return gitHubCloneSession;
}
private void checkSession() {
// if you do not need to something when the session expire
CheckSession.getInstance().startPolling();
}
private void sessionExpiredShow() {
CheckSession.showLogoutDialog();
}
public void sessionExpiredShowDelayed() {
Timer timeoutTimer = new Timer() {
public void run() {
sessionExpiredShow();
}
};
int TIMEOUT = 3; // 3 second timeout
timeoutTimer.schedule(TIMEOUT * 1000); // timeout is in milliseconds
}
}

View File

@ -0,0 +1,34 @@
package org.gcube.portlets.widgets.githubconnector.client.resource;
import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public interface GCResources extends ClientBundle {
public static final GCResources INSTANCE = GWT.create(GCResources.class);
@Source("Wizard.css")
WizardCSS wizardCSS();
@Source("wizard-next_24.png")
ImageResource wizardNext24();
@Source("wizard-previous_24.png")
ImageResource wizardPrevious24();
@Source("wizard-go_24.png")
ImageResource wizardGo24();
@Source("tool-button-close_20.png")
ImageResource toolButtonClose20();
@Source("search_16.png")
ImageResource search16();
}

View File

@ -0,0 +1,94 @@
@CHARSET "UTF-8";
.wizard-card-title {
padding: 5px;
font-weight: bold;
font-size: small;
background-color: #f1f1f1;
}
.wizard-card-footer {
padding: 5px;
font-weight: bold;
font-size: x-small;
text-align: left;
background-color: #f1f1f1;
}
.wizard-previous-button-text {
line-height: 24px;
vertical-align: middle;
}
.wizard-previous-button-icon {
vertical-align: middle;
float: left;
}
.wizard-next-button-text {
line-height: 24px;
vertical-align: middle;
}
.wizard-next-button-icon {
vertical-align: middle;
float: right;
}
.wizard-tool-button-text {
margin-left: -20px;
margin-top: 2px;
}
.wizard-tool-button-text:hover {
margin-left: -20px;
margin-top: 0px;
}
.wizard-tool-button-icon {
height: 20px;
}
.wizard-tool-button-icon:hover {
height: 20px;
border: 1px solid #222;
}
.card-panel {
border: 1px solid #ccc;
background-color: white;
margin-top: 4px;
margin-bottom: 4px;
}
.card-panel-content {
margin: 6px;
}
/* Progress */
.progress-bar-container {
width: 100%;
height: 25px;
position: relative;
background-color: #f1f1f1;
}
.progress-bar {
color: #fff;
background-color: #a5a5a5;
height: 100%;
position: absolute;
line-height: inherit;
}
.progress-bar-text {
text-align: center;
color: #2d2d2d;
position: absolute;
width: 100%;
margin-top: 5px;
}

View File

@ -0,0 +1,55 @@
/**
*
*/
package org.gcube.portlets.widgets.githubconnector.client.resource;
import com.google.gwt.resources.client.CssResource;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public interface WizardCSS extends CssResource {
@ClassName("wizard-card-title")
public String getWizardCardTitle();
@ClassName("wizard-card-footer")
public String getWizardCardFooter();
@ClassName("wizard-previous-button-text")
public String getWizardPreviousButtonText();
@ClassName("wizard-previous-button-icon")
public String getWizardPreviousButtonIcon();
@ClassName("wizard-next-button-text")
public String getWizardNextButtonText();
@ClassName("wizard-next-button-icon")
public String getWizardNextButtonIcon();
@ClassName("wizard-tool-button-text")
public String getWizardToolButtonText();
@ClassName("wizard-tool-button-icon")
public String getWizardToolButtonIcon();
@ClassName("card-panel")
public String getCardPanel();
@ClassName("card-panel-content")
public String getCardPanelContent();
@ClassName("progress-bar-container")
public String getProgressBarContainer();
@ClassName("progress-bar")
public String getProgressBar();
@ClassName("progress-bar-text")
public String getProgressBarText();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 569 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 957 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -0,0 +1,30 @@
package org.gcube.portlets.widgets.githubconnector.client.rpc;
import java.util.ArrayList;
import org.gcube.portlets.widgets.githubconnector.shared.exception.ServiceException;
import org.gcube.portlets.widgets.githubconnector.shared.git.GitHubCloneSession;
import org.gcube.portlets.widgets.githubconnector.shared.git.data.GitHubRepository;
import org.gcube.portlets.widgets.githubconnector.shared.git.data.credential.GitHubCredential;
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;
/**
*
* @author Giancarlo Panichi
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
@RemoteServiceRelativePath("githubconnectorservice")
public interface GitHubConnectorService extends RemoteService {
public UserInfo hello() throws ServiceException;
public ArrayList<GitHubRepository> getRepositories(String repositoryOwner, GitHubCredential gitHubCredential) throws ServiceException;
public void cloneRepository(GitHubCloneSession gitHubCloneSession) throws ServiceException;
}

View File

@ -0,0 +1,33 @@
package org.gcube.portlets.widgets.githubconnector.client.rpc;
import java.util.ArrayList;
import org.gcube.portlets.widgets.githubconnector.shared.git.GitHubCloneSession;
import org.gcube.portlets.widgets.githubconnector.shared.git.data.GitHubRepository;
import org.gcube.portlets.widgets.githubconnector.shared.git.data.credential.GitHubCredential;
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 repositoryOwner,
GitHubCredential gitHubCredential,
AsyncCallback<ArrayList<GitHubRepository>> callback);
void cloneRepository(GitHubCloneSession gitHubCloneSession,
AsyncCallback<Void> callback);
}

View File

@ -0,0 +1,70 @@
package org.gcube.portlets.widgets.githubconnector.client.util;
import com.google.gwt.core.client.Callback;
import com.google.gwt.dom.client.Style.Unit;
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 {
private Callback<Void, Void> callback;
protected HTML msg;
protected double msgMinWidth=200;
protected double msgMinHeight=30;
public AlertDialog(String title, String text, int zIndex) {
init(title, text, zIndex);
}
public AlertDialog(String title, String text, int zIndex, Callback<Void, Void> callback) {
init(title, text, zIndex);
}
private void init(String title, String text, int zIndex) {
setText(title);
setModal(true);
setGlassEnabled(true);
Button closeButton = new Button("Close", this);
msg = new HTML(text, true);
msg.getElement().getStyle().setProperty("minWidth", msgMinWidth, Unit.PX);
msg.getElement().getStyle().setProperty("minHeight",msgMinHeight, Unit.PX);
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);
if(zIndex>0){
getGlassElement().getStyle().setZIndex(zIndex+4);
getElement().getStyle().setZIndex(zIndex+5);
}
center();
}
@Override
public void onClick(ClickEvent event) {
if(callback!=null){
callback.onSuccess(null);
}
hide();
}
}

View File

@ -0,0 +1,27 @@
package org.gcube.portlets.widgets.githubconnector.client.util;
import com.google.gwt.core.client.Callback;
/**
*
* @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, int zIndex) {
AlertDialog alertDialog = new AlertDialog(title, text, zIndex);
alertDialog.show();
}
public static void alert(String title, String text,int zIndex,
Callback<Void, Void> callback) {
AlertDialog alertDialog = new AlertDialog(title, text, zIndex, callback);
alertDialog.show();
}
}

View File

@ -0,0 +1,112 @@
package org.gcube.portlets.widgets.githubconnector.client.util;
import org.gcube.portlets.widgets.githubconnector.client.resource.GCResources;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.DialogBox;
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 WaitDialog extends DialogBox {
private HandlerRegistration resizeHandlerRegistration;
private HTML msg;
private String msgWidth = "200px";
private String msgHeight = "25px";
private Timer t;
public WaitDialog(int zIndex){
init("Please Wait", "Working...", zIndex);
}
public WaitDialog(String title, String text, int zIndex) {
init(title, text, zIndex);
}
private void init(String title, String text, int zIndex) {
GWT.log("WaitDialog:[title=" + title + ", text=" + text + "]");
GCResources.INSTANCE.wizardCSS().ensureInjected();
setModal(true);
setGlassEnabled(true);
initHandler();
setText(title);
msg = new HTML("<div class='"
+ GCResources.INSTANCE.wizardCSS().getProgressBarContainer()
+ "'>" + "<div class='"
+ GCResources.INSTANCE.wizardCSS().getProgressBar()
+ "' style='width:50%'></div>" + "<div class='"
+ GCResources.INSTANCE.wizardCSS().getProgressBarText() + "'>"
+ text + "</div>" + "</div><br>");
msg.setWidth(msgWidth);
msg.setHeight(msgHeight);
setWidget(msg);
if(zIndex>0){
getGlassElement().getStyle().setZIndex(zIndex+2);
getElement().getStyle().setZIndex(zIndex+3);
}
center();
startTimer();
}
private void initHandler() {
resizeHandlerRegistration = Window
.addResizeHandler(new ResizeHandler() {
@Override
public void onResize(ResizeEvent event) {
center();
}
});
}
private void startTimer() {
t = new Timer() {
private int width = 0;
@Override
public void run() {
if (width > 100) {
width = 0;
}
msg.getElement().getFirstChildElement().getFirstChildElement()
.getStyle().setWidth(width, Unit.PCT);
width += 10;
}
};
// Schedule the timer to run once in 200 millseconds.
t.scheduleRepeating(400);
}
private void stopTimer() {
t.cancel();
}
@Override
public void hide() {
stopTimer();
if (resizeHandlerRegistration != null) {
resizeHandlerRegistration.removeHandler();
resizeHandlerRegistration = null;
}
super.hide();
}
}

View File

@ -0,0 +1,75 @@
/**
*
*/
package org.gcube.portlets.widgets.githubconnector.client.wizard;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.SimplePanel;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class SimpleWizardCard extends WizardCard {
/**
* Create a new simple wizard card.
*
* @param title
* the card title.
* @param footer
* the card footer.
* @param content
* the card content.
*/
public SimpleWizardCard(String title, String footer, String content) {
super(title, footer);
SimplePanel contentPanel = new SimplePanel();
HTML htmlContent = new HTML(content);
htmlContent.setStyleName("wizard-simple-content");
contentPanel.add(htmlContent);
setContent(contentPanel);
}
@Override
public void setup() {
Command sayNextCard = new Command() {
public void execute() {
try {
GWT.log("NextCard");
getWizardWindow().nextCard();
} catch (Exception e) {
GWT.log("sayNextCard :" + e.getLocalizedMessage());
}
}
};
Command sayPreviousCard = new Command() {
public void execute() {
try {
GWT.log("PreviousCard");
getWizardWindow().previousCard();
} catch (Exception e) {
GWT.log("sayPreviousCard :" + e.getLocalizedMessage());
}
}
};
getWizardWindow().setPreviousButtonCommand(sayPreviousCard);
getWizardWindow().setNextButtonCommand(sayNextCard);
setEnableBackButton(true);
setBackButtonVisible(true);
setEnableNextButton(true);
setNextButtonVisible(true);
}
}

View File

@ -0,0 +1,244 @@
/**
*
*/
package org.gcube.portlets.widgets.githubconnector.client.wizard;
import org.gcube.portlets.widgets.githubconnector.client.resource.GCResources;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class WizardCard extends SimplePanel {
private WizardWindow wizardWindow;
private DockPanel dockPanel;
protected GCResources res=GCResources.INSTANCE;
/**
* Creates a new wizard card.
* The footer is automatically calculated.
* @param title the card title.
*/
public WizardCard(String title) {
this(title,"");
}
/**
* Creates a new wizard card.
* @param title the card title.
* @param footer the card footer.
*/
public WizardCard(String title, String footer) {
GWT.log(title);
res.wizardCSS().ensureInjected();
HTML t=new HTML(title);
t.setStyleName(res.wizardCSS().getWizardCardTitle());
HTML f=new HTML(footer);
f.setStyleName(res.wizardCSS().getWizardCardFooter());
dockPanel=new DockPanel();
dockPanel.setWidth("100%");
dockPanel.add(t, DockPanel.NORTH);
dockPanel.add(f, DockPanel.SOUTH);
setWidget(dockPanel);
}
/**
* Sets the card content.
* @param content the card content.
*/
public void setContent(Widget content)
{
GWT.log("Card SetContent()");
dockPanel.add(content, DockPanel.CENTER);
}
/**
* Enables the next button.
* @param enable <code>true</code> to enable it, <code>false</code> otherwise.
*/
public void setEnableNextButton(boolean enable)
{
if (wizardWindow!=null){
wizardWindow.setEnableNextButton(enable);
}
}
/**
* Enables the back button.
* @param enable <code>true</code> to enable the button, <code>false</code> otherwise.
*/
public void setEnableBackButton(boolean enable)
{
if (wizardWindow!=null){
wizardWindow.setEnableBackButton(enable);
}
}
/**dispose
* Sets the next button label.
* @param text the button label.
*/
public void setNextButtonText(String text)
{
if (wizardWindow!=null){
wizardWindow.setNextButtonText(text);
}
}
/**
* Sets the back button label.
* @param text the button label.
*/
public void setBackButtonText(String text)
{
if (wizardWindow!=null){
wizardWindow.setBackButtonText(text);
}
}
/**
* Visible the next button.
* @param visible <code>true</code> to show the button, <code>false</code> otherwise.
*/
public void setNextButtonVisible(boolean visible)
{
if (wizardWindow!=null){
wizardWindow.setNextButtonVisible(visible);
}
}
/**
* Visible the back button.
* @param visible <code>true</code> to show the button, <code>false</code> otherwise.
*/
public void setBackButtonVisible(boolean visible)
{
if (wizardWindow!=null){
wizardWindow.setBackButtonVisible(visible);
}
}
public void setNextButtonToFinish()
{
if (wizardWindow!=null){
wizardWindow.setNextButtonToFinish();
}
}
/**
* Sets the WizardWindow for this import card.
* @param wizardWindow the WizardWindow.
*/
protected void setWizardWindow(WizardWindow wizardWindow)
{
this.wizardWindow = wizardWindow;
}
/**
* Returns the current wizard window.
* @return the wizard window.
*/
protected WizardWindow getWizardWindow()
{
if (wizardWindow==null) throw new IllegalStateException("No Wizard Window setup");
return wizardWindow;
}
public void addToWindowTitle(String toAdd)
{
wizardWindow.setTitle(wizardWindow.getOriginalTitle()+toAdd);
}
/**
* Called before the card is showed.
*/
public void setup()
{
}
/**
* Called when the card is disposed.
*/
public void dispose()
{}
/**
* Add a listener to the next button.
* @param listener the listener to add.
*/
public void addNextButtonListener(ClickHandler listener)
{
if (wizardWindow!=null){
wizardWindow.addNextButtonListener(listener);
}
}
/**
* Gets the number of cards in the wizard window.
* @return the number of cards.
*/
public int getNumberOfCards()
{
return getWizardWindow().getCardStackSize();
}
/**
* Returns this card position on card list.
* @return the card position on the card stack.
*/
public int getCardPosition()
{
int indexPosition = getWizardWindow().getCardStack().indexOf(this);
return (indexPosition>=0)?indexPosition+1:indexPosition;
}
public void showErrorAndHide(String title, final String message, final Throwable throwable)
{
wizardWindow.showErrorAndHide(title, message, throwable);
}
public void showErrorAndHide(String title, final String message)
{
wizardWindow.showErrorAndHide(title, message);
}
public int getZIndex(){
return wizardWindow.getZIndex();
}
public void hideWindow()
{
wizardWindow.hide();
}
public EventBus getEventBus(){
return wizardWindow.eventBus;
}
}

View File

@ -0,0 +1,24 @@
package org.gcube.portlets.widgets.githubconnector.client.wizard;
import com.google.gwt.i18n.client.Messages;
/**
*
* @author giancarlo
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public interface WizardMessages extends Messages {
//
@DefaultMessage("Back")
String buttonBackLabel();
@DefaultMessage("Next")
String buttonNextLabel();
@DefaultMessage("Finish")
String buttonFinishLabel();
}

View File

@ -0,0 +1,615 @@
/**
*
*/
package org.gcube.portlets.widgets.githubconnector.client.wizard;
import java.util.ArrayList;
import org.gcube.portlets.widgets.githubconnector.client.resource.GCResources;
import org.gcube.portlets.widgets.githubconnector.client.util.GWTMessages;
import org.gcube.portlets.widgets.githubconnector.client.wizard.event.WizardEvent;
import org.gcube.portlets.widgets.githubconnector.client.wizard.event.WizardEventType;
import org.gcube.portlets.widgets.githubconnector.client.wizard.event.WizardEvent.WizardEventHandler;
import com.google.gwt.core.client.Callback;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.dom.client.Node;
import com.google.gwt.dom.client.Style.Float;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Event.NativePreviewEvent;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class WizardWindow extends DialogBox implements WizardEvent.HasWizardEventHandler {
private HandlerRegistration resizeHandlerRegistration;
protected boolean WIZARD_RESIZABLE = false;
protected boolean WIZARD_COLLAPSIBLE = true;
protected EventBus eventBus;
protected String title;
protected ArrayList<WizardCard> cardStack = new ArrayList<WizardCard>();
protected Button backButton;
protected Button nextButton;
protected String originalTitle;
protected boolean checkBeforeClose = true;
protected boolean nextCardFinish = false;
protected Command nextButtonAction = null;
protected Command previousButtonAction = null;
protected DockPanel dockPanel;
protected FlowPanel moveToolBar;
// protected FillToolItem fillSpacingCardMoveToolBar;
protected WizardMessages msgs;
protected DeckPanel deckPanel;
private Node closeEventTarget = null;
private int zIndex=-1;
/**
* Create a new Wizard Window with the specified title.
*
* @param title
* the wizard window title.
*/
public WizardWindow(String title) {
this(title, new SimpleEventBus());
}
public WizardWindow(String title, EventBus eventBus) {
super();
GWT.log("WizardWindow");
this.title = title;
this.eventBus = eventBus;
this.msgs = GWT.create(WizardMessages.class);
initWindow();
initHandler();
addToolIcon();
deckPanel = new DeckPanel();
backButton = new Button("<div><img class='"
+ GCResources.INSTANCE.wizardCSS()
.getWizardPreviousButtonIcon()
+ "' src='"
+ GCResources.INSTANCE.wizardPrevious24().getSafeUri()
.asString()
+ "'/>"
+ "<span class='"
+ GCResources.INSTANCE.wizardCSS()
.getWizardPreviousButtonText() + "'>"
+ msgs.buttonBackLabel() + "</span>" + "</div>");
backButton.setEnabled(false);
backButton.setTabIndex(1001);
backButton.getElement().getStyle().setFloat(Float.LEFT);
backButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (previousButtonAction != null)
previousButtonAction.execute();
else
previousCard();
}
});
nextButton = new Button();
setNextButtonToDefault();
nextButton.setEnabled(false);
nextButton.setTabIndex(1002);
nextButton.getElement().getStyle().setFloat(Float.RIGHT);
nextButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (nextButtonAction != null)
nextButtonAction.execute();
else
nextCard();
}
});
moveToolBar = new FlowPanel();
moveToolBar.setWidth("100%");
moveToolBar.add(backButton);
moveToolBar.add(nextButton);
dockPanel = new DockPanel();
dockPanel.setSpacing(4);
dockPanel.add(deckPanel, DockPanel.CENTER);
dockPanel.add(moveToolBar, DockPanel.SOUTH);
dockPanel.setWidth("100%");
setWidget(dockPanel);
center();
}
private void initHandler() {
resizeHandlerRegistration = Window
.addResizeHandler(new ResizeHandler() {
@Override
public void onResize(ResizeEvent event) {
center();
}
});
}
protected void initWindow() {
GWT.log(title);
setModal(true);
setGlassEnabled(true);
setAnimationEnabled(true);
setText(title);
this.originalTitle = title;
}
/**
* Shows the next available card.
*/
public void nextCard() {
try {
int index = deckPanel.getVisibleWidget();
int newPos = 0;
if (index > -1) {
Widget activeItem = deckPanel.getWidget(index);
if (activeItem instanceof WizardCard)
((WizardCard) activeItem).dispose();
int cardPos = cardStack.indexOf(activeItem);
deckPanel.remove(activeItem);
newPos = cardPos + 1;
}
nextButtonAction = null;
previousButtonAction = null;
GWT.log("cardStack size:" + cardStack.size());
if (cardStack.size() > 0) {
nextButton.setEnabled(true);
backButton.setEnabled(true);
WizardCard card = cardStack.get(newPos);
deckPanel.add(card);
int indexNew = deckPanel.getWidgetIndex(card);
deckPanel.showWidget(indexNew);
card.setup();
} else {
nextButton.setEnabled(false);
backButton.setEnabled(false);
}
} catch (Throwable e) {
GWT.log("Error in nextCard():" + e.getLocalizedMessage());
e.printStackTrace();
}
}
/**
* Shows the previous available card.
*/
public void previousCard() {
try {
int index = deckPanel.getVisibleWidget();
int newPos = 0;
if (index > -1) {
Widget activeItem = deckPanel.getWidget(index);
if (activeItem instanceof WizardCard)
((WizardCard) activeItem).dispose();
deckPanel.remove(activeItem);
int cardPos = cardStack.indexOf(activeItem);
cardStack.remove(cardPos);
newPos = cardPos - 1;
}
nextButtonAction = null;
previousButtonAction = null;
nextButton.setEnabled(true);
backButton.setEnabled(true);
if (newPos == 0) {
backButton.setEnabled(false);
}
GWT.log("cardStack size:" + cardStack.size());
if (cardStack.size() > 0) {
WizardCard card = cardStack.get(newPos);
deckPanel.add(card);
int indexNew = deckPanel.getWidgetIndex(card);
deckPanel.showWidget(indexNew);
card.setup();
} else {
nextButton.setEnabled(false);
backButton.setEnabled(false);
}
} catch (Throwable e) {
GWT.log("Error in previousCard():" + e.getLocalizedMessage());
e.printStackTrace();
}
}
/**
* Returns the number of available cards.
*
* @return
*/
public int getCardStackSize() {
return cardStack.size();
}
/**
* Returns the current active card.
*
* @return
*/
public int getCurrentCard() {
int index = deckPanel.getVisibleWidget();
Widget activeItem = deckPanel.getWidget(index);
return cardStack.indexOf(activeItem);
}
public boolean checkBeforeClose() {
return true;
}
public void close(boolean check) {
checkBeforeClose = check;
hide();
}
/**
* Sets the label of next button to "Finish" value
*/
public void setNextButtonToFinish() {
nextButton.setHTML("<div><span class='"
+ GCResources.INSTANCE.wizardCSS().getWizardNextButtonText()
+ "'>" + msgs.buttonFinishLabel() + "</span>" + "<img class='"
+ GCResources.INSTANCE.wizardCSS().getWizardNextButtonIcon()
+ "'" + " src='"
+ GCResources.INSTANCE.wizardGo24().getSafeUri().asString()
+ "'/></div>");
// nextButton.setIcon(GCResources.INSTANCE.wizardGo());
// nextButton.setIconAlign(IconAlign.RIGHT);
/*
* nextButtonAction = new Command() {
*
* public void execute() { close(false); } };
*/
}
public void setNextButtonToDefault() {
nextButton.setHTML("<div><span class='"
+ GCResources.INSTANCE.wizardCSS().getWizardNextButtonText()
+ "'>" + msgs.buttonNextLabel() + "</span>" + "<img class='"
+ GCResources.INSTANCE.wizardCSS().getWizardNextButtonIcon()
+ "'" + " src='"
+ GCResources.INSTANCE.wizardNext24().getSafeUri().asString()
+ "'/></div>");
}
/**
* Set the command for the next button.
*
* @param command
* the command to execute.
*/
public void setNextButtonCommand(Command command) {
nextButtonAction = command;
}
/**
* Set the command for the previous button.
*
* @param command
* the command to execute.
*/
public void setPreviousButtonCommand(Command command) {
previousButtonAction = command;
}
/**
* {@inheritDoc}
*/
@Override
public void show() {
super.show();
int index = deckPanel.getVisibleWidget();
GWT.log("Visible widget: " + index);
if (index == -1) {
if (cardStack.size() > 0) {
WizardCard firstCard = cardStack.get(0);
deckPanel.clear();
deckPanel.add(firstCard);
int activeIndex = deckPanel.getWidgetIndex(firstCard);
deckPanel.showWidget(activeIndex);
firstCard.setup();
backButton.setEnabled(false);
center();
} else {
backButton.setEnabled(false);
nextButton.setEnabled(false);
}
} else {
deckPanel.showWidget(index);
Widget activeItem = deckPanel.getWidget(index);
if (activeItem instanceof WizardCard)
((WizardCard) activeItem).setup();
}
}
@Override
public void hide() {
if (resizeHandlerRegistration != null) {
resizeHandlerRegistration.removeHandler();
resizeHandlerRegistration = null;
}
super.hide();
}
/**
* Set the card list.
*
* @param cards
*/
public void setCards(ArrayList<WizardCard> cards) {
for (WizardCard card : cards) {
addCard(card);
}
}
/**
* Adds a card to this wizard.
*
* @param card
* the card to add.
*/
public void addCard(WizardCard card) {
card.setWizardWindow(this);
cardStack.add(card);
}
/**
* Remove a card to this wizard.
*
* @param card
* the card to add.
*/
public void removeCard(WizardCard card) {
cardStack.remove(card);
}
/**
* Enables the next button on the wizard.
*
* @param enable
* <code>true</code> to enable the next button,
* <code>false</code> otherwise.
*/
public void setEnableNextButton(boolean enable) {
nextButton.setEnabled(enable);
}
/**
* Enables the back button on the wizard.
*
* @param enable
* <code>true</code> to enable the back button,
* <code>false</code> otherwise.
*/
public void setEnableBackButton(boolean enable) {
backButton.setEnabled(enable);
}
/**
* Sets the next button label.
*
* @param text
* the button label.
*/
protected void setNextButtonText(String text) {
nextButton.setText(text);
}
/**
* Sets the back button label.
*
* @param text
* the button label.
*/
protected void setBackButtonText(String text) {
backButton.setText(text);
}
/**
* Sets visible next button.
*
* @param visible
*/
protected void setNextButtonVisible(boolean visible) {
nextButton.setVisible(visible);
}
/**
* Sets visible back button.
*
* @param visible
*/
protected void setBackButtonVisible(boolean visible) {
backButton.setVisible(visible);
}
/**
* Add a listener to the next button.
*
* @param listener
* the listener to add.
*/
protected void addNextButtonListener(ClickHandler listener) {
nextButton.addClickHandler(listener);
}
/**
* @return the originalTitle
*/
public String getOriginalTitle() {
return originalTitle;
}
/**
* Returns the card list.
*
* @return teh card list.
*/
public ArrayList<WizardCard> getCardStack() {
return cardStack;
}
public void showErrorAndHide(final String title, final String message) {
showErrorAndHide(title, message,
new Throwable());
}
public void showErrorAndHide(final String title, final String message,
final Throwable throwable) {
final WizardEvent event=new WizardEvent(WizardEventType.Failed);
event.setErrorMessage(message);
event.setException(new Exception(throwable));
GWTMessages.alert(title, message, getZIndex(), new Callback<Void, Void>() {
@Override
public void onFailure(Void reason) {
fireEvent(event);
hide();
}
@Override
public void onSuccess(Void result) {
fireEvent(event);
hide();
}
});
}
private void addToolIcon() {
// get the "dialogTopRight" class td
Element dialogTopRight = getCellElement(0, 2);
// close button image html
dialogTopRight.setInnerHTML("<div class='"
+ GCResources.INSTANCE.wizardCSS().getWizardToolButtonText()
+ "'>"
+ "<img src='"
+ GCResources.INSTANCE.toolButtonClose20().getSafeUri()
.asString() + "' class='"
+ GCResources.INSTANCE.wizardCSS().getWizardToolButtonIcon()
+ "' /></div>");
// set the event target
closeEventTarget = dialogTopRight.getChild(0).getChild(0);
}
@Override
protected void onPreviewNativeEvent(NativePreviewEvent event) {
NativeEvent nativeEvent = event.getNativeEvent();
if (!event.isCanceled() && (event.getTypeInt() == Event.ONCLICK)
&& isCloseEvent(nativeEvent)) {
final WizardEvent wizardEvent=new WizardEvent(WizardEventType.Aborted);
fireEvent(wizardEvent);
this.hide();
}
super.onPreviewNativeEvent(event);
}
// see if the click target is the close button
private boolean isCloseEvent(NativeEvent event) {
return event.getEventTarget().equals(closeEventTarget); // compares
// equality of
// the
// underlying
// DOM elements
}
@Override
public HandlerRegistration addWizardEventHandler(WizardEventHandler handler) {
return addHandler(handler, WizardEvent.getType());
}
public void setZIndex(int zIndex) {
this.zIndex=zIndex;
getGlassElement().getStyle().setZIndex(zIndex);
getElement().getStyle().setZIndex(zIndex+1);
}
public int getZIndex(){
return zIndex;
}
}

View File

@ -0,0 +1,85 @@
package org.gcube.portlets.widgets.githubconnector.client.wizard.event;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.event.shared.HasHandlers;
/**
* Wizard Event
*
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class WizardEvent extends GwtEvent<WizardEvent.WizardEventHandler> {
public static Type<WizardEventHandler> TYPE = new Type<WizardEventHandler>();
private WizardEventType wizardEventType;
private String errorMessage;
private Exception exception;
public interface WizardEventHandler extends EventHandler {
void onResponse(WizardEvent event);
}
public interface HasWizardEventHandler extends HasHandlers {
public HandlerRegistration addWizardEventHandler(
WizardEventHandler handler);
}
public WizardEvent(WizardEventType wizardEventType) {
this.wizardEventType = wizardEventType;
}
@Override
protected void dispatch(WizardEventHandler handler) {
handler.onResponse(this);
}
@Override
public Type<WizardEventHandler> getAssociatedType() {
return TYPE;
}
public static Type<WizardEventHandler> getType() {
return TYPE;
}
public static void fire(HasHandlers source, WizardEvent deleteItemEvent) {
source.fireEvent(deleteItemEvent);
}
public WizardEventType getWizardEventType() {
return wizardEventType;
}
public void setWizardEventType(WizardEventType wizardEventType) {
this.wizardEventType = wizardEventType;
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public Exception getException() {
return exception;
}
public void setException(Exception exception) {
this.exception = exception;
}
@Override
public String toString() {
return "WizardEvent [wizardEventType=" + wizardEventType
+ ", errorMessage=" + errorMessage + ", exception=" + exception
+ "]";
}
}

View File

@ -0,0 +1,60 @@
package org.gcube.portlets.widgets.githubconnector.client.wizard.event;
import java.util.Arrays;
import java.util.List;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public enum WizardEventType {
Completed("Completed"), Failed("Failed"), Aborted("Aborted"), Background(
"Background");
/**
* @param text
*/
private WizardEventType(final String id) {
this.id = id;
}
private final String id;
@Override
public String toString() {
return id;
}
public String getLabel() {
return id;
}
public String getId() {
return id;
}
/**
*
* @param id
* @return
*/
public static WizardEventType getTypeFromId(String id) {
if (id == null || id.isEmpty())
return null;
for (WizardEventType type : values()) {
if (type.id.compareToIgnoreCase(id) == 0) {
return type;
}
}
return null;
}
public static List<WizardEventType> asList() {
List<WizardEventType> list = Arrays.asList(values());
return list;
}
}

View File

@ -0,0 +1,42 @@
<?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.resources.Resources" />
<inherits name='com.google.gwt.user.theme.clean.Clean' />
<!-- Debug CSS style -->
<set-configuration-property name="CssResource.style"
value="pretty" />
<inherits name='org.gcube.portlets.widgets.sessionchecker.SessionChecker' />
<!--
<entry-point
class='org.gcube.portlets.widgets.githubconnector.client.GitHubConnectorManager' />
-->
<!--
<set-property name="gwt.logging.enabled" value="TRUE" />
<set-property name="gwt.logging.logLevel" value="SEVERE" />
<set-property name="gwt.logging.consoleHandler" value="ENABLED" />
<set-property name="gwt.logging.simpleRemoteHandler" value="ENABLED" />
-->
<!--
<set-property name="log_ConsoleLogger" value="ENABLED" />
<set-property name="log_DivLogger" value="ENABLED" />
<set-property name="log_GWTLogger" value="ENABLED" />
<set-property name="log_SystemLogger" value="ENABLED" /> -->
<!--
<set-property name="log_ConsoleLogger" value="DISABLED" />
<set-property name="log_DivLogger" value="DISABLED" />
<set-property name="log_GWTLogger" value="DISABLED" />
<set-property name="log_SystemLogger" value="DISABLED" /> -->
<source path='client' />
<source path='shared' />
</module>

View File

@ -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);
}
}

View File

@ -0,0 +1,116 @@
package org.gcube.portlets.widgets.githubconnector.server;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.portlets.widgets.githubconnector.client.rpc.GitHubConnectorService;
import org.gcube.portlets.widgets.githubconnector.server.git.GitConnectorService;
import org.gcube.portlets.widgets.githubconnector.shared.exception.ServiceException;
import org.gcube.portlets.widgets.githubconnector.shared.git.GitHubCloneSession;
import org.gcube.portlets.widgets.githubconnector.shared.git.data.GitHubRepository;
import org.gcube.portlets.widgets.githubconnector.shared.git.data.credential.GitHubCredential;
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;
/**
*
* @author Giancarlo Panichi
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
@SuppressWarnings("serial")
public class GitHubConnectorServiceImpl extends RemoteServiceServlet implements
GitHubConnectorService {
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);
SessionUtil.getToken(aslSession);
logger.debug("hello()");
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 ArrayList<GitHubRepository> getRepositories(String repositoryOwner,
GitHubCredential gitHubCredential) throws ServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
SessionUtil.getToken(aslSession);
logger.debug("getRepository(): " + gitHubCredential);
GitConnectorService gitConnectorService = new GitConnectorService(
aslSession.getUsername(), gitHubCredential);
return gitConnectorService.getRepositories(repositoryOwner);
} 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 void cloneRepository(GitHubCloneSession gitHubCloneSession)
throws ServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
SessionUtil.getToken(aslSession);
logger.debug("cloneRepository(): " + gitHubCloneSession);
GitConnectorService gitConnectorService = new GitConnectorService(
aslSession.getUsername(),
gitHubCloneSession.getGitHubCredential());
gitConnectorService.cloneRepository(gitHubCloneSession.getDestinationFolderId(),
gitHubCloneSession.getRepositoryOwner(), gitHubCloneSession.getRepositoryName());
return;
} catch (ServiceException e) {
e.printStackTrace();
throw e;
} catch (Throwable e) {
e.printStackTrace();
logger.error("Hello(): " + e.getLocalizedMessage(), e);
throw new ServiceException(e.getLocalizedMessage(), e);
}
}
}

View File

@ -0,0 +1,73 @@
/**
*
*/
package org.gcube.portlets.widgets.githubconnector.server;
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)
throws ServiceException {
String token = null;
if (Constants.DEBUG_MODE) {
token = Constants.DEFAULT_TOKEN;
} else {
token = aslSession.getSecurityToken();
}
logger.info("received token: " + token);
return token;
}
}

View File

@ -0,0 +1,214 @@
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.data.GitHubRepository;
import org.gcube.portlets.widgets.githubconnector.shared.git.data.credential.GitHubCredential;
import org.gcube.portlets.widgets.githubconnector.shared.git.data.credential.GitHubCredentialLogin;
import org.gcube.portlets.widgets.githubconnector.shared.git.data.credential.GitHubCredentialOAuth2;
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;
/**
*
* @param userName
* @param gitHubCredential
*/
public GitConnectorService(String userName, GitHubCredential gitHubCredential) {
this.userName = userName;
if(gitHubCredential!=null&& gitHubCredential.getType()!=null){
if(gitHubCredential instanceof GitHubCredentialLogin){
GitHubCredentialLogin gitHubCredentialLogin=(GitHubCredentialLogin) gitHubCredential;
gitHubClient = new GitHubClient();
gitHubClient.setCredentials(gitHubCredentialLogin.getUser()
,gitHubCredentialLogin.getPassword());
} else {
if(gitHubCredential instanceof GitHubCredentialOAuth2){
GitHubCredentialOAuth2 gitHubCredentialOAuth2=(GitHubCredentialOAuth2) gitHubCredential;
gitHubClient = new GitHubClient();
gitHubClient.setOAuth2Token(gitHubCredentialOAuth2.getToken());
} else {
}
}
}
}
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() + "]");
String internalFolderId=StorageUtil.createFolderOnWorkspace(userName, destinationFolderId,
contents.getName(), contents.getName());
createContent(internalFolderId, 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);
}
}
}

View File

@ -0,0 +1,88 @@
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.data.GitHubRepository;
import org.gcube.portlets.widgets.githubconnector.shared.git.data.GitHubUser;
/**
*
* @author Giancarlo Panichi
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class GitHubRepositoryBuilder {
private static Logger logger = Logger
.getLogger(GitHubRepositoryBuilder.class);
/**
*
* @param repository
* @return
* @throws ServiceException
*/
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);
}
}
/**
*
* @param repositories
* @return
* @throws ServiceException
*/
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!");
}
}
}

View File

@ -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);
}
}
}

View File

@ -0,0 +1,29 @@
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 = false;
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 final static String DEFAULT_SCOPE = "/gcube/devNext/NextNext";
public final static String DEFAULT_TOKEN = "6af6eaff-35bd-4405-b747-f63246d0212a-98187548";
public static final String DEFAULT_ROLE = "OrganizationMember";
public static final String DEFAULT_FOLDER_ID = "";
public static final String DEFAULT_REPOSITORY_OWNER = "jonan";
public static final String DEFAULT_REPOSITORY_NAME = "jonan.github.io";
}

View File

@ -0,0 +1,39 @@
package org.gcube.portlets.widgets.githubconnector.shared.exception;
/**
* ASL Session Expired Exception
*
*
* @author Giancarlo Panichi
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
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);
}
}

View File

@ -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);
}
}

View File

@ -0,0 +1,92 @@
package org.gcube.portlets.widgets.githubconnector.shared.git;
import java.io.Serializable;
import org.gcube.portlets.widgets.githubconnector.shared.git.data.credential.GitHubCredential;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class GitHubCloneSession implements Serializable {
private static final long serialVersionUID = 4995026750312087485L;
private String destinationFolderId;
private GitHubCredential gitHubCredential;
private String repositoryOwner;
private String repositoryName;
public GitHubCloneSession() {
super();
}
/**
*
* @param destinationFolderId
*/
public GitHubCloneSession(String destinationFolderId) {
super();
this.destinationFolderId = destinationFolderId;
}
/**
*
* @param destinationFolderId
* @param gitHubCredential
* @param repositoryOwner
* @param repositoryName
*/
public GitHubCloneSession(String destinationFolderId,
GitHubCredential gitHubCredential, String repositoryOwner,
String repositoryName) {
super();
this.destinationFolderId = destinationFolderId;
this.gitHubCredential = gitHubCredential;
this.repositoryOwner = repositoryOwner;
this.repositoryName = repositoryName;
}
public GitHubCredential getGitHubCredential() {
return gitHubCredential;
}
public void setGitHubCredential(GitHubCredential gitHubCredential) {
this.gitHubCredential = gitHubCredential;
}
public String getDestinationFolderId() {
return destinationFolderId;
}
public void setDestinationFolderId(String destinationFolderId) {
this.destinationFolderId = destinationFolderId;
}
public String getRepositoryOwner() {
return repositoryOwner;
}
public void setRepositoryOwner(String repositoryOwner) {
this.repositoryOwner = repositoryOwner;
}
public String getRepositoryName() {
return repositoryName;
}
public void setRepositoryName(String repositoryName) {
this.repositoryName = repositoryName;
}
@Override
public String toString() {
return "GitHubCloneSession [destinationFolderId=" + destinationFolderId
+ ", gitHubCredential=" + gitHubCredential
+ ", repositoryOwner=" + repositoryOwner + ", repositoryName="
+ repositoryName + "]";
}
}

View File

@ -0,0 +1,113 @@
package org.gcube.portlets.widgets.githubconnector.shared.git.data;
import java.io.Serializable;
import java.util.Date;
/**
*
* @author Giancarlo Panichi
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
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 + "]";
}
}

View File

@ -0,0 +1,103 @@
package org.gcube.portlets.widgets.githubconnector.shared.git.data;
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 + "]";
}
}

View File

@ -0,0 +1,34 @@
package org.gcube.portlets.widgets.githubconnector.shared.git.data.credential;
import java.io.Serializable;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class GitHubCredential implements Serializable {
private static final long serialVersionUID = 6198756446799134610L;
private GitHubCredentialType type;
public GitHubCredential() {
super();
}
public GitHubCredential(GitHubCredentialType type) {
super();
this.type = type;
}
public GitHubCredentialType getType() {
return type;
}
@Override
public String toString() {
return "GitHubCredential [type=" + type + "]";
}
}

View File

@ -0,0 +1,22 @@
package org.gcube.portlets.widgets.githubconnector.shared.git.data.credential;
/**
*
* @author Giancarlo Panichi
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class GitHubCredentialAnonymous extends GitHubCredential {
private static final long serialVersionUID = 6967297424938062981L;
public GitHubCredentialAnonymous() {
super(GitHubCredentialType.Anonymous);
}
@Override
public String toString() {
return "GitHubCredentialAnonymous []";
}
}

View File

@ -0,0 +1,47 @@
package org.gcube.portlets.widgets.githubconnector.shared.git.data.credential;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class GitHubCredentialLogin extends GitHubCredential {
private static final long serialVersionUID = 6967297424938062981L;
private String user;
private String password;
public GitHubCredentialLogin() {
super(GitHubCredentialType.Login);
}
public GitHubCredentialLogin(String user, String password) {
super(GitHubCredentialType.Login);
this.user = user;
this.password = password;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "GitHubCredentialLogin [user=" + user + ", password=" + password
+ "]";
}
}

View File

@ -0,0 +1,36 @@
package org.gcube.portlets.widgets.githubconnector.shared.git.data.credential;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class GitHubCredentialOAuth2 extends GitHubCredential {
private static final long serialVersionUID = 6967297424938062981L;
private String token;
public GitHubCredentialOAuth2() {
super(GitHubCredentialType.OAuth2);
}
public GitHubCredentialOAuth2(String token) {
super(GitHubCredentialType.OAuth2);
this.token = token;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
@Override
public String toString() {
return "GitHubCredentialOAuth2 [token=" + token + "]";
}
}

View File

@ -0,0 +1,43 @@
package org.gcube.portlets.widgets.githubconnector.shared.git.data.credential;
/**
*
* @author Giancarlo Panichi
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public enum GitHubCredentialType {
Anonymous("Anonymous"),
OAuth2("OAuth2"),
Login("Login");
/**
* @param text
*/
private GitHubCredentialType(final String id) {
this.id = id;
}
private final String id;
@Override
public String toString() {
return id;
}
public String getLabel() {
return id;
}
public static GitHubCredentialType getFromId(String id) {
for (GitHubCredentialType type : values()) {
if (type.id.compareToIgnoreCase(id) == 0) {
return type;
}
}
return null;
}
}

View File

@ -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 + "]";
}
}

View File

@ -0,0 +1,94 @@
@CHARSET "UTF-8";
.wizard-card-title {
padding: 5px;
font-weight: bold;
font-size: small;
background-color: #f1f1f1;
}
.wizard-card-footer {
padding: 5px;
font-weight: bold;
font-size: x-small;
text-align: left;
background-color: #f1f1f1;
}
.wizard-previous-button-text {
line-height: 24px;
vertical-align: middle;
}
.wizard-previous-button-icon {
vertical-align: middle;
float: left;
}
.wizard-next-button-text {
line-height: 24px;
vertical-align: middle;
}
.wizard-next-button-icon {
vertical-align: middle;
float: right;
}
.wizard-tool-button-text {
margin-left: -20px;
margin-top: 2px;
}
.wizard-tool-button-text:hover {
margin-left: -20px;
margin-top: 0px;
}
.wizard-tool-button-icon {
height: 20px;
}
.wizard-tool-button-icon:hover {
height: 20px;
border: 1px solid #222;
}
.card-panel {
border: 1px solid #ccc;
background-color: white;
margin-top: 4px;
margin-bottom: 4px;
}
.card-panel-content {
margin: 6px;
}
/* Progress */
.progress-bar-container {
width: 100%;
height: 25px;
position: relative;
background-color: #f1f1f1;
}
.progress-bar {
color: #fff;
background-color: #a5a5a5;
height: 100%;
position: absolute;
line-height: inherit;
}
.progress-bar-text {
text-align: center;
color: #2d2d2d;
position: absolute;
width: 100%;
margin-top: 5px;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 569 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 957 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -0,0 +1,43 @@
<?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.resources.Resources" />
<inherits name='com.google.gwt.user.theme.clean.Clean' />
<!-- Debug CSS style -->
<set-configuration-property name="CssResource.style"
value="pretty" />
<inherits name='org.gcube.portlets.widgets.sessionchecker.SessionChecker' />
<!--
<entry-point
class='org.gcube.portlets.widgets.githubconnector.client.GitHubConnectorManager' />
-->
<!--
<set-property name="gwt.logging.enabled" value="TRUE" />
<set-property name="gwt.logging.logLevel" value="SEVERE" />
<set-property name="gwt.logging.consoleHandler" value="ENABLED" />
<set-property name="gwt.logging.simpleRemoteHandler" value="ENABLED" />
-->
<!--
<set-property name="log_ConsoleLogger" value="ENABLED" />
<set-property name="log_DivLogger" value="ENABLED" />
<set-property name="log_GWTLogger" value="ENABLED" />
<set-property name="log_SystemLogger" value="ENABLED" /> -->
<!--
<set-property name="log_ConsoleLogger" value="DISABLED" />
<set-property name="log_DivLogger" value="DISABLED" />
<set-property name="log_GWTLogger" value="DISABLED" />
<set-property name="log_SystemLogger" value="DISABLED" /> -->
<source path='client' />
<source path='shared' />
</module>

View File

View File

@ -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">
<title>Data Miner Manager</title>
<script type="text/javascript" src="githubman/js/jquery-1.11.0.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>

View File

@ -0,0 +1,18 @@
<%@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">
<script
src='<%=request.getContextPath()%>/githubman/js/jquery-1.11.0.min.js'></script>
<script
src='<%=request.getContextPath()%>/githubman/githubman.nocache.js'></script>
<div class="contentDiv" id="contentDiv"></div>

View File

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

View File

@ -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=

View File

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 6.2.0//EN"
"http://www.liferay.com/dtd/liferay-portlet-app_6_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>

View File

@ -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>

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,137 @@
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.gcube.portlets.widgets.githubconnector.shared.git.data.credential.GitHubCredentialAnonymous;
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, new GitHubCredentialAnonymous());
try {
gitConnectorService
.cloneRepository(Constants.DEFAULT_FOLDER_ID, Constants.DEFAULT_REPOSITORY_OWNER,
Constants.DEFAULT_REPOSITORY_NAME);
} 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());
}
}
}