OLINGO-738: Adding upsertEntity feature for the server-extension framework

This commit is contained in:
Ramesh Reddy 2015-07-23 18:00:50 -05:00
parent 1ebbbc3698
commit cb0f7f2d70
4 changed files with 35 additions and 1 deletions

View File

@ -101,6 +101,21 @@ public interface ServiceHandler extends Processor {
void updateEntity(DataRequest request, Entity entity, boolean merge, String entityETag,
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
* @param request

View File

@ -430,4 +430,11 @@ public class ProcessorServiceHandler implements ServiceHandler {
throw new ODataHandlerException("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);
}
}

View File

@ -317,7 +317,7 @@ public class DataRequest extends ServiceRequest {
getContextURL(odata), false, response, getReturnRepresentation());
handler.createEntity(DataRequest.this, getEntityFromClient(), entityResponse);
} else {
handler.updateEntity(DataRequest.this, getEntityFromClient(), isPATCH(), getETag(),
handler.upsertEntity(DataRequest.this, getEntityFromClient(), isPATCH(), getETag(),
entityResponse);
}
} else if (isPOST()) {

View File

@ -544,4 +544,16 @@ public class TripPinHandler implements ServiceHandler {
public void crossJoin(DataRequest dataRequest, List<String> entitySetNames, ODataResponse response) {
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);
}
}
}