@Override public boolean isComplex() { return getType().isComplexType(); }
/** * 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; }
list = (List<Object>) value; if (ftype.isComplexType()) { List<Object> clonedList = new ArrayList<>(list.size()); for (Object o : list) {
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 */ @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(); }
} else if (type.isListType()) { Type fieldType = ((ListType) type).getFieldType(); if (fieldType.isComplexType()) { findBlobPaths((ComplexType) fieldType, fieldPath + "/*", schema, paths); } else {
} else if (type.isComplexType()) { return new MapProperty(parent, field, flags); } else if (type.isListType()) {
protected Field resolveSubField(ListType listType, String subName, boolean fallbackOnSubElement) { Type itemType = listType.getFieldType(); if (itemType.isComplexType() && subName != null) { ComplexType complexType = (ComplexType) itemType; Field subField = complexType.getField(subName); return subField; } if (fallbackOnSubElement) { return listType.getField(); } return null; }
@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; }
/** * Check if the given field type store a list of values and if the given value is compatible with the given type. We * assume the Type store a list of scalar values, not complex types. */ protected void checkFieldType(Type type, Object value) throws OperationException { if (!type.isListType()) { throw new OperationException("Only multivalued types can be set using this operation"); } ListType listType = (ListType) type; Type itemType = listType.getFieldType(); if (itemType.isComplexType()) { throw new UnsupportedOperationException("Manage only lists of scalar items"); } try { if (itemType.convert(value) == null) { String exceptionReason = String.format("Given type \"%s\" value is not a %s type", value, itemType.getName()); throw new UnsupportedOperationException(exceptionReason); } } catch (TypeException | ClassCastException e) { String exceptionReason = String.format("Given type \"%s\" value is not a %s type", value, itemType.getName()); throw new OperationException(exceptionReason, e); } } }
/** * Checks if a field is a primitive type or array. */ private static boolean isScalarField(Field field) { Type fieldType = field.getType(); if (fieldType.isComplexType()) { // complex type return false; } if (!fieldType.isListType()) { // primitive type return true; } // array or complex list? return ((ListType) fieldType).getFieldType().isSimpleType(); }
protected Field getField(Field parent, String subFieldName, boolean finalCall) { if (parent != null) { Type type = parent.getType(); if (type.isListType()) { ListType listType = (ListType) type; // remove indexes in case of multiple values if ("*".equals(subFieldName)) { if (!finalCall) { return parent; } else { return resolveSubField(listType, null, true); } } try { Integer.valueOf(subFieldName); if (!finalCall) { return parent; } else { return resolveSubField(listType, null, true); } } catch (NumberFormatException e) { return resolveSubField(listType, subFieldName, false); } } else if (type.isComplexType()) { return ((ComplexType) type).getField(subFieldName); } } return null; }
@OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) throws OperationException, IOException { Property complexProperty = doc.getProperty(xpath); ListType listType = (ListType) complexProperty.getField().getType(); if (!listType.getFieldType().isComplexType()) { throw new OperationException("Property type " + listType.getFieldType().getClass().getName() + " is not supported by this operation"); } List<Object> newVals = ComplexTypeJSONDecoder.decodeList(listType, complexJsonProperties); for (Object newVal : newVals) { complexProperty.addValue(newVal); } doc = session.saveDocument(doc); if (save) { session.save(); } return doc; }
} else if (type.isComplexType()) {
} else if (type.isComplexType()) { ComplexType ctype = (ComplexType) type; if (TypeConstants.isContentType(ctype)) {
protected void walkType(Type type, String path, String addPrefix) { if (type.isSimpleType()) { walkSimpleType(type, path, addPrefix); } else if (type.isListType()) { String listPath = path + "/*"; Type ftype = ((ListType) type).getField().getType(); if (ftype.isComplexType()) { // complex list walkComplexType((ComplexType) ftype, listPath, addPrefix); } else { // array walkSimpleType(ftype, listPath, addPrefix); } } else { // complex type ComplexType ctype = (ComplexType) type; walkComplexType(ctype, path, addPrefix); } }
/** * Given a document property, updates its value with the given blob. The property can be a blob list or a blob. If a * blob list the blob is appended to the list, if a blob then it will be set as the property value. Both blob list * formats are supported: the file list (blob holder list) and simple blob list. */ public static void addBlob(Property p, Blob blob) throws PropertyException { if (p.isList()) { // detect if a list of simple blobs or a list of files (blob // holder) Type ft = ((ListProperty) p).getType().getFieldType(); if (ft.isComplexType() && ((ComplexType) ft).getFieldsCount() == 1) { p.addValue(createBlobHolderMap(blob)); } else { p.addValue(blob); } } else { p.setValue(blob); } }
ListType listType = (ListType) complexProperty.getField().getType(); if (!listType.getFieldType().isComplexType() && !listType.isListType()) { throw new OperationException("Property type is not supported by this operation"); ListType listType = (ListType) complexProperty.getField().getType(); if (!listType.getFieldType().isComplexType() && !listType.isListType()) { throw new OperationException("Property type is not supported by this operation");