Full navigation is working including viewing individual photos.
[photos] / src / main / java / org / wamblee / photos / wicket / HomePage.java
1 /*
2  * Copyright 2005-2010 the original author or authors.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.wamblee.photos.wicket;
17
18 import java.util.List;
19 import java.util.logging.Logger;
20 import javax.inject.Inject;
21
22 import org.apache.wicket.PageParameters;
23 import org.apache.wicket.markup.html.link.Link;
24 import org.wamblee.photos.model.Album;
25 import org.wamblee.photos.model.Photo;
26 import org.wamblee.photos.model.PhotoEntry;
27 import org.wamblee.photos.model.plumbing.AllPhotos;
28 import org.wamblee.photos.model.plumbing.AuthorizedPhotos;
29 import org.wamblee.security.authentication.User;
30 import org.wamblee.security.authentication.UserAdministration;
31
32 /**
33  * Homepage
34  */
35 public class HomePage extends BasePage {
36
37     private static final Logger LOGGER = Logger.getLogger(HomePage.class.getName());
38
39     private static final long serialVersionUID = 1L;
40
41     @Inject
42     private transient User user;
43
44     @Inject
45     private transient UserAdministration userAdmin;
46
47     // TODO the state should be stored as a path.
48
49     @Inject
50     @AllPhotos
51     private transient Album album;
52
53     @Inject
54     @AuthorizedPhotos
55     private transient Album authorized;
56
57     private class SerializableEntryLink extends Link {
58
59         private String path;
60
61         public SerializableEntryLink(String aId, String aPath) {
62             super(aId);
63             path = aPath;
64         }
65
66         @Override
67         public void onClick() {
68             System.out.println("Entry " + path + " was clicked");
69             PageParameters pars = new PageParameters();
70             pars.put("path", path);
71             setResponsePage(HomePage.class, pars);
72         }
73     }
74
75     private String path;
76
77     /**
78      * Constructor that is invoked when page is invoked without a session.
79      *
80      * @param parameters Page parameters
81      */
82     public HomePage(final PageParameters parameters) throws Exception {
83         super();
84
85         path = parameters.getString("path", "/");
86         if (!path.startsWith("/")) {
87             info("Invalid album '" + path + "', showing root album instead");
88             path = "/";
89         }
90
91         System.out.println("Currently logged in user: " + user);
92
93         List<String> usernames = userAdmin.getUsers();
94         System.out.println("All user names: " + usernames);
95
96         usernames = userAdmin.getUsers("public");
97         System.out.println("Users in group public: " + usernames);
98
99         System.out.println("Entries: " + album.size());
100         for (int i = 0; i < album.size(); i++) {
101             PhotoEntry entry = album.getEntry(i);
102             System.out.println("Entry " + i + " " + entry.getId() + " " + entry.getPath());
103         }
104
105         System.out.println("Authorized Entries: " + authorized.size());
106         for (int i = 0; i < authorized.size(); i++) {
107             PhotoEntry entry = authorized.getEntry(i);
108             System.out.println("Entry " + i + " " + entry.getId() + " " + entry.getPath());
109         }
110
111         PhotoEntry current = authorized.getEntry(path);
112
113         if (current instanceof Photo) {
114             add(new PhotoPanel("content", parameters));
115         } else {
116             add(new AlbumPanel("content", parameters));
117         }
118     }
119 }