ref #7995 invoking Registration.updateStatusAndDate() from RegistrationEditorPresenter
[cdm-vaadin.git] / src / main / java / eu / etaxonomy / cdm / vaadin / view / RedirectToLoginView.java
1 /**
2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.cdm.vaadin.view;
10
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
13 import org.springframework.context.annotation.Scope;
14 import org.vaadin.spring.events.EventBus;
15
16 import com.vaadin.navigator.Navigator;
17 import com.vaadin.navigator.View;
18 import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
19 import com.vaadin.spring.annotation.SpringComponent;
20 import com.vaadin.ui.Alignment;
21 import com.vaadin.ui.Label;
22 import com.vaadin.ui.VerticalLayout;
23 import com.vaadin.ui.themes.ValoTheme;
24
25 import eu.etaxonomy.cdm.service.UserHelperAccess;
26 import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent;
27 import eu.etaxonomy.vaadin.ui.navigation.NavigationManager;
28
29 /**
30 * A {@link SpringViewProvider.setAccessDeniedViewClass(Class<? extends View> accessDeniedViewClass) accessDeniedViewClass}
31 * can not be a view- or UI-scoped bean, since the view context is not set up at the time when the <code>accessDeniedViewClass</code>
32 * is needed. Therefore the <code>RedirectToLoginView</code> is a scoped prototype bean which always available. Using the 'singleton'
33 * scope should also work but is not a good idea for a login view.
34 * The <code>RedirectToLoginView</code> redirects the request to the LoginView which then is in a correctly
35 * set up view scope.
36
37 *
38 * @author a.kohlbecker
39 * @since Jul 13, 2017
40 *
41 */
42 @SpringComponent
43 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
44 public class RedirectToLoginView extends VerticalLayout implements View {
45
46
47 private static final long serialVersionUID = -8763747518841365925L;
48
49 @Autowired
50 NavigationManager navigationManager;
51
52 @Autowired
53 protected EventBus.UIEventBus uiEventBus;
54
55 public RedirectToLoginView() {
56
57 this.setWidth("100%");
58 Label header = new Label("Access to this content is restricted");
59 header.setStyleName(ValoTheme.LABEL_FAILURE);
60 header.setWidthUndefined();
61
62 addComponent(header);
63 setComponentAlignment(header, Alignment.MIDDLE_CENTER);
64 }
65
66 /**
67 * {@inheritDoc}
68 */
69 @Override
70 public void enter(ViewChangeEvent event) {
71
72 if(!UserHelperAccess.userHelper().userIsAutheticated()){
73 String currentState = ((Navigator)navigationManager).getState();
74 // redirect to the login view and pass over the current state
75 uiEventBus.publish(this, new NavigationEvent(LoginViewBean.NAME, currentState));
76 }
77 }
78
79 }