/** * Validates sub fields for given complex field. * * @since 7.1 */ @SuppressWarnings("unchecked") private List<ConstraintViolation> validateComplexTypeField(Schema schema, List<PathNode> path, Field field, Object value) { assert field.getType().isComplexType(); List<ConstraintViolation> violations = new ArrayList<>(); ComplexType complexType = (ComplexType) field.getType(); // this code does not support other type than Map as value if (!(value instanceof Map)) { return violations; } Map<String, Object> map = (Map<String, Object>) value; for (Field child : complexType.getFields()) { Object item = map.get(child.getName().getLocalName()); List<PathNode> subPath = new ArrayList<>(path); subPath.add(new PathNode(child)); violations.addAll(validateAnyTypeField(schema, subPath, child, item, true)); } return violations; }
/** * @since 7.1 */ private List<ConstraintViolation> validateSimpleTypeProperty(Schema schema, List<PathNode> path, Property prop, boolean dirtyOnly) { Field field = prop.getField(); assert field.getType().isSimpleType() || prop.isScalar(); List<ConstraintViolation> violations = new ArrayList<>(); Serializable value = prop.getValue(); Object defaultValue = field.getDefaultValue(); // check nullity constraint only if field doesn't have a default value (phantom case) if (prop.isPhantom() && defaultValue == null || value == null) { if (!field.isNillable()) { addNotNullViolation(violations, schema, path); } } else { violations.addAll(validateSimpleTypeField(schema, path, field, value)); } return violations; }
assert field.getType().isListType(); List<ConstraintViolation> violations = new ArrayList<>(); Collection<?> castedValue = null; if (!field.isNillable() && value == null) { addNotNullViolation(violations, schema, path); if (!field.isNillable() && castedValue.isEmpty()) { addNotNullViolation(violations, schema, path); ListType listType = (ListType) field.getType(); Field listField = listType.getField(); int index = 0;
@Override public ComplexType getType() { return (ComplexType) field.getType(); }
@Override public Map<String, Object> newInstance() { if (TypeConstants.isContentType(this)) { // NXP-912: should return null for a blob. Since there is no // pluggable adapter mechanism on types, and since document model // properties consider that every complex property named "content" // should be dealt with a BlobProperty, this is hardcoded here. return null; } Map<String, Object> map = new HashMap<String, Object>(); for (Field field : fields.values()) { Object value; Type type = field.getType(); if (type.isComplexType()) { value = type.newInstance(); } else if (type.isListType()) { value = new ArrayList<Object>(); } else { value = field.getDefaultValue(); } map.put(field.getName().getLocalName(), value); } return map; }
if (field != null && field.getType().isListType()) { Field itemField = ((ListType) field.getType()).getField(); if (xpathToken.matches("\\d+")) { int index = Integer.parseInt(xpathToken); path.add(new PathNode(field, index)); } else if (xpathToken.equals(itemField.getName().getLocalName())) { Schema schema = field.getDeclaringType().getSchema(); // NOSONAR return new DocumentValidationReport(validateAnyTypeField(schema, path, field, value, validateSubProperties));
/** * Create a schema from a ComplexType * * @since 5.7 * @param complexType * @param name * @param ns */ public SchemaImpl(ComplexType complexType, String name, Namespace ns, boolean isVersionWritabe) { super(null, SchemaNames.SCHEMAS, name, ns); this.isVersionWritabe = isVersionWritabe; if (complexType != null) { for (Field field : complexType.getFields()) { QName fieldname = QName.valueOf(field.getName().getLocalName(), ns.prefix); Type type = field.getType(); String defaultValue = type.encode(field.getDefaultValue()); Set<Constraint> constraint = field.getConstraints(); FieldImpl newField = new FieldImpl(fieldname, this, type, defaultValue, 0, constraint); newField.setConstant(field.isConstant()); addField(newField); } } }
Field schemaIdField = schemaFieldMap.get(getIdField()); String idFieldName = schemaIdField.getName().getPrefixedName(); idColumn = column; String prefixedName = schemaFieldMap.get(column.getKey()).getName().getPrefixedName(); if (prefixedField != null && prefixedField.getDefaultValue() != null) { fieldMap.put(prefixedName, prefixedField.getDefaultValue()); } else { i.remove(); List<Serializable> values = new ArrayList<>(columnList.size()); for (Column column : columnList) { String prefixField = schemaFieldMap.get(column.getKey()).getName().getPrefixedName(); Object value = fieldMap.get(prefixField); Serializable v; String prefixField = schemaFieldMap.get(column.getKey()).getName().getPrefixedName(); Object value = fieldMap.get(prefixField); setFieldValue(ps, index, column, value);
String typeValue; Set<Constraint> itemConstraints = null; if (field.getType().isListType()) { ListType lt = (ListType) field.getType(); Type type = lt.getFieldType(); itemConstraints = type.getConstraints(); Type type = field.getType(); while (!(type instanceof PrimitiveType)) { type = type.getSuperType(); jg.writeObjectFieldStart(field.getName().getLocalName()); jg.writeStringField("type", typeValue); Writer<Constraint> constraintWriter = registry.getWriter(ctx, Constraint.class, APPLICATION_JSON_TYPE); OutputStream out = new OutputStreamWithJsonWriter(jg); jg.writeArrayFieldStart("constraints"); for (Constraint c : field.getConstraints()) { constraintWriter.write(c, Constraint.class, Constraint.class, APPLICATION_JSON_TYPE, out); jg.writeStringField(field.getName().getLocalName(), typeValue);
@Override public Schema createSchema(ComplexType input) { Schema schema = Schema.createRecord(getName(input), null, input.getNamespace().prefix, false); List<Field> fields = new ArrayList<>(input.getFields().size()); for (org.nuxeo.ecm.core.schema.types.Field f : context.sort(input.getFields())) { String fieldName = context.getService().encodeName(f.getName().getLocalName()); Schema fieldSchema = context.createSchema(f.getType()); if (f.isNillable()) { fieldSchema = nullable(fieldSchema); } fields.add(new Field(fieldName, fieldSchema, null, (Object) null)); } schema.setFields(fields); return schema; }
protected void writeBuckets(String fieldName, List<Bucket> buckets, Field field, JsonGenerator jg) throws IOException, JsonGenerationException { Schema schema = field.getDeclaringType().getSchema(); DocumentPartImpl part = new DocumentPartImpl(schema); prop = PropertyFactory.createProperty(part, t.getField(), Property.NONE); log.debug(String.format("Writing %s for field %s resolved to %s", fieldName, field.getName().toString(), prop.getName())); prop.setValue(bucket.getKey());
/** * This method should be the only one to create {@link ConstraintViolation}. * * @since 7.1 */ private List<ConstraintViolation> validateSimpleTypeField(Schema schema, List<PathNode> path, Field field, Object value) { Type type = field.getType(); assert type.isSimpleType() || type.isListType(); // list type to manage ArrayProperty List<ConstraintViolation> violations = new ArrayList<>(); Set<Constraint> constraints; if (type.isListType()) { // ArrayProperty constraints = ((ListType) type).getFieldType().getConstraints(); } else { constraints = field.getConstraints(); } for (Constraint constraint : constraints) { if (!constraint.validate(value)) { ConstraintViolation violation = new ConstraintViolation(schema, path, constraint, value); violations.add(violation); } } return violations; }
Type type = field.getType(); if (type instanceof SimpleTypeImpl) { Object defaultValue = field.getDefaultValue(); String typeName = type.getName(); if (attribute == null) {
/** * Gets the column type from a Nuxeo Schema field, including its constrained length if any. */ public static ColumnType fromField(Field field) { return fromFieldType(field.getType(), field.getMaxLength()); }
@Override protected Serializable getDefaultValue() { Serializable value = (Serializable) field.getDefaultValue(); if (value == null) { value = new ArrayList<Serializable>(); } return value; }
@Override public DocumentValidationReport validate(Field field, Object value, boolean validateSubProperties) { Schema schema = field.getDeclaringType().getSchema(); return new DocumentValidationReport(validate(schema, field, value, validateSubProperties)); }
LengthConstraint lc = ConstraintUtils.getConstraint(field.getConstraints(), LengthConstraint.class); if (lc != null && lc.getMax() != null) { field.setMaxLength(lc.getMax().intValue());
@Override public Type getType() { return field.getType(); }
Field field = entry.getValue(); if (field != null) { String fieldName = field.getName().getPrefixedName(); Object value = newDocMap.get(fieldName); Type type = field.getType(); if (value instanceof String) { String v = (String) value; Object defaultValue = field.getDefaultValue(); if (defaultValue != null) { newDocMap.put(fieldName, defaultValue);