Revision 0d6a5e24
Added by Andreas Müller over 6 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/in/DatabaseMapping.java | ||
---|---|---|
57 | 57 |
|
58 | 58 |
private ICdmDataSource datasource; |
59 | 59 |
private final String mappingId; |
60 |
private final Map<String, Class> shortCuts = new HashMap<String, Class>();
|
|
61 |
private final Map<Class, String> reverseShortCuts = new HashMap<Class, String>();
|
|
60 |
private final Map<String, Class> shortCuts = new HashMap<>(); |
|
61 |
private final Map<Class, String> reverseShortCuts = new HashMap<>(); |
|
62 | 62 |
|
63 | 63 |
|
64 | 64 |
@Override |
... | ... | |
81 | 81 |
|
82 | 82 |
@Override |
83 | 83 |
public void putMapping(String namespace, String sourceKey, IdentifiableEntity destinationObject){ |
84 |
CdmKey<IdentifiableEntity<?>> cdmKey = new CdmKey(destinationObject); |
|
84 |
CdmKey<IdentifiableEntity<?>> cdmKey = new CdmKey<>(destinationObject);
|
|
85 | 85 |
putMapping(namespace, sourceKey, cdmKey); |
86 | 86 |
} |
87 | 87 |
|
... | ... | |
149 | 149 |
|
150 | 150 |
@Override |
151 | 151 |
public Set<CdmKey> get(String sourceNamespace, String sourceId) { |
152 |
Set<CdmKey> result = new HashSet<CdmKey>();
|
|
152 |
Set<CdmKey> result = new HashSet<>(); |
|
153 | 153 |
String normalizedKey = normalizeKey(sourceId); |
154 | 154 |
String selectMappingSql = " SELECT %s, %s FROM %s" + |
155 | 155 |
" WHERE %s = '%s' AND %s = '%s' AND %s = '%s' "; |
... | ... | |
166 | 166 |
throw new RuntimeException("Destination id for import mapping is 'null'"); |
167 | 167 |
} |
168 | 168 |
|
169 |
Class clazz = getCdmClass(clazzStr); |
|
169 |
Class<?> clazz = getCdmClass(clazzStr);
|
|
170 | 170 |
|
171 |
CdmKey<?> key = new CdmKey(clazz, Integer.valueOf(String.valueOf(id))); |
|
171 |
CdmKey<?> key = new CdmKey<>(clazz, Integer.valueOf(String.valueOf(id)));
|
|
172 | 172 |
result.add(key); |
173 | 173 |
} |
174 | 174 |
} catch (NumberFormatException e) { |
... | ... | |
257 | 257 |
* @return |
258 | 258 |
* @throws ClassNotFoundException |
259 | 259 |
*/ |
260 |
private Class getCdmClass(String clazzStr) throws ClassNotFoundException { |
|
261 |
Class clazz = shortCuts.get(clazzStr); |
|
260 |
private Class<?> getCdmClass(String clazzStr) throws ClassNotFoundException {
|
|
261 |
Class<?> clazz = shortCuts.get(clazzStr);
|
|
262 | 262 |
if (clazz == null){ |
263 | 263 |
clazz = Class.forName(clazzStr); |
264 | 264 |
} |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/in/GbifDistributionCsv2CdmConverter.java | ||
---|---|---|
49 | 49 |
|
50 | 50 |
@Override |
51 | 51 |
public IReader<MappedCdmBase> map(StreamItem item ){ |
52 |
List<MappedCdmBase> resultList = new ArrayList<MappedCdmBase>();
|
|
52 |
List<MappedCdmBase> resultList = new ArrayList<>(); |
|
53 | 53 |
|
54 | 54 |
Map<String, String> csv = item.map; |
55 | 55 |
Reference sourceReference = state.getTransactionalSourceReference(); |
... | ... | |
92 | 92 |
} |
93 | 93 |
|
94 | 94 |
//return |
95 |
return new ListReader<MappedCdmBase>(resultList);
|
|
95 |
return new ListReader<>(resultList); |
|
96 | 96 |
} |
97 | 97 |
|
98 | 98 |
|
... | ... | |
168 | 168 |
|
169 | 169 |
@Override |
170 | 170 |
public Set<String> requiredSourceNamespaces() { |
171 |
Set<String> result = new HashSet<String>();
|
|
171 |
Set<String> result = new HashSet<>(); |
|
172 | 172 |
result.add(TermUri.DWC_TAXON.toString()); |
173 | 173 |
result.add(TermUri.DWC_LOCATION_ID.toString()); |
174 | 174 |
return result; |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/stream/StreamImportStateBase.java | ||
---|---|---|
135 | 135 |
|
136 | 136 |
|
137 | 137 |
public void loadRelatedObjects (InMemoryMapping mapping){ |
138 |
Map<String, Map<String, IdentifiableEntity>> result = new HashMap<String, Map<String,IdentifiableEntity>>();
|
|
138 |
Map<String, Map<String, IdentifiableEntity>> result = new HashMap<>(); |
|
139 | 139 |
|
140 | 140 |
List<MappingEntry<String, String, Class, Integer>> mappingEntryList = mapping.getEntryList(); |
141 | 141 |
|
142 | 142 |
//order ids by destination classes |
143 |
Map<Class, Set<Integer>> destinationNamespaceMap = new HashMap<Class, Set<Integer>>();
|
|
143 |
Map<Class, Set<Integer>> destinationNamespaceMap = new HashMap<>(); |
|
144 | 144 |
for (MappingEntry<String, String, Class, Integer> entry : mappingEntryList){ |
145 | 145 |
Set<Integer> idSet = destinationNamespaceMap.get(entry.getDestinationNamespace()); |
146 | 146 |
if (idSet == null){ |
... | ... | |
151 | 151 |
} |
152 | 152 |
|
153 | 153 |
//retrieve cdm objects per class |
154 |
Map<Class, Map<Integer, IdentifiableEntity>> classMap = new HashMap<Class, Map<Integer,IdentifiableEntity>>();
|
|
154 |
Map<Class, Map<Integer, IdentifiableEntity>> classMap = new HashMap<>(); |
|
155 | 155 |
for (Class<?> cdmClass : destinationNamespaceMap.keySet()){ |
156 | 156 |
IIdentifiableEntityService<?> classService = getCurrentIO().getServiceByClass(cdmClass); |
157 | 157 |
Set<Integer> idSet = destinationNamespaceMap.get(cdmClass); |
158 | 158 |
List<? extends IdentifiableEntity> relatedObjects = classService.findById(idSet); |
159 | 159 |
|
160 | 160 |
//put into id map |
161 |
Map<Integer, IdentifiableEntity> idMap = new HashMap<Integer, IdentifiableEntity>();
|
|
161 |
Map<Integer, IdentifiableEntity> idMap = new HashMap<>(); |
|
162 | 162 |
for (IdentifiableEntity<?> identEnt : relatedObjects){ |
163 | 163 |
idMap.put(identEnt.getId(), identEnt); |
164 | 164 |
} |
... | ... | |
199 | 199 |
// } |
200 | 200 |
|
201 | 201 |
public void unloadPartitionStore(Map<String, Map<String, IdentifiableEntity>> partitionStore) { |
202 |
this.partitionStore = new HashMap<String, Map<String,IdentifiableEntity>>();
|
|
202 |
this.partitionStore = new HashMap<>(); |
|
203 | 203 |
} |
204 | 204 |
|
205 | 205 |
public IImportMapping getMapping() { |
... | ... | |
210 | 210 |
private Map<String, IdentifiableEntity> getOrMakeNamespaceMap(Map<String, Map<String, IdentifiableEntity>> relatedObjectMap2, String namespace) { |
211 | 211 |
Map<String, IdentifiableEntity> namespaceMap = relatedObjectMap2.get(namespace); |
212 | 212 |
if (namespaceMap == null){ |
213 |
namespaceMap = new HashMap<String, IdentifiableEntity>();
|
|
213 |
namespaceMap = new HashMap<>(); |
|
214 | 214 |
relatedObjectMap2.put(namespace, namespaceMap); |
215 | 215 |
} |
216 | 216 |
return namespaceMap; |
Also available in: Unified diff
cleanup