Project

General

Profile

Revision 7ccaf356

ID7ccaf3562708dc92374ebb9b54bd7b5e93f13734
Parent 35a1b7c4
Child c41c3457

Added by Andreas Müller 2 months ago

ref #6581 adapt TaxonGraphBeforeTransactionCompleteProcess to nomenclaturalSource

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/taxonGraph/TaxonGraphBeforeTransactionCompleteProcess.java
8 8
*/
9 9
package eu.etaxonomy.cdm.api.service.taxonGraph;
10 10

  
11
import java.lang.reflect.InvocationTargetException;
11 12
import java.util.Objects;
12 13

  
14
import org.apache.commons.beanutils.BeanUtils;
13 15
import org.apache.commons.lang.ArrayUtils;
14 16
import org.apache.log4j.Level;
15 17
import org.apache.log4j.Logger;
......
41 43
    private static final Logger logger = Logger.getLogger(TaxonGraphBeforeTransactionCompleteProcess.class);
42 44

  
43 45
    private String[] NAMEPARTS_OR_RANK_PROPS = new String[]{"genusOrUninomial", "specificEpithet", "rank"};
44
    private String[] NOMREF_PROP = new String[]{"nomenclaturalSource.citation"};
46
    private String NOMREF_PROP = "nomenclaturalSource.citation";
45 47

  
46 48
    private Session temporarySession;
47 49

  
......
92 94
                    onNameOrRankChange(entity);
93 95
                    getSession().flush();
94 96
                }
95
                int changedNomRefIndex = checkStateChange(NOMREF_PROP);
97
                int changedNomRefIndex = checkStateChangeNomRef(NOMREF_PROP);
96 98
                if(changedNomRefIndex > -1){
97 99
                    createTempSession(session);
98 100
                    onNomReferenceChange(entity, (Reference)oldState[changedNomRefIndex]);
......
133 135
        throw new RuntimeException("TaxonName class misses at least one property of: " + ArrayUtils.toString(propertyNamesToCheck));
134 136
    }
135 137

  
138
    private int checkStateChangeNomRef(String propertyPath){
139

  
140
        if(oldState == null){
141
            return -1;
142
        }
143

  
144
        try {
145
            String[] path = propertyPath.split("\\.");
146
            for (int i=1; i < propertyNames.length; i++) {
147
                if(propertyNames[i].equals(path[0])){
148
                    if (oldState[i] == null && state[i] == null){
149
                        return -1;
150
                    }else{
151
                        //TODO make it recursive (until now only a 2 step path is allowed, but should be enough for the given use-case)
152
                        Object oldStatePathObj = (oldState[i]==null) ? null: BeanUtils.getProperty(oldState[i],path[1]);
153
                        Object newStatePathObj = (state[i]==null) ? null: BeanUtils.getProperty(state[i],path[1]);
154
                        if (oldStatePathObj == null && newStatePathObj == null){
155
                            return -1;
156
                        }else{
157
                            if(!Objects.equals(oldStatePathObj, newStatePathObj)){
158
                                return 0;
159
                            }else{
160
                                return -1;
161
                            }
162
                        }
163
                    }
164
                }
165
            }
166
        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
167
            throw new RuntimeException("The nomenclatural reference path seems to be invalid: " + propertyPath);
168
        }
169
        // this exception should be raised during the unit tests already and thus will never occur in production
170
        throw new RuntimeException("TaxonName class misses at least one property of: " + propertyPath);
171
    }
172

  
136 173
    /**
137 174
     * Concept of creation of sub-sessions found in AuditProcess.doBeforeTransactionCompletion(SessionImplementor session)
138 175
     * and adapted to make it work for this case.

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)