void appendConstraint(Constraint constraint, StringBuilder buffer) { ConstraintType type = constraint.getConstraintType(); // Add the escapes since they have been removed when converting the original data to a Java Strinng. They need to // be added back for use in the Constraint declaration. buffer.append(String.format(CONSTRAINT, type.getName(), constraint.getValue().replace("\\", "\\\\"))); } }
constraintModels.stream().collect(Collectors.toMap(ConstraintModel::getId, Function.identity())); if (attribute.getConstraints() != null) { constraintModels.removeIf(a -> attribute.getConstraints().stream().noneMatch(b -> b.getId().equals(a.getId()))); for (Constraint constraint : attribute.getConstraints()) { ConstraintModel constraintModel; if (constraint.getId() != null) { constraintModel = constraintMap.get(constraint.getId()); constraintModel.setConstraintType(constraint.getConstraintType().getName()); constraintModel.setValue(constraint.getValue()); } else { constraintModel = new ConstraintModel(); constraintModel.setConstraintType(constraint.getConstraintType().getName()); constraintModel.setValue(constraint.getValue()); constraintModels.add(constraintModel);
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; } }
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); } } }
sb.append(" "); sb.append("name=\"").append(constraint.getConstraintType().getName()).append("\""); sb.append("value=\"").append(constraint.getValue()).append("\"");