Commit 8fab901d authored by igoshin's avatar igoshin Committed by Matija Obreza

Column configuration

parent a09aed07
/**
* Copyright 2014 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.
......@@ -24,15 +24,23 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.genesys2.anno.model.*;
import org.genesys2.anno.model.Column;
import org.genesys2.anno.model.ColumnDataType;
import org.genesys2.anno.model.DatabaseSettings;
import org.genesys2.anno.model.OAuthSettings;
import org.genesys2.anno.model.Settings;
import org.genesys2.anno.parser.CsvDataSourceSheet;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.springframework.beans.factory.annotation.Autowired;
public class DwcaBuilder extends AbstractModelObject {
@Autowired
private DataSourceLoader dataSourceLoader;
private List<IDataSource> fileRoots = new ArrayList<IDataSource>();
private String workspaceFilename = null;
......@@ -235,8 +243,19 @@ public class DwcaBuilder extends AbstractModelObject {
JSONArray columns = sheetJ.getJSONArray("columns");
List<Column> columnList = new ArrayList<Column>();
for (int x = 0; x < columns.length(); x++) {
JSONObject column = columns.getJSONObject(x);
List<Object[]> rows=null;
try {
rows = dataSourceLoader.loadRows(sourceSheet, 200);
} catch (UnsupportedDataFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
sourceSheet.updateData(rows);
List<Column> loadedColumns = sourceSheet.getColumns();
for (int x = 0; x < columns.length(); x++) {
JSONObject column = columns.getJSONObject(x);
Column sourceColumn = new Column();
......@@ -257,11 +276,20 @@ public class DwcaBuilder extends AbstractModelObject {
if (column.has("multiple"))
sourceColumn.setMultiple(column.getBoolean("multiple"));
columnList.add(sourceColumn);
}
sourceSheet.setColumns(columnList);
sourceSheetList.add(sourceSheet);
}
if (loadedColumns.contains(sourceColumn)){
columnList.add(sourceColumn);
}
}
for (Column loadedColumn:loadedColumns){
if (!columnList.contains(loadedColumn)){
columnList.add(loadedColumns.indexOf(loadedColumn),loadedColumn);
}
}
sourceSheet.setColumns(columnList);
sourceSheetList.add(sourceSheet);
}
sourceFile.setSheets(sourceSheetList);
......
......@@ -120,4 +120,18 @@ public class Column extends AbstractModelObject {
this.groupPattern = groupPattern;
firePropertyChange("groupPattern", null, this.groupPattern);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Column column = (Column) o;
if (preferredName != null ? !preferredName.equals(column.preferredName) : column.preferredName != null)
return false;
return true;
}
}
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