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.common.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 import org.springframework.web.context.request.RequestContextHolder;
27
28 import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
29 import com.hack23.cia.service.api.action.application.RegisterUserRequest;
30 import com.hack23.cia.web.impl.ui.application.action.ViewAction;
31 import com.hack23.cia.web.impl.ui.application.views.common.viewnames.ApplicationPageMode;
32 import com.hack23.cia.web.impl.ui.application.views.common.viewnames.CommonsViews;
33 import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.RegisterUserClickListener;
34 import com.vaadin.data.util.BeanItem;
35 import com.vaadin.ui.Button.ClickListener;
36 import com.vaadin.ui.FormLayout;
37 import com.vaadin.ui.Layout;
38 import com.vaadin.ui.MenuBar;
39 import com.vaadin.ui.Panel;
40 import com.vaadin.ui.VerticalLayout;
41
42
43
44
45 @Component
46 public final class MainViewRegisterPageModContentFactoryImpl extends AbstractPageModContentFactoryImpl {
47
48
49 private static final String CITIZEN_INTELLIGENCE_AGENCY_MAIN = "Citizen Intelligence Agency::Main";
50
51
52 public static final String NAME = CommonsViews.MAIN_VIEW_NAME;
53
54
55
56
57 public MainViewRegisterPageModContentFactoryImpl() {
58 super();
59 }
60
61 @Override
62 public boolean matches(final String page, final String parameters) {
63 return NAME.equals(page)
64 && (!StringUtils.isEmpty(parameters) && parameters.contains(ApplicationPageMode.REGISTER.toString()));
65 }
66
67 @Secured({ "ROLE_ANONYMOUS" })
68 @Override
69 public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
70 final VerticalLayout content = createPanelContent();
71 final String pageId = getPageId(parameters);
72
73
74 getMenuItemFactory().createMainPageMenuBar(menuBar);
75
76 final VerticalLayout registerLayout = new VerticalLayout();
77 registerLayout.setSizeFull();
78
79 final Panel formPanel = new Panel();
80 formPanel.setSizeFull();
81
82 registerLayout.addComponent(formPanel);
83
84 final FormLayout formContent = new FormLayout();
85 formPanel.setContent(formContent);
86
87 final RegisterUserRequest reqisterRequest = new RegisterUserRequest();
88 reqisterRequest.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
89 reqisterRequest.setUsername("");
90 reqisterRequest.setEmail("");
91 reqisterRequest.setCountry("");
92 reqisterRequest.setUserpassword("");
93 final ClickListener reqisterListener = new RegisterUserClickListener(reqisterRequest);
94 getFormFactory().addRequestInputFormFields(formContent, new BeanItem<>(reqisterRequest),
95 RegisterUserRequest.class,
96 Arrays.asList(new String[] { "username", "email", "country", "userpassword" }), "Register",
97 reqisterListener);
98
99 content.addComponent(registerLayout);
100
101 panel.setCaption(CITIZEN_INTELLIGENCE_AGENCY_MAIN);
102 getPageActionEventHelper().createPageEvent(ViewAction.VISIT_MAIN_VIEW, ApplicationEventGroup.USER,
103 CommonsViews.MAIN_VIEW_NAME, parameters, pageId);
104
105 return content;
106
107 }
108
109 }