Commit 7f64baf4 authored by Matija Obreza's avatar Matija Obreza
Browse files

Licensing information

parent 2c3c006b
/*
* Copyright 2016 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys2.anno.converter;
public class GenesysJSONException extends Exception {
......
/*
* Copyright 2016 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys2.anno.converter;
public class GenesysJSONIncompleteException extends GenesysJSONException {
......
/*
* Copyright 2016 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys2.anno.converter;
import java.util.ArrayList;
......@@ -37,10 +52,8 @@ public class RowConverter {
private static final Pattern REGEXP_REPLACE_PATTERN = Pattern.compile("\\$(\\d+)");
public static Map<String, ?> toMap(IDataSourceSheet dataSourceSheet,
Object[] row, ColumnDefs columnDefs) {
HashMap<String, Object> map = new HashMap<String, Object>(columnDefs
.getColumnDefs().size());
public static Map<String, ?> toMap(IDataSourceSheet dataSourceSheet, Object[] row, ColumnDefs columnDefs) {
HashMap<String, Object> map = new HashMap<String, Object>(columnDefs.getColumnDefs().size());
_log.debug("Converting " + ArrayUtils.toString(row));
......@@ -48,8 +61,7 @@ public class RowConverter {
for (int i = 0; i < columns.size(); i++) {
Column column = columns.get(i);
ColumnDef columnDef = findColumnDef(column,
columnDefs.getColumnDefs());
ColumnDef columnDef = findColumnDef(column, columnDefs.getColumnDefs());
if (columnDef == null) {
continue;
}
......@@ -58,38 +70,30 @@ public class RowConverter {
if (column.isIncludeNull()) {
map.put(columnDef.getRdfTerm(), null);
}
_log.debug("Row has less than " + (i + 1) + " columns: len="
+ row.length + " " + ArrayUtils.toString(row));
_log.debug("Row has less than " + (i + 1) + " columns: len=" + row.length + " " + ArrayUtils.toString(row));
continue;
}
Object rowValue = convertCellValue(row[i], column.isMultiple(),
column.getSeparator(), column.getPattern(),
column.getGroupPattern());
Object rowValue = convertCellValue(row[i], column.isMultiple(), column.getSeparator(), column.getPattern(), column.getGroupPattern());
Object mapValue = map.get(columnDef.getRdfTerm());
if (mapValue == null) {
_log.debug("Adding value for " + columnDef.getRdfTerm()
+ " val=" + rowValue);
_log.debug("Adding value for " + columnDef.getRdfTerm() + " val=" + rowValue);
if (rowValue instanceof String[]) {
_log.debug("val=" + ArrayUtils.toString(rowValue));
map.put(columnDef.getRdfTerm(), new ArrayList<String>(
Arrays.asList((String[]) rowValue)));
map.put(columnDef.getRdfTerm(), new ArrayList<String>(Arrays.asList((String[]) rowValue)));
} else {
map.put(columnDef.getRdfTerm(), rowValue);
}
} else if (mapValue instanceof List<?>) {
_log.debug("Adding " + columnDef.getRdfTerm() + " to List<?>"
+ " val=" + rowValue);
_log.debug("Adding " + columnDef.getRdfTerm() + " to List<?>" + " val=" + rowValue);
if (rowValue instanceof String[]) {
((List<Object>) mapValue).addAll(Arrays
.asList((String[]) rowValue));
((List<Object>) mapValue).addAll(Arrays.asList((String[]) rowValue));
} else if (rowValue != null) {
((List<Object>) mapValue).add(rowValue);
}
} else if (rowValue != null) {
_log.debug("Converting " + columnDef.getRdfTerm()
+ " to List<?>" + " val=" + rowValue);
_log.debug("Converting " + columnDef.getRdfTerm() + " to List<?>" + " val=" + rowValue);
Object currentVal = mapValue;
List<Object> newVal = new ArrayList<Object>();
newVal.add(currentVal);
......@@ -117,8 +121,7 @@ public class RowConverter {
return map;
}
private static Object convertCellValue(Object value, boolean splitString,
String separator, String pattern, String groupPattern) {
private static Object convertCellValue(Object value, boolean splitString, String separator, String pattern, String groupPattern) {
if (value != null) {
if (value instanceof String) {
String stringValue = ((String) value);
......@@ -129,8 +132,7 @@ public class RowConverter {
String[] split = stringValue.split(separator);
for (int i = split.length - 1; i >= 0; i--) {
if (pattern != null) {
split[i] = valueFromPattern(split[i].trim(),
pattern, groupPattern);
split[i] = valueFromPattern(split[i].trim(), pattern, groupPattern);
} else {
split[i] = split[i].trim();
}
......@@ -138,8 +140,7 @@ public class RowConverter {
return split;
}
String patVal = valueFromPattern(stringValue.trim(), pattern,
groupPattern);
String patVal = valueFromPattern(stringValue.trim(), pattern, groupPattern);
if (StringUtils.isBlank(patVal)) {
return null;
}
......@@ -151,16 +152,14 @@ public class RowConverter {
return value;
}
private static String valueFromPattern(String trim, String pattern,
String groupPattern) {
private static String valueFromPattern(String trim, String pattern, String groupPattern) {
if (StringUtils.isBlank(pattern)) {
return trim;
}
Pattern pat = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
Matcher matcher = pat.matcher(trim);
if (matcher.find()) {
String res = matcher.groupCount() == 0 ? matcher.group() : matcher
.group(1);
String res = matcher.groupCount() == 0 ? matcher.group() : matcher.group(1);
if (StringUtils.isNotBlank(groupPattern)) {
res = groupPattern;
Matcher replaceMat = REGEXP_REPLACE_PATTERN.matcher(groupPattern);
......@@ -177,8 +176,7 @@ public class RowConverter {
return null;
}
private static ColumnDef findColumnDef(Column column,
List<ColumnDef> columnDefList) {
private static ColumnDef findColumnDef(Column column, List<ColumnDef> columnDefList) {
for (ColumnDef columnDef : columnDefList) {
if (columnDef.getRdfTerm().equals(column.getRdfTerm())) {
return columnDef;
......@@ -189,8 +187,7 @@ public class RowConverter {
return null;
}
public static List<Map<String, ?>> toMap(IDataSourceSheet dataSourceSheet,
List<Object[]> rows, ColumnDefs columnDefs) {
public static List<Map<String, ?>> toMap(IDataSourceSheet dataSourceSheet, List<Object[]> rows, ColumnDefs columnDefs) {
List<Map<String, ?>> list = new ArrayList<Map<String, ?>>(rows.size());
for (Object[] row : rows) {
list.add(toMap(dataSourceSheet, row, columnDefs));
......@@ -198,8 +195,7 @@ public class RowConverter {
return list;
}
public static ArrayNode toGenesysJson(List<Map<String, ?>> list)
throws GenesysJSONException, JsonGenerationException {
public static ArrayNode toGenesysJson(List<Map<String, ?>> list) throws GenesysJSONException, JsonGenerationException {
ArrayNode result = mapper.createArrayNode();
for (Map<String, ?> row : list) {
......@@ -213,8 +209,7 @@ public class RowConverter {
return result;
}
public static ObjectNode toJson(Map<String, ?> row)
throws GenesysJSONException, JsonGenerationException {
public static ObjectNode toJson(Map<String, ?> row) throws GenesysJSONException, JsonGenerationException {
if (row == null)
return null;
......@@ -229,19 +224,14 @@ public class RowConverter {
for (GenesysJSON.JsonField jsonField : genesysJson.getRequiredFields()) {
if (!hasNodeValue(rowNode, jsonField.getFieldName())) {
throw new GenesysJSONIncompleteException(
"Missing required property '"
+ jsonField.getFieldName() + "' "
+ jsonField.getRdfTerm());
throw new GenesysJSONIncompleteException("Missing required property '" + jsonField.getFieldName() + "' " + jsonField.getRdfTerm());
}
}
return rowNode;
}
private static void add(ObjectNode rowNode, JsonField jsonField,
Object rdfValues) throws GenesysJSONException,
JsonGenerationException {
private static void add(ObjectNode rowNode, JsonField jsonField, Object rdfValues) throws GenesysJSONException, JsonGenerationException {
String fieldName = jsonField.getFieldName();
ObjectNode containerNode = ensureNode(rowNode, fieldName);
int dotPost = fieldName.lastIndexOf('.');
......@@ -257,8 +247,7 @@ public class RowConverter {
}
} else {
if (jsonField.hasAllowMultiple() && !valueNode.isArray()) {
throw new GenesysJSONException("Expecting arrayObject for "
+ fieldName);
throw new GenesysJSONException("Expecting arrayObject for " + fieldName);
}
}
......@@ -276,17 +265,14 @@ public class RowConverter {
} else {
// System.err.println("Putting field=" + fieldName + " type=" +
// rdfValues.getClass());
containerNode.set(fieldName,
coerce(jsonField.getType(), rdfValues));
containerNode.set(fieldName, coerce(jsonField.getType(), rdfValues));
}
}
}
static ObjectNode ensureNode(ObjectNode parentNode, String nodeName)
throws JsonGenerationException {
static ObjectNode ensureNode(ObjectNode parentNode, String nodeName) throws JsonGenerationException {
if (StringUtils.isBlank(nodeName)) {
throw new JsonGenerationException(
"nodeName should not be blank or null");
throw new JsonGenerationException("nodeName should not be blank or null");
}
int dotIndex = nodeName.indexOf('.');
if (dotIndex > -1) {
......@@ -302,11 +288,9 @@ public class RowConverter {
return parentNode;
}
static boolean hasNodeValue(final ObjectNode parentNode,
final String nodeName) throws JsonGenerationException {
static boolean hasNodeValue(final ObjectNode parentNode, final String nodeName) throws JsonGenerationException {
if (StringUtils.isBlank(nodeName)) {
throw new JsonGenerationException(
"nodeName should not be blank or null");
throw new JsonGenerationException("nodeName should not be blank or null");
}
String[] path = nodeName.split("\\.");
JsonNode node = parentNode;
......@@ -326,8 +310,7 @@ public class RowConverter {
}
}
}
return node != null && !node.isNull() && !node.isMissingNode()
&& !node.isArray() && node.isValueNode();
return node != null && !node.isNull() && !node.isMissingNode() && !node.isArray() && node.isValueNode();
}
static JsonNode coerce(Class<?> clazz, Object rdfValues) {
......@@ -350,11 +333,7 @@ public class RowConverter {
}
private static boolean toBoolean(String rdfValue) {
return "true".equalsIgnoreCase(rdfValue)
|| "yes".equalsIgnoreCase(rdfValue)
|| "t".equalsIgnoreCase(rdfValue)
|| "y".equalsIgnoreCase(rdfValue)
|| "1".equalsIgnoreCase(rdfValue);
return "true".equalsIgnoreCase(rdfValue) || "yes".equalsIgnoreCase(rdfValue) || "t".equalsIgnoreCase(rdfValue) || "y".equalsIgnoreCase(rdfValue) || "1".equalsIgnoreCase(rdfValue);
}
}
......@@ -207,14 +207,13 @@ public class AppWindow {
private static Image addDatabaseIcon;
static Image applicationIcon128;
private Tree filesTree;
private Display display;
private TreeViewer treeViewer;
private TableViewer tableViewer;
private CTabFolder tabFolder;
private Table table;
static {
AppWindow.archiveIcon = ImageDescriptor.createFromURL(AppWindow.class.getResource("/icon/archive.png")).createImage();
AppWindow.openPackageIcon = ImageDescriptor.createFromURL(AppWindow.class.getResource("/icon/openpackage.png")).createImage();
......@@ -236,7 +235,7 @@ public class AppWindow {
*/
public static void main(String[] args) {
Shell workspaceShell = new Shell();
WorkspaceDialog workspaceDialog = new WorkspaceDialog(workspaceShell);
Object workspacePath = workspaceDialog.open();
workspaceShell.dispose();
......@@ -415,14 +414,14 @@ public class AppWindow {
builder.removeDataSource((IDataSource) selectedObject);
tableViewer.refresh();
}
if (selectedObject instanceof JdbcDataSourceSheet) {
IStructuredSelection thisSelection = (IStructuredSelection) treeViewer.getSelection();
IDataSource currentSource= (IDataSource) ((TreeSelection) thisSelection).getPaths()[0].getFirstSegment();
if (confirmRemoveQuery()){
currentSource.removeSheet((IDataSourceSheet) selectedObject);
}
tableViewer.refresh();
}
if (selectedObject instanceof JdbcDataSourceSheet) {
IStructuredSelection thisSelection = (IStructuredSelection) treeViewer.getSelection();
IDataSource currentSource = (IDataSource) ((TreeSelection) thisSelection).getPaths()[0].getFirstSegment();
if (confirmRemoveQuery()) {
currentSource.removeSheet((IDataSourceSheet) selectedObject);
}
tableViewer.refresh();
}
}
treeViewer.refresh();
......@@ -439,11 +438,11 @@ public class AppWindow {
Object selectedObject = iterator.next();
_log.debug("Sel " + selectedObject);
if (selectedObject instanceof IDataSource) {
enabled = true;
}
if(selectedObject instanceof JdbcDataSourceSheet){
enabled=true;
}
enabled = true;
}
if (selectedObject instanceof JdbcDataSourceSheet) {
enabled = true;
}
}
mntmRemoveFile.setEnabled(enabled);
......@@ -507,9 +506,9 @@ public class AppWindow {
IStructuredSelection thisSelection = (IStructuredSelection) e.getSelection();
Object selectedNode = thisSelection.getFirstElement();
IDataSource currentSource= (IDataSource) ((TreeSelection) thisSelection).getPaths()[0].getFirstSegment();
IDataSource currentSource = (IDataSource) ((TreeSelection) thisSelection).getPaths()[0].getFirstSegment();
if (selectedNode instanceof IDataSourceSheet) {
if (selectedNode instanceof IDataSourceSheet) {
final IDataSourceSheet currentSheet = (IDataSourceSheet) selectedNode;
_log.debug("Doubleclick " + currentSheet);
int i = 0;
......@@ -523,7 +522,7 @@ public class AppWindow {
i++;
}
}
CTabItem newSheetTab = createTab(tabFolder,currentSource, currentSheet);
CTabItem newSheetTab = createTab(tabFolder, currentSource, currentSheet);
// Load stuff
if (selectedNode instanceof DataSourceSheet) {
......@@ -585,26 +584,26 @@ public class AppWindow {
});
tltmSettings.setText("Settings");
tltmSettings.setImage(settingsIcon);
ToolItem tltmAddFile = new ToolItem(toolBar, SWT.NONE);
tltmAddFile.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
addSourceFile();
}
});
tltmAddFile.setText("Add file");
tltmAddFile.setImage(openPackageIcon);
ToolItem tltmDatabase = new ToolItem(toolBar, SWT.NONE);
tltmDatabase.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doDatabase();
}
});
tltmDatabase.setText("Add database");
tltmDatabase.setImage(AppWindow.addDatabaseIcon);
ToolItem tltmAddFile = new ToolItem(toolBar, SWT.NONE);
tltmAddFile.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
addSourceFile();
}
});
tltmAddFile.setText("Add file");
tltmAddFile.setImage(openPackageIcon);
ToolItem tltmDatabase = new ToolItem(toolBar, SWT.NONE);
tltmDatabase.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doDatabase();
}
});
tltmDatabase.setText("Add database");
tltmDatabase.setImage(AppWindow.addDatabaseIcon);
ToolItem tltmAutomap = new ToolItem(toolBar, SWT.NONE);
tltmAutomap.addSelectionListener(new SelectionAdapter() {
......@@ -635,7 +634,7 @@ public class AppWindow {
tbtmOther.setText(currentSheet.getSheetName());
tbtmOther.setImage(spreadsheetIcon16);
final SheetDisplay sheetDisplay = (SheetDisplay) applicationContext.getBean("sheetDisplay",currentSource, currentSheet, tabFolder, treeViewer, SWT.NONE);
final SheetDisplay sheetDisplay = (SheetDisplay) applicationContext.getBean("sheetDisplay", currentSource, currentSheet, tabFolder, treeViewer, SWT.NONE);
tbtmOther.setControl(sheetDisplay);
tbtmOther.addDisposeListener(new DisposeListener() {
......@@ -648,14 +647,14 @@ public class AppWindow {
return tbtmOther;
}
private boolean confirmRemoveQuery() {
MessageBox dialog = new MessageBox(shlGenesysMagic, SWT.ICON_WARNING | SWT.OK | SWT.CANCEL);
dialog.setText("Remove query");
dialog.setMessage("Do you want remove this query?");
return dialog.open() == SWT.OK;
}
private boolean confirmRemoveQuery() {
MessageBox dialog = new MessageBox(shlGenesysMagic, SWT.ICON_WARNING | SWT.OK | SWT.CANCEL);
dialog.setText("Remove query");
dialog.setMessage("Do you want remove this query?");
return dialog.open() == SWT.OK;
}
private void doSaveWorkSpace() {
private void doSaveWorkSpace() {
FileDialog dialog = new FileDialog(shlGenesysMagic, SWT.SAVE);
dialog.setFilterNames(new String[] { "JSON Format" });
dialog.setFilterExtensions(new String[] { "*.json" });
......@@ -702,12 +701,11 @@ public class AppWindow {
if (dss == null) {
return;
}
final IDataSource dataSource = getCurrentDataSource();
final IDataSource dataSource = getCurrentDataSource();
PushDialog pushDialog = (PushDialog) applicationContext.getBean("pushDialog", shlGenesysMagic, SWT.NONE);
pushDialog.setDataSourceSheet(dss);
pushDialog.setDataSource(dataSource);
pushDialog.setDataSource(dataSource);
pushDialog.setColumnDefs(this.columnDefs);
pushDialog.open();
......@@ -749,15 +747,15 @@ public class AppWindow {
return dss;
}
public IDataSource getCurrentDataSource() {
CTabItem currentTab = tabFolder.getSelection();
if (currentTab == null) {
_log.info("No tab selected");
return null;
}
final IDataSource ds = ((SheetDisplay) currentTab.getControl()).getDataSource();
return ds;
}
public IDataSource getCurrentDataSource() {
CTabItem currentTab = tabFolder.getSelection();
if (currentTab == null) {
_log.info("No tab selected");
return null;
}
final IDataSource ds = ((SheetDisplay) currentTab.getControl()).getDataSource();
return ds;
}
public void addJdbcQuery(JdbcDataSource dataSource) {
JdbcDataSourceSheet dataSourceSheet = new JdbcDataSourceSheet();
......
......@@ -51,10 +51,10 @@ public class DataSourceFile extends AbstractModelObject implements IDataSource {
firePropertyChange("sheets", null, sheets);
}
@Override
public void removeSheet(IDataSourceSheet sourceSheet){
this.sheets.remove(sourceSheet);
}
@Override
public void removeSheet(IDataSourceSheet sourceSheet) {
this.sheets.remove(sourceSheet);
}
@Override
public String toString() {
......
......@@ -33,5 +33,5 @@ public interface DataSourceLoader {
List<Object[]> loadDataRows(DataSourceSheet sheet, int maxRows) throws UnsupportedDataFormatException, FileNotFoundException, IOException;
RowReader createRowReader(IDataSourceSheet sheet,IDataSource dataSource) throws IOException, UnsupportedDataFormatException;
RowReader createRowReader(IDataSourceSheet sheet, IDataSource dataSource) throws IOException, UnsupportedDataFormatException;
}
/*
* Copyright 2016 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys2.anno.gui;
import java.io.File;
......@@ -44,8 +59,8 @@ public class DatabaseDialog extends Dialog {
private static final Logger _log = Logger.getLogger(DatabaseDialog.class);
private DataBindingContext m_bindingContext;
@Value("${genesys.magic.workspace}")
private String workspacePath;
@Value("${genesys.magic.workspace}")
private String workspacePath;
@Autowired
private DatabaseSettings databaseSettings;
......@@ -53,11 +68,11 @@ public class DatabaseDialog extends Dialog {
@Autowired
private DwcaBuilder builder;
@Autowired
private JdbcDrivers drivers;
@Autowired
private JdbcDrivers drivers;
@Autowired
private ExtraClassLoader extraClassLoader;
@Autowired
private ExtraClassLoader extraClassLoader;
protected Object result;
protected Shell shell;
......@@ -123,21 +138,21 @@ public class DatabaseDialog extends Dialog {
lblType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblType.setText("Database type");
comboType = new Combo(grpDbConfiguration, SWT.NONE);
comboType.setItems(getDriversNames(drivers.getJdbcDrivers()));
comboType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
comboType.addSelectionListener(new SelectionAdapter() {
@Override