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; }
@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); }
private void setStillSchema(Schema schema, DocumentModel doc) { Map<String, Object> data = new HashMap<String, Object>(); Collection<Field> fields = schema.getFields(); Iterator<Field> iterator = fields.iterator(); while(iterator.hasNext()){ Field field = iterator.next(); String name = field.getName().getLocalName(); data.put(name, null); } doc.setProperties(schema.getName(), data); }
/** * Constructs a composite type. Schemas must include those from the super type. */ public CompositeTypeImpl(CompositeType superType, String schema, String name, List<Schema> schemaList) { super(superType, schema, name); if (schemaList == null) { schemaList = Collections.emptyList(); } for (Schema s : schemaList) { schemas.put(s.getName(), s); for (Field field : s.getFields()) { addField(field); } } }
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(); }
@Override protected void writeEntityBody(Schema schema, JsonGenerator jg) throws IOException { jg.writeStringField("name", schema.getName()); String prefix = schema.getNamespace().prefix; if (StringUtils.isNotBlank(prefix)) { jg.writeStringField("prefix", prefix); // backward compat for old schema writers jg.writeStringField("@prefix", prefix); } jg.writeObjectFieldStart("fields"); for (Field field : schema.getFields()) { writeField(jg, field); } jg.writeEndObject(); }
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(); }
for (Field field : schema.getFields()) { QName fieldName = field.getName(); String key = fieldName.getLocalName();
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); } } }
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); } } } }
readColumns = new LinkedList<>(); boolean hasPrimary = false; for (Field f : schema.getFields()) { String fieldName = f.getName().getLocalName();
protected void writeUserProfile(JsonGenerator jg, DocumentModel up) throws IOException { Writer<Property> propertyWriter = registry.getWriter(ctx, Property.class, APPLICATION_JSON_TYPE); Schema schema = schemaManager.getSchema(USER_PROFILE_SCHEMA); // provides the user profile document to the property marshaller try (Closeable resource = ctx.wrap().with(ENTITY_TYPE, up).open()) { for (Field field : schema.getFields()) { jg.writeFieldName(field.getName().getLocalName()); Property property = up.getProperty(field.getName().getPrefixedName()); 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(); } else if (group != null) { Schema schema = schemaManager.getSchema(userManager.getGroupSchemaName()); for (Field field : schema.getFields()) { QName fieldName = field.getName(); String key = fieldName.getLocalName();
protected void readDocumentSchemas(Element element, DocumentModel doc, boolean inlineBlobs) throws IOException { SchemaManager schemaManager = Framework.getService(SchemaManager.class); String[] schemaNames = doc.getSchemas(); for (String schemaName : schemaNames) { Element schemaElement = element.addElement(ExportConstants.SCHEMA_TAG).addAttribute("name", schemaName); Schema schema = schemaManager.getSchema(schemaName); Namespace targetNs = schema.getNamespace(); // If namespace prefix is empty, use schema name if (StringUtils.isEmpty(targetNs.prefix)) { targetNs = new Namespace(targetNs.uri, schema.getName()); } schemaElement.addNamespace(targetNs.prefix, targetNs.uri); DataModel dataModel = doc.getDataModel(schemaName); for (Field field : schema.getFields()) { Object value = dataModel.getData(field.getName().getLocalName()); readProperty(schemaElement, targetNs, field, value, inlineBlobs); } } }
public static void applyAllPropertyValues(DocumentModel src, DocumentModel dst) { SchemaManager service = Framework.getService(SchemaManager.class); DocumentType type = service.getDocumentType(src.getType()); String[] schemas = type.getSchemaNames(); for (String schemaName : schemas) { Schema schema = service.getSchema(schemaName); DataModelImpl dataModel = (DataModelImpl) dst.getDataModel(schemaName); DataModelImpl fromDataModel = (DataModelImpl) src.getDataModel(schemaName); for (Field field : schema.getFields()) { String fieldName = field.getName().getLocalName(); Serializable data = (Serializable) fromDataModel.getData(fieldName); try { if (!(dataModel.getDocumentPart().get(fieldName) instanceof BlobProperty)) { dataModel.setData(fieldName, data); } else { dataModel.setData(fieldName, decodeBlob(data)); } } catch (PropertyNotFoundException e) { continue; } } } }
if (session.hasPermission(principal, document.getRef(), permission)) { JSONObject obj = new JSONObject(); for (Field field : schema.getFields()) { QName fieldName = field.getName(); String key = fieldName.getLocalName(); for (Field field : schema.getFields()) { QName fieldName = field.getName(); String key = fieldName.getLocalName();