@Override public ComplexType getType() { return (ComplexType) field.getType(); }
@Override public Type getType() { return field.getType(); }
@Override public ListType getType() { return (ListType) field.getType(); }
@Override public Serializable normalize(Object value) throws PropertyConversionException { if (isNormalized(value)) { return (Serializable) value; } if (value.getClass() == Date.class) { Calendar cal = Calendar.getInstance(); cal.setTime((Date) value); return cal; } if (value instanceof String) { String string = (String) value; if (string.length() == 0) { return null; } return (Calendar) field.getType().decode(value.toString()); } throw new PropertyConversionException(value.getClass(), Calendar.class); }
/** * 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 */ @SuppressWarnings("rawtypes") private List<ConstraintViolation> validateAnyTypeField(Schema schema, List<PathNode> path, Field field, Object value, boolean validateSubProperties) { if (field.getType().isSimpleType()) { return validateSimpleTypeField(schema, path, field, value); } else if (field.getType().isComplexType()) { List<ConstraintViolation> res = new ArrayList<>(); if (!field.isNillable() && (value == null || (value instanceof Map && ((Map) value).isEmpty()))) { addNotNullViolation(res, schema, path); } if (validateSubProperties) { List<ConstraintViolation> subs = validateComplexTypeField(schema, path, field, value); if (subs != null) { res.addAll(subs); } } return res; } else if (field.getType().isListType()) { // maybe validate the list type here if (validateSubProperties) { return validateListTypeField(schema, path, field, value); } } // unrecognized type : ignored return Collections.emptyList(); }
/** * @since 7.1 */ private List<ConstraintViolation> validateAnyTypeProperty(Schema schema, List<PathNode> path, Property prop, boolean dirtyOnly, boolean validateSubProperties) { Field field = prop.getField(); if (!dirtyOnly || prop.isDirty()) { if (field.getType().isSimpleType()) { return validateSimpleTypeProperty(schema, path, prop, dirtyOnly); } else if (field.getType().isComplexType()) { // ignore for now the case when the complex property is null with a null contraints because it's // currently impossible if (validateSubProperties) { return validateComplexTypeProperty(schema, path, prop, dirtyOnly); } } else if (field.getType().isListType()) { if (validateSubProperties) { return validateListTypeProperty(schema, path, prop, dirtyOnly); } } } // unrecognized type : ignored return Collections.emptyList(); }
public static DocumentPropertyObjectResolverImpl create(DocumentModel doc, String xpath) { Field field = Framework.getService(SchemaManager.class).getField(xpath); if (field != null) { ObjectResolver resolver = field.getType().getObjectResolver(); if (resolver != null) { return new DocumentPropertyObjectResolverImpl(doc, xpath, resolver); } } return null; }
protected boolean compatibleTypes(Type targetType, Type sourceType) { if (!sourceType.getName().equals(targetType.getName())) { return false; } if (sourceType.isComplexType()) { for (Field field : ((ComplexType) sourceType).getFields()) { Field targetField = ((ComplexType) targetType).getField(field.getName()); if (targetField == null || !field.getType().equals(targetField.getType())) { return false; } } } if (sourceType.isListType()) { if (!((ListType) sourceType).getFieldType().equals(((ListType) targetType).getFieldType())) { return false; } if (((ListType) sourceType).getFieldType().isComplexType()) { return compatibleTypes(((ListType) targetType).getFieldType(), ((ListType) sourceType).getFieldType()); } } return true; } }
boolean dirtyOnly) { Field field = prop.getField(); assert field.getType().isComplexType(); List<ConstraintViolation> violations = new ArrayList<>(); boolean allChildrenPhantom = true;
/** * @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; }
/** * 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; }
boolean dirtyOnly) { Field field = prop.getField(); assert field.getType().isListType(); List<ConstraintViolation> violations = new ArrayList<>(); Serializable value = prop.getValue();
fieldPath = path + "/" + fieldPath; Type type = field.getType(); if (type.isSimpleType()) { continue; // not binary text
/** * 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()); }
protected static String getRangeClause(String field, BucketRange bucketRange) { Type type = Framework.getService(SchemaManager.class).getField(field).getType(); Double from = bucketRange.getFrom() != null ? bucketRange.getFrom() : Double.NEGATIVE_INFINITY; Double to = bucketRange.getTo() != null ? bucketRange.getTo() : Double.POSITIVE_INFINITY; if (type instanceof IntegerType) { return field + " BETWEEN " + from.intValue() + " AND " + to.intValue(); } else if (type instanceof LongType) { return field + " BETWEEN " + from.longValue() + " AND " + to.longValue(); } return field + " BETWEEN " + from + " AND " + to; }