Skip to content

Commit

Permalink
Merge pull request #66 from infor-cloud/UpdatedExamples
Browse files Browse the repository at this point in the history
Removed 'def' from examples, using correct types instead
  • Loading branch information
filiphakansson1 authored Dec 5, 2023
2 parents 9e88341 + 18f30b9 commit 766a53c
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 95 deletions.
48 changes: 24 additions & 24 deletions docs/documentation/api-specification/ion-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,23 @@ This method performs a POST request and returns an ION Response object.
```groovy
@Override
void main() {
def endpoint = "/IONAttachment/supportedfile/list"
def headers = ["Accept": "application/json"]
def queryParameters = (Map)null // define as map if there are any query parameters e.g. ["name1": "value1", "name2": "value2"]
def formParameters = (Map)null // post URL encoded parameters
IonResponse response = ion.post(endpoint, headers, queryParameters, formParameters)
String endpoint = "/IONAttachment/supportedfile/list";
Map<String, String> headers = ["Accept": "application/json"];
Map<String, String> queryParameters = (Map)null; // define as map if there are any query parameters e.g. ["name1": "value1", "name2": "value2"]
Map<String, String> formParameters = (Map)null; // post URL encoded parameters
IonResponse response = ion.post(endpoint, headers, queryParameters, formParameters);
if (response.getError()) {
logger.debug("Failed calling ION API, detailed error message: ${response.getErrorMessage()}")
logger.debug("Failed calling ION API, detailed error message: ${response.getErrorMessage()}");
return
}
if (response.getStatusCode() != 200) {
logger.debug("Expected status 200 but got ${response.getStatusCode()} instead")
logger.debug("Expected status 200 but got ${response.getStatusCode()} instead");
return
}
String content = response.getContent()
String content = response.getContent();
if (content != null) {
logger.debug("Expected content from the request but got no content")
logger.debug("Expected content from the request but got no content");
return
}
Expand All @@ -105,21 +105,21 @@ This method performs a GET request and returns an ION Response object.
```groovy
@Override
void main() {
def endpoint = "/IONAttachment/supportedfile/list"
def headers = ["Accept": "application/json"]
def queryParameters = (Map)null // define as map if there are any query parameters e.g. ["name1": "value1", "name2": "value2"]
IonResponse response = ion.get(endpoint, headers, queryParameters)
String endpoint = "/IONAttachment/supportedfile/list";
Map<String, String> headers = ["Accept": "application/json"];
Map<String, String> queryParameters = (Map)null; // define as map if there are any query parameters e.g. ["name1": "value1", "name2": "value2"]
IonResponse response = ion.get(endpoint, headers, queryParameters);
if (response.getError()) {
logger.debug("Failed calling ION API, detailed error message: ${response.getErrorMessage()}")
logger.debug("Failed calling ION API, detailed error message: ${response.getErrorMessage()}");
return
}
if (response.getStatusCode() != 200) {
logger.debug("Expected status 200 but got ${response.getStatusCode()} instead")
logger.debug("Expected status 200 but got ${response.getStatusCode()} instead");
return
}
String content = response.getContent()
String content = response.getContent();
if (content != null) {
logger.debug("Expected content from the request but got no content")
logger.debug("Expected content from the request but got no content");
return
}
```
Expand All @@ -129,10 +129,10 @@ This method performs a PUT request and returns an ION Response object.
```groovy
@Override
void main() {
def endpoint = "/IONAttachment/supportedfile/list"
def headers = ["Accept": "application/json"]
def queryParameters = (Map)null // define as map if there are any query parameters e.g. ["name1": "value1", "name2": "value2"]
def formParameters = (Map)null //
String endpoint = "/IONAttachment/supportedfile/list"
Map<String, String> headers = ["Accept": "application/json"]
Map<String, String> queryParameters = (Map)null // define as map if there are any query parameters e.g. ["name1": "value1", "name2": "value2"]
Map<String, String> formParameters = (Map)null //
IonResponse response = ion.put(endpoint, headers, queryParameters, formParameters)
if (response.getError()) {
logger.debug("Failed calling ION API, detailed error message: ${response.getErrorMessage()}")
Expand All @@ -155,9 +155,9 @@ This method performs a DELETE request and returns an ION Response object.
```groovy
@Override
void main() {
def endpoint = "/IONAttachment/supportedfile/list"
def headers = ["Accept": "application/json"]
def queryParameters = (Map)null // define as map if there are any query parameters e.g. ["name1": "value1", "name2": "value2"]
String endpoint = "/IONAttachment/supportedfile/list"
Map<String, String> headers = ["Accept": "application/json"]
Map<String, String> queryParameters = (Map)null // define as map if there are any query parameters e.g. ["name1": "value1", "name2": "value2"]
IonResponse response = ion.delete(endpoint, headers, queryParameters)
if (response.getError()) {
logger.debug("Failed calling ION API, detailed error message: ${response.getErrorMessage()}")
Expand Down
25 changes: 7 additions & 18 deletions docs/documentation/api-specification/mi-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,11 @@ The MI API allows for reading input parameters and writing output parameters sen

## Features

### mi.in
### mi.inData
This method allows to get value from data container and containes In values for Transactions. Contained values are already converted to the proper type.
Takes string key as a parameter and returns value associeted with the key.

Example 1:
```groovy
def <T> Optional<T> getParameter(String name, Class<T> type) {
if (type == Double.class) {
String raw = mi.in.get(name)
if (raw == null || raw.trim().isEmpty()) {
return Optional.empty()
}
return Optional.of((mi.in.get(name) as Double) as T)
}
return Optional.empty()
}
```
<br>

Example 2:
Example:
```groovy
private String whlo;
private String itno;
Expand Down Expand Up @@ -166,17 +151,21 @@ boolean validateInput() {
if (!getWarehouse(whlo)){
mi.error("Warehouse " + whlo + " is invalid");
return false;
} else {
return true;
}
}
```
<br>

Example 2:
```groovy
def boolean validResponsible(String Responsible) {
boolean validResponsible(String Responsible) {
if (Responsible.isEmpty()){
mi.error("Responsible must be entered");
return false;
} else {
return true;
}
}
```
Expand Down
26 changes: 12 additions & 14 deletions docs/documentation/api-specification/micaller-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public class TestProgram extends ExtendM3Trigger {
public void main() {
String customer = null
def callback = {
Map<String, String> response ->
Closure<?> callback = { Map<String, String> response ->
logger.info("Response = ${response}")
if(response.CUNO != null){
customer = response.CUNO
Expand Down Expand Up @@ -87,14 +86,14 @@ public class TestProgram extends ExtendM3Trigger {
String DSPpostalcode = interactive.display.fields.WRPONO.toString();
String DSPtown = interactive.display.fields.WRTOWN.toString();
def params = [ "SQRY":"CUNM:${DSPname}~ AND CUA1:${DSPaddress} AND PONO:${DSPpostalcode} AND TOWN:{DSPtown}".toString() ] // toString is needed to convert from gstring to string
Map<String, String> params = [ "SQRY":"CUNM:${DSPname}~ AND CUA1:${DSPaddress} AND PONO:${DSPpostalcode} AND TOWN:{DSPtown}".toString() ] // toString is needed to convert from gstring to string
String customer = null
def callback = {
Map<String, String> response ->
logger.info("Response = ${response}")
if(response.CUNO != null){
customer = response.CUNO
}
Closure<?> callback = {
Map<String, String> response ->
logger.info("Response = ${response}")
if(response.CUNO != null){
customer = response.CUNO
}
}
miCaller.call("CRS610MI","SearchCustomer", params, callback)
Expand Down Expand Up @@ -129,9 +128,9 @@ public class TestProgram extends ExtendM3Trigger {
String DSPpostalcode = interactive.display.fields.WRPONO.toString();
String DSPtown = interactive.display.fields.WRTOWN.toString();
def params = [ "SQRY":"CUNM:${DSPname}~ AND CUA1:${DSPaddress} AND PONO:${DSPpostalcode} AND TOWN:{DSPtown}".toString() ] // toString is needed to convert from gstring to string
Map<String, String> params = [ "SQRY":"CUNM:${DSPname}~ AND CUA1:${DSPaddress} AND PONO:${DSPpostalcode} AND TOWN:{DSPtown}".toString() ] // toString is needed to convert from gstring to string
String customer = null
def callback = {
Closure<?> callback = {
Map<String, String> response ->
logger.info("Response = ${response}")
if(response.CUNO != null){
Expand Down Expand Up @@ -175,10 +174,9 @@ public class TestProgram extends ExtendM3Trigger {
String DSPpostalcode = interactive.display.fields.WRPONO.toString();
String DSPtown = interactive.display.fields.WRTOWN.toString();
def params = [ "SQRY":"CUNM:${DSPname}~ AND CUA1:${DSPaddress} AND PONO:${DSPpostalcode} AND TOWN:{DSPtown}".toString() ] // toString is needed to convert from gstring to string
Map<String, String> params = [ "SQRY":"CUNM:${DSPname}~ AND CUA1:${DSPaddress} AND PONO:${DSPpostalcode} AND TOWN:{DSPtown}".toString() ] // toString is needed to convert from gstring to string
String customer = null
def callback = {
Map<String, String> response ->
Closure<?> callback = { Map<String, String> response ->
logger.info("Response = ${response}")
if(response.CUNO != null){
customer = response.CUNO
Expand Down
9 changes: 7 additions & 2 deletions docs/documentation/api-specification/program-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The Program API contains APIs that can be used to get information from the curre
Returns the current user
<br>
Example:

```groovy
public class testProgram extends ExtendM3Trigger {
private final ProgramAPI program
Expand All @@ -49,9 +50,11 @@ public class testProgram extends ExtendM3Trigger {
}
}
```

### getTableRecord
To be able to retrieve a record from a specific table in the program
<br>

Example:
```groovy
public class TestProgram extends ExtendM3Trigger {
Expand All @@ -66,8 +69,8 @@ public class TestProgram extends ExtendM3Trigger {
}
public void main() {
def mitwhl = program.getTableRecord("MITWHL")
def whlo = mitwhl.MWWHLO
TableRecordAPI mitwhl = program.getTableRecord("MITWHL")
String whlo = mitwhl.MWWHLO
if (program.getUser() != "CRIUBA36") {
return
}
Expand All @@ -81,6 +84,7 @@ public class TestProgram extends ExtendM3Trigger {
To be able to retrieve fields mapped in LDAZD
<br>
Example:

```groovy
public class testProgram extends ExtendM3Trigger {
private final ProgramAPI program
Expand All @@ -107,6 +111,7 @@ public class testProgram extends ExtendM3Trigger {
To be able to retrieve field mapped in LDAZZ
<br>
Example:

```groovy
public class testProgram extends ExtendM3Trigger {
private final ProgramAPI program
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/Batch-extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public class batchTest extends ExtendM3Transaction {
Closure<?> callback = {Map<String, String> result ->
logger.info("Result is: ${result}");
}
def params = ["TX30": "CallingFromEXT919MI",
Map<String, String> params = ["TX30": "CallingFromEXT919MI",
"XCAT": "010".toString(),
"SCTY": "1".toString(),
"XNOW": "1".toString(),
Expand Down
65 changes: 31 additions & 34 deletions docs/examples/Templates/Transaction_Template.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,42 +43,40 @@ public class TransactionTemplate extends ExtendM3Transaction {
public void main() {
def callback = {
Map <String, String> out ->
if (out.error != null) {
mi.error(out.errorMessage);
return;
}
/* Setting up out data in transaction using MI API
Remove .trim on input fields as this causes errors if fields are null
*/
mi.outData.put("OUT1", out.get("OUT1").trim());
mi.outData.put("OUT2", out.get("OUT2").trim());
mi.outData.put("OUT3", out.get("OUT3").trim());
mi.outData.put("OUT4", out.get("OUT4").trim());
mi.outData.put("OUT5", out.get("OUT5").trim());
//Setting container parameters
String out6 = "";
String out7 = "";
if (out.get("OUT3").toInteger() == 3) {
DBAction query = database.table("CONT01")
.index("00")
.selection("OQOUT1","OQOUT2","OQOUT3","OQOUT4").build();
DBContainer CONT01 = query.getContainer();
CONT01.set("OQOUT1", out.get("OUT1").trim().toInteger());
CONT01.set("OQOUT2", 1);
CONT01.set("OQOUT3", out.get("OUT3").trim().toInteger());
}
mi.outData.put("OUT6", out6);
mi.outData.put("OUT7", out7);
mi.write();
Closure<?> callback = { Map <String, String> out ->
if (out.error != null) {
mi.error(out.errorMessage);
return;
}
/* Setting up out data in transaction using MI API
Remove .trim on input fields as this causes errors if fields are null
*/
mi.outData.put("OUT1", out.get("OUT1").trim());
mi.outData.put("OUT2", out.get("OUT2").trim());
mi.outData.put("OUT3", out.get("OUT3").trim());
mi.outData.put("OUT4", out.get("OUT4").trim());
mi.outData.put("OUT5", out.get("OUT5").trim());
//Setting container parameters
String out6 = "";
String out7 = "";
if (out.get("OUT3").toInteger() == 3) {
DBAction query = database.table("CONT01")
.index("00")
.selection("OQOUT1","OQOUT2","OQOUT3","OQOUT4").build();
DBContainer CONT01 = query.getContainer();
CONT01.set("OQOUT1", out.get("OUT1").trim().toInteger());
CONT01.set("OQOUT2", 1);
CONT01.set("OQOUT3", out.get("OUT3").trim().toInteger());
}
mi.outData.put("OUT6", out6);
mi.outData.put("OUT7", out7);
mi.write();
}
// Transaction In Data parametrers
def params = [ "OUT2": mi.inData.get("OUT2"),
Map<String, String> params = [ "OUT2": mi.inData.get("OUT2"),
"IND1": mi.inData.get("PAR1"),
"IND2": mi.inData.get("PAR2"),
"IND3": mi.inData.get("PAR3"),
Expand All @@ -87,7 +85,6 @@ public class TransactionTemplate extends ExtendM3Transaction {
];
miCaller.call("MWS420MI", "TransactionTemplate", params, callback);
}
}
```
## Important notes
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/use-cases/object-access-control.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public class AuthorityCheck extends ExtendM3Trigger {
method.setReturnValue(isUserAuthorizedToWarehouse(record.MWCSCD));
}
if (table == "MITBAL") {
def query = database.table("MITWHL").index("00").selection("MWCSCD").build();
def container = query.createContainer();
DBAction query = database.table("MITWHL").index("00").selection("MWCSCD").build();
DBContainer container = query.createContainer();
container.set("MWCONO", program.LDAZD.CONO);
container.set("MWWHLO", record.MBWHLO);
if (query.read(container)) {
Expand Down

0 comments on commit 766a53c

Please sign in to comment.