Revision 01146fd8
Added by Andreas Müller over 3 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/algaterra/AlgaTerraPictureImport.java | ||
---|---|---|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
9 |
|
|
10 | 9 |
package eu.etaxonomy.cdm.io.algaterra; |
11 | 10 |
|
12 | 11 |
import java.sql.ResultSet; |
... | ... | |
34 | 33 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
35 | 34 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
36 | 35 |
|
37 |
|
|
38 | 36 |
/** |
39 | 37 |
* Import for AlgaTerra images from table |
40 | 38 |
* @author a.mueller |
... | ... | |
42 | 40 |
*/ |
43 | 41 |
@Component |
44 | 42 |
public class AlgaTerraPictureImport extends AlgaTerraImageImportBase { |
45 |
private static final Logger logger = Logger.getLogger(AlgaTerraPictureImport.class); |
|
46 | 43 |
|
44 |
private static final long serialVersionUID = 3910940848080132170L; |
|
45 |
private static final Logger logger = Logger.getLogger(AlgaTerraPictureImport.class); |
|
47 | 46 |
|
48 | 47 |
private static int modCount = 5000; |
49 | 48 |
private static final String pluralString = "pictures"; |
... | ... | |
53 | 52 |
super(dbTableName, pluralString); |
54 | 53 |
} |
55 | 54 |
|
56 |
|
|
57 |
/* (non-Javadoc) |
|
58 |
* @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getIdQuery() |
|
59 |
*/ |
|
60 | 55 |
@Override |
61 | 56 |
protected String getIdQuery(BerlinModelImportState state) { |
62 | 57 |
String result = " SELECT p.PictureId " |
... | ... | |
66 | 61 |
return result; |
67 | 62 |
} |
68 | 63 |
|
69 |
/* (non-Javadoc) |
|
70 |
* @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getRecordQuery(eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator) |
|
71 |
*/ |
|
72 | 64 |
@Override |
73 | 65 |
protected String getRecordQuery(BerlinModelImportConfigurator config) { |
74 | 66 |
String strQuery = |
... | ... | |
77 | 69 |
" FROM Picture p INNER JOIN Fact f ON p.PictureId = f.ExtensionFk LEFT OUTER JOIN PTaxon pt ON f.PTNameFk = pt.PTNameFk AND f.PTRefFk = pt.PTRefFk " |
78 | 70 |
+ " WHERE f.FactCategoryFk = 205 AND ( p.PictureID IN (" + ID_LIST_TOKEN + ") )" |
79 | 71 |
+ " ORDER BY p.PictureId, f.factId, pt.RIdentifier "; |
80 |
; |
|
81 | 72 |
return strQuery; |
82 | 73 |
} |
83 | 74 |
|
84 |
/* (non-Javadoc) |
|
85 |
* @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#doPartition(eu.etaxonomy.cdm.io.berlinModel.in.ResultSetPartitioner, eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState) |
|
86 |
*/ |
|
87 | 75 |
@Override |
88 | 76 |
public boolean doPartition(ResultSetPartitioner partitioner, BerlinModelImportState bmState) { |
89 | 77 |
boolean success = true; |
90 | 78 |
|
91 | 79 |
AlgaTerraImportState state = (AlgaTerraImportState)bmState; |
92 | 80 |
|
93 |
// Set<SpecimenOrObservationBase> specimenToSave = new HashSet<SpecimenOrObservationBase>(); |
|
94 |
Set<TaxonBase> taxaToSave = new HashSet<TaxonBase>(); |
|
81 |
Set<TaxonBase> taxaToSave = new HashSet<>(); |
|
95 | 82 |
|
96 |
// Map<String, DerivedUnitBase> ecoFactMap = (Map<String, DerivedUnitBase>) partitioner.getObjectMap(AlgaTerraSpecimenImportBase.ECO_FACT_DERIVED_UNIT_NAMESPACE); |
|
97 | 83 |
Map<String, TaxonBase> taxonMap = partitioner.getObjectMap(BerlinModelTaxonImport.NAMESPACE); |
98 | 84 |
Map<String, DerivedUnit> specimenMap = partitioner.getObjectMap(AlgaTerraFactEcologyImport.FACT_ECOLOGY_NAMESPACE); |
99 | 85 |
|
100 | 86 |
ResultSet rs = partitioner.getResultSet(); |
101 | 87 |
|
102 | 88 |
try { |
103 |
|
|
104 | 89 |
int i = 0; |
105 |
|
|
106 | 90 |
//for each reference |
107 | 91 |
while (rs.next()){ |
108 | 92 |
|
... | ... | |
111 | 95 |
int pictureId = rs.getInt("PictureID"); |
112 | 96 |
int taxonId = rs.getInt("RIdentifier"); |
113 | 97 |
int factId = rs.getInt("FactId"); |
114 |
|
|
115 |
|
|
116 | 98 |
//TODO etc. Created, Notes, Copyright, TermsOfUse etc. |
117 |
|
|
118 | 99 |
try { |
119 | 100 |
|
120 | 101 |
TaxonBase<?> taxonBase = taxonMap.get(String.valueOf(taxonId)); |
... | ... | |
132 | 113 |
|
133 | 114 |
taxaToSave.add(taxon); |
134 | 115 |
} |
135 |
|
|
136 |
|
|
137 | 116 |
} catch (Exception e) { |
138 | 117 |
logger.warn("Exception in " + getTableName() + ": PictureId " + pictureId + ". " + e.getMessage()); |
139 | 118 |
e.printStackTrace(); |
140 | 119 |
} |
141 |
|
|
142 | 120 |
} |
143 | 121 |
|
144 |
// logger.warn("Specimen: " + countSpecimen + ", Descriptions: " + countDescriptions ); |
|
145 |
|
|
146 | 122 |
logger.warn(pluralString + " to save: " + taxaToSave.size()); |
147 |
// getOccurrenceService().save(taxaToSave); |
|
148 | 123 |
getTaxonService().save(taxaToSave); |
149 | 124 |
|
150 | 125 |
return success; |
... | ... | |
154 | 129 |
} |
155 | 130 |
} |
156 | 131 |
|
157 |
|
|
158 |
|
|
159 | 132 |
private void handlePictureSpecificFields(ResultSet rs, Media media, AlgaTerraImportState state, Map<String, DerivedUnit> specimenMap) throws SQLException { |
160 | 133 |
Integer specimenFactId = nullSafeInt(rs, "FactFk"); |
161 | 134 |
if (specimenFactId != null){ |
... | ... | |
173 | 146 |
} |
174 | 147 |
} |
175 | 148 |
} |
176 |
|
|
177 | 149 |
} |
178 | 150 |
|
179 |
|
|
180 | 151 |
@Override |
181 | 152 |
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, BerlinModelImportState state) { |
182 | 153 |
|
183 | 154 |
String nameSpace; |
184 | 155 |
Set<String> idSet; |
185 |
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
|
|
156 |
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>(); |
|
186 | 157 |
|
187 | 158 |
try{ |
188 |
Set<String> taxonIdSet = new HashSet<String>();
|
|
189 |
Set<String> specimenIdSet = new HashSet<String>();
|
|
159 |
Set<String> taxonIdSet = new HashSet<>(); |
|
160 |
Set<String> specimenIdSet = new HashSet<>(); |
|
190 | 161 |
|
191 | 162 |
while (rs.next()){ |
192 | 163 |
handleForeignKey(rs, taxonIdSet, "RIdentifier"); |
... | ... | |
214 | 185 |
return result; |
215 | 186 |
} |
216 | 187 |
|
217 |
|
|
218 | 188 |
@Override |
219 | 189 |
protected boolean doCheck(BerlinModelImportState state){ |
220 | 190 |
IOValidator<BerlinModelImportState> validator = new AlgaTerraTypeImportValidator(); |
... | ... | |
226 | 196 |
AlgaTerraImportConfigurator config = ((AlgaTerraImportState) bmState).getAlgaTerraConfigurator(); |
227 | 197 |
return ! ( config.isDoTypes() && config.isDoImages()) ; |
228 | 198 |
} |
229 |
|
|
230 | 199 |
} |
Also available in: Unified diff
cleanup