public final Collection<Property> getNonPhantomChildren() { ComplexType type = getType(); if (children.size() < type.getFieldsCount()) { // populate with // unloaded props only // if needed for (Field field : type.getFields()) { getNonPhantomChild(field); // force loading non phantom props } } return Collections.unmodifiableCollection(children.values()); }
/** * 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; }
public void visitChildren(PropertyVisitor visitor, Object arg) throws PropertyException { boolean includePhantoms = visitor.acceptPhantoms(); if (includePhantoms) { for (Property property : getChildren()) { property.accept(visitor, arg); } } else { for (Field field : getType().getFields()) { Property property = getNonPhantomChild(field); if (property == null) { continue; // a phantom property not yet initialized } else if (property.isPhantom()) { continue; // a phantom property } else { property.accept(visitor, arg); } } } }
@Override public Collection<Property> getChildren() { ComplexType type = getType(); if (children.size() < type.getFieldsCount()) { // populate with // phantoms if needed for (Field field : type.getFields()) { getChild(field); // force loading all props including // phantoms } } return Collections.unmodifiableCollection(children.values()); }
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; } }
protected void findBlobPaths(ComplexType complexType, String path, Schema schema, List<String> paths) { for (Field field : complexType.getFields()) { String fieldPath = field.getName().getPrefixedName(); if (path == null) {
protected void buildComplexFields(JsonGenerator jg, Field field) throws IOException { ComplexType cplXType = (ComplexType) field.getType(); jg.writeObjectFieldStart("fields"); for (Field subField : cplXType.getFields()) { writeField(jg, subField); } jg.writeEndObject(); }
protected Object getValueComplex(T state, ComplexType complexType) throws PropertyException { if (TypeConstants.isContentType(complexType)) { return getValueBlob(state); } Map<String, Object> map = new HashMap<>(); for (Field field : complexType.getFields()) { String name = field.getName().getPrefixedName(); Object value = getValueField(state, field); map.put(name, value); } return map; }
protected void setValueComplex(T state, Field field, String xpath, Object value) throws PropertyException { ComplexType complexType = (ComplexType) field.getType(); if (TypeConstants.isContentType(complexType)) { if (value != null && !(value instanceof Blob)) { throw new PropertyException( "Expected Blob value for: " + xpath + ", got " + value.getClass().getName() + " instead"); } setValueBlob(state, (Blob) value, xpath); return; } if (value != null && !(value instanceof Map)) { throw new PropertyException( "Expected Map value for: " + xpath + ", got " + value.getClass().getName() + " instead"); } @SuppressWarnings("unchecked") Map<String, Object> map = value == null ? Collections.emptyMap() : (Map<String, Object>) value; Set<String> keys = new HashSet<>(map.keySet()); for (Field f : complexType.getFields()) { String name = f.getName().getPrefixedName(); keys.remove(name); value = map.get(name); setValueField(state, f, xpath + '/' + name, value); } if (!keys.isEmpty()) { throw new PropertyException("Unknown key: " + keys.iterator().next() + " for " + xpath); } }
protected void walkComplexType(ComplexType complexType, String path, String addPrefix) { for (Field field : complexType.getFields()) { String name = field.getName().getPrefixedName(); String fieldPath = path == null ? name : path + '/' + name; walkType(field.getType(), fieldPath, addPrefix); } }
for (Field field : complexType.getFields()) { String propertyName = field.getName().getPrefixedName(); String path = prefix + propertyName;
@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; }
jg.writeObjectFieldStart("fields"); ComplexType cplXType = (ComplexType) lt.getField().getType(); for (Field subField : cplXType.getFields()) { writeField(jg, subField); ComplexType cplXType = (ComplexType) field.getType(); jg.writeObjectFieldStart("fields"); for (Field subField : cplXType.getFields()) { writeField(jg, subField);
for (Field field : complexType.getFields()) { Type fieldType = field.getType(); if (fieldType.isComplexType()) {
/** * 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); } } }
private static void avoidBlobUpdate(Property propToClean, DocumentModel docRef) { if (propToClean instanceof BlobProperty) { // if the blob used to exist if (propToClean.getValue() == null) { try { Serializable value = docRef.getPropertyValue(propToClean.getXPath()); propToClean.setValue(value); } catch (PropertyNotFoundException e) { // As the blob property doesn't exist in the document in the first place, ignore the operation } } } else if (propToClean instanceof ComplexProperty) { ComplexProperty complexPropToClean = (ComplexProperty) propToClean; for (Field field : complexPropToClean.getType().getFields()) { Property childPropToClean = complexPropToClean.get(field.getName().getLocalName()); avoidBlobUpdate(childPropToClean, docRef); } } else if (propToClean instanceof ListProperty) { ListProperty listPropToClean = (ListProperty) propToClean; for (int i = 0; i < listPropToClean.size(); i++) { Property elPropToClean = listPropToClean.get(i); avoidBlobUpdate(elPropToClean, docRef); } } }
for (Field parentField : superType.getFields()) { ct.addField(parentField.getName().getLocalName(), parentField.getType(), (String) parentField.getDefaultValue(), 0, null);