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
Document
xpath,ecm:repositoryName
,ecm:path
, or, to match the current blob being dispatched,blob:name
,blob:mime-type
,blob:encoding
,blob:digest
,blob:length
orblob:xpath
.Comma-separated clauses are ANDed together. The special name
default
defines 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 class
DefaultBlobDispatcher.Clause
protected static class
DefaultBlobDispatcher.Op
protected static class
DefaultBlobDispatcher.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 String
BLOB_DIGEST
protected static String
BLOB_ENCODING
protected static String
BLOB_LENGTH
protected static String
BLOB_MIME_TYPE
protected static String
BLOB_NAME
protected static String
BLOB_PREFIX
protected static String
BLOB_XPATH
protected String
defaultProviderId
protected static String
IS_FLEXIBLE_RECORD
Pseudo-property for the flexible record state.protected static String
IS_RECORD
Pseudo-property for the record state.protected static String
NAME_DEFAULT
protected static Pattern
NAME_PATTERN
protected static String
NAME_RECORDS
protected static String
PATH
Pseudo-property for the document path.protected Set<String>
providerIds
protected static String
REPOSITORY_NAME
Pseudo-property for the repository name.protected List<String>
repositoryNames
protected List<DefaultBlobDispatcher.Rule>
rules
protected Set<String>
rulesXPaths
protected boolean
useRepositoryName
-
Constructor Summary
Constructors Constructor Description DefaultBlobDispatcher()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.protected void
checkBlobCanBeDeleted(Document doc, String xpath)
protected boolean
compare(Object a, DefaultBlobDispatcher.Clause clause, boolean eqneq, IntPredicate predicate)
protected Object
convert(Object value)
protected void
deleteBlobIfRecord(String blobProviderId, Document doc, String xpath)
String
getBlobProvider(String repositoryName)
Decides whichBlobProvider
to use to read a blob from the given repository if no prefix is specified in the blob key.BlobDispatcher.BlobDispatch
getBlobProvider(Document doc, Blob blob, String xpath)
Decides whichBlobProvider
to 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.Clause
getClause(String name)
protected Pattern
getPatternFromGlob(String glob)
protected String
getProviderId(Document doc, Blob blob, String blobXPath)
protected Object
getValue(Document doc, Blob blob, String blobXPath, DefaultBlobDispatcher.Clause clause)
void
initialize(Map<String,String> properties)
Initializes this blob dispatcher.boolean
isUseRepositoryName()
protected boolean
match(Object value, DefaultBlobDispatcher.Clause clause)
void
notifyAfterCopy(Document doc)
Notifies the blob dispatcher that the document has been copied.void
notifyBeforeRemove(Document doc)
Notifies the blob dispatcher that the document is about to be removed.void
notifyChanges(Document doc, Set<String> xpaths)
Notifies the blob dispatcher that a set of xpaths have changed on a document.void
notifyMakeRecord(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:BlobDispatcher
Initializes this blob dispatcher.- Specified by:
initialize
in interfaceBlobDispatcher
-
getClause
protected DefaultBlobDispatcher.Clause getClause(String name)
-
getBlobProviderIds
public Collection<String> getBlobProviderIds()
Description copied from interface:BlobDispatcher
Gets 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:
getBlobProviderIds
in 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:BlobDispatcher
Decides whichBlobProvider
to use to read a blob from the given repository if no prefix is specified in the blob key.- Specified by:
getBlobProvider
in 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:BlobDispatcher
Decides whichBlobProvider
to use to write the given blob, and whether the provider id should be added as prefix to the managed blob key.- Specified by:
getBlobProvider
in 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:BlobDispatcher
Notifies the blob dispatcher that a set of xpaths have changed on a document.- Specified by:
notifyChanges
in 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:BlobDispatcher
Notifies the blob dispatcher that the document was made a record.- Specified by:
notifyMakeRecord
in interfaceBlobDispatcher
- Parameters:
doc
- the document
-
notifyAfterCopy
public void notifyAfterCopy(Document doc)
Description copied from interface:BlobDispatcher
Notifies the blob dispatcher that the document has been copied.- Specified by:
notifyAfterCopy
in interfaceBlobDispatcher
- Parameters:
doc
- the new document, the result of the copy
-
notifyBeforeRemove
public void notifyBeforeRemove(Document doc)
Description copied from interface:BlobDispatcher
Notifies the blob dispatcher that the document is about to be removed.- Specified by:
notifyBeforeRemove
in interfaceBlobDispatcher
- Parameters:
doc
- the document
-
deleteBlobIfRecord
protected void deleteBlobIfRecord(String blobProviderId, Document doc, String xpath)
-
isUseRepositoryName
public boolean isUseRepositoryName()
- Specified by:
isUseRepositoryName
in interfaceBlobDispatcher
- Returns:
- true if the blobs are dispatched to the provider with the same name than the repository.
-
-