Commit 2a977f6e authored by Matija Obreza's avatar Matija Obreza

opencsv upgraded

parent 6e0bedfd
...@@ -325,11 +325,6 @@ ...@@ -325,11 +325,6 @@
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>2.3</version>
</dependency>
<dependency> <dependency>
<groupId>org.sitemesh</groupId> <groupId>org.sitemesh</groupId>
<artifactId>sitemesh</artifactId> <artifactId>sitemesh</artifactId>
...@@ -502,6 +497,11 @@ ...@@ -502,6 +497,11 @@
<artifactId>jsoup</artifactId> <artifactId>jsoup</artifactId>
<version>1.8.2</version> <version>1.8.2</version>
</dependency> </dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>3.7</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -2,22 +2,18 @@ package org.genesys2.server.service.impl; ...@@ -2,22 +2,18 @@ package org.genesys2.server.service.impl;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.math.BigDecimal;
import java.sql.Clob; import java.sql.Clob;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.ResultSetMetaData; import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types; import java.sql.Types;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.genesys2.util.NumberUtils; import org.genesys2.util.NumberUtils;
import au.com.bytecode.opencsv.ResultSetHelperService; import com.opencsv.ResultSetHelperService;
/** /**
* This class extends {@link ResultSetHelperService} by adding support for UUID. * This class extends {@link ResultSetHelperService} by adding support for UUID.
...@@ -34,56 +30,43 @@ public class CSVResultSetHelper extends ResultSetHelperService { ...@@ -34,56 +30,43 @@ public class CSVResultSetHelper extends ResultSetHelperService {
private static final int LONGNVARCHAR = -16; private static final int LONGNVARCHAR = -16;
private static final int NCLOB = 2011; private static final int NCLOB = 2011;
/// Copied straight from superclass /**
* Get all the column values from the result set.
*
* @param rs
* - the ResultSet containing the values.
* @param trim
* - values should have white spaces trimmed.
* @param dateFormatString
* - format String for dates.
* @param timeFormatString
* - format String for timestamps.
* @return - String array containing all the column values.
* @throws SQLException
* - thrown by the result set.
* @throws IOException
* - thrown by the result set.
*/
@Override @Override
public String[] getColumnValues(ResultSet rs) throws SQLException, IOException { public String[] getColumnValues(ResultSet rs, boolean trim, String dateFormatString, String timeFormatString) throws SQLException, IOException {
List<String> values = new ArrayList<String>(); List<String> values = new ArrayList<String>();
ResultSetMetaData metadata = rs.getMetaData(); ResultSetMetaData metadata = rs.getMetaData();
for (int i = 0; i < metadata.getColumnCount(); i++) { for (int i = 0; i < metadata.getColumnCount(); i++) {
values.add(getColumnValue(rs, metadata.getColumnType(i + 1), i + 1)); values.add(getColumnValue(rs, metadata.getColumnType(i + 1), i + 1, trim, dateFormatString, timeFormatString));
} }
String[] valueArray = new String[values.size()]; String[] valueArray = new String[values.size()];
return values.toArray(valueArray); return values.toArray(valueArray);
} }
private String handleObject(Object obj) {
return obj == null ? "" : String.valueOf(obj);
}
private String handleBigDecimal(BigDecimal decimal) {
return decimal == null ? "" : decimal.toString();
}
private String handleLong(ResultSet rs, int columnIndex) throws SQLException {
long lv = rs.getLong(columnIndex);
return rs.wasNull() ? "" : Long.toString(lv);
}
private String handleInteger(ResultSet rs, int columnIndex) throws SQLException {
int i = rs.getInt(columnIndex);
return rs.wasNull() ? "" : Integer.toString(i);
}
private String handleDate(ResultSet rs, int columnIndex) throws SQLException {
java.sql.Date date = rs.getDate(columnIndex);
String value = null;
if (date != null) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
value = dateFormat.format(date);
}
return value;
}
private String handleBinary(ResultSet rs, int colIndex) throws SQLException { private String handleBinary(ResultSet rs, int colIndex) throws SQLException {
byte[] bs = rs.getBytes(colIndex); byte[] bs = rs.getBytes(colIndex);
if (bs == null) { if (bs == null) {
return null; return null;
} }
if (bs.length == 16) { if (bs.length == 16) {
// UUID? // UUID?
UUID uuid = NumberUtils.toUUID(bs); UUID uuid = NumberUtils.toUUID(bs);
...@@ -94,16 +77,19 @@ public class CSVResultSetHelper extends ResultSetHelperService { ...@@ -94,16 +77,19 @@ public class CSVResultSetHelper extends ResultSetHelperService {
} }
} }
private String handleTime(Time time) { private static String read(Clob c) throws SQLException, IOException {
return time == null ? null : time.toString(); StringBuilder sb = new StringBuilder((int) c.length());
} Reader r = c.getCharacterStream();
char[] cbuf = new char[CLOBBUFFERSIZE];
private String handleTimestamp(Timestamp timestamp) { int n;
SimpleDateFormat timeFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss"); while ((n = r.read(cbuf, 0, cbuf.length)) != -1) {
return timestamp == null ? null : timeFormat.format(timestamp); sb.append(cbuf, 0, n);
}
return sb.toString();
} }
private String getColumnValue(ResultSet rs, int colType, int colIndex) throws SQLException, IOException { private String getColumnValue(ResultSet rs, int colType, int colIndex, boolean trim, String dateFormatString, String timestampFormatString)
throws SQLException, IOException {
String value = ""; String value = "";
...@@ -127,25 +113,29 @@ public class CSVResultSetHelper extends ResultSetHelperService { ...@@ -127,25 +113,29 @@ public class CSVResultSetHelper extends ResultSetHelperService {
value = handleLong(rs, colIndex); value = handleLong(rs, colIndex);
break; break;
case Types.DECIMAL: case Types.DECIMAL:
case Types.DOUBLE:
case Types.FLOAT:
case Types.REAL: case Types.REAL:
case Types.NUMERIC: case Types.NUMERIC:
value = handleBigDecimal(rs.getBigDecimal(colIndex)); value = handleBigDecimal(rs.getBigDecimal(colIndex));
break; break;
case Types.DOUBLE:
value = handleDouble(rs.getDouble(colIndex));
break;
case Types.FLOAT:
value = handleFloat(rs.getFloat(colIndex));
break;
case Types.INTEGER: case Types.INTEGER:
case Types.TINYINT: case Types.TINYINT:
case Types.SMALLINT: case Types.SMALLINT:
value = handleInteger(rs, colIndex); value = handleInteger(rs, colIndex);
break; break;
case Types.DATE: case Types.DATE:
value = handleDate(rs, colIndex); value = handleDate(rs, colIndex, dateFormatString);
break; break;
case Types.TIME: case Types.TIME:
value = handleTime(rs.getTime(colIndex)); value = handleTime(rs.getTime(colIndex));
break; break;
case Types.TIMESTAMP: case Types.TIMESTAMP:
value = handleTimestamp(rs.getTimestamp(colIndex)); value = handleTimestamp(rs.getTimestamp(colIndex), timestampFormatString);
break; break;
case NVARCHAR: // todo : use rs.getNString case NVARCHAR: // todo : use rs.getNString
case NCHAR: // todo : use rs.getNString case NCHAR: // todo : use rs.getNString
...@@ -153,13 +143,17 @@ public class CSVResultSetHelper extends ResultSetHelperService { ...@@ -153,13 +143,17 @@ public class CSVResultSetHelper extends ResultSetHelperService {
case Types.LONGVARCHAR: case Types.LONGVARCHAR:
case Types.VARCHAR: case Types.VARCHAR:
case Types.CHAR: case Types.CHAR:
value = rs.getString(colIndex); String columnValue = rs.getString(colIndex);
if (trim && columnValue != null) {
value = columnValue.trim();
} else {
value = columnValue;
}
break; break;
case Types.BINARY: case Types.BINARY:
value = handleBinary(rs, colIndex); value = handleBinary(rs, colIndex);
break; break;
default: default:
// System.err.println("SQLType not handled " + colType);
value = ""; value = "";
} }
...@@ -168,17 +162,5 @@ public class CSVResultSetHelper extends ResultSetHelperService { ...@@ -168,17 +162,5 @@ public class CSVResultSetHelper extends ResultSetHelperService {
} }
return value; return value;
}
private static String read(Clob c) throws SQLException, IOException {
StringBuilder sb = new StringBuilder((int) c.length());
Reader r = c.getCharacterStream();
char[] cbuf = new char[CLOBBUFFERSIZE];
int n;
while ((n = r.read(cbuf, 0, cbuf.length)) != -1) {
sb.append(cbuf, 0, n);
}
return sb.toString();
} }
} }
...@@ -119,9 +119,9 @@ import org.springframework.security.acls.domain.BasePermission; ...@@ -119,9 +119,9 @@ import org.springframework.security.acls.domain.BasePermission;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import au.com.bytecode.opencsv.CSVWriter; import com.opencsv.CSVWriter;
import au.com.bytecode.opencsv.ResultSetHelper; import com.opencsv.ResultSetHelper;
import au.com.bytecode.opencsv.ResultSetHelperService; import com.opencsv.ResultSetHelperService;
@Service @Service
@Transactional(readOnly = true) @Transactional(readOnly = true)
......
...@@ -37,7 +37,7 @@ import org.apache.http.impl.client.HttpClientBuilder; ...@@ -37,7 +37,7 @@ import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import au.com.bytecode.opencsv.CSVReader; import com.opencsv.CSVReader;
/** /**
* Fetch and parse country information from * Fetch and parse country information from
......
...@@ -43,7 +43,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -43,7 +43,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor; import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import au.com.bytecode.opencsv.CSVReader; import com.opencsv.CSVReader;
/** /**
* Update country ITPGRFA status by fetching data from * Update country ITPGRFA status by fetching data from
......
...@@ -46,7 +46,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -46,7 +46,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor; import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import au.com.bytecode.opencsv.CSVReader; import com.opencsv.CSVReader;
@Component @Component
public class InstituteUpdater { public class InstituteUpdater {
...@@ -225,12 +225,6 @@ public class InstituteUpdater { ...@@ -225,12 +225,6 @@ public class InstituteUpdater {
LOG.info("Updating FaoInstitutes: " + toSave.size()); LOG.info("Updating FaoInstitutes: " + toSave.size());
instituteService.update(toSave); instituteService.update(toSave);
} }
// try {
// Thread.sleep(2000);
// } catch (final InterruptedException e) {
// LOG.warn(e.getMessage());
// }
} }
private FaoInstitute insertData(String[] line) { private FaoInstitute insertData(String[] line) {
...@@ -267,7 +261,9 @@ public class InstituteUpdater { ...@@ -267,7 +261,9 @@ public class InstituteUpdater {
} }
faoInstitute.setAcronym(acronym); faoInstitute.setAcronym(acronym);
faoInstitute.setFullName(fullName); faoInstitute.setFullName(fullName);
LOG.info("Updating: " + instCode + " " + fullName); if (LOG.isTraceEnabled()) {
LOG.trace("Updating: code=" + instCode + " fullname='" + fullName + "' acronym=" + acronym);
}
faoInstitute.setPgrActivity(pgrActivity); faoInstitute.setPgrActivity(pgrActivity);
faoInstitute.setMaintainsCollection(maintColl); faoInstitute.setMaintainsCollection(maintColl);
faoInstitute.setEmail(email); faoInstitute.setEmail(email);
......
...@@ -38,8 +38,6 @@ import org.genesys2.server.model.genesys.Accession; ...@@ -38,8 +38,6 @@ import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.SvalbardData; import org.genesys2.server.model.genesys.SvalbardData;
import org.genesys2.server.persistence.domain.SvalbardRepository; import org.genesys2.server.persistence.domain.SvalbardRepository;
import org.genesys2.server.service.GenesysService; import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.TaxonomyService;
import org.hibernate.exception.ConstraintViolationException; import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor; import org.springframework.core.task.TaskExecutor;
...@@ -47,7 +45,7 @@ import org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureExcep ...@@ -47,7 +45,7 @@ import org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureExcep
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import au.com.bytecode.opencsv.CSVReader; import com.opencsv.CSVReader;
@Component @Component
public class SGSVUpdate { public class SGSVUpdate {
...@@ -71,12 +69,6 @@ public class SGSVUpdate { ...@@ -71,12 +69,6 @@ public class SGSVUpdate {
@Autowired @Autowired
private GenesysService genesysService; private GenesysService genesysService;
@Autowired
private TaxonomyService taxonomyService;
@Autowired
private GeoService geoService;
@Autowired @Autowired
private SvalbardRepository svalbardRepository; private SvalbardRepository svalbardRepository;
......
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