Commit 104e55aa authored by Alex Igoshin's avatar Alex Igoshin
Browse files

Merged genesys2/anno-swt into master

parents b287ebca 791a8a2b
...@@ -73,4 +73,5 @@ ...@@ -73,4 +73,5 @@
<version>4.3</version> <version>4.3</version>
</dependency> </dependency>
</dependencies> </dependencies>
<name>Anno for Windows, Linux</name>
</project> </project>
\ No newline at end of file
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
</parent> </parent>
<artifactId>anno-gui</artifactId> <artifactId>anno-gui</artifactId>
<name>Data annotator</name> <name>Data annotator GUI</name>
<repositories> <repositories>
<repository> <repository>
......
...@@ -42,6 +42,12 @@ public class RowConverter { ...@@ -42,6 +42,12 @@ public class RowConverter {
List<Column> columns = dataSourceSheet.getColumns(); List<Column> columns = dataSourceSheet.getColumns();
for (int i = 0; i < columns.size(); i++) { for (int i = 0; i < columns.size(); i++) {
if (i >= row.length) {
_log.warn("Row has less than " + (i + 1) + " columns: " + ArrayUtils.toString(row));
continue;
}
Column column = columns.get(i); Column column = columns.get(i);
ColumnDef columnDef = findColumnDef(column, columnDefs.getColumnDefs()); ColumnDef columnDef = findColumnDef(column, columnDefs.getColumnDefs());
if (columnDef == null) { if (columnDef == null) {
...@@ -181,6 +187,8 @@ public class RowConverter { ...@@ -181,6 +187,8 @@ public class RowConverter {
ObjectNode rowNode = mapper.createObjectNode(); ObjectNode rowNode = mapper.createObjectNode();
for (GenesysJSON.JsonField jsonField : genesysJson.getJsonFields()) { for (GenesysJSON.JsonField jsonField : genesysJson.getJsonFields()) {
if (!row.containsKey(jsonField.getRdfTerm()))
continue;
Object rdfValues = row.get(jsonField.getRdfTerm()); Object rdfValues = row.get(jsonField.getRdfTerm());
add(rowNode, jsonField, rdfValues); add(rowNode, jsonField, rdfValues);
} }
......
...@@ -12,6 +12,7 @@ import java.util.concurrent.ThreadPoolExecutor; ...@@ -12,6 +12,7 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.apache.log4j.Level;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeEvent;
...@@ -44,7 +45,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; ...@@ -44,7 +45,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
public class PushDialog extends Dialog { public class PushDialog extends Dialog {
private static final Logger _log = Logger.getLogger(PushDialog.class); private static final Logger _log = Logger.getLogger(PushDialog.class);
protected static final int BATCH_SIZE = 25; protected static final int BATCH_SIZE = 50;
@Autowired @Autowired
private Settings settings; private Settings settings;
...@@ -52,7 +53,7 @@ public class PushDialog extends Dialog { ...@@ -52,7 +53,7 @@ public class PushDialog extends Dialog {
@Autowired @Autowired
protected DataSourceLoader dataSourceLoader; protected DataSourceLoader dataSourceLoader;
BlockingQueue<Runnable> linkedBlockingDeque = new LinkedBlockingDeque<Runnable>(100); BlockingQueue<Runnable> linkedBlockingDeque = new LinkedBlockingDeque<Runnable>(4);
private ThreadPoolExecutor executorService = new ThreadPoolExecutor(1, 2, 30, TimeUnit.SECONDS, linkedBlockingDeque, new ThreadPoolExecutor.CallerRunsPolicy()); private ThreadPoolExecutor executorService = new ThreadPoolExecutor(1, 2, 30, TimeUnit.SECONDS, linkedBlockingDeque, new ThreadPoolExecutor.CallerRunsPolicy());
protected Object result; protected Object result;
...@@ -121,7 +122,7 @@ public class PushDialog extends Dialog { ...@@ -121,7 +122,7 @@ public class PushDialog extends Dialog {
executorService.shutdown(); executorService.shutdown();
executorService.shutdownNow(); executorService.shutdownNow();
event.doit = executorService.getActiveCount() == 0; event.doit = executorService.getActiveCount() == 0;
_log.warn("Jobs are still running, refusing to close."); _log.warn((executorService.getActiveCount()) + " jobs are still running, refusing to close.");
} }
}); });
shell.setSize(691, 383); shell.setSize(691, 383);
...@@ -150,6 +151,34 @@ public class PushDialog extends Dialog { ...@@ -150,6 +151,34 @@ public class PushDialog extends Dialog {
tltmPushToGenesys.setText("Upload"); tltmPushToGenesys.setText("Upload");
tltmPushToGenesys.setImage(AppWindow.pushDataIcon); tltmPushToGenesys.setImage(AppWindow.pushDataIcon);
ToolItem tltmRadioItemDebug = new ToolItem(toolBar, SWT.RADIO);
tltmRadioItemDebug.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
logAppender.setThreshold(Level.DEBUG);
}
});
tltmRadioItemDebug.setSelection(true);
tltmRadioItemDebug.setText("DEBUG");
ToolItem tltmRadioItemInfo = new ToolItem(toolBar, SWT.RADIO);
tltmRadioItemInfo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
logAppender.setThreshold(Level.INFO);
}
});
tltmRadioItemInfo.setText("INFO");
ToolItem tltmRadioItemWarning = new ToolItem(toolBar, SWT.RADIO);
tltmRadioItemWarning.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
logAppender.setThreshold(Level.WARN);
}
});
tltmRadioItemWarning.setText("WARNING");
txtJson = new Text(shell, SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI); txtJson = new Text(shell, SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI);
txtJson.setLayoutData(BorderLayout.CENTER); txtJson.setLayoutData(BorderLayout.CENTER);
...@@ -238,7 +267,7 @@ public class PushDialog extends Dialog { ...@@ -238,7 +267,7 @@ public class PushDialog extends Dialog {
try { try {
do { do {
List<Object[]> rows = rowReader.readRows(10); List<Object[]> rows = rowReader.readRows(100);
if (rows.size() == 0) { if (rows.size() == 0) {
_log.info("Exhausted data source."); _log.info("Exhausted data source.");
...@@ -294,7 +323,10 @@ public class PushDialog extends Dialog { ...@@ -294,7 +323,10 @@ public class PushDialog extends Dialog {
_log.error(e.getMessage(), e); _log.error(e.getMessage(), e);
} catch (InterruptedException e) { } catch (InterruptedException e) {
_log.info("Execution was interrupted"); _log.info("Execution was interrupted");
} catch (Throwable e) {
_log.error(e.getMessage(), e);
} finally { } finally {
_log.info("Reader finished.");
try { try {
rowReader.close(); rowReader.close();
} catch (IOException e) { } catch (IOException e) {
...@@ -346,6 +378,12 @@ public class PushDialog extends Dialog { ...@@ -346,6 +378,12 @@ public class PushDialog extends Dialog {
public void run() { public void run() {
try { try {
_log.info("Pushing data for instCode=" + instCode + " size=" + accns.size()); _log.info("Pushing data for instCode=" + instCode + " size=" + accns.size());
if (_log.isDebugEnabled()) {
for (ObjectNode o : accns) {
_log.debug(o);
}
}
genesysClient.updateAccessions(instCode, accns); genesysClient.updateAccessions(instCode, accns);
} catch (OAuthAuthenticationException e) { } catch (OAuthAuthenticationException e) {
_log.error(e.getMessage(), e); _log.error(e.getMessage(), e);
......
...@@ -229,13 +229,18 @@ public class SettingsDialog extends Dialog { ...@@ -229,13 +229,18 @@ public class SettingsDialog extends Dialog {
try { try {
genesysClient.me(); genesysClient.me();
oauthSettings.setAccessToken(genesysClient.getAccessToken().getToken());
SwtUtil.showMessageBox(getParent(), "OAuth", "Tokens are up to date.");
} catch (OAuthConnectionException e) { } catch (OAuthConnectionException e) {
_log.error(e.getMessage(), 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) { } catch (OAuthAuthenticationException e) {
_log.warn(e.getMessage()); _log.warn(e.getMessage());
String authorizationUrl = genesysClient.getAuthorizationUrl(null); String authorizationUrl = genesysClient.getAuthorizationUrl(null);
VerifierDialog vd = new VerifierDialog(getParent(), SWT.NONE); VerifierDialog vd = new VerifierDialog(getParent(), SWT.NONE);
String verifierCode = vd.open(authorizationUrl); String verifierCode = vd.open(authorizationUrl).trim();
_log.info("Got verifier code: " + verifierCode); _log.info("Got verifier code: " + verifierCode);
if (StringUtils.isNotBlank(verifierCode)) { if (StringUtils.isNotBlank(verifierCode)) {
genesysClient.authenticate(verifierCode); genesysClient.authenticate(verifierCode);
......
...@@ -22,7 +22,6 @@ import java.util.ArrayList; ...@@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.eclipse.core.databinding.Binding; import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext; import org.eclipse.core.databinding.DataBindingContext;
...@@ -63,7 +62,6 @@ import org.eclipse.swt.widgets.Composite; ...@@ -63,7 +62,6 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.TabFolder; import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem; import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Table;
...@@ -459,7 +457,7 @@ public class SheetDisplay extends Composite { ...@@ -459,7 +457,7 @@ public class SheetDisplay extends Composite {
try { try {
final ObjectNode jsonObject = RowConverter.toJson(map1); final ObjectNode jsonObject = RowConverter.toJson(map1);
final String prettyJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonObject); final String prettyJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonObject);
showMessageBox("Genesys JSON Preview", prettyJson); SwtUtil.showMessageBox(getShell(), "Genesys JSON Preview", prettyJson);
} catch (Exception e) { } catch (Exception e) {
_log.error(e.getMessage(), e); _log.error(e.getMessage(), e);
showMessageBox("Conversion error", e); showMessageBox("Conversion error", e);
...@@ -472,19 +470,7 @@ public class SheetDisplay extends Composite { ...@@ -472,19 +470,7 @@ public class SheetDisplay extends Composite {
pw.println(e.getMessage()); pw.println(e.getMessage());
e.printStackTrace(pw); e.printStackTrace(pw);
sw.flush(); sw.flush();
showMessageBox(title, sw.toString()); SwtUtil.showMessageBox(getShell(), title, sw.toString());
}
public void showMessageBox(final String title, final String message) {
getDisplay().syncExec(new Runnable() {
@Override
public void run() {
MessageBox mb = new MessageBox(getShell());
mb.setMessage(StringUtils.defaultIfBlank(message, "?"));
mb.setText(StringUtils.defaultIfBlank(title, "A message from our sponsors"));
mb.open();
}
});
} }
protected void doDataReload() { protected void doDataReload() {
......
...@@ -10,6 +10,7 @@ import org.genesys2.anno.model.Settings; ...@@ -10,6 +10,7 @@ import org.genesys2.anno.model.Settings;
import org.genesys2.anno.parser.CsvDataSourceParser; import org.genesys2.anno.parser.CsvDataSourceParser;
import org.genesys2.anno.parser.XlsxDataSourceParser; import org.genesys2.anno.parser.XlsxDataSourceParser;
import org.genesys2.client.oauth.GenesysClient; import org.genesys2.client.oauth.GenesysClient;
import org.genesys2.client.oauth.api.GenesysApi;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
...@@ -17,7 +18,6 @@ import org.springframework.context.annotation.Bean; ...@@ -17,7 +18,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
...@@ -96,6 +96,7 @@ public class SpringConfig { ...@@ -96,6 +96,7 @@ public class SpringConfig {
// Not a bean // Not a bean
public static GenesysClient createGenesysClient(OAuthSettings oauthSettings) { public static GenesysClient createGenesysClient(OAuthSettings oauthSettings) {
GenesysClient genesysClient = new GenesysClient(); GenesysClient genesysClient = new GenesysClient();
genesysClient.setGenesysApi(new GenesysApi());
genesysClient.setBaseUrl(oauthSettings.getServerUrl()); genesysClient.setBaseUrl(oauthSettings.getServerUrl());
genesysClient.setAccessToken(oauthSettings.getAccessToken()); genesysClient.setAccessToken(oauthSettings.getAccessToken());
genesysClient.setRefreshToken(oauthSettings.getRefreshToken()); genesysClient.setRefreshToken(oauthSettings.getRefreshToken());
......
...@@ -15,7 +15,7 @@ import org.eclipse.swt.widgets.Text; ...@@ -15,7 +15,7 @@ import org.eclipse.swt.widgets.Text;
public class SwtLogAppender extends WriterAppender { public class SwtLogAppender extends WriterAppender {
private static final String DEFAULT_LAYOUT_PATTERN = "%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n"; private static final String DEFAULT_LAYOUT_PATTERN = "%d{yyyy-MM-dd HH:mm:ss} %t %-5p %c{1}:%L - %m%n";
private Text text; private Text text;
private Display display; private Display display;
private int maxBufferSize = 100000; private int maxBufferSize = 100000;
......
package org.genesys2.anno.gui;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
public class SwtUtil {
public static void showMessageBox(final Shell shell, final String title, final String message) {
shell.getDisplay().syncExec(new Runnable() {
@Override
public void run() {
MessageBox mb = new MessageBox(shell);
mb.setMessage(StringUtils.defaultIfBlank(message, "?"));
mb.setText(StringUtils.defaultIfBlank(title, "A message from our sponsors"));
mb.open();
}
});
}
}
Supports Markdown
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