2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.ext
.geo
;
11 import java
.awt
.Color
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
17 import org
.apache
.logging
.log4j
.LogManager
;
18 import org
.apache
.logging
.log4j
.Logger
;
19 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
20 import org
.springframework
.stereotype
.Service
;
21 import org
.springframework
.transaction
.annotation
.Transactional
;
23 import de
.micromata
.opengis
.kml
.v_2_2_0
.Kml
;
24 import eu
.etaxonomy
.cdm
.ext
.geo
.kml
.KMLDocumentBuilder
;
25 import eu
.etaxonomy
.cdm
.model
.location
.Point
;
26 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
27 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldUnit
;
28 import eu
.etaxonomy
.cdm
.model
.occurrence
.GatheringEvent
;
29 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
30 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
31 import eu
.etaxonomy
.cdm
.persistence
.dao
.occurrence
.IOccurrenceDao
;
34 * @author a.kohlbecker
38 @Transactional(readOnly
= true)
39 public class EditGeoService
implements IEditGeoService
{
41 @SuppressWarnings("unused")
42 private static final Logger logger
= LogManager
.getLogger();
45 private IOccurrenceDao occurrenceDao
;
48 public OccurrenceServiceRequestParameterDto
getOccurrenceServiceRequestParameters(
49 List
<SpecimenOrObservationBase
> specimensOrObservations
,
50 Map
<SpecimenOrObservationType
, Color
> specimenOrObservationTypeColors
) {
52 List
<Point
> fieldUnitPoints
= new ArrayList
<>();
53 List
<Point
> derivedUnitPoints
= new ArrayList
<>();
55 for (SpecimenOrObservationBase
<?
> specimenOrObservationBase
: specimensOrObservations
) {
56 SpecimenOrObservationBase
<?
> specimensOrObservation
= occurrenceDao
57 .load(specimenOrObservationBase
.getUuid());
59 if (specimensOrObservation
instanceof FieldUnit
) {
60 GatheringEvent gatherEvent
= ((FieldUnit
) specimensOrObservation
).getGatheringEvent();
61 if (gatherEvent
!= null && gatherEvent
.getExactLocation() != null){
62 fieldUnitPoints
.add(gatherEvent
.getExactLocation());
65 if (specimensOrObservation
instanceof DerivedUnit
) {
66 registerDerivedUnitLocations((DerivedUnit
) specimensOrObservation
, derivedUnitPoints
);
70 return EditGeoServiceUtilities
.getOccurrenceServiceRequestParameterString(fieldUnitPoints
,
71 derivedUnitPoints
, specimenOrObservationTypeColors
);
75 public Kml
occurrencesToKML(
76 @SuppressWarnings("rawtypes") List
<SpecimenOrObservationBase
> specimensOrObservations
,
77 Map
<SpecimenOrObservationType
, Color
> specimenOrObservationTypeColors
) {
79 KMLDocumentBuilder builder
= new KMLDocumentBuilder();
81 for (SpecimenOrObservationBase
<?
> specimenOrObservationBase
: specimensOrObservations
) {
82 builder
.addSpecimenOrObservationBase(occurrenceDao
.load(specimenOrObservationBase
.getUuid()));
85 Kml kml
= builder
.build();
91 private void registerDerivedUnitLocations(DerivedUnit derivedUnit
, List
<Point
> derivedUnitPoints
) {
93 @SuppressWarnings("rawtypes")
94 Set
<SpecimenOrObservationBase
> originals
= derivedUnit
.getOriginals();
95 for (SpecimenOrObservationBase
<?
> original
: originals
) {
96 if (original
instanceof FieldUnit
) {
97 if (((FieldUnit
) original
).getGatheringEvent() != null) {
98 Point point
= ((FieldUnit
) original
).getGatheringEvent().getExactLocation();
100 // points with no longitude or latitude should not exist
101 // see #4173 ([Rule] Longitude and Latitude in Point must not be null)
102 if (point
.getLatitude() == null || point
.getLongitude() == null){
105 // FIXME: remove next statement after
106 // DerivedUnitFacade or ABCD import is fixed
108 if(point
.getLatitude() == 0.0 || point
.getLongitude() == 0.0) {
111 derivedUnitPoints
.add(point
);
115 registerDerivedUnitLocations((DerivedUnit
) original
, derivedUnitPoints
);