전자 결재 DTD(exchange.dtd, pack.dtd) 정의 및 생성 및 테스트 반영

dev
Jonguk. Lim 6 months ago
parent 9c14262418
commit c7f827b305

@ -3,6 +3,7 @@ package cokr.xit.adds.inf.mois.model;
import java.util.List; import java.util.List;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlCData; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlCData;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
@ -37,22 +38,27 @@ public class ExchangeCommon {
@Builder @Builder
public static class Common { public static class Common {
@JacksonXmlProperty(localName = "SENDER") @JacksonXmlProperty(localName = "SENDER")
@JsonProperty(required = true)
private Sender sender; private Sender sender;
@JacksonXmlProperty(localName = "RECEIVER") @JacksonXmlProperty(localName = "RECEIVER")
@JsonProperty(required = true)
private Receiver receiver; private Receiver receiver;
@JacksonXmlProperty(localName = "TITLE") @JacksonXmlProperty(localName = "TITLE")
@JacksonXmlCData @JsonProperty(required = true)
private String title; private String title;
@JacksonXmlProperty(localName = "CREATED_DATE") @JacksonXmlProperty(localName = "CREATED_DATE")
@JsonProperty(required = true)
private String createdDate; private String createdDate;
@JacksonXmlProperty(localName = "ATTACHNUM") @JacksonXmlProperty(localName = "ATTACHNUM")
@JsonProperty(required = true)
private int attachnum; private int attachnum;
@JacksonXmlProperty(localName = "ADMINISTRATIVE_NUM") @JacksonXmlProperty(localName = "ADMINISTRATIVE_NUM")
@JsonProperty(required = true)
private String administrativeNum; private String administrativeNum;
} }
@ -62,9 +68,11 @@ public class ExchangeCommon {
@Builder @Builder
public static class Sender { public static class Sender {
@JacksonXmlProperty(localName = "SERVERID") @JacksonXmlProperty(localName = "SERVERID")
@JsonProperty(required = true)
private String serverid; private String serverid;
@JacksonXmlProperty(localName = "USERID") @JacksonXmlProperty(localName = "USERID")
@JsonProperty(required = true)
private String userid; private String userid;
@JacksonXmlProperty(localName = "EMAIL") @JacksonXmlProperty(localName = "EMAIL")
@ -77,28 +85,29 @@ public class ExchangeCommon {
@Builder @Builder
public static class Receiver { public static class Receiver {
@JacksonXmlProperty(localName = "SERVERID") @JacksonXmlProperty(localName = "SERVERID")
@JsonProperty(required = true)
private String serverid; private String serverid;
@JacksonXmlProperty(localName = "USERID") @JacksonXmlProperty(localName = "USERID")
@JsonProperty(required = true)
private String userid; private String userid;
@JacksonXmlProperty(localName = "EMAIL") @JacksonXmlProperty(localName = "EMAIL")
private String email; private String email;
} }
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public static class Docnum { public static class Docnum {
@JacksonXmlProperty(localName = "docnumcode", isAttribute = true) @JacksonXmlProperty(localName = "docnumcode", isAttribute = true)
@JsonProperty(required = true)
@JacksonXmlCData
private String docnumcode; private String docnumcode;
@XmlValue @XmlValue
@JacksonXmlText @JacksonXmlText
@JacksonXmlCData
private String value; private String value;
} }
@ -111,9 +120,11 @@ public class ExchangeCommon {
* | * |
*/ */
@JacksonXmlProperty(localName = "status", isAttribute = true) @JacksonXmlProperty(localName = "status", isAttribute = true)
@JsonProperty(required = true)
private String status; private String status;
@JacksonXmlProperty(localName = "LINES") @JacksonXmlProperty(localName = "LINES")
@JsonProperty(required = true)
private Lines lines; private Lines lines;
} }
@ -124,6 +135,7 @@ public class ExchangeCommon {
public static class Lines { public static class Lines {
@JacksonXmlElementWrapper(useWrapping = false) @JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty(localName = "LINE") @JacksonXmlProperty(localName = "LINE")
@JsonProperty(required = true)
private List<Line> line; private List<Line> line;
} }
@ -133,9 +145,11 @@ public class ExchangeCommon {
@Builder @Builder
public static class Line { public static class Line {
@JacksonXmlProperty(localName = "LEVEL") @JacksonXmlProperty(localName = "LEVEL")
@JsonProperty(required = true)
private String level; private String level;
@JacksonXmlProperty(localName = "SANCTION") @JacksonXmlProperty(localName = "SANCTION")
@JsonProperty(required = true)
private Sanction sanction; private Sanction sanction;
} }
@ -150,6 +164,7 @@ public class ExchangeCommon {
* </pre> * </pre>
*/ */
@JacksonXmlProperty(localName = "result", isAttribute = true) @JacksonXmlProperty(localName = "result", isAttribute = true)
@JsonProperty(required = true)
private String result; private String result;
/** /**
@ -158,16 +173,18 @@ public class ExchangeCommon {
* </pre> * </pre>
*/ */
@JacksonXmlProperty(localName = "type", isAttribute = true) @JacksonXmlProperty(localName = "type", isAttribute = true)
@JsonProperty(required = true)
private String type; private String type;
@JacksonXmlProperty(localName = "PERSON") @JacksonXmlProperty(localName = "PERSON")
@JsonProperty(required = true)
private Person person; private Person person;
@JacksonXmlProperty(localName = "COMMENT") @JacksonXmlProperty(localName = "COMMENT")
@JacksonXmlCData
private String comment; private String comment;
@JacksonXmlProperty(localName = "DATE") @JacksonXmlProperty(localName = "DATE")
@JsonProperty(required = true)
private String date; private String date;
} }
@ -177,20 +194,23 @@ public class ExchangeCommon {
@Builder @Builder
public static class Person { public static class Person {
@JacksonXmlProperty(localName = "USERID") @JacksonXmlProperty(localName = "USERID")
@JsonProperty(required = true)
private String userid; private String userid;
@JacksonXmlProperty(localName = "NAME") @JacksonXmlProperty(localName = "NAME")
@JsonProperty(required = true)
private String name; private String name;
@JacksonXmlProperty(localName = "POSITION") @JacksonXmlProperty(localName = "POSITION")
@JsonProperty(required = true)
private String position; private String position;
@JacksonXmlProperty(localName = "DEPT") @JacksonXmlProperty(localName = "DEPT")
@JacksonXmlCData @JsonProperty(required = true)
private String dept; private String dept;
@JacksonXmlProperty(localName = "ORG") @JacksonXmlProperty(localName = "ORG")
@JacksonXmlCData @JsonProperty(required = true)
private String org; private String org;
} }
@ -200,6 +220,7 @@ public class ExchangeCommon {
@Builder @Builder
public static class ModificationFlag { public static class ModificationFlag {
@JacksonXmlProperty(localName = "MODIFIABLE") @JacksonXmlProperty(localName = "MODIFIABLE")
@JsonProperty(required = true)
private Modifiable modifiable; private Modifiable modifiable;
@JacksonXmlProperty(localName = "MODIFIED") @JacksonXmlProperty(localName = "MODIFIED")
@ -215,6 +236,7 @@ public class ExchangeCommon {
* yes | no * yes | no
*/ */
@JacksonXmlProperty(localName = "modifyflag", isAttribute = true) @JacksonXmlProperty(localName = "modifyflag", isAttribute = true)
@JsonProperty(required = true)
@Builder.Default @Builder.Default
private String modifyflag = "no"; private String modifyflag = "no";
} }
@ -234,14 +256,17 @@ public class ExchangeCommon {
@Builder @Builder
public static class Addendum { public static class Addendum {
@JacksonXmlProperty(localName = "comment", isAttribute = true) @JacksonXmlProperty(localName = "comment", isAttribute = true)
@JsonProperty(required = true)
@JacksonXmlCData
private String comment; private String comment;
@JacksonXmlProperty(localName = "name", isAttribute = true) @JacksonXmlProperty(localName = "name", isAttribute = true)
@JsonProperty(required = true)
@JacksonXmlCData
private String name; private String name;
@XmlValue @XmlValue
@JacksonXmlText @JacksonXmlText
@JacksonXmlCData
private String value; private String value;
} }
@ -255,6 +280,7 @@ public class ExchangeCommon {
@JacksonXmlElementWrapper(useWrapping = false) @JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty(localName = "ATTACHMENT") @JacksonXmlProperty(localName = "ATTACHMENT")
@JsonProperty(required = true)
private List<Attachment> attachment; private List<Attachment> attachment;
} }
@ -276,10 +302,19 @@ public class ExchangeCommon {
@Builder @Builder
public static class XMLFile { public static class XMLFile {
@JacksonXmlProperty(localName = "filename", isAttribute = true) @JacksonXmlProperty(localName = "filename", isAttribute = true)
String filename; @JsonProperty(required = true)
@JacksonXmlCData
private String filename;
@JacksonXmlProperty(localName = "desc", isAttribute = true) @JacksonXmlProperty(localName = "desc", isAttribute = true)
String desc; @JsonProperty(required = true)
@JacksonXmlCData
private String desc;
@XmlValue
@JacksonXmlText
@JsonProperty(required = true)
private String value;
} }
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
@ -288,10 +323,19 @@ public class ExchangeCommon {
@Builder @Builder
public static class XSLFile { public static class XSLFile {
@JacksonXmlProperty(localName = "filename", isAttribute = true) @JacksonXmlProperty(localName = "filename", isAttribute = true)
String filename; @JsonProperty(required = true)
@JacksonXmlCData
private String filename;
@JacksonXmlProperty(localName = "desc", isAttribute = true) @JacksonXmlProperty(localName = "desc", isAttribute = true)
String desc; @JsonProperty(required = true)
@JacksonXmlCData
private String desc;
@XmlValue
@JacksonXmlText
@JsonProperty(required = true)
private String value;
} }
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
@ -300,14 +344,18 @@ public class ExchangeCommon {
@Builder @Builder
public static class Attachment { public static class Attachment {
@JacksonXmlProperty(localName = "filename", isAttribute = true) @JacksonXmlProperty(localName = "filename", isAttribute = true)
@JsonProperty(required = true)
@JacksonXmlCData
private String filename; private String filename;
@JacksonXmlProperty(localName = "desc", isAttribute = true) @JacksonXmlProperty(localName = "desc", isAttribute = true)
@JsonProperty(required = true)
@JacksonXmlCData
private String desc; private String desc;
@XmlValue @XmlValue
@JacksonXmlText @JacksonXmlText
@JacksonXmlCData @JsonProperty(required = true)
private String value; private String value;
} }
} }

@ -1,7 +1,7 @@
package cokr.xit.adds.inf.mois.model; package cokr.xit.adds.inf.mois.model;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlCData; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
@ -31,10 +31,10 @@ import lombok.NoArgsConstructor;
@Builder @Builder
public class ExchangeDto extends ExchangeCommon { public class ExchangeDto extends ExchangeCommon {
@JacksonXmlProperty(localName = "HEADER") @JacksonXmlProperty(localName = "HEADER")
@JsonProperty(required = true)
private Header header; private Header header;
@JacksonXmlProperty(localName = "BODY") @JacksonXmlProperty(localName = "BODY")
@JacksonXmlCData
private String body; private String body;
@JacksonXmlProperty(localName = "ATTACHMENTS") @JacksonXmlProperty(localName = "ATTACHMENTS")
@ -46,9 +46,11 @@ public class ExchangeDto extends ExchangeCommon {
@Builder @Builder
public static class Header { public static class Header {
@JacksonXmlProperty(localName = "COMMON") @JacksonXmlProperty(localName = "COMMON")
@JsonProperty(required = true)
private Common common; private Common common;
@JacksonXmlProperty(localName = "DIRECTION") @JacksonXmlProperty(localName = "DIRECTION")
@JsonProperty(required = true)
private Direction direction; private Direction direction;
@JacksonXmlProperty(localName = "ADDENDA") @JacksonXmlProperty(localName = "ADDENDA")
@ -82,6 +84,7 @@ public class ExchangeDto extends ExchangeCommon {
* all | final * all | final
*/ */
@JacksonXmlProperty(isAttribute = true, localName = "notification") @JacksonXmlProperty(isAttribute = true, localName = "notification")
@JsonProperty(required = true)
@Builder.Default @Builder.Default
String notification = "all"; String notification = "all";
@ -89,6 +92,7 @@ public class ExchangeDto extends ExchangeCommon {
private Lines lines; private Lines lines;
@JacksonXmlProperty(localName = "MODIFICATION_FLAG") @JacksonXmlProperty(localName = "MODIFICATION_FLAG")
@JsonProperty(required = true)
private ModificationFlag modificationFlag; private ModificationFlag modificationFlag;
} }
@ -98,12 +102,15 @@ public class ExchangeDto extends ExchangeCommon {
@Builder @Builder
public static class ToAdministrativeSystem { public static class ToAdministrativeSystem {
@JacksonXmlProperty(localName = "DOCNUM") @JacksonXmlProperty(localName = "DOCNUM")
@JsonProperty(required = true)
private Docnum docnum; private Docnum docnum;
@JacksonXmlProperty(localName = "SANCTION_INFO") @JacksonXmlProperty(localName = "SANCTION_INFO")
@JsonProperty(required = true)
private SanctionInfo sanctionInfo; private SanctionInfo sanctionInfo;
@JacksonXmlProperty(localName = "MODIFICATION_FLAG") @JacksonXmlProperty(localName = "MODIFICATION_FLAG")
@JsonProperty(required = true)
private ModificationFlag modificationFlag; private ModificationFlag modificationFlag;
} }
} }

@ -1,11 +1,16 @@
package cokr.xit.adds.inf.mois.model; package cokr.xit.adds.inf.mois.model;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.Base64Utils;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlCData;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
@ -14,6 +19,7 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText;
import jakarta.xml.bind.annotation.XmlValue; import jakarta.xml.bind.annotation.XmlValue;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** /**
@ -35,6 +41,7 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
@Getter
public class PackDto { public class PackDto {
@JacksonXmlProperty @JacksonXmlProperty
@JsonProperty(required = true) @JsonProperty(required = true)
@ -44,59 +51,157 @@ public class PackDto {
@JsonProperty(required = true) @JsonProperty(required = true)
protected Contents contents; protected Contents contents;
/**
* <pre>
*
* </pre>
*/
@JacksonXmlProperty(localName = "filename", isAttribute = true) @JacksonXmlProperty(localName = "filename", isAttribute = true)
@JsonProperty(required = true) @JsonProperty(required = true)
protected String filename; protected String filename;
@JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonInclude(JsonInclude.Include.NON_EMPTY)
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor
@Builder @Builder
@Getter
public static class Header { public static class Header {
/**
* <pre>
* docType
* send | fail |arrive | receive | invalid | submit | return |approval
* | | | || | |
*</pre>
*/
@JacksonXmlProperty @JacksonXmlProperty
@JsonProperty(required = true) @JsonProperty(required = true)
protected Type type; protected Type type;
/**
* <pre>
* : YYYY-MM-DD HH:mm:ss
*</pre>
*/
@JacksonXmlProperty @JacksonXmlProperty
@JsonProperty(required = true) @JsonProperty(required = true)
protected String date; protected String date;
/**
* <pre>
*
*</pre>
*/
@JacksonXmlProperty @JacksonXmlProperty
@JsonProperty(required = true) @JsonProperty(required = true)
protected String sender; protected String sender;
/**
* <pre>
*
*</pre>
*/
@JacksonXmlProperty @JacksonXmlProperty
@JsonProperty(required = true) @JsonProperty(required = true)
protected String receiver; protected String receiver;
/**
* <pre>
* ID
*</pre>
*/
@JacksonXmlProperty(localName = "sender_userid") @JacksonXmlProperty(localName = "sender_userid")
@JsonProperty(required = true) @JsonProperty(required = true)
protected String senderUserid; protected String senderUserid;
/**
* <pre>
* ID
*</pre>
*/
@JacksonXmlProperty(localName = "receiver_userid") @JacksonXmlProperty(localName = "receiver_userid")
@JsonProperty(required = true) @JsonProperty(required = true)
protected String receiverUserid; protected String receiverUserid;
/**
* <pre>
*
* 0 ~ n
*</pre>
*/
@JacksonXmlProperty(localName = "sender_email") @JacksonXmlProperty(localName = "sender_email")
protected String senderEmail; protected String senderEmail;
/**
* <pre>
* - base64 encoding
* CDATA
*</pre>
*/
@JacksonXmlProperty(localName = "sender_orgname") @JacksonXmlProperty(localName = "sender_orgname")
@JsonProperty(required = true) @JsonProperty(required = true)
@JacksonXmlCData
protected String senderOrgname; protected String senderOrgname;
// public String getSenderOrgname() {
// return new String(Base64Utils.decodeFromString(senderOrgname));
// }
// public void setSenderOrgname(String senderOrgname) {
// this.senderOrgname = Base64Utils.encodeToString(senderOrgname.getBytes(StandardCharsets.UTF_8));
// }
/**
* <pre>
* - base64 encoding
* CDATA
*</pre>
*/
@JacksonXmlProperty(localName = "sender_systemname") @JacksonXmlProperty(localName = "sender_systemname")
@JsonProperty(required = true) @JsonProperty(required = true)
@JacksonXmlCData
protected String senderSystemname; protected String senderSystemname;
// public String getSenderSystemname() {
// return new String(Base64Utils.decodeFromString(senderSystemname));
// }
//public void setSenderSystemname(String senderSystemname) {
// this.senderSystemname = Base64Utils.encodeToString(senderSystemname.getBytes(StandardCharsets.UTF_8));
//}
/**
* <pre>
*
*</pre>
*/
@JacksonXmlProperty(localName = "administrative_num") @JacksonXmlProperty(localName = "administrative_num")
@JsonProperty(required = true) @JsonProperty(required = true)
protected String administrativeNum; protected String administrativeNum;
public Header(
Type type,
String date,
String sender,
String receiver,
String senderUserid,
String receiverUserid,
String senderEmail,
String senderOrgname,
String senderSystemname,
String administrativeNum) {
this.type = type;
this.date = date;
this.sender = sender;
this.receiver = receiver;
this.senderUserid = senderUserid;
this.receiverUserid = receiverUserid;
this.senderEmail = senderEmail;
this.senderOrgname = StringUtils.isEmpty(senderOrgname)? senderOrgname : Base64Utils.encodeToString(senderOrgname.getBytes(StandardCharsets.UTF_8));
this.senderSystemname = StringUtils.isEmpty(senderSystemname)? senderSystemname : Base64Utils.encodeToString(senderSystemname.getBytes(StandardCharsets.UTF_8));
this.administrativeNum = administrativeNum;
}
} }
@JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonInclude(JsonInclude.Include.NON_EMPTY)
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
@Getter
public static class Type { public static class Type {
/** /**
* <pre> * <pre>
@ -128,29 +233,91 @@ public class PackDto {
@JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonInclude(JsonInclude.Include.NON_EMPTY)
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor
@Builder @Builder
@Getter
public static class Content { public static class Content {
/**
* <pre>
* content - base64 encoding
* CDATA
*</pre>
*/
@XmlValue @XmlValue
@JacksonXmlText @JacksonXmlText
@JacksonXmlCData
protected String value; protected String value;
// public String getValue() {
// return new String(Base64Utils.decodeFromString(value));
// }
// public void setValue(String value) {
// this.value = Base64Utils.encodeToString(value.getBytes(StandardCharsets.UTF_8));
// }
/**
* <pre>
* content
* exchange -
* notification -
* attch -
* attch_xml - XML
* attch_xsl - XSL
* fail - (text)
* </pre>
*/
@JacksonXmlProperty(localName = "content-role", isAttribute = true) @JacksonXmlProperty(localName = "content-role", isAttribute = true)
@JsonProperty(required = true) @JsonProperty(required = true)
protected String contentRole; protected String contentRole;
/**
* - default base64
*/
@JacksonXmlProperty(localName = "content-transfer-encoding", isAttribute = true) @JacksonXmlProperty(localName = "content-transfer-encoding", isAttribute = true)
protected String contentTransferEncoding = "base64"; protected String contentTransferEncoding = "base64";
/**
* - base64 encoding
* CDATA
*/
@JacksonXmlProperty(localName = "filename", isAttribute = true) @JacksonXmlProperty(localName = "filename", isAttribute = true)
@JsonProperty(required = true) @JsonProperty(required = true)
@JacksonXmlCData
protected String filename; protected String filename;
// public String getFilename() {
// return new String(Base64Utils.decodeFromString(filename));
// }
// public void setFilename(String filename) {
// this.filename = Base64Utils.encodeToString(filename.getBytes(StandardCharsets.UTF_8));
// }
/**
* content-type(MIME)
*/
@JacksonXmlProperty(localName = "content-type", isAttribute = true) @JacksonXmlProperty(localName = "content-type", isAttribute = true)
protected String contentType; protected String contentType;
/**
* charset
*/
@JacksonXmlProperty(localName = "charset", isAttribute = true) @JacksonXmlProperty(localName = "charset", isAttribute = true)
protected String charset; protected String charset;
public Content(
String value,
String contentRole,
String contentTransferEncoding,
String filename,
String contentType,
String charset) {
this.value = StringUtils.isEmpty(value)? value : Base64Utils.encodeToString(value.getBytes(StandardCharsets.UTF_8));
this.contentRole = contentRole;
if(!StringUtils.isEmpty(contentTransferEncoding)){
this.contentTransferEncoding = contentTransferEncoding;
}
this.filename = StringUtils.isEmpty(filename)? filename : Base64Utils.encodeToString(filename.getBytes(StandardCharsets.UTF_8));
this.contentType = contentType;
this.charset = charset;
}
} }
public void configureXmlMapper(XmlMapper xmlMapper) { public void configureXmlMapper(XmlMapper xmlMapper) {

@ -1,27 +1,27 @@
<?xml version="1.0" encoding="EUC-KR" ?> <?xml version="1.0" encoding="EUC-KR" ?>
<!ELEMENT pack (header, contents)> <!ELEMENT pack (header, contents)>
<!ATTLIST pack filename CDATA #REQUIRED > <!ATTLIST pack filename CDATA #REQUIRED >
<!ELEMENT header (type, date, sender, receiver, sender_userid, receiver_userid, sender_email?,sender_orgname, sender_systemname?, administrative_num)> <!ELEMENT header (type, date, sender, receiver, sender_userid, receiver_userid, sender_email?,sender_orgname, sender_systemname?, administrative_num)>
<!ELEMENT type EMPTY> <!ELEMENT type EMPTY>
<!ATTLIST type doc-type (send|fail|arrive|receive|invalid|submit|return|approval) #REQUIRED >` <!ATTLIST type doc-type (send|fail|arrive|receive|invalid|submit|return|approval) #REQUIRED >
<!ELEMENT date (#PCDATA)> <!ELEMENT date (#PCDATA)>
<!ELEMENT sender (#PCDATA)> <!ELEMENT sender (#PCDATA)>
<!ELEMENT receiver (#PCDATA)> <!ELEMENT receiver (#PCDATA)>
<!ELEMENT sender_userid (#PCDATA)> <!ELEMENT sender_userid (#PCDATA)>
<!ELEMENT receiver_userid (#PCDATA)> <!ELEMENT receiver_userid (#PCDATA)>
<!ELEMENT sender_email (#PCDATA)> <!ELEMENT sender_email (#PCDATA)>
<!ELEMENT sender_orgname (#PCDATA)> <!ELEMENT sender_orgname (#PCDATA)>
<!ELEMENT sender_systemname (#PCDATA)> <!ELEMENT sender_systemname (#PCDATA)>
<!ELEMENT administrative_num (#PCDATA)> <!ELEMENT administrative_num (#PCDATA)>
<!ELEMENT contents (content)*> <!ELEMENT contents (content)*>
<!ELEMENT content (#PCDATA)> <!ELEMENT content (#PCDATA)>
<!ATTLIST content content-role CDATA #REQUIRED > <!ATTLIST content content-role CDATA #REQUIRED >
<!ATTLIST content content-transfer-encoding CDATA "base64" > <!ATTLIST content content-transfer-encoding CDATA "base64" >
<!ATTLIST content filename CDATA #REQUIRED > <!ATTLIST content filename CDATA #REQUIRED >
<!ATTLIST content content-type CDATA #IMPLIED > <!ATTLIST content content-type CDATA #IMPLIED >
<!ATTLIST content charset CDATA #IMPLIED > <!ATTLIST content charset CDATA #IMPLIED >

@ -1,20 +1,36 @@
package cokr.xit.adds.inf.mois.model; package cokr.xit.adds.inf.mois.model;
import java.io.FileOutputStream; import static org.junit.jupiter.api.Assertions.*;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader;
import java.util.List; import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.util.Base64Utils;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule; import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import cokr.xit.adds.core.spring.exception.ApiCustomException;
import cokr.xit.foundation.data.XML; import cokr.xit.foundation.data.XML;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -79,10 +95,20 @@ public class PackDtoTest {
// xmlMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, true); // xmlMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, true);
// }; // };
// xml.configure(configurer); // xml.configure(configurer);
PackDto dto = xml.parse(packXml, new TypeReference<PackDto>() {}); FileInputStream fileInputStream = new FileInputStream("pack.xml");
byte[] bytes = fileInputStream.readAllBytes();
String content = new String(bytes);
PackDto dto = xml.parse(content, new TypeReference<PackDto>() {});
log.info("dto: {}", dto); log.info("dto: {}", dto);
xml.write(System.out, dto, true); xml.write(System.out, dto, true);
assertEquals("senderOrgname", new String(Base64Utils.decodeFromString(dto.getHeader().getSenderOrgname())));
assertEquals("senderSystemname", new String(Base64Utils.decodeFromString(dto.getHeader().getSenderSystemname())));
assertEquals("filename", new String(Base64Utils.decodeFromString(dto.getContents().getContent().get(0).getFilename())));
assertEquals("content-value", new String(Base64Utils.decodeFromString(dto.getContents().getContent().get(0).getValue())));
// XmlMapper xmlMapper = new XmlMapper(); // XmlMapper xmlMapper = new XmlMapper();
// xmlMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, true); // xmlMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, true);
// PackDto dto = xmlMapper.readValue(packXml, PackDto.class); // PackDto dto = xmlMapper.readValue(packXml, PackDto.class);
@ -102,27 +128,53 @@ public class PackDtoTest {
XMLOutputFactory factory = mapper.getFactory().getXMLOutputFactory(); XMLOutputFactory factory = mapper.getFactory().getXMLOutputFactory();
String dtd = """ String dtd = """
<!DOCTYPE EXCHANGE SYSTEM "exchange.dtd"> <!DOCTYPE pack SYSTEM "pack.dtd">
"""; """;
// FIXME: 파일명 생성 try (FileWriter w = new FileWriter("pack.xml")) {
try (FileOutputStream fos = new FileOutputStream("pack.xml");) { XMLStreamWriter sw = factory.createXMLStreamWriter(w);
XML xml = new XML(); sw.writeStartDocument("EUC-KR", "1.0");
//dto.configureXmlMapper(xml.getXmlMapper()); sw.writeDTD("\n"+dtd);
xml.write(fos, dto, true); mapper.enable(SerializationFeature.INDENT_OUTPUT);
xml.write(System.out, dto, true); mapper.writeValue(sw, dto);
// StringWriter swr = new StringWriter();
// XmlMapper xmlMapper = new XmlMapper(); // mapper.writeValue(swr, dto);
// dto.configureXmlMapper(xmlMapper); // System.out.println(swr.toString());
// //xmlMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, true);
// String str = xmlMapper.writeValueAsString(dto); // FileInputStream fileInputStream = new FileInputStream("pack.xml");
// System.out.println("Generated XML:"); // byte[] bytes = fileInputStream.readAllBytes();
// System.out.println(str); // String content = new String(bytes);
//fos.flush(); // System.out.println(content);
}catch (Exception e) { // PackDto rtnDto = toObjByXml(content, PackDto.class);
//
// StringWriter swr = new StringWriter();
// mapper.writeValue(swr, content);
//System.out.println(swr.toString());
}catch (XMLStreamException e) {
e.printStackTrace(); e.printStackTrace();
} }
// FIXME: 파일명 생성
// try (FileOutputStream fos = new FileOutputStream("pack.xml");) {
// XML xml = new XML();
// //dto.configureXmlMapper(xml.getXmlMapper());
// xml.write(fos, dto, true);
// xml.write(System.out, dto, true);
// // XmlMapper xmlMapper = new XmlMapper();
// // dto.configureXmlMapper(xmlMapper);
// // //xmlMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, true);
// // String str = xmlMapper.writeValueAsString(dto);
// // System.out.println("Generated XML:");
// // System.out.println(str);
// //fos.flush();
//
// }catch (Exception e) {
// e.printStackTrace();
// }
} }
private static PackDto getPackDto() { private static PackDto getPackDto() {
@ -146,6 +198,7 @@ public class PackDtoTest {
.contentRole("contentRole") .contentRole("contentRole")
.contentType("constentType") .contentType("constentType")
.charset("utf8") .charset("utf8")
.filename("filename")
.value("content-value") .value("content-value")
.build(); .build();
@ -160,4 +213,17 @@ public class PackDtoTest {
return packDto; return packDto;
} }
private static <T> T toObjByXml(String xml, final Class<T> cls){
ObjectMapper OM = new ObjectMapper();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(xml)));
return new XML().parse(xml, cls);
} catch (ParserConfigurationException | SAXException | IOException e) {
throw ApiCustomException.create(e.getMessage());
}
}
} }

Loading…
Cancel
Save