Commit 46da3175 authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '7-settings-scope' into 'master'

Resolve "Settings: Scope"

Closes #7

See merge request !4
parents d46ad112 af93ec20
......@@ -148,7 +148,7 @@
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>genesys-client-api</artifactId>
<version>1.1-SNAPSHOT</version>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
......
Genesys Anno User Manual
========================
December 2015: Commit {buildNumber}
October 2017: Commit {buildNumber}
:revnumber: {projectVersion}
:doctype: book
:toc: left
......@@ -16,15 +16,15 @@ December 2015: Commit {buildNumber}
Introduction
------------
*Anno* is a standalone Java application for managing accession-level data on
Genesys PGR - global database on PGR in world's genebanks. Genesys database is
accessible at https://www.genesys-pgr.org .
*Anno* is a standalone Java application for managing accession-level data on
Genesys PGR - global database on PGR in world's genebanks. Genesys database is
accessible at https://www.genesys-pgr.org .
The application allows users to map their Excel, CSV or database SQL queries to Multi-Crop
The application allows users to map their Excel, CSV or database SQL queries to Multi-Crop
Passport Descriptor format (MCPD) and push the mapped data to Genesys for publication.
*Genesys Sandbox*, a playground instance of the Genesys
database, is available for developers and integrators to validate and test their
database, is available for developers and integrators to validate and test their
configuration at https://sandbox.genesys-pgr.org
before pushing data to *live* Genesys servers.
......@@ -39,4 +39,3 @@ include::sections/mapping.adoc[]
include::sections/push.adoc[]
include::sections/troubleshooting.adoc[]
include::sections/ack.adoc[]
......@@ -2,7 +2,7 @@
[[download]]
== Installing Anno
Anno is an open-source project, licensed under Apache License v2.
Anno is an open-source project, licensed under Apache License v2.
Anno requires the Java 8 Run-Time Environment (JRE) to run.
NOTE: Make sure you don't allow installation of browser toolbars like Ask.com in the Java JRE installer.
......@@ -18,12 +18,11 @@ You probably have 64-bit CPU and JRE and should use the package labeled `x86_64`
Download the package from the https://bitbucket.org/genesys2/anno-swt/downloads[downloads section]
extract if necessary and run the executable for your platform.
[cols="1,4"]
[cols="1,4"]
.Resources
|===
|Project page|https://bitbucket.org/genesys2/anno-swt
|Project page|https://gitlab.croptrust.org/genesys-pgr/anno
|Pre-compiled binaries|https://bitbucket.org/genesys2/anno-swt/downloads
|`git` repository URL|https://bitbucket.org/genesys2/anno-swt.git
|Issue tracker|https://bitbucket.org/genesys2/anno-swt/issues
|`git` repository URL|https://gitlab.croptrust.org/genesys-pgr/anno.git
|Issue tracker|https://gitlab.croptrust.org/genesys-pgr/anno/issues
|===
......@@ -8,10 +8,10 @@ which Genesys server will receive your data.
.Settings Dialog
image::settings-dialog.png[role="text-center"]
The settings are stored in the Project file and will be saved and loaded with the
The settings are stored in the Project file and will be saved and loaded with the
rest of the project configuration.
[cols="1,4", options="header"]
[cols="1,4", options="header"]
.Settings Dialog
|===
|Label|Description
......@@ -24,8 +24,11 @@ rest of the project configuration.
changed. Don't touch.
|Client API key and secret|Contact the helpdesk at helpdesk@genesys-pgr.org to obtain the valid
client key and secret. Different values are used for sandbox and production environments.
|Access and Refresh tokens|Authentication tokens used to identify you with Genesys server.
These are obtained by clicking "Authenticate" or loaded from the Project file.
|Access and Refresh tokens|Authentication tokens used to identify you with Genesys server.
These are obtained by clicking "Authenticate" or loaded from the Project file.
|Scope|Scopes granted to Anno to manage data on your behalf on Genesys.
The scope must be: `write`
|Clear tokens|Clears access and refresh token values. You will have to re-authenticate with the
server.
|Authenticate|Validates the current configuration against the server or asks you to authenticate
......@@ -35,21 +38,21 @@ rest of the project configuration.
=== Authenticating with Genesys
A valid user account on Genesys is required. You may use your Google+ account or create the account
manually by providing a valid email address and an account password.
manually by providing a valid email address and an account password.
Make sure you have valid user accounts for the sandbox environment at https://sandbox.genesys-pgr.org/login
and the production servers at https://www.genesys-pgr.org/login
NOTE: You can use Google+ to create your user account on Genesys. You will not need to remember a separate password!
After you have obtained valid Client key and secret from helpdesk@genesys-pgr.org and created your
After you have obtained valid Client key and secret from helpdesk@genesys-pgr.org and created your
Genesys accounts, you can authenticate against the selected server (sandbox or production).
Click the "Authenticate" button. When the access and refresh tokens are missing or have expired,
Click the "Authenticate" button. When the access and refresh tokens are missing or have expired,
the application will prompt you to authorize the
application's request to access Genesys on your behalf.
application's request to access Genesys on your behalf.
If tokens are still valid, their values in the
If tokens are still valid, their values in the
dialog will be updated with the message: "Tokens are up to date."
.Authentication Dialog
......@@ -57,20 +60,16 @@ image::authentication-dialog.png[role="text-center"]
"Open link in browser" opens your default web browser application (Chrome, IE, Firefox, ...) and
Genesys prompts you to allow access to your resources. If you are not yet logged in
Genesys prompts you to allow access to your resources. If you are not yet logged in
to Genesys, you will be prompted to log in before the confirmation dialog is displayed.
.Allow access
image::confirm-access.png[role="text-center"]
Select "Yes, allow access" and Genesys will generate a short-lived *verifier code* that you must copy and paste
Select "Yes, allow access" and Genesys will generate a short-lived *verifier code* that you must copy and paste
to the *Verifier code* field in the Anno dialog. The verifier code is a 6-character string (e.g. `td1S83`).
Unless an error occurs or the verifier code times out, your access and refresh tokens will be updated.
After obtaining the tokens, *save the project* by clicking the "Save" button in the application Toolbar. Give
the project file a name that tells you which Genesys server (production or sandbox) you have selected.
......@@ -699,9 +699,9 @@ public class AppWindow {
try {
builder.saveWorkspace(path, settings);
} catch (JSONException e) {
_log.error(e.getMessage());
_log.error(e.getMessage(), e);
} catch (IOException e) {
_log.error(e.getMessage());
_log.error(e.getMessage(), e);
}
}
}
......
......@@ -24,6 +24,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.genesys2.anno.model.Column;
import org.genesys2.anno.model.ColumnDataType;
import org.genesys2.anno.model.DatabaseSettings;
......@@ -85,6 +86,7 @@ public class DwcaBuilder extends AbstractModelObject {
oauthSettings.put("authorizationEndpoint", sourceSettings.getOauthSettings().getAuthorizationEndpoint());
oauthSettings.put("clientKey", sourceSettings.getOauthSettings().getClientKey());
oauthSettings.put("clientSecret", sourceSettings.getOauthSettings().getClientSecret());
oauthSettings.put("scope", sourceSettings.getOauthSettings().getScope());
oauthSettings.put("refreshToken", sourceSettings.getOauthSettings().getRefreshToken());
oauthSettings.put("serverUrl", sourceSettings.getOauthSettings().getServerUrl());
oauthSettings.put("tokenEndpoint", sourceSettings.getOauthSettings().getTokenEndpoint());
......@@ -301,6 +303,7 @@ public class DwcaBuilder extends AbstractModelObject {
oAuthSettings.setAuthorizationEndpoint(jsonSettings.getString("authorizationEndpoint"));
oAuthSettings.setClientKey(jsonSettings.getString("clientKey"));
oAuthSettings.setClientSecret(jsonSettings.getString("clientSecret"));
oAuthSettings.setScope(StringUtils.defaultIfBlank(jsonSettings.getString("scope"), "read,write"));
oAuthSettings.setRefreshToken(jsonSettings.getString("refreshToken"));
oAuthSettings.setServerUrl(jsonSettings.getString("serverUrl"));
oAuthSettings.setTokenEndpoint(jsonSettings.getString("tokenEndpoint"));
......
......@@ -17,12 +17,15 @@ package org.genesys2.anno.gui;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeanProperties;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
......@@ -45,14 +48,12 @@ import org.genesys2.client.oauth.GenesysClient;
import org.genesys2.client.oauth.HttpRedirectException;
import org.genesys2.client.oauth.OAuthAuthenticationException;
import org.genesys2.client.oauth.PleaseRetryException;
import org.scribe.exceptions.OAuthConnectionException;
import org.springframework.beans.factory.annotation.Autowired;
import swing2swt.layout.BorderLayout;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
public class SettingsDialog extends Dialog {
private Binding scope;
private static final Logger _log = Logger.getLogger(SettingsDialog.class);
private DataBindingContext m_bindingContext;
......@@ -69,6 +70,7 @@ public class SettingsDialog extends Dialog {
private Text txtRefreshToken;
private Text txtClientKey;
private Text txtClientSecret;
private Text txtScope;
/**
* Create the dialog.
......@@ -195,6 +197,14 @@ public class SettingsDialog extends Dialog {
}
});
txtClientSecret.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label tblScope = new Label(grpGenesysApiConfiguration, SWT.NONE);
tblScope.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
tblScope.setText("Scope");
tblScope.setAlignment(SWT.RIGHT);
txtScope = new Text(grpGenesysApiConfiguration, SWT.BORDER);
txtScope.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Group grpOauthTokens = new Group(composite, SWT.NONE);
grpOauthTokens.setLayout(new GridLayout(2, false));
......@@ -270,9 +280,6 @@ public class SettingsDialog extends Dialog {
SwtUtil.showMessageBox(getParent(), "OAuth", "Tokens are up to date.");
} catch (OAuthConnectionException e) {
_log.error(e.getMessage(), e);
SwtUtil.showMessageBox(getParent(), "Problem connecting to server", "Could not access remote service at:\n" + oauthSettings.getServerUrl() + "\n\n" + e.getMessage());
} catch (OAuthAuthenticationException e) {
_log.warn(e.getMessage());
String authorizationUrl = genesysClient.getAuthorizationUrl();
......@@ -300,7 +307,6 @@ public class SettingsDialog extends Dialog {
_log.error("Please retry", e);
}
}
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
......@@ -336,6 +342,10 @@ public class SettingsDialog extends Dialog {
IObservableValue oauthSettingsclientSecretSettingsObserveValue = BeanProperties.value("oauthSettings.clientSecret").observe(settings);
bindingContext.bindValue(observeTextTxtClientSecretObserveWidget, oauthSettingsclientSecretSettingsObserveValue, null, null);
//
IObservableValue observeTextTxtScopeObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtScope);
IObservableValue scopeSettingsgetOauthSettingsObserveValue = BeanProperties.value("scope").observe(settings.getOauthSettings());
scope = bindingContext.bindValue(observeTextTxtScopeObserveWidget, scopeSettingsgetOauthSettingsObserveValue, null, null);
//
return bindingContext;
}
}
......@@ -182,14 +182,11 @@ public class SpringConfig {
// Not a bean
public static GenesysClient createGenesysClient(OAuthSettings oauthSettings) {
GenesysClient genesysClient = new GenesysClient();
genesysClient.setGenesysApi(new GenesysApi());
genesysClient.setBaseUrl(oauthSettings.getServerUrl());
GenesysClient genesysClient = new GenesysClient(oauthSettings.getServerUrl(), oauthSettings.getClientKey(), oauthSettings.getClientSecret(), "oob", oauthSettings.getScope());
GenesysTokens genesysTokens = new GenesysTokens();
genesysTokens.setAccessToken(oauthSettings.getAccessToken());
genesysTokens.setRefreshToken(oauthSettings.getRefreshToken());
genesysClient.setTokens(genesysTokens);
genesysClient.connect(oauthSettings.getClientKey(), oauthSettings.getClientSecret(), "oob");
return genesysClient;
}
}
......@@ -26,6 +26,7 @@ public class OAuthSettings extends AbstractModelObject {
private String refreshToken = "";
private String clientKey = "";
private String clientSecret = "";
private String scope = "write";
public String getServerUrl() {
return serverUrl;
......@@ -107,4 +108,12 @@ public class OAuthSettings extends AbstractModelObject {
firePropertyChange("clientSecret", null, this.clientSecret);
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
firePropertyChange("scope", null, this.scope);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment