Skip to content

Commit

Permalink
Merge branch 'ibi-group:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanlaar authored May 15, 2023
2 parents 2b8070f + 3e4ea7f commit b629235
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -436,19 +438,43 @@ private <O extends Serializable> 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<String, Object> map1 = mapper.readValue(customRouterConfigString, Map.class);
Map<String, Object> map2 = mapper.readValue(routerConfigString, Map.class);
Map<String, Object> merged = new HashMap<String, Object>(map2);
new HashMap<String, Object>(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 "";
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Updater> 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;
Expand All @@ -31,7 +34,7 @@ public static class Updater implements Serializable {

public String url;

public String defaultAgencyId;
public String feedId;
}

public String requestLogFile;
Expand Down

0 comments on commit b629235

Please sign in to comment.