View Javadoc
1   /*
2    * Copyright 2014 James Pether Sörling
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   *	$Id$
17   *  $HeadURL$
18  */
19  package com.hack23.cia.web.impl.ui.application.views.admin.system.pagemode;
20  
21  import java.util.Arrays;
22  
23  import org.springframework.security.access.annotation.Secured;
24  import org.springframework.stereotype.Component;
25  
26  import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
27  import com.hack23.cia.model.internal.application.user.impl.UserAccount;
28  import com.hack23.cia.model.internal.application.user.impl.UserAccount_;
29  import com.hack23.cia.service.api.DataContainer;
30  import com.hack23.cia.web.impl.ui.application.action.ViewAction;
31  import com.hack23.cia.web.impl.ui.application.views.common.labelfactory.LabelFactory;
32  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.AdminViews;
33  import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.PageItemPropertyClickListener;
34  import com.vaadin.data.util.BeanItem;
35  import com.vaadin.data.util.BeanItemContainer;
36  import com.vaadin.ui.Layout;
37  import com.vaadin.ui.MenuBar;
38  import com.vaadin.ui.Panel;
39  import com.vaadin.ui.VerticalLayout;
40  
41  /**
42   * The Class AdminUserAccountPageModContentFactoryImpl.
43   */
44  @Component
45  public final class AdminUserAccountPageModContentFactoryImpl extends AbstractAdminSystemPageModContentFactoryImpl {
46  
47  	/** The Constant ADMIN_USERACCOUNT. */
48  	private static final String ADMIN_USERACCOUNT = "Admin Useraccount";
49  
50  	/** The Constant NAME. */
51  	public static final String NAME = AdminViews.ADMIN_USERACCOUNT_VIEW_NAME;
52  
53  	/**
54  	 * Instantiates a new admin user account page mod content factory impl.
55  	 */
56  	public AdminUserAccountPageModContentFactoryImpl() {
57  		super();
58  	}
59  
60  	@Override
61  	public boolean matches(final String page, final String parameters) {
62  		return NAME.equals(page);
63  	}
64  
65  	@Secured({ "ROLE_ADMIN" })
66  	@Override
67  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
68  		final VerticalLayout content = createPanelContent();
69  
70  		final String pageId = getPageId(parameters);
71  		final int pageNr= getPageNr(parameters);
72  
73  		getMenuItemFactory().createMainPageMenuBar(menuBar);
74  
75  		LabelFactory.createHeader2Label(content,ADMIN_USERACCOUNT);
76  
77  		final DataContainer<UserAccount, Long> dataContainer = getApplicationManager()
78  				.getDataContainer(UserAccount.class);
79  
80  		final BeanItemContainer<UserAccount> politicianDocumentDataSource = new BeanItemContainer<>(UserAccount.class,
81  				dataContainer.getPageOrderBy(pageNr,DEFAULT_RESULTS_PER_PAGE,UserAccount_.createdDate));
82  
83  		createPagingControls(content,NAME,pageId, dataContainer.getSize(), pageNr, DEFAULT_RESULTS_PER_PAGE);
84  
85  		getGridFactory().createBasicBeanItemGrid(content,
86  				politicianDocumentDataSource,
87  				"UserAccount",
88  				new String[] { "hjid", "modelObjectId", "modelObjectVersion", "createdDate", "userId", "username",
89  						"userType", "userRole", "userpassword", "email", "country", "numberOfVisits" }, new String[] { "hjid", "modelObjectId", "modelObjectVersion","userId","userpassword", "address","googleAuthKey",
90  							    "googleAuthVerificationCode",
91  							    "googleAuthScratchCodes" },
92  				new PageItemPropertyClickListener(AdminViews.ADMIN_USERACCOUNT_VIEW_NAME, "hjid"), null, null);
93  
94  
95  		if (pageId != null && !pageId.isEmpty()) {
96  
97  			final UserAccount userAccount = dataContainer.load(Long.valueOf(pageId));
98  
99  			if (userAccount != null) {
100 
101 				getFormFactory()
102 						.addFormPanelTextFields(content, new BeanItem<>(userAccount), UserAccount.class,
103 								Arrays.asList(new String[] {"username", "createdDate", "email", "country",
104 										"numberOfVisits" }));
105 			}
106 		}
107 
108 		getPageActionEventHelper().createPageEvent(ViewAction.VISIT_ADMIN_USERACCOUNT_VIEW, ApplicationEventGroup.ADMIN,
109 				NAME, null, pageId);
110 
111 		return content;
112 
113 	}
114 
115 }