net.sf.aguacate.model.EntityInfo Maven / Gradle / Ivy
package net.sf.aguacate.model;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import net.sf.aguacate.context.ContextProcessor;
import net.sf.aguacate.context.ContextValidator;
import net.sf.aguacate.util.formatter.OutputFormater;
import net.sf.aguacate.validator.ValidatorConverter;
import net.sf.aguacate.validator.impl.InputValidatorImpl;
public class EntityInfo {
private final Map validatorConverters;
private final Map> outputFields;
private final ContextValidator contextValidator;
private final ContextProcessor contextProcessor;
private final OutputFormater outputFormater;
public EntityInfo(ValidatorConverter validatorConverter, String primary,
Map> inputFields, Map> outputFields,
ContextValidator contextValidator, ContextProcessor contextProcessor, OutputFormater outputFormater) {
Map temp = new HashMap<>();
for (Map.Entry> entry : inputFields.entrySet()) {
Map fields = entry.getValue();
temp.put(entry.getKey(), new InputValidatorImpl(validatorConverter, fields.remove(primary), fields));
}
this.validatorConverters = temp;
this.outputFields = outputFields;
this.contextValidator = contextValidator;
this.contextProcessor = contextProcessor;
this.outputFormater = outputFormater;
}
public InputValidatorImpl getValidatorConverter(String method) {
return validatorConverters.get(method);
}
public boolean accepts(String method) {
if (validatorConverters.containsKey(method) && validatorConverters.get(method) != null) {
return true;
} else {
Map data = outputFields.get(method);
return data != null && !data.isEmpty();
}
}
public Map> getOutputFields() {
return outputFields;
}
public ContextValidator getContextValidator() {
return contextValidator;
}
public ContextProcessor getContextProcessor() {
return contextProcessor;
}
public OutputFormater getOutputFormater() {
return outputFormater;
}
public Collection methods() {
Set methods1 = validatorConverters.keySet();
Set methods2 = outputFields.keySet();
if (methods1 == null) {
if (methods2 == null) {
return Collections.emptyList();
} else {
return methods2;
}
} else {
if (methods2 == null) {
return methods1;
} else {
Set set = new TreeSet<>(methods1);
set.addAll(methods2);
return set;
}
}
}
}