From 19d81dede576abcb03921db0f7f758a91e64b88a Mon Sep 17 00:00:00 2001 From: "Jonguk. Lim" Date: Wed, 8 May 2024 18:10:52 +0900 Subject: [PATCH] =?UTF-8?q?ExchangeDto,=20test=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../adds/inf/mois/model/ExchangeCommon.java | 27 +++- .../xit/adds/inf/mois/model/ExchangeDto.java | 16 +- .../adds/inf/mois/model/ExchangepackDto.java | 3 - .../cokr/xit/adds/inf/mois/model/PackDto.java | 9 +- .../adds/inf/mois/model/ExchangeDtoTest.java | 151 +++++++++++++----- .../xit/adds/inf/mois/model/PackDtoTest.java | 33 +++- 7 files changed, 181 insertions(+), 59 deletions(-) diff --git a/.gitignore b/.gitignore index d5d585e..3a28696 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ build/ ### h2db ### *.mv.db *exchange*.xml +pack.xml diff --git a/src/main/java/cokr/xit/adds/inf/mois/model/ExchangeCommon.java b/src/main/java/cokr/xit/adds/inf/mois/model/ExchangeCommon.java index 21eb22e..85fb6ee 100644 --- a/src/main/java/cokr/xit/adds/inf/mois/model/ExchangeCommon.java +++ b/src/main/java/cokr/xit/adds/inf/mois/model/ExchangeCommon.java @@ -3,6 +3,7 @@ package cokr.xit.adds.inf.mois.model; import java.util.List; 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.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText; @@ -42,6 +43,7 @@ public class ExchangeCommon { private Receiver receiver; @JacksonXmlProperty(localName = "TITLE") + @JacksonXmlCData private String title; @JacksonXmlProperty(localName = "CREATED_DATE") @@ -96,6 +98,7 @@ public class ExchangeCommon { @XmlValue @JacksonXmlText + @JacksonXmlCData private String value; } @@ -104,6 +107,9 @@ public class ExchangeCommon { @AllArgsConstructor @Builder public static class SanctionInfo { + /** + * 진행| 완료 + */ @JacksonXmlProperty(localName = "status", isAttribute = true) private String status; @@ -138,9 +144,19 @@ public class ExchangeCommon { @AllArgsConstructor @Builder public static class Sanction { + /** + *
+         *     상신 | 기안취소 | 승인 | 반려 | 미결
+         * 
+ */ @JacksonXmlProperty(localName = "result", isAttribute = true) private String result; + /** + *
+         *     기안 | 검토 | 협조 | 전결 | 대결 | 결재
+         * 
+ */ @JacksonXmlProperty(localName = "type", isAttribute = true) private String type; @@ -148,6 +164,7 @@ public class ExchangeCommon { private Person person; @JacksonXmlProperty(localName = "COMMENT") + @JacksonXmlCData private String comment; @JacksonXmlProperty(localName = "DATE") @@ -169,9 +186,11 @@ public class ExchangeCommon { private String position; @JacksonXmlProperty(localName = "DEPT") + @JacksonXmlCData private String dept; @JacksonXmlProperty(localName = "ORG") + @JacksonXmlCData private String org; } @@ -192,8 +211,12 @@ public class ExchangeCommon { @AllArgsConstructor @Builder public static class Modifiable { + /** + * yes | no + */ @JacksonXmlProperty(localName = "modifyflag", isAttribute = true) - private String modifyflag; + @Builder.Default + private String modifyflag = "no"; } @JsonInclude(JsonInclude.Include.NON_NULL) @@ -218,6 +241,7 @@ public class ExchangeCommon { @XmlValue @JacksonXmlText + @JacksonXmlCData private String value; } @@ -283,6 +307,7 @@ public class ExchangeCommon { @XmlValue @JacksonXmlText + @JacksonXmlCData private String value; } } diff --git a/src/main/java/cokr/xit/adds/inf/mois/model/ExchangeDto.java b/src/main/java/cokr/xit/adds/inf/mois/model/ExchangeDto.java index ceb6c42..c6d97d1 100644 --- a/src/main/java/cokr/xit/adds/inf/mois/model/ExchangeDto.java +++ b/src/main/java/cokr/xit/adds/inf/mois/model/ExchangeDto.java @@ -1,6 +1,7 @@ package cokr.xit.adds.inf.mois.model; 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.JacksonXmlRootElement; @@ -33,6 +34,7 @@ public class ExchangeDto extends ExchangeCommon { private Header header; @JacksonXmlProperty(localName = "BODY") + @JacksonXmlCData private String body; @JacksonXmlProperty(localName = "ATTACHMENTS") @@ -53,6 +55,12 @@ public class ExchangeDto extends ExchangeCommon { private Addenda addenda; } + /** + *
+     * ToDocumentSystem | ToAdministrativeSystem
+     * or 관계 - 둘중 하나만 사용 되어야 한다
+     * 
+ */ @JsonInclude(JsonInclude.Include.NON_NULL) @NoArgsConstructor @AllArgsConstructor @@ -62,7 +70,7 @@ public class ExchangeDto extends ExchangeCommon { private ToDocumentSystem toDocumentSystem; @JacksonXmlProperty(localName = "TO_ADMINISTRATIVE_SYSTEM") - private ExchangeMisDto.ToAdministrativeSystem toAdministrativeSystem; + private ToAdministrativeSystem toAdministrativeSystem; } @JsonInclude(JsonInclude.Include.NON_NULL) @@ -70,8 +78,12 @@ public class ExchangeDto extends ExchangeCommon { @AllArgsConstructor @Builder public static class ToDocumentSystem { + /** + * all | final + */ @JacksonXmlProperty(isAttribute = true, localName = "notification") - String notification; + @Builder.Default + String notification = "all"; @JacksonXmlProperty(localName = "LINES") private Lines lines; diff --git a/src/main/java/cokr/xit/adds/inf/mois/model/ExchangepackDto.java b/src/main/java/cokr/xit/adds/inf/mois/model/ExchangepackDto.java index 28ab7af..44c992a 100644 --- a/src/main/java/cokr/xit/adds/inf/mois/model/ExchangepackDto.java +++ b/src/main/java/cokr/xit/adds/inf/mois/model/ExchangepackDto.java @@ -10,8 +10,6 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText; 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.Builder; import lombok.NoArgsConstructor; @@ -286,7 +284,6 @@ public class ExchangepackDto { * */ @JacksonXmlProperty(localName = "modify", isAttribute = true) - @XmlJavaTypeAdapter(CollapsedStringAdapter.class) @Builder.Default protected String modify = "non"; } diff --git a/src/main/java/cokr/xit/adds/inf/mois/model/PackDto.java b/src/main/java/cokr/xit/adds/inf/mois/model/PackDto.java index 99d7481..4e1ddf4 100644 --- a/src/main/java/cokr/xit/adds/inf/mois/model/PackDto.java +++ b/src/main/java/cokr/xit/adds/inf/mois/model/PackDto.java @@ -5,14 +5,13 @@ import java.util.List; import com.fasterxml.jackson.annotation.JsonInclude; 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.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText; 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.Builder; import lombok.NoArgsConstructor; @@ -107,7 +106,6 @@ public class PackDto { */ @JacksonXmlProperty(localName = "doc-type", isAttribute = true) @JsonProperty(required = true) - @XmlJavaTypeAdapter(CollapsedStringAdapter.class) protected String docType; } @@ -154,4 +152,9 @@ public class PackDto { @JacksonXmlProperty(localName = "charset", isAttribute = true) protected String charset; } + + public void configureXmlMapper(XmlMapper xmlMapper) { + // 필수 필드 체크를 활성화 + xmlMapper.configure(com.fasterxml.jackson.databind.SerializationFeature.FAIL_ON_EMPTY_BEANS, true); + } } diff --git a/src/test/java/cokr/xit/adds/inf/mois/model/ExchangeDtoTest.java b/src/test/java/cokr/xit/adds/inf/mois/model/ExchangeDtoTest.java index aec802d..2c944e0 100644 --- a/src/test/java/cokr/xit/adds/inf/mois/model/ExchangeDtoTest.java +++ b/src/test/java/cokr/xit/adds/inf/mois/model/ExchangeDtoTest.java @@ -65,36 +65,36 @@ public class ExchangeDtoTest { - - - 1 - - - hongkildong - 홍길동 - 전산주사 - - - - - 2007-01-25 14:45:34 - - - - final - - - parkchulsoo - 박철수 - 팀장 - - - - - 2007-01-25 14:45:34 - - - + + + 1 + + + hongkildong + 홍길동 + 전산주사 + + + + + 2007-01-25 14:45:34 + + + + final + + + parkchulsoo + 박철수 + 팀장 + + + + + 2007-01-25 14:45:34 + + + @@ -152,12 +152,12 @@ public class ExchangeDtoTest { """; // FIXME: 파일명 생성 - try (FileWriter w = new FileWriter("exchange_exchange_1.xml")) { + try (FileWriter w = new FileWriter("exchange.xml")) { XMLStreamWriter sw = factory.createXMLStreamWriter(w); sw.writeStartDocument("EUC-KR", "1.0"); sw.writeDTD("\n"+dtd); mapper.enable(SerializationFeature.INDENT_OUTPUT); - //mapper.writeValue(sw, dto); + mapper.writeValue(sw, dto); @@ -190,19 +190,82 @@ public class ExchangeDtoTest { .administrativeNum("APP20060000000004075") .build(); - ExchangeDto.Direction direction = ExchangeDto.Direction.builder() - .toDocumentSystem( - ExchangeDto.ToDocumentSystem.builder() - .notification("all") - .modificationFlag( - ExchangeDto.ModificationFlag.builder() - .modifiable( - ExchangeDto.Modifiable.builder() - .modifyflag("yes") - .build()) + + ExchangeDto.Docnum docnum = ExchangeCommon.Docnum.builder() + .docnumcode("1310000012699") + .value("고도화팀-2699") + .build(); + + ExchangeCommon.Line line1 = ExchangeCommon.Line.builder() + .level("1") + .sanction( + 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(); + + 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(); ExchangeDto.Header header = ExchangeDto.Header.builder() diff --git a/src/test/java/cokr/xit/adds/inf/mois/model/PackDtoTest.java b/src/test/java/cokr/xit/adds/inf/mois/model/PackDtoTest.java index 14e3616..5db65ef 100644 --- a/src/test/java/cokr/xit/adds/inf/mois/model/PackDtoTest.java +++ b/src/test/java/cokr/xit/adds/inf/mois/model/PackDtoTest.java @@ -40,8 +40,8 @@ public class PackDtoTest {
- - 2024-03-14 + send + 20241231 sender receiver senderUserid @@ -74,9 +74,20 @@ public class PackDtoTest { // xmlMapper.writeValue(System.out, dto); XML xml = new XML(); + // Consumer configurer = xmlMapper -> { + // // 필수 필드 체크를 활성화 + // xmlMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, true); + // }; + // xml.configure(configurer); PackDto dto = xml.parse(packXml, new TypeReference() {}); log.info("dto: {}", dto); 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 테스트") @@ -96,8 +107,18 @@ public class PackDtoTest { // FIXME: 파일명 생성 try (FileOutputStream fos = new FileOutputStream("pack.xml");) { XML xml = new XML(); + //dto.configureXmlMapper(xml.getXmlMapper()); 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) { e.printStackTrace(); @@ -108,9 +129,9 @@ public class PackDtoTest { PackDto.Header header = PackDto.Header.builder() .type(PackDto.Type.builder() - .docType("docType") - .build()) - .date("2024-03-14") + .docType("send") + .build()) + .date("20241231") .sender("sender") .receiver("receiver") .senderUserid("senderUserid")