private OperationException performImport(OperationAttributes attr, Map<SiteKey, MopImport> importMap)
throws OperationException {
// Performs import
Map<SiteKey, MopImport> importsRan = new HashMap<SiteKey, MopImport>();
OperationException importError = null;
try {
log.info("Performing import using importMode '" + attr.importMode + "'");
for (Map.Entry<SiteKey, MopImport> mopImportEntry : importMap.entrySet()) {
SiteKey siteKey = mopImportEntry.getKey();
MopImport mopImport = mopImportEntry.getValue();
MopImport ran = new MopImport();
if (importsRan.containsKey(siteKey)) {
throw new IllegalStateException("Multiple site imports for same operation.");
}
importsRan.put(siteKey, ran);
log.debug("Importing data for site " + siteKey);
// Site layout import
if (mopImport.siteTask != null) {
log.debug("Importing site layout data.");
ran.siteTask = mopImport.siteTask;
mopImport.siteTask.importData(attr.importMode);
}
// Pages import
if (mopImport.pageTask != null) {
log.debug("Importing page data.");
ran.pageTask = mopImport.pageTask;
mopImport.pageTask.importData(attr.importMode);
}
// Navigation import
if (mopImport.navigationTask != null) {
log.debug("Importing navigation data.");
ran.navigationTask = mopImport.navigationTask;
mopImport.navigationTask.importData(attr.importMode);
}
}
log.info("Import successful !");
} catch (Throwable t) {
boolean rollbackSuccess = true;
log.error("Exception importing data.", t);
log.info("Attempting to rollback data modified by import.");
for (Map.Entry<SiteKey, MopImport> mopImportEntry : importsRan.entrySet()) {
SiteKey siteKey = mopImportEntry.getKey();
MopImport mopImport = mopImportEntry.getValue();
log.debug("Rolling back imported data for site " + siteKey);
if (mopImport.navigationTask != null) {
log.debug("Rolling back navigation modified during import...");
try {
mopImport.navigationTask.rollback();
} catch (Throwable t1) // Continue rolling back even though there are exceptions.
{
rollbackSuccess = false;
log.error("Error rolling back navigation data for site " + siteKey, t1);
}
}
if (mopImport.pageTask != null) {
log.debug("Rolling back pages modified during import...");
try {
mopImport.pageTask.rollback();
} catch (Throwable t1) // Continue rolling back even though there are exceptions.
{
rollbackSuccess = false;
log.error("Error rolling back page data for site " + siteKey, t1);
}
}
if (mopImport.siteTask != null) {
log.debug("Rolling back site layout modified during import...");
try {
mopImport.siteTask.rollback();
} catch (Throwable t1) // Continue rolling back even though there are exceptions.
{
rollbackSuccess = false;
log.error("Error rolling back site layout for site " + siteKey, t1);
}
}
}
String message = (rollbackSuccess) ?
"Error during import. Tasks successfully rolled back. Portal should be back to consistent state."
: "Error during import. Errors in rollback as well. Portal may be in an inconsistent state.";
importError = new OperationException(attr.operationName, message, t);
} finally {
importMap.clear();
importsRan.clear();
}