Commit a9395f0c authored by Alzhan Turlybekov's avatar Alzhan Turlybekov
Browse files

updates to 4.1 for 11 and 12 tuts. WIP

parent f8daf2bd
......@@ -22,6 +22,8 @@ version: "1.0"
code: BBM_CreateOrder-v1.0.qclass
config-items:
- name: create-workflow-order-mapper
value:
"- asd - asdd"
default_value:
null
config_group: Create Workflow Order
......
......@@ -11,11 +11,11 @@ classes:
groups:
- BASIC-TRAINING-EXCHANGE-APP
lang: qore
mappers:
- exchange-currency-api-mapper:1.0
autostart: true
version: "1.0"
servicetype: USER
mappers:
- exchange-currency-api-mapper:1.0
code: basics-exchange-currency-api-service-1.0.qsd
class-connections:
Connection_1:
......
# -*- mode: qore; indent-tabs-mode: nil -*-
#
# Qorus Integration Engine
%new-style
%strict-args
%require-types
%enable-all-warnings
our string format_version = "2.6";
our hash<auto> groups."BASIC-TRAINING-EXCHANGE-APP".desc = "Basic training exchange application objects";
const steps = (
"class:BasicsChangeOrderStatusToInProgress:1.0",
(
"class:BasicsSendMoneyToBank:1.0",
("class:BasicsSendMoneyToUser:1.0", "class:BasicsSendEmailToUser:1.0"),
),
"class:BasicsChangeOrderStatusToCompleted:1.0",
);
our hash<auto> workflows."BASICS-PROCESS-ORDERS-WORKFLOW"."1.0" = {
"desc" : "Processes given orders",
"author" : "Alzhan Turlybekov (Qore Technologies)",
"steps" : steps,
"keylist" : ("ids",),
"classes" : ("BasicsChangeOrderStatus",),
"constants" : ("exchange_rates_app_constants",),
"groups" : ("BASIC-TRAINING-EXCHANGE-APP",),
"autostart" : 1,
};
# name: BasicsChangeOrderStatusToCompleted
# version: 1.0
# desc: Changes the status of orders to completed
# author: Alzhan Turlybekov (Qore Technologies)
%strict-args
%require-types
%new-style
%enable-all-warnings
class BasicsChangeOrderStatusToCompleted inherits QorusNormalStep {
primary() {
DatasourcePool omquser_ds = getDatasourcePool("omquser");
on_success omquser_ds.commit();
on_error omquser_ds.rollback();
BasicsChangeOrderStatus::changeStatus(omquser_ds, "completed");
}
}
# END
# -*- mode: qore; indent-tabs-mode nil -*-
# name: exchange_rates_app_constants
# version: 1.0
# desc: Defines constants for exchange rates application
# author: Alzhan Turlybekov (Qore Technologies)
%new-style
%require-types
%strict-args
%enable-all-warnings
namespace ExchangeRates {
# Commission is used to calculate the amount that will be sent to the bank
const COMMISSION = 0.05;
}
# END
\ No newline at end of file
# This is a generated file, don't edit!
type: workflow
name: BASICS-PROCESS-ORDERS-WORKFLOW-JAVA
desc: "Processes given orders"
author:
- Qore Technologies, s.r.o.
classes:
- BasicsChangeOrderStatusJava
groups:
- BASIC-TRAINING-EXCHANGE-APP
steps:
[
"BasicsChangeOrderStatusToInProgressJava:1.0",
"BasicsSendMoneyToBankJava:1.0",
"BasicsSendMoneyToUserJava:1.0",
"BasicsSendEmailToUserJava:1.0",
"BasicsChangeOrderStatusToCompletedJava:1.0"
]
version: "1.0"
# This is a generated file, don't edit!
type: class
name: BasicsChangeOrderStatusJava
desc: "Changes the status of orders"
author:
- Qore Technologies, s.r.o.
class-name: BasicsChangeOrderStatusJava
lang: qore
version: "1.0"
code: BasicsChangeOrderStatusJava.java
import com.qoretechnologies.qorus.*;
import org.qore.lang.sqlutil.AbstractTable;
import org.qore.lang.DatasourcePool;
import java.util.Map;
import java.util.HashMap;
class BasicsChangeOrderStatus {
public static void changeStatus(DatasourcePool ds, String status) throws Throwable {
HashMap<String, Object> orders = (HashMap<String, Object>)getStaticData("orders");
AbstractTable table = UserApi.getSqlTable(ds, "exchange_orders");
Map<String, Object> updateMap = new Map<String, Object>() {
{
put("status", status);
}
};
for (String key : orders.keySet()) {
Map<String, Object> cond = new Map<String, Object>() {
{
put("id", key);
}
};
table.update(updateMap, cond);
}
}
}
# This is a generated file, don't edit!
type: step
name: BasicsChangeOrderStatusToCompletedJava
desc: "Changes the status of orders to completed"
author:
- Qore Technologies, s.r.o.
base-class-name: QorusNormalStep
class-name: BasicsChangeOrderStatusToCompletedJava
lang: java
version: "1.0"
steptype: NORMAL
code: BasicsChangeOrderStatusToCompletedJava.java
import com.qoretechnologies.qorus.*;
import com.qoretechnologies.qorus.workflow.*;
import org.qore.lang.DatasourcePool;
class BasicsChangeOrderStatusToCompletedJava extends QorusNormalStep {
public void primary() throws Throwable {
DatasourcePool ds = getDatasourcePool("omquser");
try {
BasicsChangeOrderStatus.changeStatus(ds, "completed");
} catch (Exception e) {
ds.rollback();
throw e;
}
ds.commit();
}
}
# This is a generated file, don't edit!
type: step
name: BasicsChangeOrderStatusToInProgressJava
desc: "Changes the status of orders to in progress"
author:
- Qore Technologies, s.r.o.
base-class-name: QorusNormalStep
class-name: BasicsChangeOrderStatusToInProgressJava
lang: java
version: "1.0"
steptype: NORMAL
code: BasicsChangeOrderStatusToInProgressJava.java
import com.qoretechnologies.qorus.*;
import com.qoretechnologies.qorus.workflow.*;
class BasicsChangeOrderStatusToInProgressJava extends QorusNormalStep {
public void primary() throws Throwable {
DatasourcePool ds = getDatasourcePool("omquser");
try {
BasicsChangeOrderStatus.changeStatus(ds, "in-progress");
} catch (Exception e) {
ds.rollback();
throw e;
}
ds.commit();
}
}
# This is a generated file, don't edit!
type: step
name: BasicsSendEmailToUserJava
desc: "Sends email to user"
author:
- Qore Technologies, s.r.o.
base-class-name: QorusNormalStep
class-name: BasicsSendEmailToUserJava
lang: java
version: "1.0"
steptype: NORMAL
code: BasicsSendEmailToUserJava.java
import com.qoretechnologies.qorus.*;
import com.qoretechnologies.qorus.workflow.*;
import org.qore.lang.smtpclient.SmtpClient;
import org.qore.lang.mailmessage.Message;
import java.util.Map;
class BasicsSendEmailToUserJava extends QorusNormalStep {
public void primary() throws Throwable {
Map<String, Object> orders = (Map<String, Object>)getStaticData("orders");
SmtpClient smtp = (SmtpClient)getUserConnection("smtp-email");
for (String key : orders.keySet()) {
Map<String, Object> order = (Map<String, Object>)orders.get(key);
String userEmail = (String)order.get("user_email");
logInfo("Sending email to %s", userEmail);
mailmessage.Message message = new mailmessage.Message("test.qorus@gmail.com", "Order details");
String text = "You have received %d %s" + (String)order.get("amount") + (String)order.get("currency_to_buy");
message.setBody(text);
message.addTO(userEmail);
smtp.sendMessage(message);
}
}
}
# This is a generated file, don't edit!
type: step
name: BasicsSendMoneyToBankJava
desc: "Sends money to bank"
author:
- Qore Technologies, s.r.o.
base-class-name: QorusNormalStep
class-name: BasicsSendMoneyToBankJava
lang: java
version: "1.0"
steptype: NORMAL
code: BasicsSendMoneyToBankJava.java
import com.qoretechnologies.qorus.*;
import com.qoretechnologies.qorus.workflow.*;
import java.util.Map;
import java.util.HashMap;
import java.lang.Exception;
class BasicsSendMoneyToBankJava extends QorusNormalStep {
public void primary() throws Throwable {
Map<String, Object> staticData = (Map<String, Object>)getStaticData();
Map<String, Object> orders = (Map<String, Object>)static_data.get("orders");
Map<String, Object> exchangeRates = (Map<String, Object>)static_data.get("exchange_rates");
for (String key : orders.keySet()) {
Map<String, Object> order = orders.get(key);
String currencyToBuy = (String)order.get("currency_to_buy");
if (!exchangeRates.containsKey(currencyToBuy)) {
throw new Exception("BUSINESS-ERROR: exchange rate for " + currencyToBuy + " is missing");
}
String currencyToSell = (String)order.get("currency_to_sell");
if (!exchangeRates.containsKey(currencyToSell)) {
throw new Exception("BUSINESS-ERROR: exchange rate for " + currencyToSell + " is missing");
}
float rate = (float)exchangeRates.get(currencyToBuy);
logInfo("rate: %y", rate);
float amount = order.get("amount");
float sellRate = (float)exchangeRates.get(currencyToSell);
float amountToSend = (amount / rate) * sellRate;
amountToSend += amountToSend * (float)getConfigItemValue("bank-commission");
logInfo("Money sent to bank: %f %s", amountToSend, currencyToSell);
}
}
}
# This is a generated file, don't edit!
type: step
name: BasicsSendMoneyToUserJava
desc: "Sends money to user"
author:
- Qore Technologies, s.r.o.
base-class-name: QorusNormalStep
class-name: BasicsSendMoneyToUserJava
lang: java
version: "1.0"
steptype: NORMAL
code: BasicsSendMoneyToUserJava.java
import com.qoretechnologies.qorus.*;
import com.qoretechnologies.qorus.workflow.*;
import java.util.Map;
class BasicsSendMoneyToUserJava extends QorusNormalStep {
public void primary() throws Throwable {
Map<String, Object> orders = (Map<String, Object>)getStaticData("orders");
for (String key : orders.keySet()) {
Map<String, Object> order = (Map<String, Object>)orders.get(key);
logInfo("Money sent to user: %d %s", (float)order.get("amount"), (String)order.get("currency_to_buy"));
}
}
}
# This is a generated file, don't edit!
type: workflow
name: BASICS-PROCESS-ORDERS-WORKFLOW
desc: "Processes given orders"
author:
- Qore Technologies, s.r.o.
classes:
- BasicsChangeOrderStatus
groups:
- BASIC-TRAINING-EXCHANGE-APP
keylist:
- ids
steps:
[
"BasicsChangeOrderStatusToInProgress:1.0",
"BasicsSendMoneyToBank:1.0",
"BasicsSendMoneyToUser:1.0",
"BasicsSendEmailToUser:1.0",
"BasicsChangeOrderStatusToCompleted:1.0"
]
version: "1.0"
autostart: 1
......@@ -14,11 +14,11 @@ const ORDER_DATA = {
# Please ensure that the orders are in the database
{
"id": 10, "currency_to_buy": "USD", "currency_to_sell": "EUR", "amount": 100,
"user_email": "your@mail.com"
"user_email": "alzhan.turlybekov@qoretechnologies.com"
},
{
"id": 11, "currency_to_buy": "CZK", "currency_to_sell": "EUR", "amount": 600,
"user_email": "your@mail.com"
"user_email": "alzhan.turlybekov@qoretechnologies.com"
}
),
"exchange_rates": {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment