Class MailEventActivityHandler
- java.lang.Object
-
- de.aristaflow.adept2.core.eventmanager.common.AbstractEventHandler
-
- de.aristaflow.adept2.core.eventmanager.common.AbstractActivityEventHandler
-
- de.aristaflow.adept2.core.eventmanager.mailevents.MailEventActivityHandler
-
- All Implemented Interfaces:
ActivityEventHandler
,EventHandler
@ConfigurationDescription(properties={@Property(name="IsCritical",type=BOOLEAN,defaultValue="true",description="Whether the event handler is critical and problems handling the event should abort all handling of the current event."),,,,}) public class MailEventActivityHandler extends AbstractActivityEventHandler
An event handler for mail events, that stores data from an occurred mail event as output parameter in the data context of the corresponding activity.
This event handler considers a handled mail event as consumed since the corresponding activity has been terminated.This implementation is robust with respect to invalid parameter configurations and conversions, that is a parameter configuration referring to an unknown field of the mail or failing value conversions are just logged. The activity will be terminated normally but in case of a mandatory output parameter this will fail the activity.
-
-
Field Summary
Fields Modifier and Type Field Description protected File
fileStore
The configured file store path, used for providing the mail content as file URI to the started process ornull
in case no files should be stored.static long
HANDLER_MAIL_INVALID_DATA_TYPE_EXCEPTION_CODE
Code for an output parameter having an inappropriate type.static String
HANDLER_MAIL_INVALID_DATA_TYPE_EXCEPTION_STATE
State for an output parameter having an inappropriate type.static long
HANDLER_MAIL_IO_EXCEPTION_CODE
Code for creating UDT values based on the message fields or content fails.static String
HANDLER_MAIL_IO_EXCEPTION_STATE
State for creating UDT values based on the message fields or content fails.static long
HANDLER_MAIL_MESSAGING_EXCEPTION_CODE
Code for retrieving fields from the message fails.static String
HANDLER_MAIL_MESSAGING_EXCEPTION_STATE
State for retrieving fields from the message fails.static String
PAC_MAIL_EVENT_FIELD
Parameter activity configuration: the field of the mail to be stored, e.gMailTools.PARAM_BODY
.static String
PAC_MAIL_EVENT_REGEX
Parameter activity configuration: a regular expression for picking some data out of the message body and store it to the parameter.static String
PAC_MAIL_EVENT_REGEX_GROUP
Parameter activity configuration: the matching group ofPAC_MAIL_EVENT_REGEX
to be used for getting the data from the matched regex.static String
PARAM_AC_PREFIX
Prefix for our configuration values in the parameter's activity configuration.-
Fields inherited from class de.aristaflow.adept2.core.eventmanager.common.AbstractActivityEventHandler
contexts, eventManager
-
Fields inherited from class de.aristaflow.adept2.core.eventmanager.common.AbstractEventHandler
consuming, critical, exclusive, id, interruptible, logger
-
-
Constructor Summary
Constructors Constructor Description MailEventActivityHandler(org.apache.commons.configuration2.Configuration conf, ActivityEventManager eventManager, Registry registry)
Creates a new handler for mail events that starts or resumes activities and stores data from the mail in their output data context.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
canHandle(Event event, boolean consumed)
Gets whether the designated event can be handled by this (sub-)class.protected void
handleField(String field, Parameter param, MailEvent event, ActivityData data)
Gets the designated field from the message of the designated mail event and stores the value for the output parameter in the designated data context.protected void
handleRegEx(String regex, Parameter param, MailEvent event, ActivityData data)
Applies the designated regular expression to (the string representation of) the content of the message of the designated mail event and stores the match for the output parameter in the designated data context.protected boolean
processEvent(Event event, ActivityInstance activity, DataContext dataContext)
Processes the designated event for the designated activity instance.-
Methods inherited from class de.aristaflow.adept2.core.eventmanager.common.AbstractActivityEventHandler
close, handleEvent, init, kill, remove, reset, signal, suspend
-
Methods inherited from class de.aristaflow.adept2.core.eventmanager.common.AbstractEventHandler
getID, isConsuming, isCritical, isExclusive, isInterruptible
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.aristaflow.adept2.model.events.handler.EventHandler
getID, isConsuming, isExclusive, isInterruptible
-
-
-
-
Field Detail
-
HANDLER_MAIL_MESSAGING_EXCEPTION_STATE
public static final String HANDLER_MAIL_MESSAGING_EXCEPTION_STATE
State for retrieving fields from the message fails.- See Also:
- Constant Field Values
-
HANDLER_MAIL_MESSAGING_EXCEPTION_CODE
public static final long HANDLER_MAIL_MESSAGING_EXCEPTION_CODE
Code for retrieving fields from the message fails.- See Also:
- Constant Field Values
-
HANDLER_MAIL_IO_EXCEPTION_STATE
public static final String HANDLER_MAIL_IO_EXCEPTION_STATE
State for creating UDT values based on the message fields or content fails.- See Also:
- Constant Field Values
-
HANDLER_MAIL_IO_EXCEPTION_CODE
public static final long HANDLER_MAIL_IO_EXCEPTION_CODE
Code for creating UDT values based on the message fields or content fails.- See Also:
- Constant Field Values
-
HANDLER_MAIL_INVALID_DATA_TYPE_EXCEPTION_STATE
public static final String HANDLER_MAIL_INVALID_DATA_TYPE_EXCEPTION_STATE
State for an output parameter having an inappropriate type.- See Also:
- Constant Field Values
-
HANDLER_MAIL_INVALID_DATA_TYPE_EXCEPTION_CODE
public static final long HANDLER_MAIL_INVALID_DATA_TYPE_EXCEPTION_CODE
Code for an output parameter having an inappropriate type.- See Also:
- Constant Field Values
-
PARAM_AC_PREFIX
public static final String PARAM_AC_PREFIX
Prefix for our configuration values in the parameter's activity configuration.- See Also:
- Constant Field Values
-
PAC_MAIL_EVENT_FIELD
public static final String PAC_MAIL_EVENT_FIELD
Parameter activity configuration: the field of the mail to be stored, e.gMailTools.PARAM_BODY
.- See Also:
- Constant Field Values
-
PAC_MAIL_EVENT_REGEX
public static final String PAC_MAIL_EVENT_REGEX
Parameter activity configuration: a regular expression for picking some data out of the message body and store it to the parameter.- See Also:
- Constant Field Values
-
PAC_MAIL_EVENT_REGEX_GROUP
public static final String PAC_MAIL_EVENT_REGEX_GROUP
Parameter activity configuration: the matching group ofPAC_MAIL_EVENT_REGEX
to be used for getting the data from the matched regex. Defaults to group 1.- See Also:
- Constant Field Values
-
fileStore
protected final File fileStore
The configured file store path, used for providing the mail content as file URI to the started process ornull
in case no files should be stored.
-
-
Constructor Detail
-
MailEventActivityHandler
public MailEventActivityHandler(org.apache.commons.configuration2.Configuration conf, ActivityEventManager eventManager, Registry registry) throws ConfigurationException
Creates a new handler for mail events that starts or resumes activities and stores data from the mail in their output data context.- Parameters:
conf
- The configuration for this plugin instance.eventManager
- The event manager for communicating with the runtime service.registry
- The registry for retrieving the plugin instance name (handler ID).- Throws:
ConfigurationException
- If there are problems creating the configured file store or writing to it, aConfigurationException
will be thrown.
-
-
Method Detail
-
canHandle
protected boolean canHandle(Event event, boolean consumed)
Description copied from class:AbstractActivityEventHandler
Gets whether the designated event can be handled by this (sub-)class. This should for instance check for the event type as well as whether consumed events can be handled.- Specified by:
canHandle
in classAbstractActivityEventHandler
- Parameters:
event
- The event which is about to be handled.consumed
- Whether the event has been consumed by a previous event handler.- Returns:
- Whether the event has been consumed (that is changed) while
handling it. If the event has been consumed before the current
handing, it will have to remain consumed (implementations must
return
true
).
-
processEvent
protected boolean processEvent(Event event, ActivityInstance activity, DataContext dataContext)
Description copied from class:AbstractActivityEventHandler
Processes the designated event for the designated activity instance. Usually this requires setting the output parameters in the designated data context appropriately based on the event.- Specified by:
processEvent
in classAbstractActivityEventHandler
- Parameters:
event
- The event to be processed.activity
- The activity for which to process event. This also provides the configuration of the activity and also the defined output parameters.dataContext
- The data context to write the values of the output parameters to.- Returns:
- Whether the event has been consumed (that is changed) while
handling it. If the event has been consumed before the current
handing, it will have to remain consumed (implementations must
return
true
). - Throws:
ApplicationFailedException
- If- one of the designated parameter has an inappropriate type with respect to the data context or its user-defined type is not valid for the corresponding field,
- one of the designated parameter does not exist in the data context,
- there are problems serialising fields of the message or retrieving content, or
- there are problems retrieving the message content or its fields
ApplicationFailedException
will be thrown.
-
handleField
protected void handleField(String field, Parameter param, MailEvent event, ActivityData data) throws IOException, javax.mail.MessagingException
Gets the designated field from the message of the designated mail event and stores the value for the output parameter in the designated data context. Some fields can be stored with different types, for instance the addresses of the message or its attachments. The type depends on the data type of the parameter.
This method is fail-safe with respect to configuration problems, that is the designated field referring to an unknown field will just be logged. In consequence this may lead to undefined output parameter values which in turn will fail the activity if such a parameter is mandatory.- Parameters:
field
- The field which to retrieve from the message.param
- The output parameter for which to retrieve the value.event
- The mail event that is currently being handled.data
- The activity data in which to store the determined value of the output parameter.- Throws:
IOException
- If there are problems serialising fields of the message or retrieving content, anIOException
will be thrown.javax.mail.MessagingException
- If there are problems retrieving the message content or its fields, aMessagingException
will be thrown.
-
handleRegEx
protected void handleRegEx(String regex, Parameter param, MailEvent event, ActivityData data) throws javax.mail.MessagingException, IOException
Applies the designated regular expression to (the string representation of) the content of the message of the designated mail event and stores the match for the output parameter in the designated data context. The match of the regular expression is converted to the data type of the parameter.
This method is fail-safe with respect to problems occurring when converting, that is these problems are logged but ignored. In consequence this may lead to undefined output parameter values which in turn will fail the activity if such a parameter is mandatory.- Parameters:
regex
- The regular expression which to apply to (the string representation of) the message content.param
- The output parameter for which to retrieve the value with the regular expression.event
- The mail event that is currently being handled.data
- The activity data in which to store the determined value of the output parameter.- Throws:
javax.mail.MessagingException
- If there are problems retrieving the message content, aMessagingException
will be thrown.IOException
- If there are problems retrieving the body part content, anIOException
will be thrown.
-
-