Create Contactor with paramater for ExternalAction - rule-engine

How I can create Contactor in code effect for ExternalAction ,
I have this code
[ExternalAction(typeof(Service), "SendEmail")]
And I want send email when success Evaluate but without write send code in SendEmail, I want use call interface to send it , like this
private readonly IEmailService email;
public Service(IEmailService emailService)
{
email = emailService;
}
[Action("Send Email", "Send Email to Someone")]
public void SendEmail(Rule Rule, [Parameter(ValueInputType.User, Description = "Output message", DataSourceName = "UserList")] int userId)
{
email.sene(userId);
}

You are trying to use the instance action method. For the engine to be able to invoke such a method it needs to instantiate your type. Your Service class doesn't have an empty (parameterless/default) constructor. Obviously, the engine won't have an instance of your EmailService at evaluation time. Therefore, it can't invoke your instance method. Either add a default constructor to your Service class and find another way to pass EmailService to the Service class or use a static method with value type parameters.

Related

How can I access to the acknowledge entity in spring cloud sqs without setting custom argument resolvers?

In order to have access to events like S3EventNotification we need to specify a custom argument resolver in in the QueueMessageHandlerFactory. But since the order in which those argument resolver are evaluated matters it forces me to have a list that has every argument resolver twice. Is it possible to avoid this?
I am trying to read from a queue where events are generated by amazon itself.
In this case I need to set
messageConverter.setStrictContentTypeMatch(false);
as explained here: https://cloud.spring.io/spring-cloud-aws/1.2.x/multi/multi__messaging.html#_consuming_aws_event_messages_with_amazon_sqs
In the method however I needed to use Acknowledge, Visibility, and header method parameters but those were not passed correctly unless I redefine all the possible argument resolver in the configuration.
So to have the following method signature:
#SqsListener(value = "${my-queue-name}", deletionPolicy = NEVER)
public void processRequest(
#Payload S3EventNotification s3EventNotificationRecord,
#Header("ApproximateReceiveCount") final int receiveCount,
Acknowledgment acknowledgment,
Visibility visibility) {
// do some stuff and decide to acknowledge or extend visibility
}
I was forced to write this custom configuration like:
#Configuration
public class AmazonSQSConfig {
private static final String ACKNOWLEDGMENT = "Acknowledgment";
private static final String VISIBILITY = "Visibility";
#Bean
public QueueMessageHandlerFactory queueMessageHandlerFactory() {
QueueMessageHandlerFactory factory = new QueueMessageHandlerFactory();
factory.setArgumentResolvers(initArgumentResolvers());
return factory;
}
private List<HandlerMethodArgumentResolver> initArgumentResolvers() {
MappingJackson2MessageConverter messageConverter = new MappingJackson2MessageConverter();
messageConverter.setStrictContentTypeMatch(false);
return List.of(
new HeaderMethodArgumentResolver(null, null),
new HeadersMethodArgumentResolver(),
new NotificationSubjectArgumentResolver(),
new AcknowledgmentHandlerMethodArgumentResolver(ACKNOWLEDGMENT),
new VisibilityHandlerMethodArgumentResolver(VISIBILITY),
new PayloadArgumentResolver(messageConverter));
}
}
I would expect to have a way to define a custom argument resolver but still have all the argument passed to the method once executed.

Get SalesFormLetter class from SalesEditLines form formRun using PreHandler AX7

I need to make some changes on closeOk of SalesEditLines form. As I know, I am not able to change the standard methods, so I need to create an event handler for closeOk.
[PreHandlerFor(formStr(SalesEditLines), formMethodStr(SalesEditLines, closeOk))]
public static void SalesEditLines_Pre_closeOk(XppPrePostArgs args)
{
FormRun sender = args.getThis() as FormRun;
Object callerObject = sender.args().caller();
}
The question is - how can i access a SalesFormLetter through SalesEditLines form formRun using PreHandler?
You can see the following line in init method of SalesEditLines form
salesFormLetter = element.args().caller();
So your callerObject is an instance of SalesFormLetter class, you need just cast it to proper type.
Please check the following link:
https://learn.microsoft.com/en-us/dynamicsax-2012/developer/expression-operators-is-and-as-for-inheritance

Getting method name related to a rest service

I wanted to know if there exist a way of retrieving the actual method name associated to a rest service provided. Lets suppose my url is http://localhost:8080/v1/mytesturl now i want to retrieve the actual method name that is associated with this url.
Actually we are maintaining some key/value pair specific to the method that we have created and i need to make some checks based on the method name that gets executed using these values.
Plz let me know if there exist some way to do that..
Simply get the method name from the Object class.
#RestController
#RequestMapping("")
public class HomeController {
#RequestMapping("/mytesturl")
#ResponseBody
public String getMethodName() {
return new Object(){}.getClass().getEnclosingMethod().getName();
}
}
i got the solution by using this
Map<RequestMappingInfo, HandlerMethod> handlerMethods = RequestMappingHandlerMapping.getHandlerMethods();
HandlerExecutionChain handler = RequestMappingHandlerMapping.getHandler(requestr);
HandlerMethod handler1 = null;
if(Objects.nonNull(handler)){
handler1 = (HandlerMethod) handler.getHandler();
handler1.getMethod().getName()
}
this provide me with what i wanted..

Using a Mailable instead of a MailMessage for password reset emails in Laravel 5.5

I'd like my application to use Mailables for all of the emails it sends, so I created my own ResetPasswordEmail class that extends Mailable. Then I created my own ResetPassword notification class that extends the vendor class of the same name and overrode the toMail method as follows:
public function toMail($notifiable)
{
return (new ResetPasswordEmail())->with('token', $this->token);
}
Then I overrode the sendPasswordResetNotification from the CanResetPassword trait in my User model like this:
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPassword($token));
}
Calling my custom ResetPassword notification class.
The problem is that if I use the default method of creating a MailMessage and sending it, it automatically populates the 'to' field with the user's email. But when I use my ResetPasswordEmail mailable class, it doesn't.
Is there a good way to get it to work like that with my custom mailable?
Well in the end I just set the "to" field for my Mailable instance like this:
public function toMail($notifiable)
{
return (new ResetPasswordEmail())->with('token', $this->token)->to($notifiable->email);
}
Since $notifiable is an instance of the User model in this case, I can get the email like that. I don't know if this is the best way to do it, but it works.

vertx 2: vertx.eventBus().send(ClassName.ADDRESS, ....) why does it init a new class?

I work on a project based on Vertx the following line:
vertx.eventBus().send(MyClass.ADDRESS, requestBody, new Handler<Message<Object>>() {
....
}
public class MyClass implements Handler<Message<JsonObject>> {
public static final String ADDRESS = "coupons.api.manager";
...
#Override
public void handle(Message<JsonObject> msg) {
...
}
}
Whereas MyClass.ADDRESS is a static field of type string in the class MyClass, I found out that the line vertx.eventBus(...) creates an object of MyClass and then runs the handle() function.
My question is why? MyClass.ADDRESS is a string, and a static one. How does vertx "know" that it has to create an object from a class that this string is an attribute of?
I looked at the documentation of the send() function: http://vertx.io/docs/apidocs/io/vertx/core/eventbus/EventBus.html#send-java.lang.String-java.lang.Object-io.vertx.core.eventbus.DeliveryOptions-io.vertx.core.Handler-
and it says that the first argument in the function is "the address to send it to". OK. But, who said that the address means instantiating this class?
I made a small research, and yes. Vertx, behind the curtains, connects all the classes that implement Handler> to the string value they have in the attribute ClassName.ADDRESS.
When the statement:
vertx.eventBus().send(MyClass.ADDRESS, requestBody, new Handler<Message<Object>>() {
....
}
is invoked, a new thread is created and runs the handle method in the class MyClass.