ExchangeDto, test 반영

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

1
.gitignore vendored

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

@ -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 {
/**
* <pre>
* | | | |
* </pre>
*/
@JacksonXmlProperty(localName = "result", isAttribute = true)
private String result;
/**
* <pre>
* | | | | |
* </pre>
*/
@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;
}
}

@ -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;
}
/**
* <pre>
* ToDocumentSystem | ToAdministrativeSystem
* or -
* </pre>
*/
@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;

@ -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 {
* </pre>
*/
@JacksonXmlProperty(localName = "modify", isAttribute = true)
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@Builder.Default
protected String modify = "non";
}

@ -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);
}
}

@ -152,12 +152,12 @@ public class ExchangeDtoTest {
<!DOCTYPE EXCHANGE SYSTEM "exchange.dtd">
""";
// 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")
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("yes")
.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()

@ -40,8 +40,8 @@ public class PackDtoTest {
<?xml version='1.1' encoding='UTF-8'?>
<pack filename="filename">
<header>
<type doc-type="docType"/>
<date>2024-03-14</date>
<doc-type>send</doc-type>
<date>20241231</date>
<sender>sender</sender>
<receiver>receiver</receiver>
<sender_userid>senderUserid</sender_userid>
@ -74,9 +74,20 @@ public class PackDtoTest {
// xmlMapper.writeValue(System.out, dto);
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>() {});
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")
.docType("send")
.build())
.date("2024-03-14")
.date("20241231")
.sender("sender")
.receiver("receiver")
.senderUserid("senderUserid")

Loading…
Cancel
Save