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.user.document.pagemode;
20  
21  import org.apache.commons.lang3.StringUtils;
22  import org.springframework.security.access.annotation.Secured;
23  import org.springframework.stereotype.Component;
24  
25  import com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentElement;
26  import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentData;
27  import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentData_;
28  import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentDetailData;
29  import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentStatusContainer;
30  import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentStatusContainer_;
31  import com.hack23.cia.model.external.riksdagen.utskottsforslag.impl.CommitteeProposalComponentData;
32  import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
33  import com.hack23.cia.service.api.DataContainer;
34  import com.hack23.cia.web.impl.ui.application.action.ViewAction;
35  import com.hack23.cia.web.impl.ui.application.views.common.labelfactory.LabelFactory;
36  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.DocumentPageMode;
37  import com.vaadin.data.util.BeanItemContainer;
38  import com.vaadin.ui.Layout;
39  import com.vaadin.ui.MenuBar;
40  import com.vaadin.ui.Panel;
41  import com.vaadin.ui.VerticalLayout;
42  
43  /**
44   * The Class DocumentDetailsPageModContentFactoryImpl.
45   */
46  @Component
47  public final class DocumentDetailsPageModContentFactoryImpl extends AbstractDocumentPageModContentFactoryImpl {
48  
49  	/** The Constant DOCUMENT_DETAILS. */
50  	private static final String DOCUMENT_DETAILS = "Document Details";
51  
52  	/**
53  	 * Instantiates a new document details page mod content factory impl.
54  	 */
55  	public DocumentDetailsPageModContentFactoryImpl() {
56  		super();
57  	}
58  
59  	@Override
60  	public boolean matches(final String page, final String parameters) {
61  		return NAME.equals(page) && (!StringUtils.isEmpty(parameters)
62  				&& parameters.contains(DocumentPageMode.DOCUMENTDETAILS.toString()));
63  	}
64  
65  	@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
66  	@Override
67  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
68  		final VerticalLayout panelContent = createPanelContent();
69  
70  		final String pageId = getPageId(parameters);
71  
72  		final DataContainer<DocumentElement, String> documentElementDataContainer = getApplicationManager()
73  				.getDataContainer(DocumentElement.class);
74  
75  		final DataContainer<DocumentStatusContainer, String> documentStatusContainerDataContainer = getApplicationManager()
76  				.getDataContainer(DocumentStatusContainer.class);
77  
78  		getApplicationManager().getDataContainer(CommitteeProposalComponentData.class);
79  
80  		final DocumentElement documentElement = documentElementDataContainer.load(pageId);
81  
82  		if (documentElement != null) {
83  
84  			getDocumentMenuItemFactory().createDocumentMenuBar(menuBar, pageId);
85  
86  			final DocumentStatusContainer documentStatusContainer = documentStatusContainerDataContainer
87  					.findByQueryProperty(DocumentStatusContainer.class, DocumentStatusContainer_.document,
88  							DocumentData.class, DocumentData_.id, pageId);
89  
90  			LabelFactory.createHeader2Label(panelContent,DOCUMENT_DETAILS);
91  
92  
93  			if (documentStatusContainer != null && documentStatusContainer.getDocumentDetailContainer() != null
94  					&& documentStatusContainer.getDocumentDetailContainer().getDocumentDetailList() != null) {
95  				final BeanItemContainer<DocumentDetailData> documentDetailDataDataDataSource = new BeanItemContainer<>(
96  						DocumentDetailData.class,
97  						documentStatusContainer.getDocumentDetailContainer().getDocumentDetailList());
98  
99  				getGridFactory().createBasicBeanItemGrid(
100 						panelContent, documentDetailDataDataDataSource,
101 						"Document details", new String[] { "code", "detailName", "text" }, new String[] { "hjid" }, null, null, null);
102 			}
103 
104 			panel.setContent(panelContent);
105 			getPageActionEventHelper().createPageEvent(ViewAction.VISIT_DOCUMENT_VIEW, ApplicationEventGroup.USER, NAME,
106 					parameters, pageId);
107 		}
108 
109 		return panelContent;
110 
111 	}
112 
113 }