Project

General

Profile

« Previous | Next » 

Revision 94adeb1d

Added by Patrick Plitzner about 8 years ago

Handle Misapplications

  • speed up author loading

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/Namespace.java
18 18

  
19 19
    public static final String NAME_NAMESPACE = "name";
20 20
    public static final String TAXON_NAMESPACE = "taxon";
21
    public static final String AUTHOR_NAMESPACE = "author";
21 22
}
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportAuthor.java
93 93
    }
94 94

  
95 95
    private void makePerson(RedListGefaesspflanzenImportState state, String authorName) {
96
        //check if misapplied name
97
        if(authorName.trim().equals("auct.")){
98
            return;
99
        }
96 100
        TeamOrPersonBase teamOrPerson;
97 101
        //check if there are ex authors
98 102
        if(authorName.contains(" ex ")){
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportClassification.java
86 86
            e.printStackTrace();
87 87
        }
88 88

  
89
        logger.info("Update classification (1000 nodes)");
89 90
        getClassificationService().saveOrUpdate(classification);
90 91
        return true;
91 92
    }
......
99 100
        TaxonBase taxonBase = state.getRelatedObject(Namespace.TAXON_NAMESPACE, id, TaxonBase.class);
100 101
        Taxon parent = (Taxon) state.getRelatedObject(Namespace.TAXON_NAMESPACE, parentId, TaxonBase.class);
101 102

  
102
        if(taxonBase.isInstanceOf(Taxon.class)){
103
        //misapplied name
104
        if(taxonBase.getName().getAppendedPhrase().contains("auct.")){
105
            //TODO why can't I add synonymy as misapplications
106
//            parent.addMisappliedName(misappliedNameTaxon, citation, microcitation)
107
        }
108
        //taxon
109
        else if(taxonBase.isInstanceOf(Taxon.class)){
103 110
            classification.addParentChild(parent, (Taxon)taxonBase, null, null);
104 111
        }
105 112
        else if(taxonBase.isInstanceOf(Synonym.class)){
113
            //basionym
106 114
            if(gueltString.equals("b")){
107 115
                parent.addHomotypicSynonym((Synonym) taxonBase, null, null);
108 116
                parent.getName().addBasionym(taxonBase.getName());
109 117
            }
118
            //regular synonym
110 119
            else{
111 120
                //TODO: how to correctly add a synonym?
112 121
                parent.addSynonym((Synonym) taxonBase, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF(), null, null);
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportNames.java
20 20
import org.springframework.stereotype.Component;
21 21

  
22 22
import eu.etaxonomy.cdm.common.CdmUtils;
23
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
24 23
import eu.etaxonomy.cdm.io.common.DbImportBase;
25 24
import eu.etaxonomy.cdm.io.common.IPartitionedIO;
26 25
import eu.etaxonomy.cdm.io.common.ImportHelper;
27 26
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
28 27
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
28
import eu.etaxonomy.cdm.model.agent.AgentBase;
29 29
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
30 30
import eu.etaxonomy.cdm.model.common.CdmBase;
31 31
import eu.etaxonomy.cdm.model.name.BotanicalName;
......
149 149
            for (int i = 0; i < kombSplit.length; i++) {
150 150
                if(i==0){
151 151
                    //first author is ex author
152
                    TeamOrPersonBase authorKomb = HibernateProxyHelper.deproxy(getAgentService().load(state.getAuthorMap().get(kombSplit[i])), TeamOrPersonBase.class);
152
                    TeamOrPersonBase authorKomb = (TeamOrPersonBase) state.getRelatedObject(Namespace.AUTHOR_NAMESPACE, kombSplit[i]);
153 153
                    name.setExCombinationAuthorship(authorKomb);
154 154
                }
155 155
                else{
156
                    TeamOrPersonBase authorKomb = HibernateProxyHelper.deproxy(getAgentService().load(state.getAuthorMap().get(kombSplit[i])), TeamOrPersonBase.class);
156
                    TeamOrPersonBase authorKomb = (TeamOrPersonBase) state.getRelatedObject(Namespace.AUTHOR_NAMESPACE, kombSplit[i]);
157 157
                    name.setCombinationAuthorship(authorKomb);
158 158
                }
159 159
            }
160 160
        }
161
        else if(authorKombString.trim().equals("auct.")){
162
            logger.warn("NAMNR: "+id+" AUCT information in AUTOR_KOMB column");
163
        }
161 164
        else if(!CdmUtils.isBlank(authorKombString)){
162
            TeamOrPersonBase authorKomb = HibernateProxyHelper.deproxy(getAgentService().load(state.getAuthorMap().get(authorKombString)), TeamOrPersonBase.class);
165
            TeamOrPersonBase authorKomb = (TeamOrPersonBase) state.getRelatedObject(Namespace.AUTHOR_NAMESPACE, authorKombString);
163 166
            name.setCombinationAuthorship(authorKomb);
164 167
        }
165 168
        //basionym author
......
170 173
                    logger.error("NAMNR: "+id+" Multiple ex basionymn authors found");
171 174
                }
172 175
                if(i==0){
173
                    TeamOrPersonBase authorBasi = HibernateProxyHelper.deproxy(getAgentService().load(state.getAuthorMap().get(basiSplit[i])), TeamOrPersonBase.class);
176
                    TeamOrPersonBase authorBasi= (TeamOrPersonBase) state.getRelatedObject(Namespace.AUTHOR_NAMESPACE, basiSplit[i]);
174 177
                    name.setExBasionymAuthorship(authorBasi);
175 178
                }
176 179
                else{
177
                    TeamOrPersonBase authorBasi = HibernateProxyHelper.deproxy(getAgentService().load(state.getAuthorMap().get(basiSplit[i])), TeamOrPersonBase.class);
180
                    TeamOrPersonBase authorBasi= (TeamOrPersonBase) state.getRelatedObject(Namespace.AUTHOR_NAMESPACE, basiSplit[i]);
178 181
                    name.setBasionymAuthorship(authorBasi);
179 182
                }
180 183
            }
181 184
        }
185
        else if(authorBasiString.trim().equals("auct.")){
186
            name.setAppendedPhrase(authorBasiString);
187
        }
182 188
        else if(!CdmUtils.isBlank(authorBasiString)){
183 189
            //this seems to be a convention in the source database: When there is only a single author then only the "AUTOR_BASI" column is used
184
            TeamOrPersonBase authorBasi = HibernateProxyHelper.deproxy(getAgentService().load(state.getAuthorMap().get(authorBasiString)), TeamOrPersonBase.class);
190
            TeamOrPersonBase authorBasi= (TeamOrPersonBase) state.getRelatedObject(Namespace.AUTHOR_NAMESPACE, authorBasiString);
185 191
            if(CdmUtils.isBlank(authorKombString)){
186 192
                name.setCombinationAuthorship(authorBasi);
187 193
            }
......
197 203
        if(!CdmUtils.isBlank(zusatzString)){
198 204
            authorString = authorString.replace(", "+zusatzString, "");
199 205
        }
200
        if(CdmUtils.isBlank(authorKombString) && !CdmUtils.isBlank(authorBasiString)){
201
            authorString = "("+authorString+")";
202
        }
206
//        if(CdmUtils.isBlank(authorKombString) && !CdmUtils.isBlank(authorBasiString)){
207
//            authorString = "("+authorString+")";
208
//        }
203 209
        if(!authorString.equals(authorshipCache)){
204 210
            logger.warn("NAMNR: "+id+" Authorship inconsistent! name.authorhshipCache <-> Column AUTOR: "+authorshipCache+" <-> "+authorString);
205 211
        }
......
215 221
        if(gueltString.equals("1")){
216 222
            taxonBase = Taxon.NewInstance(name, null);
217 223
        }
218
        else if(gueltString.equals("x")){
219
            taxonBase = Synonym.NewInstance(name, null);
220
        }
221
        else if(gueltString.equals("b")){
224
        else if(gueltString.equals("x") || gueltString.equals("b")){
222 225
            taxonBase = Synonym.NewInstance(name, null);
223 226
        }
224 227
        if(taxonBase==null){
......
252 255
    public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs,
253 256
            RedListGefaesspflanzenImportState state) {
254 257
        Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
255
//        Map<Long, AgentBase<?>> authorKombMap = new HashMap<>();
256
//        Map<Long, AgentBase<?>> authorBasiMap = new HashMap<>();
257
//
258
//        //load authors
259
//        for(Entry<Long, UUID> entry:state.getAuthorKombMap().entrySet()){
260
//            authorKombMap.put(entry.getKey(), getAgentService().load(entry.getValue()));
261
//        }
262
//        for(Entry<Long, UUID> entry:state.getAuthorBasiMap().entrySet()){
263
//            authorBasiMap.put(entry.getKey(), getAgentService().load(entry.getValue()));
264
//        }
265
//        try {
266
//            while (rs.next()){
267
//                long id = rs.getLong("NAMNR");
268
//            }
269
//        } catch (SQLException e) {
270
//            e.printStackTrace();
271
//        }
272
//
273
//        //Authors
274
//        Set<UUID> uuidSet = new HashSet<>();
275
//        for (String authorStr : authorKombSet){
276
//            UUID uuid = state.getAuthorUuid(authorStr);
277
//            uuidSet.add(uuid);
278
//        }
279
//        List<TeamOrPersonBase<?>> authors = (List)getAgentService().find(uuidSet);
280
//        Map<UUID, TeamOrPersonBase<?>> authorUuidMap = new HashMap<>();
281
//        for (TeamOrPersonBase<?> author : authors){
282
//            authorUuidMap.put(author.getUuid(), author);
283
//        }
284
//
285
//        for (String authorStr : authorKombSet){
286
//            UUID uuid = state.getAuthorUuid(authorStr);
287
//            TeamOrPersonBase<?> author = authorUuidMap.get(uuid);
288
//            authorMap.put(authorStr, author);
289
//        }
290
//        result.put(AUTHOR_NAMESPACE, authorMap);
291
//
292
//        //reference map
293
//        String nameSpace = REFERENCE_NAMESPACE;
294
//        Class<?> cdmClass = Reference.class;
295
//        Set<String> idSet = referenceIdSet;
296
//        Map<String, Reference<?>> referenceMap = (Map<String, Reference<?>>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
297
//        result.put(nameSpace, referenceMap);
298
//
299
//        //secundum
300
//        UUID secUuid = state.getConfig().getSecUuid();
301
//        Reference<?> secRef = getReferenceService().find(secUuid);
302
//        referenceMap.put(secUuid.toString(), secRef);
258
        Map<String, AgentBase<?>> authorMap = new HashMap<String, AgentBase<?>>();
259

  
260
        try {
261
            while (rs.next()){
262
                String authorKombString = rs.getString("AUTOR_KOMB");
263

  
264
                if(authorKombString.contains(EX)){
265
                    String[] kombSplit = authorKombString.split(EX);
266
                    for (int i = 0; i < kombSplit.length; i++) {
267
                        if(!authorMap.containsKey(kombSplit[i])){
268
                            authorMap.put(kombSplit[i], getAgentService().load(state.getAuthorMap().get(kombSplit[i])));
269
                        }
270
                    }
271
                }
272
                else if(!CdmUtils.isBlank(authorKombString) && !authorMap.containsKey(authorKombString)){
273
                    authorMap.put(authorKombString, getAgentService().load(state.getAuthorMap().get(authorKombString)));
274
                }
275

  
276
                String authorBasiString = rs.getString("AUTOR_BASI");
277
                //basionym author
278
                if(authorBasiString.contains(EX)){
279
                    String[] basiSplit = authorBasiString.split(EX);
280
                    for (int i = 0; i < basiSplit.length; i++) {
281
                        if(!authorMap.containsKey(basiSplit[i])){
282
                            authorMap.put(basiSplit[i], getAgentService().load(state.getAuthorMap().get(basiSplit[i])));
283
                        }
284
                    }
285
                }
286
                else if(!CdmUtils.isBlank(authorBasiString) && !authorMap.containsKey(authorBasiString)){
287
                    authorMap.put(authorBasiString, getAgentService().load(state.getAuthorMap().get(authorBasiString)));
288
                }
289
            }
290
        } catch (SQLException e) {
291
            e.printStackTrace();
292
        }
293
        result.put(Namespace.AUTHOR_NAMESPACE, authorMap);
303 294

  
304 295
        return result;
305 296
    }

Also available in: Unified diff