accounting-lib/src/main/java/org/gcube/accounting/datamodel/validations/validators/MatcherReplace.java

47 lines
1.1 KiB
Java

package org.gcube.accounting.datamodel.validations.validators;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.DSMapper;
import com.fasterxml.jackson.annotation.JsonSetter;
public class MatcherReplace {
protected MultiMatcher multiMatcher;
protected Replacer replacer;
public MatcherReplace() {}
public MultiMatcher getMultiMatcher() {
return multiMatcher;
}
@JsonSetter(value="match")
public void setMultiMatcher(MultiMatcher multiMatcher) {
this.multiMatcher = multiMatcher;
}
public Replacer getReplacer() {
return replacer;
}
@JsonSetter(value="replace")
public void setReplacer(Replacer replacer) {
this.replacer = replacer;
}
public boolean check(String serviceClass, String serviceName, String calledMethod) throws InvalidValueException {
return multiMatcher.match(serviceClass, serviceName, calledMethod);
}
@Override
public String toString() {
try {
return DSMapper.getObjectMapper().writeValueAsString(this);
} catch(Exception e) {
return "MatcherReplace [multiMatcher=" + multiMatcher + ", replacer=" + replacer + "]";
}
}
}