Class DocumentModelResolver

  • All Implemented Interfaces:
    Serializable, ObjectResolver

    public class DocumentModelResolver
    extends AbstractObjectResolver
    implements ObjectResolver
    This ObjectResolver allows to manage integrity for fields containing DocumentModel references (id or path).

    Resolved references must be either a path or an id, default mode is id. Storing path keep link with place in the Document hierarchy no matter which Document is referenced. Storing id track the Document no matter where the Document is stored.

    All references, id or path, are prefixed with the document expected repository name. For example :

    • default:352c21bc-f908-4507-af99-411d3d84ee7d
    • test:/path/to/my/doc

    The fetch(Object) method returns DocumentModel. The fetch(Class, Object) returns DocumentModel or specific document adapter.

    To use it, put the following code in your schema XSD :

     
     <!-- default resolver is an id based resolver -->
     <xs:simpleType name="favoriteDocument1">
       <xs:restriction base="xs:string" ref:resolver="documentResolver" />
     </xs:simpleType>
    
     <!-- store id -->
     <xs:simpleType name="favoriteDocument2">
       <xs:restriction base="xs:string" ref:resolver="documentResolver" ref:store="id" />
     </xs:simpleType>
    
     <!-- store path -->
     <xs:simpleType name="bestDocumentRepositoryPlace">
       <xs:restriction base="xs:string" ref:resolver="documentResolver" ref:store="path" />
     </xs:simpleType>
     
     
    Since:
    7.1
    See Also:
    Serialized Form
    • Constructor Detail

      • DocumentModelResolver

        public DocumentModelResolver()
    • Method Detail

      • validate

        public boolean validate​(Object value)
        Description copied from interface: ObjectResolver
        Validates some value references an existing entity.
        Specified by:
        validate in interface ObjectResolver
        Overrides:
        validate in class AbstractObjectResolver
        Parameters:
        value - The reference.
        Returns:
        true if value could be resolved as an existing external reference, false otherwise.
      • validate

        public boolean validate​(Object value,
                                Object context)
        Description copied from interface: ObjectResolver
        Validates some value references an existing entity, in the given context
        Specified by:
        validate in interface ObjectResolver
        Overrides:
        validate in class AbstractObjectResolver
        Parameters:
        value - The reference.
        context - A resolver-specific context allowing resolution of the value.
        Returns:
        true if value could be resolved as an existing external reference, false otherwise.
      • fetch

        public Object fetch​(Object value)
        Description copied from interface: ObjectResolver
        Provides the entity referenced by a value.
        Specified by:
        fetch in interface ObjectResolver
        Parameters:
        value - The reference.
        Returns:
        The referenced entity, null if no entity matches the value.
      • fetch

        public Object fetch​(Object value,
                            Object context)
        Description copied from interface: ObjectResolver
        Provides the entity referenced by a value, in the given context.
        Specified by:
        fetch in interface ObjectResolver
        Parameters:
        value - The reference.
        context - A resolver-specific context allowing resolution of the value.
        Returns:
        The referenced entity, null if no entity matches the value.
      • hasReadPermission

        protected boolean hasReadPermission​(CoreSession session,
                                            DocumentRef docRef)
        Checks directly the Read permission as CoreSession.exists(DocumentRef) relies on the Browse permission only.

        A user can have Browse but not Read, thus the resolver won't be able to fetch the document.

      • resolve

        protected void resolve​(Object value,
                               Object context,
                               BiConsumer<CoreSession,​DocumentRef> resolver)
        Resolves the value (in the context) into a session and docRef, and passes them to the resolver.

        The resolver is not called if the value cannot be resolved.

      • fetch

        public <T> T fetch​(Class<T> type,
                           Object value)
                    throws IllegalStateException
        Description copied from interface: ObjectResolver
        Provides the entity referenced by a value, return the entity as expected type.
        Specified by:
        fetch in interface ObjectResolver
        value - The reference.
        Returns:
        The referenced entity, null if no entity matches the value or if this entity cannot be converted as type.
        Throws:
        IllegalStateException - If this resolver has not been configured.
      • getConstraintErrorMessage

        public String getConstraintErrorMessage​(Object invalidValue,
                                                Locale locale)
        Description copied from interface: ObjectResolver
        Provides an error message to display when some invalid value does not match existing entity.
        Specified by:
        getConstraintErrorMessage in interface ObjectResolver
        Parameters:
        invalidValue - The invalid value that don't match any entity.
        locale - The language in which the message should be generated.
        Returns:
        A message in the specified language or