从四个java源码构文件建一个机票预定业务的规则引擎(下篇)

一、前言

本文仅代表作者的个人观点;

本文的内容仅限于技术探讨,不能作为指导生产环境的素材;

本文素材是红帽公司产品技术和手册;

本文分为上篇和下篇两部分,本文是下篇;

二、一个飞机购票程序源码解析

我们继续上一篇的案例,看一个kjar:kie-server-lab-kjar。

Kjar和普通jar不同的地方是,它把规则打包起来。

我们看一下kie-server-lab-kjar的目录结构:

通过IDE工具打开:查看订票流程定义文件:

我们查看这个kjar的三个源码文件,这其实是三个数据对象:

第一个:Applicant.java,这个代码主要是获取买票申请人的个人信息:

先看外部结构:

package org.specialtripsagency;

/**

* This class was automatically generated by the data modeler tool.

*/

public class Applicant implements java.io.Serializable

{

static final long serialVersionUID = 1L;

private java.lang.String name;

private java.lang.String emailAddress;

private java.lang.Integer numberOfTravelers;

private java.lang.String otherDetails;

public Applicant()

{

}

public java.lang.String getName()

{

return this.name;

}

public void setName(java.lang.String name)

{

this.name = name;

}

public java.lang.String getEmailAddress()

{

return this.emailAddress;

}

public void setEmailAddress(java.lang.String emailAddress)

{

this.emailAddress = emailAddress;

}

public java.lang.Integer getNumberOfTravelers()

{

return this.numberOfTravelers;

}

public void setNumberOfTravelers(java.lang.Integer numberOfTravelers)

{

this.numberOfTravelers = numberOfTravelers;

}

public java.lang.String getOtherDetails()

{

return this.otherDetails;

}

public void setOtherDetails(java.lang.String otherDetails)

{

this.otherDetails = otherDetails;

}

public Applicant(java.lang.String name, java.lang.String emailAddress,

java.lang.Integer numberOfTravelers, java.lang.String otherDetails)

{

this.name = name;

this.emailAddress = emailAddress;

this.numberOfTravelers = numberOfTravelers;

this.otherDetails = otherDetails;

}

}

这个源码的外部结构:

第二个:BookingObject.java,这个主要是预定的对象:

package org.specialtripsagency;

/**

* This class was automatically generated by the data modeler tool.

*/

public class BookingObject extends java.lang.Object implements java.io.Serializable

{

static final long serialVersionUID = 1L;

private org.specialtripsagency.Applicant applicant;

private String bookingId;

private org.specialtripsagency.Flight flight;

public BookingObject()

{

}

public org.specialtripsagency.Applicant getApplicant()

{

return this.applicant;

}

public void setApplicant(org.specialtripsagency.Applicant applicant)

{

this.applicant = applicant;

}

public java.lang.String getBookingId()

{

return this.bookingId;

}

public void setBookingId(java.lang.String bookingId)

{

this.bookingId = bookingId;

}

public org.specialtripsagency.Flight getFlight()

{

return this.flight;

}

public void setFlight(org.specialtripsagency.Flight flight)

{

this.flight = flight;

}

public BookingObject(org.specialtripsagency.Applicant applicant,

java.lang.String bookingId, org.specialtripsagency.Flight flight)

{

this.applicant = applicant;

this.bookingId = bookingId;

this.flight = flight;

}

}

再看第三个:Flight.java,这个主要是航班信息相关内容:

package org.specialtripsagency;

/**

* This class was automatically generated by the data modeler tool.

*

*/

public class Flight extends java.lang.Object implements java.io.Serializable

{

static final long serialVersionUID = 1L;

private java.lang.String carrier;

private java.lang.String flightNr;

private java.lang.Integer priceDiscount;

private java.lang.Integer ratePerPerson;

private java.lang.String returnDate;

private java.lang.String startCity;

private java.lang.String targetCity;

private java.lang.String travelDate;

private java.lang.String travelClass;

private java.lang.String bookingStatus;

private java.lang.String bookingId;

public Flight()

{

}

public java.lang.String getCarrier()

{

return this.carrier;

}

public void setCarrier(java.lang.String carrier)

{

this.carrier = carrier;

}

public java.lang.String getFlightNr()

{

return this.flightNr;

}

public void setFlightNr(java.lang.String flightNr)

{

this.flightNr = flightNr;

}

public java.lang.Integer getPriceDiscount()

{

return this.priceDiscount;

}

public void setPriceDiscount(java.lang.Integer priceDiscount)

{

this.priceDiscount = priceDiscount;

}

public java.lang.Integer getRatePerPerson()

{

return this.ratePerPerson;

}

public void setRatePerPerson(java.lang.Integer ratePerPerson)

{

this.ratePerPerson = ratePerPerson;

}

public java.lang.String getReturnDate()

{

return this.returnDate;

}

public void setReturnDate(java.lang.String returnDate)

{

this.returnDate = returnDate;

}

public java.lang.String getStartCity()

{

return this.startCity;

}

public void setStartCity(java.lang.String startCity)

{

this.startCity = startCity;

}

public java.lang.String getTargetCity()

{

return this.targetCity;

}

public void setTargetCity(java.lang.String targetCity)

{

this.targetCity = targetCity;

}

public java.lang.String getTravelDate()

{

return this.travelDate;

}

public void setTravelDate(java.lang.String travelDate)

{

this.travelDate = travelDate;

}

public java.lang.String getTravelClass()

{

return this.travelClass;

}

public void setTravelClass(java.lang.String travelClass)

{

this.travelClass = travelClass;

}

public java.lang.String getBookingStatus()

{

return this.bookingStatus;

}

public void setBookingStatus(java.lang.String bookingStatus)

{

this.bookingStatus = bookingStatus;

}

public java.lang.String getBookingId()

{

return this.bookingId;

}

public void setBookingId(java.lang.String bookingId)

{

this.bookingId = bookingId;

}

public Flight(java.lang.String carrier, java.lang.String flightNr,

java.lang.Integer priceDiscount, java.lang.Integer ratePerPerson,

java.lang.String returnDate, java.lang.String startCity,

java.lang.String targetCity, java.lang.String travelDate,

java.lang.String travelClass, java.lang.String bookingStatus,

java.lang.String bookingId)

{

this.carrier = carrier;

this.flightNr = flightNr;

this.priceDiscount = priceDiscount;

this.ratePerPerson = ratePerPerson;

this.returnDate = returnDate;

this.startCity = startCity;

this.targetCity = targetCity;

this.travelDate = travelDate;

this.travelClass = travelClass;

this.bookingStatus = bookingStatus;

this.bookingId = bookingId;

}

}

在BPM中打开Kjar

查看数据对象:

再看business流程:

选择org.specialtripsagency package.

接下来看一下流程建模,本流程是审核机票预订流程的定义。

我们分步骤查看,整体上,就是订票,输入信息,然后付款,付款成功订票成功;否则取消:

第一步Prepare WS Data的脚本:

/* Populating Applicant object */

org.specialtripsagency.Applicant _applicant = new org.specialtripsagency.Applicant();

_applicant.setName(applicantName);

/* Populating Flight object */

org.specialtripsagency.Flight _flight = new org.specialtripsagency.Flight();

_flight.setCarrier(flight_carrier);

_flight.setFlightNr(flight_flightNr);

_flight.setTravelClass(flight_travelClass);

/* Populating BookingObject object */

org.specialtripsagency.BookingObject _booking = new org.specialtripsagency.BookingObject();

_booking.setApplicant(_applicant);

_booking.setFlight(_flight);

kcontext.setVariable("booking", _booking);

/* FlightService : Booking */

org.acme.specialtripsagency.flightservice.Booking _flightBooking = new org.acme.specialtripsagency.flightservice.Booking();

_flightBooking.setCarrier(_flight.getCarrier());

_flightBooking.setFlightNr(_flight.getFlightNr());

_flightBooking.setTravelClass(_flight.getTravelClass());

_flightBooking.setType("PREBOOKING");

kcontext.setVariable("flightBooking", _flightBooking);

第二步:flight pre-booking:

这步主要做的数据重定向:

第三步:处理订票数据:

/* Populate BookingObject with data from flight booking */

org.specialtripsagency.BookingObject _booking = (org.specialtripsagency.BookingObject)kcontext.getVariable("booking");

org.acme.specialtripsagency.flightservice.BookingResponse _flightBookingResponse = (org.acme.specialtripsagency.flightservice.BookingResponse)kcontext.getVariable("flightBookingResponse");

_booking.getFlight().setBookingId(_flightBookingResponse.getBooking());

_booking.getFlight().setBookingStatus(_flightBookingResponse.getStatus());

_booking.setBookingId(_flightBookingResponse.getBooking());

第四步:Payment Instructions STUB

System.out.println("Flight Booking Process: Payment Instructions Sent to Customer");

第五步:Process payment

选择1:Prepare Data for confirmation

org.specialtripsagency.BookingObject _booking = (org.specialtripsagency.BookingObject) kcontext.getVariable("booking");

org.specialtripsagency.Flight _flight = _booking.getFlight();

/* FlightService : Booking */

org.acme.specialtripsagency.flightservice.Booking _flightBooking = new org.acme.specialtripsagency.flightservice.Booking();

_flightBooking.setCarrier(_flight.getCarrier());

_flightBooking.setFlightNr(_flight.getFlightNr());

_flightBooking.setTravelClass(_flight.getTravelClass());

_flightBooking.setType("BOOKING");

_flightBooking.setBooking(_flight.getBookingId());

kcontext.setVariable("flightBooking", _flightBooking);

订票成功:

选择2:订票取消:

org.specialtripsagency.BookingObject _booking = (org.specialtripsagency.BookingObject) kcontext.getVariable("booking");

org.acme.specialtripsagency.flightservice.BookingCancellation _flightCancellation = new org.acme.specialtripsagency.flightservice.BookingCancellation();

_flightCancellation.setBooking(_booking.getFlight().getBookingId());

kcontext.setVariable("flightCancellation", _flightCancellation);

机票取消:

三、源码的构建与部署

选择构建和部署:

增加web container:

查看部署在KIE服务器上的容器:

四、流程模拟

点击下图start:

提示输入信息:购票人、航空公司、航班号、仓位:

处理任务:

提交以后:

这个时候,流程已经走到了:

处理支付:

魏新宇

  • "大魏分享"运营者、红帽资深解决方案架构师
  • 专注开源云计算、容器及自动化运维在金融行业的推广
  • 拥有MBA、ITIL V3、Cobit5、C-STAR、TOGAF9.1(鉴定级)等管理认证。
  • 拥有红帽RHCE/RHCA、VMware VCP-DCV、VCP-DT、VCP-Network、VCP-Cloud、AIX、HPUX等技术认证。

原文发布于微信公众号 - 大魏分享(david-share)

原文发表时间:2018-06-02

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏魂祭心

原 canvas绘制clock

5144
来自专栏张善友的专栏

Miguel de Icaza 细说 Mix 07大会上的Silverlight和DLR

Mono之父Miguel de Icaza 详细报道微软Mix 07大会上的Silverlight和DLR ,上面还谈到了Mono and Silverligh...

2997
来自专栏Ceph对象存储方案

Luminous版本PG 分布调优

Luminous版本开始新增的balancer模块在PG分布优化方面效果非常明显,操作也非常简便,强烈推荐各位在集群上线之前进行这一操作,能够极大的提升整个集群...

3675
来自专栏杨龙飞前端

scrollto 到指定位置

2954
来自专栏张善友的专栏

Silverlight + Model-View-ViewModel (MVVM)

     早在2005年,John Gossman写了一篇关于Model-View-ViewModel模式的博文,这种模式被他所在的微软的项目组用来创建Expr...

3278
来自专栏hbbliyong

WPF Trigger for IsSelected in a DataTemplate for ListBox items

<DataTemplate DataType="{x:Type vm:HeaderSlugViewModel}"> <vw:HeaderSlug...

4224
来自专栏一个会写诗的程序员的博客

Spring Reactor 项目核心库Reactor Core

Non-Blocking Reactive Streams Foundation for the JVM both implementing a Reactiv...

2802
来自专栏pangguoming

Spring Boot集成JasperReports生成PDF文档

由于工作需要,要实现后端根据模板动态填充数据生成PDF文档,通过技术选型,使用Ireport5.6来设计模板,结合JasperReports5.6工具库来调用渲...

1.4K7
来自专栏陈仁松博客

ASP.NET Core 'Microsoft.Win32.Registry' 错误修复

今天在发布Asp.net Core应用到Azure的时候出现错误InvalidOperationException: Cannot find compilati...

5238
来自专栏一个爱瞎折腾的程序猿

sqlserver使用存储过程跟踪SQL

USE [master] GO /****** Object: StoredProcedure [dbo].[sp_perfworkload_trace_s...

2880

扫码关注云+社区