You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by at...@apache.org on 2012/08/20 13:23:18 UTC

svn commit: r1374974 - in /rave/sandbox/content-services/demo-portal/src/main/java/org: ./ apache/ apache/rave/ apache/rave/portal/ apache/rave/portal/web/ apache/rave/portal/web/hmvc/ apache/rave/portal/web/hmvc/controller/

Author: ate
Date: Mon Aug 20 11:23:17 2012
New Revision: 1374974

URL: http://svn.apache.org/viewvc?rev=1374974&view=rev
Log:
RAVE-698: New dynamic page mapping and definition based on or cloned from Rave PageController. Work in progress but kind of working on url /portal/app/page (only)
- missing controller classes

Added:
    rave/sandbox/content-services/demo-portal/src/main/java/org/
    rave/sandbox/content-services/demo-portal/src/main/java/org/apache/
    rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/
    rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/
    rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/
    rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/
    rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/
    rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/FooterController.java   (with props)
    rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageBodyController.java   (with props)
    rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageContentController.java   (with props)
    rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageHeaderController.java   (with props)
    rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageTabsController.java   (with props)
    rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/UserPageController.java   (with props)

Added: rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/FooterController.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/FooterController.java?rev=1374974&view=auto
==============================================================================
--- rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/FooterController.java (added)
+++ rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/FooterController.java Mon Aug 20 11:23:17 2012
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.rave.portal.web.hmvc.controller;
+
+import org.apache.rave.portal.web.hmvc.Hmvc;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@Controller
+public class FooterController {
+
+    @Hmvc
+    @RequestMapping
+    public String render() {
+        return "hmvc/footer";
+    }
+}

Propchange: rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/FooterController.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/FooterController.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageBodyController.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageBodyController.java?rev=1374974&view=auto
==============================================================================
--- rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageBodyController.java (added)
+++ rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageBodyController.java Mon Aug 20 11:23:17 2012
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.rave.portal.web.hmvc.controller;
+
+import org.apache.rave.portal.web.hmvc.Hmvc;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@Controller
+public class PageBodyController {
+
+    @Hmvc
+    @RequestMapping
+    public String render() {
+        return "hmvc/page-body";
+    }
+}

Propchange: rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageBodyController.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageBodyController.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageContentController.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageContentController.java?rev=1374974&view=auto
==============================================================================
--- rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageContentController.java (added)
+++ rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageContentController.java Mon Aug 20 11:23:17 2012
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.rave.portal.web.hmvc.controller;
+
+import org.apache.rave.portal.web.hmvc.Hmvc;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@Controller
+public class PageContentController {
+
+    @Hmvc
+    @RequestMapping
+    public String render() {
+        return "hmvc/page-content";
+    }
+}

Propchange: rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageContentController.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageContentController.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageHeaderController.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageHeaderController.java?rev=1374974&view=auto
==============================================================================
--- rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageHeaderController.java (added)
+++ rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageHeaderController.java Mon Aug 20 11:23:17 2012
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.rave.portal.web.hmvc.controller;
+
+import org.apache.rave.portal.model.Page;
+import org.apache.rave.portal.model.PageUser;
+import org.apache.rave.portal.model.User;
+import org.apache.rave.portal.web.hmvc.Hmvc;
+import org.apache.rave.portal.web.model.NavigationItem;
+import org.apache.rave.portal.web.model.NavigationMenu;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@Controller
+public class PageHeaderController {
+
+    @Hmvc
+    @RequestMapping
+    public String render(Model model, @ModelAttribute User user, @ModelAttribute Page page, @ModelAttribute PageUser pageUser) {
+        NavigationMenu menu = new NavigationMenu("topnav");
+        NavigationItem profile = new NavigationItem("page.profile.title", getDisplayName(user), "/app/person/" + user.getUsername() + "?referringPageId=" + page.getId());
+        menu.addNavigationItem(profile);
+        if (pageUser.isEditor()) {
+            NavigationItem store = new NavigationItem("page.store.title", null, "/app/store?referringPageId=" + page.getId());
+            menu.addNavigationItem(store);
+        }
+        NavigationItem admin = getAdminItem();
+        menu.addNavigationItem(admin);
+
+        NavigationItem logout = getLogoutItem();
+        menu.addNavigationItem(logout);
+        model.addAttribute(menu.getName(), menu);
+        return "hmvc/page-header";
+    }
+
+    protected static NavigationItem getAdminItem() {
+        return new NavigationItem("page.general.toadmininterface", null, "/app/admin/");
+    }
+
+    protected static NavigationItem getLogoutItem() {
+        return new NavigationItem("page.general.logout", null, "/j_spring_security_logout");
+    }
+
+    protected static String getDisplayName(User user) {
+        String displayName = user.getDisplayName();
+        return (displayName == null || "".equals(displayName)) ? user.getUsername() : displayName;
+    }
+}

Propchange: rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageHeaderController.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageHeaderController.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageTabsController.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageTabsController.java?rev=1374974&view=auto
==============================================================================
--- rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageTabsController.java (added)
+++ rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageTabsController.java Mon Aug 20 11:23:17 2012
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.rave.portal.web.hmvc.controller;
+
+import org.apache.rave.portal.web.hmvc.Hmvc;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@Controller
+public class PageTabsController {
+
+    @Hmvc
+    @RequestMapping
+    public String render() {
+        return "hmvc/page-tabs";
+    }
+}

Propchange: rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageTabsController.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/PageTabsController.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/UserPageController.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/UserPageController.java?rev=1374974&view=auto
==============================================================================
--- rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/UserPageController.java (added)
+++ rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/UserPageController.java Mon Aug 20 11:23:17 2012
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.rave.portal.web.hmvc.controller;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.rave.portal.model.Page;
+import org.apache.rave.portal.model.PageInvitationStatus;
+import org.apache.rave.portal.model.PageLayout;
+import org.apache.rave.portal.model.PageUser;
+import org.apache.rave.portal.model.User;
+import org.apache.rave.portal.service.PageLayoutService;
+import org.apache.rave.portal.service.PageService;
+import org.apache.rave.portal.service.UserService;
+import org.apache.rave.portal.web.hmvc.Hmvc;
+import org.apache.rave.portal.web.util.ModelKeys;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@Controller
+public class UserPageController {
+    private final Logger logger = LoggerFactory.getLogger(getClass());
+
+    private PageService pageService;
+    private UserService userService;
+    private PageLayoutService pageLayoutService;
+
+    @Autowired
+    public UserPageController(PageService pageService, UserService userService, PageLayoutService pageLayoutService) {
+        this.pageService = pageService;
+        this.userService = userService;
+        this.pageLayoutService = pageLayoutService;
+    }
+
+    @Hmvc
+    @RequestMapping
+    public String render(Model model, HttpServletRequest request) {
+        List<Page> pages = getAllPagesForAuthenticatedUser();
+        Page page = pageService.getDefaultPageFromList(pages);
+        PageUser currentPageUser = null;
+        User thisUser = userService.getAuthenticatedUser();
+        for(PageUser pageUser : page.getMembers()){
+            if(pageUser.getUser().equals(thisUser)){
+                currentPageUser = pageUser;
+            }
+        }
+        List<PageLayout> pageLayouts = pageLayoutService.getAllUserSelectable();
+
+        model.addAttribute(ModelKeys.USER, thisUser);
+        model.addAttribute(ModelKeys.PAGE, page);
+        model.addAttribute(ModelKeys.PAGES, pages);
+        model.addAttribute(ModelKeys.PAGE_USER, currentPageUser);
+        model.addAttribute(ModelKeys.PAGE_LAYOUTS, pageLayouts);
+
+        return "hmvc/page";
+    }
+
+    private List<Page> getAllPagesForAuthenticatedUser() {
+        User user = userService.getAuthenticatedUser();
+        long userId = user.getId();
+        List<Page> pages = pageService.getAllUserPages(userId);
+        // we add pages to this list which the corresponding pageUser object is not set to "refused"
+        List<Page> viewablePages = new ArrayList<Page>();
+        for(Page page : pages){
+            for(PageUser pageUser : page.getMembers()){
+                if(pageUser != null && pageUser.getUser().equals(user) && !pageUser.getPageStatus().equals(PageInvitationStatus.REFUSED)){
+                    viewablePages.add(page);
+                }
+            }
+        }
+        if (viewablePages.isEmpty()) {
+            // create a new default page for the user
+            logger.info("User {} does not have any pages - creating default page", user.getUsername());
+            pageService.addNewDefaultUserPage(userId);
+            // refresh the pages list which will now have the new page
+            viewablePages = pageService.getAllUserPages(userId);
+        }
+        return viewablePages;
+    }
+}

Propchange: rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/UserPageController.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: rave/sandbox/content-services/demo-portal/src/main/java/org/apache/rave/portal/web/hmvc/controller/UserPageController.java
------------------------------------------------------------------------------
    svn:keywords = Id