Class DefaultBlobDispatcher
- java.lang.Object
-
- org.nuxeo.ecm.core.blob.DefaultBlobDispatcher
-
- All Implemented Interfaces:
BlobDispatcher
public class DefaultBlobDispatcher extends Object implements BlobDispatcher
Default blob dispatcher, that uses the repository name as the blob provider.Alternatively, it can be configured through properties to dispatch to a blob provider based on document properties instead of the repository name.
The property name is a list of comma-separated clauses, with each clause consisting of a property, an operator and a value. The property can be a
Documentxpath,ecm:repositoryName,ecm:path, or, to match the current blob being dispatched,blob:name,blob:mime-type,blob:encoding,blob:digest,blob:lengthorblob:xpath.Comma-separated clauses are ANDed together. The special name
defaultdefines the default provider, and must be present.Available operators between property and value are =, !=, <, <= ,>, >=, ~ and ^.
The operators =, !=, <, <=, > and >= work as numeric operators if the property is numeric, otherwise as string comparisons operators.
The operator ~ does glob matching using
?to match a single arbitrary character, and*to match any number of characters (including none). The operator ^ does full regexp matching.For example, to dispatch to the "first" provider if dc:format is "video", to the "second" provider if the blob's MIME type is "video/mp4", to the "third" provider if the blob is stored as a secondary attached file, to the "fourth" provider if the lifecycle state is "approved", to the "fifth" provider if the blob's document is stored in under an "images" folder, and the document is in the default repository, and otherwise to the "other" provider:
<property name="dc:format=video">first</property> <property name="blob:mime-type=video/mp4">second</property> <property name="blob:xpath~files/*/file">third</property> <property name="ecm:repositoryName=default,ecm:lifeCycleState=approved">fourth</property> <property name="ecm:path^.*/images/.*">fifth</property> <property name="default">other</property>You can make use of a record blob provider by using:
<property name="records">records</property> <property name="default">other</property>- Since:
- 7.3
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classDefaultBlobDispatcher.Clauseprotected static classDefaultBlobDispatcher.Opprotected static classDefaultBlobDispatcher.Rule-
Nested classes/interfaces inherited from interface org.nuxeo.ecm.core.blob.BlobDispatcher
BlobDispatcher.BlobDispatch
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringBLOB_DIGESTprotected static StringBLOB_ENCODINGprotected static StringBLOB_LENGTHprotected static StringBLOB_MIME_TYPEprotected static StringBLOB_NAMEprotected static StringBLOB_PREFIXprotected static StringBLOB_XPATHprotected StringdefaultProviderIdprotected static StringIS_FLEXIBLE_RECORDPseudo-property for the flexible record state.protected static StringIS_RECORDPseudo-property for the record state.protected static StringNAME_DEFAULTprotected static PatternNAME_PATTERNprotected static StringNAME_RECORDSprotected static StringPATHPseudo-property for the document path.protected Set<String>providerIdsprotected static StringREPOSITORY_NAMEPseudo-property for the repository name.protected List<String>repositoryNamesprotected List<DefaultBlobDispatcher.Rule>rulesprotected Set<String>rulesXPathsprotected booleanuseRepositoryName
-
Constructor Summary
Constructors Constructor Description DefaultBlobDispatcher()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckBlob(Document doc, Document.BlobAccessor accessor)Checks if the blob is stored in the expected blob provider to which it's supposed to be dispatched.protected voidcheckBlobCanBeDeleted(Document doc, String xpath)protected booleancompare(Object a, DefaultBlobDispatcher.Clause clause, boolean eqneq, IntPredicate predicate)protected Objectconvert(Object value)protected voiddeleteBlobIfRecord(String blobProviderId, Document doc, String xpath)StringgetBlobProvider(String repositoryName)Decides whichBlobProviderto use to read a blob from the given repository if no prefix is specified in the blob key.BlobDispatcher.BlobDispatchgetBlobProvider(Document doc, Blob blob, String xpath)Decides whichBlobProviderto use to write the given blob, and whether the provider id should be added as prefix to the managed blob key.Collection<String>getBlobProviderIds()Gets the provider ids to which this dispatcher can dispatch.protected DefaultBlobDispatcher.ClausegetClause(String name)protected PatterngetPatternFromGlob(String glob)protected StringgetProviderId(Document doc, Blob blob, String blobXPath)protected ObjectgetValue(Document doc, Blob blob, String blobXPath, DefaultBlobDispatcher.Clause clause)voidinitialize(Map<String,String> properties)Initializes this blob dispatcher.booleanisUseRepositoryName()protected booleanmatch(Object value, DefaultBlobDispatcher.Clause clause)voidnotifyAfterCopy(Document doc)Notifies the blob dispatcher that the document has been copied.voidnotifyBeforeRemove(Document doc)Notifies the blob dispatcher that the document is about to be removed.voidnotifyChanges(Document doc, Set<String> xpaths)Notifies the blob dispatcher that a set of xpaths have changed on a document.voidnotifyMakeRecord(Document doc)Notifies the blob dispatcher that the document was made a record.-
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.blob.BlobDispatcher
getBlobProvider
-
-
-
-
Field Detail
-
NAME_DEFAULT
protected static final String NAME_DEFAULT
- See Also:
- Constant Field Values
-
NAME_RECORDS
protected static final String NAME_RECORDS
- See Also:
- Constant Field Values
-
NAME_PATTERN
protected static final Pattern NAME_PATTERN
-
REPOSITORY_NAME
protected static final String REPOSITORY_NAME
Pseudo-property for the repository name.- See Also:
- Constant Field Values
-
PATH
protected static final String PATH
Pseudo-property for the document path.- See Also:
- Constant Field Values
-
IS_RECORD
protected static final String IS_RECORD
Pseudo-property for the record state.- Since:
- 11.1
- See Also:
- Constant Field Values
-
IS_FLEXIBLE_RECORD
protected static final String IS_FLEXIBLE_RECORD
Pseudo-property for the flexible record state.- Since:
- 2023.1
- See Also:
- Constant Field Values
-
BLOB_PREFIX
protected static final String BLOB_PREFIX
- See Also:
- Constant Field Values
-
BLOB_NAME
protected static final String BLOB_NAME
- See Also:
- Constant Field Values
-
BLOB_MIME_TYPE
protected static final String BLOB_MIME_TYPE
- See Also:
- Constant Field Values
-
BLOB_ENCODING
protected static final String BLOB_ENCODING
- See Also:
- Constant Field Values
-
BLOB_DIGEST
protected static final String BLOB_DIGEST
- See Also:
- Constant Field Values
-
BLOB_LENGTH
protected static final String BLOB_LENGTH
- See Also:
- Constant Field Values
-
BLOB_XPATH
protected static final String BLOB_XPATH
- See Also:
- Constant Field Values
-
useRepositoryName
protected boolean useRepositoryName
-
rules
protected List<DefaultBlobDispatcher.Rule> rules
-
defaultProviderId
protected String defaultProviderId
-
-
Method Detail
-
initialize
public void initialize(Map<String,String> properties)
Description copied from interface:BlobDispatcherInitializes this blob dispatcher.- Specified by:
initializein interfaceBlobDispatcher
-
getClause
protected DefaultBlobDispatcher.Clause getClause(String name)
-
getBlobProviderIds
public Collection<String> getBlobProviderIds()
Description copied from interface:BlobDispatcherGets the provider ids to which this dispatcher can dispatch.Blobs already having a provider id not listed here won't be touched on write.
- Specified by:
getBlobProviderIdsin interfaceBlobDispatcher- Returns:
- a collection containing the provider ids
-
getValue
protected Object getValue(Document doc, Blob blob, String blobXPath, DefaultBlobDispatcher.Clause clause)
-
match
protected boolean match(Object value, DefaultBlobDispatcher.Clause clause)
-
compare
protected boolean compare(Object a, DefaultBlobDispatcher.Clause clause, boolean eqneq, IntPredicate predicate)
-
getBlobProvider
public String getBlobProvider(String repositoryName)
Description copied from interface:BlobDispatcherDecides whichBlobProviderto use to read a blob from the given repository if no prefix is specified in the blob key.- Specified by:
getBlobProviderin interfaceBlobDispatcher- Parameters:
repositoryName- the repository name- Returns:
- the blob provider id
-
getBlobProvider
public BlobDispatcher.BlobDispatch getBlobProvider(Document doc, Blob blob, String xpath)
Description copied from interface:BlobDispatcherDecides whichBlobProviderto use to write the given blob, and whether the provider id should be added as prefix to the managed blob key.- Specified by:
getBlobProviderin interfaceBlobDispatcher- Parameters:
doc- the document containing the blobblob- the blobxpath- the xpath of the blob in the document- Returns:
- the blob provider id and whether it should be added as prefix
-
notifyChanges
public void notifyChanges(Document doc, Set<String> xpaths)
Description copied from interface:BlobDispatcherNotifies the blob dispatcher that a set of xpaths have changed on a document.- Specified by:
notifyChangesin interfaceBlobDispatcher- Parameters:
doc- the documentxpaths- the set of changed xpaths
-
checkBlob
protected void checkBlob(Document doc, Document.BlobAccessor accessor)
Checks if the blob is stored in the expected blob provider to which it's supposed to be dispatched. If not, store it in the correct one (and maybe remove it from the previous one if it makes sense).
-
notifyMakeRecord
public void notifyMakeRecord(Document doc)
Description copied from interface:BlobDispatcherNotifies the blob dispatcher that the document was made a record.- Specified by:
notifyMakeRecordin interfaceBlobDispatcher- Parameters:
doc- the document
-
notifyAfterCopy
public void notifyAfterCopy(Document doc)
Description copied from interface:BlobDispatcherNotifies the blob dispatcher that the document has been copied.- Specified by:
notifyAfterCopyin interfaceBlobDispatcher- Parameters:
doc- the new document, the result of the copy
-
notifyBeforeRemove
public void notifyBeforeRemove(Document doc)
Description copied from interface:BlobDispatcherNotifies the blob dispatcher that the document is about to be removed.- Specified by:
notifyBeforeRemovein interfaceBlobDispatcher- Parameters:
doc- the document
-
deleteBlobIfRecord
protected void deleteBlobIfRecord(String blobProviderId, Document doc, String xpath)
-
isUseRepositoryName
public boolean isUseRepositoryName()
- Specified by:
isUseRepositoryNamein interfaceBlobDispatcher- Returns:
- true if the blobs are dispatched to the provider with the same name than the repository.
-
-