Revision 85cf08c3
Added by Andreas Müller about 11 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/algaterra/AlgaTerraCollectionImport.java | ||
---|---|---|
27 | 27 |
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner; |
28 | 28 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
29 | 29 |
import eu.etaxonomy.cdm.model.occurrence.Collection; |
30 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit; |
|
31 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
|
30 | 32 |
import eu.etaxonomy.cdm.model.reference.Reference; |
31 | 33 |
|
32 | 34 |
|
... | ... | |
60 | 62 |
protected String getIdQuery(BerlinModelImportState state) { |
61 | 63 |
String result = " SELECT CollectionId " + |
62 | 64 |
" FROM Collection c " |
63 |
+ " ORDER BY c.CollectionId "; |
|
65 |
+ " ORDER BY partOfFk, c.CollectionId ";
|
|
64 | 66 |
return result; |
65 | 67 |
} |
66 | 68 |
|
... | ... | |
70 | 72 |
@Override |
71 | 73 |
protected String getRecordQuery(BerlinModelImportConfigurator config) { |
72 | 74 |
String strQuery = |
73 |
" SELECT CollectionId, Name, Town, IHCode, Subcollection, TDWGGazetteerFk, Address, CultCollFlag, " + |
|
75 |
" SELECT CollectionId, Name, Town, IHCode, Subcollection, partOfFk, TDWGGazetteerFk, Address, CultCollFlag, " +
|
|
74 | 76 |
" Created_When, Updated_When, Created_Who, Updated_Who, Notes " + |
75 | 77 |
" FROM Collection c " + |
76 | 78 |
" WHERE c.CollectionId IN (" + ID_LIST_TOKEN + ") " |
77 |
+ " ORDER BY c.CollectionId " |
|
79 |
+ " ORDER BY partOfFk, c.CollectionId "
|
|
78 | 80 |
; |
79 | 81 |
return strQuery; |
80 | 82 |
} |
... | ... | |
87 | 89 |
|
88 | 90 |
AlgaTerraImportState state = (AlgaTerraImportState)bmState; |
89 | 91 |
Set<Collection> collectionsToSave = new HashSet<Collection>(); |
92 |
|
|
93 |
|
|
94 |
Map<String, Collection> collectionMap = (Map<String, Collection>) partitioner.getObjectMap(NAMESPACE_COLLECTION); |
|
95 |
|
|
90 | 96 |
|
91 | 97 |
ResultSet rs = partitioner.getResultSet(); |
92 | 98 |
|
... | ... | |
104 | 110 |
String town = rs.getString("Town"); |
105 | 111 |
String ihCode = rs.getString("IHCode"); |
106 | 112 |
String subCollectionStr = rs.getString("Subcollection"); |
107 |
Integer tdwgArea = nullSafeInt(rs, "TDWGGazetteerFk"); //somehow redundant with town |
|
108 |
String address = rs.getString("Address"); //only available for BGBM |
|
109 |
Boolean cultCollFlag = rs.getBoolean("CultCollFlag"); //?? not really needed according to Henning |
|
113 |
Integer partOfFk = nullSafeInt(rs, "PartOfFk"); |
|
114 |
|
|
115 |
// Integer tdwgArea = nullSafeInt(rs, "TDWGGazetteerFk"); //somehow redundant with town |
|
116 |
// String address = rs.getString("Address"); //only available for BGBM |
|
117 |
// Boolean cultCollFlag = rs.getBoolean("CultCollFlag"); //?? not really needed according to Henning |
|
118 |
|
|
110 | 119 |
//TODO createdUpdates, NOtes |
111 | 120 |
|
112 | 121 |
try { |
... | ... | |
115 | 124 |
Reference<?> sourceRef = state.getTransactionalSourceReference(); |
116 | 125 |
|
117 | 126 |
|
118 |
Collection collection = Collection.NewInstance(); |
|
119 |
collection.setName(name); |
|
120 |
if (isNotBlank("ihCode")){ |
|
121 |
collection.setCode(ihCode); |
|
122 |
collection.setCodeStandard("Index Herbariorum"); |
|
127 |
//collection |
|
128 |
Collection collection; |
|
129 |
if (partOfFk == null){ |
|
130 |
collection = makeCollection(collectionsToSave, |
|
131 |
collectionId, name, town, ihCode, sourceRef, NAMESPACE_COLLECTION, collectionMap); |
|
132 |
}else{ |
|
133 |
collection = collectionMap.get(String.valueOf(partOfFk)); |
|
134 |
if (collection == null){ |
|
135 |
logger.warn("PartOf collection not found"); |
|
136 |
} |
|
123 | 137 |
} |
124 | 138 |
|
125 |
collection.setTownOrLocation(town); |
|
126 |
collection.addSource(String.valueOf(collectionId), NAMESPACE_COLLECTION, sourceRef, null); |
|
127 |
|
|
128 |
collectionsToSave.add(collection); //or subcollection ? |
|
129 | 139 |
|
130 | 140 |
//subcollection |
131 | 141 |
if (isNotBlank(subCollectionStr)){ |
132 |
Collection subCollection = Collection.NewInstance(); |
|
133 |
subCollection.setName(subCollectionStr); |
|
142 |
Collection subCollection = makeCollection(collectionsToSave, collectionId, subCollectionStr, town, ihCode, sourceRef, NAMESPACE_SUBCOLLECTION, collectionMap); |
|
134 | 143 |
subCollection.setSuperCollection(collection); |
135 |
collectionsToSave.add(subCollection); //or subcollection ? |
|
136 |
collection.addSource(String.valueOf(collectionId), NAMESPACE_SUBCOLLECTION, sourceRef, null); |
|
137 | 144 |
} |
138 | 145 |
|
139 |
//TODO partOfFk , movedToFk |
|
146 |
|
|
147 |
//TODO movedToFk (extension ??) |
|
140 | 148 |
|
141 | 149 |
|
142 | 150 |
} catch (Exception e) { |
... | ... | |
158 | 166 |
|
159 | 167 |
|
160 | 168 |
|
169 |
/** |
|
170 |
* @param collectionsToSave |
|
171 |
* @param collectionId |
|
172 |
* @param name |
|
173 |
* @param town |
|
174 |
* @param ihCode |
|
175 |
* @param sourceRef |
|
176 |
* @param collectionMap |
|
177 |
* @return |
|
178 |
*/ |
|
179 |
private Collection makeCollection(Set<Collection> collectionsToSave, int collectionId, |
|
180 |
String name, String town, String ihCode, Reference<?> sourceRef, String namespace, Map<String, Collection> collectionMap) { |
|
181 |
Collection collection = Collection.NewInstance(); |
|
182 |
collection.setName(name); |
|
183 |
if (isNotBlank(ihCode)){ |
|
184 |
collection.setCode(ihCode); |
|
185 |
collection.setCodeStandard("Index Herbariorum"); |
|
186 |
} |
|
187 |
|
|
188 |
collection.setTownOrLocation(town); |
|
189 |
collection.addSource(String.valueOf(collectionId), namespace, sourceRef, null); |
|
190 |
|
|
191 |
collectionMap.put(String.valueOf(collectionId), collection); |
|
192 |
collectionsToSave.add(collection); //or subcollection ? |
|
193 |
return collection; |
|
194 |
} |
|
195 |
|
|
196 |
|
|
197 |
|
|
161 | 198 |
/* (non-Javadoc) |
162 | 199 |
* @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#getRelatedObjectsForPartition(java.sql.ResultSet) |
163 | 200 |
*/ |
164 | 201 |
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs) { |
165 |
//no related objects are needed |
|
202 |
String nameSpace; |
|
203 |
Class cdmClass; |
|
204 |
Set<String> idSet; |
|
166 | 205 |
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>(); |
167 | 206 |
|
207 |
try{ |
|
208 |
Set<String> collectionIdSet = new HashSet<String>(); |
|
209 |
|
|
210 |
while (rs.next()){ |
|
211 |
handleForeignKey(rs, collectionIdSet, "partOfFk"); |
|
212 |
} |
|
213 |
|
|
214 |
//type specimen map |
|
215 |
nameSpace = NAMESPACE_COLLECTION; |
|
216 |
cdmClass = Collection.class; |
|
217 |
idSet = collectionIdSet; |
|
218 |
Map<String, Collection> collectionMap = (Map<String, Collection>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
|
219 |
result.put(nameSpace, collectionMap); |
|
220 |
|
|
221 |
|
|
222 |
} catch (SQLException e) { |
|
223 |
throw new RuntimeException(e); |
|
224 |
} |
|
168 | 225 |
return result; |
169 | 226 |
|
170 | 227 |
} |
Also available in: Unified diff
some bugfixes for collection import