001/*
002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Thomas Roger
018 */
019
020package org.nuxeo.ecm.csv.core;
021
022import java.io.Serializable;
023import java.util.List;
024
025/**
026 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
027 * @since 5.7
028 */
029public class CSVImportResult implements Serializable {
030
031    private static final long serialVersionUID = 1L;
032
033    protected final long totalLineCount;
034
035    protected final long successLineCount;
036
037    protected final long skippedLineCount;
038
039    protected final long errorLineCount;
040
041    public static final CSVImportResult fromImportLogs(List<CSVImportLog> importLogs) {
042        long totalLineCount = importLogs.size();
043        long successLineCount = 0;
044        long skippedLineCount = 0;
045        long errorLineCount = 0;
046        for (CSVImportLog importLog : importLogs) {
047            if (importLog.isSuccess()) {
048                successLineCount++;
049            } else if (importLog.isSkipped()) {
050                skippedLineCount++;
051            } else if (importLog.isError()) {
052                errorLineCount++;
053            }
054        }
055        return new CSVImportResult(totalLineCount, successLineCount, skippedLineCount, errorLineCount);
056    }
057
058    public CSVImportResult(long totalLineCount, long successLineCount, long skippedLineCount, long errorLineCount) {
059        this.totalLineCount = totalLineCount;
060        this.successLineCount = successLineCount;
061        this.skippedLineCount = skippedLineCount;
062        this.errorLineCount = errorLineCount;
063    }
064
065    public long getTotalLineCount() {
066        return totalLineCount;
067    }
068
069    public long getSuccessLineCount() {
070        return successLineCount;
071    }
072
073    public long getSkippedLineCount() {
074        return skippedLineCount;
075    }
076
077    public long getErrorLineCount() {
078        return errorLineCount;
079    }
080}