Skip to content

Commit

Permalink
adds button to manually trigger destination on form submission
Browse files Browse the repository at this point in the history
  • Loading branch information
jdbranham committed Oct 21, 2024
1 parent 59384f9 commit 30c1d30
Showing 1 changed file with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package net.savantly.nexus.flow.dom.formSubmission;

import java.util.List;

import org.apache.causeway.applib.annotation.Action;
import org.apache.causeway.applib.annotation.ActionLayout;
import org.apache.causeway.applib.annotation.MemberSupport;
import org.apache.causeway.applib.annotation.PriorityPrecedence;
import org.apache.causeway.applib.annotation.PromptStyle;
import org.apache.causeway.applib.annotation.Publishing;
import org.apache.causeway.applib.annotation.SemanticsOf;
import org.apache.causeway.applib.services.message.MessageService;

import com.fasterxml.jackson.databind.ObjectMapper;

import jakarta.inject.Inject;
import lombok.extern.log4j.Log4j2;
import net.savantly.nexus.flow.dom.destination.Destination;
import net.savantly.nexus.flow.dom.destination.DestinationHookFactory;
import net.savantly.nexus.flow.dom.form.FormSubmissionProxy;

@Log4j2
@jakarta.annotation.Priority(PriorityPrecedence.EARLY)
@Action(semantics = SemanticsOf.NON_IDEMPOTENT, commandPublishing = Publishing.ENABLED, executionPublishing = Publishing.ENABLED)
@ActionLayout(promptStyle = PromptStyle.DIALOG, associateWith = "payload")
@lombok.RequiredArgsConstructor(onConstructor_ = { @Inject })
public class FormSubmission_triggerDestination {

final FormSubmission object;

public static class ActionEvent
extends
org.apache.causeway.applib.CausewayModuleApplib.ActionDomainEvent<FormSubmission_triggerDestination> {
}

@Inject
MessageService messageService;
@Inject
DestinationHookFactory destinationHookFactory;
@Inject
ObjectMapper objectMapper;
@Inject
FormSubmissionProxy formSubmissionProxy;

@MemberSupport
public FormSubmission act(
final Destination destination) {

try {
formSubmissionProxy.triggerDestinationForSubmission(object, destination.getId());
messageService.informUser("Hook executed successfully: " + destination.getName());

} catch (Exception e) {
messageService.raiseError("Failed to execute destination hook: " + e.getMessage());
}

return object;
}

@MemberSupport
public List<Destination> choices0Act() {
return object.getForm().getDestinations().stream().toList();
}

}

0 comments on commit 30c1d30

Please sign in to comment.