GPXMetadata.java

  1. /*
  2.  * This file is part of Openrouteservice.
  3.  *
  4.  * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
  5.  * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
  6.  * of the License, or (at your option) any later version.
  7.  *
  8.  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  9.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10.  * See the GNU Lesser General Public License for more details.
  11.  *
  12.  * You should have received a copy of the GNU Lesser General Public License along with this library;
  13.  * if not, see <https://www.gnu.org/licenses/>.
  14.  */

  15. package org.heigit.ors.api.responses.routing.gpx;

  16. import com.graphhopper.util.shapes.BBox;
  17. import jakarta.xml.bind.annotation.XmlElement;
  18. import jakarta.xml.bind.annotation.XmlRootElement;
  19. import org.heigit.ors.api.EndpointsProperties;
  20. import org.heigit.ors.api.SystemMessageProperties;
  21. import org.heigit.ors.api.requests.routing.RouteRequest;
  22. import org.heigit.ors.api.responses.common.boundingbox.BoundingBox;
  23. import org.heigit.ors.api.responses.common.boundingbox.BoundingBoxFactory;
  24. import org.heigit.ors.exceptions.StatusCodeException;
  25. import org.heigit.ors.routing.RouteResult;
  26. import org.heigit.ors.util.GeomUtility;

  27. import java.util.Date;

  28. @XmlRootElement(name = "metadata")
  29. public class GPXMetadata {
  30.     @XmlElement(name = "name")
  31.     private String name;
  32.     @XmlElement(name = "desc")
  33.     private String description;
  34.     @XmlElement(name = "author")
  35.     private GPXAuthor author;
  36.     @XmlElement(name = "copyright")
  37.     private GPXCopyright copyright;
  38.     @XmlElement(name = "time")
  39.     private Date timeGenerated;
  40.     @XmlElement(name = "bounds", type = GPXBounds.class)
  41.     private BoundingBox bounds;
  42.     @XmlElement(name = "extensions")
  43.     private GPXMetadataExtensions extensions;

  44.     public GPXMetadata() {
  45.     }

  46.     public GPXMetadata(RouteResult[] routeResults, RouteRequest request, SystemMessageProperties systemMessageProperties, EndpointsProperties endpointsProperties) throws StatusCodeException {
  47.         EndpointsProperties.EndpointRoutingProperties props = endpointsProperties.getRouting();
  48.         this.name = props.getGpxName();
  49.         this.description = props.getGpxDescription();
  50.         this.author = new GPXAuthor(props.getGpxAuthor(), props.getGpxSupportMail(), props.getGpxBaseUrl());
  51.         this.copyright = new GPXCopyright(props.getGpxContentLicence(), endpointsProperties.getRouting().getAttribution());
  52.         this.timeGenerated = new Date();

  53.         BBox[] bboxes = new BBox[routeResults.length];
  54.         for (int i = 0; i < routeResults.length; i++) {
  55.             bboxes[i] = routeResults[i].getSummary().getBBox();
  56.         }

  57.         this.bounds = BoundingBoxFactory.constructBoundingBox(GeomUtility.generateBoundingFromMultiple(bboxes), request);

  58.         this.extensions = new GPXMetadataExtensions(request, systemMessageProperties);
  59.     }

  60.     public String getName() {
  61.         return name;
  62.     }

  63.     public String getDescription() {
  64.         return description;
  65.     }

  66.     public GPXAuthor getAuthor() {
  67.         return author;
  68.     }

  69.     public GPXCopyright getCopyright() {
  70.         return copyright;
  71.     }

  72.     public Date getTimeGenerated() {
  73.         return timeGenerated;
  74.     }

  75.     public BoundingBox getBounds() {
  76.         return bounds;
  77.     }

  78.     public GPXMetadataExtensions getExtensions() {
  79.         return extensions;
  80.     }
  81. }