Project

General

Profile

Revision b64acc4b

IDb64acc4ba5456e740d39ec3d2a26f6abd9b11a77
Parent c3d8375b
Child 39ad25f2

Added by Andreas Müller over 3 years ago

ref #6524 add reporting to distribution updater

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/distribution/excelupdate/ExcelDistributionUpdate.java
19 19
import org.springframework.stereotype.Component;
20 20

  
21 21
import eu.etaxonomy.cdm.common.CdmUtils;
22
import eu.etaxonomy.cdm.io.common.ImportResult;
22 23
import eu.etaxonomy.cdm.io.excel.common.ExcelImporterBase;
23 24
import eu.etaxonomy.cdm.model.common.CdmBase;
24 25
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
......
99 100
     */
100 101
    private void handleAreasForTaxon(ExcelDistributionUpdateState state, Taxon taxon, HashMap<String, String> record,
101 102
            String line) {
103
        ImportResult result = state.getResult();
102 104
        Map<NamedArea, Set<Distribution>> existingDistributions = getExistingDistributions(state, taxon, line);
103 105
        Map<NamedArea, Distribution> newDistributions = getNewDistributions(state, record, line);
104 106
        TaxonDescription newDescription = TaxonDescription.NewInstance();
105 107
        newDescription.addImportSource(null, null, state.getConfig().getSourceReference(), "row " + state.getCurrentLine());
106 108
        newDescription.setTitleCache("Updated distributions for " + getTaxonLabel(taxon), true);
107
        //TODO add reference
108 109
        Set<TaxonDescription> oldReducedDescriptions = new HashSet<>();
109 110
        for (NamedArea area : newDistributions.keySet()){
110 111
            Set<Distribution> existingDistrForArea = existingDistributions.get(area);
......
122 123
                        if (state.getConfig().isCreateNewDistribution() || newDistribution == null ){
123 124
                            DescriptionBase<?> inDescription = existingDistr.getInDescription();
124 125
                            inDescription.removeElement(existingDistr);
126
                            result.addDeletedRecord(existingDistr);
125 127
                            hasChange = true;
126 128
                            oldReducedDescriptions.add(CdmBase.deproxy(inDescription, TaxonDescription.class));
127 129
                        }else{
128 130
                            existingDistr.setStatus(newDistribution.getStatus());
131
                            result.addUpdatedRecord(existingDistr);
129 132
                            existingDistr.addImportSource(null, null, state.getConfig().getSourceReference(), "row "+state.getCurrentLine());
130 133
                        }
131 134
                    }else{
......
135 138
            }
136 139
            if (hasChange && newDistribution != null){
137 140
                newDescription.addElement(newDistribution);
141
                result.addNewRecord(newDistribution);
138 142
            }
139 143
        }
140 144
        //add new description to taxon if any new element exists
141 145
        if (!newDescription.getElements().isEmpty()){
142 146
            taxon.addDescription(newDescription);
147
            result.addNewRecord(newDescription);
143 148
        }
144 149
        //remove old empty descriptions (oldReducedDescriptions) if really empty
145 150
        for (TaxonDescription desc : oldReducedDescriptions){
146 151
            if (desc.getElements().isEmpty()){
147 152
                desc.getTaxon().removeDescription(desc);
153
                result.addDeletedRecord(desc);
148 154
            }
149 155
        }
150 156
    }
......
175 181
                    Distribution previousDistribution = result.put(area, distribution);
176 182
                    if (previousDistribution != null){
177 183
                        String message = line + "Multiple distributions exist for same area (" + area.getTitleCache() +  ") in input source";
184
                        logger.warn(message);
178 185
                        state.getResult().addWarning(message);
179 186
                    }
180 187
                }else{

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)