This is an automated email from the git hooks/post-receive script. New commit to branch feature/6688 in repository tutti. See http://git.codelutin.com/tutti.git commit 7e02fa99ab963f66edf3d5bd457fa0317e56e5ef Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Feb 25 19:26:46 2015 +0100 count file lines --- .../genericformat/GenericFormatArchive.java | 203 ++++++++++++++------- 1 file changed, 135 insertions(+), 68 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatArchive.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatArchive.java index 3ea7e5f..4bf7e08 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatArchive.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatArchive.java @@ -19,6 +19,7 @@ import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; +import java.util.EnumMap; import java.util.EnumSet; import java.util.List; import java.util.zip.ZipEntry; @@ -89,6 +90,10 @@ public class GenericFormatArchive implements Serializable { private final String prefixPath; + private final EnumMap<ArchiveFilePath, Integer> countLines; + + private final EnumSet<ArchiveFilePath> missingPaths; + public static GenericFormatArchive forImport(File archiveFile, File tempDirectory) { try { @@ -208,6 +213,59 @@ public class GenericFormatArchive implements Serializable { return getPath(ArchiveFilePath.DATA_MARINE_LITTER); } + public int getSurveyLineCount() { + return countImportLines(ArchiveFilePath.DATA_SURVEY); + } + + public int getGearCaracteristicsPathLineCount() { + return countImportLines(ArchiveFilePath.DATA_GEAR_CARACTERISTIC); + } + + public int getOperationPathLineCount() { + return countImportLines(ArchiveFilePath.DATA_OPERATION); + } + + public int getIndividualObservationPathLineCount() { + return countImportLines(ArchiveFilePath.DATA_INDIVIDUAL_OBSERVATION); + } + + public int getSpeciesPathLineCount() { + return countImportLines(ArchiveFilePath.DATA_SPECIES); + } + + public int getCatchPathLineCount() { + return countImportLines(ArchiveFilePath.DATA_CATCH); + } + + public int getAccidentalCatchPathLineCount() { + return countImportLines(ArchiveFilePath.DATA_ACCIDENTAL_CATCH); + } + + public int getParameterPathLineCount() { + return countImportLines(ArchiveFilePath.DATA_PARAMETER); + } + + public int getMarineLitterPathLineCount() { + return countImportLines(ArchiveFilePath.DATA_MARINE_LITTER); + } + + public int getTemporaryReferentialGearLineCount() { + return countImportLines(ArchiveFilePath.REFERENTIAL_GEAR); + } + + public int getTemporaryReferentialPersonLineCount() { + return countImportLines(ArchiveFilePath.REFERENTIAL_PERSON); + } + + public int getTemporaryReferentialSpeciesLineCount() { + return countImportLines(ArchiveFilePath.REFERENTIAL_SPECIES); + } + + public int getTemporaryReferentialVesselLineCount() { + return countImportLines(ArchiveFilePath.REFERENTIAL_VESSEL); + } + + public void validateArchiveLayout() throws GenericFormatArchiveInvalidLayoutException { List<String> errors = new ArrayList<>(); @@ -257,25 +315,6 @@ public class GenericFormatArchive implements Serializable { } - public int countImportLines(Path path) { - - try (BufferedReader bufferedReader = Files.newBufferedReader(path, Charset.forName("UTF-8"))) { - - try (LineNumberReader lineNumberReader = new LineNumberReader(bufferedReader)) { - lineNumberReader.skip(Long.MAX_VALUE); - int result = lineNumberReader.getLineNumber() - 1; - if (result == -1) { - result = 0; - } - return result; - } - - } catch (IOException e) { - throw new ApplicationTechnicalException("Could not read " + path.toFile().getName() + " file from archive " + archiveFile, e); - } - - } - public void createZip(ProgressionModel progressionModel) { if (progressionModel != null) { @@ -288,60 +327,12 @@ public class GenericFormatArchive implements Serializable { } - protected Path getPath(ArchiveFilePath archiveFilePath) { - - String filename = archiveFilePath.getFilename(); - - Path file = workingDirectory.toPath().resolve(filename); - - if (isImport() && Files.notExists(file) && !missingPaths.contains(archiveFilePath)) { - - // Explode from archive - - try (ZipFile zipFile = new ZipFile(archiveFile)) { - - String zipEntryPath = getZipEntryPath(archiveFilePath); - ZipEntry entry = zipFile.getEntry(zipEntryPath); - - Preconditions.checkState(!(archiveFilePath.isMandatory() && entry == null), "Must have entry " + filename); - - if (entry != null) { - - if (log.isInfoEnabled()) { - log.info("Explode zip entry to " + file.toFile().getName()); - } - - try (InputStream inputStream = zipFile.getInputStream(entry)) { - Files.copy(inputStream, file); - } - - } - - } catch (IOException e) { - throw new ApplicationTechnicalException("Could not open zip file: " + archiveFile, e); - } - - } - - return file; - - } - - protected boolean isImport() { - return ArchiveMode.IMPORT == archiveMode; - } - - protected boolean isExport() { - return ArchiveMode.EXPORT == archiveMode; - } - - protected final EnumSet<ArchiveFilePath> missingPaths; - protected GenericFormatArchive(ArchiveMode archiveMode, File archiveFile, File workingDirectory) { this.archiveFile = archiveFile; this.workingDirectory = workingDirectory; this.archiveMode = archiveMode; + this.countLines = new EnumMap<>(ArchiveFilePath.class); if (log.isInfoEnabled()) { log.info("Archive zip file: " + archiveFile); @@ -363,6 +354,14 @@ public class GenericFormatArchive implements Serializable { } + protected boolean isImport() { + return ArchiveMode.IMPORT == archiveMode; + } + + protected boolean isExport() { + return ArchiveMode.EXPORT == archiveMode; + } + protected String extractPrefixPath() { FileObject fileObject = ApplicationIOUtil.resolveFile( @@ -380,6 +379,45 @@ public class GenericFormatArchive implements Serializable { } + protected Path getPath(ArchiveFilePath archiveFilePath) { + + String filename = archiveFilePath.getFilename(); + + Path file = workingDirectory.toPath().resolve(filename); + + if (isImport() && Files.notExists(file) && !missingPaths.contains(archiveFilePath)) { + + // Explode from archive + + try (ZipFile zipFile = new ZipFile(archiveFile)) { + + String zipEntryPath = getZipEntryPath(archiveFilePath); + ZipEntry entry = zipFile.getEntry(zipEntryPath); + + Preconditions.checkState(!(archiveFilePath.isMandatory() && entry == null), "Must have entry " + filename); + + if (entry != null) { + + if (log.isInfoEnabled()) { + log.info("Explode zip entry to " + file.toFile().getName()); + } + + try (InputStream inputStream = zipFile.getInputStream(entry)) { + Files.copy(inputStream, file); + } + + } + + } catch (IOException e) { + throw new ApplicationTechnicalException("Could not open zip file: " + archiveFile, e); + } + + } + + return file; + + } + protected String getZipEntryPath(ArchiveFilePath archiveFilePath) { String path = prefixPath + archiveFilePath.getFilename(); @@ -433,4 +471,33 @@ public class GenericFormatArchive implements Serializable { return result; } + protected int countImportLines(ArchiveFilePath archiveFilePath) { + + Integer result = countLines.get(archiveFilePath); + if (result == null) { + + Path path = getPath(archiveFilePath); + + try (BufferedReader bufferedReader = Files.newBufferedReader(path, Charset.forName("UTF-8"))) { + + try (LineNumberReader lineNumberReader = new LineNumberReader(bufferedReader)) { + lineNumberReader.skip(Long.MAX_VALUE); + result = lineNumberReader.getLineNumber() - 1; + if (result == -1) { + result = 0; + } + countLines.put(archiveFilePath, result); + + } + + } catch (IOException e) { + throw new ApplicationTechnicalException("Could not read " + path.toFile().getName() + " file from archive " + archiveFile, e); + } + + } + + return result; + + } + } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.