开发确认解释器
本主题介绍如何扩展预设监管提交处理器类,以及如何使用监管部门特定的处理方法来改写确认处理方法。
解决方案
• 创建一个自定义类来扩展预设监管提交处理器。
• 创建一个 xconf 条目来注册自定义类。
解决方案元素
下一张表格介绍解决方案元素:
元素
|
类型
|
说明
|
processAcknowledgement(String transmissionName, String transmissionContent)
|
API
|
用于处理从监管部门收到的关于监管提交的确认消息。
|
ApplicationData processAcknowledgement(String transmissionName, byte[] transmissionContent)
|
API
|
用作替代 API 来处理从监管部门收到的关于监管提交的确认消息。
|
默认行为
预计各监管部门会为每一种监管提交类型提供确认声明编号和格式的相关文档。根据需要,实施者可以创建与所提供的文档相匹配的提交特定处理器。默认实施仅用于演示和教学目的。
“确认 1”包含下列格式的 JSON 字符串:
{
"ackNumber": 1,
"typeName": "<typeName>"
"name": "<regulatorySubmissionName>",
"number": "<regulatorySubmissionNumber>",
"remoteIdentifier": "<remoteIdentifier>"
}
“确认 2”包含给定成功格式的 JSON 字符串:
{
"ackNumber": 2,
"typeName": "<typeName>"
"remoteIdentifier": "<remoteIdentifier>"
"certificationNumber": "<certificateNumber>"
"expirationDate": "<expirationDate>"
"result": "SUCCESS"
}
“确认 2”包含给定失败格式的 JSON 字符串:
{
"ackNumber": 2,
"typeName": "<typeName>"
"remoteIdentifier": "<remoteIdentifier>"
"certificationNumber": "<certificateNumber>"
"expirationDate": "<expirationDate>"
"result": "FAILURE"
"errorCodes": [
{
"errorCode": "0",
"errorMessage": "A regulatory sumission error has occured."
},
{
"errorCode": "1",
"errorMessage": "One or more regularory submission attributes exceeds."
}
]
}
根据监管提交处理器接口,仅在收到“确认 2”时才会发送确认事件。包括
typename,因为这是一个示例通用确认处理器。在监管提交类型特定的处理器中,
typename 已知,因为监管提交处理器与注册该处理器的类型之间存在一对一关系。有关监管提交处理器接口的详情,请参阅
监管提交处理器接口。
创建自定义类
要自定义确认处理,首先创建一个用于扩展 SimpleRegulatorySubmissionProcessor 的 Java 类 (您的处理器),或相应的可修订子类型处理器,然后改写 processAcknowledegment 方法。可修订子类型填充器可以是 AERSubmissionProcessor、ERSubmissionProcessor、RPSSubmissionProcessor 或 UDISubmissionProcessor。
下一示例显示了一个新的自定义类,该类包含已改写的 processAcknowledgement 方法的预设要求。ConditionalCheckoutRunner 用于通过禁止在调用多个服务时自动检出来防止多次迭代。
@Override
public ApplicationData processAcknowledgement(String transmissionName, byte[] transmissionContent)
throws Exception {
AcknowledgmentResult acknowledgmentResult = new AcknowledgmentResult();
new TransactionRunner<Boolean>() {
@Override
public Boolean performBusinessProcess() throws Exception {
JSONObject jsonContent = new JSONObject(new String(transmissionContent, StandardCharsets.UTF_8));
switch (jsonContent.getInt("ackNumber")) {
case 1:
String typeName = jsonContent.getString("typeName");
String number = jsonContent.getString("number");
RegulatorySubmission regulatorySubmission = RegulatorySubmissionHelper.service
.findRegulatorySubmissionByTypeAndAttribute(typeName, "number", number);
acknowledgmentResult.setTargetSubmission(regulatorySubmission);
new ConditionalAutoCheckoutRunner<RegulatorySubmission>(regulatorySubmission) {
@Override
public RegulatorySubmission performBusinessProcess(RegulatorySubmission coRegSub)
throws Exception {
ApplicationData appData = RegulatoryContentHelper.getService()
.storeRegulatoryContentReturnApplicationData(
coRegSub, RegulatoryContentCategory.ACKNOWLEDGEMENT1,
transmissionName,
new String(transmissionContent, StandardCharsets.UTF_8));
acknowledgmentResult.setCreatedData(appData);
return RegulatorySubmissionHelper.service.modifyRegulatorySubmission(coRegSub,
Map.of("remoteIdentifier", jsonContent.getString("remoteIdentifier")));
}
}.invoke();
break;
case 2:
String remoteIdentifier = jsonContent.getString("remoteIdentifier");
typeName = jsonContent.getString("typeName");
regulatorySubmission = RegulatorySubmissionHelper.service
.findRegulatorySubmissionByTypeAndAttribute(typeName, "remoteIdentifier", remoteIdentifier);
acknowledgmentResult.setTargetSubmission(regulatorySubmission);
regulatorySubmission = new ConditionalAutoCheckoutRunner<RegulatorySubmission>(
regulatorySubmission) {
@Override
public RegulatorySubmission performBusinessProcess(RegulatorySubmission coRegSub)
throws Exception {
ApplicationData appData = RegulatoryContentHelper.getService()
.storeRegulatoryContentReturnApplicationData(coRegSub,
RegulatoryContentCategory.ACKNOWLEDGEMENT2, transmissionName,
new String(transmissionContent, StandardCharsets.UTF_8));
acknowledgmentResult.setCreatedData(appData);
if (jsonContent.has("result") && "SUCCESS".equals(jsonContent.get("result"))) {
String expDateString = jsonContent.getString("expirationDate");
Timestamp expDate = Timestamp.valueOf(expDateString);
coRegSub = RegulatorySubmissionHelper.service.modifyRegulatorySubmission(coRegSub,
Map.of("certificateNumber", jsonContent.getString("certificateNumber"),
"expirationDate", expDate));
acknowledgmentResult.setAcknowledgmentSuccessful(true);
}
else {
if (jsonContent.has("errorCodes")) {
JSONArray failureCodes = jsonContent.getJSONArray("errorCodes");
ArrayList<AcknowledgementMessageBean> ackMessages = new ArrayList<>();
for (int i = 0; i < failureCodes.length(); i++) {
JSONObject failCode = failureCodes.getJSONObject(i);
String code = failCode.get("errorCode").toString();
String message = failCode.get("errorMessage").toString();
ackMessages.add(new AcknowledgementMessageBean(message, code));
}
RegulatorySubmissionHelper.service.saveAcknowledgementMessage(coRegSub,
ackMessages);
}
acknowledgmentResult.setAcknowledgmentFailed(true);
}
return coRegSub;
}
}.invoke();
// must dispatch events against the checked-in regulatory submission because the checked out version
// is on it's own branch
if (acknowledgmentResult.isAcknowledgmentSuccessful()) {
RegulatorySubmissionProcessorHelper.dispatchAcknowledgmentSuccessfulEvent(regulatorySubmission);
}
else {
RegulatorySubmissionProcessorHelper.dispatchAcknowledgmentFailedEvent(regulatorySubmission);
}
break;
default:
break;
}
return true;
}
}.invoke();
return acknowledgmentResult.getCreatedData();
}