Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeType;
import com.marklogic.client.*;
import com.marklogic.client.DatabaseClientFactory.HandleFactoryRegistry;
import com.marklogic.client.MarkLogicBindingException;
import com.marklogic.client.MarkLogicIOException;
import com.marklogic.client.MarkLogicInternalException;
import com.marklogic.client.Transaction;
import com.marklogic.client.document.DocumentWriteSet;
import com.marklogic.client.expression.PlanBuilder;
import com.marklogic.client.expression.PlanBuilder.Plan;
Expand Down Expand Up @@ -422,11 +419,22 @@ private RESTServiceResultIterator submitPlan(PlanBuilderBaseImpl.RequestPlan req
AbstractWriteHandle astHandle = requestPlan.getHandle();
List<ContentParam> contentParams = requestPlan.getContentParams();
final String path = determinePath();
if (contentParams != null && !contentParams.isEmpty()) {
contentParams.add(new ContentParam(new PlanBuilderBaseImpl.PlanParamBase("query"), astHandle, null));
return services.postMultipartForm(requestLogger, path, transaction, params, contentParams);
}
return services.postIteratedResource(requestLogger, path, transaction, params, astHandle);
try {
if (contentParams != null && !contentParams.isEmpty()) {
contentParams.add(new ContentParam(new PlanBuilderBaseImpl.PlanParamBase("query"), astHandle, null));
return services.postMultipartForm(requestLogger, path, transaction, params, contentParams);
}
return services.postIteratedResource(requestLogger, path, transaction, params, astHandle);
} catch (FailedRequestException ex) {
String message = ex.getMessage();
if (message != null && message.contains("RESTAPI-UPDATEFROMQUERY")) {
String betterMessage = "The Optic plan is attempting an update but was sent to the wrong REST API endpoint. " +
"You must invoke `withUpdate(true)` on the instance of com.marklogic.client.row.RowManager that you " +
"are using to submit the plan";
throw new FailedRequestException(betterMessage, ex.getFailedRequest());
}
throw ex;
}
}

private PlanBuilderBaseImpl.RequestPlan checkPlan(Plan plan) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,18 @@ public void basicTest() {
@Test
void wrongEndpoint() {
rowManager.withUpdate(false);
assertThrows(
FailedRequestException ex = assertThrows(
FailedRequestException.class,
() -> rowManager.execute(op.fromDocUris("/optic/test/musician1.json").lockForUpdate()),
"Hoping to update this assertion to verify that the server message tells the user to hit v1/rows/update " +
"instead; right now, it's mentioning using declareUpdate() which isn't applicable to a REST API user."
);

assertTrue(ex.getMessage().contains(
"The Optic plan is attempting an update but was sent to the wrong REST API endpoint. " +
"You must invoke `withUpdate(true)` on the instance of com.marklogic.client.row.RowManager " +
"that you are using to submit the plan."),
"Unexpected message: " + ex.getMessage());
}

@Test
Expand Down