package eu.etaxonomy.cdm.io.cdmLight;
import java.io.ByteArrayOutputStream;
-import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.commons.io.IOUtils;
-import eu.etaxonomy.cdm.io.common.ExportResult;
-import eu.etaxonomy.cdm.io.common.ExportResultType;
+import eu.etaxonomy.cdm.io.common.ExportType;
import eu.etaxonomy.cdm.model.common.ICdmBase;
/**
* @author k.luther
- * @date 16.03.2017
+ * @since 16.03.2017
*
*/
public class CdmLightExportResultProcessor {
private static final String HEADER = "HEADER_207dd23a-f877-4c27-b93a-8dbea3234281";
private Map<CdmLightExportTable, Map<String,String[]>> result = new HashMap<>();
- //private CdmLightExportState state;
+ private CdmLightExportState state;
/**
*/
public CdmLightExportResultProcessor(CdmLightExportState state) {
super();
- //this.state = state;
+ this.state = state;
}
* @param taxon
* @param csvLine
*/
- public void put(CdmLightExportTable table, String id, String[] csvLine, CdmLightExportState state) {
+ public void put(CdmLightExportTable table, String id, String[] csvLine) {
Map<String,String[]> resultMap = result.get(table);
if (resultMap == null ){
resultMap = new HashMap<>();
String[] oldRecord = resultMap.put(id, record);
if (oldRecord != null){
- System.out.println("This should not happen");
+ String message = "Output processor already has a record for id " + id + ". This should not happen.";
+ state.getResult().addWarning(message);
}
}
}
}
}
+ public String[] getRecord(CdmLightExportTable table, String id){
+ return result.get(table).get(id);
+
+ }
/**
* @param table
* @param taxon
* @param csvLine
*/
- public void put(CdmLightExportTable table, ICdmBase cdmBase, String[] csvLine, CdmLightExportState state) {
- this.put(table, String.valueOf(cdmBase.getId()), csvLine, state);
+ public void put(CdmLightExportTable table, ICdmBase cdmBase, String[] csvLine) {
+ this.put(table, cdmBase.getUuid().toString(), csvLine);
}
* @return
*/
public void createFinalResult(CdmLightExportState state) {
- ExportResult finalResult = ExportResult.NewInstance(ExportResultType.MAP_BYTE_ARRAY);
if (!result.isEmpty() ){
+ state.setAuthorStore(new HashMap<>());
+ state.setHomotypicalGroupStore(new HashMap<>());
+ state.setReferenceStore(new HashMap<>());
+ state.setSpecimenStore(new HashMap<>());
+ state.setNodeChildrenMap(new HashMap<>());
//Replace quotes by double quotes
for (CdmLightExportTable table: result.keySet()){
//schreibe jede Tabelle in einen Stream...
ByteArrayOutputStream exportStream = new ByteArrayOutputStream();
try{
- List<String> data = new ArrayList<String>();
+ List<String> data = new ArrayList<>();
String[] csvHeaderLine = tableData.get(HEADER);
String lineString = createCsvLine(config, csvHeaderLine);
lineString = lineString+ "";
IOUtils.writeLines(data,
null,exportStream,
Charset.forName("UTF-8"));
- } catch(IOException e){
- finalResult.addException(e, e.getMessage());
+ } catch(Exception e){
+ state.getResult().addException(e, e.getMessage());
}
- finalResult.putExportData(table.getTableName(), exportStream.toByteArray());
+ state.getResult().putExportData(table.getTableName(), exportStream.toByteArray());
+ state.getResult().setExportType(ExportType.CDM_LIGHT);
}
}
result.clear();
-
- state.setResult(finalResult);
}