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  import java.util.List;
23  
24  import org.springframework.security.access.annotation.Secured;
25  import org.springframework.stereotype.Component;
26  
27  import com.hack23.cia.model.internal.application.system.impl.ApplicationActionEvent;
28  import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
29  import com.hack23.cia.model.internal.application.system.impl.ApplicationSession;
30  import com.hack23.cia.model.internal.application.system.impl.ApplicationSession_;
31  import com.hack23.cia.service.api.DataContainer;
32  import com.hack23.cia.web.impl.ui.application.action.ViewAction;
33  import com.hack23.cia.web.impl.ui.application.views.common.converters.ListPropertyConverter;
34  import com.hack23.cia.web.impl.ui.application.views.common.labelfactory.LabelFactory;
35  import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentRatio;
36  import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentSize;
37  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.AdminViews;
38  import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.PageItemPropertyClickListener;
39  import com.vaadin.data.util.BeanItem;
40  import com.vaadin.data.util.BeanItemContainer;
41  import com.vaadin.ui.HorizontalLayout;
42  import com.vaadin.ui.Layout;
43  import com.vaadin.ui.MenuBar;
44  import com.vaadin.ui.Panel;
45  import com.vaadin.ui.VerticalLayout;
46  
47  /**
48   * The Class AdminApplicationSessionPageModContentFactoryImpl.
49   */
50  @Component
51  public final class AdminApplicationSessionPageModContentFactoryImpl extends AbstractAdminSystemPageModContentFactoryImpl {
52  
53  	/** The Constant ADMIN_APPLICATION_SESSION. */
54  	private static final String ADMIN_APPLICATION_SESSION = "Admin Application Session";
55  
56  	/** The Constant NAME. */
57  	public static final String NAME = AdminViews.ADMIN_APPLICATIONS_SESSION_VIEW_NAME;
58  
59  	/**
60  	 * Instantiates a new admin application session page mod content factory
61  	 * impl.
62  	 */
63  	public AdminApplicationSessionPageModContentFactoryImpl() {
64  		super();
65  	}
66  
67  	@Override
68  	public boolean matches(final String page, final String parameters) {
69  		return NAME.equals(page);
70  	}
71  
72  	@Secured({ "ROLE_ADMIN" })
73  	@Override
74  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
75  		final VerticalLayout content = createPanelContent();
76  
77  		final String pageId = getPageId(parameters);
78  		final int pageNr= getPageNr(parameters);
79  
80  		getMenuItemFactory().createMainPageMenuBar(menuBar);
81  
82  		LabelFactory.createHeader2Label(content,ADMIN_APPLICATION_SESSION);
83  
84  		final DataContainer<ApplicationSession, Long> dataContainer = getApplicationManager()
85  				.getDataContainer(ApplicationSession.class);
86  
87  
88  		final BeanItemContainer<ApplicationSession> politicianDocumentDataSource = new BeanItemContainer<>(
89  				ApplicationSession.class, dataContainer.getPageOrderBy(pageNr,DEFAULT_RESULTS_PER_PAGE, ApplicationSession_.createdDate));
90  
91  		createPagingControls(content,NAME,pageId, dataContainer.getSize(), pageNr, DEFAULT_RESULTS_PER_PAGE);
92  
93  		getGridFactory().createBasicBeanItemGrid(content, politicianDocumentDataSource,
94  				"ApplicationSession",
95  				new String[] { "hjid", "createdDate", "sessionType", "userId", "events", "operatingSystem", "locale",
96  						"ipInformation", "userAgentInformation", "sessionId" }, new String[] { "hjid", "modelObjectId", "modelObjectVersion" ,"userAgentInformation", "sessionId","ipInformation"},
97  				new PageItemPropertyClickListener(AdminViews.ADMIN_APPLICATIONS_SESSION_VIEW_NAME, "hjid"), null, new ListPropertyConverter[] { new ListPropertyConverter(List.class, "page", "events","actionName")});
98  
99  		if (pageId != null && !pageId.isEmpty()) {
100 
101 			final ApplicationSession applicationSession = dataContainer.load(Long.valueOf(pageId));
102 
103 			if (applicationSession != null) {
104 
105 				final VerticalLayout rightLayout = new VerticalLayout();
106 				rightLayout.setSizeFull();
107 				final HorizontalLayout horizontalLayout = new HorizontalLayout();
108 				horizontalLayout.setWidth(ContentSize.FULL_SIZE);
109 				content.addComponent(horizontalLayout);
110 				content.setExpandRatio(horizontalLayout, ContentRatio.GRID);
111 
112 
113 				getFormFactory().addFormPanelTextFields(horizontalLayout, new BeanItem<>(applicationSession),
114 						ApplicationSession.class,
115 						Arrays.asList(new String[] { "createdDate","sessionType", "userId", "sessionId", "operatingSystem", "locale",
116 								"ipInformation", "userAgentInformation"}));
117 
118 				horizontalLayout.addComponent(rightLayout);
119 				horizontalLayout.setExpandRatio(rightLayout, ContentRatio.GRID);
120 
121 				final BeanItemContainer<ApplicationActionEvent> eventsItemContainer = new BeanItemContainer<>(
122 						ApplicationActionEvent.class, applicationSession.getEvents());
123 
124 				getGridFactory().createBasicBeanItemGrid(rightLayout,
125 						eventsItemContainer,
126 						"ApplicationActionEvent",
127 						new String[] { "hjid", "createdDate", "eventGroup", "actionName", "applicationOperation", "page", "pageMode",
128 								"elementId", "errorMessage", "applicationMessage",
129 								"modelObjectVersion" }, new String[] { "hjid", "modelObjectId","modelObjectVersion","userId", "sessionId" },
130 						new PageItemPropertyClickListener(AdminViews.ADMIN_APPLICATIONS_EVENTS_VIEW_NAME, "hjid"),
131 						null, null);
132 			}
133 
134 		}
135 
136 		getPageActionEventHelper().createPageEvent(ViewAction.VISIT_ADMIN_APPLICATION_SESSION_VIEW, ApplicationEventGroup.ADMIN,
137 				NAME, null, pageId);
138 
139 		return content;
140 
141 	}
142 
143 }