Project

General

Profile

« Previous | Next » 

Revision c189e0fb

Added by Andreas Müller almost 3 years ago

cleanup and return empty Set (not null) for getOriginals

View differences:

cdmlib-ext/src/main/java/eu/etaxonomy/cdm/ext/geo/EditGeoService.java
238 238

  
239 239
        @SuppressWarnings("rawtypes")
240 240
        Set<SpecimenOrObservationBase> originals = derivedUnit.getOriginals();
241
        if (originals != null) {
242
            for (SpecimenOrObservationBase<?> original : originals) {
243
                if (original instanceof FieldUnit) {
244
                    if (((FieldUnit) original).getGatheringEvent() != null) {
245
                        Point point = ((FieldUnit) original).getGatheringEvent().getExactLocation();
246
                        if (point != null) {
247
                            // points with no longitude or latitude should not exist
248
                            // see  #4173 ([Rule] Longitude and Latitude in Point must not be null)
249
                            if (point.getLatitude() == null || point.getLongitude() == null){
250
                                continue;
251
                            }
252
                            // FIXME: remove next statement after
253
                            // DerivedUnitFacade or ABCD import is fixed
254
                            //
255
                            if(point.getLatitude() == 0.0 || point.getLongitude() == 0.0) {
256
                                continue;
257
                            }
258
                            derivedUnitPoints.add(point);
241
        for (SpecimenOrObservationBase<?> original : originals) {
242
            if (original instanceof FieldUnit) {
243
                if (((FieldUnit) original).getGatheringEvent() != null) {
244
                    Point point = ((FieldUnit) original).getGatheringEvent().getExactLocation();
245
                    if (point != null) {
246
                        // points with no longitude or latitude should not exist
247
                        // see  #4173 ([Rule] Longitude and Latitude in Point must not be null)
248
                        if (point.getLatitude() == null || point.getLongitude() == null){
249
                            continue;
259 250
                        }
251
                        // FIXME: remove next statement after
252
                        // DerivedUnitFacade or ABCD import is fixed
253
                        //
254
                        if(point.getLatitude() == 0.0 || point.getLongitude() == 0.0) {
255
                            continue;
256
                        }
257
                        derivedUnitPoints.add(point);
260 258
                    }
261
                } else {
262
                    registerDerivedUnitLocations((DerivedUnit) original, derivedUnitPoints);
263 259
                }
260
            } else {
261
                registerDerivedUnitLocations((DerivedUnit) original, derivedUnitPoints);
264 262
            }
265 263
        }
266 264
    }
cdmlib-ext/src/main/java/eu/etaxonomy/cdm/ext/geo/kml/KMLDocumentBuilder.java
118 118
		}
119 119
	}
120 120

  
121
	/**
122
	 * @param documentFeatures
123
	 * @param fieldUnit
124
	 * @param gatherEvent
125
	 */
126 121
	private void createFieldUnitPlacemarks(List<Feature> documentFeatures, FieldUnit fieldUnit) {
127 122

  
128 123
		GatheringEvent gatherEvent = fieldUnit.getGatheringEvent();
......
135 130
		}
136 131
	}
137 132

  
138

  
139
	/**
140
	 * @param exactLocation
141
	 * @param altitude
142
	 * @param locationType
143
	 * @param recordBases
144
	 * @return
145
	 */
146 133
	private Placemark fieldUnitLocationMarker(Point exactLocation, Integer altitude, Set<SpecimenOrObservationType> recordBases) {
147 134

  
148 135
		Placemark mapMarker = KmlFactory.createPlacemark();
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/occurrence/DerivedUnit.java
271 271
		if(getDerivedFrom() != null){
272 272
			return getDerivedFrom().getOriginals();
273 273
		}
274
		return null;
274
		return new HashSet<>();
275 275
	}
276 276

  
277 277
	public Collection getCollection(){
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/occurrence/FieldUnit.java
101 101

  
102 102
	/**
103 103
	 * Factory method.
104
	 * @return
105 104
	 */
106 105
	public static FieldUnit NewInstance(){
107 106
		return new FieldUnit();
......
142 141
    }
143 142

  
144 143

  
144

  
145

  
145 146
// ************************ GETTER / SETTER *******************************************
146 147

  
147 148
	public GatheringEvent getGatheringEvent() {
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/facade/DerivedUnitFacade.java
1298 1298
	/**
1299 1299
	 * convienience method for {@link #getLocality()}.
1300 1300
	 * {@link LanguageString#getText() getText()}
1301
	 *
1302
	 * @return
1303 1301
	 */
1304 1302
	@Transient
1305 1303
	public String getLocalityText() {
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/facade/DerivedUnitFacadeFieldUnitCacheStrategy.java
16 16

  
17 17
import eu.etaxonomy.cdm.common.CdmUtils;
18 18
import eu.etaxonomy.cdm.model.agent.AgentBase;
19
import eu.etaxonomy.cdm.model.agent.Institution;
20 19
import eu.etaxonomy.cdm.model.agent.Person;
21 20
import eu.etaxonomy.cdm.model.agent.Team;
22 21
import eu.etaxonomy.cdm.model.common.CdmBase;
23 22
import eu.etaxonomy.cdm.model.common.Language;
24 23
import eu.etaxonomy.cdm.model.common.TimePeriod;
25 24
import eu.etaxonomy.cdm.model.location.NamedArea;
26
import eu.etaxonomy.cdm.model.occurrence.Collection;
27 25
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
28 26
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
29 27
import eu.etaxonomy.cdm.model.term.Representation;
......
202 200
		}
203 201
	}
204 202

  
205
	/**
206
	 * @param facade
207
	 */
208
	private String getCode(DerivedUnitFacade facade) {
209
		String code = "";
210
		if(facade.getCollection() != null){
211
			code = facade.getCollection().getCode();
212
			if (isBlank(code)){
213
				Institution institution = facade.getCollection().getInstitute();
214
				if (institution != null){
215
					code = institution.getCode();
216
				}
217
				if (isBlank(code)){
218
					Collection superCollection = facade.getCollection().getSuperCollection();
219
					if (superCollection != null){
220
						code = superCollection.getCode();
221
					}
222
				}
223
			}
224
		}
225
		return code;
226
	}
227

  
228 203
// ************************** GETTER / SETTER ******************************************************
229 204

  
230 205
	public boolean isIncludeSeconds() {
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationSetManager.java
370 370

  
371 371
    private FieldUnit findFieldUnit(DerivedUnit du) {
372 372

  
373
        if(du == null || du.getOriginals() == null){
373
        if(du == null || du.getOriginals() == null || du.getOriginals().isEmpty()){
374 374
            return null;
375 375
        }
376 376
        @SuppressWarnings("rawtypes")
377
        Set<SpecimenOrObservationBase> originals = du.getDerivedFrom().getOriginals();
377
        Set<SpecimenOrObservationBase> originals = du.getOriginals();
378 378
        @SuppressWarnings("rawtypes")
379 379
        Optional<SpecimenOrObservationBase> fieldUnit = originals.stream()
380 380
                .filter(original -> original instanceof FieldUnit).findFirst();
381 381
        if (fieldUnit.isPresent()) {
382 382
            return (FieldUnit) fieldUnit.get();
383 383
        } else {
384
            for (@SuppressWarnings("rawtypes")
385
            SpecimenOrObservationBase sob : originals) {
384
            for (@SuppressWarnings("rawtypes") SpecimenOrObservationBase sob : originals) {
386 385
                if (sob instanceof DerivedUnit) {
387 386
                    FieldUnit fu = findFieldUnit((DerivedUnit) sob);
388 387
                    if (fu != null) {

Also available in: Unified diff