Skip to content

Commit 124cf31

Browse files
committed
Allow an API user to explicitly target the OBE
This code predates core looking at the feature flag to decide where to put a dataset when it's not specified, so it assumes that "don't ask for a backend" implies "put it in the OBE". That's not true anymore. This change keeps the existing semantics unchanged, but adds a new way to specify the backend (and reimplements the existing codepath in terms of it).
1 parent 4a1ac4f commit 124cf31

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.socrata.api;
2+
3+
public enum DatasetDestination {
4+
OBE, NBE;
5+
}

src/main/java/com/socrata/api/HttpLowLevel.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,24 @@ public Response postRaw(final URI uri, final MediaType mediaType, final ContentE
490490
/**
491491
* If true adds ?nbe=true flag to all URIs (to enable creating datasets on New Backend)
492492
*
493-
* @param useNbe iff true use New Backend, otherwise use old
493+
* Prefer to use the setDatasetDestination method, as this one has surprising behavior
494+
* when its parameter is false.
495+
*
496+
* @param useNbe if true use New Backend, otherwise use the default
494497
*/
495498
public void setUseNewBackend(boolean useNbe) {
496-
if(useNbe)
497-
additionalParams.put(NBE_FLAG, "true");
498-
else
499-
additionalParams.remove(NBE_FLAG);
499+
if(useNbe) setDatasetDestination(DatasetDestination.NBE);
500+
else setDatasetDestination(null);
501+
}
502+
503+
/**
504+
* Specify (or reset to the default) the backend on which datasets will be created.
505+
*
506+
* @param destination The target backend, or null for the default.
507+
*/
508+
public void setDatasetDestination(DatasetDestination destination) {
509+
if(destination == null) additionalParams.remove(NBE_FLAG);
510+
else additionalParams.put(NBE_FLAG, Boolean.toString(destination == DatasetDestination.NBE));
500511
}
501512

502513
private Object encodeContents(final ContentEncoding contentEncoding,

src/main/java/com/socrata/api/SodaDdl.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.core.JsonParseException;
44
import com.fasterxml.jackson.databind.JsonMappingException;
55
import com.google.common.base.Preconditions;
6+
import com.socrata.api.DatasetDestination;
67
import com.socrata.exceptions.LongRunningQueryException;
78
import com.socrata.exceptions.SodaError;
89
import com.socrata.model.SearchResults;
@@ -135,19 +136,38 @@ public DatasetInfo createDataset(final DatasetInfo dataset) throws SodaError, In
135136
*
136137
* The new dataset will be unpublished.
137138
*
139+
* Prefer to use the createDataset(DatasetInfo, DatasetDestination) method, as this
140+
* one has surprising behavior when useNewBackend is false.
141+
*
138142
* @param dataset dataset to create the new dataset on. The ID should NOT be set.
139-
* @param useNewBackend iff true create dataset on the New Backend
143+
* @param useNewBackend if true create dataset on the New Backend, otherwise use the default.
140144
* @return the created dataset, the ID will be set on this.
141145
* @throws SodaError
142146
* @throws InterruptedException
143147
*/
144148
public DatasetInfo createDataset(final DatasetInfo dataset, final boolean useNewBackend) throws SodaError, InterruptedException
149+
{
150+
return createDataset(dataset, useNewBackend ? DatasetDestination.NBE : null);
151+
}
152+
153+
/**
154+
* Creates an empty dataset, based on the dataset passed in.
155+
*
156+
* The new dataset will be unpublished.
157+
*
158+
* @param dataset dataset to create the new dataset on. The ID should NOT be set.
159+
* @param destination Specify the backend for the new dataset, or null for the default.
160+
* @return the created dataset, the ID will be set on this.
161+
* @throws SodaError
162+
* @throws InterruptedException
163+
*/
164+
public DatasetInfo createDataset(final DatasetInfo dataset, final DatasetDestination destination) throws SodaError, InterruptedException
145165
{
146166
SodaRequest requester = new SodaRequest<DatasetInfo>(null, dataset)
147167
{
148168
public Response issueRequest() throws LongRunningQueryException, SodaError
149169
{
150-
httpLowLevel.setUseNewBackend(useNewBackend);
170+
httpLowLevel.setDatasetDestination(destination);
151171
return httpLowLevel.postRaw(viewUri, HttpLowLevel.JSON_TYPE, ContentEncoding.IDENTITY, payload);
152172
}
153173
};

0 commit comments

Comments
 (0)