Project

General

Profile

« Previous | Next » 

Revision 1eaef993

Added by Andreas Müller over 6 years ago

cleanup

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/in/DwcTaxonCsv2CdmTaxonRelationConverter.java
64 64

  
65 65

  
66 66
    @Override
67
    public IReader<MappedCdmBase> map(StreamItem item){
68
		List<MappedCdmBase> resultList = new ArrayList<MappedCdmBase>();
67
    public IReader<MappedCdmBase<? extends CdmBase>> map(StreamItem item){
68
		List<MappedCdmBase<? extends CdmBase>> resultList = new ArrayList<>();
69 69

  
70 70
		Map<String, String> csvRecord = item.map;
71 71
		Reference sourceReference = state.getTransactionalSourceReference();
......
79 79
			fireWarningEvent(warning, item, 8);
80 80
		}else{
81 81

  
82
			MappedCdmBase mcb = new MappedCdmBase(taxonBase);
82
			MappedCdmBase<? extends CdmBase> mcb = new MappedCdmBase<>(taxonBase);
83 83
			resultList.add(mcb);
84 84

  
85 85
			handleAcceptedNameUsage(item, state, taxonBase, id);
......
128 128
//		    <field index='24' term='http://purl.org/dc/terms/description'/>
129 129
//		    </core>
130 130

  
131
		return new ListReader<MappedCdmBase>(resultList);
131
		return new ListReader<>(resultList);
132 132
	}
133 133

  
134 134

  
......
168 168
	}
169 169

  
170 170

  
171
	private void handleParentNameUsage(StreamItem item, DwcaDataImportStateBase<DwcaDataImportConfiguratorBase> state, TaxonBase<?> taxonBase, String id, List<MappedCdmBase> resultList) {
172
		if (exists(TermUri.DWC_PARENT_NAME_USAGE_ID, item) || exists(TermUri.DWC_PARENT_NAME_USAGE, item)){
171
	private void handleParentNameUsage(StreamItem item, DwcaDataImportStateBase<DwcaDataImportConfiguratorBase> state,
172
	        TaxonBase<?> taxonBase, String id, List<MappedCdmBase<? extends CdmBase>> resultList) {
173

  
174
	    if (exists(TermUri.DWC_PARENT_NAME_USAGE_ID, item) || exists(TermUri.DWC_PARENT_NAME_USAGE, item)){
173 175
			String parentId = item.get(TermUri.DWC_PARENT_NAME_USAGE_ID);
174 176
			if (id.equals(parentId)){
175 177
				//taxon can't be it's own child
......
188 190
					if (classification == null){
189 191
						String warning = "Classification not found. Can't create parent-child relationship";
190 192
						fireWarningEvent(warning, item, 12);
191
					}
192
					try {
193
						classification.addParentChild(parentTaxon, taxon, citationForParentChild, null);
194
					} catch (IllegalStateException e) {
195
						String message = "Exception occurred when trying to add a child to a parent in a classification: %s";
196
						message = String.format(message, e.getMessage());
197
						fireWarningEvent(message, item, 12);
193
					}else{
194
					    try {
195
					        classification.addParentChild(parentTaxon, taxon, citationForParentChild, null);
196
					    } catch (IllegalStateException e) {
197
					        String message = "Exception occurred when trying to add a child to a parent in a classification: %s";
198
					        message = String.format(message, e.getMessage());
199
					        fireWarningEvent(message, item, 12);
200
					    }
198 201
					}
199 202
				}
200 203
			}else if (taxonBase.isInstanceOf(Synonym.class)){
......
211 214
				fireWarningEvent(message, item, 12);
212 215
			}
213 216
		}
214

  
215

  
216 217
	}
217 218

  
218 219

  
219
	private Classification getClassification(StreamItem item, List<MappedCdmBase> resultList) {
220
		Set<Classification> resultSet = new HashSet<Classification>();
220
	private Classification getClassification(StreamItem item, List<MappedCdmBase<? extends CdmBase>> resultList) {
221
		Set<Classification> resultSet = new HashSet<>();
221 222
		//
222 223
		if (config.isDatasetsAsClassifications()){
223 224
			String datasetKey = item.get(TermUri.DWC_DATASET_ID);
......
241 242
				if (StringUtils.isNotBlank(config.getClassificationName())){
242 243
					newClassification.setName(LanguageString.NewInstance(config.getClassificationName(), Language.DEFAULT()));
243 244
				}
244
				resultList.add(new MappedCdmBase(SINGLE_CLASSIFICATION, SINGLE_CLASSIFICATION_ID, newClassification));
245
				resultList.add(new MappedCdmBase<>(SINGLE_CLASSIFICATION, SINGLE_CLASSIFICATION_ID, newClassification));
245 246
				resultSet.add(newClassification);
246 247
			}
247 248
		}
......
254 255
	}
255 256

  
256 257

  
257
	private void handleAcceptedNameUsage(StreamItem item, DwcaDataImportStateBase<DwcaDataImportConfiguratorBase> state, TaxonBase taxonBase, String id) {
258
	private void handleAcceptedNameUsage(StreamItem item, DwcaDataImportStateBase<DwcaDataImportConfiguratorBase> state, TaxonBase<?> taxonBase, String id) {
258 259
		if (acceptedNameUsageExists(item)){
259 260
			String accId = item.get(TermUri.DWC_ACCEPTED_NAME_USAGE_ID);
260 261
			handleAcceptedNameUsageParam(item, state, taxonBase, id, accId);
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/in/DwcTaxonStreamItem2CdmTaxonConverter.java
109 109
    }
110 110

  
111 111
	@Override
112
    public IReader<MappedCdmBase> map(StreamItem csvTaxonRecord){
113
		List<MappedCdmBase> resultList = new ArrayList<MappedCdmBase>();
112
    public IReader<MappedCdmBase<? extends CdmBase>> map(StreamItem csvTaxonRecord){
113
		List<MappedCdmBase<? extends CdmBase>> resultList = new ArrayList<>();
114 114

  
115 115
		//TODO what if not transactional?
116 116
		Reference sourceReference = state.getTransactionalSourceReference();
......
118 118

  
119 119
		//taxon
120 120
		TaxonBase<?> taxonBase = getTaxonBase(csvTaxonRecord);
121
		MappedCdmBase  mcb = new MappedCdmBase(csvTaxonRecord.term, csvTaxonRecord.get(ID), taxonBase);
121
		MappedCdmBase<TaxonBase<?>>  mcb = new MappedCdmBase<>(csvTaxonRecord.term, csvTaxonRecord.get(ID), taxonBase);
122 122
		resultList.add(mcb);
123 123

  
124 124
		//original source
125 125
		String id = csvTaxonRecord.get(ID);
126 126
		IdentifiableSource source = taxonBase.addSource(OriginalSourceType.Import, id, "Taxon", sourceReference, sourceReferenceDetail);
127
		MappedCdmBase mappedSource = new MappedCdmBase(csvTaxonRecord.get(ID), source);
127
		MappedCdmBase<IdentifiableSource> mappedSource = new MappedCdmBase<>(csvTaxonRecord.get(ID), source);
128 128
		resultList.add(mappedSource);
129 129
		csvTaxonRecord.remove(ID);
130 130

  
......
212 212
//		    <field index='24' term='http://purl.org/dc/terms/description'/>
213 213
//		    </core>
214 214

  
215
		return new ListReader<MappedCdmBase>(resultList);
215
		return new ListReader<MappedCdmBase<? extends CdmBase>>(resultList);
216 216
	}
217 217

  
218 218

  
......
381 381
	}
382 382

  
383 383

  
384
	private void handleDataset(StreamItem item, TaxonBase<?> taxonBase, List<MappedCdmBase> resultList, Reference sourceReference, String sourceReferecenDetail) {
384
	private void handleDataset(StreamItem item, TaxonBase<?> taxonBase, List<MappedCdmBase<? extends CdmBase>> resultList, Reference sourceReference, String sourceReferecenDetail) {
385 385
		TermUri idTerm = TermUri.DWC_DATASET_ID;
386 386
		TermUri strTerm = TermUri.DWC_DATASET_NAME;
387 387

  
......
413 413
				//source
414 414
				IdentifiableSource source = classification.addSource(OriginalSourceType.Import, classificationId, "Dataset", sourceReference, sourceReferecenDetail);
415 415
				//add to result
416
				resultList.add(new MappedCdmBase(idTerm, datasetId, classification));
417
				resultList.add(new MappedCdmBase(strTerm, datasetName, classification));
418
				resultList.add(new MappedCdmBase(source));
416
				resultList.add(new MappedCdmBase<>(idTerm, datasetId, classification));
417
				resultList.add(new MappedCdmBase<>(strTerm, datasetName, classification));
418
				resultList.add(new MappedCdmBase<>(source));
419 419
				//TODO this is not so nice but currently necessary as classifications are requested in the same partition
420 420
				state.putMapping(idTerm.toString(), classificationId, classification);
421 421
				state.putMapping(strTerm.toString(), classificationName, classification);
......
449 449
		return id;
450 450
	}
451 451

  
452
	private MappedCdmBase<Reference> getNameAccordingTo(StreamItem item, List<MappedCdmBase> resultList) {
452
	private MappedCdmBase<Reference> getNameAccordingTo(StreamItem item, List<MappedCdmBase<? extends CdmBase>> resultList) {
453 453
		if (config.isDatasetsAsSecundumReference()){
454 454
			//TODO store nameAccordingTo info some where else or let the user define where to store it.
455 455
			return null;
......
500 500
	}
501 501

  
502 502

  
503
	private TaxonName getScientificName(StreamItem item, NomenclaturalCode nomCode, Rank rank, List<MappedCdmBase> resultList, Reference sourceReference) {
503
	private TaxonName getScientificName(StreamItem item, NomenclaturalCode nomCode, Rank rank, List<MappedCdmBase<? extends CdmBase>> resultList, Reference sourceReference) {
504 504
		TaxonName name = null;
505 505
		String strScientificName = getValue(item, TermUri.DWC_SCIENTIFIC_NAME);
506 506
		//Name
......
559 559
	 * @param idIsInternal
560 560
	 * @return
561 561
	 */
562
	private MappedCdmBase<Reference> getReference(StreamItem item, List<MappedCdmBase> resultList, TermUri idTerm, TermUri strTerm, boolean idIsInternal) {
562
	private MappedCdmBase<Reference> getReference(StreamItem item,
563
	        List<MappedCdmBase<? extends CdmBase>> resultList, TermUri idTerm,
564
	        TermUri strTerm, boolean idIsInternal) {
563 565
		Reference newRef = null;
564 566
		Reference sourceCitation = null;
565 567

  
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/in/EolAgent2CdmConverter.java
45 45

  
46 46

  
47 47
	@Override
48
    public IReader<MappedCdmBase> map(StreamItem item ){
49
		List<MappedCdmBase> resultList = new ArrayList<MappedCdmBase>();
48
    public IReader<MappedCdmBase<? extends CdmBase>> map(StreamItem item ){
49
		List<MappedCdmBase<? extends CdmBase>> resultList = new ArrayList<>();
50 50

  
51 51
		Map<String, String> csv = item.map;
52 52
		Reference sourceReference = state.getTransactionalSourceReference();
......
92 92

  
93 93
			}
94 94

  
95
			MappedCdmBase<Person>  mcb = new MappedCdmBase<Person>(item.term, id, person);
95
			MappedCdmBase<Person>  mcb = new MappedCdmBase<>(item.term, id, person);
96 96
			resultList.add(mcb);
97 97

  
98 98
		}else{
......
105 105

  
106 106

  
107 107
		//return
108
		return new ListReader<MappedCdmBase>(resultList);
108
		return new ListReader<>(resultList);
109 109

  
110 110
	}
111 111

  
......
145 145

  
146 146
	@Override
147 147
	public final Set<String> requiredSourceNamespaces() {
148
		Set<String> result = new HashSet<String>();
148
		Set<String> result = new HashSet<>();
149 149
 		result.add(TermUri.DWC_TAXON.toString());
150 150
 		return result;
151 151
	}
......
159 159
		return this.getClass().getName();
160 160
	}
161 161

  
162

  
163

  
164

  
165

  
166 162
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/in/GbifDescriptionCsv2CdmConverter.java
51 51
	}
52 52

  
53 53
	@Override
54
    public IReader<MappedCdmBase> map(StreamItem item ){
55
		List<MappedCdmBase> resultList = new ArrayList<MappedCdmBase>();
54
    public IReader<MappedCdmBase<? extends CdmBase>> map(StreamItem item ){
55
		List<MappedCdmBase<? extends CdmBase>> resultList = new ArrayList<>();
56 56

  
57 57
		Map<String, String> csv = item.map;
58 58
		Reference sourceReference = state.getTransactionalSourceReference();
......
84 84
					}
85 85
				}
86 86

  
87
				if (addRights && (rights != null || rights != "")) {
87
				if (addRights && (isNotBlank(rights))) {
88 88
					Rights copyright = Rights.NewInstance(rights, language);
89 89
					taxonDescription.addRights(copyright);
90 90
				}
......
99 99
				fireWarningEvent(message, item, 4);
100 100
			}
101 101

  
102
			MappedCdmBase  mcb = new MappedCdmBase(item.term, csv.get(CORE_ID), taxon);
102
			MappedCdmBase<? extends CdmBase>  mcb = new MappedCdmBase<>(item.term, csv.get(CORE_ID), taxon);
103 103
			resultList.add(mcb);
104 104
		}else{
105 105
			String message = "Taxon is not available for id '%s'";
......
107 107
			fireWarningEvent(message, item, 12);
108 108
		}
109 109

  
110
		return new ListReader<MappedCdmBase>(resultList);
110
		return new ListReader<>(resultList);
111 111
	}
112 112

  
113 113

  
......
133 133
	 * @param resultList
134 134
	 * @return
135 135
	 */
136
	private Feature getFeatureByDcType(StreamItem item, List<MappedCdmBase> resultList) {
136
	private Feature getFeatureByDcType(StreamItem item, List<MappedCdmBase<? extends CdmBase>> resultList) {
137 137
		String descriptionType = item.get(TermUri.DC_TYPE);
138 138
		item.remove(TermUri.DC_TYPE);
139 139

  
......
156 156
				feature.setSupportsTextData(true);
157 157
//				state.putMapping(namespace, type, feature);
158 158
				state.getCurrentIO().saveNewTerm(feature);
159
				MappedCdmBase  mcb = new MappedCdmBase(namespace, descriptionType, feature);
159
				MappedCdmBase<? extends CdmBase>  mcb = new MappedCdmBase<>(namespace, descriptionType, feature);
160 160
				resultList.add(mcb);
161 161
			}
162 162
			return feature;
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/in/GbifDistributionCsv2CdmConverter.java
48 48
	}
49 49

  
50 50
	@Override
51
    public IReader<MappedCdmBase> map(StreamItem item ){
52
		List<MappedCdmBase> resultList = new ArrayList<>();
51
    public IReader<MappedCdmBase<? extends CdmBase>> map(StreamItem item ){
52
		List<MappedCdmBase<? extends CdmBase>> resultList = new ArrayList<>();
53 53

  
54 54
		Map<String, String> csv = item.map;
55 55
		Reference sourceReference = state.getTransactionalSourceReference();
......
62 62
			String locationId = item.get(TermUri.DWC_LOCATION_ID);
63 63
			NamedArea area = getAreaByLocationId(item, locationId);
64 64
			if (area != null){
65
				MappedCdmBase  mcb = new MappedCdmBase(item.term, csv.get(TermUri.DWC_LOCATION_ID), area);
65
				MappedCdmBase<? extends CdmBase>  mcb = new MappedCdmBase<>(item.term, csv.get(TermUri.DWC_LOCATION_ID), area);
66 66
				resultList.add(mcb);
67 67
			}else if (! config.isExcludeLocality()){
68 68
				String locality = item.get(TermUri.DWC_LOCALITY);
69 69
				area = getAreaByLocality(item, locality);
70
				MappedCdmBase  mcb = new MappedCdmBase(item.term, csv.get(TermUri.DWC_LOCALITY), area);
70
				MappedCdmBase<? extends CdmBase>  mcb = new MappedCdmBase<>(item.term, csv.get(TermUri.DWC_LOCALITY), area);
71 71
				resultList.add(mcb);
72 72
			}
73 73

  
......
82 82
				desc.addElement(distribution);
83 83

  
84 84
				//save taxon
85
				MappedCdmBase  mcb = new MappedCdmBase(item.term, csv.get(CORE_ID), taxon);
85
				MappedCdmBase<? extends CdmBase>  mcb = new MappedCdmBase<>(item.term, csv.get(CORE_ID), taxon);
86 86
				resultList.add(mcb);
87 87
			}
88 88

  
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/in/GbifImageCsv2CdmConverter.java
43 43
	}
44 44

  
45 45
	@Override
46
    public IReader<MappedCdmBase> map(StreamItem item ){
47
		List<MappedCdmBase> resultList = new ArrayList<MappedCdmBase>();
46
    public IReader<MappedCdmBase<? extends CdmBase>> map(StreamItem item ){
47
		List<MappedCdmBase<? extends CdmBase>> resultList = new ArrayList<>();
48 48

  
49 49
		Map<String, String> csv = item.map;
50 50
		Reference sourceReference = state.getTransactionalSourceReference();
......
62 62
		}
63 63

  
64 64
		//return
65
		return new ListReader<MappedCdmBase>(resultList);
65
		return new ListReader<>(resultList);
66 66
	}
67 67

  
68 68

  
......
93 93

  
94 94
	@Override
95 95
	public Set<String> requiredSourceNamespaces() {
96
		Set<String> result = new HashSet<String>();
96
		Set<String> result = new HashSet<>();
97 97
 		result.add(TermUri.DWC_TAXON.toString());
98 98
 		return result;
99 99
	}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/in/GbifReferenceCsv2CdmConverter.java
61 61
	}
62 62

  
63 63
	@Override
64
    public IReader<MappedCdmBase> map(StreamItem item ){
65
		List<MappedCdmBase> resultList = new ArrayList<MappedCdmBase>();
64
    public IReader<MappedCdmBase<? extends CdmBase>> map(StreamItem item ){
65
		List<MappedCdmBase<? extends CdmBase>> resultList = new ArrayList<>();
66 66

  
67 67
		Map<String, String> csv = item.map;
68 68
		Reference sourceReference = state.getTransactionalSourceReference();
......
108 108
		handleType(reference, strType, taxon, resultList, item);
109 109

  
110 110

  
111
		return new ListReader<MappedCdmBase>(resultList);
111
		return new ListReader<>(resultList);
112 112
	}
113 113

  
114 114

  
115
	private void handleType(Reference reference, String strType, TaxonBase<?> taxon, List<MappedCdmBase> resultList, StreamItem item) {
115
	private void handleType(Reference reference, String strType, TaxonBase<?> taxon,
116
	        List<MappedCdmBase<? extends CdmBase>> resultList, StreamItem item) {
116 117
		// TODO handleType not yet implemented
117 118

  
118 119
		if (taxon == null){
......
231 232
		return tp;
232 233
	}
233 234

  
234
	private TeamOrPersonBase handleCreator(String strCreator) {
235
	private TeamOrPersonBase<?> handleCreator(String strCreator) {
235 236
		Team team = Team.NewTitledInstance(strCreator, strCreator);
236 237
		return team;
237 238
	}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/in/GbifTypesAndSpecimen2CdmConverter.java
52 52
	}
53 53

  
54 54
	@Override
55
    public IReader<MappedCdmBase> map(StreamItem item ){
56
		List<MappedCdmBase> resultList = new ArrayList<MappedCdmBase>();
55
    public IReader<MappedCdmBase<? extends CdmBase>> map(StreamItem item ){
56
		List<MappedCdmBase<? extends CdmBase>> resultList = new ArrayList<>();
57 57

  
58 58
		Reference sourceReference = state.getTransactionalSourceReference();
59 59
		String sourceReferecenDetail = null;
......
91 91
				if (typeStatus.isInstanceOf(SpecimenTypeDesignationStatus.class)){
92 92
					SpecimenTypeDesignationStatus status = CdmBase.deproxy(typeStatus, SpecimenTypeDesignationStatus.class);
93 93
					name.addSpecimenTypeDesignation(specimen, status, null, null, null, false, true);
94
					MappedCdmBase<?>  mcb = new MappedCdmBase(taxon);
94
					MappedCdmBase<? extends CdmBase>  mcb = new MappedCdmBase<>(taxon);
95 95
					resultList.add(mcb);
96 96
				}else if (typeStatus.isInstanceOf(NameTypeDesignationStatus.class)){
97 97
					String message = "NameTypeDesignation not yet implemented";
......
103 103
				}
104 104
			}
105 105

  
106
			MappedCdmBase<?>  mcb = new MappedCdmBase(specimen);
106
			MappedCdmBase<? extends CdmBase>  mcb = new MappedCdmBase<>(specimen);
107 107
			resultList.add(mcb);
108 108

  
109 109
		}else{
......
112 112
		}
113 113

  
114 114
		//return
115
		return new ListReader<MappedCdmBase>(resultList);
115
		return new ListReader<>(resultList);
116 116
	}
117 117

  
118 118

  
119
	private Collection getCollection(DwcaDataImportStateBase state, StreamItem item, List<MappedCdmBase> resultList) {
119
	private Collection getCollection(DwcaDataImportStateBase state, StreamItem item,
120
	        List<MappedCdmBase<? extends CdmBase>> resultList) {
120 121
		String institutionCode = item.get(TermUri.DWC_INSTITUTION_CODE);
121 122
		String collectionCode = item.get(TermUri.DWC_COLLECTION_CODE);
122 123
		//institution
123 124
		Institution institution = getInstitutionByInstitutionCode(item, institutionCode);
124 125
		if (institution != null){
125
			MappedCdmBase  mcb = new MappedCdmBase(item.term, item.get(TermUri.DWC_INSTITUTION_CODE), institution);
126
			MappedCdmBase<? extends CdmBase>  mcb = new MappedCdmBase<>(item.term, item.get(TermUri.DWC_INSTITUTION_CODE), institution);
126 127
			resultList.add(mcb);
127 128
		}
128 129
		//collection
129 130
		Collection collection = getCollectionByCollectionCode(item, collectionCode, institution);
130 131
		if (collection != null){
131
			MappedCdmBase  mcb = new MappedCdmBase(item.term, item.get(TermUri.DWC_COLLECTION_CODE), collection);
132
			MappedCdmBase<? extends CdmBase>  mcb = new MappedCdmBase<>(item.term, item.get(TermUri.DWC_COLLECTION_CODE), collection);
132 133
			resultList.add(mcb);
133 134
		}
134 135
		return collection;
......
280 281

  
281 282
	@Override
282 283
	public Set<String> requiredSourceNamespaces() {
283
		Set<String> result = new HashSet<String>();
284
		Set<String> result = new HashSet<>();
284 285
 		result.add(TermUri.DWC_TAXON.toString());
285 286
 		result.add(TermUri.DWC_LOCATION_ID.toString());
286 287
 		return result;
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/in/GbifVernacularNameCsv2CdmConverter.java
45 45

  
46 46

  
47 47
	@Override
48
    public IReader<MappedCdmBase> map(StreamItem item ){
49
		List<MappedCdmBase> resultList = new ArrayList<MappedCdmBase>();
48
    public IReader<MappedCdmBase<? extends CdmBase>> map(StreamItem item ){
49
		List<MappedCdmBase<? extends CdmBase>> resultList = new ArrayList<>();
50 50

  
51 51
		Map<String, String> csv = item.map;
52 52
		Reference sourceReference = state.getTransactionalSourceReference();
......
55 55
		String id = csv.get(CORE_ID);
56 56
		Taxon taxon = getTaxonBase(id, item, Taxon.class, state);
57 57
		if (taxon != null){
58
			MappedCdmBase  mcb = new MappedCdmBase(item.term, csv.get(CORE_ID), taxon);
58
			MappedCdmBase<? extends CdmBase>  mcb = new MappedCdmBase<>(item.term, csv.get(CORE_ID), taxon);
59 59
			String vernacular = item.get(TermUri.DWC_VERNACULAR_NAME);
60 60
			//TODO language, area,
61 61
			TaxonDescription desc = getTaxonDescription(taxon, false);
......
71 71
		}
72 72

  
73 73
		//return
74
		return new ListReader<MappedCdmBase>(resultList);
74
		return new ListReader<>(resultList);
75 75

  
76 76
	}
77 77

  
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/in/IConverter.java
1 1
/**
2 2
* Copyright (C) 2009 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
*/
9 9
package eu.etaxonomy.cdm.io.dwca.in;
10 10

  
11
import eu.etaxonomy.cdm.model.common.CdmBase;
11 12

  
12 13
/**
13 14
 * Interface for all converters from some input to some output.
14 15
 * Supports mapping of input to output and identifier identification.
15
 * 
16
 *
16 17
 * @author a.mueller
17 18
 * @date 23.11.2011
18 19
 *
19 20
 */
20 21
public interface IConverter<IN extends IConverterInput, OUT extends IConverterOutput, SOURCE_ID extends Object> {
21 22

  
22
	public IReader<MappedCdmBase> map(IN item); 
23
	
23
	public IReader<MappedCdmBase<? extends CdmBase>> map(IN item);
24

  
24 25
	/**
25 26
	 * Returns the identifier (if any) of the input
26 27
	 * @param item
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/in/StreamPartitioner.java
28 28
 * @author a.mueller
29 29
 *
30 30
 */
31
public class StreamPartitioner<ITEM extends IConverterInput>  implements INamespaceReader<IReader<MappedCdmBase>>{
31
public class StreamPartitioner<ITEM extends IConverterInput>
32
            implements INamespaceReader<IReader<MappedCdmBase<? extends CdmBase>>>{
32 33
	private static final Logger logger = Logger.getLogger(StreamPartitioner.class);
33 34

  
34 35
	private final int partitionSize;
35 36
	private final LookAheadStream<ITEM> inStream;
36 37
	private final IPartitionableConverter converter;
37 38
	private final StreamImportStateBase<StreamImportConfiguratorBase, StreamImportBase> state;
38
	private ConcatenatingReader<MappedCdmBase> outStream;
39
	private ConcatenatingReader<MappedCdmBase<? extends CdmBase>> outStream;
39 40

  
40 41
	public StreamPartitioner(INamespaceReader<ITEM> input, IPartitionableConverter converter, StreamImportStateBase state, Integer size){
41 42
		 this.inStream = new LookAheadStream<ITEM>(input);
......
47 48

  
48 49

  
49 50
	private void initNewOutStream(){
50
		outStream = new ConcatenatingReader<MappedCdmBase>();
51
		outStream = new ConcatenatingReader<>();
51 52
	}
52 53

  
53 54
	@Override
......
61 62
	}
62 63

  
63 64
	@Override
64
	public IReader<MappedCdmBase> read() {
65
	public IReader<MappedCdmBase<? extends CdmBase>> read() {
65 66
		logger.debug("Start partitioner read");
66 67
		handleNextPartition();
67
		IReader<MappedCdmBase> result = this.outStream;
68
		IReader<MappedCdmBase<? extends CdmBase>> result = this.outStream;
68 69

  
69 70
		initNewOutStream();
70 71
		logger.debug("End partitioner read");
......
88 89
		state.loadRelatedObjects(partialMapping);
89 90

  
90 91
		while (inStream.isLookingAhead() && inStream.hasNext()){
91
			IReader<MappedCdmBase> resultReader = converter.map(inStream.read());
92
			List<MappedCdmBase> resultList = new ArrayList<MappedCdmBase>();  //maybe better let converter return list from the beginning
92
			IReader<MappedCdmBase<? extends CdmBase>> resultReader = converter.map(inStream.read());
93
			List<MappedCdmBase<? extends CdmBase>> resultList = new ArrayList<>();  //maybe better let converter return list from the beginning
93 94
			while (resultReader.hasNext()){
94
				MappedCdmBase item = resultReader.read();
95
				MappedCdmBase<? extends CdmBase> item = resultReader.read();
95 96
				resultList.add(item);
96
				addItemToRelatedObjects(item);
97
				if (item.getCdmBase().isInstanceOf(IdentifiableEntity.class)) {
98
				    addItemToRelatedObjects((MappedCdmBase<IdentifiableEntity>)item);
99
				}else{
100
				    logger.error("Non identifiable objects can not be added to related objects yet");
101
				}
97 102
			}
98
			outStream.add(new ListReader<MappedCdmBase>(resultList));
103
			outStream.add(new ListReader<>(resultList));
99 104
		}
100 105

  
101 106
		return;
......
107 112
	 * Add new items to the local mapping
108 113
	 * @param item
109 114
	 */
110
	private void addItemToRelatedObjects(MappedCdmBase<IdentifiableEntity> item) {
115
	private void addItemToRelatedObjects(MappedCdmBase<? extends IdentifiableEntity> item) {
111 116
		CdmBase cdmBase = item.getCdmBase();
112 117
		if (cdmBase.getId() == 0){
113 118
			if (cdmBase.isInstanceOf(IdentifiableEntity.class)){
114 119
			    Set<String> requiredSourceNamespaces = converter.requiredSourceNamespaces();
115 120
				if (requiredSourceNamespaces.contains(item.getNamespace())){
116
					state.addRelatedObject(item.getNamespace(), item.getSourceId(),  item.getCdmBase());
121
					if (item.getCdmBase().isInstanceOf(IdentifiableEntity.class)) {
122
					    IdentifiableEntity identEntity = CdmBase.deproxy(item.getCdmBase(), IdentifiableEntity.class);
123
                        state.addRelatedObject(item.getNamespace(), item.getSourceId(), identEntity);
124
                    }else{
125

  
126
                    }
117 127
				}
118 128
			}
119 129
		}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/stream/StreamImportBase.java
42 42
 * @author a.mueller
43 43
 *
44 44
 */
45
public abstract class StreamImportBase<CONFIG extends StreamImportConfiguratorBase, STATE extends StreamImportStateBase<CONFIG,StreamImportBase>> extends CdmImportBase<CONFIG, STATE>{
46
	private static final Logger logger = Logger.getLogger(StreamImportBase.class);
45
public abstract class StreamImportBase<CONFIG extends StreamImportConfiguratorBase, STATE extends StreamImportStateBase<CONFIG,StreamImportBase>>
46
        extends CdmImportBase<CONFIG, STATE>{
47

  
48
    private static final long serialVersionUID = -125414263689509881L;
49
    private static final Logger logger = Logger.getLogger(StreamImportBase.class);
47 50

  
48 51

  
49 52
	protected void makeSourceRef(STATE state) {
......
72 75

  
73 76
			ItemFilter<StreamItem> filter = partitionConverter.getItemFilter();
74 77
			IItemStream filteredStream = filter == null ? recordStream : new FilteredStream(recordStream, filter);
75
			StreamPartitioner<StreamItem> partitionStream = new StreamPartitioner<StreamItem>(filteredStream,
78
			StreamPartitioner<StreamItem> partitionStream = new StreamPartitioner<>(filteredStream,
76 79
					partitionConverter, state, partitionSize);//   (csvStream, streamConverter,state 1000);
77 80

  
78 81
			int i = 1;
......
81 84
				TransactionStatus tx = startTransaction();
82 85

  
83 86
				try {
84
					IReader<MappedCdmBase> partStream = partitionStream.read();
87
					IReader<MappedCdmBase<? extends CdmBase>> partStream = partitionStream.read();
85 88

  
86 89
					fireProgressEvent("Handel " + i + ". partition", i + ". partition");
87 90
					logger.info("Handel " + i++ + ". partition");
......
140 143
			state.setSuccess(false);
141 144
			return;
142 145
		}
143
		IReader<MappedCdmBase> resultReader = converter.map(item);
146
		IReader<MappedCdmBase<? extends CdmBase>> resultReader = converter.map(item);
144 147
		handleResults(state, resultReader, item.getLocation());
145 148
		return;
146 149
	}
......
151 154
	 * @param item
152 155
	 * @param resultReader
153 156
	 */
154
	private void handleResults(STATE state, IReader<MappedCdmBase> resultReader, String location) {
157
	private void handleResults(STATE state, IReader<MappedCdmBase<? extends CdmBase>> resultReader, String location) {
155 158
		while (resultReader.hasNext()){
156 159

  
157 160
			MappedCdmBase<?> mappedCdmBase = resultReader.read();
......
277 280
	}
278 281

  
279 282

  
280

  
281

  
282
	/* (non-Javadoc)
283
	 * @see eu.etaxonomy.cdm.io.common.CdmImportBase#getFeature(eu.etaxonomy.cdm.io.common.ImportStateBase, java.util.UUID, java.lang.String, java.lang.String, java.lang.String, eu.etaxonomy.cdm.model.common.TermVocabulary)
284
	 */
285 283
	//Make public to allow to use by converters
286 284
	@Override
287 285
	public Feature getFeature(STATE state, UUID uuid, String label, String description, String labelAbbrev, TermVocabulary<Feature> voc) {

Also available in: Unified diff