FixAssetsProcessStatus.startProgress();
FixAssetsProcessStatus.setDescription("task 30: DeleteOrphanedAssets");
HibernateUtil.startTransaction();
int total = 0;
try {
DotConnect dc = new DotConnect();
dc.setSQL(identifiersToDelete);
List<Map<String, String>> identifiersToDeleteResult = dc.loadResults();
total = total + identifiersToDeleteResult.size();
FixAssetsProcessStatus.setTotal(total);
if ((identifiersToDeleteResult != null) && (0 < identifiersToDeleteResult.size())) {
modifiedData = identifiersToDeleteResult;
List<Map<String, String>> inodesToDeleteResult;
List<Map<String, String>> assetsToDeleteResult;
Map<String, String> identifierToDelete;
boolean assetDeleted;
for (int i = 0; i < identifiersToDeleteResult.size(); ++i) {
identifierToDelete = identifiersToDeleteResult.get(i);
assetDeleted = false;
dc.setSQL(inodesToDelete);
dc.addParam(identifierToDelete.get("id"));
dc.addParam(identifierToDelete.get("id"));
dc.addParam(identifierToDelete.get("id"));
inodesToDeleteResult = dc.loadResults();
if ((inodesToDeleteResult != null) && (0 < inodesToDeleteResult.size())) {
modifiedData.addAll(inodesToDeleteResult);
if (inodesToDeleteResult.get(0).get("type").equals("htmlpage")) {
Logger.debug(this, "Deleting orphan HTMLPage with Identifier='" + identifierToDelete.get("id") + "'");
dc.setSQL(htmlPagesToDelete);
dc.addParam(identifierToDelete.get("id"));
assetsToDeleteResult = dc.loadResults();
if ((assetsToDeleteResult != null) && (0 < assetsToDeleteResult.size())) {
modifiedData.addAll(assetsToDeleteResult);
dc.setSQL(deleteHTMLPages);
dc.addParam(identifierToDelete.get("id"));
dc.loadResult();
assetDeleted = true;
}
} else if (inodesToDeleteResult.get(0).get("type").equals("links")) {
Logger.debug(this, "Deleting orphan Link with Identifier='" + identifierToDelete.get("id") + "'");
dc.setSQL(linksToDelete);
dc.addParam(identifierToDelete.get("id"));
assetsToDeleteResult = dc.loadResults();
if ((assetsToDeleteResult != null) && (0 < assetsToDeleteResult.size())) {
modifiedData.addAll(assetsToDeleteResult);
dc.setSQL(deleteLinks);
dc.addParam(identifierToDelete.get("id"));
dc.loadResult();
assetDeleted = true;
}
} else if (inodesToDeleteResult.get(0).get("type").equals("file_asset")) {
Logger.debug(this, "Deleting orphan File Asset with Identifier='" + identifierToDelete.get("id") + "'");
dc.setSQL(fileAssetsToDelete);
dc.addParam(identifierToDelete.get("id"));
assetsToDeleteResult = dc.loadResults();
if ((assetsToDeleteResult != null) && (0 < assetsToDeleteResult.size())) {
modifiedData.addAll(assetsToDeleteResult);
dc.setSQL(deleteFileAssets);
dc.addParam(identifierToDelete.get("id"));
dc.loadResult();
assetDeleted = true;
}
}
if (assetDeleted) {
dc.setSQL(deleteTrees);
dc.addParam(identifierToDelete.get("id"));
dc.addParam(identifierToDelete.get("id"));
dc.addParam(identifierToDelete.get("id"));
dc.addParam(identifierToDelete.get("id"));
dc.addParam(identifierToDelete.get("id"));
dc.addParam(identifierToDelete.get("id"));
dc.loadResult();
dc.setSQL(deleteInodes);
dc.addParam(identifierToDelete.get("id"));
dc.addParam(identifierToDelete.get("id"));
dc.addParam(identifierToDelete.get("id"));
dc.loadResult();
}
}
if (assetDeleted) {
dc.setSQL(deleteIdentifier);
dc.addParam(identifierToDelete.get("id"));
dc.loadResult();
Logger.debug(this, "Delete completed");
}
}
}