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 java.util.Arrays;
22  
23  import org.apache.commons.lang3.StringUtils;
24  import org.springframework.security.access.annotation.Secured;
25  import org.springframework.stereotype.Component;
26  
27  import com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentElement;
28  import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentData;
29  import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentData_;
30  import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentStatusContainer;
31  import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentStatusContainer_;
32  import com.hack23.cia.model.external.riksdagen.utskottsforslag.impl.CommitteeProposalComponentData;
33  import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
34  import com.hack23.cia.service.api.DataContainer;
35  import com.hack23.cia.web.impl.ui.application.action.ViewAction;
36  import com.hack23.cia.web.impl.ui.application.views.common.labelfactory.LabelFactory;
37  import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentRatio;
38  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.PageMode;
39  import com.vaadin.data.util.BeanItem;
40  import com.vaadin.ui.Layout;
41  import com.vaadin.ui.MenuBar;
42  import com.vaadin.ui.Panel;
43  import com.vaadin.ui.VerticalLayout;
44  
45  /**
46   * The Class DocumentOverviewPageModContentFactoryImpl.
47   */
48  @Component
49  public final class DocumentOverviewPageModContentFactoryImpl extends AbstractDocumentPageModContentFactoryImpl {
50  
51  	/** The Constant OVERVIEW. */
52  	private static final String OVERVIEW = "overview";
53  
54  	/**
55  	 * Instantiates a new document overview page mod content factory impl.
56  	 */
57  	public DocumentOverviewPageModContentFactoryImpl() {
58  		super();
59  	}
60  
61  	@Override
62  	public boolean matches(final String page, final String parameters) {
63  		final String pageId = getPageId(parameters);
64  		return NAME.equals(page) && (StringUtils.isEmpty(parameters) || parameters.equals(pageId)
65  				|| parameters.contains(PageMode.OVERVIEW.toString()));
66  	}
67  
68  	@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
69  	@Override
70  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
71  		final VerticalLayout panelContent = createPanelContent();
72  
73  		final String pageId = getPageId(parameters);
74  
75  		final DataContainer<DocumentElement, String> documentElementDataContainer = getApplicationManager()
76  				.getDataContainer(DocumentElement.class);
77  
78  		final DataContainer<DocumentStatusContainer, String> documentStatusContainerDataContainer = getApplicationManager()
79  				.getDataContainer(DocumentStatusContainer.class);
80  
81  		getApplicationManager().getDataContainer(CommitteeProposalComponentData.class);
82  
83  		final DocumentElement documentElement = documentElementDataContainer.load(pageId);
84  
85  		if (documentElement != null) {
86  
87  			getDocumentMenuItemFactory().createDocumentMenuBar(menuBar, pageId);
88  
89  			final DocumentStatusContainer documentStatusContainer = documentStatusContainerDataContainer
90  					.findByQueryProperty(DocumentStatusContainer.class, DocumentStatusContainer_.document,
91  							DocumentData.class, DocumentData_.id, pageId);
92  
93  			LabelFactory.createHeader2Label(panelContent,OVERVIEW);
94  
95  			final VerticalLayout overviewLayout = new VerticalLayout();
96  			overviewLayout.setSizeFull();
97  
98  			panelContent.addComponent(overviewLayout);
99  			panelContent.setExpandRatio(overviewLayout, ContentRatio.LARGE_FORM);
100 
101 			getDocumentMenuItemFactory().createOverviewPage(overviewLayout, pageId);
102 
103 			getFormFactory().addFormPanelTextFields(panelContent, new BeanItem<>(documentElement), DocumentElement.class,
104 					Arrays.asList(new String[] { "id", "org", "documentType", "subType", "rm", "status", "title",
105 							"subTitle", "madePublicDate", "createdDate", "systemDate", "relatedId", "label",
106 							"tempLabel", "numberValue", "kallId", "documentFormat" }));
107 
108 
109 			if (documentStatusContainer != null) {
110 				getFormFactory().addFormPanelTextFields(panelContent, new BeanItem<>(documentStatusContainer),
111 						DocumentStatusContainer.class, Arrays.asList(new String[] { "documentCategory" }));
112 
113 				getFormFactory()
114 						.addFormPanelTextFields(panelContent, new BeanItem<>(documentStatusContainer.getDocument()),
115 								DocumentData.class,
116 								Arrays.asList(new String[] { "id", "org", "documentType", "subType", "rm", "status",
117 										"title", "subTitle", "madePublicDate", "label", "tempLabel", "numberValue",
118 										"hangarId", }));
119 			}
120 
121 			panel.setContent(panelContent);
122 			getPageActionEventHelper().createPageEvent(ViewAction.VISIT_DOCUMENT_VIEW, ApplicationEventGroup.USER, NAME,
123 					parameters, pageId);
124 		}
125 
126 		return panelContent;
127 
128 	}
129 
130 }