60 |
60 |
private static final Logger logger = Logger.getLogger(BerlinModelOccurrenceImport.class);
|
61 |
61 |
|
62 |
62 |
public static final String NAMESPACE = "Occurrence";
|
63 |
|
private static final String EM_AREA_NAMESPACE = "emArea";
|
64 |
63 |
|
65 |
64 |
private static int modCount = 5000;
|
66 |
65 |
private static final String pluralString = "occurrences";
|
... | ... | |
81 |
80 |
|
82 |
81 |
@Override
|
83 |
82 |
protected String getRecordQuery(BerlinModelImportConfigurator config) {
|
84 |
|
String emCode = config.isIncludesAreaEmCode()? ", emArea.EMCode" : "";
|
|
83 |
String emCode = config.isIncludesAreaEmCode()? ", ar.EMCode" : "";
|
85 |
84 |
String strQuery = //DISTINCT because otherwise emOccurrenceSource creates multiple records for a single distribution
|
86 |
|
" SELECT DISTINCT PTaxon.RIdentifier AS taxonId, emOccurrence.OccurrenceId, emOccurrence.Native, emOccurrence.Introduced, " +
|
87 |
|
" emOccurrence.Cultivated, emOccurrence.Notes occNotes, " +
|
88 |
|
" emOccurSumCat.emOccurSumCatId, emOccurSumCat.Short, emOccurSumCat.Description, " +
|
89 |
|
" emOccurSumCat.OutputCode, emArea.AreaId, emArea.TDWGCode " + emCode +
|
90 |
|
" FROM emOccurrence INNER JOIN " +
|
91 |
|
" emArea ON emOccurrence.AreaFk = emArea.AreaId INNER JOIN " +
|
92 |
|
" PTaxon ON emOccurrence.PTNameFk = PTaxon.PTNameFk AND emOccurrence.PTRefFk = PTaxon.PTRefFk LEFT OUTER JOIN " +
|
93 |
|
" emOccurSumCat ON emOccurrence.SummaryStatus = emOccurSumCat.emOccurSumCatId LEFT OUTER JOIN " +
|
94 |
|
" emOccurrenceSource ON emOccurrence.OccurrenceId = emOccurrenceSource.OccurrenceFk " +
|
95 |
|
" WHERE (emOccurrence.OccurrenceId IN (" + ID_LIST_TOKEN + ") )" +
|
|
85 |
" SELECT DISTINCT pt.RIdentifier AS taxonId, occ.OccurrenceId, occ.Native, occ.Introduced, " +
|
|
86 |
" occ.Cultivated, occ.Notes occNotes, " +
|
|
87 |
" sumcat.emOccurSumCatId, sumcat.Short, sumcat.Description, " +
|
|
88 |
" sumcat.OutputCode, ar.AreaId, ar.TDWGCode " + emCode +
|
|
89 |
" FROM emOccurrence occ " +
|
|
90 |
" INNER JOIN emArea ar ON occ.AreaFk = ar.AreaId " +
|
|
91 |
" INNER JOIN PTaxon pt ON occ.PTNameFk = pt.PTNameFk AND occ.PTRefFk = pt.PTRefFk " +
|
|
92 |
" LEFT OUTER JOIN emOccurSumCat sumcat ON occ.SummaryStatus = sumcat.emOccurSumCatId " +
|
|
93 |
" LEFT OUTER JOIN emOccurrenceSource ocs ON occ.OccurrenceId = ocs.OccurrenceFk " +
|
|
94 |
" WHERE (occ.OccurrenceId IN (" + ID_LIST_TOKEN + ") )" +
|
96 |
95 |
" ORDER BY PTaxon.RIdentifier";
|
97 |
96 |
return strQuery;
|
98 |
97 |
}
|
99 |
98 |
|
100 |
|
// private Map<Integer, NamedArea> euroMedAreas = new HashMap<>();
|
101 |
|
|
102 |
99 |
|
103 |
100 |
@Override
|
104 |
101 |
public void doInvoke(BerlinModelImportState state) {
|
105 |
|
// if (state.getConfig().isUseEmAreaVocabulary()){
|
106 |
|
// try {
|
107 |
|
// createEuroMedAreas(state);
|
108 |
|
// } catch (Exception e) {
|
109 |
|
// logger.error("Exception occurred when trying to create euroMed Areas");
|
110 |
|
// e.printStackTrace();
|
111 |
|
// state.setSuccess(false);
|
112 |
|
// }
|
113 |
|
// }
|
114 |
102 |
super.doInvoke(state);
|
115 |
|
//reset
|
116 |
|
// euroMedAreas = new HashMap<>();
|
117 |
103 |
}
|
118 |
104 |
|
119 |
|
/**
|
120 |
|
* @param emCode
|
121 |
|
* @return
|
122 |
|
*/
|
123 |
105 |
private NamedArea getAreaByAreaId(int areaId) {
|
124 |
106 |
NamedArea result = null;
|
125 |
107 |
String areaIdStr = String.valueOf(areaId);
|
... | ... | |
156 |
138 |
}
|
157 |
139 |
|
158 |
140 |
@Override
|
159 |
|
public boolean doPartition(ResultSetPartitioner partitioner, BerlinModelImportState state) {
|
|
141 |
public boolean doPartition(@SuppressWarnings("rawtypes") ResultSetPartitioner partitioner, BerlinModelImportState state) {
|
160 |
142 |
boolean success = true;
|
161 |
|
Set<TaxonBase> taxaToSave = new HashSet<>();
|
|
143 |
@SuppressWarnings("rawtypes")
|
|
144 |
Set<TaxonBase> taxaToSave = new HashSet<>();
|
162 |
145 |
|
163 |
|
Map<String, TaxonBase<?>> taxonMap = partitioner.getObjectMap(BerlinModelTaxonImport.NAMESPACE);
|
|
146 |
@SuppressWarnings("unchecked")
|
|
147 |
Map<String, TaxonBase<?>> taxonMap = partitioner.getObjectMap(BerlinModelTaxonImport.NAMESPACE);
|
164 |
148 |
|
165 |
149 |
ResultSet rs = partitioner.getResultSet();
|
166 |
150 |
|
... | ... | |
267 |
251 |
* @throws SQLException
|
268 |
252 |
*/
|
269 |
253 |
//Create area list
|
270 |
|
private List<NamedArea> makeAreaList(BerlinModelImportState state, ResultSetPartitioner partitioner, ResultSet rs, int occurrenceId) throws SQLException {
|
|
254 |
private List<NamedArea> makeAreaList(BerlinModelImportState state,
|
|
255 |
@SuppressWarnings("rawtypes") ResultSetPartitioner partitioner,
|
|
256 |
ResultSet rs, int occurrenceId) throws SQLException {
|
271 |
257 |
|
272 |
258 |
List<NamedArea> areas = new ArrayList<>();
|
273 |
259 |
|
... | ... | |
329 |
315 |
String nameSpace = BerlinModelTaxonImport.NAMESPACE;
|
330 |
316 |
Class<?> cdmClass = TaxonBase.class;
|
331 |
317 |
Set<String> idSet = taxonIdSet;
|
332 |
|
Map<String, ? extends CdmBase> objectMap = (Map<String, TaxonBase>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
|
318 |
@SuppressWarnings("unchecked")
|
|
319 |
Map<String, ? extends CdmBase> objectMap = (Map<String, TaxonBase<?>>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
333 |
320 |
result.put(nameSpace, objectMap);
|
334 |
321 |
|
335 |
322 |
return result;
|
cleanup