Revision e0935f63
Added by Andreas Müller over 4 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/algaterra/AlgaTerraSiteImagesImport.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; |
... | ... | |
39 | 38 |
public class AlgaTerraSiteImagesImport extends AlgaTerraImageImportBase { |
40 | 39 |
private static final Logger logger = Logger.getLogger(AlgaTerraSiteImagesImport.class); |
41 | 40 |
|
42 |
|
|
41 |
|
|
43 | 42 |
private static int modCount = 5000; |
44 | 43 |
private static final String pluralString = "site images"; |
45 |
private static final String dbTableName = "SiteImages"; //??
|
|
46 |
|
|
44 |
private static final String dbTableName = "SiteImages"; //?? |
|
45 |
|
|
47 | 46 |
public AlgaTerraSiteImagesImport(){ |
48 | 47 |
super(dbTableName, pluralString); |
49 | 48 |
} |
50 |
|
|
51 |
|
|
49 |
|
|
50 |
|
|
52 | 51 |
/* (non-Javadoc) |
53 | 52 |
* @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getIdQuery() |
54 | 53 |
*/ |
55 | 54 |
@Override |
56 | 55 |
protected String getIdQuery(BerlinModelImportState state) { |
57 |
String result = " SELECT SiteId "
|
|
58 |
+ " FROM SiteImages "
|
|
56 |
String result = " SELECT SiteId " |
|
57 |
+ " FROM SiteImages " |
|
59 | 58 |
+ " ORDER BY EcoFactFk "; |
60 | 59 |
return result; |
61 | 60 |
} |
... | ... | |
65 | 64 |
*/ |
66 | 65 |
@Override |
67 | 66 |
protected String getRecordQuery(BerlinModelImportConfigurator config) { |
68 |
String strQuery =
|
|
69 |
|
|
67 |
String strQuery = |
|
68 |
|
|
70 | 69 |
" SELECT si.*, si.Comment as FigurePhrase, si.Picture as fileName, si.Path as filePath " + |
71 |
" FROM SiteImages si "
|
|
72 |
+ " WHERE (si.SiteID IN (" + ID_LIST_TOKEN + ") )"
|
|
70 |
" FROM SiteImages si " |
|
71 |
+ " WHERE (si.SiteID IN (" + ID_LIST_TOKEN + ") )" |
|
73 | 72 |
+ " ORDER BY EcoFactFk "; |
74 | 73 |
; |
75 | 74 |
return strQuery; |
... | ... | |
78 | 77 |
/* (non-Javadoc) |
79 | 78 |
* @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#doPartition(eu.etaxonomy.cdm.io.berlinModel.in.ResultSetPartitioner, eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState) |
80 | 79 |
*/ |
81 |
public boolean doPartition(ResultSetPartitioner partitioner, BerlinModelImportState bmState) { |
|
80 |
@Override |
|
81 |
public boolean doPartition(ResultSetPartitioner partitioner, BerlinModelImportState bmState) { |
|
82 | 82 |
boolean success = true; |
83 |
|
|
83 |
|
|
84 | 84 |
AlgaTerraImportState state = (AlgaTerraImportState)bmState; |
85 |
|
|
85 |
|
|
86 | 86 |
Set<SpecimenOrObservationBase> unitsToSave = new HashSet<SpecimenOrObservationBase>(); |
87 |
|
|
88 |
Map<String, FieldUnit> ecoFactFieldObservationMap = (Map<String, FieldUnit>) partitioner.getObjectMap(AlgaTerraSpecimenImportBase.ECO_FACT_FIELD_OBSERVATION_NAMESPACE);
|
|
89 |
|
|
87 |
|
|
88 |
Map<String, FieldUnit> ecoFactFieldObservationMap = partitioner.getObjectMap(AlgaTerraSpecimenImportBase.ECO_FACT_FIELD_OBSERVATION_NAMESPACE); |
|
89 |
|
|
90 | 90 |
ResultSet rs = partitioner.getResultSet(); |
91 | 91 |
|
92 | 92 |
try { |
93 |
|
|
93 |
|
|
94 | 94 |
int i = 0; |
95 | 95 |
|
96 | 96 |
//for each reference |
97 | 97 |
while (rs.next()){ |
98 |
|
|
98 |
|
|
99 | 99 |
if ((i++ % modCount) == 0 && i!= 1 ){ logger.info(pluralString + " handled: " + (i-1));} |
100 |
|
|
100 |
|
|
101 | 101 |
int figureId = rs.getInt("SiteId"); |
102 | 102 |
int ecoFactFk = rs.getInt("EcoFactFk"); |
103 |
|
|
104 |
|
|
103 |
|
|
104 |
|
|
105 | 105 |
//TODO etc. Created, Notes, Copyright, TermsOfUse etc. |
106 |
|
|
106 |
|
|
107 | 107 |
try { |
108 |
|
|
108 |
|
|
109 | 109 |
//TODO use deduplicated ecofact |
110 | 110 |
FieldUnit fieldObservation = ecoFactFieldObservationMap.get(String.valueOf(ecoFactFk)); |
111 |
|
|
111 |
|
|
112 | 112 |
if (fieldObservation == null){ |
113 | 113 |
logger.warn("Could not find eco fact field observation (" + ecoFactFk +") for site image " + figureId); |
114 | 114 |
}else{ |
115 |
|
|
115 |
|
|
116 | 116 |
} |
117 |
|
|
117 |
|
|
118 | 118 |
//field observation |
119 | 119 |
Media media = handleSingleImage(rs, fieldObservation, state, partitioner, PathType.Site); |
120 |
|
|
120 |
|
|
121 | 121 |
handleSiteImageSpecificFields(rs, media, state); |
122 |
|
|
123 |
unitsToSave.add(fieldObservation);
|
|
124 |
|
|
122 |
|
|
123 |
unitsToSave.add(fieldObservation); |
|
124 |
|
|
125 | 125 |
|
126 | 126 |
} catch (Exception e) { |
127 | 127 |
logger.warn("Exception in " + getTableName() + ": SiteId " + figureId + ". " + e.getMessage()); |
128 | 128 |
e.printStackTrace(); |
129 |
}
|
|
130 |
|
|
129 |
} |
|
130 |
|
|
131 | 131 |
} |
132 |
|
|
132 |
|
|
133 | 133 |
// logger.warn("Specimen: " + countSpecimen + ", Descriptions: " + countDescriptions ); |
134 | 134 |
|
135 | 135 |
logger.warn(pluralString + " to save: " + unitsToSave.size()); |
136 |
getOccurrenceService().saveOrUpdate(unitsToSave);
|
|
137 |
|
|
136 |
getOccurrenceService().saveOrUpdate(unitsToSave); |
|
137 |
|
|
138 | 138 |
return success; |
139 | 139 |
} catch (SQLException e) { |
140 | 140 |
logger.error("SQLException:" + e); |
... | ... | |
146 | 146 |
|
147 | 147 |
private void handleSiteImageSpecificFields(ResultSet rs, Media media, AlgaTerraImportState state) throws SQLException { |
148 | 148 |
//TODO |
149 |
|
|
149 |
|
|
150 | 150 |
} |
151 | 151 |
|
152 | 152 |
|
153 | 153 |
@Override |
154 | 154 |
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, BerlinModelImportState state) { |
155 |
String nameSpace; |
|
156 |
Class<?> cdmClass;
|
|
155 |
|
|
156 |
String nameSpace;
|
|
157 | 157 |
Set<String> idSet; |
158 |
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
|
|
159 |
|
|
158 |
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>(); |
|
159 |
|
|
160 | 160 |
try{ |
161 |
Set<String> ecoFactIdSet = new HashSet<String>();
|
|
162 |
|
|
161 |
Set<String> ecoFactIdSet = new HashSet<>(); |
|
162 |
|
|
163 | 163 |
while (rs.next()){ |
164 | 164 |
handleForeignKey(rs, ecoFactIdSet, "EcoFactFk"); |
165 | 165 |
} |
166 |
|
|
166 |
|
|
167 | 167 |
//field observation map |
168 | 168 |
nameSpace = AlgaTerraSpecimenImportBase.ECO_FACT_FIELD_OBSERVATION_NAMESPACE; |
169 |
cdmClass = FieldUnit.class; |
|
170 | 169 |
idSet = ecoFactIdSet; |
171 |
Map<String, FieldUnit> fieldObservationMap = (Map<String,FieldUnit>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
|
170 |
Map<String, FieldUnit> fieldObservationMap = getCommonService().getSourcedObjectsByIdInSourceC(FieldUnit.class, idSet, nameSpace);
|
|
172 | 171 |
result.put(nameSpace, fieldObservationMap); |
173 | 172 |
|
174 |
|
|
173 |
|
|
175 | 174 |
} catch (SQLException e) { |
176 | 175 |
throw new RuntimeException(e); |
177 | 176 |
} |
... | ... | |
189 | 188 |
AlgaTerraImportConfigurator config = ((AlgaTerraImportState) bmState).getAlgaTerraConfigurator(); |
190 | 189 |
return ! ( config.isDoEcoFacts() && config.isDoImages()) ; |
191 | 190 |
} |
192 |
|
|
191 |
|
|
193 | 192 |
} |
Also available in: Unified diff
adapt some classes to new CommonService.getSourcedObjectSByIdInSourceC and cleanup