Project

General

Profile

« Previous | Next » 

Revision c4a57e04

Added by Andreas Müller almost 2 years ago

cleanup and rename RegistrationValidationException to TypeDesignationSetException

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/compare/term/OrderedTermComparator.java
22 22
    @Override
23 23
    public int compare(T o1, T o2) {
24 24
        if (o1 instanceof OrderedTermBase && o2 instanceof OrderedTermBase){
25
            OrderedTermBase odt1 = (OrderedTermBase) o1;
26
            OrderedTermBase odt2 = (OrderedTermBase) o2;
25
            OrderedTermBase odt1 = (OrderedTermBase<?>) o1;
26
            OrderedTermBase odt2 = (OrderedTermBase<?>) o2;
27 27
            if (odt1.getVocabulary().equals(odt2.getVocabulary())){
28 28
                return - odt1.compareTo(odt2);
29 29
            }else{
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/RegistrationWorkingSet.java
18 18

  
19 19
import org.joda.time.DateTime;
20 20

  
21
import eu.etaxonomy.cdm.api.service.exception.RegistrationValidationException;
21
import eu.etaxonomy.cdm.api.service.exception.TypeDesignationSetException;
22 22
import eu.etaxonomy.cdm.model.name.Registration;
23 23
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
24 24
import eu.etaxonomy.cdm.model.name.TaxonName;
......
49 49

  
50 50
    }
51 51

  
52
    public RegistrationWorkingSet(List<RegistrationDTO> registrationDTOs) throws RegistrationValidationException {
52
    public RegistrationWorkingSet(List<RegistrationDTO> registrationDTOs) throws TypeDesignationSetException {
53 53
        validateAndAddDTOs(registrationDTOs, null);
54 54
    }
55 55

  
56 56
    /**
57 57
     * @param candidated
58
     * @throws RegistrationValidationException
58
     * @throws TypeDesignationSetException
59 59
     *
60 60
     */
61
    private void validateAndAdd(Set<Registration> candidates) throws RegistrationValidationException {
61
    private void validateAndAdd(Set<Registration> candidates) throws TypeDesignationSetException {
62 62
        List<RegistrationDTO> dtos = new ArrayList<>(registrationDTOs.size());
63 63
        candidates.forEach(reg -> dtos.add(new RegistrationDTO(reg)));
64 64
        validateAndAddDTOs(dtos, null);
......
70 70
     * citation of the {@link TypeDesignations}. In case the citation is a section and this section is
71 71
     * having an in-reference the in-reference will be used instead.
72 72
     * Registration with a differing publication are not added to
73
     * the working set, instead a {@link RegistrationValidationException} is thrown which is a container for
73
     * the working set, instead a {@link TypeDesignationSetException} is thrown which is a container for
74 74
     * all validation problems.
75 75
     *
76 76
     * @param candidates
77 77
     * @param problems
78 78
     *    Problems detected in prior validation and processing passed to this method to be completed. Can be <code>null</code>.
79
     * @throws RegistrationValidationException
79
     * @throws TypeDesignationSetException
80 80
     */
81
    private void validateAndAddDTOs(List<RegistrationDTO> candidates, List<String> problems) throws RegistrationValidationException {
81
    private void validateAndAddDTOs(List<RegistrationDTO> candidates, List<String> problems) throws TypeDesignationSetException {
82 82
        if(problems == null){
83 83
            problems = new ArrayList<>();
84 84
        }
......
100 100
        }
101 101

  
102 102
        if(!problems.isEmpty()){
103
            throw new RegistrationValidationException("", problems);
103
            throw new TypeDesignationSetException("", problems);
104 104
        }
105 105

  
106 106
    }
......
122 122

  
123 123
    /**
124 124
     * @param reg
125
     * @throws RegistrationValidationException
125
     * @throws TypeDesignationSetException
126 126
     */
127
    public void add(Registration reg) throws RegistrationValidationException {
127
    public void add(Registration reg) throws TypeDesignationSetException {
128 128
        Set<Registration> candidates = new HashSet<>();
129 129
        candidates.add(reg);
130 130
        validateAndAdd(candidates);
131 131
    }
132 132

  
133
    public void add(RegistrationDTO regDTO) throws RegistrationValidationException {
133
    public void add(RegistrationDTO regDTO) throws TypeDesignationSetException {
134 134
        validateAndAddDTOs(Arrays.asList(regDTO), null);
135 135
    }
136 136

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/exception/DataChangeNoRollbackException.java
1
/**
2
* Copyright (C) 2009 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.api.service.exception;
10

  
11
import org.springframework.transaction.interceptor.DefaultTransactionAttribute;
12

  
13
/**
14
 * Base class for all exceptions occurring during data change actions within the service layer.
15
 * NOTE: This exception needs to be thrown before any data is saved to the session as it rather forces 
16
 * commit then rollback. This is intended behavior to avoid full transaction rollback within longer
17
 * transactions. This way we do not need an explicit method to check if a data change method will
18
 * succeed or fail.<BR>
19
 * To avoid rollback the class on purpose does not inherit from RuntimeException
20
 * as RuntimeException leads to rollback when using {@link DefaultTransactionAttribute#rollbackOn(Throwable)}
21
 * which is used by spring as default transaction attribute.
22
 * @author a.mueller
23
 * @since 13.10.2011
24
 *
25
 */
26
public class DataChangeNoRollbackException extends Exception {
27
	private static final long serialVersionUID = -5279586708452619581L;
28

  
29

  
30
	public DataChangeNoRollbackException() {
31
	}
32
	
33
	public DataChangeNoRollbackException(String message) {
34
		super(message);
35
	}
36

  
37

  
38
}
1
/**
2
* Copyright (C) 2009 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.api.service.exception;
10

  
11
import org.springframework.transaction.interceptor.DefaultTransactionAttribute;
12

  
13
/**
14
 * Base class for all exceptions occurring during data change actions within the service layer.
15
 * NOTE: This exception needs to be thrown before any data is saved to the session as it rather forces
16
 * commit then rollback. This is intended behavior to avoid full transaction rollback within longer
17
 * transactions. This way we do not need an explicit method to check if a data change method will
18
 * succeed or fail.<BR>
19
 * To avoid rollback the class on purpose does not inherit from RuntimeException
20
 * as RuntimeException leads to rollback when using {@link DefaultTransactionAttribute#rollbackOn(Throwable)}
21
 * which is used by spring as default transaction attribute.
22
 * @author a.mueller
23
 * @since 13.10.2011
24
 */
25
public class DataChangeNoRollbackException extends Exception {
26

  
27
    private static final long serialVersionUID = -5279586708452619581L;
28

  
29
	public DataChangeNoRollbackException() {
30
	}
31

  
32
	public DataChangeNoRollbackException(String message) {
33
		super(message);
34
	}
35
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/exception/HomotypicalGroupChangeException.java
1
/**
2
* Copyright (C) 2009 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.api.service.exception;
10

  
11

  
12
/**
13
 * Exception that is thrown when a name that is to be changed or deleted belongs to homotypical group
14
 * which may lead to inconsistent data. Only throw this exception if the inconsistency can not be
15
 * resolved automatically.
16
 * @author a.mueller
17
 * @since 14.10.2011
18
 *
19
 */
20
public class HomotypicalGroupChangeException extends DataChangeNoRollbackException {
21
	private static final long serialVersionUID = -294632690489123786L;
22

  
23
	public HomotypicalGroupChangeException(){
24
		super();
25
	}
26
	
27
	public HomotypicalGroupChangeException(String message){
28
		super(message);
29
	}
30
}
1
/**
2
* Copyright (C) 2009 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.api.service.exception;
10

  
11
/**
12
 * Exception that is thrown when a name that is to be changed or deleted belongs to homotypical group
13
 * which may lead to inconsistent data. Only throw this exception if the inconsistency can not be
14
 * resolved automatically.
15
 * @author a.mueller
16
 * @since 14.10.2011
17
 */
18
public class HomotypicalGroupChangeException extends DataChangeNoRollbackException {
19

  
20
	private static final long serialVersionUID = -294632690489123786L;
21

  
22
	public HomotypicalGroupChangeException(){
23
		super();
24
	}
25

  
26
	public HomotypicalGroupChangeException(String message){
27
		super(message);
28
	}
29
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/exception/ReferencedObjectUndeletableException.java
1
/**
2
* Copyright (C) 2009 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.api.service.exception;
10

  
11

  
12
/**
13
 * Exception that is thrown when an object that is to be deleted within a deleteXXX
14
 * method can not be deleted due to other objects referencing the given object.
15
 * @author a.mueller
16
 * @since 12.10.2011
17
 *
18
 */
19
public class ReferencedObjectUndeletableException extends DataChangeNoRollbackException {
20
	private static final long serialVersionUID = -7232205281413184907L;
21

  
22
	
23
	public ReferencedObjectUndeletableException(){
24
		super();
25
	}
26
	
27
	public ReferencedObjectUndeletableException(String message){
28
		super(message);
29
	}
30
}
1
/**
2
* Copyright (C) 2009 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.api.service.exception;
10

  
11
/**
12
 * Exception that is thrown when an object that is to be deleted within a deleteXXX
13
 * method can not be deleted due to other objects referencing the given object.
14
 *
15
 * @author a.mueller
16
 * @since 12.10.2011
17
 */
18
public class ReferencedObjectUndeletableException extends DataChangeNoRollbackException {
19

  
20
    private static final long serialVersionUID = -7232205281413184907L;
21

  
22
	public ReferencedObjectUndeletableException(){
23
		super();
24
	}
25

  
26
	public ReferencedObjectUndeletableException(String message){
27
		super(message);
28
	}
29
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/exception/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.api.service.exception;
10

  
11
import java.util.ArrayList;
12
import java.util.List;
13

  
14
/**
15
 * @author a.kohlbecker
16
 * @since Mar 23, 2017
17
 *
18
 */
19
@SuppressWarnings("serial")
20
public class RegistrationValidationException extends Exception {
21

  
22
    List<String> problems = new ArrayList<>();
23

  
24
    /**
25
     * @param message
26
     */
27
    public RegistrationValidationException(String message, List<String> problems) {
28
        super(message);
29
        this.problems = problems;
30
    }
31

  
32
    @Override
33
    public String getMessage() {
34
        StringBuffer sb = new StringBuffer(super.getMessage()).append(" - Problems:");
35
        problems.forEach(p -> sb.append("- ").append(p).append("\n"));
36
        return sb.toString();
37
    }
38

  
39
    public List<String> getProblems() {
40
        return problems;
41
    }
42

  
43

  
44
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/exception/TypeDesignationSetException.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.api.service.exception;
10

  
11
import java.util.ArrayList;
12
import java.util.List;
13

  
14
/**
15
 * @author a.kohlbecker
16
 * @since Mar 23, 2017
17
 */
18
@SuppressWarnings("serial")
19
public class TypeDesignationSetException extends Exception {
20

  
21
    private List<String> problems = new ArrayList<>();
22

  
23
    /**
24
     * @param message
25
     */
26
    public TypeDesignationSetException(String message, List<String> problems) {
27
        super(message);
28
        this.problems = problems;
29
    }
30

  
31
    @Override
32
    public String getMessage() {
33
        StringBuffer sb = new StringBuffer(super.getMessage()).append(" - Problems:");
34
        problems.forEach(p -> sb.append("- ").append(p).append("\n"));
35
        return sb.toString();
36
    }
37

  
38
    public List<String> getProblems() {
39
        return problems;
40
    }
41
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationSetContainer.java
22 22
import java.util.Set;
23 23
import java.util.UUID;
24 24

  
25
import eu.etaxonomy.cdm.api.service.exception.RegistrationValidationException;
25
import eu.etaxonomy.cdm.api.service.exception.TypeDesignationSetException;
26 26
import eu.etaxonomy.cdm.api.service.name.TypeDesignationSet.TypeDesignationSetType;
27 27
import eu.etaxonomy.cdm.compare.name.NullTypeDesignationStatus;
28 28
import eu.etaxonomy.cdm.compare.name.TypeDesignationStatusComparator;
......
130 130
// **************************** CONSTRUCTOR ***********************************/
131 131

  
132 132
    public TypeDesignationSetContainer(@SuppressWarnings("rawtypes") Collection<TypeDesignationBase> typeDesignations)
133
            throws RegistrationValidationException{
133
            throws TypeDesignationSetException{
134 134
    	this(typeDesignations, null);
135 135
    }
136 136

  
137 137
    public TypeDesignationSetContainer(@SuppressWarnings("rawtypes") Collection<TypeDesignationBase> typeDesignations,
138 138
            TaxonName typifiedName)
139
            throws RegistrationValidationException  {
139
            throws TypeDesignationSetException  {
140 140
        for (TypeDesignationBase<?> typeDes:typeDesignations){
141 141
            this.typeDesignations.put(typeDes.getUuid(), typeDes);
142 142
        }
143 143
        try {
144 144
        	findTypifiedName();
145
        }catch (RegistrationValidationException e) {
145
        }catch (TypeDesignationSetException e) {
146 146
        	if (typifiedName == null) {
147 147
        		throw e;
148 148
        	}
......
277 277
    }
278 278

  
279 279
    //TODO maybe not needed anymore
280
    protected static TypedEntityReference<? extends VersionableEntity> makeEntityReference(VersionableEntity baseEntity) {
280
    private static TypedEntityReference<? extends VersionableEntity> makeEntityReference(VersionableEntity baseEntity) {
281 281

  
282 282
        baseEntity = CdmBase.deproxy(baseEntity);
283 283
        String label = TypeDesignationSetFormatter.entityLabel(baseEntity);
......
321 321
    /**
322 322
     * FIXME use the validation framework validators to store the validation problems!!!
323 323
     *
324
     * @return
325
     * @throws RegistrationValidationException
324
     * @throws TypeDesignationSetException
326 325
     */
327
    private void findTypifiedName() throws RegistrationValidationException {
326
    private void findTypifiedName() throws TypeDesignationSetException {
328 327

  
329 328
        List<String> problems = new ArrayList<>();
330 329

  
......
357 356
        }
358 357
        if(!problems.isEmpty()){
359 358
            // FIXME use the validation framework
360
            throw new RegistrationValidationException("Inconsistent type designations", problems);
359
            throw new TypeDesignationSetException("Inconsistent type designations", problems);
361 360
        }
362 361

  
363 362
        if(typifiedName != null){
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/registration/IRegistrationWorkingSetService.java
16 16

  
17 17
import eu.etaxonomy.cdm.api.service.dto.RegistrationDTO;
18 18
import eu.etaxonomy.cdm.api.service.dto.RegistrationWorkingSet;
19
import eu.etaxonomy.cdm.api.service.exception.RegistrationValidationException;
19
import eu.etaxonomy.cdm.api.service.exception.TypeDesignationSetException;
20 20
import eu.etaxonomy.cdm.api.service.pager.Pager;
21 21
import eu.etaxonomy.cdm.database.PermissionDeniedException;
22 22
import eu.etaxonomy.cdm.model.name.Registration;
......
50 50
     * @return
51 51
     */
52 52
    @Deprecated
53
    public RegistrationWorkingSet loadWorkingSetByReferenceID(Integer referenceID, boolean resolveSections) throws RegistrationValidationException;
53
    public RegistrationWorkingSet loadWorkingSetByReferenceID(Integer referenceID, boolean resolveSections) throws TypeDesignationSetException;
54 54

  
55 55
    /**
56 56
     * Loads the working set specified by the <code>referenceUuid</code> from the database. The list of {@link RegistrationDTO}s can be empty in case
......
61 61
     *  use the inReference which is the journal article.
62 62
     * @return
63 63
     */
64
    public RegistrationWorkingSet loadWorkingSetByReferenceUuid(UUID referenceUuid, boolean resolveSections) throws RegistrationValidationException, PermissionDeniedException;
64
    public RegistrationWorkingSet loadWorkingSetByReferenceUuid(UUID referenceUuid, boolean resolveSections) throws TypeDesignationSetException, PermissionDeniedException;
65 65

  
66 66
    public Set<RegistrationDTO> loadBlockingRegistrations(UUID blockedRegistrationUuid);
67 67

  
......
77 77
            String taxonNameFilterPattern, MatchMode matchMode, Integer pageSize, Integer pageIndex,
78 78
            List<OrderHint> orderHints);
79 79

  
80
    public Pager<RegistrationDTO> pageWorkingSetsByNameUUID(Collection<UUID> taxonNameUuids, Integer pageIndex, Integer pageSize, List<OrderHint> orderHints) throws RegistrationValidationException, PermissionDeniedException;
80
    public Pager<RegistrationDTO> pageWorkingSetsByNameUUID(Collection<UUID> taxonNameUuids, Integer pageIndex, Integer pageSize, List<OrderHint> orderHints) throws TypeDesignationSetException, PermissionDeniedException;
81 81
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/registration/RegistrationWorkingSetService.java
30 30
import eu.etaxonomy.cdm.api.application.CdmRepository;
31 31
import eu.etaxonomy.cdm.api.service.dto.RegistrationDTO;
32 32
import eu.etaxonomy.cdm.api.service.dto.RegistrationWorkingSet;
33
import eu.etaxonomy.cdm.api.service.exception.RegistrationValidationException;
33
import eu.etaxonomy.cdm.api.service.exception.TypeDesignationSetException;
34 34
import eu.etaxonomy.cdm.api.service.pager.Pager;
35 35
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
36 36
import eu.etaxonomy.cdm.api.util.UserHelper;
......
262 262

  
263 263
    /**
264 264
     * {@inheritDoc}
265
     * @throws RegistrationValidationException
265
     * @throws TypeDesignationSetException
266 266
     */
267 267
    @Override
268
    public RegistrationWorkingSet loadWorkingSetByReferenceUuid(UUID referenceUuid, boolean resolveSections) throws RegistrationValidationException, PermissionDeniedException {
268
    public RegistrationWorkingSet loadWorkingSetByReferenceUuid(UUID referenceUuid, boolean resolveSections) throws TypeDesignationSetException, PermissionDeniedException {
269 269

  
270 270
        Reference reference = repo.getReferenceService().load(referenceUuid); // needed to use load to avoid the problem described in #7331
271 271
        if(resolveSections){
......
356 356

  
357 357
    /**
358 358
     * {@inheritDoc}
359
     * @throws RegistrationValidationException
359
     * @throws TypeDesignationSetException
360 360
     */
361 361
    @Override
362
    public RegistrationWorkingSet loadWorkingSetByReferenceID(Integer referenceID, boolean resolveSections) throws RegistrationValidationException, PermissionDeniedException {
362
    public RegistrationWorkingSet loadWorkingSetByReferenceID(Integer referenceID, boolean resolveSections) throws TypeDesignationSetException, PermissionDeniedException {
363 363

  
364 364
        Reference reference = repo.getReferenceService().find(referenceID);
365 365
        if(resolveSections){
......
379 379
    }
380 380

  
381 381
    @Override
382
    public Pager<RegistrationDTO> pageWorkingSetsByNameUUID(Collection<UUID> taxonNameUuids, Integer pageIndex, Integer pageSize, List<OrderHint> orderHints) throws RegistrationValidationException, PermissionDeniedException {
382
    public Pager<RegistrationDTO> pageWorkingSetsByNameUUID(Collection<UUID> taxonNameUuids, Integer pageIndex, Integer pageSize, List<OrderHint> orderHints) throws TypeDesignationSetException, PermissionDeniedException {
383 383

  
384 384
        if(orderHints == null){
385 385
            orderHints = Arrays.asList(new OrderHint("identifier", SortOrder.ASCENDING));
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationSetContainerTest.java
20 20
import org.junit.Before;
21 21
import org.junit.Test;
22 22

  
23
import eu.etaxonomy.cdm.api.service.exception.RegistrationValidationException;
23
import eu.etaxonomy.cdm.api.service.exception.TypeDesignationSetException;
24 24
import eu.etaxonomy.cdm.model.agent.Person;
25 25
import eu.etaxonomy.cdm.model.agent.Team;
26 26
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
......
181 181
        }
182 182

  
183 183
        @Test
184
        public void test1() throws RegistrationValidationException{
184
        public void test1() throws TypeDesignationSetException{
185 185

  
186 186
            @SuppressWarnings("rawtypes")
187 187
            List<TypeDesignationBase> tds = new ArrayList<>();

Also available in: Unified diff