-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
56 changed files
with
1,023 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...ow/src/main/java/net/savantly/nexus/flow/dom/destination/AbstractBaseDestinationHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package net.savantly.nexus.flow.dom.destination; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
import org.apache.causeway.applib.services.repository.RepositoryService; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
import net.savantly.nexus.flow.dom.destinationExecution.DestinationExecution; | ||
import net.savantly.nexus.flow.dom.flowContext.FlowContextFactory; | ||
import net.savantly.nexus.flow.dom.formMapping.Mapping; | ||
import net.savantly.nexus.flow.executor.javascript.JavascriptExecutor; | ||
|
||
@Log4j2 | ||
@RequiredArgsConstructor | ||
public abstract class AbstractBaseDestinationHook implements DestinationHook { | ||
|
||
private final FlowContextFactory flowContextFactory; | ||
private final JavascriptExecutor javascriptExecutor; | ||
private final RepositoryService repositoryService; | ||
|
||
public abstract DestinationHookResponse sendData(Destination destination, Map<String, Object> payload, | ||
Collection<? extends Mapping> formMappings); | ||
|
||
protected Map<String, Object> transformPayload(Destination destination, Map<String, Object> payload) { | ||
log.info("Transforming payload for destination {}", destination.getName()); | ||
var context = flowContextFactory.create(destination.getOrganization().getId()); | ||
context.setVariable("payload", payload); | ||
|
||
if (destination.getTransformScript() != null) { | ||
try { | ||
var result = javascriptExecutor.execute(destination.getTransformScript(), context); | ||
log.info("Transform script result type: {}", result.getClass()); | ||
} catch (Exception e) { | ||
log.error("Failed to execute transform script", e); | ||
throw new IllegalArgumentException("Failed to execute transform script. " + e.getMessage()); | ||
} | ||
} | ||
return payload; | ||
} | ||
|
||
@Override | ||
public DestinationHookResponse execute(Destination destination, Map<String, Object> payload, | ||
Collection<? extends Mapping> formMappings) { | ||
|
||
var transformedPayload = transformPayload(destination, payload); | ||
|
||
var result = sendData(destination, transformedPayload, formMappings); | ||
var executionAudit = DestinationExecution.withResult(destination, result.isSuccess(), result.getMessage()); | ||
|
||
repositoryService.persist(executionAudit); | ||
|
||
return result; | ||
} | ||
|
||
} |
Oops, something went wrong.