Revision 191308d3
Added by Andreas Kohlbecker about 7 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/event/AbstractEntityEvent.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.event; |
|
10 |
|
|
11 |
/** |
|
12 |
* @author a.kohlbecker |
|
13 |
* @since Mar 22, 2017 |
|
14 |
* |
|
15 |
*/ |
|
16 |
public abstract class AbstractEntityEvent { |
|
17 |
|
|
18 |
|
|
19 |
private EntityEventType eventType; |
|
20 |
|
|
21 |
public AbstractEntityEvent(EntityEventType eventType) { |
|
22 |
this.eventType = eventType; |
|
23 |
if(eventType == null){ |
|
24 |
throw new NullPointerException(); |
|
25 |
} |
|
26 |
} |
|
27 |
|
|
28 |
public EntityEventType getEventType() { |
|
29 |
return eventType; |
|
30 |
} |
|
31 |
|
|
32 |
public boolean isAddEvent() { |
|
33 |
return eventType.equals(EntityEventType.ADD); |
|
34 |
} |
|
35 |
public boolean isEditEvent() { |
|
36 |
return eventType.equals(EntityEventType.EDIT); |
|
37 |
} |
|
38 |
public boolean isRemoveEvent() { |
|
39 |
return eventType.equals(EntityEventType.REMOVE); |
|
40 |
} |
|
41 |
|
|
42 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/event/EntityEventType.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.event; |
|
10 |
|
|
11 |
/** |
|
12 |
* @author a.kohlbecker |
|
13 |
* @since Mar 22, 2017 |
|
14 |
* |
|
15 |
*/ |
|
16 |
public enum EntityEventType { |
|
17 |
|
|
18 |
ADD, |
|
19 |
EDIT, |
|
20 |
REMOVE; |
|
21 |
|
|
22 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/event/ReferenceEvent.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.event; |
|
10 |
|
|
11 |
/** |
|
12 |
* @author a.kohlbecker |
|
13 |
* @since Mar 22, 2017 |
|
14 |
* |
|
15 |
*/ |
|
16 |
public class ReferenceEvent extends AbstractEntityEvent { |
|
17 |
|
|
18 |
|
|
19 |
public ReferenceEvent(EntityEventType eventType) { |
|
20 |
super(eventType); |
|
21 |
} |
|
22 |
|
|
23 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/event/TaxonNameEvent.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.event; |
|
10 |
|
|
11 |
/** |
|
12 |
* @author a.kohlbecker |
|
13 |
* @since Mar 22, 2017 |
|
14 |
* |
|
15 |
*/ |
|
16 |
public class TaxonNameEvent extends AbstractEntityEvent { |
|
17 |
|
|
18 |
|
|
19 |
public TaxonNameEvent(EntityEventType eventType) { |
|
20 |
super(eventType); |
|
21 |
} |
|
22 |
|
|
23 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/event/TypeDesignationEvent.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.event; |
|
10 |
|
|
11 |
/** |
|
12 |
* @author a.kohlbecker |
|
13 |
* @since Mar 22, 2017 |
|
14 |
* |
|
15 |
*/ |
|
16 |
public class TypeDesignationEvent extends AbstractEntityEvent { |
|
17 |
|
|
18 |
|
|
19 |
public TypeDesignationEvent(EntityEventType eventType) { |
|
20 |
super(eventType); |
|
21 |
} |
|
22 |
|
|
23 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/model/registration/RegistrationWorkingSet.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.model.registration; |
|
10 |
|
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.HashSet; |
|
13 |
import java.util.List; |
|
14 |
import java.util.Set; |
|
15 |
|
|
16 |
import eu.etaxonomy.cdm.mock.Registration; |
|
17 |
import eu.etaxonomy.cdm.vaadin.presenter.registration.RegistrationDTO; |
|
18 |
import eu.etaxonomy.cdm.vaadin.presenter.registration.RegistrationValidationException; |
|
19 |
|
|
20 |
/** |
|
21 |
* @author a.kohlbecker |
|
22 |
* @since Mar 22, 2017 |
|
23 |
* |
|
24 |
*/ |
|
25 |
public class RegistrationWorkingSet { |
|
26 |
|
|
27 |
private Set<Registration> registrations = new HashSet<>(); |
|
28 |
|
|
29 |
private int citationId = -1; |
|
30 |
|
|
31 |
private String citation = null; |
|
32 |
|
|
33 |
public RegistrationWorkingSet(Set<Registration> registrations) throws RegistrationValidationException { |
|
34 |
|
|
35 |
validateAndAdd(registrations); |
|
36 |
} |
|
37 |
|
|
38 |
/** |
|
39 |
* @param candidated |
|
40 |
* @throws RegistrationValidationException |
|
41 |
* |
|
42 |
*/ |
|
43 |
private void validateAndAdd(Set<Registration> candidated) throws RegistrationValidationException { |
|
44 |
List<String> problems = new ArrayList<>(); |
|
45 |
for(Registration reg : candidated){ |
|
46 |
try { |
|
47 |
RegistrationDTO regDto = new RegistrationDTO(reg); |
|
48 |
if(citationId == -1){ |
|
49 |
citationId = regDto.getCitationID(); |
|
50 |
citation = regDto.getCitation(); |
|
51 |
} else { |
|
52 |
if(regDto.getCitationID() != citationId){ |
|
53 |
problems.add("Removing Registration " + reg.toString() + " from set since this refers to a different citation.\n"); |
|
54 |
continue; |
|
55 |
} |
|
56 |
} |
|
57 |
this.registrations.add(reg); |
|
58 |
|
|
59 |
} catch (RegistrationValidationException e) { |
|
60 |
problems.add(e.getMessage()); |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
64 |
if(!problems.isEmpty()){ |
|
65 |
throw new RegistrationValidationException(problems.toString()); |
|
66 |
} |
|
67 |
|
|
68 |
} |
|
69 |
|
|
70 |
public boolean add(Registration registration){ |
|
71 |
return registrations.add(registration); |
|
72 |
} |
|
73 |
|
|
74 |
/** |
|
75 |
* @return the registrations |
|
76 |
*/ |
|
77 |
public Set<Registration> getRegistrations() { |
|
78 |
return registrations; |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* @return the citationId |
|
83 |
*/ |
|
84 |
public int getCitationId() { |
|
85 |
return citationId; |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* @return the citation |
|
90 |
*/ |
|
91 |
public String getCitation() { |
|
92 |
return citation; |
|
93 |
} |
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/registration/RegistrationValidationException.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.presenter.registration; |
|
10 |
|
|
11 |
/** |
|
12 |
* @author a.kohlbecker |
|
13 |
* @since Mar 23, 2017 |
|
14 |
* |
|
15 |
*/ |
|
16 |
public class RegistrationValidationException extends Exception { |
|
17 |
|
|
18 |
/** |
|
19 |
* @param message |
|
20 |
*/ |
|
21 |
public RegistrationValidationException(String message) { |
|
22 |
super(message); |
|
23 |
} |
|
24 |
|
|
25 |
|
|
26 |
} |
Also available in: Unified diff
ref #6169 initial RegistrationWorkingSet implementation