Skip to content

Commit

Permalink
Merge pull request #278 from nicolas-f/fixparse2
Browse files Browse the repository at this point in the history
About #277 handle corrupted zip
  • Loading branch information
nicolas-f authored Jun 12, 2018
2 parents 70dc204 + 114f4ec commit c3fd406
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ onomap-geoserver/geoserver/build
*.bak
onomap-geoserver/geoserver/data_dir
gradle.properties
onomap-geoserver/geoserver/out/

Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@

package org.noise_planet.noisecapturegs

import geoserver.GeoServer
import geoserver.catalog.Store
import groovy.json.JsonSlurper
import groovy.sql.GroovyRowResult
import groovy.sql.Sql
import groovy.lang.MissingPropertyException
import geoserver.GeoServer
import org.apache.commons.lang.StringEscapeUtils
import org.codehaus.groovy.runtime.StackTraceUtils
import org.geotools.jdbc.JDBCDataStore
Expand All @@ -44,7 +43,6 @@ import java.security.InvalidParameterException
import java.sql.Connection
import java.sql.DriverManager
import java.sql.SQLException
import java.sql.Timestamp
import java.time.Instant
import java.time.ZoneId
import java.time.format.DateTimeFormatter
Expand Down Expand Up @@ -317,15 +315,15 @@ def static void buildStatistics(Connection connection, Integer pkParty) {
connection.setAutoCommit(true)
}

def static int processFiles(Connection connection, File[] files, int processFileLimit, boolean moveFiles) {
def static int processFiles(Connection connection, File[] files, int processFileLimit, boolean writeFiles) {
Logger logger = LoggerFactory.getLogger("logger_nc_parse")
int processed = 0
Set<Integer> partyIds = new HashSet<>();
for (File zipFile : files) {
Map trackData = [uuid: '00000000-0000-0000-0000-000000000000']
try {
partyIds.add(processFile(connection, zipFile, trackData, false))
} catch (SQLException|InvalidParameterException|MissingPropertyException ex) {
} catch (SQLException|InvalidParameterException|MissingPropertyException|IOException ex) {
// Log error
logger.error(zipFile.getName() + " Message: " + ex.getMessage(), StackTraceUtils.sanitize(new Exception(ex)))
if(ex instanceof SQLException) {
Expand All @@ -341,12 +339,14 @@ def static int processFiles(Connection connection, File[] files, int processFile
t = t.getCause()
}
// Log track in error
new File("data_dir/onomap_archive", "track_exception.csv") << zipFile.getName() << "," << StringEscapeUtils.escapeCsv(ex.getMessage()) << "\n"
if(writeFiles) {
new File("data_dir/onomap_archive", "track_exception.csv") << zipFile.getName() << "," << StringEscapeUtils.escapeCsv(ex.getMessage()) << "\n"
}
// Cancel transaction
connection.rollback()
}
// Move file to processed folder
if(moveFiles) {
if(writeFiles) {
File processedDir = new File("data_dir/onomap_archive", trackData.uuid.substring(0, 2))
processedDir = new File(processedDir, trackData.uuid.substring(2, 4))
processedDir = new File(processedDir, trackData.uuid.substring(4, 6))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,17 @@ class TestNoiseCaptureParse extends GroovyTestCase {
def result = sql.firstRow("SELECT tag FROM noisecapture_track nt, noisecapture_party np where nt.pk_party = np.pk_party and nt.pk_track = :pktrack",[pktrack:idtrack])
assertEquals("UDC", result.tag)
}

void testFileCorrupt() {
Statement st = connection.createStatement()
// Load timezone file
st.execute("CALL FILE_TABLE('"+TestNoiseCaptureProcess.getResource("tz_world.shp").file+"', 'TZ_WORLD');")
st.execute("CREATE SPATIAL INDEX ON TZ_WORLD(THE_GEOM)")
// ut_deps has been derived from https://www.data.gouv.fr/fr/datasets/contours-des-departements-francais-issus-d-openstreetmap/ (c) osm
// See ut_deps.txt for more details
st.execute("CALL GEOJSONREAD('"+TestNoiseCaptureProcess.getResource("ut_deps.geojson").file+"', 'GADM28');")

assertEquals(1, new nc_parse().processFiles(connection, [new File(TestNoiseCaptureParse.getResource("track_00a20ba7-35f7-4ac4-923b-9d43dd5348b8.zip").file)] as File[],
0, false))
}
}
Binary file not shown.

0 comments on commit c3fd406

Please sign in to comment.