Project

General

Profile

Download (2.37 KB) Statistics
| Branch: | Tag: | Revision:
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.validation;
10

    
11
import java.util.Set;
12

    
13
import javax.validation.ConstraintViolation;
14

    
15
import org.springframework.transaction.TransactionStatus;
16

    
17
import eu.etaxonomy.cdm.api.application.ICdmRepository;
18
import eu.etaxonomy.cdm.model.common.CdmBase;
19
import eu.etaxonomy.cdm.model.common.ICdmBase;
20
import eu.etaxonomy.cdm.model.validation.CRUDEventType;
21
import eu.etaxonomy.cdm.persistence.dao.validation.IEntityValidationCrud;
22
import eu.etaxonomy.cdm.persistence.validation.Level3ValidationTask;
23

    
24
/**
25
 * A {@link Runnable} performing Level-3 validation of a JPA entity
26
 *
27
 * @author ayco_holleman
28
 *
29
 */
30
class Level3TransactionalValidationTask extends Level3ValidationTask {
31

    
32
    private ICdmRepository repository;
33

    
34
    public Level3TransactionalValidationTask(CdmBase entity, IEntityValidationCrud dao) {
35
        super(entity, dao);
36
    }
37

    
38
    public Level3TransactionalValidationTask(ICdmBase entity, CRUDEventType crudEventType, IEntityValidationCrud dao, ICdmRepository repository) {
39
        super(entity, crudEventType, dao);
40
        this.repository = repository;
41
    }
42

    
43
    @Override
44
    protected Set<ConstraintViolation<ICdmBase>> validateWithErrorHandling() {
45
        if (repository != null){
46
            TransactionStatus tx = repository.startTransaction(true);
47
            //TODO what if getEntity() is not CdmBase?
48
            CdmBase cdmBase = CdmBase.deproxy(getEntity(), CdmBase.class);
49
            repository.getCommonService().find(cdmBase.getClass(), cdmBase.getId());
50
            //was "create Entity in 2 open sessions" error
51
            //not sure if the above works, should set the entity, but allowing to do so is critical the id is part of hash function, so we have to make sure that only entities with the same id can be replaced
52
//            repository.getCommonService().updateEntity(cdmBase);
53
            Set<ConstraintViolation<ICdmBase>> result = super.validateWithErrorHandling();
54
            repository.commitTransaction(tx);
55
            return result;
56
        }else{
57
            return super.validateWithErrorHandling();
58
        }
59
    }
60

    
61
}
(2-2/3)