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.DocumentReferenceData;
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 DocumentReferencesPageModContentFactoryImpl.
45   */
46  @Component
47  public final class DocumentReferencesPageModContentFactoryImpl extends AbstractDocumentPageModContentFactoryImpl {
48  
49  	/** The Constant DOCUMENT_REFERENCES. */
50  	private static final String DOCUMENT_REFERENCES = "Document References";
51  
52  
53  
54  	/**
55  	 * Instantiates a new document references page mod content factory impl.
56  	 */
57  	public DocumentReferencesPageModContentFactoryImpl() {
58  		super();
59  	}
60  
61  	@Override
62  	public boolean matches(final String page, final String parameters) {
63  		return NAME.equals(page) && (!StringUtils.isEmpty(parameters) && parameters.contains(DocumentPageMode.DOCUMENTREFERENCES.toString()));
64  	}
65  
66  	@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
67  	@Override
68  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
69  		final VerticalLayout panelContent = createPanelContent();
70  
71  		final String pageId = getPageId(parameters);
72  
73  		final DataContainer<DocumentElement, String> documentElementDataContainer = getApplicationManager()
74  				.getDataContainer(DocumentElement.class);
75  
76  		final DataContainer<DocumentStatusContainer, String> documentStatusContainerDataContainer = getApplicationManager()
77  				.getDataContainer(DocumentStatusContainer.class);
78  
79  		getApplicationManager()
80  				.getDataContainer(CommitteeProposalComponentData.class);
81  
82  		final DocumentElement documentElement = documentElementDataContainer.load(pageId);
83  
84  		if (documentElement != null) {
85  
86  			getDocumentMenuItemFactory().createDocumentMenuBar(menuBar, pageId);
87  
88  			final DocumentStatusContainer documentStatusContainer = documentStatusContainerDataContainer
89  					.findByQueryProperty(DocumentStatusContainer.class, DocumentStatusContainer_.document,
90  							DocumentData.class, DocumentData_.id, pageId);
91  
92  
93  
94  
95  			LabelFactory.createHeader2Label(panelContent,DOCUMENT_REFERENCES);
96  
97  
98  			if (documentStatusContainer != null
99  					&& documentStatusContainer.getDocumentReferenceContainer() != null
100 					&& documentStatusContainer.getDocumentReferenceContainer()
101 							.getDocumentReferenceList() != null) {
102 				final BeanItemContainer<DocumentReferenceData> documentReferenceDataDataSource = new BeanItemContainer<>(
103 						DocumentReferenceData.class,
104 						documentStatusContainer.getDocumentReferenceContainer().getDocumentReferenceList());
105 
106 				getGridFactory().createBasicBeanItemGrid(
107 						panelContent, documentReferenceDataDataSource,
108 						"Document references",
109 						new String[] { "referenceType", "referenceDocumentId", "detail" }, new String[] { "hjid" }, null, null, null);
110 			}
111 
112 
113 			panel.setContent(panelContent);
114 			getPageActionEventHelper().createPageEvent(ViewAction.VISIT_DOCUMENT_VIEW, ApplicationEventGroup.USER, NAME, parameters, pageId);
115 		}
116 
117 		return panelContent;
118 
119 	}
120 
121 
122 }