}
public void onStartRequest(Application app, PortalRequestContext context) throws Exception {
String userName = context.getRemoteUser();
if (userName != null && SiteType.USER == context.getSiteType() && userName.equals(context.getSiteName())) {
DataStorage storage = (DataStorage) PortalContainer.getComponent(DataStorage.class);
UserPortalConfigService configService = (UserPortalConfigService) PortalContainer
.getComponent(UserPortalConfigService.class);
PortalConfig portalConfig = storage.getPortalConfig("user", userName);
//
if (portalConfig == null) {
log.debug("About to create user site for user " + userName);
configService.createUserSite(userName);
}
UserPortalConfig userPortalConfig = context.getUserPortalConfig();
UserPortal userPortal = userPortalConfig.getUserPortal();
SiteKey siteKey = context.getSiteKey();
UserNavigation nav = userPortal.getNavigation(siteKey);
try {
UserNode rootNode = userPortal.getNode(nav, Scope.CHILDREN, UserNodeFilterConfig.builder().build(), null);
if (rootNode.getChildren().size() < 1) {
// TODO: Retrieve tab name from request
Page page = configService.createPageTemplate(PAGE_TEMPLATE, siteKey.getTypeName(), siteKey.getName());
page.setName(DEFAULT_TAB_NAME);
page.setTitle(DEFAULT_TAB_NAME);
//
PageState pageState = new PageState(page.getTitle(), page.getDescription(), page.isShowMaxWindow(),
page.getFactoryId(), page.getAccessPermissions() != null ? Arrays.asList(page
.getAccessPermissions()) : null, page.getEditPermission());
configService.getPageService().savePage(new PageContext(page.getPageKey(), pageState));
//
storage.save(page);
//
UserNode tabNode = rootNode.addChild(DEFAULT_TAB_NAME);
tabNode.setLabel(DEFAULT_TAB_NAME);
tabNode.setPageRef(PageKey.parse(page.getPageId()));