diff --git a/src/main/java/com/conveyal/datatools/manager/models/Deployment.java b/src/main/java/com/conveyal/datatools/manager/models/Deployment.java index 39b0d668e..5b783122a 100644 --- a/src/main/java/com/conveyal/datatools/manager/models/Deployment.java +++ b/src/main/java/com/conveyal/datatools/manager/models/Deployment.java @@ -4,7 +4,6 @@ import com.conveyal.datatools.common.utils.aws.CheckedAWSException; import com.conveyal.datatools.common.utils.aws.EC2Utils; import com.conveyal.datatools.manager.DataManager; -import static com.conveyal.datatools.manager.DataManager.getConfigPropertyAsText; import com.conveyal.datatools.manager.jobs.DeployJob; import com.conveyal.datatools.manager.persistence.Persistence; import com.conveyal.datatools.manager.utils.StringUtils; @@ -42,11 +41,14 @@ import java.util.Collection; import java.util.Collections; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import static com.conveyal.datatools.manager.DataManager.getConfigPropertyAsText; import static com.mongodb.client.model.Filters.and; import static com.mongodb.client.model.Filters.eq; @@ -436,19 +438,43 @@ private String writeToString(O object) { } /** Generate router config for deployment as string. */ - public byte[] generateRouterConfig() { + public byte[] generateRouterConfig() throws IOException { Project project = this.parentProject(); - return customRouterConfig != null - ? customRouterConfig.getBytes(StandardCharsets.UTF_8) - : project.routerConfig != null + + byte[] customRouterConfigString = customRouterConfig != null + ? customRouterConfig.getBytes(StandardCharsets.UTF_8) + : null; + + byte[] routerConfigString = project.routerConfig != null ? writeToBytes(project.routerConfig) : null; + + // If both router configs are present, merge the JSON before returning + // Merger code from: https://stackoverflow.com/questions/35747813/how-to-merge-two-json-strings-into-one-in-java + if (customRouterConfigString != null && routerConfigString != null) { + ObjectMapper mapper = new ObjectMapper(); + Map map1 = mapper.readValue(customRouterConfigString, Map.class); + Map map2 = mapper.readValue(routerConfigString, Map.class); + Map merged = new HashMap(map2); + new HashMap(map2).putAll(map1); + return mapper.writeValueAsString(merged).getBytes(); + } + + return customRouterConfigString != null + ? customRouterConfigString + : routerConfigString != null + ? routerConfigString + : null; } /** Generate router config for deployment as byte array (for writing to file output stream). */ public String generateRouterConfigAsString() { - if (customRouterConfig != null) return customRouterConfig; - return writeToString(this.parentProject().routerConfig); + try { + return new String(generateRouterConfig(), StandardCharsets.UTF_8); + } catch (IOException e) { + LOG.error("Failed to generate router config: ", e); + return ""; + } } /** diff --git a/src/main/java/com/conveyal/datatools/manager/models/OtpRouterConfig.java b/src/main/java/com/conveyal/datatools/manager/models/OtpRouterConfig.java index 1a5b342a5..09771fb76 100644 --- a/src/main/java/com/conveyal/datatools/manager/models/OtpRouterConfig.java +++ b/src/main/java/com/conveyal/datatools/manager/models/OtpRouterConfig.java @@ -11,16 +11,19 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class OtpRouterConfig implements Serializable { private static final long serialVersionUID = 1L; - public Integer numItineraries; - - public Double walkSpeed; + public Double driveDistanceReluctance; public Double stairsReluctance; - public Double carDropoffTime; - public Collection updaters; + public ItineraryFilter itineraryFilters; + + public static class ItineraryFilter implements Serializable { + private static final long serialVersionUID = 1L; + public String nonTransitGeneralizedCostLimit; + } + public static class Updater implements Serializable { private static final long serialVersionUID = 1L; public String type; @@ -31,7 +34,7 @@ public static class Updater implements Serializable { public String url; - public String defaultAgencyId; + public String feedId; } public String requestLogFile;