empty = entry.getName().equals("");
if (empty) continue;
// Parse zip entry
String[] parts = parseEntry(entry);
SiteKey siteKey = Utils.siteKey(parts[0], parts[1]);
String file = parts[2];
MopImport mopImport = importMap.get(siteKey);
if (mopImport == null)
{
mopImport = new MopImport();
importMap.put(siteKey, mopImport);
}
if (SiteLayoutExportTask.FILES.contains(file))
{
// Unmarshal site layout data
Marshaller<PortalConfig> marshaller = operationContext.getBindingProvider().getMarshaller(PortalConfig.class, ContentType.XML);
PortalConfig portalConfig = marshaller.unmarshal(zis);
portalConfig.setType(siteKey.getTypeName());
if (!portalConfig.getName().equals(siteKey.getName()))
{
throw new OperationException(operationName, "Name of site does not match that of the zip entry site name.");
}
// Add import task to run later
mopImport.siteTask = new SiteLayoutImportTask(portalConfig, siteKey, dataStorage);
}
else if (file.equals(PageExportTask.FILE))
{
// Unmarshal page data
Marshaller<Page.PageSet> marshaller = operationContext.getBindingProvider().getMarshaller(Page.PageSet.class, ContentType.XML);
Page.PageSet pages = marshaller.unmarshal(zis);
for (Page page : pages.getPages())
{
page.setOwnerType(siteKey.getTypeName());
page.setOwnerId(siteKey.getName());
}
// Add import task to run later.
mopImport.pageTask = new PageImportTask(pages, siteKey, dataStorage);
}
else if (file.equals(NavigationExportTask.FILE))
{
// Unmarshal navigation data
Marshaller<PageNavigation> marshaller = operationContext.getBindingProvider().getMarshaller(PageNavigation.class, ContentType.XML);
PageNavigation navigation = marshaller.unmarshal(zis);
navigation.setOwnerType(siteKey.getTypeName());
navigation.setOwnerId(siteKey.getName());
// Add import task to run later
mopImport.navigationTask = new NavigationImportTask(navigation, siteKey, navigationService, descriptionService, dataStorage);
}
}
resultHandler.completed(NoResultModel.INSTANCE);
}
catch (Throwable t)
{
throw new OperationException(operationContext.getOperationName(), "Exception reading data for import.", t);
}
finally
{
try
{
zis.reallyClose();
}
catch (IOException e)
{
log.warn("Exception closing underlying data stream from import.");
}
}
if (empty)
{
log.info("Nothing to import, zip file empty.");
return;
}
// Perform import
Map<SiteKey, MopImport> importsRan = new HashMap<SiteKey, MopImport>();
try
{
log.info("Performing import using importMode '" + mode + "'");
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(importMode);
}
// Page import
if (mopImport.pageTask != null)
{
log.debug("Importing page data.");
ran.pageTask = mopImport.pageTask;
mopImport.pageTask.importData(importMode);
}
// Navigation import
if (mopImport.navigationTask != null)
{
log.debug("Importing navigation data.");
ran.navigationTask = mopImport.navigationTask;
mopImport.navigationTask.importData(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)
{