Project

General

Profile

« Previous | Next » 

Revision c1641f79

Added by Patrick Plitzner almost 8 years ago

Improved author and name import (unstable)

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportAuthor.java
13 13
import java.sql.SQLException;
14 14
import java.util.HashMap;
15 15
import java.util.Map;
16
import java.util.Map.Entry;
17 16
import java.util.UUID;
18 17

  
19 18
import org.apache.log4j.Logger;
20 19
import org.springframework.stereotype.Component;
21 20

  
22 21
import eu.etaxonomy.cdm.common.CdmUtils;
22
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
23 23
import eu.etaxonomy.cdm.io.common.DbImportBase;
24 24
import eu.etaxonomy.cdm.io.common.IPartitionedIO;
25
import eu.etaxonomy.cdm.io.common.ImportHelper;
26 25
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
27
import eu.etaxonomy.cdm.model.agent.AgentBase;
28 26
import eu.etaxonomy.cdm.model.agent.Person;
29 27
import eu.etaxonomy.cdm.model.agent.Team;
28
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
30 29
import eu.etaxonomy.cdm.model.common.CdmBase;
31 30

  
32 31
/**
......
43 42

  
44 43
    private static final String pluralString = "authors";
45 44

  
46
    private static final String AUTHOR_KOMB_NAMESPACE = "author_komb";
47
    private static final String AUTHOR_BASI_NAMESPACE = "author_basi";
48

  
49 45
    public RedListGefaesspflanzenImportAuthor() {
50 46
        super(tableName, pluralString);
51 47
    }
......
75 71
    @Override
76 72
    public boolean doPartition(ResultSetPartitioner partitioner, RedListGefaesspflanzenImportState state) {
77 73
        ResultSet rs = partitioner.getResultSet();
78
        Map<String, AgentBase> teamsOrPersonToSave = new HashMap<String, AgentBase>();
74
        Map<String, TeamOrPersonBase> teamsOrPersonToSave = new HashMap<String, TeamOrPersonBase>();
79 75
        try {
80 76
            while (rs.next()){
81 77
                makeSingleAuthor(state, rs, teamsOrPersonToSave);
......
85 81
            e.printStackTrace();
86 82
        }
87 83

  
88
        getAgentService().saveOrUpdate(teamsOrPersonToSave.values());
89
        //add partition to state map
90
        for (Entry<String, AgentBase> entry: teamsOrPersonToSave.entrySet()) {
91
            state.getAgentMap().put(entry.getKey(), entry.getValue().getUuid());
92
        }
84
//        getAgentService().saveOrUpdate(teamsOrPersonToSave.values());
93 85
        return true;
94 86
    }
95 87

  
96
    private void makeSingleAuthor(RedListGefaesspflanzenImportState state, ResultSet rs, Map<String, AgentBase> teamsOrPersonToSave)
88
    private void makeSingleAuthor(RedListGefaesspflanzenImportState state, ResultSet rs, Map<String, TeamOrPersonBase> teamsOrPersonToSave)
97 89
            throws SQLException {
98 90
        long id = rs.getLong("NAMNR");
99 91
        String authorName = rs.getString("AUTOR");
......
102 94

  
103 95
        //check null values
104 96
        if(CdmUtils.isBlank(authorName) && CdmUtils.isBlank(authorBasiName) && CdmUtils.isBlank(authorKombName)){
105
            logger.info("NAMNR "+id+": No author found for NAMNR "+id);
97
            logger.info("NAMNR "+id+": No author found!");
106 98
            return;
107 99
        }
108
        AgentBase authorKomb = null;
109
        AgentBase authorBasi = null;
110
        AgentBase author = null;
100
        TeamOrPersonBase authorKomb = null;
101
        TeamOrPersonBase authorBasi = null;
111 102

  
112
        authorKomb = importPerson(state, teamsOrPersonToSave, id, authorKombName, AUTHOR_KOMB_NAMESPACE);
113
        authorBasi = importPerson(state, teamsOrPersonToSave, id, authorBasiName, AUTHOR_BASI_NAMESPACE);
103
        authorKomb = importPerson(state, teamsOrPersonToSave, id, authorKombName);
104
        if(authorKomb!=null){
105
            state.getAuthorKombMap().put(id, authorKomb.getUuid());
106
        }
107
        authorBasi = importPerson(state, teamsOrPersonToSave, id, authorBasiName);
108
        if(authorKomb!=null){
109
            state.getAuthorBasiMap().put(id, authorBasi.getUuid());
110
        }
114 111

  
115 112
        //check if missapplied name
116 113
        if(authorName.equals("auct.")){
......
122 119
        }
123 120
        else if(authorBasi==null && authorKomb==null){
124 121
            logger.warn("NAMNR "+id+": Author not atomised in authorKomb and authorBasi. Author: "+authorName);
125
            importPerson(state, teamsOrPersonToSave, id, authorName, AUTHOR_KOMB_NAMESPACE);
122
            TeamOrPersonBase team = importPerson(state, teamsOrPersonToSave, id, authorName);
123
            state.getAuthorKombMap().put(id, team.getUuid());
126 124
        }
127 125
//        //check author column consistency
128 126
//        String authorCheckString = "";
......
143 141

  
144 142
    }
145 143

  
146
    private AgentBase importPerson(RedListGefaesspflanzenImportState state, Map<String, AgentBase> teamsOrPersonToSave,
147
            long id, String agentName, String namespace) {
148
        AgentBase agent = null;
144
    private TeamOrPersonBase importPerson(RedListGefaesspflanzenImportState state, Map<String, TeamOrPersonBase> teamsOrPersonToSave,
145
            long id, String agentName) {
146
        TeamOrPersonBase agent = null;
149 147
        //check if agent already exists
150
        AgentBase notYetPersistedAgent = teamsOrPersonToSave.get(agentName);
151
        UUID existingAgentUuid = state.getAgentMap().get(agentName);
148
        TeamOrPersonBase notYetPersistedAgent = teamsOrPersonToSave.get(agentName);
149
        UUID existingAgentUuid = state.getAuthorKombMap().get(agentName);
152 150
        if(notYetPersistedAgent!=null){
153 151
            agent = notYetPersistedAgent;
154 152
        }
155 153
        else if(existingAgentUuid!=null){
156
            agent = getAgentService().load(existingAgentUuid);
154
            agent = HibernateProxyHelper.deproxy(getAgentService().load(existingAgentUuid), TeamOrPersonBase.class);
157 155
        }
158 156
        else if(!CdmUtils.isBlank(agentName)){
159 157
            //check if it is a team
......
168 166
                agent = Person.NewTitledInstance(agentName);
169 167
            }
170 168
            teamsOrPersonToSave.put(agentName, agent);
171
            state.getAgentMap().put(agentName, agent.getUuid());
172
            ImportHelper.setOriginalSource(agent, state.getTransactionalSourceReference(), id, namespace);
169
//            ImportHelper.setOriginalSource(agent, state.getTransactionalSourceReference(), id, namespace);
173 170
        }
174 171
        return agent;
175 172
    }
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportNames.java
19 19
import org.apache.log4j.Logger;
20 20
import org.springframework.stereotype.Component;
21 21

  
22
import eu.etaxonomy.cdm.common.CdmUtils;
22 23
import eu.etaxonomy.cdm.io.common.DbImportBase;
23 24
import eu.etaxonomy.cdm.io.common.IPartitionedIO;
24 25
import eu.etaxonomy.cdm.io.common.ImportHelper;
25 26
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
26 27
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
28
import eu.etaxonomy.cdm.model.agent.AgentBase;
27 29
import eu.etaxonomy.cdm.model.common.CdmBase;
28 30
import eu.etaxonomy.cdm.model.name.BotanicalName;
29 31
import eu.etaxonomy.cdm.model.name.Rank;
......
46 48
    private static final String pluralString = "names";
47 49

  
48 50
    private static final String TAXON_NAMESPACE = "name";
51
    private static final String AUTHOR_KOMB_NAMESPACE = "author_komb";
52
    private static final String AUTHOR_BASI_NAMESPACE = "author_basi";
49 53

  
50 54
    public RedListGefaesspflanzenImportNames() {
51 55
        super(tableName, pluralString);
......
101 105
        String nomZusatzString = rs.getString("NOM_ZUSATZ");
102 106
        String zusatzString = rs.getString("ZUSATZ");
103 107

  
108
        if(CdmUtils.isBlank(taxNameString) && CdmUtils.isBlank(ep1String)){
109
            logger.error("NAMNR: "+id+" No name found!");
110
        }
111

  
112

  
113
        Rank rank = makeRank(state, rangString);
114
        BotanicalName name = BotanicalName.NewInstance(rank);
104 115

  
105
        BotanicalName name = BotanicalName.NewInstance(makeRank(state, rangString));
116
        //ep1 should always be present
117
        name.setGenusOrUninomial(ep1String);
118
        if(rank==Rank.SPECIES()){
119
            name.setGenusOrUninomial(ep1String);
120
        }
106 121

  
122
        //add author
123
        AgentBase authorKomb = getAgentService().load(state.getAuthorKombMap().get(id));
124
//        name.setCombinationAuthorship(authorKomb);
107 125

  
108 126
        //id
109 127
        ImportHelper.setOriginalSource(name, state.getTransactionalSourceReference(), id, TAXON_NAMESPACE);
......
128 146
    public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs,
129 147
            RedListGefaesspflanzenImportState state) {
130 148
        Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
131
//        Map<String, TeamOrPersonBase<?>> authorMap = new HashMap<>();
132
//        Set<String> authorKombSet = new HashSet<>();
133
//        Set<String> referenceIdSet = new HashSet<String>();
149
//        Map<Long, AgentBase<?>> authorKombMap = new HashMap<>();
150
//        Map<Long, AgentBase<?>> authorBasiMap = new HashMap<>();
134 151
//
152
//        //load authors
153
//        for(Entry<Long, UUID> entry:state.getAuthorKombMap().entrySet()){
154
//            authorKombMap.put(entry.getKey(), getAgentService().load(entry.getValue()));
155
//        }
156
//        for(Entry<Long, UUID> entry:state.getAuthorBasiMap().entrySet()){
157
//            authorBasiMap.put(entry.getKey(), getAgentService().load(entry.getValue()));
158
//        }
135 159
//        try {
136 160
//            while (rs.next()){
137
//                String authorStr = rs.getString("tax_author_name");
138
//                authorKombSet.add(authorStr);
139
//                handleForeignKey(rs, referenceIdSet, "tax_document");
161
//                long id = rs.getLong("NAMNR");
140 162
//            }
141 163
//        } catch (SQLException e) {
142 164
//            e.printStackTrace();
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportState.java
28 28
	@SuppressWarnings("unused")
29 29
	private static final Logger logger = Logger.getLogger(RedListGefaesspflanzenImportState.class);
30 30

  
31
	private Map<String, UUID> agentMap = new HashMap<String, UUID>();
31
	private Map<Long, UUID> authorKombMap = new HashMap<Long, UUID>();
32
	private Map<Long, UUID> authorBasiMap = new HashMap<Long, UUID>();
32 33

  
33 34
    protected RedListGefaesspflanzenImportState(RedListGefaesspflanzenImportConfigurator config) {
34 35
        super(config);
35 36
    }
36 37

  
37
    public Map<String, UUID> getAgentMap() {
38
        return agentMap;
38
    public Map<Long, UUID> getAuthorKombMap() {
39
        return authorKombMap;
40
    }
41

  
42
    public Map<Long, UUID> getAuthorBasiMap() {
43
        return authorBasiMap;
39 44
    }
40 45

  
41 46
}
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenTransformer.java
35 35
        else if (key.equals("SPE")){return Rank.SPECIES();}
36 36
        else if (key.equals("VAR")){return Rank.VARIETY();}
37 37
        else if (key.equals("SSP")){return Rank.SUBSPECIES();}
38
        else if (key.equals("FOR")){return Rank.FORM();}
39
        else if (key.equals("RAC")){return Rank.RACE();}
40
        else if (key.equals("SEC")){return Rank.SECTION_BOTANY();}
41
        else if (key.equals("SSE")){return Rank.SUBSECTION_BOTANY();}
42
        else if (key.equals("SGE")){return Rank.SUBGENUS();}
43
        else if (key.equals("ORA")){return Rank.UNKNOWN_RANK();}
44
        else if (key.equals("SVA")){return Rank.SUBVARIETY();}
45
        else if (key.equals("CV")){return Rank.CULTIVAR();}
46
        else if (key.equals("PRO")){return Rank.PROLES();}
47
        else if (key.equals("SER")){return Rank.SERIES();}
48
        else if (key.equals("GRE")){return Rank.GREX();}
38 49
        return null;
39 50
    }
40 51

  

Also available in: Unified diff