001/*
002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Thomas Roger
016 */
017
018package org.nuxeo.ecm.csv;
019
020import java.util.List;
021
022/**
023 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
024 * @since 5.7
025 */
026public class CSVImportResult {
027
028    protected final long totalLineCount;
029
030    protected final long successLineCount;
031
032    protected final long skippedLineCount;
033
034    protected final long errorLineCount;
035
036    public static final CSVImportResult fromImportLogs(List<CSVImportLog> importLogs) {
037        long totalLineCount = importLogs.size();
038        long successLineCount = 0;
039        long skippedLineCount = 0;
040        long errorLineCount = 0;
041        for (CSVImportLog importLog : importLogs) {
042            if (importLog.isSuccess()) {
043                successLineCount++;
044            } else if (importLog.isSkipped()) {
045                skippedLineCount++;
046            } else if (importLog.isError()) {
047                errorLineCount++;
048            }
049        }
050        return new CSVImportResult(totalLineCount, successLineCount, skippedLineCount, errorLineCount);
051    }
052
053    public CSVImportResult(long totalLineCount, long successLineCount, long skippedLineCount, long errorLineCount) {
054        this.totalLineCount = totalLineCount;
055        this.successLineCount = successLineCount;
056        this.skippedLineCount = skippedLineCount;
057        this.errorLineCount = errorLineCount;
058    }
059
060    public long getTotalLineCount() {
061        return totalLineCount;
062    }
063
064    public long getSuccessLineCount() {
065        return successLineCount;
066    }
067
068    public long getSkippedLineCount() {
069        return skippedLineCount;
070    }
071
072    public long getErrorLineCount() {
073        return errorLineCount;
074    }
075}