org.nuxeo.ecm.core.api.model.Property类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(18.1k)|赞(0)|评价(0)|浏览(96)

本文整理了Java中org.nuxeo.ecm.core.api.model.Property类的一些代码示例,展示了Property类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Property类的具体详情如下:
包路径:org.nuxeo.ecm.core.api.model.Property
类名称:Property

Property介绍

[英]Document properties are instances of document schema fields.

You can say that a Field object is like a Java class and a Property object like a class instance. Thus, schemas defines fields (or elements) which have a name and a type, and each field of a document can be instantiated (if the schema permits) as a Property object.

Properties are always bound to a schema field that provides the type and constraints on the property values. An exception is the root property the DocumentPart object which is not bound to a field but to a schema.

So properties are holding the actual values for each defined field.

The usual way of using properties is to get a document from the storage server then modify document properties and send them back to the storage server to that modifications are be stored.

Note that the storage server can be on a remote machine so when modifying properties remotely they are serialized and sent through the network between the two machines. This means properties must hold serializable values and also they must store some state flags so that the storage can decide which property was modified and how in order to correctly update the stored versions.

As we have seen each property may hold a serializable value which we will refer to as the normalized property value. For each schema field type there is only one java serializable object representation that will be used as the normalized value. The property API is giving you the possibility to use different compatible objects when setting or getting property values. Each property implementation will automatically convert the given value into a normalized one; so internally only the normalized value is stored.

For example, for date properties you may use either Date or Calendar when setting or retrieving a property value, but the normalized value will be the Calendar one.

As we have seen, properties keep some state flags. Property flags can be divided in two groups:

  • Dirty Flags - that reflect the public status of the document
  • Internal Flags - that reflect some internal state

Property Types:

Before going deeper in property flags, we will talk first about property types. There are several types of properties that are very closed on the type of fields they are bound onto.

  • Root Property (or DocumentPart) - this is a special property that is bound to a schema instead of a field And it is the root of the property tree.

  • Complex Properties - container properties that are bound to complex field types that can be represented as java Map objects. These properties contains a set of schema defined properties. You cannot add new child properties. You can only modify existing child properties. Complex property values are expressed as java Map objects.

  • Structured Properties - this is a special case of complex properties. The difference is that structured property values are expressed as scalar java objects instead of java maps. By scalar java objects we mean any well structured object which is not a container like a Map or a Collection. These objects are usually as scalar values - it doesn't make sense for example to set only some parts of that objects without creating the object completely. An example of usage are Blob properties that use Blob values.

  • List Properties - container properties that are bound to list field types.

  • Scalar Properties - atomic properties that are bound to scalar field types and that are using as values scalar or primitive java objects like arrays, primitives, String, Date etc.

As we've seen there are 2 categories of properties: container properties and scalar properties Complex and list properties are container properties while structured and scalar properties are scalar.

Dirty Flags:

Dirty flags are used to keep track of the dirty state of a property. The following flags are supported:

  • IS_PHANTOM - whether the property is existing in the storage (was explicitly set by the user) or it was dynamically generated using the default value by the implementation to fulfill schema definition. This applies to all property types
  • IS_MODIFIED - whether the property value was modified. This applies to all property types.
  • IS_NEW - whether the property is a new property that was added to a parent list property This applies only to properties that are children of a list property.
  • IS_REMOVED - whether a property was removed. A removed property will be removed from the storage and the next time you access the property it will be a phantom one. This applies only to properties that are children of a complex property.
  • IS_MOVED - whether the property was moved on another position inside the container list. This applies only to properties that are children of a list property.

There are several constraints on how property flags may change. This is a list of all changes that may occur over dirty flags:

  • NONE + MODIFIED => MODFIED
  • NONE + REMOVED => REMOVED
  • NONE + MOVED => MOVED
  • PHANTOM + MODIFIED => MODIFIED
  • NEW + MODIFIED => NEW | MODIFIED
  • NEW + MOVED => NEW | MOVED
  • MODIFIED + REMOVED => REMOVED
  • MODIFIED + MOVED => MODIFIED | MOVED
  • MODIFIED + MODIFIED => MODIFIED

The combinations not listed above are not permitted.

In case of list items, the REMOVED flag is not used since the property will be physically removed from the property tree.

Also when the dirty flag of a children property changes, its parent is informed to update its MODIFIED flag if needed. This way a modification on a children property is propagated to parents in the form of a MODIFIED flag.

Internal Flags:

Internal flags are used by the implementation to keep some internal state. For these flags you should look into the implementation

Apart flags properties can also hold some random user data using Property#setData(Object) and Property#getData() methods. This can be used for example to keep a context attached to a property. But be aware when using this you should provide serializable objects as the data you are attaching otherwise if properties are serialized / unserialized this will generate errors. The API is not forcing you to use serializable values since you can also use this feature to store temporary context data that will not be sent over the network.
[中]文档属性是文档架构字段的实例。
可以说字段对象类似于Java类,属性对象类似于类实例。因此,模式定义具有名称和类型的字段(或元素),文档的每个字段都可以实例化(如果模式允许)为属性对象。
属性总是绑定到提供属性值的类型和约束的架构字段。一个例外是DocumentPart对象的根属性,它没有绑定到字段,而是绑定到架构。
所以属性保存每个定义字段的实际值。
使用属性的通常方法是从存储服务器获取文档,然后修改文档属性并将其发送回存储服务器,以存储修改。
请注意,存储服务器可以位于远程计算机上,因此在远程修改属性时,它们会被序列化并通过两台计算机之间的网络发送。这意味着属性必须包含可序列化的值,并且它们必须存储一些状态标志,以便存储可以决定修改了哪个属性,以及如何正确更新存储的版本。
正如我们所看到的,每个属性可能都有一个可序列化的值,我们将其称为normalized属性值。对于每个模式字段类型,只有一个java serializable对象表示将用作规范化值。属性API使您可以在设置或获取属性值时使用不同的兼容对象。每个属性实现将自动将给定值转换为规范化值;因此,内部只存储标准化值。
例如,对于日期属性,在设置或检索属性值时,可以使用DateCalendar,但标准化值将是Calendar值。
正如我们所看到的,房产上保留着一些州旗。属性标志可分为两组:
*脏标志-反映文档的公共状态
*内部标志——反映某些内部状态的标志
属性类型:
在深入了解属性标志之前,我们将首先讨论属性类型。有几种类型的属性在它们绑定到的字段类型上非常接近。
*根属性(或DocumentPart)-这是绑定到架构而不是字段的特殊属性,是属性树的根。
*复杂属性-绑定到复杂字段类型的容器属性,这些字段类型可以表示为javaMap对象。这些属性包含一组架构定义的属性。不能添加新的子属性。只能修改现有的子属性。复杂属性值表示为javaMap对象。
*结构化属性——这是复杂属性的特例。不同之处在于,结构化属性值被表示为标量java对象,而不是java映射。所谓标量java对象,我们指的是任何结构良好的对象,它不是像MapCollection那样的容器。这些对象通常是标量值——例如,在不完全创建对象的情况下只设置对象的某些部分是没有意义的。使用Blob值的Blob属性就是一个例子。
*列表属性-绑定到列表字段类型的容器属性。
*标量属性——绑定到标量字段类型并用作标量值或基本java对象(如数组、基本体、字符串、日期等)的原子属性。
正如我们所看到的,有两类属性:容器属性和标量属性复杂和列表属性是容器属性,而结构化和标量属性是标量属性。
脏旗:
脏标志用于跟踪属性的脏状态。支持以下标志:
*[$9$]-该属性是否存在于存储中(由用户显式设置),还是由实现使用默认值动态生成以实现架构定义。这适用于所有属性类型
*IS_MODIFIED-属性值是否已修改。这适用于所有属性类型。
*IS_NEW-该属性是否是添加到父列表属性的新属性这仅适用于列表属性的子属性。
*IS_REMOVED-是否删除了某个属性。已删除的属性将从存储中删除,下次访问该属性时,它将是phantom属性。这仅适用于复杂属性的子属性。
*IS_MOVED-是否将属性移动到容器列表中的另一个位置。这仅适用于列表属性的子属性。
关于属性标志的更改方式,有几个限制。这是脏标志上可能发生的所有更改的列表:
*无+修改=>MODIFIED
*无+移除=>移除
*无+移动=>移动
*幻影+修改=>修改
*新建+修改=>新建|修改
*新建+移动=>新建|移动
*修改+删除=>删除
*修改+移动=>修改|移动
*修改+修改=>修改
以上未列出的组合是不允许的。
对于列表项,不使用删除标志,因为属性将从属性树中物理删除。
此外,当子属性的脏标志更改时,会通知其父属性在需要时更新其已修改的标志。这样,对子属性的修改将以修改标志的形式传播给父属性。
内部标志:
实现使用内部标志来保持一些内部状态。对于这些标志,您应该查看实现
此外,属性还可以使用Property#setData(Object)和Property#getData()方法保存一些随机用户数据。例如,这可以用于将上下文附加到属性。但是请注意,在使用此方法时,您应该提供可序列化的对象作为附加的数据,否则,如果属性已序列化/未序列化,这将生成错误。API不会强制您使用可序列化值,因为您还可以使用此功能存储不会通过网络发送的临时上下文数据。

代码示例

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-api

@Override
public Object fetch() {
  return resolver.fetch(property.getValue());
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-api

@Override
public Collection<String> getDirtyFields() {
  Collection<String> dirtyFields = new ArrayList<String>();
  for (Property prop : dp.getChildren()) {
    if (prop.isDirty()) {
      dirtyFields.add(prop.getName());
    }
  }
  return dirtyFields;
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-api

@Override
public Object setValue(String path, Object value) throws PropertyException {
  Property prop = dp.resolvePath(path);
  Object oldValue = prop.getValue();
  prop.setValue(value);
  return oldValue;
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-api

@Override
public Serializable internalGetValue() throws PropertyException {
  // noinspection CollectionDeclaredAsConcreteClass
  HashMap<String, Serializable> map = new HashMap<String, Serializable>();
  for (Property property : getChildren()) {
    map.put(property.getName(), property.getValue());
  }
  return map;
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-api

@Override
public void mapProperties(CoreSession session, DocumentModel sourceDoc, DocumentModel targetDoc, String mapping)
    {
  Map<String, String> properties = getMapping(mapping);
  for (String keyProp : properties.keySet()) {
    // verify that mapping can be done
    Property sourceProperty = sourceDoc.getProperty(keyProp);
    Property targetProperty = targetDoc.getProperty(properties.get(keyProp));
    Type sourceType = sourceProperty.getType();
    Type targetType = targetProperty.getType();
    if (!compatibleTypes(targetType, sourceType)) {
      throw new NuxeoException(
          String.format("Invalid mapping. Cannot map %s on type %s ", sourceType, targetType));
    }
    targetDoc.setPropertyValue(targetProperty.getXPath(), sourceProperty.getValue());
  }
  session.saveDocument(targetDoc);
}

代码示例来源:origin: org.nuxeo.ecm.platform/nuxeo-apidoc-core

boolean force = fileProperty.getValue() != null && doc.getPropertyValue(ATTRIBUTES_PROPERTY) == null;
if (!(force || fileProperty.isDirty() || ABOUT_TO_CREATE.equals(event.getName()))) {
  return;
Blob blob = (Blob) fileProperty.getValue();
if (blob == null) {
  doc.setPropertyValue(ATTRIBUTES_PROPERTY, null);

代码示例来源:origin: org.nuxeo.ecm.automation/nuxeo-automation-core

@OperationMethod(collector = DocumentModelCollector.class)
public DocumentModel run(DocumentModel doc) throws OperationException {
  Property p = doc.getProperty(xpath);
  Type type = p.getType();
  checkFieldType(type, value);
  List<Serializable> array = p.getValue() != null ? Arrays.asList((Serializable[]) p.getValue()) : null;
  Serializable newValue = addValueIntoList(array, value);
  p.setValue(newValue);
  if (save) {
    doc = session.saveDocument(doc);
    session.save();
  }
  return doc;
}

代码示例来源:origin: org.nuxeo.ecm.platform/nuxeo-platform-webapp-base

for (String schema : collector.getSchemas()) {
  for (Property property : collector.getPropertyObjects(schema)) {
    if (!property.isDirty()) {
      continue;
    Serializable data = property.getValue();
    if (data instanceof Date) {
      data = DateParser.formatW3CDateTime((Date) data);
      data = DateParser.formatW3CDateTime(((Calendar) data).getTime());
    formData.put(property.getName(), data);

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-api

Field field = prop.getField();
assert field.getType().isComplexType();
List<ConstraintViolation> violations = new ArrayList<>();
boolean allChildrenPhantom = true;
for (Property child : prop.getChildren()) {
  if (!child.isPhantom()) {
    allChildrenPhantom = false;
    break;
Object value = prop.getValue();
if (prop.isPhantom() || value == null || allChildrenPhantom) {
  if (!field.isNillable()) {
    addNotNullViolation(violations, schema, path);
      for (Property child : prop.getChildren()) {
        List<PathNode> subPath = new ArrayList<>(path);
        subPath.add(new PathNode(child.getField()));
        violations.addAll(validateAnyTypeProperty(schema, subPath, child, dirtyOnly, true));

代码示例来源:origin: org.nuxeo.ecm.platform/nuxeo-platform-imaging-api

@Override
public Blob getPictureFromTitle(String title) throws PropertyException {
  if (title == null) {
    return null;
  }
  Collection<Property> views = doc.getProperty(VIEWS_PROPERTY).getChildren();
  for (Property property : views) {
    if (title.equals(property.getValue(TITLE_PROPERTY))) {
      Blob blob = (Blob) property.getValue("content");
      if (blob != null) {
        blob.setFilename((String) property.getValue(FILENAME_PROPERTY));
      }
      return blob;
    }
  }
  return null;
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-api

protected void findBlobsProperties(Property property, List<String> split, List<Property> properties) {
  if (split.isEmpty()) {
    if (property.getValue() != null) {
      properties.add(property);
    }
  } else {
    for (Property childProperty : property.getChildren()) {
      Property childSubProp = childProperty.get(split.get(0));
      List<String> subPath = split.subList(1, split.size());
      findBlobsProperties(childSubProp, subPath, properties);
    }
  }
}

代码示例来源:origin: org.nuxeo.ecm.platform/nuxeo-platform-rendering

public TemplateModel wrap(Property property) throws TemplateModelException {
  try {
    if (property.isScalar()) {
      Object value = property.getValue();
      if (value == null) {
        return TemplateModel.NOTHING;
      if (property.getType() == DateType.INSTANCE) {
        return new SimpleDate(((Calendar) value).getTime(), TemplateDateModel.DATETIME);
    } else if (property.isList()) {
      if (property.isContainer()) {
        return new ListPropertyTemplate(wrapper, (ListProperty) property);
      } else {
        Object value;
        try {
          value = property.getValue();
        } catch (PropertyException e) {
          throw new IllegalArgumentException("Cannot get array from array property " + property);
      return new BlobTemplate(wrapper, (Blob) property.getValue());
    } else {
      return new ComplexPropertyTemplate(wrapper, property);

代码示例来源:origin: toutatice-services.carto-nat/toutatice-carto-nat-ecm

@OperationMethod(collector=DocumentModelCollector.class)
public DocumentModel run(DocumentModel doc) throws Exception {
  
  Property propertyRoot =  doc.getProperty(xpathRoot);
  Collection<Property> childrenProperties = propertyRoot.getChildren();
  boolean add=true;
  if(key != null){
          
    for (Property property : childrenProperties) {
      if(property.getValue(key).equals(properties.get(key))){
        for (String pptyKey : properties.keySet()) {
          property.setValue(pptyKey, properties.get(pptyKey));
        }
        add=false;
        break;
      }
    }
  }
  if(key==null || add){
    propertyRoot.addValue(properties);
  }
  
  if (save) {
    doc = session.saveDocument(doc);
  }
  return doc;
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-api

/**
 * @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;
}

代码示例来源:origin: org.nuxeo.binary.metadata/nuxeo-binary-metadata

@Override
public void handleUpdate(List<MetadataMappingDescriptor> mappingDescriptors, DocumentModel doc) {
  for (MetadataMappingDescriptor mappingDescriptor : mappingDescriptors) {
    Property fileProp = doc.getProperty(mappingDescriptor.getBlobXPath());
    Blob blob = fileProp.getValue(Blob.class);
    if (blob != null) {
      boolean isDirtyMapping = isDirtyMapping(mappingDescriptor, doc);
      if (isDirtyMapping) {
        BlobManager blobManager = Framework.getService(BlobManager.class);
        BlobProvider blobProvider = blobManager.getBlobProvider(blob);
        // do not write metadata in blobs backed by extended blob providers (ex: Google Drive) or blobs from
        // providers that prevent user updates
        if (blobProvider != null && (!blobProvider.supportsUserUpdate() || blobProvider.getBinaryManager() == null)) {
          return;
        }
        // if document metadata dirty, write metadata from doc to Blob
        Blob newBlob = writeMetadata(mappingDescriptor.getProcessor(), fileProp.getValue(Blob.class), mappingDescriptor.getId(), doc);
        fileProp.setValue(newBlob);
      } else if (fileProp.isDirty()) {
        // if Blob dirty and document metadata not dirty, write metadata from Blob to doc
        writeMetadata(doc);
      }
    }
  }
}

代码示例来源:origin: org.nuxeo.ecm.webengine/nuxeo-webengine-core

static void fillDocumentProperty(Property p, String key, Object[] ar) throws PropertyException {
  if (ar == null || ar.length == 0) {
    p.remove();
  } else if (p.isScalar()) {
    p.setValue(ar[0]);
  } else if (p.isList()) {
    if (!p.isContainer()) { // an array
      p.setValue(ar);
    } else {
      Type elType = ((ListType) p.getType()).getFieldType();
      if (elType.isSimpleType()) {
        p.setValue(ar);
      } else if ("content".equals(elType.getName())) {
        p.setValue(blobs);
      } else {
  } else if (p.isComplex()) {
    if (p.getClass() == BlobProperty.class) {
        blob = (Blob) ar[0];
      p.setValue(blob);
    } else {

代码示例来源:origin: org.nuxeo.ecm.automation/nuxeo-automation-core

protected void writeListProperty(JsonGenerator jg, Property prop, PropertyConsumer fieldNameWriter)
    throws PropertyException, IOException {
  // test if array/list is empty - don't write empty case
  if (!writeEmpty && (prop == null || (prop instanceof ArrayProperty && prop.getValue() == null)
      || (prop instanceof ListProperty && prop.getChildren().isEmpty()))) {
    return;
  }
  fieldNameWriter.accept(jg, prop);
  jg.writeStartArray();
  if (prop instanceof ArrayProperty) {
    Object[] ar = (Object[]) prop.getValue();
    if (ar == null) {
      jg.writeEndArray();
      return;
    }
    Type type = ((ListType) prop.getType()).getFieldType();
    for (Object o : ar) {
      jg.writeString(type.encode(o));
    }
  } else {
    for (Property p : prop.getChildren()) {
      // it's a list of complex object, don't write field names
      writeProperty(jg, p, PropertyConsumer.nothing());
    }
  }
  jg.writeEndArray();
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core

private void filterProperty(Property prop, DocumentModel docModel) {
  if (!prop.isDirty()) {
    return;
    String p = (String) prop.getValue();
    if (p != null && charsToRemove.matchesAnyOf(p)) {
      String filteredProp = filter(p);
      docModel.setPropertyValue(prop.getXPath(), filteredProp);
    Serializable value = prop.getValue();
    if (value instanceof Object[]) {
      Object[] arrayProp = (Object[]) value;
        docModel.setPropertyValue(prop.getXPath(), arrayProp);

代码示例来源:origin: toutatice-services.carto-nat/toutatice-carto-nat-ecm

if (unumPart != null) {
  Collection<Property> referentsProps = unumPart.get(DenormalizationConstants.REF_REFERENTS).getChildren();
      Collection<Property> childrenProps = prop.getChildren();
      if (CollectionUtils.isNotEmpty(childrenProps)) {
        jg.writeStartObject();
        for (Property childProp : childrenProps) {
          String childPropName = childProp.getName();
          jg.writeFieldName(childPropName);
          JsonESDocumentWriter.writePropertyValue(jg, childProp, null);
          if (StringUtils.equals(DenormalizationConstants.REF_REFERENTS_UID_PROPERTY, childPropName)) {
            DocumentModel userModel = userManager.getUserModel(childProp.getValue(String.class));
            if (denormalizeUser(jg, doc, childProp, userModel)) {
              usersModels.add(userModel);

代码示例来源:origin: toutatice-services.carto-nat/toutatice-carto-nat-ecm

@OperationMethod
public DocumentModel run(DocumentModel input) throws Exception {
  
  if(input.isProxy()){
    input = session.getWorkingCopy(input.getRef());
  }
  Property ppt = input.getProperty(xpath);
  Collection<Property> childrenPpt = ppt.getChildren();
  if (!childrenPpt.isEmpty()) {
    for (Property child : childrenPpt) {
      Serializable pptyval = child.getValue(criterion);
      if (pptyval != null && (pptyval.toString()).equals(filterValue)) {					
        child.remove();
        break;
      }
    }
  }
  if (save) {
    input = session.saveDocument(input);
  }
  return input;
}

相关文章