Project

General

Profile

« Previous | Next » 

Revision c7605112

Added by Fabian Reimeier about 6 years ago

ref #7241 modifications to use generic DelegatingErrorHandler

View differences:

src/main/java/eu/etaxonomy/cdm/i18n/Messages.java
53 53
    public static String DistributionToolbar_STATUS = "DistributionToolbar_STATUS";
54 54
    public static String DistributionToolbar_HELP = "DistributionToolbar_HELP";
55 55
    public static String HelpWindow_RESOURCE = "HelpWindow_RESOURCE";
56
    public static String PermissionDeniedErrorHandler_ERROR_MSG = "PermissionDeniedErrorHandler_ERROR_MSG";
56
    public static String HibernateExceptionHandler_PERMISSION_DENIED = "HibernateExceptionHandler_PERMISSION_DENIED";
57 57
    public static String SettingsDialogWindowBase_CANCEL = "SettingsDialogWindowBase_CANCEL";
58 58
    public static String SettingsDialogWindowBase_OK = "SettingsDialogWindowBase_OK";
59 59

  
src/main/java/eu/etaxonomy/cdm/vaadin/event/error/HibernateExceptionHandler.java
1
/**
2
* Copyright (C) 2018 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.event.error;
10

  
11
import org.hibernate.HibernateException;
12

  
13
import com.vaadin.server.ErrorEvent;
14
import com.vaadin.server.Page;
15
import com.vaadin.ui.Notification;
16

  
17
import eu.etaxonomy.cdm.database.PermissionDeniedException;
18
import eu.etaxonomy.cdm.i18n.Messages;
19

  
20
/**
21
 * @author freimeier
22
 *
23
 */
24
public class HibernateExceptionHandler extends ErrorTypeHandler<HibernateException>{
25

  
26
    private static final long serialVersionUID = -5703485298578474572L;
27

  
28
    /**
29
     * {@inheritDoc}
30
     */
31
    @Override
32
    public Class<HibernateException> supports() {
33
        return HibernateException.class;
34
    }
35

  
36
    /**
37
     * {@inheritDoc}
38
     */
39
    @Override
40
    public void error(ErrorEvent event) {
41
        // not needed in this class so far
42
    }
43

  
44
    @Override
45
    public void exception(HibernateException exception) {
46
        if(exception != null) {
47
            Notification notification = new Notification(exception.getMessage());
48
            if(exception.getCause() != null) {
49
                if(exception.getCause().getClass().equals(PermissionDeniedException.class)) {
50
                    notification = new Notification(Messages.getLocalizedString(Messages.HibernateExceptionHandler_PERMISSION_DENIED));
51
                }else {
52
                    notification = new Notification(exception.getCause().getMessage());
53
                }
54
            }
55
            notification.show(Page.getCurrent());
56
        }
57
    }
58

  
59

  
60

  
61
}
src/main/java/eu/etaxonomy/cdm/vaadin/event/error/HibernateSystemErrorHandler.java
1
// $Id$
2
/**
3
* Copyright (C) 2018 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.vaadin.event.error;
11

  
12
import org.springframework.orm.hibernate5.HibernateSystemException;
13

  
14
import com.vaadin.server.ErrorEvent;
15
import com.vaadin.ui.Notification;
16

  
17
import eu.etaxonomy.cdm.database.PermissionDeniedException;
18
import eu.etaxonomy.cdm.i18n.Messages;
19

  
20
/**
21
 * @author freimeier
22
 *
23
 */
24
public class HibernateSystemErrorHandler extends ErrorTypeHandler<HibernateSystemException>{
25

  
26
    private static final long serialVersionUID = -5703485298578474572L;
27

  
28
    /**
29
     * {@inheritDoc}
30
     */
31
    @Override
32
    public Class<HibernateSystemException> supports() {
33
        return HibernateSystemException.class;
34
    }
35

  
36
    /**
37
     * {@inheritDoc}
38
     */
39
    @Override
40
    public void error(ErrorEvent event) {
41
        // not needed in this class so far
42
    }
43

  
44
    @Override
45
    public void exception(HibernateSystemException exception) {
46

  
47
        if(exception != null) {
48
            if(exception.getCause().getClass().equals(PermissionDeniedException.class)) {
49
                Notification.show(Messages.getLocalizedString(Messages.PermissionDeniedErrorHandler_ERROR_MSG));
50
            }else {
51
                Notification.show(exception.getCause().getMessage());
52
            }
53
        }
54
    }
55

  
56

  
57

  
58
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionTableViewBean.java
51 51
import eu.etaxonomy.cdm.vaadin.component.distributionStatus.HelpWindow;
52 52
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
53 53
import eu.etaxonomy.cdm.vaadin.event.error.DelegatingErrorHandler;
54
import eu.etaxonomy.cdm.vaadin.event.error.HibernateSystemErrorHandler;
54
import eu.etaxonomy.cdm.vaadin.event.error.HibernateExceptionHandler;
55 55
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
56 56
import eu.etaxonomy.cdm.vaadin.util.CdmQueryFactory;
57 57
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
......
174 174
                //popup window
175 175
                final Window popup = new Window(Messages.getLocalizedString(Messages.DistributionTableViewBean_CHOOSE_DISTRIBUTION_STATUS));
176 176
                DelegatingErrorHandler errorHandler = new DelegatingErrorHandler();
177
                errorHandler.registerHandler(new HibernateSystemErrorHandler());
177
                errorHandler.registerHandler(new HibernateExceptionHandler());
178 178
                popup.setErrorHandler(errorHandler);
179 179
                final ListSelect termSelect = new ListSelect();
180 180
                termSelect.setSizeFull();
......
241 241
		columnHeaders.remove(CdmQueryFactory.ID_COLUMN);
242 242
		columnHeaders.remove(CdmQueryFactory.UUID_COLUMN);
243 243
		columnHeaders.remove(CdmQueryFactory.CLASSIFICATION_COLUMN);
244
//		columnHeaders.sort(new Comparator<String>() {
245
//            @Override
246
//            public int compare(String o1, String o2) {
247
//                if(o1.equals(CdmQueryFactory.TAXON_COLUMN) || o2.equals(CdmQueryFactory.TAXON_COLUMN)) {
248
//                    return o1.equals(CdmQueryFactory.TAXON_COLUMN) ? -1 : 1;
249
//                }
250
//                if(o1.equals(CdmQueryFactory.RANK_COLUMN) || o2.equals(CdmQueryFactory.RANK_COLUMN)) {
251
//                    return o1.equals(CdmQueryFactory.RANK_COLUMN) ? -1 : 1;
252
//                }
253
//
254
//                // TODO: HACK FOR RL 2017, REMOVE AS SOON AS POSSIBLE
255
//                if(o1.equals("DE") || o1.equals("Deutschland")
256
//                        || o2.equals("DE") || o2.equals("Deutschland")) {
257
//                    return (o1.equals("DE") || o1.equals("Deutschland")) ? -1 : 1;
258
//                }
259
//
260
//                return o1.compareTo(o2);
261
//            }
262
//		});
263 244

  
264 245
		List<String> columnList = new ArrayList<>(columnHeaders);
265 246

  
src/main/resources/eu/etaxonomy/cdm/i18n/messages.properties
29 29
DistributionToolbar_STATUS=Status
30 30
DistributionToolbar_HELP=Help
31 31
HelpWindow_RESOURCE=help_en.html
32
PermissionDeniedErrorHandler_ERROR_MSG=You have no permission to do that!
32
HibernateExceptionHandler_PERMISSION_DENIED=You have no permission to do that!
33 33
SettingsDialogWindowBase_CANCEL=Cancel
34 34
SettingsDialogWindowBase_OK=OK
src/main/resources/eu/etaxonomy/cdm/i18n/messages_de.properties
29 29
DistributionToolbar_STATUS=Status
30 30
DistributionToolbar_HELP=Hilfe
31 31
HelpWindow_RESOURCE=help_de.html
32
PermissionDeniedErrorHandler_ERROR_MSG=Sie haben keine ausreichenden Berechtigungen, um diesen Vorgang auszuf?hren!
32
HibernateExceptionHandler_PERMISSION_DENIED=Sie haben keine ausreichenden Berechtigungen, um diesen Vorgang auszuf?hren!
33 33
SettingsDialogWindowBase_CANCEL=Abbrechen
34 34
SettingsDialogWindowBase_OK=OK

Also available in: Unified diff