diff --git a/mtconnect-api/src/main/java/io/github/protocol/mtconnect/api/CuttingTool.java b/mtconnect-api/src/main/java/io/github/protocol/mtconnect/api/CuttingTool.java new file mode 100644 index 0000000..4072487 --- /dev/null +++ b/mtconnect-api/src/main/java/io/github/protocol/mtconnect/api/CuttingTool.java @@ -0,0 +1,28 @@ +package io.github.protocol.mtconnect.api; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +public class CuttingTool { + + @JacksonXmlProperty(isAttribute = true, localName = "serialNumber") + private String serialNumber; + + @JacksonXmlProperty(isAttribute = true, localName = "timestamp") + private String timestamp; + + @JacksonXmlProperty(isAttribute = true, localName = "assetId") + private String assetId; + + @JacksonXmlProperty(localName = "Description") + private String description; + + @JacksonXmlProperty(localName = "ToolDefinition") + private String toolDefinition; + + @JacksonXmlProperty(localName = "ToolLifeCycle") + private ToolLifeCycle toolLifeCycle; +} diff --git a/mtconnect-api/src/main/java/io/github/protocol/mtconnect/api/Error.java b/mtconnect-api/src/main/java/io/github/protocol/mtconnect/api/Error.java new file mode 100644 index 0000000..94e6e6c --- /dev/null +++ b/mtconnect-api/src/main/java/io/github/protocol/mtconnect/api/Error.java @@ -0,0 +1,15 @@ +package io.github.protocol.mtconnect.api; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +public class Error { + @JacksonXmlProperty(isAttribute = true, localName = "errorCode") + private String errorCode; + + @JacksonXmlProperty + private String value; +} diff --git a/mtconnect-api/src/main/java/io/github/protocol/mtconnect/api/MTConnectAssets.java b/mtconnect-api/src/main/java/io/github/protocol/mtconnect/api/MTConnectAssets.java new file mode 100644 index 0000000..3e04c5f --- /dev/null +++ b/mtconnect-api/src/main/java/io/github/protocol/mtconnect/api/MTConnectAssets.java @@ -0,0 +1,23 @@ +package io.github.protocol.mtconnect.api; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +@Setter +@Getter +public class MTConnectAssets { + + @JacksonXmlProperty(isAttribute = true, localName = "schemaLocation") + private String schemaLocation; + + @JacksonXmlProperty(localName = "Header") + private Header header; + + @JacksonXmlElementWrapper(localName = "Assets") + @JacksonXmlProperty(localName = "CuttingTool") + private List cuttingTools; +} diff --git a/mtconnect-api/src/main/java/io/github/protocol/mtconnect/api/MTConnectError.java b/mtconnect-api/src/main/java/io/github/protocol/mtconnect/api/MTConnectError.java new file mode 100644 index 0000000..eb7557e --- /dev/null +++ b/mtconnect-api/src/main/java/io/github/protocol/mtconnect/api/MTConnectError.java @@ -0,0 +1,21 @@ +package io.github.protocol.mtconnect.api; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +@Setter +@Getter +public class MTConnectError { + @JacksonXmlProperty(isAttribute = true, localName = "schemaLocation") + private String schemaLocation; + + @JacksonXmlProperty(localName = "Header") + private Header header; + + @JacksonXmlElementWrapper(localName = "Errors") + private List errors; +} diff --git a/mtconnect-api/src/main/java/io/github/protocol/mtconnect/api/ToolLifeCycle.java b/mtconnect-api/src/main/java/io/github/protocol/mtconnect/api/ToolLifeCycle.java new file mode 100644 index 0000000..d38d142 --- /dev/null +++ b/mtconnect-api/src/main/java/io/github/protocol/mtconnect/api/ToolLifeCycle.java @@ -0,0 +1,16 @@ +package io.github.protocol.mtconnect.api; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +public class ToolLifeCycle { + + @JacksonXmlProperty(isAttribute = true, localName = "deviceUuid") + private String deviceUuid; + + @JacksonXmlProperty(isAttribute = true, localName = "toolId") + private String toolId; +} diff --git a/mtconnect-server/src/test/java/io/github/protocol/mtconnect/server/MTConnectAssetsDecodeTest.java b/mtconnect-server/src/test/java/io/github/protocol/mtconnect/server/MTConnectAssetsDecodeTest.java new file mode 100644 index 0000000..57218b9 --- /dev/null +++ b/mtconnect-server/src/test/java/io/github/protocol/mtconnect/server/MTConnectAssetsDecodeTest.java @@ -0,0 +1,63 @@ +package io.github.protocol.mtconnect.server; + +import io.github.protocol.mtconnect.api.MTConnectAssets; +import io.github.protocol.mtconnect.api.CuttingTool; +import io.github.protocol.mtconnect.common.XmlUtil; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class MTConnectAssetsDecodeTest { + + @Test + void testMTConnectAssetsParsing() throws Exception { + String xml = """ + + + +
+ + + + Cutting Tool + ... + ... + + + + """; + + MTConnectAssets mtConnectAssets = XmlUtil.fromXml(xml, MTConnectAssets.class); + + // Validate MTConnectAssets object + Assertions.assertNotNull(mtConnectAssets); + Assertions.assertEquals("urn:mtconnect.org:MTConnectAssets:1.2 ../MTConnectAssets_1.2.xsd", mtConnectAssets.getSchemaLocation()); + + // Validate Header object + Assertions.assertNotNull(mtConnectAssets.getHeader()); + Assertions.assertEquals("2001-12-17T09:30:47Z", mtConnectAssets.getHeader().getCreationTime()); + Assertions.assertEquals("localhost", mtConnectAssets.getHeader().getSender()); + Assertions.assertEquals("1", mtConnectAssets.getHeader().getInstanceId()); + Assertions.assertEquals(131000, mtConnectAssets.getHeader().getBufferSize()); + Assertions.assertEquals("1.2", mtConnectAssets.getHeader().getVersion()); + + // Validate CuttingTool list + Assertions.assertNotNull(mtConnectAssets.getCuttingTools()); + Assertions.assertEquals(1, mtConnectAssets.getCuttingTools().size()); + + // Validate individual CuttingTool + CuttingTool cuttingTool = mtConnectAssets.getCuttingTools().get(0); + Assertions.assertEquals("1234", cuttingTool.getSerialNumber()); + Assertions.assertEquals("2001-12-17T09:30:47Z", cuttingTool.getTimestamp()); + Assertions.assertEquals("1234-112233", cuttingTool.getAssetId()); + Assertions.assertEquals("Cutting Tool", cuttingTool.getDescription()); + Assertions.assertEquals("...", cuttingTool.getToolDefinition()); + + // Validate ToolLifeCycle + Assertions.assertNotNull(cuttingTool.getToolLifeCycle()); + Assertions.assertEquals("1222", cuttingTool.getToolLifeCycle().getDeviceUuid()); + Assertions.assertEquals("1234", cuttingTool.getToolLifeCycle().getToolId()); + } +} diff --git a/mtconnect-server/src/test/java/io/github/protocol/mtconnect/server/MTConnectDevicesDecodeTest.java b/mtconnect-server/src/test/java/io/github/protocol/mtconnect/server/MTConnectDevicesDecodeTest.java index 55856aa..0749452 100644 --- a/mtconnect-server/src/test/java/io/github/protocol/mtconnect/server/MTConnectDevicesDecodeTest.java +++ b/mtconnect-server/src/test/java/io/github/protocol/mtconnect/server/MTConnectDevicesDecodeTest.java @@ -9,7 +9,6 @@ class MTConnectDevicesDecodeTest { @Test void testMTConnectDevicesParsing() throws Exception { - // The raw XML string String xml = """ + + +
+ + + Argument was out of range + Bad path + + + """; + + MTConnectError mtConnectError = XmlUtil.fromXml(xml, MTConnectError.class); + + // Validate MTConnectError object + Assertions.assertNotNull(mtConnectError); + Assertions.assertEquals("urn:mtconnect.org:MTConnectError:1.1 http://www.mtconnect.org/schemas/MTConnectError_1.1.xsd", mtConnectError.getSchemaLocation()); + + // Validate Header object + Assertions.assertNotNull(mtConnectError.getHeader()); + Assertions.assertEquals("2010-03-12T12:33:01", mtConnectError.getHeader().getCreationTime()); + Assertions.assertEquals("localhost", mtConnectError.getHeader().getSender()); + Assertions.assertEquals("1.1", mtConnectError.getHeader().getVersion()); + Assertions.assertEquals(131072, mtConnectError.getHeader().getBufferSize()); + Assertions.assertEquals("1268463594", mtConnectError.getHeader().getInstanceId()); + + // Validate Errors list + Assertions.assertNotNull(mtConnectError.getErrors()); + Assertions.assertEquals(2, mtConnectError.getErrors().size()); + + // Validate individual errors + Assertions.assertEquals("OUT_OF_RANGE", mtConnectError.getErrors().get(0).getErrorCode()); + Assertions.assertEquals("Argument was out of range", mtConnectError.getErrors().get(0).getValue()); + Assertions.assertEquals("INVALID_XPATH", mtConnectError.getErrors().get(1).getErrorCode()); + Assertions.assertEquals("Bad path", mtConnectError.getErrors().get(1).getValue()); + } +} diff --git a/pom.xml b/pom.xml index a35c69a..ab5cc5f 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ 0.8.12 3.13.0 3.5.0 - 3.8.0 + 3.6.0 3.2.5 3.10.0 3.1.1