-
Notifications
You must be signed in to change notification settings - Fork 8
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
10 changed files
with
360 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions | ||
name: sync-and-deploy | ||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- devtober-demo | ||
|
||
jobs: | ||
# Unit test | ||
unit_test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-java@v4 | ||
with: | ||
java-version: '8' | ||
distribution: 'temurin' | ||
- name: 'Local unit test with Maven' | ||
run: mvn clean test | ||
|
||
# Sync designtime artifact to tenant | ||
sync: | ||
runs-on: ubuntu-latest | ||
needs: unit_test | ||
container: | ||
image: engswee/flashpipe:latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: 'Update/Upload DemoFlow to design time' | ||
uses: engswee/flashpipe-action/sync@v1 | ||
with: | ||
tmn-host: equaliseit.it-cpi023.cfapps.eu20-001.hana.ondemand.com | ||
oauth-host: equaliseit.authentication.eu20.hana.ondemand.com | ||
oauth-clientid: ${{ secrets.DEV_CLIENT_ID }} | ||
oauth-clientsecret: ${{ secrets.DEV_CLIENT_SECRET }} | ||
target: tenant | ||
package-id: FlashPipeDemo | ||
|
||
# Deploy to runtime | ||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: sync | ||
container: | ||
image: engswee/flashpipe:latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: 'Deploy DemoFlow to runtime' | ||
uses: engswee/flashpipe-action/deploy@v1 | ||
with: | ||
tmn-host: equaliseit.it-cpi023.cfapps.eu20-001.hana.ondemand.com | ||
oauth-host: equaliseit.authentication.eu20.hana.ondemand.com | ||
oauth-clientid: ${{ secrets.DEV_CLIENT_ID }} | ||
oauth-clientsecret: ${{ secrets.DEV_CLIENT_SECRET }} | ||
artifact-ids: DemoFlow |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.equaliseit</groupId> | ||
<artifactId>flashpipe-demo</artifactId> | ||
<version>1.0.0</version> | ||
</parent> | ||
|
||
<artifactId>DemoFlow</artifactId> | ||
<version>1.0.0</version> | ||
|
||
</project> |
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
37 changes: 37 additions & 0 deletions
37
DemoFlow/src/main/resources/script/XMLTransformation.groovy
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,37 @@ | ||
import com.sap.gateway.ip.core.customdev.util.Message | ||
import com.sap.it.api.ITApiFactory | ||
import com.sap.it.api.mapping.ValueMappingApi | ||
import groovy.xml.MarkupBuilder | ||
|
||
import java.text.SimpleDateFormat | ||
|
||
def Message processData(Message message) { | ||
Reader reader = message.getBody(Reader) | ||
def Order = new XmlSlurper().parse(reader) | ||
Writer writer = new StringWriter() | ||
def builder = new MarkupBuilder(writer) | ||
|
||
def sourceDocType = message.getProperty('DocType') | ||
ValueMappingApi api = ITApiFactory.getService(ValueMappingApi, null) | ||
|
||
def items = Order.Item.findAll { it.Valid.text() == 'true' } | ||
builder.PurchaseOrder { | ||
'Header' { | ||
'ID' Order.Header.OrderNumber | ||
'DocumentDate' new SimpleDateFormat('yyyy-MM-dd').format(new SimpleDateFormat('yyyyMMdd').parse(Order.Header.Date.text())) | ||
if (!items.size()) | ||
'DocumentType' api.getMappedValue('S4', 'DocType', sourceDocType, 'ACME', 'DocumentType') | ||
} | ||
|
||
items.each { item -> | ||
'Item' { | ||
'ItemNumber' item.ItemNumber.text().padLeft(3, '0') | ||
'ProductCode' item.MaterialNumber | ||
'Quantity' item.Quantity | ||
} | ||
} | ||
} | ||
|
||
message.setBody(writer.toString()) | ||
return message | ||
} |
This file was deleted.
Oops, something went wrong.
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,61 @@ | ||
import com.sap.gateway.ip.core.customdev.util.Message | ||
import com.sap.it.api.mapping.ValueMappingApi | ||
import spock.lang.Shared | ||
import spock.lang.Specification | ||
|
||
class XMLTransformationSpec extends Specification { | ||
@Shared | ||
Script script | ||
Message msg | ||
|
||
def setupSpec() { | ||
GroovyShell shell = new GroovyShell() | ||
script = shell.parse(this.getClass().getResource('/script/XMLTransformation.groovy').toURI()) | ||
} | ||
|
||
def setup() { | ||
msg = new Message() | ||
} | ||
|
||
def 'Scenario 1 - Order has items'() { | ||
given: 'the message body is initialized' | ||
msg.setBody(this.getClass().getResource('input1.xml').newInputStream()) | ||
|
||
when: 'we execute the Groovy script' | ||
script.processData(msg) | ||
|
||
then: 'the output message body is as expected' | ||
def root = new XmlSlurper().parse(msg.getBody(Reader)) | ||
verifyAll { | ||
root.Header.ID.text() == 'ORD60001' | ||
root.Header.DocumentDate.text() == '2019-02-18' | ||
root.Header.DocumentType.text() == '' | ||
root.Item.size() == 1 | ||
root.Item.ItemNumber.text() == '010' | ||
root.Item.ProductCode.text() == 'MT70001' | ||
root.Item.Quantity.text() == '57' | ||
} | ||
} | ||
|
||
def 'Scenario 2 - Order does not have items'() { | ||
given: 'the message body and property are initialized' | ||
msg.setBody(this.getClass().getResource('input2.xml').newInputStream()) | ||
msg.setProperty('DocType', 'HDR') | ||
|
||
// Set up value mapping entries | ||
ValueMappingApi vmapi = ValueMappingApi.getInstance() | ||
vmapi.addEntry('S4', 'DocType', 'HDR', 'ACME', 'DocumentType', 'ACME-HDR') | ||
|
||
when: 'we execute the Groovy script' | ||
script.processData(msg) | ||
|
||
then: 'the output message body is as expected' | ||
def root = new XmlSlurper().parse(msg.getBody(Reader)) | ||
verifyAll { | ||
root.Header.ID.text() == 'ORD80002' | ||
root.Header.DocumentDate.text() == '2020-02-18' | ||
root.Header.DocumentType.text() == 'ACME-HDR' | ||
root.Item.size() == 0 | ||
} | ||
} | ||
} |
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,18 @@ | ||
<Order> | ||
<Header> | ||
<OrderNumber>ORD60001</OrderNumber> | ||
<Date>20190218</Date> | ||
</Header> | ||
<Item> | ||
<ItemNumber>10</ItemNumber> | ||
<MaterialNumber>MT70001</MaterialNumber> | ||
<Quantity>57</Quantity> | ||
<Valid>true</Valid> | ||
</Item> | ||
<Item> | ||
<ItemNumber>20</ItemNumber> | ||
<MaterialNumber>MT80001</MaterialNumber> | ||
<Quantity>28</Quantity> | ||
<Valid>false</Valid> | ||
</Item> | ||
</Order> |
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,12 @@ | ||
<Order> | ||
<Header> | ||
<OrderNumber>ORD80002</OrderNumber> | ||
<Date>20200218</Date> | ||
</Header> | ||
<Item> | ||
<ItemNumber>10</ItemNumber> | ||
<MaterialNumber>MT90001</MaterialNumber> | ||
<Quantity>55</Quantity> | ||
<Valid>false</Valid> | ||
</Item> | ||
</Order> |
Oops, something went wrong.