View Javadoc

1   /*
2    * #%L
3    * Bitrepository Integrity Client
4    * *
5    * $Id$
6    * $HeadURL$
7    * %%
8    * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark
9    * %%
10   * This program is free software: you can redistribute it and/or modify
11   * it under the terms of the GNU Lesser General Public License as 
12   * published by the Free Software Foundation, either version 2.1 of the 
13   * License, or (at your option) any later version.
14   * 
15   * This program is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   * GNU General Lesser Public License for more details.
19   * 
20   * You should have received a copy of the GNU General Lesser Public 
21   * License along with this program.  If not, see
22   * <http://www.gnu.org/licenses/lgpl-2.1.html>.
23   * #L%
24   */
25  package org.bitrepository.integrityservice.cache;
26  
27  import java.util.Collection;
28  import java.util.Date;
29  import java.util.List;
30  
31  import org.bitrepository.bitrepositoryelements.ChecksumDataForChecksumSpecTYPE;
32  import org.bitrepository.bitrepositoryelements.FileIDsData;
33  import org.bitrepository.integrityservice.cache.database.IntegrityIssueIterator;
34  
35  /**
36   * Store of cached integrity information.
37   */
38  public interface IntegrityModel {
39      /**
40       * Add file ID data to cache.
41       * @param data The received data.
42       * @param pillarId The id of the pillar the received data comes from.
43       * @param collectionId The id of the collection the received data belongs to.
44       */
45      void addFileIDs(FileIDsData data, String pillarId, String collectionId);
46  
47      /**
48       * Add checksum data to cache.
49       * @param data The received data.
50       * @param pillarId The id of the pillar the received data comes from.
51       * @param collectionId The id of the collection the received data belongs to.
52       */
53      void addChecksums(List<ChecksumDataForChecksumSpecTYPE> data, String pillarId, String collectionId);
54  
55      /**
56       * Retrieves the information of a given file id for all pillars.
57       * @param fileId The id of the file. 
58       * @param collectionId The id of the collection the file belongs to
59       * @return The collection of information about this file.
60       */
61      Collection<FileInfo> getFileInfos(String fileId, String collectionId);
62      
63      /**
64       * Retrieves all the file ids in the collection.
65       * @param collectiondId The ID of the collection from which to get all fileIDs
66       * @return The collection of file ids.
67       */
68      Collection<String> getAllFileIDs(String collectionId);
69      
70      /**
71       * Retrieves the number of files in a collection
72       * @param collectionId The ID of the collection
73       * @return The number of files in the collection
74       */
75      long getNumberOfFilesInCollection(String collectionId);
76      
77      /**
78       * Retrieves the number of files on a pillar in a collection
79       * @param pillarId The pillar.
80       * @param collectionId The ID of the collection to get the number of files from
81       * @return Retrieves the number of files in the state 'EXISTING' or 'PREVIOUSLY_SEEN' at a given pillar.
82       */
83      long getNumberOfFiles(String pillarId, String collectionId);
84      
85      /**
86       * A list of files for a given pillar, restricted by min and max ids.
87       * @param pillarId The id of the pillar.
88       * @param minId The minimum result number.
89       * @param maxId The maximum result number.
90       * @param collectionId The ID of the collection to get files from
91       * @return The list of file ids for the pillar, between min and max.
92       */
93      List<String> getFilesOnPillar(String pillarId, long minId, long maxId, String collectionId);
94      
95      /**
96       * @param pillarId The pillar.
97       * @param collectionId The collection to look for missing files in
98       * @return Retrieves the number of files in the state 'MISSING' at a given pillar.
99       */
100     long getNumberOfMissingFiles(String pillarId, String collectionId);
101     
102     /**
103      * An IntegrityIssueIterator for missing files for a given pillar, restricted by min and max ids.
104      * @param pillarId The id of the pillar.
105      * @param minId The minimum result number.
106      * @param maxId The maximum result number.
107      * @param collectionId The ID of the collection to get missing files from
108      * @return The IntegrityIssueIterator for missing file ids for the pillar, between min and max.
109      */
110     IntegrityIssueIterator getMissingFilesAtPillarByIterator(String pillarId, long minId, long maxId, 
111             String collectionId);
112     
113     /**
114      * @param pillarId The pillar.
115      * @param collectionId The ID of the collection to look for checksum errors in
116      * @return The number of files with checksum state 'ERROR' for the given pillar.
117      */
118     long getNumberOfChecksumErrors(String pillarId, String collectionId);
119     
120     
121     /**
122      * A list of files with checksum error for a given pillar, restricted by min and max ids.
123      * @param pillarId The id of the pillar.
124      * @param minId The minimum result number.
125      * @param maxId The maximum result number.
126      * @param collectionId The ID of the collection to get checksum errors from
127      * @return The list of ids for the files with checksum errors for the pillar, between min and max.
128      */
129     List<String> getFilesWithChecksumErrorsAtPillar(String pillarId, long minId, long maxId, String collectionId);
130 
131     /**
132      * Sets the file to be missing at the given pillars.
133      * @param fileId The id of the file, which is missing at some pillars.
134      * @param pillarIds The ids of the pillars, where the file is missing.
135      * @param collectionId The ID of the collection where the file belongs
136      */
137     void setFileMissing(String fileId, Collection<String> pillarIds, String collectionId);
138     
139     /**
140      * Sets the checksum state of the file to be erroneous at the given pillars.
141      * @param fileId The id of the file, which has erroneous checksum at some pillars.
142      * @param pillarIds The ids of the pillars, where the file has a erroneous checksum.
143      * @param collectionId The ID of the collection where the file belongs
144      */
145     void setChecksumError(String fileId, Collection<String> pillarIds, String collectionId);
146     
147     /**
148      * Sets the checksum state of the file to be valid at the given pillars.
149      * @param fileId The id of the file, which has valid checksum at some pillars.
150      * @param pillarIds The ids of the pillars, where the file has a valid checksum.
151      * @param collectionId The ID of the collection that the file belongs to
152      */
153     void setChecksumAgreement(String fileId, Collection<String> pillarIds, String collectionId);
154     
155     /**
156      * Removes a given file id from the cache.
157      * @param fileId The id of the file to be removed from cache.
158      * @param collectionId The id of the collection the file belongs to.
159      */
160     void deleteFileIdEntry(String fileId, String collectionId);
161     
162     /**
163      * Locates the files which exists but are missing their checksum at any pillar.
164      * @param collectionId The collection in which to look for missing checksums
165      * @return The list of file ids for the files which exists but are missing their checksum at any pillar.
166      */
167     List<String> findMissingChecksums(String collectionId);
168     
169     /**
170      * Locates the id of all the files which are older than a given date.
171      * @param date The date for the checksum to be old than.
172      * @param pillarID The pillar to get checksums from
173      * @param collectionId The collection to where the files belong
174      * @return The list of ids for the files which have an old checksum.
175      */
176     Collection<String> findChecksumsOlderThan(Date date, String pillarID, String collectionId);
177     
178     /**
179      * Locates the files which are missing at any pillar.
180      * @param collectionId The ID of the collection in which to search for missing files
181      * @return The list of file ids for the files which are missing at any pillar.
182      */
183     List<String> findMissingFiles(String collectionId);
184     
185     /**
186      * Finds orphan files within a collection, i.e. files that no longer exists on any pillar
187      * @param collectionId, The ID of the collection in which to find orphan files.
188      * @return The list of orphan files   
189      */
190     List<String> findOrphanFiles(String collectionID);
191     
192     /**
193      * Checks whether a given file is missing and returns the list of pillars, where it is missing.
194      * @param fileId The id of the file to check whether it is missing.
195      * @param collectiondId The ID of the collection where the file belongs
196      * @return The list of pillars where it is missing (empty list, if not missing at any pillar).
197      */
198     List<String> getPillarsMissingFile(String fileId, String collectionId);
199     
200     /**
201      * Retrieves the list of file ids for the files, where the pillars does not agree about the checksums.
202      * @param The ID of the collection in which to get files from.
203      * @return The list of file ids for the files with distinct checksums.
204      */
205     List<String> getFilesWithInconsistentChecksums(String collectionId);
206     
207     /**
208      * Set the checksum state of a file to 'valid' its entries if the different checksums are unanimous.
209      * @param collectionId The ID of the collection in which to change the state
210      */
211     void setFilesWithConsistentChecksumToValid(String collectionId);
212     
213     /**
214      * Set the file state of all files to 'unknown'.
215      * @param collectionId The ID of the collection to work on.
216      */
217     void setExistingFilesToPreviouslySeenFileState(String collectionId);
218 
219     /**
220      * Set the file state of all unknown files to 'missing' if the file-date is newer than the grace period.
221      * @param collectionId The ID of the collection to work on
222      */
223     void setOldUnknownFilesToMissing(String collectionId);
224     
225     /**
226      * Set the file state of all 'PreviouslySeen' files to 'missing'.
227      * @param collectionId
228      */
229     void setPreviouslySeenFilesToMissing(String collectionId);
230     
231     /**
232      * Set the file state of all 'PreviouslySeen' files of a given pillar to 'existing'.
233      * This is to be used when a is not responding during a update of the filelist.
234      * @param collectionId The id of the collection.
235      * @param pillar The id of the pillar.
236      */
237     void setPreviouslySeenToExisting(String collectionId, String pillarId);
238 
239     /**
240      * @param fileId The id of the file.
241      * @param collectionId The id of the collection.
242      * @return Whether the given file is within the given collection.
243      */
244     boolean hasFile(String fileId, String collectionId);
245     
246     /**
247      * Retrieves the date for the latest file entry for a given collection.
248      * E.g. the date for the latest file which has been positively identified as existing in the collection.  
249      * @param collectionId The ID of the collection to look in
250      * @return The requested date.
251      */
252      Date getDateForNewestFileEntryForCollection(String collectionId);
253     
254     /**
255      * Retrieves the date for the latest file entry for a given pillar.
256      * E.g. the date for the latest file which has been positively identified as existing on the given pillar.  
257      * @param pillarId The pillar whose latest file entry is requested.
258      * @param collectionId The ID of the collection to look in
259      * @return The requested date.
260      */
261     Date getDateForNewestFileEntryForPillar(String pillarId, String collectionId);
262     
263     /**
264      * Retrieves the date for the latest checksum entry for a given pillar.
265      * E.g. the date for the latest checksum which has been positively identified as valid on the given pillar.  
266      * @param pillarId The pillar whose latest checksum entry is requested.
267      * @param collectionId The ID of the collection to look in
268      * @return The requested date.
269      */
270     Date getDateForNewestChecksumEntryForPillar(String pillarId, String collectionId);
271 
272     /**
273      * Retrieves the accumulated size of the files in the given collection
274      * @param collectionId The ID of the collection
275      * @return The accumulated size of the files in the collection.
276      */
277     Long getCollectionFileSize(String collectionId);
278     
279     /**
280      * Retrieves the accumulated data size of the files on a given pillar
281      * @param pillarID The ID of the pillar
282      * @return The accumulated data size for the pillar
283      */
284     Long getPillarDataSize(String pillarID);
285     
286     /**
287      *  Retrieves the latest collection statistics for the given collection
288      *  @param collectionID The ID of the collection
289      *  @return {@link CollectionStat} The latest collection statistics object for the collection
290      */
291     List<CollectionStat> getLatestCollectionStat(String collectionID, int count);
292     
293     /**
294      * Retrieves the lastest statistics for the set of pillars in the given collection
295      * @param collectionID The ID of the collection
296      * @return {@link PillarStat} The latest pillar statistics for the pillars in the collection 
297      */
298     List<PillarStat> getLatestPillarStats(String collectionID);
299     
300     /**
301      * Method to create a new set of statistics entries for a given collection
302      * @param collectionID The ID of the collection
303      */
304     void makeStatisticsForCollection(String collectionID);
305     
306     /**
307      * Shutdown the model. This will typically consist of closing DB connections.
308      */
309     void close();
310 }