Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

GTNPORTAL-3437: "overwrite" import mode does not delete pages #815

Open
wants to merge 1 commit into
base: 3.5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
Expand All @@ -46,6 +47,7 @@
import org.exoplatform.portal.config.model.PageNode;
import org.exoplatform.portal.config.model.PortalConfig;
import org.exoplatform.portal.config.model.UnmarshalledObject;
import org.exoplatform.portal.mop.SiteKey;
import org.exoplatform.portal.mop.description.DescriptionService;
import org.exoplatform.portal.mop.importer.ImportMode;
import org.exoplatform.portal.mop.importer.Imported;
Expand All @@ -54,7 +56,9 @@
import org.exoplatform.portal.mop.importer.PageImporter;
import org.exoplatform.portal.mop.importer.PortalConfigImporter;
import org.exoplatform.portal.mop.navigation.NavigationService;
import org.exoplatform.portal.mop.page.PageContext;
import org.exoplatform.portal.mop.page.PageService;
import org.exoplatform.portal.mop.page.PageServiceWrapper;
import org.exoplatform.portal.pom.config.POMSession;
import org.exoplatform.portal.pom.config.POMSessionManager;
import org.gatein.common.logging.Logger;
Expand Down Expand Up @@ -468,17 +472,34 @@ public void createPage(NewPortalConfig config, String owner) throws Exception {
if (pageSet == null) {
return;
}
ArrayList<Page> list = pageSet.getObject().getPages();
for (Page page : list) {
RequestLifeCycle.begin(PortalContainer.getInstance());
try { //
ImportMode importMode = getRightMode(config.getImportMode());

RequestLifeCycle.begin(PortalContainer.getInstance());
try{
ImportMode importMode = getRightMode(config.getImportMode());
ArrayList<Page> list = pageSet.getObject().getPages();
HashMap<String, Page> hashPageList = new HashMap<String, Page>();
String ownerType = config.getOwnerType();
for (Page page : list) {
hashPageList.put(page.getPageId(), page);
}
// Only delete pages from group/portal, not user page
if (importMode == ImportMode.OVERWRITE && !ownerType.equals(PortalConfig.USER_TYPE) ) {
List<PageContext> allPages = ((PageServiceWrapper)pageService_).loadPages(new SiteKey(ownerType, owner));
for (PageContext currentPage : allPages) {
String currentPageId = currentPage.getKey().format();
if (!hashPageList.containsKey(currentPageId)) {
if (dataStorage_.getPage(currentPageId) != null) {
log.info("Remove page named " + currentPageId + " from Portal Data" );
pageService_.destroyPage(currentPage.getKey());
}
}
}
}
for (Page page : list) {
PageImporter importer = new PageImporter(importMode, page, dataStorage_, pageService_);
importer.perform();
} finally {
RequestLifeCycle.end();
}
} finally {
RequestLifeCycle.end();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected final String getConfig2() {
}

@Override
protected final void afterOneBootWithExtention(PortalContainer container) throws Exception {
protected void afterOneBootWithExtention(PortalContainer container) throws Exception {
RequestLifeCycle.begin(container);

POMSessionManager mgr = (POMSessionManager) container.getComponentInstanceOfType(POMSessionManager.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@
import org.exoplatform.container.component.RequestLifeCycle;
import org.exoplatform.portal.config.model.Application;
import org.exoplatform.portal.config.model.Container;
import org.exoplatform.portal.config.model.Page;
import org.exoplatform.portal.config.model.PortalConfig;
import org.exoplatform.portal.mop.SiteType;
import org.exoplatform.portal.mop.importer.ImportMode;
import org.exoplatform.portal.mop.importer.Imported;
import org.exoplatform.portal.mop.page.PageContext;
import org.exoplatform.portal.mop.page.PageKey;
import org.exoplatform.portal.mop.page.PageService;
import org.exoplatform.portal.pom.config.POMSessionManager;
import org.exoplatform.portal.pom.spi.portlet.Portlet;
import org.gatein.mop.api.workspace.Workspace;

/**
* @author <a href="[email protected]">Trong Tran</a>
Expand All @@ -40,7 +45,46 @@ public class TestSiteDataImportOverwrite extends AbstractSiteDataImportTest {
protected ImportMode getMode() {
return ImportMode.OVERWRITE;
}
@Override
protected void afterOneBootWithExtention(PortalContainer container) throws Exception
{
RequestLifeCycle.begin(container);
POMSessionManager mgr = (POMSessionManager)container.getComponentInstanceOfType(POMSessionManager.class);
Workspace workspace = mgr.getSession().getWorkspace();
assertTrue(workspace.isAdapted(Imported.class));
// Test portal
DataStorage dataStorage = (DataStorage)container.getComponentInstanceOfType(DataStorage.class);
PageService pageService = (PageService) container.getComponentInstanceOfType(PageService.class);
PortalConfig portal = dataStorage.getPortalConfig("classic");
Container layout = portal.getPortalLayout();
assertEquals(1, layout.getChildren().size());
Application<Portlet> layoutPortlet = (Application<Portlet>)layout.getChildren().get(0);
assertEquals("site2/layout", dataStorage.getId(layoutPortlet.getState()));
PageContext page = pageService.loadPage(PageKey.parse("portal::classic::home"));
assertNull(page);
page = pageService.loadPage(PageKey.parse("portal::classic::page1"));
assertNotNull(page);
assertEquals("site 2", page.getState().getDisplayName());
page = pageService.loadPage(PageKey.parse("portal::classic::page2"));
assertNotNull(page);
assertEquals("site 2", page.getState().getDisplayName());
// Test group
portal = dataStorage.getPortalConfig(SiteType.GROUP.getName(), "/platform/administrators");
layout = portal.getPortalLayout();
assertEquals(1, layout.getChildren().size());
layoutPortlet = (Application<Portlet>)layout.getChildren().get(0);
assertEquals("site1/layout", dataStorage.getId(layoutPortlet.getState()));
page = pageService.loadPage(PageKey.parse("group::/platform/administrators::page1"));
assertNotNull(page);
assertEquals("site 2", page.getState().getDisplayName());

// Test user
PageContext dashboard1 = pageService.loadPage(PageKey.parse("user::root::dashboard1"));
assertNotNull(dashboard1);
assertEquals("site 2", dashboard1.getState().getDisplayName());

RequestLifeCycle.end();
}
@Override
protected void afterSecondBootWithOverride(PortalContainer container) throws Exception {
RequestLifeCycle.begin(container);
Expand All @@ -55,8 +99,7 @@ protected void afterSecondBootWithOverride(PortalContainer container) throws Exc

//
PageContext home = pageService.loadPage(PageKey.parse("portal::classic::home"));
assertNotNull(home);
assertEquals("site 1", home.getState().getDisplayName());
assertNull(home);

PageContext page1 = pageService.loadPage(PageKey.parse("portal::classic::page1"));
assertNotNull(page1);
Expand Down