OLINGO-573: fixing an issue with adding references to collection valued navigation property
This commit is contained in:
parent
fbdf9aadc8
commit
44ff6c95c0
|
@ -194,19 +194,19 @@ public interface ServiceHandler extends Processor {
|
||||||
throws ODataTranslatedException, ODataApplicationException;
|
throws ODataTranslatedException, ODataApplicationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add references (relationships) to Entity.
|
* Add references (relationships) to Entity. This is always on collection valued navigation property
|
||||||
* @param request
|
* @param request
|
||||||
* @param entityETag - entity etag to match before add operation, "*" allows all.
|
* @param entityETag - entity etag to match before add operation, "*" allows all.
|
||||||
* @param idReferences - references to add
|
* @param referenceId - references to add
|
||||||
* @param response - return always should be 204
|
* @param response - return always should be 204
|
||||||
* @throws ODataTranslatedException
|
* @throws ODataTranslatedException
|
||||||
* @throws ODataApplicationException
|
* @throws ODataApplicationException
|
||||||
*/
|
*/
|
||||||
void addReference(DataRequest request, String entityETag, List<URI> idReferences, NoContentResponse response)
|
void addReference(DataRequest request, String entityETag, URI referenceId, NoContentResponse response)
|
||||||
throws ODataTranslatedException, ODataApplicationException;
|
throws ODataTranslatedException, ODataApplicationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update references (relationships) in an Entity
|
* Update references (relationships) in an Entity; This is always against single valued navigation property
|
||||||
* @param request
|
* @param request
|
||||||
* @param entityETag
|
* @param entityETag
|
||||||
* @param referenceId
|
* @param referenceId
|
||||||
|
@ -220,7 +220,8 @@ public interface ServiceHandler extends Processor {
|
||||||
/**
|
/**
|
||||||
* Delete references (relationships) in an Entity
|
* Delete references (relationships) in an Entity
|
||||||
* @param request
|
* @param request
|
||||||
* @param deleteId
|
* @param deleteId; for collection valued navigation this will be non-null value; for single valued
|
||||||
|
* navigation property, this will be null.
|
||||||
* @param entityETag
|
* @param entityETag
|
||||||
* @param response - always should be 204
|
* @param response - always should be 204
|
||||||
* @throws ODataTranslatedException
|
* @throws ODataTranslatedException
|
||||||
|
|
|
@ -389,7 +389,7 @@ public class ProcessorServiceHandler implements ServiceHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addReference(DataRequest request, String entityETag, List<URI> idReferences,
|
public void addReference(DataRequest request, String entityETag, URI referenceId,
|
||||||
NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
|
NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
|
||||||
selectProcessor(ReferenceProcessor.class).createReference(
|
selectProcessor(ReferenceProcessor.class).createReference(
|
||||||
request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
|
request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
|
||||||
|
|
|
@ -80,6 +80,7 @@ import org.apache.olingo.server.core.responses.NoContentResponse;
|
||||||
import org.apache.olingo.server.core.responses.PrimitiveValueResponse;
|
import org.apache.olingo.server.core.responses.PrimitiveValueResponse;
|
||||||
import org.apache.olingo.server.core.responses.PropertyResponse;
|
import org.apache.olingo.server.core.responses.PropertyResponse;
|
||||||
import org.apache.olingo.server.core.responses.StreamResponse;
|
import org.apache.olingo.server.core.responses.StreamResponse;
|
||||||
|
import org.apache.olingo.server.core.uri.parser.UriParserSemanticException;
|
||||||
|
|
||||||
public class DataRequest extends ServiceRequest {
|
public class DataRequest extends ServiceRequest {
|
||||||
protected UriResourceEntitySet uriResourceEntitySet;
|
protected UriResourceEntitySet uriResourceEntitySet;
|
||||||
|
@ -423,6 +424,10 @@ public class DataRequest extends ServiceRequest {
|
||||||
} else if (isDELETE()) {
|
} else if (isDELETE()) {
|
||||||
// if this against the collection, user need to look at $id param for entity ref #11.4.6.2
|
// if this against the collection, user need to look at $id param for entity ref #11.4.6.2
|
||||||
String id = getQueryParameter("$id");
|
String id = getQueryParameter("$id");
|
||||||
|
if (id == null && isCollection()) {
|
||||||
|
throw new UriParserSemanticException("$id not specified for delete of reference",
|
||||||
|
UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND);
|
||||||
|
}
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
handler.deleteReference(DataRequest.this, null, getETag(), new NoContentResponse(
|
handler.deleteReference(DataRequest.this, null, getETag(), new NoContentResponse(
|
||||||
getServiceMetaData(), response));
|
getServiceMetaData(), response));
|
||||||
|
@ -440,7 +445,7 @@ public class DataRequest extends ServiceRequest {
|
||||||
getServiceMetaData(), response));
|
getServiceMetaData(), response));
|
||||||
} else if (isPOST()) {
|
} else if (isPOST()) {
|
||||||
// this needs to be against collection of references
|
// this needs to be against collection of references
|
||||||
handler.addReference(DataRequest.this, getETag(), getPayload(), new NoContentResponse(
|
handler.addReference(DataRequest.this, getETag(), getPayload().get(0), new NoContentResponse(
|
||||||
getServiceMetaData(), response));
|
getServiceMetaData(), response));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -409,7 +408,7 @@ public class ServiceDispatcherTest {
|
||||||
public void validate() throws Exception {
|
public void validate() throws Exception {
|
||||||
ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
|
ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
|
||||||
ArgumentCaptor<String> arg2 = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> arg2 = ArgumentCaptor.forClass(String.class);
|
||||||
ArgumentCaptor<List> arg3 = ArgumentCaptor.forClass(List.class);
|
ArgumentCaptor<URI> arg3 = ArgumentCaptor.forClass(URI.class);
|
||||||
ArgumentCaptor<NoContentResponse> arg4 = ArgumentCaptor
|
ArgumentCaptor<NoContentResponse> arg4 = ArgumentCaptor
|
||||||
.forClass(NoContentResponse.class);
|
.forClass(NoContentResponse.class);
|
||||||
Mockito.verify(handler).addReference(arg1.capture(), arg2.capture(), arg3.capture(),
|
Mockito.verify(handler).addReference(arg1.capture(), arg2.capture(), arg3.capture(),
|
||||||
|
|
|
@ -434,18 +434,16 @@ public class TripPinHandler implements ServiceHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addReference(DataRequest request, String entityETag, List<URI> references,
|
public void addReference(DataRequest request, String entityETag, URI referenceId,
|
||||||
NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
|
NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
|
||||||
|
|
||||||
final EntityDetails details = process(request);
|
final EntityDetails details = process(request);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (URI reference : references) {
|
DataRequest bindingRequest = request.parseLink(referenceId);
|
||||||
DataRequest bindingRequest = request.parseLink(reference);
|
|
||||||
Entity linkEntity = this.dataModel.getEntity(bindingRequest.getEntitySet().getName(),
|
Entity linkEntity = this.dataModel.getEntity(bindingRequest.getEntitySet().getName(),
|
||||||
bindingRequest.getKeyPredicates());
|
bindingRequest.getKeyPredicates());
|
||||||
this.dataModel.addNavigationLink(details.navigationProperty, details.entity, linkEntity);
|
this.dataModel.addNavigationLink(details.navigationProperty, details.entity, linkEntity);
|
||||||
}
|
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
throw new ODataApplicationException(e.getMessage(), 500, Locale.getDefault(), e);
|
throw new ODataApplicationException(e.getMessage(), 500, Locale.getDefault(), e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -344,12 +344,9 @@ public class TripPinServiceTest {
|
||||||
|
|
||||||
//ADD
|
//ADD
|
||||||
String payload = "{\n" +
|
String payload = "{\n" +
|
||||||
" \"@odata.context\": \""+baseURL+"/$metadata#Collection($ref)\",\n" +
|
"\"@odata.id\": \"/People('scottketchum')\"\n" +
|
||||||
" \"value\": [\n" +
|
|
||||||
" { \"@odata.id\": \"People('russellwhyte')\" },\n" +
|
|
||||||
" { \"@odata.id\": \"People('scottketchum')\" } \n" +
|
|
||||||
" ]\n" +
|
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
HttpPost postRequest = new HttpPost(baseURL + "/People('kristakemp')/Friends/$ref");
|
HttpPost postRequest = new HttpPost(baseURL + "/People('kristakemp')/Friends/$ref");
|
||||||
postRequest.setEntity(new StringEntity(payload, ContentType.APPLICATION_JSON));
|
postRequest.setEntity(new StringEntity(payload, ContentType.APPLICATION_JSON));
|
||||||
response = httpSend(postRequest, 204);
|
response = httpSend(postRequest, 204);
|
||||||
|
@ -360,8 +357,7 @@ public class TripPinServiceTest {
|
||||||
|
|
||||||
assertTrue(node.get("value").isArray());
|
assertTrue(node.get("value").isArray());
|
||||||
assertEquals("/People('genevievereeves')", ((ArrayNode)node.get("value")).get(0).get("@odata.id").asText());
|
assertEquals("/People('genevievereeves')", ((ArrayNode)node.get("value")).get(0).get("@odata.id").asText());
|
||||||
assertEquals("/People('russellwhyte')", ((ArrayNode)node.get("value")).get(1).get("@odata.id").asText());
|
assertEquals("/People('scottketchum')", ((ArrayNode)node.get("value")).get(1).get("@odata.id").asText());
|
||||||
assertEquals("/People('scottketchum')", ((ArrayNode)node.get("value")).get(2).get("@odata.id").asText());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue