Revision 8422c0cd
Added by Andreas Müller almost 8 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/algaterra/AlgaTerraTypeImagesImport.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2007 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
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 |
*/ |
... | ... | |
19 | 19 |
import org.apache.log4j.Logger; |
20 | 20 |
import org.springframework.stereotype.Component; |
21 | 21 |
|
22 |
import eu.etaxonomy.cdm.io.algaterra.AlgaTerraImageImportBase.PathType; |
|
23 | 22 |
import eu.etaxonomy.cdm.io.algaterra.validation.AlgaTerraTypeImportValidator; |
24 | 23 |
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator; |
25 | 24 |
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState; |
... | ... | |
41 | 40 |
public class AlgaTerraTypeImagesImport extends AlgaTerraImageImportBase { |
42 | 41 |
private static final Logger logger = Logger.getLogger(AlgaTerraTypeImagesImport.class); |
43 | 42 |
|
44 |
|
|
43 |
|
|
45 | 44 |
private static int modCount = 5000; |
46 | 45 |
private static final String pluralString = "type images"; |
47 |
private static final String dbTableName = "SpecimenFigure"; //??
|
|
48 |
|
|
46 |
private static final String dbTableName = "SpecimenFigure"; //?? |
|
47 |
|
|
49 | 48 |
public AlgaTerraTypeImagesImport(){ |
50 | 49 |
super(dbTableName, pluralString); |
51 | 50 |
} |
52 |
|
|
53 |
|
|
51 |
|
|
52 |
|
|
54 | 53 |
/* (non-Javadoc) |
55 | 54 |
* @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getIdQuery() |
56 | 55 |
*/ |
57 | 56 |
@Override |
58 | 57 |
protected String getIdQuery(BerlinModelImportState state) { |
59 |
String result = " SELECT SpecimenFigureId "
|
|
60 |
+ " FROM SpecimenFigure "
|
|
58 |
String result = " SELECT SpecimenFigureId " |
|
59 |
+ " FROM SpecimenFigure " |
|
61 | 60 |
+ " WHERE TypeSpecimenFk is NOT NULL " |
62 | 61 |
+ " ORDER BY TypeSpecimenFk "; |
63 | 62 |
return result; |
... | ... | |
68 | 67 |
*/ |
69 | 68 |
@Override |
70 | 69 |
protected String getRecordQuery(BerlinModelImportConfigurator config) { |
71 |
String strQuery =
|
|
72 |
|
|
70 |
String strQuery = |
|
71 |
|
|
73 | 72 |
" SELECT sf.*, sf.SpecimenFigurePhrase as FigurePhrase, sf.SpecimenFigure as fileName, sf.PicturePath as filePath" + |
74 |
" FROM SpecimenFigure sf "
|
|
75 |
+ " WHERE (sf.SpecimenFigureId IN (" + ID_LIST_TOKEN + ") )"
|
|
73 |
" FROM SpecimenFigure sf " |
|
74 |
+ " WHERE (sf.SpecimenFigureId IN (" + ID_LIST_TOKEN + ") )" |
|
76 | 75 |
+ " ORDER BY TypeSpecimenFk "; |
77 | 76 |
; |
78 | 77 |
return strQuery; |
... | ... | |
81 | 80 |
/* (non-Javadoc) |
82 | 81 |
* @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#doPartition(eu.etaxonomy.cdm.io.berlinModel.in.ResultSetPartitioner, eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState) |
83 | 82 |
*/ |
84 |
public boolean doPartition(ResultSetPartitioner partitioner, BerlinModelImportState bmState) { |
|
83 |
@Override |
|
84 |
public boolean doPartition(ResultSetPartitioner partitioner, BerlinModelImportState bmState) { |
|
85 | 85 |
boolean success = true; |
86 |
|
|
86 |
|
|
87 | 87 |
AlgaTerraImportState state = (AlgaTerraImportState)bmState; |
88 |
|
|
88 |
|
|
89 | 89 |
Set<SpecimenOrObservationBase> unitsToSave = new HashSet<SpecimenOrObservationBase>(); |
90 |
|
|
91 |
Map<String, DerivedUnit> typeSpecimenMap = (Map<String, DerivedUnit>) partitioner.getObjectMap(AlgaTerraSpecimenImportBase.TYPE_SPECIMEN_DERIVED_UNIT_NAMESPACE);
|
|
92 |
Map<String, Reference> referenceMap = (Map<String, Reference>) partitioner.getObjectMap(BerlinModelReferenceImport.REFERENCE_NAMESPACE);
|
|
93 |
|
|
94 |
|
|
90 |
|
|
91 |
Map<String, DerivedUnit> typeSpecimenMap = partitioner.getObjectMap(AlgaTerraSpecimenImportBase.TYPE_SPECIMEN_DERIVED_UNIT_NAMESPACE); |
|
92 |
Map<String, Reference> referenceMap = partitioner.getObjectMap(BerlinModelReferenceImport.REFERENCE_NAMESPACE); |
|
93 |
|
|
94 |
|
|
95 | 95 |
ResultSet rs = partitioner.getResultSet(); |
96 | 96 |
|
97 | 97 |
try { |
98 |
|
|
98 |
|
|
99 | 99 |
int i = 0; |
100 | 100 |
|
101 | 101 |
//for each reference |
102 | 102 |
while (rs.next()){ |
103 |
|
|
103 |
|
|
104 | 104 |
if ((i++ % modCount) == 0 && i!= 1 ){ logger.info(pluralString + " handled: " + (i-1));} |
105 |
|
|
105 |
|
|
106 | 106 |
int figureId = rs.getInt("SpecimenFigureId"); |
107 | 107 |
int typeSpecimenFk = rs.getInt("typeSpecimenFk"); |
108 |
|
|
109 |
|
|
108 |
|
|
109 |
|
|
110 | 110 |
//TODO etc. Created, Notes, Copyright, TermsOfUse etc. |
111 |
|
|
111 |
|
|
112 | 112 |
try { |
113 |
|
|
113 |
|
|
114 | 114 |
//source ref |
115 |
Reference<?> sourceRef = state.getTransactionalSourceReference();
|
|
116 |
|
|
115 |
Reference sourceRef = state.getTransactionalSourceReference(); |
|
116 |
|
|
117 | 117 |
DerivedUnit derivedUnit = typeSpecimenMap.get(String.valueOf(typeSpecimenFk)); |
118 |
|
|
118 |
|
|
119 | 119 |
if (derivedUnit == null){ |
120 | 120 |
logger.warn("Could not find type specimen (" + typeSpecimenFk +") for specimen figure " + figureId); |
121 | 121 |
}else{ |
122 |
|
|
122 |
|
|
123 | 123 |
//field observation |
124 | 124 |
Media media = handleSingleImage(rs, derivedUnit, state, partitioner, PathType.Image); |
125 |
|
|
125 |
|
|
126 | 126 |
handleTypeImageSpecificFields(rs, media, state); |
127 |
|
|
128 |
unitsToSave.add(derivedUnit);
|
|
127 |
|
|
128 |
unitsToSave.add(derivedUnit); |
|
129 | 129 |
} |
130 | 130 |
|
131 | 131 |
|
132 | 132 |
} catch (Exception e) { |
133 | 133 |
logger.warn("Exception in " + getTableName() + ": SpecimenFigureId " + figureId + ". " + e.getMessage()); |
134 | 134 |
e.printStackTrace(); |
135 |
}
|
|
136 |
|
|
135 |
} |
|
136 |
|
|
137 | 137 |
} |
138 |
|
|
138 |
|
|
139 | 139 |
// logger.warn("Specimen: " + countSpecimen + ", Descriptions: " + countDescriptions ); |
140 | 140 |
|
141 | 141 |
logger.warn(pluralString + " to save: " + unitsToSave.size()); |
142 |
getOccurrenceService().saveOrUpdate(unitsToSave);
|
|
143 |
|
|
142 |
getOccurrenceService().saveOrUpdate(unitsToSave); |
|
143 |
|
|
144 | 144 |
return success; |
145 | 145 |
} catch (SQLException e) { |
146 | 146 |
logger.error("SQLException:" + e); |
... | ... | |
154 | 154 |
//TODO refFk, refDetailFk, publishFlag |
155 | 155 |
Integer refFk = nullSafeInt(rs, "refFk"); |
156 | 156 |
Integer refDetailFk = nullSafeInt(rs, "refDetailFk"); |
157 |
|
|
157 |
|
|
158 | 158 |
//TODO |
159 |
|
|
160 |
|
|
159 |
|
|
160 |
|
|
161 | 161 |
} |
162 | 162 |
|
163 | 163 |
@Override |
... | ... | |
166 | 166 |
Class<?> cdmClass; |
167 | 167 |
Set<String> idSet; |
168 | 168 |
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>(); |
169 |
|
|
169 |
|
|
170 | 170 |
try{ |
171 | 171 |
Set<String> typeSpecimenIdSet = new HashSet<String>(); |
172 |
|
|
172 |
|
|
173 | 173 |
while (rs.next()){ |
174 | 174 |
handleForeignKey(rs, typeSpecimenIdSet, "TypeSpecimenFk"); |
175 | 175 |
} |
176 |
|
|
176 |
|
|
177 | 177 |
//type specimen map |
178 | 178 |
nameSpace = AlgaTerraSpecimenImportBase.TYPE_SPECIMEN_DERIVED_UNIT_NAMESPACE; |
179 | 179 |
cdmClass = SpecimenOrObservationBase.class; |
... | ... | |
181 | 181 |
Map<String, DerivedUnit> typeSpecimenMap = (Map<String, DerivedUnit>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
182 | 182 |
result.put(nameSpace, typeSpecimenMap); |
183 | 183 |
|
184 |
|
|
184 |
|
|
185 | 185 |
} catch (SQLException e) { |
186 | 186 |
throw new RuntimeException(e); |
187 | 187 |
} |
... | ... | |
201 | 201 |
return ! ( config.isDoTypes() && config.isDoImages()) ; |
202 | 202 |
// return false; |
203 | 203 |
} |
204 |
|
|
204 |
|
|
205 | 205 |
} |
Also available in: Unified diff
Remove generics from Reference in cdmlib-app #5830