jmms.protocols.scim.v2.model.Scim2Patch Maven / Gradle / Ivy
/*
* Copyright 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package jmms.protocols.scim.v2.model;
import leap.lang.Valued;
import leap.lang.json.JsonName;
import java.util.ArrayList;
import java.util.List;
public class Scim2Patch {
protected String[] schemas;
@JsonName("Operations")
protected List operations;
public String[] getSchemas() {
return schemas;
}
public void setSchemas(String[] schemas) {
this.schemas = schemas;
}
public void addOperation(Operation operation) {
if(null == operations) {
operations = new ArrayList<>();
}
operations.add(operation);
}
public List getOperations() {
return operations;
}
public void setOperations(List operations) {
this.operations = operations;
}
public Scim2Patch add(String path, Object value) {
addOperation(new Operation(Op.ADD, path, value));
return this;
}
public Scim2Patch remove(String path) {
addOperation(new Operation(Op.REMOVE, path));
return this;
}
public Scim2Patch replace(String path, Object value) {
addOperation(new Operation(Op.REPLACE, path, value));
return this;
}
public enum Op implements Valued {
ADD("add"),
REMOVE("remove"),
REPLACE("replace");
private final String value;
Op(String value) {
this.value = value;
}
@Override
public String getValue() {
return value;
}
}
public static final class Operation {
public Op op;
public String path;
public Object value;
public Operation() {
}
public Operation(Op op, String path) {
this.op = op;
this.path = path;
}
public Operation(Op op, String path, Object value) {
this.op = op;
this.path = path;
this.value = value;
}
}
}