Skip to main content
All CollectionsWorkspaces
Using Custom Subscriptions
Using Custom Subscriptions

Leveraging Spring Expression Language (SpEL) for Custom Subscriptions in Kodexa

Updated over a week ago

In the Kodexa platform, managing and filtering documents effectively is crucial for maintaining data integrity and relevance. One of the powerful ways to achieve this is by using custom subscriptions defined through Spring Expression Language (SpEL). SpEL provides a robust mechanism to specify complex conditions for selecting documents, enhancing your ability to manage and process documents based on your specific needs.

Understanding Spring Expression Language (SpEL)

Spring Expression Language (SpEL) is a powerful expression language that supports querying and manipulation of objects at runtime. It is a part of the Spring Framework and allows for dynamic evaluation of expressions.

For Kodexa users, SpEL can be used to create custom subscriptions that determine whether a document meets certain criteria.

Sample SpEL Expressions for Kodexa Subscriptions

Below are some examples of how you can use SpEL expressions to define custom subscriptions in Kodexa:

  1. Check for Specific Key and Value from the Metadata

    Expression:

    containsKey('ShouldProcessXML') && ['ShouldProcessXML'].toLowerCase() != 'true'

    Description: This expression is used to identify documents that contain the key ShouldProcessXML but do not have its value set to true. It’s useful when you need to filter out documents that are marked for processing but are not flagged as true.

  2. Exclude Documents with Specific Mixins

    Expression:

    !hasMixins('spatial')

    Description: This expression filters out documents that have the mixin spatial. The ! operator negates the condition, meaning only documents without the spatial mixin will be included.

  3. Include Documents with a Specific Label

    Expression:

    hasLabel('PARSED')

    Description: This expression is used to include documents that are labeled with PARSED. It’s ideal for processing documents that have been successfully parsed.

  4. Complex Subscription with Multiple Labels

    Expression:

    hasLabel('MODEL-APPLIED') && !hasLabel('DONT_PUBLISH')

    Description: This expression includes documents that have the label MODEL-APPLIED but excludes those with the label DONT_PUBLISH. It’s useful for scenarios where documents that are marked for publication but not flagged for exclusion should be processed.

Implementing SpEL Expressions in Kodexa

To utilize these SpEL expressions within Kodexa:

  1. Define Your Subscription:

    • Navigate to the subscription management section in Kodexa.

    • Create a new subscription and enter your desired SpEL expression in the provided field.

  2. Apply Your Subscription:

    • Once defined, Kodexa will use your expression to filter documents as they are added to the Document store.

    • Ensure your expressions are tested and validated to confirm they meet your criteria.

  3. Monitor and Adjust:

    • Regularly review the performance of your subscriptions and adjust the SpEL expressions as necessary to refine document selection.

Conclusion

Using Spring Expression Language for custom subscriptions in Kodexa provides a powerful way to control document management based on dynamic and complex conditions. By leveraging SpEL, you can tailor your document handling processes to meet specific requirements and ensure efficient data processing.

For more details on SpEL and its capabilities, refer to the Spring Framework documentation.

If you have any questions or need assistance with creating or managing your SpEL-based subscriptions in Kodexa, feel free to reach out to our support team.

Happy document processing!


This article should give Kodexa users a clear understanding of how to use SpEL for custom subscriptions, complete with practical examples and implementation guidance.

Did this answer your question?