1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.hack23.cia.web.impl.ui.application.views.user.document.pagemode;
20
21 import java.util.Arrays;
22
23 import org.springframework.security.access.annotation.Secured;
24 import org.springframework.stereotype.Component;
25 import org.springframework.web.context.request.RequestContextHolder;
26
27 import com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentElement;
28 import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
29 import com.hack23.cia.service.api.action.user.SearchDocumentRequest;
30 import com.hack23.cia.service.api.action.user.SearchDocumentResponse;
31 import com.hack23.cia.web.impl.ui.application.action.ViewAction;
32 import com.hack23.cia.web.impl.ui.application.views.common.pagemode.AbstractPageModContentFactoryImpl;
33 import com.hack23.cia.web.impl.ui.application.views.common.viewnames.UserViews;
34 import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.SearchDocumentClickListener;
35 import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.SearchDocumentResponseHandler;
36 import com.vaadin.data.util.BeanItem;
37 import com.vaadin.data.util.BeanItemContainer;
38 import com.vaadin.ui.Button.ClickListener;
39 import com.vaadin.ui.FormLayout;
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
47
48 @Component
49 public final class SearchDocumentPageModContentFactoryImpl extends AbstractPageModContentFactoryImpl {
50
51
52 public static final String NAME = UserViews.SEARCH_DOCUMENT_VIEW_NAME;
53
54
55 private static final int MAX_RESULT_SIZE = 100;
56
57
58
59
60 public SearchDocumentPageModContentFactoryImpl() {
61 super();
62 }
63
64 @Override
65 public boolean matches(final String page, final String parameters) {
66 return NAME.equals(page);
67 }
68
69 @Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
70 @Override
71 public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
72 final VerticalLayout panelContent = createPanelContent();
73
74 final String pageId = getPageId(parameters);
75
76 getMenuItemFactory().createMainPageMenuBar(menuBar);
77
78 final VerticalLayout searchLayout = new VerticalLayout();
79 searchLayout.setSizeFull();
80 panelContent.addComponent(searchLayout);
81
82 final VerticalLayout searchresultLayout = new VerticalLayout();
83 searchresultLayout.setSizeFull();
84
85 final Panel formPanel = new Panel();
86 formPanel.setSizeFull();
87
88 searchresultLayout.addComponent(formPanel);
89
90 final FormLayout formContent = new FormLayout();
91 formPanel.setContent(formContent);
92
93 panelContent.addComponent(searchresultLayout);
94
95 final SearchDocumentRequest searchRequest = new SearchDocumentRequest();
96 searchRequest.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
97 searchRequest.setMaxResults(MAX_RESULT_SIZE);
98 searchRequest.setSearchExpression("");
99 final SearchDocumentResponseHandler handler = new SearchDocumentResponseHandler() {
100
101
102 private static final long serialVersionUID = 1L;
103
104 @Override
105 public void handle(final SearchDocumentResponse response) {
106 searchresultLayout.removeAllComponents();
107
108 final BeanItemContainer<DocumentElement> documentActivityDataDataDataSource = new BeanItemContainer<>(
109 DocumentElement.class, response.getResultElement());
110
111 getGridFactory().createBasicBeanItemGrid(searchresultLayout, documentActivityDataDataDataSource,
112 "Document",
113 new String[] { "rm", "createdDate", "madePublicDate", "documentType", "subType", "title",
114 "subTitle", "status" },
115 new String[] { "label", "id", "hit", "relatedId", "org", "tempLabel", "numberValue",
116 "systemDate", "kallId", "documentFormat", "documentUrlText", "documentUrlHtml",
117 "documentStatusUrlXml", "committeeReportUrlXml" },
118 null, null, null);
119
120 }
121 };
122 final ClickListener searchListener = new SearchDocumentClickListener(searchRequest, handler);
123 getFormFactory().addRequestInputFormFields(formContent, new BeanItem<>(searchRequest),
124 SearchDocumentRequest.class, Arrays.asList(new String[] { "searchExpression" }), "Search",
125 searchListener);
126
127 getPageActionEventHelper().createPageEvent(ViewAction.VISIT_DOCUMENT_VIEW, ApplicationEventGroup.USER, NAME,
128 parameters, pageId);
129
130 return panelContent;
131
132 }
133
134 }