OLINGO-738: Adding upsertEntity feature for the server-extension framework
This commit is contained in:
parent
1ebbbc3698
commit
cb0f7f2d70
|
@ -101,6 +101,21 @@ public interface ServiceHandler extends Processor {
|
||||||
void updateEntity(DataRequest request, Entity entity, boolean merge, String entityETag,
|
void updateEntity(DataRequest request, Entity entity, boolean merge, String entityETag,
|
||||||
EntityResponse response) throws ODataLibraryException, ODataApplicationException;
|
EntityResponse response) throws ODataLibraryException, ODataApplicationException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update or create the entity object. If based on passed in entity object's key value, if
|
||||||
|
* entity exists update the entity, else create a new entity
|
||||||
|
* @param request
|
||||||
|
* @param entity - Entity to create or update
|
||||||
|
* @param merge - in the case of update, true to do merge operation with current entity,
|
||||||
|
* false the entity needs to be replaced
|
||||||
|
* @param entityETag - previous entity tag if provided by the user. "*" means allow.
|
||||||
|
* @param response
|
||||||
|
* @throws ODataLibraryException
|
||||||
|
* @throws ODataApplicationException
|
||||||
|
*/
|
||||||
|
void upsertEntity(DataRequest request, Entity entity, boolean merge, String entityETag,
|
||||||
|
EntityResponse response) throws ODataLibraryException, ODataApplicationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the Entity
|
* Delete the Entity
|
||||||
* @param request
|
* @param request
|
||||||
|
|
|
@ -430,4 +430,11 @@ public class ProcessorServiceHandler implements ServiceHandler {
|
||||||
throw new ODataHandlerException("not implemented",
|
throw new ODataHandlerException("not implemented",
|
||||||
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void upsertEntity(DataRequest request, Entity entity, boolean merge, String entityETag,
|
||||||
|
EntityResponse response) throws ODataLibraryException, ODataApplicationException {
|
||||||
|
throw new ODataHandlerException("not implemented",
|
||||||
|
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -317,7 +317,7 @@ public class DataRequest extends ServiceRequest {
|
||||||
getContextURL(odata), false, response, getReturnRepresentation());
|
getContextURL(odata), false, response, getReturnRepresentation());
|
||||||
handler.createEntity(DataRequest.this, getEntityFromClient(), entityResponse);
|
handler.createEntity(DataRequest.this, getEntityFromClient(), entityResponse);
|
||||||
} else {
|
} else {
|
||||||
handler.updateEntity(DataRequest.this, getEntityFromClient(), isPATCH(), getETag(),
|
handler.upsertEntity(DataRequest.this, getEntityFromClient(), isPATCH(), getETag(),
|
||||||
entityResponse);
|
entityResponse);
|
||||||
}
|
}
|
||||||
} else if (isPOST()) {
|
} else if (isPOST()) {
|
||||||
|
|
|
@ -544,4 +544,16 @@ public class TripPinHandler implements ServiceHandler {
|
||||||
public void crossJoin(DataRequest dataRequest, List<String> entitySetNames, ODataResponse response) {
|
public void crossJoin(DataRequest dataRequest, List<String> entitySetNames, ODataResponse response) {
|
||||||
response.setStatusCode(200);
|
response.setStatusCode(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void upsertEntity(DataRequest request, Entity entity, boolean merge, String entityETag,
|
||||||
|
EntityResponse response) throws ODataLibraryException, ODataApplicationException {
|
||||||
|
EdmEntitySet edmEntitySet = request.getEntitySet();
|
||||||
|
Entity currentEntity = this.dataModel.getEntity(edmEntitySet.getName(), request.getKeyPredicates());
|
||||||
|
if(currentEntity == null) {
|
||||||
|
createEntity(request, entity, response);
|
||||||
|
} else {
|
||||||
|
updateEntity(request, entity, merge, entityETag, response);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue