Search in sources :

Example 1 with PatchOperation

use of com.linkedin.data.transform.patch.request.PatchOperation in project rest.li by linkedin.

the class GeneratePatchMethodInterceptor method interpretSetModeAndSet.

private void interpretSetModeAndSet(String propertyName, Object arg, SetMode setMode) {
    PathSpec pathSpec = new PathSpec(_pathSpec.getPathComponents(), propertyName);
    boolean doSet = false;
    switch(setMode) {
        case DISALLOW_NULL:
            if (arg == null)
                throw new NullPointerException("Cannot set field " + pathSpec + " on " + _schema.getFullName() + " to null");
            doSet = true;
            break;
        case IGNORE_NULL:
            if (arg != null)
                doSet = true;
            break;
        case REMOVE_IF_NULL:
            doSet = true;
            break;
        case REMOVE_OPTIONAL_IF_NULL:
            if (_schema.getField(propertyName).getOptional())
                doSet = true;
            else if (arg == null)
                throw new IllegalArgumentException("Cannot remove mandatory field " + pathSpec + " on " + _schema.getFullName());
            break;
    }
    if (doSet) {
        PatchOperation patchOp = arg == null ? PatchOpFactory.REMOVE_FIELD_OP : PatchOpFactory.setFieldOp(coerceSetValue(arg));
        _patchTree.addOperation(pathSpec, patchOp);
    }
}
Also used : PatchOperation(com.linkedin.data.transform.patch.request.PatchOperation) PathSpec(com.linkedin.data.schema.PathSpec)

Aggregations

PathSpec (com.linkedin.data.schema.PathSpec)1 PatchOperation (com.linkedin.data.transform.patch.request.PatchOperation)1