Search in sources :

Example 1 with UpdateOp

use of org.apache.geode.rest.internal.web.controllers.support.UpdateOp in project geode by apache.

the class AbstractBaseController method updateSingleKey.

ResponseEntity<String> updateSingleKey(final String region, final String key, final String json, final String opValue) {
    final JSONTypes jsonType = validateJsonAndFindType(json);
    final UpdateOp op = UpdateOp.valueOf(opValue.toUpperCase());
    String existingValue = null;
    switch(op) {
        case CAS:
            PdxInstance existingPdxObj = casValue(region, key, json);
            existingValue = convert(existingPdxObj);
            break;
        case REPLACE:
            replaceValue(region, key, convert(json));
            break;
        case PUT:
        default:
            if (JSONTypes.JSON_ARRAY.equals(jsonType)) {
                putValue(region, key, convertJsonArrayIntoPdxCollection(json));
            // putValue(region, key, convertJsonIntoPdxCollection(json));
            } else {
                putValue(region, key, convert(json));
            }
    }
    final HttpHeaders headers = new HttpHeaders();
    headers.setLocation(toUri(region, key));
    return new ResponseEntity<String>(existingValue, headers, (existingValue == null ? HttpStatus.OK : HttpStatus.CONFLICT));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) PdxInstance(org.apache.geode.pdx.PdxInstance) UpdateOp(org.apache.geode.rest.internal.web.controllers.support.UpdateOp) JSONTypes(org.apache.geode.rest.internal.web.controllers.support.JSONTypes)

Aggregations

PdxInstance (org.apache.geode.pdx.PdxInstance)1 JSONTypes (org.apache.geode.rest.internal.web.controllers.support.JSONTypes)1 UpdateOp (org.apache.geode.rest.internal.web.controllers.support.UpdateOp)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1