001/*
002 * #%L
003 * Netarchivesuite - archive
004 * %%
005 * Copyright (C) 2005 - 2014 The Royal Danish Library, the Danish State and University Library,
006 *             the National Library of France and the Austrian National Library.
007 * %%
008 * This program is free software: you can redistribute it and/or modify
009 * it under the terms of the GNU Lesser General Public License as
010 * published by the Free Software Foundation, either version 2.1 of the
011 * License, or (at your option) any later version.
012 * 
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Lesser Public License for more details.
017 * 
018 * You should have received a copy of the GNU General Lesser Public
019 * License along with this program.  If not, see
020 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
021 * #L%
022 */
023package dk.netarkivet.archive.arcrepositoryadmin;
024
025import java.sql.Date;
026import java.sql.ResultSet;
027import java.sql.SQLException;
028
029import dk.netarkivet.common.distribute.arcrepository.ReplicaStoreState;
030import dk.netarkivet.common.exceptions.ArgumentNotValid;
031
032/**
033 * This is a container for the ReplicaFileInfo table in the bitpreservation database.
034 */
035public class ReplicaFileInfo {
036    /** The guid. Unique identification key. */
037    private long guid;
038    /** The replicaId. The identification of the replica. */
039    private String replicaId;
040    /** The id of the file in the file table. */
041    private long fileId;
042    /** The id of the segment in the segment. */
043    private long segmentId;
044    /** The checksum of the file in the segment within the replica. */
045    private String checksum;
046    /** The uploadstatus. */
047    private ReplicaStoreState uploadStatus;
048    /** The filelist status. */
049    private FileListStatus filelistStatus;
050    /** The checksum status. */
051    private ChecksumStatus checksumStatus;
052    /** The date for the last filelist update of the entry. */
053    private Date filelistCheckdatetime;
054    /** The date for the last checksum update of the entry. */
055    private Date checksumCheckdatetime;
056
057    /**
058     * Constructor.
059     *
060     * @param gId The guid.
061     * @param rId The replicaId.
062     * @param fId The fileId.
063     * @param sId the segmentId.
064     * @param cs The checksum.
065     * @param us The uploadstatus.
066     * @param fs The fileliststatus.
067     * @param css The checksumstatus.
068     * @param fDate The date for the last filelist update.
069     * @param cDate The date for the last checksum update.
070     * @throws ArgumentNotValid If gId or fId is negative, the rId is either null or the empty string. The other
071     * variables are not validated, since they are allowed to be null (e.g. the dates before they are updated).
072     */
073    public ReplicaFileInfo(long gId, String rId, long fId, long sId, String cs, int us, int fs, int css, Date fDate,
074            Date cDate) throws ArgumentNotValid {
075        ArgumentNotValid.checkNotNegative(gId, "long gId");
076        ArgumentNotValid.checkNotNullOrEmpty(rId, "String rId");
077        ArgumentNotValid.checkNotNegative(fId, "long fId");
078
079        this.guid = gId;
080        this.replicaId = rId;
081        this.fileId = fId;
082        this.segmentId = sId;
083        this.checksum = cs;
084        this.uploadStatus = ReplicaStoreState.fromOrdinal(us);
085        this.filelistStatus = FileListStatus.fromOrdinal(fs);
086        this.checksumStatus = ChecksumStatus.fromOrdinal(css);
087        this.filelistCheckdatetime = fDate;
088        this.checksumCheckdatetime = cDate;
089    }
090
091    public ReplicaFileInfo(ResultSet res) throws SQLException {
092        this(res.getLong(1), res.getString(2), res.getLong(3), res.getLong(4), res.getString(5), res.getInt(6), res
093                .getInt(7), res.getInt(8), res.getDate(9), res.getDate(10));
094    }
095
096    /**
097     * Retrieves this object as as a string. Contains all the variables.
098     *
099     * @return A string representing this object.
100     */
101    public String toString() {
102        return guid + ":" + replicaId + ":" + fileId + ":" + segmentId + ":" + checksum + ":" + uploadStatus + ":"
103                + filelistStatus + ":" + filelistCheckdatetime + ":" + checksumCheckdatetime;
104    }
105
106    /**
107     * Retrieves the guid.
108     *
109     * @return The guid.
110     */
111    public long getGuid() {
112        return guid;
113    }
114
115    /**
116     * Retrieves the replicaId.
117     *
118     * @return The replicaId.
119     */
120    public String getReplicaId() {
121        return replicaId;
122    }
123
124    /**
125     * Retrieves the fileId.
126     *
127     * @return The fileId.
128     */
129    public long getFileId() {
130        return fileId;
131    }
132
133    /**
134     * Retrieves the segmentId.
135     *
136     * @return The segmentId.
137     */
138    public long getSegmentId() {
139        return segmentId;
140    }
141
142    /**
143     * Retrieves the checksum.
144     *
145     * @return The checksum.
146     */
147    public String getChecksum() {
148        return checksum;
149    }
150
151    /**
152     * Retrieves the uploadState.
153     *
154     * @return The uploadState.
155     */
156    public ReplicaStoreState getUploadState() {
157        return uploadStatus;
158    }
159
160    /**
161     * Retrieves the filelistStatus.
162     *
163     * @return The filelistStatus.
164     */
165    public FileListStatus getFileListState() {
166        return filelistStatus;
167    }
168
169    /**
170     * Retrieves the checksumStatus.
171     *
172     * @return The checksumStatus.
173     */
174    public ChecksumStatus getChecksumStatus() {
175        return checksumStatus;
176    }
177
178    /**
179     * Retrieves the filelistCheckdatetime.
180     *
181     * @return The filelistCheckdatetime.
182     */
183    public Date getFileListCheckDateTime() {
184        return filelistCheckdatetime;
185    }
186
187    /**
188     * Retrieves the checksumCheckDatetime.
189     *
190     * @return The checksumCheckDateTime.
191     */
192    public Date getChecksumCheckdatetime() {
193        return checksumCheckdatetime;
194    }
195}