public static ConstraintPlugins getInstance() { if (instance == null) { synchronized(LOCK) { if (instance == null) { instance = new ConstraintPlugins(); } } } return instance; }
@Override public Set<String> getConstraintTypes() { return ConstraintPlugins.getInstance().getConstraintMap().keySet(); }
private static void validateConstraints(boolean isRequestContext, Constraint[] constraints, String name, String value, StringBuilder errors) { for (Constraint constraint : constraints) { constraintPlugins.validateConstraint(isRequestContext, constraint.constraintType(), name, value, constraint.constraintValue(), errors); } }
public Attribute convert(AttributeModel model) { Attribute attribute = new Attribute(); attribute.setName(model.getName()); attribute.setDisplayName(model.getDisplayName()); attribute.setDescription(model.getDescription()); attribute.setAliases(model.getAliases()); attribute.setId(model.getId()); attribute.setCatalogId(model.getCatalogId()); attribute.setIndexed(model.isIndexed()); attribute.setSortable(model.isSortable()); attribute.setRequestContext(model.isRequestContext()); attribute.setRequired(model.isRequired()); attribute.setDataType(model.getDataType()); Set<ConstraintModel> constraintModels = model.getConstraints(); Set<Constraint> constraints = new HashSet<>(); if (constraintModels != null) { for (ConstraintModel constraintModel : constraintModels) { Constraint constraint = new Constraint(); constraint.setId(constraintModel.getId()); constraint.setConstraintType(ConstraintPlugins.getInstance().findByName(constraintModel.getConstraintType())); constraint.setValue(constraintModel.getValue()); constraints.add(constraint); } } attribute.setConstraints(constraints); return attribute; } }
@Override public ConstraintType deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonNode node = jp.getCodec().readTree(jp); String name = node.get("name").textValue(); ConstraintType type = plugins.findByName(name); if (type == null) { throw new NameNotFoundException("Unable to locate plugin for constraint type " + name); } return type; } }
private static void validateConstraints(boolean isRequestContext, Collection<Constraint> constraints, String name, String value, StringBuilder errors) { for (Constraint constraint : constraints) { constraintPlugins.validateConstraint(isRequestContext, constraint.getConstraintType().getName(), name, value, constraint.getValue(), errors); } } }
} else if (annotation instanceof Constraint) { Constraint constraint = (Constraint) annotation; constraintPlugins.validateConstraint(false, constraint.constraintType(), name, objects[0].toString(), constraint.constraintValue(), errors);