@Override public String getName() { return schema.getName(); }
String first = slash == -1 ? path : path.substring(0, slash); for (Schema schema : schemaManager.getSchemas()) { if (!schema.getNamespace().hasPrefix()) { if (schema.getField(first) != null) { path = schema.getName() + ":" + path; break;
public static DataModel cloneDataModel(Schema schema, DataModel data) { DataModel dm = new DataModelImpl(schema.getName()); for (Field field : schema.getFields()) { String key = field.getName().getLocalName(); Object value; try { value = data.getData(key); } catch (PropertyException e1) { continue; } if (value == null) { continue; } Object clone = cloneField(field, key, value); dm.setData(key, clone); } return dm; }
protected void writeSchema(JsonGenerator jg, Schema schema) throws IOException { jg.writeObjectFieldStart(schema.getName()); jg.writeStringField("@prefix", schema.getNamespace().prefix); for (Field field : schema.getFields()) { writeField(jg, field); } jg.writeEndObject(); }
if (path == null) { if (!schema.getNamespace().hasPrefix()) { fieldPath = schema.getName() + ":" + fieldPath;
@SuppressWarnings("unchecked") protected static void loadSchema(ExportedDocument xdoc, Schema schema, DocumentModel doc, Element schemaElement) throws ClientException { String schemaName = schemaElement.attributeValue(ExportConstants.NAME_ATTR); Map<String, Object> data = new HashMap<String, Object>(); Iterator<Element> it = schemaElement.elementIterator(); while (it.hasNext()) { Element element = it.next(); String name = element.getName(); Field field = schema.getField(name); if (field == null) { log.info("Property " + name + " doesn't exist anymore in " + schemaName + " schema"); } else { Object value = getElementData(xdoc, element, field.getType()); data.put(name, value); } } doc.setProperties(schemaName, data); }
private void writeSchemaProperties(JsonGenerator jg, DocumentModel doc, String schemaName) throws IOException { Writer<Property> propertyWriter = registry.getWriter(ctx, Property.class, APPLICATION_JSON_TYPE); // provides the current document to the property marshaller try (Closeable resource = ctx.wrap().with(ENTITY_TYPE, doc).open()) { Schema schema = schemaManager.getSchema(schemaName); String prefix = schema.getNamespace().prefix; if (prefix == null || prefix.length() == 0) { prefix = schemaName; } prefix = prefix + ":"; for (Field field : schema.getFields()) { String prefixedName = prefix + field.getName().getLocalName(); jg.writeFieldName(prefixedName); Property property = doc.getProperty(prefixedName); OutputStream out = new OutputStreamWithJsonWriter(jg); propertyWriter.write(property, Property.class, Property.class, APPLICATION_JSON_TYPE, out); } } }
for (Field field : schema.getFields()) { QName fieldName = field.getName(); String key = fieldName.getLocalName();
@Override public DocumentValidationReport validate(DocumentModel document, boolean dirtyOnly) { List<ConstraintViolation> violations = new ArrayList<>(); DocumentType docType = document.getDocumentType(); if (dirtyOnly) { for (DataModel dataModel : document.getDataModels().values()) { Schema schemaDef = getSchemaManager().getSchema(dataModel.getSchema()); for (String fieldName : dataModel.getDirtyFields()) { Field field = schemaDef.getField(fieldName); Property property = document.getProperty(field.getName().getPrefixedName()); List<PathNode> path = singletonList(new PathNode(property.getField())); violations.addAll(validateAnyTypeProperty(property.getSchema(), path, property, true, true)); } } } else { for (Schema schema : docType.getSchemas()) { for (Field field : schema.getFields()) { Property property = document.getProperty(field.getName().getPrefixedName()); List<PathNode> path = singletonList(new PathNode(property.getField())); violations.addAll(validateAnyTypeProperty(property.getSchema(), path, property, false, true)); } } } return new DocumentValidationReport(violations); }
buf.append(labelFieldName.substring(i + LANG_TOKEN.length())); String result = buf.toString(); if (schema.getField(result) != null) { return result; } else { if (schema.getField(result) != null) { log.warn(String.format("Unable to find field %s in directory schema %s. Trying to fallback on default one.", labelFieldName, schema.getName())); if (schema.getField(result) != null) { if (schema.getField(result) != null) { if (schema.getField(labelFieldName) != null) { throw new IllegalArgumentException(String.format("Unable to find field %s in directory schema %s", labelFieldName, schema.getName())); if (schema.getField(labelFieldName) != null) { return labelFieldName; } else { throw new IllegalArgumentException(String.format("Unable to find field %s in directory schema %s", labelFieldName, schema.getName()));
if (!StringUtils.isBlank(schema.getNamespace().prefix)) { field = schema.getField(first); if (field != null) { break;
protected Object getDataModelField(DocumentRef docRef, String schema, String field) { Document doc = resolveReference(docRef); if (doc != null) { checkPermission(doc, READ); Schema docSchema = doc.getType().getSchema(schema); if (docSchema != null) { String prefix = docSchema.getNamespace().prefix; if (prefix != null && prefix.length() > 0) { field = prefix + ':' + field; } return doc.getPropertyValue(field); } else { log.warn("Cannot find schema with name=" + schema); } } else { log.warn("Cannot resolve docRef=" + docRef); } return null; }
protected Type createFakeComplexType(Schema schema, ComplexType superType, String name, XSModelGroup mg) throws TypeBindingException { ComplexType ct = new ComplexTypeImpl(superType, schema.getName(), name); // -------- Workaround - we register now the complex type - to fix // recursive references to the same type schema.registerType(ct); return processModelGroup(schema, superType, name, ct, mg, false); }
throw new DirectoryException(directorySchema + " is not a registered directory"); if (level == 0 && schema.hasField(PARENT_FIELD_ID)) {
protected void writeSchemaObject(JsonGenerator jg, Schema schema) throws IOException { jg.writeStartObject(); jg.writeStringField("name", schema.getName()); jg.writeStringField("@prefix", schema.getNamespace().prefix); jg.writeObjectFieldStart("fields"); for (Field field : schema.getFields()) { writeField(jg, field); } jg.writeEndObject(); jg.writeEndObject(); }
protected void registerSchema(Schema schema) { schemas.put(schema.getName(), schema); Namespace ns = schema.getNamespace(); uriToSchema.put(ns.uri, schema); if (!StringUtils.isBlank(ns.prefix)) { prefixToSchema.put(ns.prefix, schema); } }
@SuppressWarnings("unchecked") protected static void loadSchema(ExportedDocument xdoc, Schema schema, DocumentModel doc, Element schemaElement) { String schemaName = schemaElement.attributeValue(ExportConstants.NAME_ATTR); Map<String, Object> data = new HashMap<>(); Iterator<Element> it = schemaElement.elementIterator(); while (it.hasNext()) { Element element = it.next(); String name = element.getName(); Field field = schema.getField(name); if (field == null) { throw new NuxeoException( "Invalid input document. No such property was found " + name + " in schema " + schemaName); } Object value = getElementData(xdoc, element, field.getType()); data.put(name, value); } doc.setProperties(schemaName, data); }
private void writeSchemaProperties(JsonGenerator jg, DocumentModel doc, String schemaName) throws IOException { Writer<Property> propertyWriter = registry.getWriter(ctx, Property.class, APPLICATION_JSON_TYPE); // provides the current document to the property marshaller try (Closeable resource = ctx.wrap().with(ENTITY_TYPE, doc).open()) { Schema schema = schemaManager.getSchema(schemaName); String prefix = schema.getNamespace().prefix; if (prefix == null || prefix.length() == 0) { prefix = schemaName; } prefix = prefix + ":"; for (Field field : schema.getFields()) { String prefixedName = prefix + field.getName().getLocalName(); jg.writeFieldName(prefixedName); Property property = doc.getProperty(prefixedName); OutputStream out = new OutputStreamWithJsonWriter(jg); propertyWriter.write(property, Property.class, Property.class, APPLICATION_JSON_TYPE, out); } } } }