Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
swiftMtMx
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
isc-v3.1-tmp
swiftMtMx
Commits
4c384059
Commit
4c384059
authored
Aug 26, 2022
by
chengzhuoshen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
没有用到的节点需要通过xsd获取是否必填,非必填才会放到转换报告中
parent
6b723a62
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
102 additions
and
7 deletions
+102
-7
AbstractMx2MtCreator.java
...java/com/brilliance/swift/mx2mt/AbstractMx2MtCreator.java
+96
-5
Mx2MtContextIdentifier.java
...va/com/brilliance/swift/mx2mt/Mx2MtContextIdentifier.java
+2
-0
Mx2MtCreatorManager.java
.../java/com/brilliance/swift/mx2mt/Mx2MtCreatorManager.java
+2
-1
MxPacs00800108.xml
swiftCore/src/main/resources/swiftXml/MxPacs00800108.xml
+1
-0
head00100102.xsd
swiftCore/src/main/resources/xsd/head00100102.xsd
+1
-1
No files found.
swiftCore/src/main/java/com/brilliance/swift/mx2mt/AbstractMx2MtCreator.java
View file @
4c384059
...
...
@@ -15,10 +15,10 @@ import com.prowidesoftware.swift.io.IConversionService;
import
com.prowidesoftware.swift.io.writer.SwiftWriter
;
import
com.prowidesoftware.swift.model.*
;
import
com.prowidesoftware.swift.model.field.*
;
import
com.prowidesoftware.swift.model.mx.NamespaceReader
;
import
org.apache.commons.lang3.Validate
;
import
org.dom4j.Attribute
;
import
org.dom4j.Document
;
import
org.dom4j.Element
;
import
org.dom4j.*
;
import
org.dom4j.io.SAXReader
;
import
javax.xml.datatype.DatatypeConfigurationException
;
import
javax.xml.datatype.DatatypeFactory
;
...
...
@@ -144,6 +144,91 @@ public abstract class AbstractMx2MtCreator implements Mx2MtCreator {
}
/**
* 过滤掉必填节点值,这些值不会在错误报告中显示
* @param list
* @param xml
*/
public
static
List
<
String
>
filterMandatoryPath
(
List
<
String
>
list
,
String
xml
)
{
//1.根据AppHdr@xmlns获取版本对应的xsd文件
String
appHdrXsdName
=
null
;
Optional
<
String
>
namespace
=
NamespaceReader
.
findAppHdrNamespace
(
xml
);
if
(
namespace
.
isPresent
())
{
MxId
appHdrMxId
=
new
MxId
(
namespace
.
get
());
appHdrXsdName
=
appHdrMxId
.
getBusinessProcess
().
name
()
+
appHdrMxId
.
getFunctionality
()
+
appHdrMxId
.
getVariant
()
+
appHdrMxId
.
getVersion
();
}
//2.根据Document@xmlns获取版本对应的xsd文件
String
documentXsdName
=
""
;
namespace
=
NamespaceReader
.
findDocumentNamespace
(
xml
);
if
(
namespace
.
isPresent
())
{
MxId
documentMxId
=
new
MxId
(
namespace
.
get
());
documentXsdName
=
documentMxId
.
getBusinessProcess
().
name
()
+
documentMxId
.
getFunctionality
()
+
documentMxId
.
getVariant
()
+
documentMxId
.
getVersion
();
}
List
<
String
>
newList
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
String
path
=
list
.
get
(
i
);
boolean
requiredFlag
=
false
;
if
(
path
.
indexOf
(
"AppHdr"
)
>
-
1
)
{
requiredFlag
=
getPathMinOccurs
(
path
,
appHdrXsdName
);
}
else
if
(
path
.
indexOf
(
"Document"
)
>
-
1
)
{
requiredFlag
=
getPathMinOccurs
(
path
,
documentXsdName
);
}
if
(!
requiredFlag
)
{
newList
.
add
(
path
);
}
}
return
newList
;
}
/**
* 从对应的xsd文件中找到 MinOccurs 属性
* 如果等于0 表示选填
* 如果等于null或者大于0,表示必填
* @param path
* @param xsdName
* @return
*/
public
static
boolean
getPathMinOccurs
(
String
path
,
String
xsdName
)
{
try
{
String
[]
paths
=
path
.
split
(
"\\."
);
SAXReader
saxReader
=
new
SAXReader
();
Document
document
=
saxReader
.
read
(
AbstractMx2MtCreator
.
class
.
getResource
(
"/xsd/"
+
xsdName
+
".xsd"
));
Element
element
=
document
.
getRootElement
();
String
minOccurs
=
null
;
for
(
int
i
=
0
;
i
<
paths
.
length
;
i
++)
{
String
p
=
paths
[
i
];
if
(
p
.
indexOf
(
"@"
)
>
-
1
)
{
p
=
p
.
substring
(
0
,
p
.
indexOf
(
"@"
));
}
List
<
Node
>
nodeList
=
element
.
selectNodes
(
"//xs:element[@name='"
+
p
+
"']"
);
if
(
nodeList
==
null
||
nodeList
.
size
()
==
0
)
{
continue
;
}
element
=
(
Element
)
nodeList
.
get
(
0
);
if
(
i
==
(
paths
.
length
-
1
))
{
minOccurs
=
element
.
attributeValue
(
"minOccurs"
);
}
else
{
String
type
=
element
.
attributeValue
(
"type"
);
nodeList
=
element
.
selectNodes
(
"//xs:complexType[@name='"
+
type
+
"']"
);
element
=
(
Element
)
nodeList
.
get
(
0
);
}
}
if
(
minOccurs
==
null
||
Integer
.
parseInt
(
minOccurs
)
>
0
)
{
return
true
;
}
else
{
return
false
;
}
}
catch
(
DocumentException
e
)
{
throw
new
SwiftException
(
e
.
getMessage
());
}
}
/**
* 将xml所有节点全路径放在list里面
* 除了AppHdr以外
* @param list
...
...
@@ -369,9 +454,16 @@ public abstract class AbstractMx2MtCreator implements Mx2MtCreator {
if
(
mx2MtListener
!=
null
)
{
Map
<
String
,
Boolean
>
maps
=
mx2MtListener
.
getMaps
();
List
<
String
>
pathList
=
new
ArrayList
<>();
Document
document
=
(
Document
)
context
.
get
(
Mx2MtContextIdentifier
.
MX_XMl_DOCUMENT
,
true
);
String
xml
=
(
String
)
context
.
get
(
Mx2MtContextIdentifier
.
MX_XMl
,
true
);
Document
document
=
null
;
try
{
document
=
DocumentHelper
.
parseText
(
xml
);
}
catch
(
DocumentException
e
)
{
throw
new
SwiftException
(
e
.
getMessage
());
}
parseDocument
(
pathList
,
document
.
getRootElement
(),
document
.
getRootElement
().
getName
());
if
(
pathList
.
size
()
>
0
)
{
pathList
=
filterMandatoryPath
(
pathList
,
xml
);
for
(
String
path
:
pathList
)
{
if
(!
maps
.
containsKey
(
path
))
{
String
originalValue
=
XmlUtil
.
getXmlNodeValue
(
document
,
path
);
...
...
@@ -382,7 +474,6 @@ public abstract class AbstractMx2MtCreator implements Mx2MtCreator {
}
}
}
}
public
void
write
(
SwiftMessage
swiftMessage
,
File
file
)
throws
SwiftException
{
...
...
swiftCore/src/main/java/com/brilliance/swift/mx2mt/Mx2MtContextIdentifier.java
View file @
4c384059
...
...
@@ -4,6 +4,8 @@ public class Mx2MtContextIdentifier {
public
static
final
String
MX_XMl_DOCUMENT
=
"mx.xml.document"
;
public
static
final
String
MX_XMl
=
"mx.xml"
;
public
static
final
String
MX_OBJ
=
"mx.obj"
;
public
static
final
String
MX_TO_MT_OUTPUT_FILE_PATH
=
"mx.to.mt.output.filepath"
;
...
...
swiftCore/src/main/java/com/brilliance/swift/mx2mt/Mx2MtCreatorManager.java
View file @
4c384059
...
...
@@ -43,6 +43,7 @@ public class Mx2MtCreatorManager {
context
.
set
(
Mx2MtContextIdentifier
.
MX_XMl_DOCUMENT
,
document
);
context
.
set
(
Mx2MtContextIdentifier
.
MX_TO_MT_OUTPUT_FILE_PATH
,
fileOutputPath
);
context
.
set
(
Mx2MtContextIdentifier
.
MX_OBJ
,
abstractMX
);
context
.
set
(
Mx2MtContextIdentifier
.
MX_XMl
,
xml
);
String
applicationMode
=
"O"
;
//代表是收报,默认值
if
(
extraMap
!=
null
)
{
applicationMode
=
(
String
)
extraMap
.
get
(
Mx2MtConstants
.
APPLICATION_MODE
);
...
...
@@ -121,7 +122,7 @@ public class Mx2MtCreatorManager {
if
(
"pacs.004.001"
.
equals
(
messageType
))
{
Map
<
String
,
String
>
parentElementMaps
=
XmlUtil
.
getParentElementMaps
(
document
);
String
grpParentElementName
=
parentElementMaps
.
get
(
"OrgnlGrpInf"
);
String
orgMessageNameId
=
XmlUtil
.
getXmlNodeValue
(
document
,
grpParentElementName
+
"OrgnlGrpInf.OrgnlMsgNmId"
);
String
orgMessageNameId
=
XmlUtil
.
getXmlNodeValue
(
document
,
grpParentElementName
+
"
.
OrgnlGrpInf.OrgnlMsgNmId"
);
if
(
StringUtil
.
isNotEmpty
(
orgMessageNameId
))
{
if
(
orgMessageNameId
.
indexOf
(
"pacs.008"
)
>
-
1
||
orgMessageNameId
.
startsWith
(
"MT103"
))
{
messageType
+=
".MT103"
;
...
...
swiftCore/src/main/resources/swiftXml/MxPacs00800108.xml
View file @
4c384059
...
...
@@ -48,6 +48,7 @@ Change Log
<PmtId>
<InstrId>
pacs8bizmsgidr01qwerssee
</InstrId>
<EndToEndId>
pacs008EndToEndId-001
</EndToEndId>
<TxId>
123456
</TxId>
<UETR>
8a562c67-ca16-48ba-b074-65581be6f001
</UETR>
</PmtId>
<PmtTpInf>
...
...
swiftCore/src/main/resources/xsd/head00100102.xsd
View file @
4c384059
...
...
@@ -7,7 +7,7 @@
<xs:element
name=
"To"
type=
"Party44Choice"
/>
<xs:element
name=
"BizMsgIdr"
type=
"Max35Text"
/>
<xs:element
name=
"MsgDefIdr"
type=
"Max35Text"
/>
<xs:element
maxOccurs=
"1"
minOccurs=
"0"
name=
"BizSvc"
type=
"Max35Text"
/>
<xs:element
name=
"BizSvc"
type=
"Max35Text"
/>
<xs:element
name=
"CreDt"
type=
"ISODateTime"
/>
<xs:element
maxOccurs=
"1"
minOccurs=
"0"
name=
"CpyDplct"
type=
"CopyDuplicate1Code"
/>
<xs:element
maxOccurs=
"1"
minOccurs=
"0"
name=
"PssblDplct"
type=
"YesNoIndicator"
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment