-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add mtconnect error and devices decode
Signed-off-by: ZhangJian He <shoothzj@gmail.com>
- Loading branch information
Showing
9 changed files
with
220 additions
and
2 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
mtconnect-api/src/main/java/io/github/protocol/mtconnect/api/CuttingTool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
15 changes: 15 additions & 0 deletions
15
mtconnect-api/src/main/java/io/github/protocol/mtconnect/api/Error.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
23 changes: 23 additions & 0 deletions
23
mtconnect-api/src/main/java/io/github/protocol/mtconnect/api/MTConnectAssets.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<CuttingTool> cuttingTools; | ||
} |
21 changes: 21 additions & 0 deletions
21
mtconnect-api/src/main/java/io/github/protocol/mtconnect/api/MTConnectError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Error> errors; | ||
} |
16 changes: 16 additions & 0 deletions
16
mtconnect-api/src/main/java/io/github/protocol/mtconnect/api/ToolLifeCycle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
63 changes: 63 additions & 0 deletions
63
...t-server/src/test/java/io/github/protocol/mtconnect/server/MTConnectAssetsDecodeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.github.protocol.mtconnect.server; | ||
|
||
import io.github.protocol.mtconnect.api.CuttingTool; | ||
import io.github.protocol.mtconnect.api.MTConnectAssets; | ||
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 = """ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<MTConnectAssets xmlns="urn:mtconnect.org:MTConnectAssets:1.2" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="urn:mtconnect.org:MTConnectAssets:1.2 ../MTConnectAssets_1.2.xsd"> | ||
<Header creationTime="2001-12-17T09:30:47Z" sender="localhost" | ||
version="1.2" bufferSize="131000" instanceId="1" /> | ||
<Assets> | ||
<CuttingTool serialNumber="1234" timestamp="2001-12-17T09:30:47Z" assetId="1234-112233"> | ||
<Description>Cutting Tool</Description> | ||
<ToolDefinition>...</ToolDefinition> | ||
<ToolLifeCycle deviceUuid="1222" toolId="1234">...</ToolLifeCycle> | ||
</CuttingTool> | ||
</Assets> | ||
</MTConnectAssets> | ||
"""; | ||
|
||
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...ct-server/src/test/java/io/github/protocol/mtconnect/server/MTConnectErrorDecodeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.github.protocol.mtconnect.server; | ||
|
||
import io.github.protocol.mtconnect.api.MTConnectError; | ||
import io.github.protocol.mtconnect.common.XmlUtil; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class MTConnectErrorDecodeTest { | ||
|
||
@Test | ||
void testMTConnectErrorParsing() throws Exception { | ||
// The raw XML string | ||
String xml = """ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<MTConnectError xmlns="urn:mtconnect.org:MTConnectError:1.1" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="urn:mtconnect.org:MTConnectError:1.1 http://www.mtconnect.org/schemas/MTConnectError_1.1.xsd"> | ||
<Header creationTime="2010-03-12T12:33:01" sender="localhost" | ||
version="1.1" bufferSize="131072" instanceId="1268463594" /> | ||
<Errors> | ||
<Error errorCode="OUT_OF_RANGE">Argument was out of range</Error> | ||
<Error errorCode="INVALID_XPATH">Bad path</Error> | ||
</Errors> | ||
</MTConnectError> | ||
"""; | ||
|
||
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters