Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.protocol.mtconnect.api;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText;
import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class Availability extends Event {
@JacksonXmlText
private String value;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
})
public class AxesComponent {
@JacksonXmlProperty(isAttribute = true)
private String id;
protected String id;

@JacksonXmlProperty(isAttribute = true)
private String name;
protected String name;
}
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.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Setter
@Getter
public class ComponentStream {

@JacksonXmlProperty(isAttribute = true, localName = "component")
private String component;

@JacksonXmlProperty(isAttribute = true, localName = "name")
private String name;

@JacksonXmlProperty(isAttribute = true, localName = "componentId")
private String componentId;

@JacksonXmlElementWrapper(localName = "Events")
private List<Event> events;

@JacksonXmlElementWrapper(localName = "Condition")
private List<Normal> normals;
}
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 DeviceStream {

@JacksonXmlProperty(isAttribute = true, localName = "name")
private String name;

@JacksonXmlProperty(isAttribute = true, localName = "uuid")
private String uuid;

@JacksonXmlElementWrapper(localName = "ComponentStream", useWrapping = false)
@JacksonXmlProperty(localName = "ComponentStream")
private List<ComponentStream> componentStreams;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.protocol.mtconnect.api;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText;
import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class EmergencyStop extends Event {
@JacksonXmlText
private String value;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.github.protocol.mtconnect.api;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "dataItemId")
@JsonSubTypes({
@JsonSubTypes.Type(value = Availability.class, name = "avail"),
@JsonSubTypes.Type(value = EmergencyStop.class, name = "estop"),
@JsonSubTypes.Type(value = Execution.class, name = "execution"),
})
public class Event {
@JacksonXmlProperty(isAttribute = true)
protected String dataItemId;

@JacksonXmlProperty(isAttribute = true)
protected long sequence;

@JacksonXmlProperty(isAttribute = true)
protected String timestamp;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.protocol.mtconnect.api;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText;
import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class Execution extends Event {

@JacksonXmlText
private String value;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,13 @@ public class Header {

@JacksonXmlProperty(isAttribute = true)
private String version;

@JacksonXmlProperty(isAttribute = true)
private long nextSequence;

@JacksonXmlProperty(isAttribute = true)
private long firstSequence;

@JacksonXmlProperty(isAttribute = true)
private long lastSequence;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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 MTConnectStreams {

@JacksonXmlProperty(isAttribute = true, localName = "schemaLocation")
private String schemaLocation;

@JacksonXmlProperty(localName = "Header")
private Header header;

@JacksonXmlElementWrapper(localName = "Streams")
private List<DeviceStream> deviceStreams;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.github.protocol.mtconnect.api;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class Normal {

@JacksonXmlProperty(isAttribute = true, localName = "dataItemId")
private String dataItemId;

@JacksonXmlProperty(isAttribute = true, localName = "sequence")
private String sequence;

@JacksonXmlProperty(isAttribute = true, localName = "timestamp")
private String timestamp;

@JacksonXmlProperty(isAttribute = true, localName = "type")
private String type;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package io.github.protocol.mtconnect.server;

import io.github.protocol.mtconnect.api.MTConnectStreams;
import io.github.protocol.mtconnect.common.XmlUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class MTConnectStreamsDecodeTest {

@Test
void testMTConnectStreamsParsing() throws Exception {
String xml = """
<?xml version="1.0" encoding="UTF-8"?>
<MTConnectStreams xmlns:m="urn:mtconnect.org:MTConnectStreams:1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:mtconnect.org:MTConnectStreams:1.1"
xsi:schemaLocation="urn:mtconnect.org:MTConnectStreams:1.1 http://www.mtconnect.org/schemas/MTConnectStreams_1.1.xsd">

<Header creationTime="2010-04-06T06:53:34+00:00" sender="localhost"
instanceId="1270534765" bufferSize="16" version="1.1" nextSequence="19"
firstSequence="3" lastSequence="18" />

<Streams>
<DeviceStream name="minimal" uuid="1">
<ComponentStream component="Device" name="minimal" componentId="d">
<Events>
<Availability dataItemId="avail" sequence="5" timestamp="2010-04-06T06:19:35.153141">AVAILABLE</Availability>
</Events>
</ComponentStream>

<ComponentStream component="Controller" name="controller" componentId="c1">
<Events>
<EmergencyStop dataItemId="estop" sequence="9" timestamp="2010-04-06T06:20:05.153230">RESET</EmergencyStop>
</Events>
<Condition>
<Normal dataItemId="system" sequence="13" timestamp="2010-04-06T06:21:35.153784" type="SYSTEM" />
</Condition>
</ComponentStream>

<ComponentStream component="Path" name="path" componentId="p1">
<Events>
<Execution dataItemId="execution" sequence="14" timestamp="2010-04-06T06:22:05.153741">ACTIVE</Execution>
</Events>
</ComponentStream>
</DeviceStream>
</Streams>
</MTConnectStreams>
""";

MTConnectStreams mtConnectStreams = XmlUtil.fromXml(xml, MTConnectStreams.class);

// Validate MTConnectStreams object
Assertions.assertNotNull(mtConnectStreams);
Assertions.assertEquals("urn:mtconnect.org:MTConnectStreams:1.1 http://www.mtconnect.org/schemas/MTConnectStreams_1.1.xsd", mtConnectStreams.getSchemaLocation());

// Validate Header
Assertions.assertNotNull(mtConnectStreams.getHeader());
Assertions.assertEquals("2010-04-06T06:53:34+00:00", mtConnectStreams.getHeader().getCreationTime());
Assertions.assertEquals("localhost", mtConnectStreams.getHeader().getSender());
Assertions.assertEquals("1270534765", mtConnectStreams.getHeader().getInstanceId());
Assertions.assertEquals(16, mtConnectStreams.getHeader().getBufferSize());
Assertions.assertEquals("1.1", mtConnectStreams.getHeader().getVersion());
Assertions.assertEquals(19, mtConnectStreams.getHeader().getNextSequence());
Assertions.assertEquals(3, mtConnectStreams.getHeader().getFirstSequence());
Assertions.assertEquals(18, mtConnectStreams.getHeader().getLastSequence());

// Validate DeviceStream
Assertions.assertNotNull(mtConnectStreams.getDeviceStreams());
Assertions.assertEquals(1, mtConnectStreams.getDeviceStreams().size());

// Validate ComponentStream
var deviceStream = mtConnectStreams.getDeviceStreams().get(0);
Assertions.assertEquals("minimal", deviceStream.getName());
Assertions.assertEquals("1", deviceStream.getUuid());

var componentStream = deviceStream.getComponentStreams().get(0);
Assertions.assertEquals("Device", componentStream.getComponent());
Assertions.assertEquals("minimal", componentStream.getName());
Assertions.assertEquals("d", componentStream.getComponentId());

// Validate Events and Condition
Assertions.assertNotNull(componentStream.getEvents());
Assertions.assertEquals(1, componentStream.getEvents().size());
}
}