|
|
|
|
@ -92,7 +92,7 @@ public HistoryServiceImpl(BundleContext bundleContext)
|
|
|
|
|
public Iterator<HistoryID> getExistingIDs()
|
|
|
|
|
{
|
|
|
|
|
List<File> vect = new Vector<File>();
|
|
|
|
|
File histDir = null;
|
|
|
|
|
File histDir;
|
|
|
|
|
try {
|
|
|
|
|
String userSetDataDirectory
|
|
|
|
|
= System.getProperty("HistoryServiceDirectory");
|
|
|
|
|
@ -160,9 +160,12 @@ public History getHistory(HistoryID id)
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public History createHistory(HistoryID id,
|
|
|
|
|
HistoryRecordStructure recordStructure)
|
|
|
|
|
throws IllegalArgumentException, IOException {
|
|
|
|
|
public History createHistory(
|
|
|
|
|
HistoryID id,
|
|
|
|
|
HistoryRecordStructure recordStructure)
|
|
|
|
|
throws IllegalArgumentException,
|
|
|
|
|
IOException
|
|
|
|
|
{
|
|
|
|
|
History retVal = null;
|
|
|
|
|
|
|
|
|
|
synchronized (this.histories)
|
|
|
|
|
@ -509,4 +512,97 @@ public boolean isHistoryCreated(HistoryID id)
|
|
|
|
|
{
|
|
|
|
|
return getDirForHistory(id).exists();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Enumerates existing histories.
|
|
|
|
|
* @param rawid the start of the HistoryID of all the histories that will be
|
|
|
|
|
* returned.
|
|
|
|
|
* @return list of histories which HistoryID starts with <tt>rawid</tt>.
|
|
|
|
|
* @throws IllegalArgumentException if the <tt>rawid</tt> contains ids
|
|
|
|
|
* which are missing in current history.
|
|
|
|
|
*/
|
|
|
|
|
public List<HistoryID> getExistingHistories(
|
|
|
|
|
String[] rawid)
|
|
|
|
|
throws IllegalArgumentException
|
|
|
|
|
{
|
|
|
|
|
File histDir = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
histDir = getFileAccessService()
|
|
|
|
|
.getPrivatePersistentDirectory(
|
|
|
|
|
DATA_DIRECTORY, FileCategory.PROFILE);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
logger.error("Error opening directory", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(histDir == null || !histDir.exists())
|
|
|
|
|
return new ArrayList<HistoryID>();
|
|
|
|
|
|
|
|
|
|
StringBuilder folderPath = new StringBuilder();
|
|
|
|
|
for(String id : rawid)
|
|
|
|
|
folderPath.append(id).append(File.separator);
|
|
|
|
|
|
|
|
|
|
File srcFolder = new File(histDir, folderPath.toString());
|
|
|
|
|
|
|
|
|
|
if(!srcFolder.exists())
|
|
|
|
|
return new ArrayList<HistoryID>();
|
|
|
|
|
|
|
|
|
|
TreeMap<File, HistoryID> recentFiles =
|
|
|
|
|
new TreeMap<File, HistoryID>(new Comparator<File>()
|
|
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public int compare(File o1, File o2)
|
|
|
|
|
{
|
|
|
|
|
return o1.getName().compareTo(o2.getName());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
getExistingFiles(srcFolder, Arrays.asList(rawid), recentFiles);
|
|
|
|
|
|
|
|
|
|
// return non duplicate
|
|
|
|
|
List<HistoryID> result = new ArrayList<HistoryID>();
|
|
|
|
|
for(Map.Entry<File, HistoryID> entry : recentFiles.entrySet())
|
|
|
|
|
{
|
|
|
|
|
HistoryID hid = entry.getValue();
|
|
|
|
|
|
|
|
|
|
if(result.contains(hid))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
result.add(hid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get existing files in <tt>res</tt> and their corresponding historyIDs.
|
|
|
|
|
* @param sourceFolder the folder to search into.
|
|
|
|
|
* @param rawID the rawID.
|
|
|
|
|
* @param res the result map.
|
|
|
|
|
*/
|
|
|
|
|
private void getExistingFiles(
|
|
|
|
|
File sourceFolder, List<String> rawID,
|
|
|
|
|
Map<File, HistoryID> res)
|
|
|
|
|
{
|
|
|
|
|
for(File f : sourceFolder.listFiles())
|
|
|
|
|
{
|
|
|
|
|
if(f.isDirectory())
|
|
|
|
|
{
|
|
|
|
|
List<String> newRawID = new ArrayList<String>(rawID);
|
|
|
|
|
newRawID.add(f.getName());
|
|
|
|
|
|
|
|
|
|
getExistingFiles(f, newRawID, res);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(f.getName().equals(DATA_FILE))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
res.put(f, HistoryID.createFromRawStrings(
|
|
|
|
|
rawID.toArray(new String[rawID.size()])));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|