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;
023
024/**
025 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
026 * @since 5.7
027 */
028public class CSVImportStatus implements Serializable {
029
030    public enum State {
031        SCHEDULED, RUNNING, COMPLETED,
032        /**
033         * @since 9.1
034         */
035        ERROR
036    }
037
038    private static final long serialVersionUID = 1L;
039
040    private final State state;
041
042    /**
043     * @deprecated since 9.1
044     */
045    @Deprecated
046    private int positionInQueue;
047
048    @Deprecated
049    /**
050     * @deprecated since 9.1
051     */
052    private int queueSize;
053
054    private long totalNumberOfDocument;
055
056    private long numberOfProcessedDocument;
057
058    public CSVImportStatus(State state) {
059        this(state, -1L, -1L);
060    }
061
062    /**
063     * @deprecated since 9.1
064     */
065    @Deprecated
066    public CSVImportStatus(State state, int positionInQueue, int queueSize) {
067        this.state = state;
068        this.positionInQueue = positionInQueue;
069        this.queueSize = queueSize;
070    }
071
072    public CSVImportStatus(State state, long numberOfProcessedDocument, long totalNumberOfDocument) {
073        this.state = state;
074        this.numberOfProcessedDocument = numberOfProcessedDocument;
075        this.totalNumberOfDocument = totalNumberOfDocument;
076    }
077
078    /**
079     * @since 9.1
080     */
081    public long getNumberOfProcessedDocument() {
082        return numberOfProcessedDocument;
083    }
084
085    /**
086     * @deprecated since 9.1, meaningless use {@link #getNumberOfProcessedDocument()} instead.
087     */
088    @Deprecated
089    public int getPositionInQueue() {
090        return positionInQueue;
091    }
092
093    /**
094     * @deprecated since 9.1, meaningless use {@link #getTotalNumberOfDocument()} instead.
095     */
096    @Deprecated
097    public int getQueueSize() {
098        return queueSize;
099    }
100
101    public State getState() {
102        return state;
103    }
104
105    /**
106     * @since 9.1
107     */
108    public long getTotalNumberOfDocument() {
109        return totalNumberOfDocument;
110    }
111
112    public boolean isComplete() {
113        return state == State.COMPLETED;
114    }
115
116    public boolean isRunning() {
117        return state == State.RUNNING;
118    }
119
120    public boolean isScheduled() {
121        return state == State.SCHEDULED;
122    }
123}