99 lines
2.1 KiB
Java
99 lines
2.1 KiB
Java
package org.gcube.application.perform.service.engine.model.importer;
|
|
|
|
import java.io.File;
|
|
import java.sql.Types;
|
|
import java.util.ArrayList;
|
|
import java.util.Map;
|
|
import java.util.Map.Entry;
|
|
|
|
import org.gcube.application.perform.service.engine.impl.Query;
|
|
import org.gcube.application.perform.service.engine.model.CSVExportRequest;
|
|
import org.gcube.application.perform.service.engine.model.DBField;
|
|
import org.gcube.application.perform.service.engine.model.DBQueryDescriptor;
|
|
|
|
public class ImportedTable {
|
|
|
|
/**
|
|
* CSV FILE labels -> DBField
|
|
*/
|
|
|
|
private Map<String,DBField> mappings;
|
|
|
|
private ArrayList<String> csvFields;
|
|
|
|
private String tablename;
|
|
private DBField routineIdField;
|
|
|
|
private Query query;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* Checks if passed set of labels is
|
|
*
|
|
* @param toMatchSchema
|
|
* @return
|
|
*/
|
|
public boolean matchesSchema(ArrayList<String> toMatchSchema) {
|
|
return csvFields.equals(toMatchSchema);
|
|
}
|
|
|
|
|
|
public DBQueryDescriptor getSetRow(Map<String,String> csvRow, Long routineId) {
|
|
DBQueryDescriptor desc=new DBQueryDescriptor();
|
|
|
|
for(Entry<String,String> csvField:csvRow.entrySet()) {
|
|
DBField toSetField=mappings.get(csvField.getKey());
|
|
|
|
Object value=csvField.getValue();
|
|
|
|
switch(toSetField.getType()) {
|
|
case Types.BIGINT : value=Long.parseLong((String) value);
|
|
break;
|
|
case Types.REAL : value=Double.parseDouble((String) value);
|
|
break;
|
|
}
|
|
desc.add(toSetField, value);
|
|
}
|
|
|
|
desc.add(routineIdField, routineId);
|
|
return desc;
|
|
}
|
|
|
|
public Query getQuery() {
|
|
return query;
|
|
}
|
|
public String getTableName() {
|
|
return tablename;
|
|
}
|
|
|
|
public File exportCSV(CSVExportRequest request) {
|
|
// USE CASE to replace values in
|
|
/**
|
|
* SELECT
|
|
CASE status
|
|
WHEN 'VS' THEN 'validated by subsidiary'
|
|
WHEN 'NA' THEN 'not acceptable'
|
|
WHEN 'D' THEN 'delisted'
|
|
ELSE 'validated'
|
|
END AS STATUS
|
|
FROM SUPP_STATUS
|
|
*/
|
|
|
|
// get deanonimized labels
|
|
// Create query
|
|
|
|
|
|
// Pass the result set to the CSV specifying labels
|
|
// final Appendable out = ...;
|
|
// final CSVPrinter printer = CSVFormat.DEFAULT.withHeader("H1", "H2").print(out)
|
|
|
|
// return file
|
|
throw new RuntimeException("Not implemented");
|
|
|
|
}
|
|
}
|