Package org.nuxeo.ecm.core.model
Class DocumentModelResolver
- java.lang.Object
-
- org.nuxeo.ecm.core.schema.types.resolver.AbstractObjectResolver
-
- org.nuxeo.ecm.core.model.DocumentModelResolver
-
- All Implemented Interfaces:
Serializable,ObjectResolver
public class DocumentModelResolver extends AbstractObjectResolver implements ObjectResolver
ThisObjectResolverallows to manage integrity for fields containingDocumentModelreferences (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 returnsDocumentModel. Thefetch(Class, Object)returnsDocumentModelor 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDocumentModelResolver.MODEprotected static classDocumentModelResolver.REF-
Nested classes/interfaces inherited from interface org.nuxeo.ecm.core.schema.types.resolver.ObjectResolver
ObjectResolver.Helper
-
-
Field Summary
Fields Modifier and Type Field Description static StringNAMEstatic StringPARAM_STOREstatic StringSTORE_ID_ONLYSince 10.2static StringSTORE_PATH_ONLYSince 10.2static StringSTORE_REPO_AND_IDstatic StringSTORE_REPO_AND_PATH-
Fields inherited from class org.nuxeo.ecm.core.schema.types.resolver.AbstractObjectResolver
parameters, validation
-
Fields inherited from interface org.nuxeo.ecm.core.schema.types.resolver.ObjectResolver
VALIDATION_PARAMETER_KEY
-
-
Constructor Summary
Constructors Constructor Description DocumentModelResolver()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigure(Map<String,String> parameters)Configure this resolver.<T> Tfetch(Class<T> type, Object value)Provides the entity referenced by a value, return the entity as expected type.Objectfetch(Object value)Provides the entity referenced by a value.Objectfetch(Object value, Object context)Provides the entity referenced by a value, in the given context.StringgetConstraintErrorMessage(Object invalidValue, Locale locale)Provides an error message to display when some invalid value does not match existing entity.List<Class<?>>getManagedClasses()Returns the resolved object types.DocumentModelResolver.MODEgetMode()StringgetName()Provides this resolver name.SerializablegetReference(Object entity)Generates a reference to an entity.protected booleanhasReadPermission(CoreSession session, DocumentRef docRef)Checks directly the Read permission asCoreSession.exists(DocumentRef)relies on the Browse permission only.protected voidresolve(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.booleanvalidate(Object value)Validates some value references an existing entity.booleanvalidate(Object value, Object context)Validates some value references an existing entity, in the given context-
Methods inherited from class org.nuxeo.ecm.core.schema.types.resolver.AbstractObjectResolver
checkConfig, getParameters
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.nuxeo.ecm.core.schema.types.resolver.ObjectResolver
getParameters
-
-
-
-
Field Detail
-
NAME
public static final String NAME
- See Also:
- Constant Field Values
-
PARAM_STORE
public static final String PARAM_STORE
- See Also:
- Constant Field Values
-
STORE_REPO_AND_PATH
public static final String STORE_REPO_AND_PATH
- See Also:
- Constant Field Values
-
STORE_PATH_ONLY
public static final String STORE_PATH_ONLY
Since 10.2- See Also:
- Constant Field Values
-
STORE_REPO_AND_ID
public static final String STORE_REPO_AND_ID
- See Also:
- Constant Field Values
-
STORE_ID_ONLY
public static final String STORE_ID_ONLY
Since 10.2- See Also:
- Constant Field Values
-
-
Method Detail
-
getMode
public DocumentModelResolver.MODE getMode()
-
getManagedClasses
public List<Class<?>> getManagedClasses()
Description copied from interface:ObjectResolverReturns the resolved object types.- Specified by:
getManagedClassesin interfaceObjectResolver
-
configure
public void configure(Map<String,String> parameters) throws IllegalStateException
Description copied from interface:ObjectResolverConfigure this resolver.- Specified by:
configurein interfaceObjectResolver- Overrides:
configurein classAbstractObjectResolver- Parameters:
parameters- A map of parameter whose keys are parameter names and map value are corresponding values.- Throws:
IllegalStateException- If this resolver is already configured.
-
getName
public String getName()
Description copied from interface:ObjectResolverProvides this resolver name.- Specified by:
getNamein interfaceObjectResolver- Returns:
- The resolver name.
-
validate
public boolean validate(Object value)
Description copied from interface:ObjectResolverValidates some value references an existing entity.- Specified by:
validatein interfaceObjectResolver- Overrides:
validatein classAbstractObjectResolver- 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:ObjectResolverValidates some value references an existing entity, in the given context- Specified by:
validatein interfaceObjectResolver- Overrides:
validatein classAbstractObjectResolver- 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:ObjectResolverProvides the entity referenced by a value.- Specified by:
fetchin interfaceObjectResolver- 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:ObjectResolverProvides the entity referenced by a value, in the given context.- Specified by:
fetchin interfaceObjectResolver- 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 asCoreSession.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:ObjectResolverProvides the entity referenced by a value, return the entity as expected type.- Specified by:
fetchin interfaceObjectResolvervalue- 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.
-
getReference
public Serializable getReference(Object entity) throws IllegalStateException
Description copied from interface:ObjectResolverGenerates a reference to an entity.- Specified by:
getReferencein interfaceObjectResolver- Parameters:
entity- The entity.- Returns:
- A reference to the entity or null if its not a managed entity type.
- Throws:
IllegalStateException- If this resolver has not been configured.
-
getConstraintErrorMessage
public String getConstraintErrorMessage(Object invalidValue, Locale locale)
Description copied from interface:ObjectResolverProvides an error message to display when some invalid value does not match existing entity.- Specified by:
getConstraintErrorMessagein interfaceObjectResolver- 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
-
-