Working upload of photos (individual and zip)
[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             PageParameters pars = new PageParameters();
69             pars.put("path", path);
70             setResponsePage(HomePage.class, pars);
71         }
72     }
73
74     private String path;
75
76     /**
77      * Constructor that is invoked when page is invoked without a session.
78      *
79      * @param parameters Page parameters
80      */
81     public HomePage(final PageParameters parameters) throws Exception {
82         super();
83
84         path = parameters.getString("path", "/");
85         if (!path.startsWith("/")) {
86             info("Invalid album '" + path + "', showing root album instead");
87             path = "/";
88         }
89
90         System.out.println("Currently logged in user: " + user);
91
92         List<String> usernames = userAdmin.getUsers();
93         System.out.println("All user names: " + usernames);
94
95         usernames = userAdmin.getUsers("public");
96         System.out.println("Users in group public: " + usernames);
97
98         System.out.println("Entries: " + album.size());
99         for (int i = 0; i < album.size(); i++) {
100             PhotoEntry entry = album.getEntry(i);
101             System.out.println("Entry " + i + " " + entry.getId() + " " + entry.getPath());
102         }
103
104         System.out.println("Authorized Entries: " + authorized.size());
105         for (int i = 0; i < authorized.size(); i++) {
106             PhotoEntry entry = authorized.getEntry(i);
107             System.out.println("Entry " + i + " " + entry.getId() + " " + entry.getPath());
108         }
109
110         PhotoEntry current = authorized.getEntry(path);
111
112         if (current instanceof Photo) {
113             add(new PhotoPanel("content", parameters));
114         } else {
115             add(new AlbumPanel("content", parameters));
116         }
117     }
118 }