// Check card images files status
monitor.subTask("Card checking");
for (Card cd : f.getLstCard())
{
AttrFile ai = (AttrFile) cd.getValue(attrIdx);
if (ai != null)
{
String absCardFileName = ai.getAbsolutePath();
File foundMMFile = null;
for (Iterator<File> itfic = lstMMFile.iterator(); itfic.hasNext() && (foundMMFile == null);)
{
File floc = itfic.next();
if (absCardFileName.equals(floc.getAbsolutePath()))
{
foundMMFile = floc;
itfic.remove();
}
}
if (foundMMFile == null)
{
// Suggest Card Deletion
DeltaMMFile dlt = new DeltaMMFile(cd, attrIdx, FileStatus.MISSING);
lstDelta.add(dlt);
}
else
{
// Check Last modification Date and size
Date dateBase = ai.getLastModificationDate();
// Get the actual file last modification date
long lmd = foundMMFile.lastModified();
if (dateBase.getTime() < lmd)
{
// Suggest Card Update
DeltaMMFile dlt = new DeltaMMFile(cd, attrIdx, FileStatus.UPDATED);
dlt.setFoundFic(foundMMFile);
lstDelta.add(dlt);
}
else
{
// Nothing to do with the card, it's up to date
}
}
} // Else the card has a non valued AttrFile
}
monitor.subTask("New File Importation");
// If the list of read files is not empty, it means that some MM files are not recorded
// in the database ==> Suggest to create them
for (File fic : lstMMFile)
{
DeltaMMFile dlt = new DeltaMMFile(fic);
dlt.setFoundFic(fic);
AttrImage imgAttr = (AttrImage) a1.create(Application.getDataStore(), fic);
if (imgAttr != null)
{
dlt.setAttrFile(imgAttr);
}
lstDelta.add(dlt);
monitor.worked(1);
}
monitor.done();
}
});
}
catch (InvocationTargetException e1)
{
e1.printStackTrace();
}
catch (InterruptedException e1)
{
e1.printStackTrace();
}
DlgDeltaFile dlg = new DlgDeltaFile(parent);
res = dlg.open(lstDelta);
if (res == C_OK)
{
for (DeltaMMFile dmmfic : lstDelta)
{
Card fcd = dmmfic.getFoundCard();
switch (dmmfic.getAction())
{
case CREATE:
Card nc = Application.getDataStore().createCard(f);
nc.setValue(attrIdx, dmmfic.getAttrFile());
break;
case DELETE:
Application.getDataStore().remove(f, fcd);
break;
case UPDATE:
AttrFile atf = (AttrFile) fcd.getValue(attrIdx);
atf.setLastModificationDate(new Date(dmmfic.getFoundFic().lastModified()));
if (atf.getStatus() == StatusCycle.UNCHANGED)
{
atf.setStatus(StatusCycle.MODIFIED);
}
if (fcd.getStatus() == StatusCycle.UNCHANGED)
{
fcd.setStatus(StatusCycle.MODIFIED);