ExchangeDto, test 반영

dev
Jonguk. Lim 6 months ago
parent 058211770c
commit 19d81dede5

1
.gitignore vendored

@ -35,3 +35,4 @@ build/
### h2db ### ### h2db ###
*.mv.db *.mv.db
*exchange*.xml *exchange*.xml
pack.xml

@ -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.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.JacksonXmlText; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText;
@ -42,6 +43,7 @@ public class ExchangeCommon {
private Receiver receiver; private Receiver receiver;
@JacksonXmlProperty(localName = "TITLE") @JacksonXmlProperty(localName = "TITLE")
@JacksonXmlCData
private String title; private String title;
@JacksonXmlProperty(localName = "CREATED_DATE") @JacksonXmlProperty(localName = "CREATED_DATE")
@ -96,6 +98,7 @@ public class ExchangeCommon {
@XmlValue @XmlValue
@JacksonXmlText @JacksonXmlText
@JacksonXmlCData
private String value; private String value;
} }
@ -104,6 +107,9 @@ public class ExchangeCommon {
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public static class SanctionInfo { public static class SanctionInfo {
/**
* |
*/
@JacksonXmlProperty(localName = "status", isAttribute = true) @JacksonXmlProperty(localName = "status", isAttribute = true)
private String status; private String status;
@ -138,9 +144,19 @@ public class ExchangeCommon {
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public static class Sanction { public static class Sanction {
/**
* <pre>
* | | | |
* </pre>
*/
@JacksonXmlProperty(localName = "result", isAttribute = true) @JacksonXmlProperty(localName = "result", isAttribute = true)
private String result; private String result;
/**
* <pre>
* | | | | |
* </pre>
*/
@JacksonXmlProperty(localName = "type", isAttribute = true) @JacksonXmlProperty(localName = "type", isAttribute = true)
private String type; private String type;
@ -148,6 +164,7 @@ public class ExchangeCommon {
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")
@ -169,9 +186,11 @@ public class ExchangeCommon {
private String position; private String position;
@JacksonXmlProperty(localName = "DEPT") @JacksonXmlProperty(localName = "DEPT")
@JacksonXmlCData
private String dept; private String dept;
@JacksonXmlProperty(localName = "ORG") @JacksonXmlProperty(localName = "ORG")
@JacksonXmlCData
private String org; private String org;
} }
@ -192,8 +211,12 @@ public class ExchangeCommon {
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public static class Modifiable { public static class Modifiable {
/**
* yes | no
*/
@JacksonXmlProperty(localName = "modifyflag", isAttribute = true) @JacksonXmlProperty(localName = "modifyflag", isAttribute = true)
private String modifyflag; @Builder.Default
private String modifyflag = "no";
} }
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
@ -218,6 +241,7 @@ public class ExchangeCommon {
@XmlValue @XmlValue
@JacksonXmlText @JacksonXmlText
@JacksonXmlCData
private String value; private String value;
} }
@ -283,6 +307,7 @@ public class ExchangeCommon {
@XmlValue @XmlValue
@JacksonXmlText @JacksonXmlText
@JacksonXmlCData
private String value; private String value;
} }
} }

@ -1,6 +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.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;
@ -33,6 +34,7 @@ public class ExchangeDto extends ExchangeCommon {
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")
@ -53,6 +55,12 @@ public class ExchangeDto extends ExchangeCommon {
private Addenda addenda; private Addenda addenda;
} }
/**
* <pre>
* ToDocumentSystem | ToAdministrativeSystem
* or -
* </pre>
*/
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@ -62,7 +70,7 @@ public class ExchangeDto extends ExchangeCommon {
private ToDocumentSystem toDocumentSystem; private ToDocumentSystem toDocumentSystem;
@JacksonXmlProperty(localName = "TO_ADMINISTRATIVE_SYSTEM") @JacksonXmlProperty(localName = "TO_ADMINISTRATIVE_SYSTEM")
private ExchangeMisDto.ToAdministrativeSystem toAdministrativeSystem; private ToAdministrativeSystem toAdministrativeSystem;
} }
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
@ -70,8 +78,12 @@ public class ExchangeDto extends ExchangeCommon {
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public static class ToDocumentSystem { public static class ToDocumentSystem {
/**
* all | final
*/
@JacksonXmlProperty(isAttribute = true, localName = "notification") @JacksonXmlProperty(isAttribute = true, localName = "notification")
String notification; @Builder.Default
String notification = "all";
@JacksonXmlProperty(localName = "LINES") @JacksonXmlProperty(localName = "LINES")
private Lines lines; private Lines lines;

@ -10,8 +10,6 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText;
import jakarta.xml.bind.annotation.XmlValue; import jakarta.xml.bind.annotation.XmlValue;
import jakarta.xml.bind.annotation.adapters.CollapsedStringAdapter;
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -286,7 +284,6 @@ public class ExchangepackDto {
* </pre> * </pre>
*/ */
@JacksonXmlProperty(localName = "modify", isAttribute = true) @JacksonXmlProperty(localName = "modify", isAttribute = true)
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@Builder.Default @Builder.Default
protected String modify = "non"; protected String modify = "non";
} }

@ -5,14 +5,13 @@ 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.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
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;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText;
import jakarta.xml.bind.annotation.XmlValue; import jakarta.xml.bind.annotation.XmlValue;
import jakarta.xml.bind.annotation.adapters.CollapsedStringAdapter;
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -107,7 +106,6 @@ public class PackDto {
*/ */
@JacksonXmlProperty(localName = "doc-type", isAttribute = true) @JacksonXmlProperty(localName = "doc-type", isAttribute = true)
@JsonProperty(required = true) @JsonProperty(required = true)
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
protected String docType; protected String docType;
} }
@ -154,4 +152,9 @@ public class PackDto {
@JacksonXmlProperty(localName = "charset", isAttribute = true) @JacksonXmlProperty(localName = "charset", isAttribute = true)
protected String charset; protected String charset;
} }
public void configureXmlMapper(XmlMapper xmlMapper) {
// 필수 필드 체크를 활성화
xmlMapper.configure(com.fasterxml.jackson.databind.SerializationFeature.FAIL_ON_EMPTY_BEANS, true);
}
} }

@ -65,36 +65,36 @@ public class ExchangeDtoTest {
<TO_ADMINISTRATIVE_SYSTEM> <TO_ADMINISTRATIVE_SYSTEM>
<DOCNUM docnumcode="1310000012699"><![CDATA[-2699]]></DOCNUM> <DOCNUM docnumcode="1310000012699"><![CDATA[-2699]]></DOCNUM>
<SANCTION_INFO status="완료"> <SANCTION_INFO status="완료">
<LINES> <LINES>
<LINE> <LINE>
<LEVEL>1</LEVEL> <LEVEL>1</LEVEL>
<SANCTION result="상신" type="기안"> <SANCTION result="상신" type="기안">
<PERSON> <PERSON>
<USERID>hongkildong</USERID> <USERID>hongkildong</USERID>
<NAME></NAME> <NAME></NAME>
<POSITION></POSITION> <POSITION></POSITION>
<DEPT><![CDATA[]]></DEPT> <DEPT><![CDATA[]]></DEPT>
<ORG><![CDATA[]]></ORG> <ORG><![CDATA[]]></ORG>
</PERSON> </PERSON>
<COMMENT><![CDATA[ .]]></COMMENT> <COMMENT><![CDATA[ .]]></COMMENT>
<DATE>2007-01-25 14:45:34</DATE> <DATE>2007-01-25 14:45:34</DATE>
</SANCTION> </SANCTION>
</LINE> </LINE>
<LINE> <LINE>
<LEVEL>final</LEVEL> <LEVEL>final</LEVEL>
<SANCTION result="결재" type="결재"> <SANCTION result="결재" type="결재">
<PERSON> <PERSON>
<USERID>parkchulsoo</USERID> <USERID>parkchulsoo</USERID>
<NAME></NAME> <NAME></NAME>
<POSITION></POSITION> <POSITION></POSITION>
<DEPT><![CDATA[]]></DEPT> <DEPT><![CDATA[]]></DEPT>
<ORG><![CDATA[]]></ORG> <ORG><![CDATA[]]></ORG>
</PERSON> </PERSON>
<COMMENT><![CDATA[ .]]></COMMENT> <COMMENT><![CDATA[ .]]></COMMENT>
<DATE>2007-01-25 14:45:34</DATE> <DATE>2007-01-25 14:45:34</DATE>
</SANCTION> </SANCTION>
</LINE> </LINE>
</LINES> </LINES>
</SANCTION_INFO> </SANCTION_INFO>
<MODIFICATION_FLAG> <MODIFICATION_FLAG>
<MODIFIABLE modifyflag="no"/> <MODIFIABLE modifyflag="no"/>
@ -152,12 +152,12 @@ public class ExchangeDtoTest {
<!DOCTYPE EXCHANGE SYSTEM "exchange.dtd"> <!DOCTYPE EXCHANGE SYSTEM "exchange.dtd">
"""; """;
// FIXME: 파일명 생성 // FIXME: 파일명 생성
try (FileWriter w = new FileWriter("exchange_exchange_1.xml")) { try (FileWriter w = new FileWriter("exchange.xml")) {
XMLStreamWriter sw = factory.createXMLStreamWriter(w); XMLStreamWriter sw = factory.createXMLStreamWriter(w);
sw.writeStartDocument("EUC-KR", "1.0"); sw.writeStartDocument("EUC-KR", "1.0");
sw.writeDTD("\n"+dtd); sw.writeDTD("\n"+dtd);
mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.enable(SerializationFeature.INDENT_OUTPUT);
//mapper.writeValue(sw, dto); mapper.writeValue(sw, dto);
@ -190,19 +190,82 @@ public class ExchangeDtoTest {
.administrativeNum("APP20060000000004075") .administrativeNum("APP20060000000004075")
.build(); .build();
ExchangeDto.Direction direction = ExchangeDto.Direction.builder()
.toDocumentSystem( ExchangeDto.Docnum docnum = ExchangeCommon.Docnum.builder()
ExchangeDto.ToDocumentSystem.builder() .docnumcode("1310000012699")
.notification("all") .value("고도화팀-2699")
.modificationFlag( .build();
ExchangeDto.ModificationFlag.builder()
.modifiable( ExchangeCommon.Line line1 = ExchangeCommon.Line.builder()
ExchangeDto.Modifiable.builder() .level("1")
.modifyflag("yes") .sanction(
.build()) ExchangeCommon.Sanction.builder()
.result("상신")
.type("기안")
.person(
ExchangeCommon.Person.builder()
.userid("hongkildong")
.name("홍길동")
.position("전산주사")
.dept("고도화팀")
.org("행정안전부")
.build())
.comment("보고자 의견입니다.")
.date("2007-01-25 14:45:34")
.build())
.build();
ExchangeCommon.Line line2 = ExchangeCommon.Line.builder()
.level("1")
.sanction(
ExchangeCommon.Sanction.builder()
.result("상신")
.type("기안")
.person(
ExchangeCommon.Person.builder()
.userid("hongkildong1")
.name("홍길동1")
.position("전산주사1")
.dept("고도화팀1")
.org("행정안전부1")
.build())
.comment("보고자 의견입니다1.")
.date("2007-01-25 14:45:34")
.build())
.build();
ExchangeDto.ToAdministrativeSystem administrativeSystem = ExchangeDto.ToAdministrativeSystem.builder()
.docnum(docnum)
.sanctionInfo(
ExchangeDto.SanctionInfo.builder()
.status("완료")
.lines(ExchangeDto.Lines.builder()
.line(List.of(line1, line2))
.build())
.build())
.modificationFlag(
ExchangeDto.ModificationFlag.builder()
.modifiable(
ExchangeDto.Modifiable.builder()
.modifyflag("no")
.build()) .build())
.build() .build())
) .build();
ExchangeDto.Direction direction = ExchangeDto.Direction.builder()
// .toDocumentSystem(
// ExchangeDto.ToDocumentSystem.builder()
// .notification("all")
// .modificationFlag(
// ExchangeDto.ModificationFlag.builder()
// .modifiable(
// ExchangeDto.Modifiable.builder()
// .modifyflag("yes")
// .build())
// .build())
// .build()
// )
.toAdministrativeSystem(administrativeSystem)
.build(); .build();
ExchangeDto.Header header = ExchangeDto.Header.builder() ExchangeDto.Header header = ExchangeDto.Header.builder()

@ -40,8 +40,8 @@ public class PackDtoTest {
<?xml version='1.1' encoding='UTF-8'?> <?xml version='1.1' encoding='UTF-8'?>
<pack filename="filename"> <pack filename="filename">
<header> <header>
<type doc-type="docType"/> <doc-type>send</doc-type>
<date>2024-03-14</date> <date>20241231</date>
<sender>sender</sender> <sender>sender</sender>
<receiver>receiver</receiver> <receiver>receiver</receiver>
<sender_userid>senderUserid</sender_userid> <sender_userid>senderUserid</sender_userid>
@ -74,9 +74,20 @@ public class PackDtoTest {
// xmlMapper.writeValue(System.out, dto); // xmlMapper.writeValue(System.out, dto);
XML xml = new XML(); XML xml = new XML();
// Consumer<XmlMapper> configurer = xmlMapper -> {
// // 필수 필드 체크를 활성화
// xmlMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, true);
// };
// xml.configure(configurer);
PackDto dto = xml.parse(packXml, new TypeReference<PackDto>() {}); PackDto dto = xml.parse(packXml, new TypeReference<PackDto>() {});
log.info("dto: {}", dto); log.info("dto: {}", dto);
xml.write(System.out, dto, true); xml.write(System.out, dto, true);
// XmlMapper xmlMapper = new XmlMapper();
// xmlMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, true);
// PackDto dto = xmlMapper.readValue(packXml, PackDto.class);
// System.out.println("Generated XML:");
// xmlMapper.writeValue(System.out, dto);
} }
@DisplayName("전자결재 pack xml write 테스트") @DisplayName("전자결재 pack xml write 테스트")
@ -96,8 +107,18 @@ public class PackDtoTest {
// FIXME: 파일명 생성 // FIXME: 파일명 생성
try (FileOutputStream fos = new FileOutputStream("pack.xml");) { try (FileOutputStream fos = new FileOutputStream("pack.xml");) {
XML xml = new XML(); XML xml = new XML();
//dto.configureXmlMapper(xml.getXmlMapper());
xml.write(fos, dto, true); xml.write(fos, dto, true);
fos.flush(); 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) { }catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -108,9 +129,9 @@ public class PackDtoTest {
PackDto.Header header = PackDto.Header.builder() PackDto.Header header = PackDto.Header.builder()
.type(PackDto.Type.builder() .type(PackDto.Type.builder()
.docType("docType") .docType("send")
.build()) .build())
.date("2024-03-14") .date("20241231")
.sender("sender") .sender("sender")
.receiver("receiver") .receiver("receiver")
.senderUserid("senderUserid") .senderUserid("senderUserid")

Loading…
Cancel
Save