Commit c61012b9 authored by Matija Obreza's avatar Matija Obreza
Browse files

Fixed typo (dublInst->duplSite) in DWCA export, added names.csv

parent a74c3d2f
...@@ -45,4 +45,6 @@ public interface GenesysLowlevelRepository { ...@@ -45,4 +45,6 @@ public interface GenesysLowlevelRepository {
void listAccessionsColl(String code, RowCallbackHandler rowCallbackHandler); void listAccessionsColl(String code, RowCallbackHandler rowCallbackHandler);
void listMetadataAccessions(long id, RowCallbackHandler rowCallbackHandler); void listMetadataAccessions(long id, RowCallbackHandler rowCallbackHandler);
void listAccessionsAlias(String code, RowCallbackHandler rowCallbackHandler);
} }
...@@ -209,7 +209,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository ...@@ -209,7 +209,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
@Override @Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException { public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
PreparedStatement stmt = con PreparedStatement stmt = con
.prepareStatement("select a.id, a.uuid, a.instCode, a.acceNumb, a.genus, t.species, a.orgCty, a.acqSrc, a.acqDate, a.mlsStat, a.available, a.storage, a.sampStat, a.dublInst, a.createdBy, a.createdDate, a.lastModifiedBy, a.lastModifiedDate from accession a left outer join taxonomy t on t.id=a.taxonomyId where a.instCode = ?"); .prepareStatement("select a.id, a.uuid, a.instCode, a.acceNumb, a.genus, t.species, a.orgCty, a.acqSrc, a.acqDate, a.mlsStat, a.available, a.storage, a.sampStat, a.duplSite, a.createdBy, a.createdDate, a.lastModifiedBy, a.lastModifiedDate from accession a left outer join taxonomy t on t.id=a.taxonomyId where a.instCode = ?");
stmt.setString(1, instCode); stmt.setString(1, instCode);
// Set mysql JConnector to stream results // Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE); stmt.setFetchSize(Integer.MIN_VALUE);
...@@ -233,6 +233,21 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository ...@@ -233,6 +233,21 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
}, rowCallbackHandler); }, rowCallbackHandler);
} }
@Override
public void listAccessionsAlias(final String instCode, RowCallbackHandler rowCallbackHandler) {
jdbcTemplate.query(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
PreparedStatement stmt = con
.prepareStatement("select a.id, n.instCode, n.name, n.aliasType, n.lang, n.version from accessionalias n inner join accession a on a.id=n.accessionId where a.instCode = ?");
stmt.setString(1, instCode);
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
return stmt;
}
}, rowCallbackHandler);
}
@Override @Override
public void listAccessionsColl(final String instCode, RowCallbackHandler rowCallbackHandler) { public void listAccessionsColl(final String instCode, RowCallbackHandler rowCallbackHandler) {
jdbcTemplate.query(new PreparedStatementCreator() { jdbcTemplate.query(new PreparedStatementCreator() {
......
...@@ -36,6 +36,7 @@ import org.apache.commons.logging.Log; ...@@ -36,6 +36,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.genesys.Accession; import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionAlias; import org.genesys2.server.model.genesys.AccessionAlias;
import org.genesys2.server.model.genesys.AccessionAlias.AliasType;
import org.genesys2.server.model.genesys.AccessionBreeding; import org.genesys2.server.model.genesys.AccessionBreeding;
import org.genesys2.server.model.genesys.AccessionCollect; import org.genesys2.server.model.genesys.AccessionCollect;
import org.genesys2.server.model.genesys.AccessionExchange; import org.genesys2.server.model.genesys.AccessionExchange;
...@@ -661,7 +662,15 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset ...@@ -661,7 +662,15 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
zos.closeEntry(); zos.closeEntry();
// AccessionGeo // AccessionGeo
ZipEntry entry = new ZipEntry("geo.csv"); ZipEntry entry = new ZipEntry("names.csv");
entry.setComment("Accession Names");
entry.setTime(System.currentTimeMillis());
zos.putNextEntry(entry);
writeAccessionsNames(faoInstitute, zos);
zos.closeEntry();
// AccessionGeo
entry = new ZipEntry("geo.csv");
entry.setComment("GIS information"); entry.setComment("GIS information");
entry.setTime(System.currentTimeMillis()); entry.setTime(System.currentTimeMillis());
zos.putNextEntry(entry); zos.putNextEntry(entry);
...@@ -705,6 +714,18 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset ...@@ -705,6 +714,18 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
osw.write("\t<field index=\"17\" term=\"lastModifiedDate\"/>\n"); osw.write("\t<field index=\"17\" term=\"lastModifiedDate\"/>\n");
osw.write("</core>\n"); osw.write("</core>\n");
osw.write("<extension encoding=\"UTF-8\" fieldsTerminatedBy=\",\" linesTerminatedBy=\"\\n\" fieldsEnclosedBy=\"&quot;\" ignoreHeaderLines=\"0\">\n");
osw.write("\t<files><location>");
osw.write("names.csv");
osw.write("</location></files>\n");
osw.write("\t<coreid index=\"0\" />\n");
osw.write("\t<field index=\"1\" term=\"instCode\"/>\n");
osw.write("\t<field index=\"2\" term=\"name\"/>\n");
osw.write("\t<field index=\"3\" term=\"aliasType\"/>\n");
osw.write("\t<field index=\"4\" term=\"lang\"/>\n");
osw.write("\t<field index=\"5\" term=\"version\"/>\n");
osw.write("</extension>\n");
osw.write("<extension encoding=\"UTF-8\" fieldsTerminatedBy=\",\" linesTerminatedBy=\"\\n\" fieldsEnclosedBy=\"&quot;\" ignoreHeaderLines=\"0\">\n"); osw.write("<extension encoding=\"UTF-8\" fieldsTerminatedBy=\",\" linesTerminatedBy=\"\\n\" fieldsEnclosedBy=\"&quot;\" ignoreHeaderLines=\"0\">\n");
osw.write("\t<files><location>"); osw.write("\t<files><location>");
osw.write("geo.csv"); osw.write("geo.csv");
...@@ -746,7 +767,7 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset ...@@ -746,7 +767,7 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
@SuppressWarnings("resource") @SuppressWarnings("resource")
final CSVWriter csv = new CSVWriter(new BufferedWriter(new OutputStreamWriter(zos)), ',', '"', '\\', "\n"); final CSVWriter csv = new CSVWriter(new BufferedWriter(new OutputStreamWriter(zos)), ',', '"', '\\', "\n");
csv.writeNext(new String[] { "genesysId", "uuid", "instCode", "acceNumb", "genus", "species", "orgCty", "acqSrc", "acqDate", "mlsStat", "available", csv.writeNext(new String[] { "genesysId", "uuid", "instCode", "acceNumb", "genus", "species", "orgCty", "acqSrc", "acqDate", "mlsStat", "available",
"storage", "sampStat", "dublInst", "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate" }); "storage", "sampStat", "duplSite", "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate" });
final ResultSetHelper csvResultsetHelper = new ResultSetHelperService(); final ResultSetHelper csvResultsetHelper = new ResultSetHelperService();
...@@ -797,6 +818,42 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset ...@@ -797,6 +818,42 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
csv.flush(); csv.flush();
} }
private void writeAccessionsNames(final FaoInstitute faoInstitute, ZipOutputStream zos) throws IOException {
@SuppressWarnings("resource")
final CSVWriter csv = new CSVWriter(new BufferedWriter(new OutputStreamWriter(zos)), ',', '"', '\\', "\n");
csv.writeNext(new String[] { "genesysId", "instCode", "name", "aliasType", "lang", "version" });
final ResultSetHelper csvResultsetHelper = new ResultSetHelperService();
// Write accession information
genesysLowlevelRepository.listAccessionsAlias(faoInstitute.getCode(), new RowCallbackHandler() {
int i = 0;
@Override
public void processRow(ResultSet rs) throws SQLException {
try {
String[] r = csvResultsetHelper.getColumnValues(rs);
if (r[3] != null) {
try {
AliasType aliasType = AliasType.getType(Integer.parseInt(r[3]));
r[3] = aliasType.name();
} catch (NumberFormatException e) {
LOG.warn(e.getMessage());
}
}
csv.writeNext(r);
} catch (IOException e) {
LOG.error("Reading resultset for DWCA aliases ", e);
}
if ((i++ % 5000) == 0) {
LOG.info("Writing alias DWCA " + faoInstitute.getCode() + " " + i);
}
}
});
csv.flush();
}
private void writeAccessionsColl(final FaoInstitute faoInstitute, ZipOutputStream zos) throws IOException { private void writeAccessionsColl(final FaoInstitute faoInstitute, ZipOutputStream zos) throws IOException {
@SuppressWarnings("resource") @SuppressWarnings("resource")
final CSVWriter csv = new CSVWriter(new BufferedWriter(new OutputStreamWriter(zos)), ',', '"', '\\', "\n"); final CSVWriter csv = new CSVWriter(new BufferedWriter(new OutputStreamWriter(zos)), ',', '"', '\\', "\n");
...@@ -909,13 +966,12 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset ...@@ -909,13 +966,12 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
zos.finish(); zos.finish();
} }
private void writeDatasetCore(final Metadata metadata, ZipOutputStream zos) throws IOException { private void writeDatasetCore(final Metadata metadata, ZipOutputStream zos) throws IOException {
@SuppressWarnings("resource") @SuppressWarnings("resource")
final CSVWriter csv = new CSVWriter(new BufferedWriter(new OutputStreamWriter(zos), 4096), ',', '"', '\\', "\n"); final CSVWriter csv = new CSVWriter(new BufferedWriter(new OutputStreamWriter(zos), 4096), ',', '"', '\\', "\n");
csv.writeNext(new String[] { "coreId", "instCode", "acceNumb", "genus" }); csv.writeNext(new String[] { "coreId", "instCode", "acceNumb", "genus" });
final ResultSetHelper csvResultsetHelper = new ResultSetHelperService(); final ResultSetHelper csvResultsetHelper = new ResultSetHelperService();
// Write accession information // Write accession information
...@@ -943,7 +999,6 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset ...@@ -943,7 +999,6 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
csv.flush(); csv.flush();
} }
@Override @Override
@Transactional @Transactional
@PreAuthorize("hasRole('ADMINISTRATOR')") @PreAuthorize("hasRole('ADMINISTRATOR')")
......
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