Project

General

Profile

« Previous | Next » 

Revision eb1e36b8

Added by Andreas Müller almost 2 years ago

cleanup

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/validation/batch/BatchValidator.java
43 43
 * @author ayco_holleman
44 44
 * @author a.mueller
45 45
 * @since 27 jan. 2015
46
 *
47 46
 */
48 47
@Component("batchValidator")
49 48
public class BatchValidator implements Runnable, ApplicationContextAware {
......
73 72
        validate();
74 73
    }
75 74

  
76
    /**
77
     *
78
     */
79 75
    private void initValidator() {
80 76
        if (getValidator() == null){
81 77
            HibernateValidatorConfiguration config = Validation.byProvider(HibernateValidator.class).configure();
......
87 83
        }
88 84
    }
89 85

  
90

  
91

  
92 86
    private <T extends ICdmBase, S extends T> void validate() {
93 87
        logger.info("Starting batch validation");
94 88

  
......
130 124

  
131 125
    }
132 126

  
133
    /**
134
     * @param readOnly
135
     * @return
136
     *
137
     */
138 127
    private TransactionStatus startTransaction(boolean readOnly) {
139 128
        PlatformTransactionManager txManager = getTransactionManager();
140 129

  
......
145 134
        return txStatus;
146 135
    }
147 136

  
148
    /**
149
     * @return
150
     */
151 137
    private PlatformTransactionManager getTransactionManager() {
152 138
        PlatformTransactionManager txManager = appContext.getBean(HibernateTransactionManager.class);
153 139
        return txManager;
......
162 148
        }
163 149
    }
164 150

  
165

  
166
    /**
167
     * @param commonService
168
     * @param entityClass
169
     * @param entityValidationService
170
     * @param jdbcPersister
171
     *
172
     */
173 151
    private void handlePage(ICommonService commonService, Class<CdmBase> entityClass, IEntityValidationService entityValidationService, EntityValidationCrudJdbcImpl jdbcPersister, int start, int pageSize) {
174 152

  
175 153
        List<CdmBase> entities;
......
298 276
    public void setValidationGroups(Class<?>... validationGroups) {
299 277
        this.validationGroups = validationGroups;
300 278
    }
301

  
302
}
279
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/validation/constraint/NoDuplicateNamesValidator.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.validation.constraint;
10

  
11
import java.util.HashSet;
12
import java.util.List;
13
import java.util.Objects;
14
import java.util.Set;
15
import java.util.stream.Collectors;
16

  
17
import javax.validation.ConstraintValidator;
18
import javax.validation.ConstraintValidatorContext;
19

  
20
import org.springframework.beans.factory.annotation.Autowired;
21

  
22
import eu.etaxonomy.cdm.api.service.INameService;
23
import eu.etaxonomy.cdm.model.name.TaxonName;
24
import eu.etaxonomy.cdm.validation.annotation.NoDuplicateNames;
25

  
26
public class NoDuplicateNamesValidator implements
27
		ConstraintValidator<NoDuplicateNames,TaxonName> {
28

  
29
	private static Set<String> includeProperties;
30

  
31
	static {
32
		includeProperties = new HashSet<>();
33
		includeProperties.add("genusOrUninomial");
34
		includeProperties.add("infraGenericEpithet");
35
		includeProperties.add("specificEpithet");
36
		includeProperties.add("infraSpecificEpithet");
37
		includeProperties.add("rank");
38
//		includeProperties.add("nomenclaturalSource.citation");   //handled in method now since #6581
39
//		includeProperties.add("nomenclaturalSource.citationMicroReference"); //handled in method now since #6581
40
		includeProperties.add("basionymAuthorship");
41
		includeProperties.add("exBasionymAuthorship");
42
		includeProperties.add("combinationAuthorship");
43
		includeProperties.add("exCombinationAuthorship");
44
	}
45

  
46
	private INameService nameService;
47

  
48
	@Autowired
49
	public void setNameService(INameService nameService) {
50
		this.nameService = nameService;
51
	}
52

  
53
	@Override
54
	public void initialize(NoDuplicateNames noDuplicateNames) { }
55

  
56
    @Override
57
	public boolean isValid(TaxonName name, ConstraintValidatorContext constraintContext) {
58
		if(name == null) {
59
			return true;
60
		} else {
61
			List<TaxonName> matchingNames = nameService.list(name, includeProperties, null, null, null, null);
62
			matchingNames = matchingNames.stream().filter(existing->
63
			           Objects.equals(existing.getNomenclaturalReference(),name.getNomenclaturalReference())
64
			        && Objects.equals(existing.getNomenclaturalMicroReference(), name.getNomenclaturalMicroReference())
65
			        && !existing.equals(name)
66
			    ).collect(Collectors.toList());
67

  
68
			if(matchingNames.size() > 0) {
69
			    if(matchingNames.size() == 1 && matchingNames.get(0).equals(name)) {
70
					return true;
71
				} else {
72
			        return false;
73
				}
74
			} else {
75
				return true;
76
			}
77
		}
78
	}
79
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/validation/constraint/NoDuplicateNamesValidator.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.validation.constraint;
10

  
11
import java.util.HashSet;
12
import java.util.List;
13
import java.util.Objects;
14
import java.util.Set;
15
import java.util.stream.Collectors;
16

  
17
import javax.validation.ConstraintValidator;
18
import javax.validation.ConstraintValidatorContext;
19

  
20
import org.springframework.beans.factory.annotation.Autowired;
21

  
22
import eu.etaxonomy.cdm.api.service.INameService;
23
import eu.etaxonomy.cdm.model.name.TaxonName;
24
import eu.etaxonomy.cdm.validation.annotation.NoDuplicateNames;
25

  
26
public class NoDuplicateNamesValidator implements
27
		ConstraintValidator<NoDuplicateNames,TaxonName> {
28

  
29
	private static Set<String> includeProperties;
30

  
31
	static {
32
		includeProperties = new HashSet<>();
33
		includeProperties.add("genusOrUninomial");
34
		includeProperties.add("infraGenericEpithet");
35
		includeProperties.add("specificEpithet");
36
		includeProperties.add("infraSpecificEpithet");
37
		includeProperties.add("rank");
38
//		includeProperties.add("nomenclaturalSource.citation");   //handled in method now since #6581
39
//		includeProperties.add("nomenclaturalSource.citationMicroReference"); //handled in method now since #6581
40
		includeProperties.add("basionymAuthorship");
41
		includeProperties.add("exBasionymAuthorship");
42
		includeProperties.add("combinationAuthorship");
43
		includeProperties.add("exCombinationAuthorship");
44
	}
45

  
46
	private INameService nameService;
47

  
48
	@Autowired
49
	public void setNameService(INameService nameService) {
50
		this.nameService = nameService;
51
	}
52

  
53
	@Override
54
	public void initialize(NoDuplicateNames noDuplicateNames) { }
55

  
56
    @Override
57
	public boolean isValid(TaxonName name, ConstraintValidatorContext constraintContext) {
58
		if(name == null) {
59
			return true;
60
		} else {
61
			List<TaxonName> matchingNames = nameService.list(name, includeProperties, null, null, null, null);
62
			matchingNames = matchingNames.stream().filter(existing->
63
			           Objects.equals(existing.getNomenclaturalReference(),name.getNomenclaturalReference())
64
			        && Objects.equals(existing.getNomenclaturalMicroReference(), name.getNomenclaturalMicroReference())
65
			        && !existing.equals(name)
66
			    ).collect(Collectors.toList());
67

  
68
			if(matchingNames.size() > 0) {
69
			    if(matchingNames.size() == 1 && matchingNames.get(0).equals(name)) {
70
					return true;
71
				} else {
72
			        return false;
73
				}
74
			} else {
75
				return true;
76
			}
77
		}
78
	}
79
}

Also available in: Unified diff