diff --git a/.gitignore b/.gitignore index 39a55e142e7..d86ce58836f 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,7 @@ atlassian-ide-plugin.xml *.tar.gz *.rar + # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/Alarm8MessageQueryType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/Alarm8MessageQueryType.java index 4783b3b23be..31e7dab0922 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/Alarm8MessageQueryType.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/Alarm8MessageQueryType.java @@ -88,7 +88,6 @@ public List getMessageObjects() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("Alarm8MessageQueryType"); // Simple Field (functionId) @@ -173,8 +172,6 @@ public static Alarm8MessageQueryType staticParse(ReadBuffer readBuffer, Object.. public static Alarm8MessageQueryType staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("Alarm8MessageQueryType"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short functionId = readSimpleField("functionId", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageAckObjectPushType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageAckObjectPushType.java index 579333c9b44..342589eba6d 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageAckObjectPushType.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageAckObjectPushType.java @@ -95,7 +95,6 @@ public short getVariableSpec() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("AlarmMessageAckObjectPushType"); // Const Field (variableSpec) @@ -172,8 +171,6 @@ public static AlarmMessageAckObjectPushType staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("AlarmMessageAckObjectPushType"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short variableSpec = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageAckPushType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageAckPushType.java index 6aeaf270c60..48491b961ad 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageAckPushType.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageAckPushType.java @@ -74,7 +74,6 @@ public List getMessageObjects() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("AlarmMessageAckPushType"); // Simple Field (TimeStamp) @@ -133,8 +132,6 @@ public static AlarmMessageAckPushType staticParse(ReadBuffer readBuffer, Object. public static AlarmMessageAckPushType staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("AlarmMessageAckPushType"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); DateAndTime TimeStamp = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageAckResponseType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageAckResponseType.java index 7d93a28b5c6..e588b6ca414 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageAckResponseType.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageAckResponseType.java @@ -65,7 +65,6 @@ public List getMessageObjects() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("AlarmMessageAckResponseType"); // Simple Field (functionId) @@ -115,8 +114,6 @@ public static AlarmMessageAckResponseType staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("AlarmMessageAckResponseType"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short functionId = readSimpleField("functionId", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageAckType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageAckType.java index 0cb1b929663..bea2571d061 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageAckType.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageAckType.java @@ -65,7 +65,6 @@ public List getMessageObjects() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("AlarmMessageAckType"); // Simple Field (functionId) @@ -118,8 +117,6 @@ public static AlarmMessageAckType staticParse(ReadBuffer readBuffer, Object... a public static AlarmMessageAckType staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("AlarmMessageAckType"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short functionId = readSimpleField("functionId", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageObjectAckType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageObjectAckType.java index bbbfc213c01..fc3ff163982 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageObjectAckType.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageObjectAckType.java @@ -93,7 +93,6 @@ public short getLength() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("AlarmMessageObjectAckType"); // Const Field (variableSpec) @@ -169,8 +168,6 @@ public static AlarmMessageObjectAckType staticParse(ReadBuffer readBuffer, Objec public static AlarmMessageObjectAckType staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("AlarmMessageObjectAckType"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short variableSpec = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageObjectPushType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageObjectPushType.java index 7680db5fd86..42777096da9 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageObjectPushType.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageObjectPushType.java @@ -116,7 +116,6 @@ public short getVariableSpec() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("AlarmMessageObjectPushType"); // Const Field (variableSpec) @@ -217,8 +216,6 @@ public static AlarmMessageObjectPushType staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("AlarmMessageObjectPushType"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short variableSpec = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageObjectQueryType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageObjectQueryType.java index 49f8d6f2750..7d931070da7 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageObjectQueryType.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageObjectQueryType.java @@ -109,7 +109,6 @@ public short getVariableSpec() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("AlarmMessageObjectQueryType"); // Simple Field (lengthDataset) @@ -199,8 +198,6 @@ public static AlarmMessageObjectQueryType staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("AlarmMessageObjectQueryType"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short lengthDataset = readSimpleField("lengthDataset", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessagePushType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessagePushType.java index a34b68b1633..a6b578a1e97 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessagePushType.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessagePushType.java @@ -74,7 +74,6 @@ public List getMessageObjects() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("AlarmMessagePushType"); // Simple Field (TimeStamp) @@ -133,8 +132,6 @@ public static AlarmMessagePushType staticParse(ReadBuffer readBuffer, Object... public static AlarmMessagePushType staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("AlarmMessagePushType"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); DateAndTime TimeStamp = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageQueryType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageQueryType.java index 4174c085100..53eddc50a4d 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageQueryType.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmMessageQueryType.java @@ -88,7 +88,6 @@ public int getDataLength() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("AlarmMessageQueryType"); // Simple Field (functionId) @@ -173,8 +172,6 @@ public static AlarmMessageQueryType staticParse(ReadBuffer readBuffer, Object... public static AlarmMessageQueryType staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("AlarmMessageQueryType"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short functionId = readSimpleField("functionId", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmStateType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmStateType.java index 10f555fd928..5a038892956 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmStateType.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmStateType.java @@ -39,7 +39,7 @@ public enum AlarmStateType { } } - private short value; + private final short value; AlarmStateType(short value) { this.value = value; diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmType.java index a11a6605086..3693907d2a4 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmType.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AlarmType.java @@ -36,7 +36,7 @@ public enum AlarmType { } } - private short value; + private final short value; AlarmType(short value) { this.value = value; diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AssociatedQueryValueType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AssociatedQueryValueType.java index 035fc29feab..9f7a355161d 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AssociatedQueryValueType.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AssociatedQueryValueType.java @@ -74,7 +74,6 @@ public List getData() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("AssociatedQueryValueType"); // Simple Field (returnCode) @@ -143,8 +142,6 @@ public static AssociatedQueryValueType staticParse(ReadBuffer readBuffer, Object public static AssociatedQueryValueType staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("AssociatedQueryValueType"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); DataTransportErrorCode returnCode = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AssociatedValueType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AssociatedValueType.java index 8b090361375..d3807cd3865 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AssociatedValueType.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/AssociatedValueType.java @@ -74,7 +74,6 @@ public List getData() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("AssociatedValueType"); // Simple Field (returnCode) @@ -148,8 +147,6 @@ public static AssociatedValueType staticParse(ReadBuffer readBuffer, Object... a public static AssociatedValueType staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("AssociatedValueType"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); DataTransportErrorCode returnCode = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketConnectionRequest.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketConnectionRequest.java index afe5079f627..f5c7bb10507 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketConnectionRequest.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketConnectionRequest.java @@ -75,7 +75,6 @@ public COTPProtocolClass getProtocolClass() { protected void serializeCOTPPacketChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("COTPPacketConnectionRequest"); // Simple Field (destinationReference) @@ -125,8 +124,6 @@ public static COTPPacketBuilder staticParseCOTPPacketBuilder( ReadBuffer readBuffer, Integer cotpLen) throws ParseException { readBuffer.pullContext("COTPPacketConnectionRequest"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); int destinationReference = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketConnectionResponse.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketConnectionResponse.java index 5fb6eb696e3..1d64fa5fa2e 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketConnectionResponse.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketConnectionResponse.java @@ -75,7 +75,6 @@ public COTPProtocolClass getProtocolClass() { protected void serializeCOTPPacketChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("COTPPacketConnectionResponse"); // Simple Field (destinationReference) @@ -125,8 +124,6 @@ public static COTPPacketBuilder staticParseCOTPPacketBuilder( ReadBuffer readBuffer, Integer cotpLen) throws ParseException { readBuffer.pullContext("COTPPacketConnectionResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); int destinationReference = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketData.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketData.java index 3b56645300b..d02dc78b246 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketData.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketData.java @@ -65,7 +65,6 @@ public short getTpduRef() { protected void serializeCOTPPacketChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("COTPPacketData"); // Simple Field (eot) @@ -101,8 +100,6 @@ public static COTPPacketBuilder staticParseCOTPPacketBuilder( ReadBuffer readBuffer, Integer cotpLen) throws ParseException { readBuffer.pullContext("COTPPacketData"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); boolean eot = readSimpleField("eot", readBoolean(readBuffer)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketDisconnectRequest.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketDisconnectRequest.java index 7a30250683d..8c1ef73f6fd 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketDisconnectRequest.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketDisconnectRequest.java @@ -75,7 +75,6 @@ public COTPProtocolClass getProtocolClass() { protected void serializeCOTPPacketChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("COTPPacketDisconnectRequest"); // Simple Field (destinationReference) @@ -125,8 +124,6 @@ public static COTPPacketBuilder staticParseCOTPPacketBuilder( ReadBuffer readBuffer, Integer cotpLen) throws ParseException { readBuffer.pullContext("COTPPacketDisconnectRequest"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); int destinationReference = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketDisconnectResponse.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketDisconnectResponse.java index cf4df50c21e..90bae295940 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketDisconnectResponse.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketDisconnectResponse.java @@ -68,7 +68,6 @@ public int getSourceReference() { protected void serializeCOTPPacketChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("COTPPacketDisconnectResponse"); // Simple Field (destinationReference) @@ -105,8 +104,6 @@ public static COTPPacketBuilder staticParseCOTPPacketBuilder( ReadBuffer readBuffer, Integer cotpLen) throws ParseException { readBuffer.pullContext("COTPPacketDisconnectResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); int destinationReference = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketTpduError.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketTpduError.java index 1cfaf8cf3c8..bb6c4ed3aa2 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketTpduError.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPPacketTpduError.java @@ -68,7 +68,6 @@ public short getRejectCause() { protected void serializeCOTPPacketChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("COTPPacketTpduError"); // Simple Field (destinationReference) @@ -105,8 +104,6 @@ public static COTPPacketBuilder staticParseCOTPPacketBuilder( ReadBuffer readBuffer, Integer cotpLen) throws ParseException { readBuffer.pullContext("COTPPacketTpduError"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); int destinationReference = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameter.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameter.java index 76a3a88e1ed..d056c5f92fc 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameter.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameter.java @@ -50,7 +50,6 @@ protected abstract void serializeCOTPParameterChild(WriteBuffer writeBuffer) public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("COTPParameter"); // Discriminator Field (parameterType) (Used as input to a switch field) @@ -113,8 +112,6 @@ public static COTPParameter staticParse(ReadBuffer readBuffer, Object... args) public static COTPParameter staticParse(ReadBuffer readBuffer, Short rest) throws ParseException { readBuffer.pullContext("COTPParameter"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short parameterType = readDiscriminatorField("parameterType", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameterCalledTsap.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameterCalledTsap.java index 2a9f41aa980..154495f6808 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameterCalledTsap.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameterCalledTsap.java @@ -59,7 +59,6 @@ protected void serializeCOTPParameterChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("COTPParameterCalledTsap"); // Simple Field (tsapId) @@ -89,8 +88,6 @@ public static COTPParameterBuilder staticParseCOTPParameterBuilder( ReadBuffer readBuffer, Short rest) throws ParseException { readBuffer.pullContext("COTPParameterCalledTsap"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); int tsapId = readSimpleField("tsapId", readUnsignedInt(readBuffer, 16)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameterCallingTsap.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameterCallingTsap.java index bcbaf504572..b61845ae97a 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameterCallingTsap.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameterCallingTsap.java @@ -59,7 +59,6 @@ protected void serializeCOTPParameterChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("COTPParameterCallingTsap"); // Simple Field (tsapId) @@ -89,8 +88,6 @@ public static COTPParameterBuilder staticParseCOTPParameterBuilder( ReadBuffer readBuffer, Short rest) throws ParseException { readBuffer.pullContext("COTPParameterCallingTsap"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); int tsapId = readSimpleField("tsapId", readUnsignedInt(readBuffer, 16)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameterChecksum.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameterChecksum.java index 23e0ceff571..bfa89f0ff1e 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameterChecksum.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameterChecksum.java @@ -59,7 +59,6 @@ protected void serializeCOTPParameterChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("COTPParameterChecksum"); // Simple Field (crc) @@ -89,8 +88,6 @@ public static COTPParameterBuilder staticParseCOTPParameterBuilder( ReadBuffer readBuffer, Short rest) throws ParseException { readBuffer.pullContext("COTPParameterChecksum"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short crc = readSimpleField("crc", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameterDisconnectAdditionalInformation.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameterDisconnectAdditionalInformation.java index b4a61e87748..9846b0517fe 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameterDisconnectAdditionalInformation.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameterDisconnectAdditionalInformation.java @@ -59,7 +59,6 @@ protected void serializeCOTPParameterChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("COTPParameterDisconnectAdditionalInformation"); // Array Field (data) @@ -91,8 +90,6 @@ public static COTPParameterBuilder staticParseCOTPParameterBuilder( ReadBuffer readBuffer, Short rest) throws ParseException { readBuffer.pullContext("COTPParameterDisconnectAdditionalInformation"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); byte[] data = readBuffer.readByteArray("data", Math.toIntExact(rest)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameterTpduSize.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameterTpduSize.java index 4cb45b96b85..be740620a83 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameterTpduSize.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPParameterTpduSize.java @@ -59,7 +59,6 @@ protected void serializeCOTPParameterChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("COTPParameterTpduSize"); // Simple Field (tpduSize) @@ -94,8 +93,6 @@ public static COTPParameterBuilder staticParseCOTPParameterBuilder( ReadBuffer readBuffer, Short rest) throws ParseException { readBuffer.pullContext("COTPParameterTpduSize"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); COTPTpduSize tpduSize = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPProtocolClass.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPProtocolClass.java index fd6ab7effda..01715721bc9 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPProtocolClass.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPProtocolClass.java @@ -38,7 +38,7 @@ public enum COTPProtocolClass { } } - private short value; + private final short value; COTPProtocolClass(short value) { this.value = value; diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPTpduSize.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPTpduSize.java index f428cfee9b5..9f7df7129aa 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPTpduSize.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/COTPTpduSize.java @@ -42,8 +42,8 @@ public enum COTPTpduSize { } } - private short value; - private int sizeInBytes; + private final short value; + private final int sizeInBytes; COTPTpduSize(short value, int sizeInBytes) { this.value = value; @@ -68,7 +68,7 @@ public static COTPTpduSize firstEnumForFieldSizeInBytes(int fieldValue) { } public static List enumsForFieldSizeInBytes(int fieldValue) { - List _values = new ArrayList(); + List _values = new ArrayList<>(); for (COTPTpduSize _val : COTPTpduSize.values()) { if (_val.getSizeInBytes() == fieldValue) { _values.add(_val); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/CpuSubscribeEvents.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/CpuSubscribeEvents.java index b9cb3f0610b..10be0b999da 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/CpuSubscribeEvents.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/CpuSubscribeEvents.java @@ -37,7 +37,7 @@ public enum CpuSubscribeEvents { } } - private short value; + private final short value; CpuSubscribeEvents(short value) { this.value = value; diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/CycServiceItemAnyType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/CycServiceItemAnyType.java index 82cfa394db0..d93c31c1d21 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/CycServiceItemAnyType.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/CycServiceItemAnyType.java @@ -87,16 +87,15 @@ protected void serializeCycServiceItemTypeChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("CycServiceItemAnyType"); - // Simple Field (transportSize) - writeSimpleEnumField( + // Enum field (transportSize) + writeEnumField( "transportSize", "TransportSize", transportSize, new DataWriterEnumDefault<>( - TransportSize::getValue, TransportSize::name, writeUnsignedShort(writeBuffer, 8))); + TransportSize::getCode, TransportSize::name, writeUnsignedShort(writeBuffer, 8))); // Simple Field (length) writeSimpleField("length", length, writeUnsignedInt(writeBuffer, 16)); @@ -129,7 +128,7 @@ public int getLengthInBits() { CycServiceItemAnyType _value = this; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - // Simple field (transportSize) + // Enum Field (transportSize) lengthInBits += 8; // Simple field (length) @@ -151,16 +150,13 @@ public static CycServiceItemTypeBuilder staticParseCycServiceItemTypeBuilder( ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("CycServiceItemAnyType"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); TransportSize transportSize = readEnumField( "transportSize", "TransportSize", - new DataReaderEnumDefault<>( - TransportSize::enumForValue, readUnsignedShort(readBuffer, 8))); + readEnum(TransportSize::firstEnumForFieldCode, readUnsignedShort(readBuffer, 8))); int length = readSimpleField("length", readUnsignedInt(readBuffer, 16)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/CycServiceItemDbReadType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/CycServiceItemDbReadType.java index c2ca696f026..73363758ddd 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/CycServiceItemDbReadType.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/CycServiceItemDbReadType.java @@ -63,7 +63,6 @@ protected void serializeCycServiceItemTypeChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("CycServiceItemDbReadType"); // Simple Field (numberOfAreas) @@ -105,8 +104,6 @@ public static CycServiceItemTypeBuilder staticParseCycServiceItemTypeBuilder( ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("CycServiceItemDbReadType"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short numberOfAreas = readSimpleField("numberOfAreas", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/CycServiceItemType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/CycServiceItemType.java index c7c6af1d4ee..9dca1f7e3ed 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/CycServiceItemType.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/CycServiceItemType.java @@ -70,7 +70,6 @@ protected abstract void serializeCycServiceItemTypeChild(WriteBuffer writeBuffer public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("CycServiceItemType"); // Const Field (functionId) @@ -122,8 +121,6 @@ public static CycServiceItemType staticParse(ReadBuffer readBuffer, Object... ar public static CycServiceItemType staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("CycServiceItemType"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short functionId = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DataTransportErrorCode.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DataTransportErrorCode.java index 160a36c0edc..72da9d71528 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DataTransportErrorCode.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DataTransportErrorCode.java @@ -39,7 +39,7 @@ public enum DataTransportErrorCode { } } - private short value; + private final short value; DataTransportErrorCode(short value) { this.value = value; diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DataTransportSize.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DataTransportSize.java index 130f5f063d0..bc667c57c38 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DataTransportSize.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DataTransportSize.java @@ -42,8 +42,8 @@ public enum DataTransportSize { } } - private short value; - private boolean sizeInBits; + private final short value; + private final boolean sizeInBits; DataTransportSize(short value, boolean sizeInBits) { this.value = value; @@ -68,7 +68,7 @@ public static DataTransportSize firstEnumForFieldSizeInBits(boolean fieldValue) } public static List enumsForFieldSizeInBits(boolean fieldValue) { - List _values = new ArrayList(); + List _values = new ArrayList<>(); for (DataTransportSize _val : DataTransportSize.values()) { if (_val.getSizeInBits() == fieldValue) { _values.add(_val); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DateAndTime.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DateAndTime.java index 26fa8d9a10e..fa0b0e1fbaa 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DateAndTime.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DateAndTime.java @@ -102,7 +102,6 @@ public byte getDow() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("DateAndTime"); // Manual Field (year) @@ -200,8 +199,6 @@ public static DateAndTime staticParse(ReadBuffer readBuffer, Object... args) public static DateAndTime staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("DateAndTime"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short year = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DeviceGroup.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DeviceGroup.java index 4fb8727c339..6386830857b 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DeviceGroup.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DeviceGroup.java @@ -36,7 +36,7 @@ public enum DeviceGroup { } } - private short value; + private final short value; DeviceGroup(short value) { this.value = value; diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/EventType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/EventType.java index 1d9931cc3e7..b80be908777 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/EventType.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/EventType.java @@ -38,7 +38,7 @@ public enum EventType { } } - private short value; + private final short value; EventType(short value) { this.value = value; diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/MemoryArea.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/MemoryArea.java index 0a244f9910f..16146f7ab20 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/MemoryArea.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/MemoryArea.java @@ -44,8 +44,8 @@ public enum MemoryArea { } } - private short value; - private String shortName; + private final short value; + private final String shortName; MemoryArea(short value, String shortName) { this.value = value; @@ -70,7 +70,7 @@ public static MemoryArea firstEnumForFieldShortName(String fieldValue) { } public static List enumsForFieldShortName(String fieldValue) { - List _values = new ArrayList(); + List _values = new ArrayList<>(); for (MemoryArea _val : MemoryArea.values()) { if (_val.getShortName().equals(fieldValue)) { _values.add(_val); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/ModeTransitionType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/ModeTransitionType.java index f31562b7309..affc7ccb3eb 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/ModeTransitionType.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/ModeTransitionType.java @@ -42,7 +42,7 @@ public enum ModeTransitionType { } } - private short value; + private final short value; ModeTransitionType(short value) { this.value = value; diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/QueryType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/QueryType.java index 7a6eaf32042..6a0986380cb 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/QueryType.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/QueryType.java @@ -37,7 +37,7 @@ public enum QueryType { } } - private short value; + private final short value; QueryType(short value) { this.value = value; diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7Address.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7Address.java index 4e3b3ac8dbe..3fdb19bcae3 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7Address.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7Address.java @@ -50,7 +50,6 @@ protected abstract void serializeS7AddressChild(WriteBuffer writeBuffer) public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7Address"); // Discriminator Field (addressType) (Used as input to a switch field) @@ -89,8 +88,6 @@ public static S7Address staticParse(ReadBuffer readBuffer, Object... args) throw public static S7Address staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("S7Address"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short addressType = readDiscriminatorField("addressType", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7AddressAny.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7AddressAny.java index 5fc9b8f1115..b9e124e6be8 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7AddressAny.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7AddressAny.java @@ -94,7 +94,6 @@ public byte getBitAddress() { protected void serializeS7AddressChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7AddressAny"); // Enum field (transportSize) @@ -170,8 +169,6 @@ public static S7AddressBuilder staticParseS7AddressBuilder(ReadBuffer readBuffer throws ParseException { readBuffer.pullContext("S7AddressAny"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); TransportSize transportSize = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7DataAlarmMessage.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7DataAlarmMessage.java index d8109b76d10..92e453cc402 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7DataAlarmMessage.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7DataAlarmMessage.java @@ -62,7 +62,6 @@ protected abstract void serializeS7DataAlarmMessageChild(WriteBuffer writeBuffer public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7DataAlarmMessage"); // Const Field (functionId) @@ -123,8 +122,6 @@ public static S7DataAlarmMessage staticParse(ReadBuffer readBuffer, Byte cpuFunc throws ParseException { readBuffer.pullContext("S7DataAlarmMessage"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short functionId = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7Message.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7Message.java index 4fc347ccb6f..19cf023dbf2 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7Message.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7Message.java @@ -77,7 +77,6 @@ protected abstract void serializeS7MessageChild(WriteBuffer writeBuffer) public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7Message"); // Const Field (protocolId) @@ -167,8 +166,6 @@ public static S7Message staticParse(ReadBuffer readBuffer, Object... args) throw public static S7Message staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("S7Message"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short protocolId = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageObjectRequest.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageObjectRequest.java index 4c85600d34a..fcdf0b49c24 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageObjectRequest.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageObjectRequest.java @@ -83,7 +83,6 @@ protected void serializeS7DataAlarmMessageChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7MessageObjectRequest"); // Const Field (variableSpec) @@ -164,8 +163,6 @@ public static S7DataAlarmMessageBuilder staticParseS7DataAlarmMessageBuilder( ReadBuffer readBuffer, Byte cpuFunctionType) throws ParseException { readBuffer.pullContext("S7MessageObjectRequest"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short variableSpec = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageObjectResponse.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageObjectResponse.java index 36bf1cea705..812a27a0bcf 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageObjectResponse.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageObjectResponse.java @@ -66,7 +66,6 @@ protected void serializeS7DataAlarmMessageChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7MessageObjectResponse"); // Simple Field (returnCode) @@ -122,8 +121,6 @@ public static S7DataAlarmMessageBuilder staticParseS7DataAlarmMessageBuilder( ReadBuffer readBuffer, Byte cpuFunctionType) throws ParseException { readBuffer.pullContext("S7MessageObjectResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); DataTransportErrorCode returnCode = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageRequest.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageRequest.java index a4b77504ea7..d7f55537d40 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageRequest.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageRequest.java @@ -50,7 +50,6 @@ public S7MessageRequest(int tpduReference, S7Parameter parameter, S7Payload payl protected void serializeS7MessageChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7MessageRequest"); writeBuffer.popContext("S7MessageRequest"); @@ -74,8 +73,6 @@ public static S7MessageBuilder staticParseS7MessageBuilder(ReadBuffer readBuffer throws ParseException { readBuffer.pullContext("S7MessageRequest"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); readBuffer.closeContext("S7MessageRequest"); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageResponse.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageResponse.java index 722f168b019..c32725f02a8 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageResponse.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageResponse.java @@ -69,7 +69,6 @@ public short getErrorCode() { protected void serializeS7MessageChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7MessageResponse"); // Simple Field (errorClass) @@ -105,8 +104,6 @@ public static S7MessageBuilder staticParseS7MessageBuilder(ReadBuffer readBuffer throws ParseException { readBuffer.pullContext("S7MessageResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short errorClass = readSimpleField("errorClass", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageResponseData.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageResponseData.java index e41e0e2ff34..a4e957df96a 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageResponseData.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageResponseData.java @@ -69,7 +69,6 @@ public short getErrorCode() { protected void serializeS7MessageChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7MessageResponseData"); // Simple Field (errorClass) @@ -105,8 +104,6 @@ public static S7MessageBuilder staticParseS7MessageBuilder(ReadBuffer readBuffer throws ParseException { readBuffer.pullContext("S7MessageResponseData"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short errorClass = readSimpleField("errorClass", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageUserData.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageUserData.java index f9a557b4a2e..93c380103cd 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageUserData.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7MessageUserData.java @@ -50,7 +50,6 @@ public S7MessageUserData(int tpduReference, S7Parameter parameter, S7Payload pay protected void serializeS7MessageChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7MessageUserData"); writeBuffer.popContext("S7MessageUserData"); @@ -74,8 +73,6 @@ public static S7MessageBuilder staticParseS7MessageBuilder(ReadBuffer readBuffer throws ParseException { readBuffer.pullContext("S7MessageUserData"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); readBuffer.closeContext("S7MessageUserData"); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7Parameter.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7Parameter.java index 051ebd2a790..d02b9522305 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7Parameter.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7Parameter.java @@ -52,7 +52,6 @@ protected abstract void serializeS7ParameterChild(WriteBuffer writeBuffer) public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7Parameter"); // Discriminator Field (parameterType) (Used as input to a switch field) @@ -108,8 +107,6 @@ public static S7Parameter staticParse(ReadBuffer readBuffer, Short messageType) throws ParseException { readBuffer.pullContext("S7Parameter"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short parameterType = readDiscriminatorField("parameterType", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterModeTransition.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterModeTransition.java index b65cb58a2e0..8858e89a028 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterModeTransition.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterModeTransition.java @@ -91,7 +91,6 @@ public short getSequenceNumber() { protected void serializeS7ParameterChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7ParameterModeTransition"); // Reserved Field (reserved) @@ -159,8 +158,6 @@ public static S7ParameterBuilder staticParseS7ParameterBuilder( ReadBuffer readBuffer, Short messageType) throws ParseException { readBuffer.pullContext("S7ParameterModeTransition"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); Integer reservedField0 = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterReadVarRequest.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterReadVarRequest.java index 4ca78328cf4..1cd784f0ee9 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterReadVarRequest.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterReadVarRequest.java @@ -62,7 +62,6 @@ public List getItems() { protected void serializeS7ParameterChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7ParameterReadVarRequest"); // Implicit Field (numItems) (Used for parsing, but its value is not stored as it's implicitly @@ -106,8 +105,6 @@ public static S7ParameterBuilder staticParseS7ParameterBuilder( ReadBuffer readBuffer, Short messageType) throws ParseException { readBuffer.pullContext("S7ParameterReadVarRequest"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short numItems = readImplicitField("numItems", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterReadVarResponse.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterReadVarResponse.java index 18f8428caa4..c79fc96629b 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterReadVarResponse.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterReadVarResponse.java @@ -62,7 +62,6 @@ public short getNumItems() { protected void serializeS7ParameterChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7ParameterReadVarResponse"); // Simple Field (numItems) @@ -92,8 +91,6 @@ public static S7ParameterBuilder staticParseS7ParameterBuilder( ReadBuffer readBuffer, Short messageType) throws ParseException { readBuffer.pullContext("S7ParameterReadVarResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short numItems = readSimpleField("numItems", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterSetupCommunication.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterSetupCommunication.java index 4e12e06c3db..c9d4cf0974e 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterSetupCommunication.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterSetupCommunication.java @@ -74,7 +74,6 @@ public int getPduLength() { protected void serializeS7ParameterChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7ParameterSetupCommunication"); // Reserved Field (reserved) @@ -122,8 +121,6 @@ public static S7ParameterBuilder staticParseS7ParameterBuilder( ReadBuffer readBuffer, Short messageType) throws ParseException { readBuffer.pullContext("S7ParameterSetupCommunication"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); Short reservedField0 = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterUserData.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterUserData.java index aa681aade73..a0013a3181f 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterUserData.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterUserData.java @@ -62,7 +62,6 @@ public List getItems() { protected void serializeS7ParameterChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7ParameterUserData"); // Implicit Field (numItems) (Used for parsing, but its value is not stored as it's implicitly @@ -106,8 +105,6 @@ public static S7ParameterBuilder staticParseS7ParameterBuilder( ReadBuffer readBuffer, Short messageType) throws ParseException { readBuffer.pullContext("S7ParameterUserData"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short numItems = readImplicitField("numItems", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterUserDataItem.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterUserDataItem.java index 4f9ec54ccf7..b041ad34770 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterUserDataItem.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterUserDataItem.java @@ -50,7 +50,6 @@ protected abstract void serializeS7ParameterUserDataItemChild(WriteBuffer writeB public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7ParameterUserDataItem"); // Discriminator Field (itemType) (Used as input to a switch field) @@ -90,8 +89,6 @@ public static S7ParameterUserDataItem staticParse(ReadBuffer readBuffer, Object. public static S7ParameterUserDataItem staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("S7ParameterUserDataItem"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short itemType = readDiscriminatorField("itemType", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterUserDataItemCPUFunctions.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterUserDataItemCPUFunctions.java index 03c8bafb7c1..7f330b5b2b7 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterUserDataItemCPUFunctions.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterUserDataItemCPUFunctions.java @@ -110,7 +110,6 @@ protected void serializeS7ParameterUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7ParameterUserDataItemCPUFunctions"); // Implicit Field (itemLength) (Used for parsing, but its value is not stored as it's implicitly @@ -197,8 +196,6 @@ public static S7ParameterUserDataItemBuilder staticParseS7ParameterUserDataItemB ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("S7ParameterUserDataItemCPUFunctions"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short itemLength = readImplicitField("itemLength", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterWriteVarRequest.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterWriteVarRequest.java index 88985ee3a6e..b70182a707d 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterWriteVarRequest.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterWriteVarRequest.java @@ -62,7 +62,6 @@ public List getItems() { protected void serializeS7ParameterChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7ParameterWriteVarRequest"); // Implicit Field (numItems) (Used for parsing, but its value is not stored as it's implicitly @@ -106,8 +105,6 @@ public static S7ParameterBuilder staticParseS7ParameterBuilder( ReadBuffer readBuffer, Short messageType) throws ParseException { readBuffer.pullContext("S7ParameterWriteVarRequest"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short numItems = readImplicitField("numItems", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterWriteVarResponse.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterWriteVarResponse.java index 157e0db7559..58fb3442e63 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterWriteVarResponse.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7ParameterWriteVarResponse.java @@ -62,7 +62,6 @@ public short getNumItems() { protected void serializeS7ParameterChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7ParameterWriteVarResponse"); // Simple Field (numItems) @@ -92,8 +91,6 @@ public static S7ParameterBuilder staticParseS7ParameterBuilder( ReadBuffer readBuffer, Short messageType) throws ParseException { readBuffer.pullContext("S7ParameterWriteVarResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short numItems = readSimpleField("numItems", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7Payload.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7Payload.java index 8f9b7d1f2a3..27068e8ebcc 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7Payload.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7Payload.java @@ -52,7 +52,6 @@ protected abstract void serializeS7PayloadChild(WriteBuffer writeBuffer) public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7Payload"); // Switch field (Serialize the sub-type) @@ -108,8 +107,6 @@ public static S7Payload staticParse( ReadBuffer readBuffer, Short messageType, S7Parameter parameter) throws ParseException { readBuffer.pullContext("S7Payload"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadAlarm8.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadAlarm8.java index d7369d05c54..8642ab90b7e 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadAlarm8.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadAlarm8.java @@ -71,7 +71,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadAlarm8"); // Simple Field (alarmMessage) @@ -102,8 +101,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadAlarm8"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); AlarmMessagePushType alarmMessage = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadAlarmAckInd.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadAlarmAckInd.java index 1d0300ffa04..15880f9c2af 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadAlarmAckInd.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadAlarmAckInd.java @@ -71,7 +71,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadAlarmAckInd"); // Simple Field (alarmMessage) @@ -102,8 +101,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadAlarmAckInd"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); AlarmMessageAckPushType alarmMessage = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadAlarmS.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadAlarmS.java index e589cd98c43..24a994f5fc1 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadAlarmS.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadAlarmS.java @@ -71,7 +71,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadAlarmS"); // Simple Field (alarmMessage) @@ -102,8 +101,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadAlarmS"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); AlarmMessagePushType alarmMessage = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadAlarmSC.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadAlarmSC.java index a37b06e484a..e1ca33f3648 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadAlarmSC.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadAlarmSC.java @@ -71,7 +71,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadAlarmSC"); // Simple Field (alarmMessage) @@ -102,8 +101,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadAlarmSC"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); AlarmMessagePushType alarmMessage = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadAlarmSQ.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadAlarmSQ.java index e69cd518f23..d944a03afc9 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadAlarmSQ.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadAlarmSQ.java @@ -71,7 +71,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadAlarmSQ"); // Simple Field (alarmMessage) @@ -102,8 +101,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadAlarmSQ"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); AlarmMessagePushType alarmMessage = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadDiagnosticMessage.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadDiagnosticMessage.java index b9392871abb..f22947b4779 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadDiagnosticMessage.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadDiagnosticMessage.java @@ -113,7 +113,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadDiagnosticMessage"); // Simple Field (EventId) @@ -180,8 +179,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadDiagnosticMessage"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); int EventId = readSimpleField("EventId", readUnsignedInt(readBuffer, 16)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadNotify.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadNotify.java index 7bcdc3efd54..f6bf5231723 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadNotify.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadNotify.java @@ -71,7 +71,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadNotify"); // Simple Field (alarmMessage) @@ -102,8 +101,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadNotify"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); AlarmMessagePushType alarmMessage = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadNotify8.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadNotify8.java index 43960bb4a84..1c7542a478f 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadNotify8.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadNotify8.java @@ -71,7 +71,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadNotify8"); // Simple Field (alarmMessage) @@ -102,8 +101,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadNotify8"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); AlarmMessagePushType alarmMessage = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadReadVarResponse.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadReadVarResponse.java index ced89add35d..4520e992e16 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadReadVarResponse.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadReadVarResponse.java @@ -62,7 +62,6 @@ public List getItems() { protected void serializeS7PayloadChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadReadVarResponse"); // Array Field (items) @@ -98,8 +97,6 @@ public static S7PayloadBuilder staticParseS7PayloadBuilder( ReadBuffer readBuffer, Short messageType, S7Parameter parameter) throws ParseException { readBuffer.pullContext("S7PayloadReadVarResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); List items = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserData.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserData.java index 39b3de767ce..466513678c3 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserData.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserData.java @@ -62,7 +62,6 @@ public List getItems() { protected void serializeS7PayloadChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserData"); // Array Field (items) @@ -98,8 +97,6 @@ public static S7PayloadBuilder staticParseS7PayloadBuilder( ReadBuffer readBuffer, Short messageType, S7Parameter parameter) throws ParseException { readBuffer.pullContext("S7PayloadUserData"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); List items = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItem.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItem.java index b66f98148d0..89e58d08883 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItem.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItem.java @@ -75,7 +75,6 @@ protected abstract void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuf public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserDataItem"); // Simple Field (returnCode) @@ -177,8 +176,6 @@ public static S7PayloadUserDataItem staticParse( throws ParseException { readBuffer.pullContext("S7PayloadUserDataItem"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); DataTransportErrorCode returnCode = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionAlarmAckErrorResponse.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionAlarmAckErrorResponse.java index dfb5a9ef037..1d3d6828ff2 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionAlarmAckErrorResponse.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionAlarmAckErrorResponse.java @@ -61,7 +61,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserDataItemCpuFunctionAlarmAckErrorResponse"); writeBuffer.popContext("S7PayloadUserDataItemCpuFunctionAlarmAckErrorResponse"); @@ -86,8 +85,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadUserDataItemCpuFunctionAlarmAckErrorResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); readBuffer.closeContext("S7PayloadUserDataItemCpuFunctionAlarmAckErrorResponse"); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionAlarmAckRequest.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionAlarmAckRequest.java index 77d23edeba5..c74ec909136 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionAlarmAckRequest.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionAlarmAckRequest.java @@ -79,7 +79,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserDataItemCpuFunctionAlarmAckRequest"); // Const Field (functionId) @@ -130,8 +129,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadUserDataItemCpuFunctionAlarmAckRequest"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short functionId = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionAlarmAckResponse.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionAlarmAckResponse.java index c56ff8b8d66..3be0eb08c87 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionAlarmAckResponse.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionAlarmAckResponse.java @@ -79,7 +79,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserDataItemCpuFunctionAlarmAckResponse"); // Simple Field (functionId) @@ -126,8 +125,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadUserDataItemCpuFunctionAlarmAckResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short functionId = readSimpleField("functionId", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionAlarmQueryRequest.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionAlarmQueryRequest.java index 67f0ed073d6..86ef1925c10 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionAlarmQueryRequest.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionAlarmQueryRequest.java @@ -108,7 +108,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserDataItemCpuFunctionAlarmQueryRequest"); // Const Field (functionId) @@ -202,8 +201,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadUserDataItemCpuFunctionAlarmQueryRequest"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short functionId = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionAlarmQueryResponse.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionAlarmQueryResponse.java index 1bff09b4c69..8cf96d3469a 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionAlarmQueryResponse.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionAlarmQueryResponse.java @@ -72,7 +72,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserDataItemCpuFunctionAlarmQueryResponse"); // Array Field (items) @@ -109,8 +108,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadUserDataItemCpuFunctionAlarmQueryResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); byte[] items = readBuffer.readByteArray("items", Math.toIntExact(dataLength)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionMsgSubscriptionAlarmResponse.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionMsgSubscriptionAlarmResponse.java index b3456d53b1e..642c00f863e 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionMsgSubscriptionAlarmResponse.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionMsgSubscriptionAlarmResponse.java @@ -100,7 +100,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserDataItemCpuFunctionMsgSubscriptionAlarmResponse"); // Simple Field (result) @@ -160,8 +159,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadUserDataItemCpuFunctionMsgSubscriptionAlarmResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short result = readSimpleField("result", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionMsgSubscriptionRequest.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionMsgSubscriptionRequest.java index ad21923a356..c75ceaf52e1 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionMsgSubscriptionRequest.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionMsgSubscriptionRequest.java @@ -93,7 +93,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserDataItemCpuFunctionMsgSubscriptionRequest"); // Simple Field (Subscription) @@ -158,8 +157,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadUserDataItemCpuFunctionMsgSubscriptionRequest"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short Subscription = readSimpleField("Subscription", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionMsgSubscriptionResponse.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionMsgSubscriptionResponse.java index 30778765efd..e63f6c495c0 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionMsgSubscriptionResponse.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionMsgSubscriptionResponse.java @@ -61,7 +61,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserDataItemCpuFunctionMsgSubscriptionResponse"); writeBuffer.popContext("S7PayloadUserDataItemCpuFunctionMsgSubscriptionResponse"); @@ -86,8 +85,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadUserDataItemCpuFunctionMsgSubscriptionResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); readBuffer.closeContext("S7PayloadUserDataItemCpuFunctionMsgSubscriptionResponse"); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionMsgSubscriptionSysResponse.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionMsgSubscriptionSysResponse.java index b4af396e7f6..d8f5fac1d79 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionMsgSubscriptionSysResponse.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionMsgSubscriptionSysResponse.java @@ -79,7 +79,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserDataItemCpuFunctionMsgSubscriptionSysResponse"); // Simple Field (result) @@ -116,8 +115,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadUserDataItemCpuFunctionMsgSubscriptionSysResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short result = readSimpleField("result", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionReadSzlNoDataRequest.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionReadSzlNoDataRequest.java index 2ef1caa82b7..947c57fa9dc 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionReadSzlNoDataRequest.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionReadSzlNoDataRequest.java @@ -61,7 +61,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserDataItemCpuFunctionReadSzlNoDataRequest"); writeBuffer.popContext("S7PayloadUserDataItemCpuFunctionReadSzlNoDataRequest"); @@ -86,8 +85,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadUserDataItemCpuFunctionReadSzlNoDataRequest"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); readBuffer.closeContext("S7PayloadUserDataItemCpuFunctionReadSzlNoDataRequest"); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionReadSzlRequest.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionReadSzlRequest.java index a7ca1d27785..31c17cd57de 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionReadSzlRequest.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionReadSzlRequest.java @@ -79,7 +79,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserDataItemCpuFunctionReadSzlRequest"); // Simple Field (szlId) @@ -116,8 +115,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadUserDataItemCpuFunctionReadSzlRequest"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); SzlId szlId = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionReadSzlResponse.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionReadSzlResponse.java index 53d665b6938..59cd4a3653c 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionReadSzlResponse.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCpuFunctionReadSzlResponse.java @@ -72,7 +72,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserDataItemCpuFunctionReadSzlResponse"); // Array Field (items) @@ -109,8 +108,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadUserDataItemCpuFunctionReadSzlResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); byte[] items = readBuffer.readByteArray("items", Math.toIntExact(dataLength)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesChangeDrivenPush.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesChangeDrivenPush.java index 5befacafb65..c1ea18e262d 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesChangeDrivenPush.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesChangeDrivenPush.java @@ -79,7 +79,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserDataItemCyclicServicesChangeDrivenPush"); // Simple Field (itemsCount) @@ -122,8 +121,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadUserDataItemCyclicServicesChangeDrivenPush"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); int itemsCount = readSimpleField("itemsCount", readUnsignedInt(readBuffer, 16)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesChangeDrivenSubscribeResponse.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesChangeDrivenSubscribeResponse.java index 8653ab2f18b..38bc3d39110 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesChangeDrivenSubscribeResponse.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesChangeDrivenSubscribeResponse.java @@ -79,7 +79,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserDataItemCyclicServicesChangeDrivenSubscribeResponse"); // Simple Field (itemsCount) @@ -122,8 +121,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadUserDataItemCyclicServicesChangeDrivenSubscribeResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); int itemsCount = readSimpleField("itemsCount", readUnsignedInt(readBuffer, 16)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesErrorResponse.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesErrorResponse.java index e6638a7ad49..f9613dcb1ad 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesErrorResponse.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesErrorResponse.java @@ -61,7 +61,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserDataItemCyclicServicesErrorResponse"); writeBuffer.popContext("S7PayloadUserDataItemCyclicServicesErrorResponse"); @@ -86,8 +85,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadUserDataItemCyclicServicesErrorResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); readBuffer.closeContext("S7PayloadUserDataItemCyclicServicesErrorResponse"); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesPush.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesPush.java index 0231b5d84b7..c2341a414b8 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesPush.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesPush.java @@ -79,7 +79,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserDataItemCyclicServicesPush"); // Simple Field (itemsCount) @@ -122,8 +121,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadUserDataItemCyclicServicesPush"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); int itemsCount = readSimpleField("itemsCount", readUnsignedInt(readBuffer, 16)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesSubscribeRequest.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesSubscribeRequest.java index fb33e91d2cc..7376db3a7cf 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesSubscribeRequest.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesSubscribeRequest.java @@ -93,7 +93,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserDataItemCyclicServicesSubscribeRequest"); // Simple Field (itemsCount) @@ -153,8 +152,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadUserDataItemCyclicServicesSubscribeRequest"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); int itemsCount = readSimpleField("itemsCount", readUnsignedInt(readBuffer, 16)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesSubscribeResponse.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesSubscribeResponse.java index bc9aae25987..fbef37afb23 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesSubscribeResponse.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesSubscribeResponse.java @@ -79,7 +79,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserDataItemCyclicServicesSubscribeResponse"); // Simple Field (itemsCount) @@ -122,8 +121,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadUserDataItemCyclicServicesSubscribeResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); int itemsCount = readSimpleField("itemsCount", readUnsignedInt(readBuffer, 16)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesUnsubscribeRequest.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesUnsubscribeRequest.java index b1b484f92c2..eadbcbbb3f7 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesUnsubscribeRequest.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesUnsubscribeRequest.java @@ -79,7 +79,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserDataItemCyclicServicesUnsubscribeRequest"); // Simple Field (function) @@ -116,8 +115,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadUserDataItemCyclicServicesUnsubscribeRequest"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short function = readSimpleField("function", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesUnsubscribeResponse.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesUnsubscribeResponse.java index 47608319a09..9e3e74c323c 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesUnsubscribeResponse.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadUserDataItemCyclicServicesUnsubscribeResponse.java @@ -61,7 +61,6 @@ protected void serializeS7PayloadUserDataItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadUserDataItemCyclicServicesUnsubscribeResponse"); writeBuffer.popContext("S7PayloadUserDataItemCyclicServicesUnsubscribeResponse"); @@ -86,8 +85,6 @@ public static S7PayloadUserDataItemBuilder staticParseS7PayloadUserDataItemBuild throws ParseException { readBuffer.pullContext("S7PayloadUserDataItemCyclicServicesUnsubscribeResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); readBuffer.closeContext("S7PayloadUserDataItemCyclicServicesUnsubscribeResponse"); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadWriteVarRequest.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadWriteVarRequest.java index 48d4a5a334e..5c31abe5b18 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadWriteVarRequest.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadWriteVarRequest.java @@ -62,7 +62,6 @@ public List getItems() { protected void serializeS7PayloadChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadWriteVarRequest"); // Array Field (items) @@ -98,8 +97,6 @@ public static S7PayloadBuilder staticParseS7PayloadBuilder( ReadBuffer readBuffer, Short messageType, S7Parameter parameter) throws ParseException { readBuffer.pullContext("S7PayloadWriteVarRequest"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); List items = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadWriteVarResponse.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadWriteVarResponse.java index 1f6e13cea17..fca9a9f20d6 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadWriteVarResponse.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7PayloadWriteVarResponse.java @@ -62,7 +62,6 @@ public List getItems() { protected void serializeS7PayloadChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7PayloadWriteVarResponse"); // Array Field (items) @@ -98,8 +97,6 @@ public static S7PayloadBuilder staticParseS7PayloadBuilder( ReadBuffer readBuffer, Short messageType, S7Parameter parameter) throws ParseException { readBuffer.pullContext("S7PayloadWriteVarResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); List items = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7VarPayloadDataItem.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7VarPayloadDataItem.java index 4483814eac5..813eb4234a5 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7VarPayloadDataItem.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7VarPayloadDataItem.java @@ -65,7 +65,6 @@ public byte[] getData() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7VarPayloadDataItem"); // Simple Field (returnCode) @@ -154,8 +153,6 @@ public static S7VarPayloadDataItem staticParse(ReadBuffer readBuffer, Object... public static S7VarPayloadDataItem staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("S7VarPayloadDataItem"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); DataTransportErrorCode returnCode = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7VarPayloadStatusItem.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7VarPayloadStatusItem.java index aec0f0e161a..718ce59fab0 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7VarPayloadStatusItem.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7VarPayloadStatusItem.java @@ -52,7 +52,6 @@ public DataTransportErrorCode getReturnCode() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7VarPayloadStatusItem"); // Simple Field (returnCode) @@ -94,8 +93,6 @@ public static S7VarPayloadStatusItem staticParse(ReadBuffer readBuffer, Object.. public static S7VarPayloadStatusItem staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("S7VarPayloadStatusItem"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); DataTransportErrorCode returnCode = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7VarRequestParameterItem.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7VarRequestParameterItem.java index 2623497f18c..a6bf2223a27 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7VarRequestParameterItem.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7VarRequestParameterItem.java @@ -50,7 +50,6 @@ protected abstract void serializeS7VarRequestParameterItemChild(WriteBuffer writ public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7VarRequestParameterItem"); // Discriminator Field (itemType) (Used as input to a switch field) @@ -90,8 +89,6 @@ public static S7VarRequestParameterItem staticParse(ReadBuffer readBuffer, Objec public static S7VarRequestParameterItem staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("S7VarRequestParameterItem"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short itemType = readDiscriminatorField("itemType", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7VarRequestParameterItemAddress.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7VarRequestParameterItemAddress.java index 18cb81bd5fa..2acc460e075 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7VarRequestParameterItemAddress.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/S7VarRequestParameterItemAddress.java @@ -59,7 +59,6 @@ protected void serializeS7VarRequestParameterItemChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("S7VarRequestParameterItemAddress"); // Implicit Field (itemLength) (Used for parsing, but its value is not stored as it's implicitly @@ -97,8 +96,6 @@ public static S7VarRequestParameterItemBuilder staticParseS7VarRequestParameterI ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("S7VarRequestParameterItemAddress"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short itemLength = readImplicitField("itemLength", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/State.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/State.java index 82d8fb4ae96..488cc8dc647 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/State.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/State.java @@ -102,7 +102,6 @@ public boolean getSIG_1() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("State"); // Simple Field (SIG_8) @@ -178,8 +177,6 @@ public static State staticParse(ReadBuffer readBuffer, Object... args) throws Pa public static State staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("State"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); boolean SIG_8 = readSimpleField("SIG_8", readBoolean(readBuffer)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SubItem.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SubItem.java index ef70ef5de58..620086f2625 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SubItem.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SubItem.java @@ -64,7 +64,6 @@ public int getStartAddress() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("SubItem"); // Simple Field (bytesToRead) @@ -110,8 +109,6 @@ public static SubItem staticParse(ReadBuffer readBuffer, Object... args) throws public static SubItem staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("SubItem"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short bytesToRead = readSimpleField("bytesToRead", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SyntaxIdType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SyntaxIdType.java index 3dd2c85acbe..f0795feaa37 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SyntaxIdType.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SyntaxIdType.java @@ -46,7 +46,7 @@ public enum SyntaxIdType { } } - private short value; + private final short value; SyntaxIdType(short value) { this.value = value; diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SzlDataTreeItem.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SzlDataTreeItem.java index de5e20b0536..e656a4637ab 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SzlDataTreeItem.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SzlDataTreeItem.java @@ -76,7 +76,6 @@ public int getAusbe() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("SzlDataTreeItem"); // Simple Field (itemIndex) @@ -137,8 +136,6 @@ public static SzlDataTreeItem staticParse(ReadBuffer readBuffer, Object... args) public static SzlDataTreeItem staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("SzlDataTreeItem"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); int itemIndex = readSimpleField("itemIndex", readUnsignedInt(readBuffer, 16)); diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SzlId.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SzlId.java index 8f46b999d75..69c2b8d94d3 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SzlId.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SzlId.java @@ -64,7 +64,6 @@ public SzlSublist getSublistList() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("SzlId"); // Simple Field (typeClass) @@ -122,8 +121,6 @@ public static SzlId staticParse(ReadBuffer readBuffer, Object... args) throws Pa public static SzlId staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("SzlId"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); SzlModuleTypeClass typeClass = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SzlModuleTypeClass.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SzlModuleTypeClass.java index 4f93cc8312e..18ffefb3f04 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SzlModuleTypeClass.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SzlModuleTypeClass.java @@ -37,7 +37,7 @@ public enum SzlModuleTypeClass { } } - private byte value; + private final byte value; SzlModuleTypeClass(byte value) { this.value = value; diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SzlSublist.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SzlSublist.java index 36bb532d160..3659cf9fa0a 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SzlSublist.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/SzlSublist.java @@ -59,7 +59,7 @@ public enum SzlSublist { } } - private short value; + private final short value; SzlSublist(short value) { this.value = value; diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/TPKTPacket.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/TPKTPacket.java index 10351a8a735..10eab0edc43 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/TPKTPacket.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/TPKTPacket.java @@ -59,7 +59,6 @@ public short getProtocolId() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("TPKTPacket"); // Const Field (protocolId) @@ -130,8 +129,6 @@ public static TPKTPacket staticParse(ReadBuffer readBuffer, Object... args) public static TPKTPacket staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("TPKTPacket"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short protocolId = diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/TimeBase.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/TimeBase.java index 2552f372192..573645a8e68 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/TimeBase.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/TimeBase.java @@ -36,7 +36,7 @@ public enum TimeBase { } } - private short value; + private final short value; TimeBase(short value) { this.value = value; diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/TransportSize.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/TransportSize.java index 4b70936705e..d99705e7540 100644 --- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/TransportSize.java +++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/TransportSize.java @@ -373,18 +373,18 @@ public enum TransportSize { } } - private short value; - private boolean supported_S7_300; - private boolean supported_LOGO; - private short code; - private short sizeInBytes; - private boolean supported_S7_400; - private boolean supported_S7_1200; - private short shortName; - private boolean supported_S7_1500; - private DataTransportSize dataTransportSize; - private String dataProtocolId; - private TransportSize baseType; + private final short value; + private final boolean supported_S7_300; + private final boolean supported_LOGO; + private final short code; + private final short sizeInBytes; + private final boolean supported_S7_400; + private final boolean supported_S7_1200; + private final short shortName; + private final boolean supported_S7_1500; + private final DataTransportSize dataTransportSize; + private final String dataProtocolId; + private final TransportSize baseType; TransportSize( short value, @@ -431,7 +431,7 @@ public static TransportSize firstEnumForFieldSupported_S7_300(boolean fieldValue } public static List enumsForFieldSupported_S7_300(boolean fieldValue) { - List _values = new ArrayList(); + List _values = new ArrayList<>(); for (TransportSize _val : TransportSize.values()) { if (_val.getSupported_S7_300() == fieldValue) { _values.add(_val); @@ -454,7 +454,7 @@ public static TransportSize firstEnumForFieldSupported_LOGO(boolean fieldValue) } public static List enumsForFieldSupported_LOGO(boolean fieldValue) { - List _values = new ArrayList(); + List _values = new ArrayList<>(); for (TransportSize _val : TransportSize.values()) { if (_val.getSupported_LOGO() == fieldValue) { _values.add(_val); @@ -477,7 +477,7 @@ public static TransportSize firstEnumForFieldCode(short fieldValue) { } public static List enumsForFieldCode(short fieldValue) { - List _values = new ArrayList(); + List _values = new ArrayList<>(); for (TransportSize _val : TransportSize.values()) { if (_val.getCode() == fieldValue) { _values.add(_val); @@ -500,7 +500,7 @@ public static TransportSize firstEnumForFieldSizeInBytes(short fieldValue) { } public static List enumsForFieldSizeInBytes(short fieldValue) { - List _values = new ArrayList(); + List _values = new ArrayList<>(); for (TransportSize _val : TransportSize.values()) { if (_val.getSizeInBytes() == fieldValue) { _values.add(_val); @@ -523,7 +523,7 @@ public static TransportSize firstEnumForFieldSupported_S7_400(boolean fieldValue } public static List enumsForFieldSupported_S7_400(boolean fieldValue) { - List _values = new ArrayList(); + List _values = new ArrayList<>(); for (TransportSize _val : TransportSize.values()) { if (_val.getSupported_S7_400() == fieldValue) { _values.add(_val); @@ -546,7 +546,7 @@ public static TransportSize firstEnumForFieldSupported_S7_1200(boolean fieldValu } public static List enumsForFieldSupported_S7_1200(boolean fieldValue) { - List _values = new ArrayList(); + List _values = new ArrayList<>(); for (TransportSize _val : TransportSize.values()) { if (_val.getSupported_S7_1200() == fieldValue) { _values.add(_val); @@ -569,7 +569,7 @@ public static TransportSize firstEnumForFieldShortName(short fieldValue) { } public static List enumsForFieldShortName(short fieldValue) { - List _values = new ArrayList(); + List _values = new ArrayList<>(); for (TransportSize _val : TransportSize.values()) { if (_val.getShortName() == fieldValue) { _values.add(_val); @@ -592,7 +592,7 @@ public static TransportSize firstEnumForFieldSupported_S7_1500(boolean fieldValu } public static List enumsForFieldSupported_S7_1500(boolean fieldValue) { - List _values = new ArrayList(); + List _values = new ArrayList<>(); for (TransportSize _val : TransportSize.values()) { if (_val.getSupported_S7_1500() == fieldValue) { _values.add(_val); @@ -615,7 +615,7 @@ public static TransportSize firstEnumForFieldDataTransportSize(DataTransportSize } public static List enumsForFieldDataTransportSize(DataTransportSize fieldValue) { - List _values = new ArrayList(); + List _values = new ArrayList<>(); for (TransportSize _val : TransportSize.values()) { if (_val.getDataTransportSize() == fieldValue) { _values.add(_val); @@ -638,7 +638,7 @@ public static TransportSize firstEnumForFieldDataProtocolId(String fieldValue) { } public static List enumsForFieldDataProtocolId(String fieldValue) { - List _values = new ArrayList(); + List _values = new ArrayList<>(); for (TransportSize _val : TransportSize.values()) { if (_val.getDataProtocolId().equals(fieldValue)) { _values.add(_val); @@ -661,7 +661,7 @@ public static TransportSize firstEnumForFieldBaseType(TransportSize fieldValue) } public static List enumsForFieldBaseType(TransportSize fieldValue) { - List _values = new ArrayList(); + List _values = new ArrayList<>(); for (TransportSize _val : TransportSize.values()) { if (_val.getBaseType() == fieldValue) { _values.add(_val); diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/events/S7CyclicEvent.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/events/S7CyclicEvent.java index 9ca081a0bc4..1010e3eee3a 100644 --- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/events/S7CyclicEvent.java +++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/events/S7CyclicEvent.java @@ -23,6 +23,7 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.nio.charset.Charset; +import java.time.Duration; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; @@ -44,6 +45,7 @@ import org.apache.plc4x.java.s7.readwrite.S7PayloadUserDataItemCyclicServicesChangeDrivenSubscribeResponse; import org.apache.plc4x.java.s7.readwrite.S7PayloadUserDataItemCyclicServicesPush; import org.apache.plc4x.java.s7.readwrite.S7PayloadUserDataItemCyclicServicesSubscribeResponse; +import org.apache.plc4x.java.s7.readwrite.utils.StaticHelper; /** * @@ -73,13 +75,15 @@ public enum Fields{ public S7CyclicEvent(PlcSubscriptionRequest request, short jobid, S7PayloadUserDataItemCyclicServicesPush event) { this.map = new HashMap(); this.timeStamp = Instant.now(); - this.request = request; + this.request = request; map.put(Fields.TYPE.name(), "CYCEVENT"); map.put(Fields.TIMESTAMP.name(),this.timeStamp); map.put(Fields.JOBID.name(), jobid); - map.put(Fields.ITEMSCOUNT.name(), event.getItemsCount()); - for (int i=0; i { + int i = n[0]; map.put(Fields.RETURNCODE_.name()+i, event.getItems().get(i).getReturnCode().getValue()); map.put(Fields.TRANSPORTSIZE_.name()+i, event.getItems().get(i).getTransportSize().getValue()); byte[] buffer = new byte[event.getItems().get(i).getData().size()]; @@ -88,8 +92,23 @@ public S7CyclicEvent(PlcSubscriptionRequest request, short jobid, S7PayloadUserD buffer[j] = s.byteValue(); j ++; }); - map.put(Fields.DATA_.name()+i, buffer); - } + map.put(tagname, buffer); + n[0]++; + }); + + +// for (int i=0; i{ +// buffer[j] = s.byteValue(); +// j ++; +// }); +// map.put(Fields.DATA_.name()+i, buffer); +// } } public S7CyclicEvent(PlcSubscriptionRequest request, short jobid, S7PayloadUserDataItemCyclicServicesChangeDrivenPush event) { @@ -99,8 +118,11 @@ public S7CyclicEvent(PlcSubscriptionRequest request, short jobid, S7PayloadUserD map.put(Fields.TYPE.name(), "CYCEVENT"); map.put(Fields.TIMESTAMP.name(),this.timeStamp); map.put(Fields.JOBID.name(), jobid); - map.put(Fields.ITEMSCOUNT.name(), event.getItemsCount()); - for (int i=0; i { + int i = n[0]; map.put(Fields.RETURNCODE_.name()+i, event.getItems().get(i).getReturnCode().getValue()); map.put(Fields.TRANSPORTSIZE_.name()+i, event.getItems().get(i).getTransportSize().getValue()); byte[] buffer = new byte[event.getItems().get(i).getData().size()]; @@ -109,8 +131,20 @@ public S7CyclicEvent(PlcSubscriptionRequest request, short jobid, S7PayloadUserD buffer[j] = s.byteValue(); j ++; }); - map.put(Fields.DATA_.name()+i, buffer); - } + map.put(tagname, buffer); + n[0]++; + }); +// for (int i=0; i{ +// buffer[j] = s.byteValue(); +// j ++; +// }); +// map.put(Fields.DATA_.name()+i, buffer); +// } } public S7CyclicEvent(PlcSubscriptionRequest request, short jobid, S7PayloadUserDataItemCyclicServicesSubscribeResponse event) { @@ -121,7 +155,10 @@ public S7CyclicEvent(PlcSubscriptionRequest request, short jobid, S7PayloadUserD map.put(Fields.TIMESTAMP.name(),this.timeStamp); map.put(Fields.JOBID.name(), jobid); map.put(Fields.ITEMSCOUNT.name(), event.getItemsCount()); - for (int i=0; i { + int i = n[0]; map.put(Fields.RETURNCODE_.name()+i, event.getItems().get(i).getReturnCode().getValue()); map.put(Fields.TRANSPORTSIZE_.name()+i, event.getItems().get(i).getTransportSize().getValue()); byte[] buffer = new byte[event.getItems().get(i).getData().size()]; @@ -130,8 +167,20 @@ public S7CyclicEvent(PlcSubscriptionRequest request, short jobid, S7PayloadUserD buffer[j] = s.byteValue(); j ++; }); - map.put(Fields.DATA_.name()+i, buffer); - } + map.put(tagname, buffer); + n[0]++; + }); +// for (int i=0; i{ +// buffer[j] = s.byteValue(); +// j ++; +// }); +// map.put(Fields.DATA_.name()+i, buffer); +// } } public S7CyclicEvent(PlcSubscriptionRequest request, short jobid, S7PayloadUserDataItemCyclicServicesChangeDrivenSubscribeResponse event) { @@ -142,7 +191,10 @@ public S7CyclicEvent(PlcSubscriptionRequest request, short jobid, S7PayloadUserD map.put(Fields.TIMESTAMP.name(),this.timeStamp); map.put(Fields.JOBID.name(), jobid); map.put(Fields.ITEMSCOUNT.name(), event.getItemsCount()); - for (int i=0; i { + int i = n[0]; map.put(Fields.RETURNCODE_.name()+i, event.getItems().get(i).getReturnCode().getValue()); map.put(Fields.TRANSPORTSIZE_.name()+i, event.getItems().get(i).getTransportSize().getValue()); byte[] buffer = new byte[event.getItems().get(i).getData().size()]; @@ -151,8 +203,20 @@ public S7CyclicEvent(PlcSubscriptionRequest request, short jobid, S7PayloadUserD buffer[j] = s.byteValue(); j ++; }); - map.put(Fields.DATA_.name()+i, buffer); - } + map.put(tagname, buffer); + n[0]++; + }); +// for (int i=0; i{ +// buffer[j] = s.byteValue(); +// j ++; +// }); +// map.put(Fields.DATA_.name()+i, buffer); +// } } @Override @@ -167,22 +231,22 @@ public Instant getTimestamp() { @Override public PlcReadRequest getRequest() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public PlcValue getAsPlcValue() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public PlcValue getPlcValue(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public int getNumberOfValues(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override @@ -193,54 +257,66 @@ public Object getObject(String name) { @Override public Object getObject(String name, int index) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public Collection getAllObjects(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean isValidBoolean(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return isValidBoolean(name, 0); } @Override public boolean isValidBoolean(String name, int index) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + try { + boolean dummy = getBoolean(name, index); + return true; + } catch (Exception ex) { + return false; + } } @Override public Boolean getBoolean(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return getBoolean(name, 0); } @Override public Boolean getBoolean(String name, int index) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + if (!(map.get(name) instanceof byte[])) + throw new UnsupportedOperationException("Field is not a buffer of bytes. Required byte[] type."); + ByteBuf byteBuf = Unpooled.wrappedBuffer((byte[]) map.get(name)); + int pos = index * 1; + return byteBuf.getBoolean(pos); } @Override public Collection getAllBooleans(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean isValidByte(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return isValidByte(name, 0); } @Override public boolean isValidByte(String name, int index) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + try { + byte dummy = getByte(name, index); + return true; + } catch (Exception ex) { + return false; + } } @Override public Byte getByte(String name) { - if (!(map.get(name) instanceof Byte)) - throw new UnsupportedOperationException("Field is not a Byte. Required Byte type."); - return (byte) map.get(name); + return getByte(name, 0); } @Override @@ -248,7 +324,7 @@ public Byte getByte(String name, int index) { if (!(map.get(name) instanceof byte[])) throw new UnsupportedOperationException("Field is not a buffer of bytes. Required byte[] type."); ByteBuf byteBuf = Unpooled.wrappedBuffer((byte[]) map.get(name)); - int pos = index*Byte.BYTES; + int pos = index * Byte.BYTES; return byteBuf.getByte(pos); } @@ -266,18 +342,22 @@ public Collection getAllBytes(String name) { @Override public boolean isValidShort(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return isValidShort(name, 0); } @Override public boolean isValidShort(String name, int index) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + try { + short dummy = getShort(name, index); + return true; + } catch (Exception ex) { + return false; + } } @Override public Short getShort(String name) { - if (!(map.get(name) instanceof Short)) return null; - return (short) map.get(name); + return getShort(name, 0); } @Override @@ -285,8 +365,8 @@ public Short getShort(String name, int index) { if (!(map.get(name) instanceof byte[])) throw new UnsupportedOperationException("Field is not a buffer of bytes. Required byte[] type."); ByteBuf byteBuf = Unpooled.wrappedBuffer((byte[]) map.get(name)); - int pos = index*Short.BYTES; - return byteBuf.getShort(index); + int pos = index * Short.BYTES; + return byteBuf.getShort(pos); } @Override @@ -301,17 +381,22 @@ public Collection getAllShorts(String name) { @Override public boolean isValidInteger(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return isValidInteger(name, 0); } @Override public boolean isValidInteger(String name, int index) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + try { + int dummy = getInteger(name, index); + return true; + } catch (Exception ex) { + return false; + } } @Override public Integer getInteger(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return getInteger(name, 0); } @Override @@ -319,7 +404,7 @@ public Integer getInteger(String name, int index) { if (!(map.get(name) instanceof byte[])) throw new UnsupportedOperationException("Field is not a buffer of bytes. Required byte[] type."); ByteBuf byteBuf = Unpooled.wrappedBuffer((byte[]) map.get(name)); - int pos = index*Integer.BYTES; + int pos = index * Integer.BYTES; return byteBuf.getInt(pos); } @@ -335,42 +420,47 @@ public Collection getAllIntegers(String name) { @Override public boolean isValidBigInteger(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean isValidBigInteger(String name, int index) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public BigInteger getBigInteger(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public BigInteger getBigInteger(String name, int index) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public Collection getAllBigIntegers(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean isValidLong(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return isValidLong(name, 0); } @Override public boolean isValidLong(String name, int index) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + try { + long dummy = getLong(name, index); + return true; + } catch (Exception ex) { + return false; + } } @Override public Long getLong(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return getLong(name, 0); } @Override @@ -394,17 +484,22 @@ public Collection getAllLongs(String name) { @Override public boolean isValidFloat(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return isValidFloat(name, 0); } @Override public boolean isValidFloat(String name, int index) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + try { + float dummy = getFloat(name, index); + return true; + } catch (Exception ex) { + return false; + } } @Override public Float getFloat(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return getFloat(name, 0); } @Override @@ -428,17 +523,22 @@ public Collection getAllFloats(String name) { @Override public boolean isValidDouble(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return isValidDouble(name, 0); } @Override public boolean isValidDouble(String name, int index) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + try { + double dummy = getDouble(name, index); + return true; + } catch (Exception ex) { + return false; + } } @Override public Double getDouble(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return getDouble(name, 0); } @Override @@ -462,37 +562,42 @@ public Collection getAllDoubles(String name) { @Override public boolean isValidBigDecimal(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean isValidBigDecimal(String name, int index) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public BigDecimal getBigDecimal(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public BigDecimal getBigDecimal(String name, int index) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public Collection getAllBigDecimals(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean isValidString(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return isValidString(name, 0); } @Override public boolean isValidString(String name, int index) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + try { + String dummy = getString(name, index); + return true; + } catch (Exception ex) { + return false; + } } @Override @@ -505,102 +610,175 @@ public String getString(String name) { @Override public String getString(String name, int index) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public Collection getAllStrings(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean isValidTime(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return isValidTime(name, 0); } @Override public boolean isValidTime(String name, int index) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + try { + LocalTime dummy = getTime(name, index); + return true; + } catch (Exception ex) { + return false; + } } @Override public LocalTime getTime(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return getTime(name, 0); } + /* + * In S7, data type TIME occupies one double word. + * The value is in milliseconds (ms). + */ @Override public LocalTime getTime(String name, int index) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + if (!(map.get(name) instanceof byte[])) + throw new UnsupportedOperationException("Field is not a buffer of bytes. Required byte[] type."); + ByteBuf byteBuf = Unpooled.wrappedBuffer((byte[]) map.get(name)); + int pos = index * Integer.BYTES; + int value = byteBuf.getInt(pos); + Duration dr = StaticHelper.S7TimeToDuration(value); + LocalTime time = LocalTime.of((int) dr.toHoursPart(), (int) dr.toMinutesPart(), (int) dr.toSecondsPart(), (int) dr.toNanosPart()); + return time; } @Override public Collection getAllTimes(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + if (!(map.get(name) instanceof byte[])) + throw new UnsupportedOperationException("Field is not a buffer of bytes. Required byte[] type."); + ByteBuf byteBuf = Unpooled.wrappedBuffer((byte[]) map.get(name)); + int nitems = (byteBuf.capacity() / Integer.BYTES); + + List items = new ArrayList(); + + for (int i = 0; i < nitems; i++) { + items.add(getTime(name, i)); + } + + return items; } @Override public boolean isValidDate(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return isValidDate(name, 0); } @Override public boolean isValidDate(String name, int index) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + try { + LocalDate dummy = getDate(name, index); + return true; + } catch (Exception ex) { + return false; + } } @Override public LocalDate getDate(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return getDate(name, 0); } @Override public LocalDate getDate(String name, int index) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + if (!(map.get(name) instanceof byte[])) + throw new UnsupportedOperationException("Field is not a buffer of bytes. Required byte[] type."); + ByteBuf byteBuf = Unpooled.wrappedBuffer((byte[]) map.get(name)); + int pos = index * Short.BYTES; + short value = byteBuf.getShort(pos); + LocalDate date = StaticHelper.S7DateToLocalDate(value); + + return date; } @Override public Collection getAllDates(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + if (!(map.get(name) instanceof byte[])) + throw new UnsupportedOperationException("Field is not a buffer of bytes. Required byte[] type."); + ByteBuf byteBuf = Unpooled.wrappedBuffer((byte[]) map.get(name)); + int nitems = (byteBuf.capacity() / Short.BYTES); + + List items = new ArrayList(); + + for (int i = 0; i < nitems; i++) { + items.add(getDate(name, i)); + } + + return items; } @Override public boolean isValidDateTime(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return isValidDateTime(name, 0); } @Override public boolean isValidDateTime(String name, int index) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + try { + LocalDateTime dummy = getDateTime(name, index); + return true; + } catch (Exception ex) { + return false; + } } @Override public LocalDateTime getDateTime(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return getDateTime(name, 0); } @Override public LocalDateTime getDateTime(String name, int index) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + if (!(map.get(name) instanceof byte[])) + throw new UnsupportedOperationException("Field is not a buffer of bytes. Required byte[] type."); + ByteBuf byteBuf = Unpooled.wrappedBuffer((byte[]) map.get(name)); + int pos = index * Long.BYTES; + + LocalDateTime datetime = StaticHelper.S7DateTimeToLocalDateTime(byteBuf.slice(pos, Long.BYTES)); + + return datetime; } @Override public Collection getAllDateTimes(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + if (!(map.get(name) instanceof byte[])) + throw new UnsupportedOperationException("Field is not a buffer of bytes. Required byte[] type."); + ByteBuf byteBuf = Unpooled.wrappedBuffer((byte[]) map.get(name)); + int nitems = (byteBuf.capacity() / Long.BYTES); + + List items = new ArrayList(); + + for (int i = 0; i < nitems; i++) { + items.add(getDateTime(name, i)); + } + + return items; } @Override public Collection getTagNames() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public PlcTag getTag(String name) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public PlcResponseCode getResponseCode(String name) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/events/S7ModeEvent.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/events/S7ModeEvent.java index aeb1923ec85..d84122a60ac 100644 --- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/events/S7ModeEvent.java +++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/events/S7ModeEvent.java @@ -56,6 +56,7 @@ public S7ModeEvent(S7ParameterModeTransition parameter) { map.put(Fields.CURRENT_MODE.name(), parameter.getCurrentMode()); this.timeStamp = Instant.now(); map.put(Fields.TIMESTAMP .name(), this.timeStamp ); + map.put(Fields.MAP.name(), map); } diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/S7Driver.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/S7Driver.java index 8a931a3e789..89906f60c3b 100644 --- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/S7Driver.java +++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/S7Driver.java @@ -136,5 +136,7 @@ public void accept(ByteBuf byteBuf) { public S7Tag prepareTag(String tagAddress){ return S7Tag.of(tagAddress); } + + } diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/configuration/S7Configuration.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/configuration/S7Configuration.java index 039e91b1f78..466f0e8affd 100644 --- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/configuration/S7Configuration.java +++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/configuration/S7Configuration.java @@ -76,20 +76,20 @@ public class S7Configuration implements Configuration, TcpTransportConfiguration public String controllerType; @ConfigurationParameter("read-timeout") - @IntDefaultValue(8) - public int readTimeout = 8; + @IntDefaultValue(0) + public int readTimeout = 0; @ConfigurationParameter("ping") @BooleanDefaultValue(false) public boolean ping = false; @ConfigurationParameter("ping-time") - @IntDefaultValue(-1) - public int pingTime = -1; + @IntDefaultValue(0) + public int pingTime = 0; @ConfigurationParameter("retry-time") - @IntDefaultValue(4) - public int retryTime = 4; + @IntDefaultValue(0) + public int retryTime = 0; public int getLocalRack() { @@ -213,7 +213,7 @@ public void setPingTime(int pingTime) { } public int getRetryTime() { - return pingTime; + return retryTime; } public void setRetryTime(int retryTime) { diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/context/S7DriverContext.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/context/S7DriverContext.java index b4ccec193fe..40e6806c8d4 100644 --- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/context/S7DriverContext.java +++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/context/S7DriverContext.java @@ -84,7 +84,8 @@ public void setConfiguration(S7Configuration configuration) { this.readTimeout = configuration.readTimeout; this.ping = configuration.ping; - this.pingTime = configuration.pingTime; + this.pingTime = (configuration.pingTime == 0)?10:configuration.pingTime; + this.retryTime = configuration.retryTime; } public boolean isPassiveMode() { @@ -184,7 +185,7 @@ public void setPingTime(int pingTime) { } public int getRetryTime() { - return pingTime; + return retryTime; } public void setRetryTime(int retryTime) { diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/optimizer/S7Optimizer.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/optimizer/S7Optimizer.java index d33ca435bee..0572fb9a1b8 100644 --- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/optimizer/S7Optimizer.java +++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/optimizer/S7Optimizer.java @@ -50,9 +50,9 @@ public class S7Optimizer extends BaseOptimizer { new S7AddressAny(TransportSize.INT, 1, 1, MemoryArea.DATA_BLOCKS, 1, (byte) 0).getLengthInBytes(); @Override - protected List processReadRequest(PlcReadRequest readRequest, DriverContext driverContext) { + protected List processReadRequest(PlcReadRequest readRequest, DriverContext driverContext) { S7DriverContext s7DriverContext = (S7DriverContext) driverContext; - List processedRequests = new LinkedList<>(); + List processedRequests = new LinkedList<>(); // This calculates the size of the header for the request and response. int curRequestSize = EMPTY_READ_REQUEST_SIZE; @@ -116,10 +116,11 @@ protected List processReadRequest(PlcReadRequest readRequest, Driver return processedRequests; } + @Override - protected List processWriteRequest(PlcWriteRequest writeRequest, DriverContext driverContext) { + protected List processWriteRequest(PlcWriteRequest writeRequest, DriverContext driverContext) { S7DriverContext s7DriverContext = (S7DriverContext) driverContext; - List processedRequests = new LinkedList<>(); + List processedRequests = new LinkedList<>(); // This calculates the size of the header for the request and response. int curRequestSize = EMPTY_WRITE_REQUEST_SIZE; diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HGeneratedDriverBase.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HGeneratedDriverBase.java index f8e91e6150b..bb700ae03ce 100644 --- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HGeneratedDriverBase.java +++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HGeneratedDriverBase.java @@ -149,7 +149,7 @@ public PlcConnection getConnection(String connectionString) throws PlcConnection awaitDiscoverComplete = Boolean.parseBoolean(System.getProperty(PROPERTY_PLC4X_FORCE_AWAIT_DISCOVER_COMPLETE)); } - return new S7HDefaultNettyPlcConnection( + return new S7HPlcConnection( canRead(), canWrite(), canSubscribe(), canBrowse(), getTagHandler(), getValueHandler(), diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HMux.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HMux.java index a7b68c30283..9697d6d774b 100644 --- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HMux.java +++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HMux.java @@ -25,5 +25,6 @@ public interface S7HMux { public void setEmbededhannel(Channel embeded_channel); public void setPrimaryChannel(Channel primary_channel); public void setSecondaryChannel(Channel secondary_channel); +public Channel getTCPChannel(); } diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HMuxImpl.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HMuxImpl.java index dd42b232d70..b0c02e71c90 100644 --- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HMuxImpl.java +++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HMuxImpl.java @@ -19,6 +19,7 @@ package org.apache.plc4x.java.s7.readwrite.protocol; import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandlerContext; @@ -29,8 +30,11 @@ import io.netty.util.AttributeKey; import java.time.LocalTime; import java.util.List; +import java.util.concurrent.TimeUnit; import org.apache.plc4x.java.spi.events.ConnectEvent; +import org.apache.plc4x.java.spi.events.ConnectedEvent; import org.apache.plc4x.java.spi.events.DisconnectEvent; +import org.apache.plc4x.java.spi.events.DisconnectedEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,6 +63,15 @@ public class S7HMuxImpl extends MessageToMessageCodec implemen */ final static AttributeKey IS_CONNECTED = AttributeKey.valueOf("IS_CONNECTED"); + /* + * This attribute indicates to the other handlers that the channel is connected + * or disconnected because a switch is being made between TCP channels or + * both TCP channels are disconnected. + * Default value: false + */ + final static AttributeKey WAS_CONNECTED = AttributeKey.valueOf("WAS_CONNECTED"); + + /* * This attribute indicates to the other handlers which channel is being used, * this allows the request to be properly prepared. @@ -117,7 +130,6 @@ public class S7HMuxImpl extends MessageToMessageCodec implemen */ @Override protected void encode(ChannelHandlerContext ctx, ByteBuf outbb, List list) throws Exception { - System.out.println("Llego aqui: " + outbb); if ((embed_ctx == null) && (ctx.channel() instanceof EmbeddedChannel)) embed_ctx = ctx; if ((tcp_channel != null) && (embed_ctx == ctx)){ tcp_channel.writeAndFlush(outbb.copy()); @@ -132,7 +144,7 @@ protected void encode(ChannelHandlerContext ctx, ByteBuf outbb, List lis * the pipeline of the channel "embeded_channel" */ @Override - protected void decode(ChannelHandlerContext ctx, ByteBuf inbb, List list) throws Exception { + protected void decode(ChannelHandlerContext ctx, ByteBuf inbb, List list) throws Exception { embed_ctx.fireChannelRead(inbb.copy()); } @@ -156,28 +168,31 @@ public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exceptio /* * The events detected here flow from the S7ProtocolLogic object. - * Upon receiving the "ConnectEvent" event, we must safely add the watchdog + * Upon receiving the "ConnectedEvent" event, we must safely add the watchdog * to the pipeline of the "tcp_channel" connection. * The supervision time can be defined in the connection URL, - * the default value being 8 secs, this value being defined experimentally. + * the default value being 0 secs disabling this function. + * This value being defined experimentally, a typical value is 8 seconds. */ @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { super.userEventTriggered(ctx, evt); logger.info(LocalTime.now().toString() + " userEventTriggered: " + ctx.name() + " Event: " + evt); - if (evt instanceof ConnectEvent) { + if (evt instanceof ConnectedEvent) { try { tcp_channel.pipeline().remove("watchdog"); } catch (Exception ex){ logger.info(ex.toString()); } try { - tcp_channel.pipeline().addFirst("watchdog", new ReadTimeoutHandler(30)); + if (embeded_channel.attr(READ_TIME_OUT).get() > 0) + tcp_channel.pipeline().addFirst("watchdog", + new ReadTimeoutHandler(embeded_channel.attr(READ_TIME_OUT).get())); if (tcp_channel.isActive()) { - embeded_channel.attr(IS_CONNECTED).set(true); + embeded_channel.attr(IS_CONNECTED).set(true); } else { embeded_channel.attr(IS_CONNECTED).set(false); - } + } } catch (Exception ex){ logger.info(ex.toString()); } @@ -212,47 +227,53 @@ public void channelUnregistered(ChannelHandlerContext ctx) throws Exception { super.channelUnregistered(ctx); logger.debug(LocalTime.now().toString() + " channelUnregistered: " + ctx.name() ); String strCanal = (tcp_channel == primary_channel)?"PRIMARY":"SECONDARY"; - logger.debug("Unregistered of channel: " + strCanal); + logger.info("Unregistered of channel: " + strCanal); //TODO: If embedded channel is closed, we need close all channels if (ctx == embed_ctx) return; - if (tcp_channel == ctx.channel()) - embeded_channel.attr(IS_CONNECTED).set(false); + if (tcp_channel == ctx.channel()) { + embeded_channel.attr(IS_CONNECTED).set(false); + embeded_channel.attr(WAS_CONNECTED).set(true); + embeded_channel.pipeline().fireUserEventTriggered(new DisconnectedEvent()); + } logger.info(embed_ctx.executor().toString()); if ((tcp_channel == primary_channel) && (primary_channel == ctx.channel())) if ((!primary_channel.isActive()) && - (secondary_channel != null)) { - if (secondary_channel.isActive()) + (secondary_channel != null)) + if (secondary_channel.isActive()) { synchronized(tcp_channel) { logger.info("Using secondary TCP channel."); tcp_channel = secondary_channel; embeded_channel.attr(IS_PRIMARY).set(false); - embeded_channel.pipeline().fireUserEventTriggered(new ConnectEvent()); + embeded_channel.pipeline().fireUserEventTriggered(new ConnectEvent()); } }; - + if ((tcp_channel == secondary_channel) && (secondary_channel == ctx.channel())) - if ((!secondary_channel.isActive() && - (primary_channel.isActive()))) { - synchronized(tcp_channel) { + if ((!secondary_channel.isActive()) && + (primary_channel != null)) + if (primary_channel.isActive()) { + synchronized(tcp_channel) { logger.info("Using primary TCP channel."); tcp_channel = primary_channel; - embeded_channel.attr(IS_PRIMARY).set(true); - embeded_channel.pipeline().fireUserEventTriggered(new ConnectEvent()); + embeded_channel.attr(IS_PRIMARY).set(true); + embeded_channel.pipeline().fireUserEventTriggered(new ConnectEvent()); } - } + } + } @Override public void setEmbededhannel(Channel embeded_channel) { this.embeded_channel = embeded_channel; - this.embeded_channel.attr(IS_CONNECTED).set(false); + this.embeded_channel.attr(IS_CONNECTED).set(false); + this.embeded_channel.attr(WAS_CONNECTED).set(false); this.embeded_channel.attr(IS_PRIMARY).set(true); this.embeded_channel.attr(READ_TIME_OUT).set(8); this.embeded_channel.attr(IS_PING_ACTIVE).set(false); @@ -260,25 +281,35 @@ public void setEmbededhannel(Channel embeded_channel) { this.embeded_channel.attr(RETRY_TIME).set(8); } + @Override public void setPrimaryChannel(Channel primary_channel) { if ((this.primary_channel == null) && (tcp_channel == null)){ if (primary_channel != null){ this.primary_channel = primary_channel; tcp_channel = primary_channel; - embeded_channel.attr(IS_PRIMARY).set(true); + embeded_channel.attr(IS_PRIMARY).set(true); } - } else if ((!this.primary_channel.isActive()) && (tcp_channel == secondary_channel)){ + } else if ((this.primary_channel == null) || + ((tcp_channel == secondary_channel)) && (tcp_channel.isActive())){ + this.primary_channel = primary_channel; + + } else if ((!this.primary_channel.isActive()) && (tcp_channel == secondary_channel)){ this.primary_channel = primary_channel; - } else if ((!this.primary_channel.isActive()) && (tcp_channel == this.primary_channel)){ + + } else if (((!this.primary_channel.isActive()) && (tcp_channel == this.primary_channel)) || + (primary_channel.isActive())) { synchronized(tcp_channel) { tcp_channel.close(); this.primary_channel = primary_channel; tcp_channel = primary_channel; - embeded_channel.attr(IS_PRIMARY).set(true); - if (tcp_channel.isActive()) { - embed_ctx.fireUserEventTriggered(new ConnectEvent()); + embeded_channel.attr(IS_PRIMARY).set(true); + + if (tcp_channel.isActive()) { + embed_ctx.fireUserEventTriggered(new ConnectEvent()); } } + } else if (primary_channel.isActive()) { + } } @@ -290,11 +321,16 @@ public void setSecondaryChannel(Channel secondary_channel) { tcp_channel = secondary_channel; embeded_channel.attr(IS_PRIMARY).set(false); } - } else if ((this.secondary_channel == null) || (tcp_channel == primary_channel)){ + + } else if ((this.secondary_channel == null) || + ((tcp_channel == primary_channel)) && (tcp_channel.isActive())){ this.secondary_channel = secondary_channel; + } else if ((!this.secondary_channel.isActive()) && (tcp_channel == primary_channel)){ this.secondary_channel = secondary_channel; - } else if ((!this.secondary_channel.isActive()) && (tcp_channel == this.secondary_channel)){ + + } else if (((!this.secondary_channel.isActive()) && (tcp_channel == this.secondary_channel)) || + (secondary_channel.isActive())){ synchronized(tcp_channel) { tcp_channel.close(); this.secondary_channel = secondary_channel; @@ -306,6 +342,11 @@ public void setSecondaryChannel(Channel secondary_channel) { } } } + + @Override + public Channel getTCPChannel() { + return tcp_channel; + } } diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HDefaultNettyPlcConnection.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HPlcConnection.java similarity index 65% rename from plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HDefaultNettyPlcConnection.java rename to plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HPlcConnection.java index 4ff983d010d..0e93414c363 100644 --- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HDefaultNettyPlcConnection.java +++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HPlcConnection.java @@ -20,16 +20,25 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; +import io.netty.channel.EventLoop; import io.netty.channel.embedded.EmbeddedChannel; import io.netty.handler.codec.MessageToMessageCodec; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; +import java.util.Timer; +import java.util.TimerTask; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; +import java.util.logging.Level; +import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.apache.plc4x.java.api.authentication.PlcAuthentication; import org.apache.plc4x.java.api.exceptions.PlcConnectionException; +import org.apache.plc4x.java.api.listener.ConnectionStateListener; import org.apache.plc4x.java.api.messages.PlcReadRequest; import org.apache.plc4x.java.api.messages.PlcReadResponse; import org.apache.plc4x.java.api.value.PlcValueHandler; @@ -40,24 +49,38 @@ import org.apache.plc4x.java.spi.connection.PlcTagHandler; import org.apache.plc4x.java.spi.connection.ProtocolStackConfigurer; import org.apache.plc4x.java.spi.events.CloseConnectionEvent; +import org.apache.plc4x.java.spi.events.ConnectEvent; +import org.apache.plc4x.java.spi.events.ConnectedEvent; import org.apache.plc4x.java.spi.events.DisconnectEvent; +import org.apache.plc4x.java.spi.events.DisconnectedEvent; import org.apache.plc4x.java.spi.optimizer.BaseOptimizer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * - * @author cgarcia + * This object generates the main connection and includes the management + * of multiple connections to the PLC, in the case of S7H there + * are two connections. + * Here the reference to the multiplexer object (S7HMuxImpl) is maintained, + * which is in charge of managing the physical TCP connections. + * + * TODO: It should be able to run in the "channel" executor. + * You should be able to remove the "executor". */ -public class S7HDefaultNettyPlcConnection extends DefaultNettyPlcConnection implements Runnable{ +public class S7HPlcConnection extends DefaultNettyPlcConnection implements Runnable { - private static final Logger logger = LoggerFactory.getLogger(S7HDefaultNettyPlcConnection.class); + private static final Logger logger = LoggerFactory.getLogger(S7HPlcConnection.class); private static final String MULTIPLEXOR = "MULTIPLEXOR"; private Boolean closed = false; private ScheduledFuture scf = null; - + private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(new BasicThreadFactory.Builder() + .namingPattern("plc4x-s7ha-thread-%d") + .daemon(true) + .priority(Thread.MAX_PRIORITY) + .build()); + protected final ChannelFactory secondaryChannelFactory; protected Channel primary_channel = null; protected Channel secondary_channel = null; @@ -66,7 +89,7 @@ public class S7HDefaultNettyPlcConnection extends DefaultNettyPlcConnection impl protected int slice_ping = 0; protected int slice_retry_time = 0; - public S7HDefaultNettyPlcConnection(boolean canRead, + public S7HPlcConnection(boolean canRead, boolean canWrite, boolean canSubscribe, boolean canBrowse, @@ -142,11 +165,11 @@ public void connect() throws PlcConnectionException { sendChannelDisconectEvent(); throw new PlcConnectionException("Connection is not possible."); } - - scf = channel.eventLoop().scheduleWithFixedDelay(this, 1, 1, TimeUnit.SECONDS); + + scf = executor.scheduleAtFixedRate(this, 1, 1, TimeUnit.SECONDS); /* - primary_channel.closeFuture().addListener(future -> { + primary_channel.closeFuture().addListener(future -> {/watch?v=TmENMZFUU_0&list=RDlBlx1JffMQ4&index=27 if (!sessionDiscoveredCompleteFuture.isDone()) { //Do Nothing try { @@ -159,7 +182,6 @@ public void connect() throws PlcConnectionException { }); */ - // Send an event to the pipeline telling the Protocol filters what's going on. sendChannelCreatedEvent(); @@ -170,6 +192,7 @@ public void connect() throws PlcConnectionException { //channel.pipeline().write(new ConnectedEvent()); // Set the connection to "connected" connected = true; + //((EmbeddedChannel) channel).runPendingTasks(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PlcConnectionException(e); @@ -208,31 +231,40 @@ public void close() throws PlcConnectionException { channel.pipeline().fireUserEventTriggered(new DisconnectEvent()); closed = true; } - + + @Override + public boolean isConnected() { + return channel.attr(S7HMuxImpl.IS_CONNECTED).get(); + } + public void doPrimaryTcpConnections(){ try { - primary_channel = channelFactory.createChannel(new LoggingHandler(LogLevel.TRACE) ); + primary_channel = channelFactory.createChannel(new LoggingHandler(LogLevel.TRACE) ); } catch (Exception ex){ + primary_channel = null; logger.info(ex.toString()); } - if (primary_channel!=null) - if (primary_channel.isActive()) + if (primary_channel != null) + if (primary_channel.isActive()) { primary_channel.pipeline().addFirst(MULTIPLEXOR,s7hmux); - ((S7HMux) s7hmux).setPrimaryChannel(primary_channel); + ((S7HMux) s7hmux).setPrimaryChannel(primary_channel); + } } public void doSecondaryTcpConnections(){ try { secondary_channel = secondaryChannelFactory.createChannel(new LoggingHandler(LogLevel.TRACE) ); } catch (Exception ex){ + secondary_channel = null; logger.info(ex.toString()); } - if (secondary_channel!=null) - if (secondary_channel.isActive()) + if (secondary_channel != null) + if (secondary_channel.isActive()) { secondary_channel.pipeline().addFirst(MULTIPLEXOR,s7hmux); - ((S7HMux) s7hmux).setSecondaryChannel(secondary_channel); + ((S7HMux) s7hmux).setSecondaryChannel(secondary_channel); + } } /* @@ -251,51 +283,107 @@ protected void sendChannelDisconectEvent() { * To avoid creating new tasks associated with the supervision of the * driver, I execute these tasks in a few slices of time. This allows me * to keep a simple control of the state machines. + * Verifies disconnection of the channel, which notifies the client + * that they are listening. */ @Override - public void run() { + public void run() { + + /* + * Here a driver reconnection is detected. If so, a connection event + * is generated, so the user application can generate its requests again. + */ + if ((channel.attr(S7HMuxImpl.WAS_CONNECTED).get()) && + (channel.attr(S7HMuxImpl.IS_CONNECTED).get())) { + (channel.attr(S7HMuxImpl.WAS_CONNECTED)).set(false); + channel.pipeline().fireUserEventTriggered(new ConnectedEvent()); + } + + /* + * Execute the ping towards the PLC. Its purpose is to keep + * the TCP channel active, for very long sampling periods. + */ + if ((channel.attr(S7HMuxImpl.IS_PING_ACTIVE).get())) { + if (slice_ping >= channel.attr(S7HMuxImpl.PING_TIME).get()) { + ping(); + slice_ping = 0; + }; + slice_ping++; + } else slice_ping = 0; + + /* + * Here it is verified if the channels are active. If they are not, + * the connection is created again. + * For H type systems, at least one of the connections must be active, + * and if the other is down, the connection must be lifted. + * S7HMuxImpl, includes the switching logic between the TCP links. + */ if (slice_retry_time >= channel.attr(S7HMuxImpl.RETRY_TIME).get()) { + if (primary_channel != null){ if (!primary_channel.isActive()){ - logger.info("Creating prymary conection."); + logger.info("Creating prymary connection."); primary_channel.eventLoop().shutdownGracefully(); doPrimaryTcpConnections(); - } + } else if (null == secondary_channel) + if ((channel.attr(S7HMuxImpl.WAS_CONNECTED).get()) && + (!channel.attr(S7HMuxImpl.IS_CONNECTED).get())) { + logger.info("Reconnecting primary channel."); + if (null != ((S7HMux) s7hmux).getTCPChannel()) { + ((S7HMux) s7hmux).setPrimaryChannel(primary_channel); + } + } } else { - logger.info("Creating firts prymary conection."); + logger.info("Creating firts prymary connection."); doPrimaryTcpConnections(); } if (secondary_channel != null){ if (!secondary_channel.isActive()){ - logger.info("Creating secondary conection."); + logger.info("Creating secondary connection."); secondary_channel.eventLoop().shutdownGracefully(); doSecondaryTcpConnections(); - } + } else if (null == primary_channel) + if ((channel.attr(S7HMuxImpl.WAS_CONNECTED).get()) && + (!channel.attr(S7HMuxImpl.IS_CONNECTED).get())) { + logger.info("Reconnecting secondary channel."); + if (null != ((S7HMux) s7hmux).getTCPChannel()) { + ((S7HMux) s7hmux).setSecondaryChannel(secondary_channel); + } + } } else { if (secondaryChannelFactory != null ) { - logger.info("Creating firts secondary conection."); + logger.info("Creating firts secondary connection."); doSecondaryTcpConnections(); } } slice_retry_time = 0; }; - - if ((channel.attr(S7HMuxImpl.IS_PING_ACTIVE).get())) { - if (slice_ping >= channel.attr(S7HMuxImpl.PING_TIME).get()) { - ping(); - slice_ping = 0; - }; - } else slice_ping = 0; - - slice_retry_time++; - slice_ping++; + + if (channel.attr(S7HMuxImpl.RETRY_TIME).get() > 0) + slice_retry_time++; + + connected = channel.attr(S7HMuxImpl.IS_CONNECTED).get(); + logger.trace("*************************************************\r\n" + +"INSTAMCIA PRIMARIO : " + ((null == primary_channel)?"NULL":primary_channel.toString()) + "\r\n" + +"ACTIVO PRIMARIO : " + ((null == primary_channel)?"NULL":primary_channel.isActive()) + "\r\n" + +"INSTAMCIA SECUNDARIO : " + ((null == secondary_channel)?"NULL":secondary_channel.toString()) + "\r\n" + +"ACTIVO SECUNDARIO : " + ((null == secondary_channel)?"NULL":secondary_channel.isActive()) + "\r\n" + +"CANAL CONECTADO? : " + channel.attr(S7HMuxImpl.IS_CONNECTED).get() + "\r\n" + +"CANAL ESTUVO CONECTADO? : " + channel.attr(S7HMuxImpl.WAS_CONNECTED).get() + "\r\n" + +"CONTADORES : " + slice_ping + " : " + slice_retry_time + "\r\n" + +"*************************************************"); } - + + /* + * PING to PLC. + */ @Override public CompletableFuture ping() { if (channel.attr(S7HMuxImpl.IS_CONNECTED).get()) { - channel.eventLoop().execute(()->{ + + //channel.eventLoop().execute(()->{ + executor.execute(()->{ PlcReadRequest.Builder builder = readRequestBuilder(); builder.addTagAddress("value", "%MX1.0:BOOL"); @@ -303,7 +391,7 @@ public CompletableFuture ping() { try { PlcReadResponse readResponse = readRequest.execute().get(2, TimeUnit.SECONDS); - logger.info("PING: " + readResponse.getResponseCode("value")); + logger.debug("PING: " + readResponse.getResponseCode("value")); } catch (Exception ex){ logger.info("PING: " + ex.toString()); } diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolEventLogic.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolEventLogic.java index 56835b7e17c..f875d0cf8cf 100644 --- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolEventLogic.java +++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolEventLogic.java @@ -28,6 +28,7 @@ import java.util.function.Consumer; import java.util.logging.Level; import java.util.logging.Logger; +import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.apache.plc4x.java.api.messages.PlcSubscriptionEvent; import org.apache.plc4x.java.api.messages.PlcSubscriptionRequest; import org.apache.plc4x.java.api.messages.PlcSubscriptionResponse; @@ -57,8 +58,8 @@ public class S7ProtocolEventLogic implements PlcSubscriber { private Map> mapIndex = new HashMap(); private Map eventtypehandles = new HashMap(); ; - private final Runnable runnProcessor; - private final Runnable runnDispacher; + private final Runnable runProcessor; + private final Runnable runDispacher; private Thread processor; @@ -66,10 +67,21 @@ public class S7ProtocolEventLogic implements PlcSubscriber { public S7ProtocolEventLogic(BlockingQueue eventqueue) { this.eventqueue = eventqueue; - runnProcessor = new ObjectProcessor(eventqueue,dispachqueue); - runnDispacher = new EventDispacher(dispachqueue); - processor = new Thread(runnProcessor); - dispacher = new Thread(runnDispacher); + runProcessor = new ObjectProcessor(eventqueue,dispachqueue); + runDispacher = new EventDispacher(dispachqueue); +// processor = new Thread(runnProcessor); +// dispacher = new Thread(runnDispacher); + processor = new BasicThreadFactory.Builder() + .namingPattern("plc4x-evt-processor-thread-%d") + .daemon(true) + .priority(Thread.MAX_PRIORITY) + .build().newThread(runProcessor); + + dispacher = new BasicThreadFactory.Builder() + .namingPattern("plc4x-evt-dispacher-thread-%d") + .daemon(true) + .priority(Thread.MAX_PRIORITY) + .build().newThread(runDispacher); } public void start() { @@ -78,8 +90,8 @@ public void start() { } public void stop(){ - ((ObjectProcessor) runnProcessor).doShutdown(); - ((EventDispacher) runnDispacher).doShutdown(); + ((ObjectProcessor) runProcessor).doShutdown(); + ((EventDispacher) runDispacher).doShutdown(); } @Override @@ -158,7 +170,7 @@ public void run() { Logger.getLogger(S7ProtocolEventLogic.class.getName()).log(Level.SEVERE, null, ex); } } - System.out.println("ObjectProcessor Bye!"); + logger.info("ObjectProcessor Bye!"); } public void doShutdown(){ @@ -209,12 +221,19 @@ public void run() { } }else if (obj instanceof S7CyclicEvent) { if (mapIndex.containsKey(EventType.CYC)) { + Map mapConsumers = mapIndex.get(EventType.CYC); if (cycDelayedObject != null) { mapConsumers.forEach((x,y) -> y.accept(cycDelayedObject)); cycDelayedObject = null; } - mapConsumers.forEach((x,y) -> y.accept(obj)); + mapConsumers.forEach((x,y) -> { + S7PlcSubscriptionHandle sh = (S7PlcSubscriptionHandle) x.getSubscriptionHandles().get(0); + Short id = Short.parseShort(sh.getEventId()); + if (((S7CyclicEvent) obj).getMap().get("JOBID") == id) + y.accept(obj); + }); + } else { cycDelayedObject = obj; } @@ -224,7 +243,7 @@ public void run() { Logger.getLogger(S7ProtocolEventLogic.class.getName()).log(Level.SEVERE, null, ex); } } - System.out.println("EventDispacher Bye!"); + logger.info("EventDispacher Bye!"); } public void doShutdown(){ diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java index 343754c0cb6..a27c3ce8dcc 100644 --- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java +++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java @@ -23,6 +23,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; +import io.netty.channel.embedded.EmbeddedChannel; import org.apache.plc4x.java.api.exceptions.PlcProtocolException; import org.apache.plc4x.java.api.exceptions.PlcRuntimeException; import org.apache.plc4x.java.api.messages.PlcReadRequest; @@ -97,7 +98,7 @@ */ public class S7ProtocolLogic extends Plc4xProtocolBase { - private final Logger logger = LoggerFactory.getLogger(S7ProtocolLogic.class); + private static final Logger logger = LoggerFactory.getLogger(S7ProtocolLogic.class); public static final Duration REQUEST_TIMEOUT = Duration.ofMillis(10000); private final AtomicInteger tpduGenerator = new AtomicInteger(10); @@ -125,7 +126,7 @@ public class S7ProtocolLogic extends Plc4xProtocolBase { private final S7PlcSubscriptionHandle sysHandle = new S7PlcSubscriptionHandle(EventType.SYS, EventLogic); private final S7PlcSubscriptionHandle usrHandle = new S7PlcSubscriptionHandle(EventType.USR, EventLogic); private final S7PlcSubscriptionHandle almHandle = new S7PlcSubscriptionHandle(EventType.ALM, EventLogic); - private final S7PlcSubscriptionHandle cycHandle = new S7PlcSubscriptionHandle(EventType.CYC,EventLogic); + //private final S7PlcSubscriptionHandle cycHandle = new S7PlcSubscriptionHandle(EventType.CYC, EventLogic); /* * For the reconnection functionality by a "TimeOut" of the connection, @@ -136,6 +137,15 @@ public class S7ProtocolLogic extends Plc4xProtocolBase { * his request. */ private HashMap> active_requests = new HashMap<>(); + + /* + * This array stores the cyclic subscription requests between the driver + * and the PLC. The purpose is to document the tags associated with the + * request. Each subscription uses a 'JobID' that is managed by the PLC and + * obtained from the response to the request. In the following, + * the values sent PUSH from the PLC to the driver refer to this JobID. + */ + private final Map cycrequests = new HashMap<>(); private S7DriverContext s7DriverContext; @@ -165,9 +175,13 @@ public void onConnect(ConversationContext context) { return; } + // If the call is for a reconnection, we must clean up + // the queued messages so that they release the transaction handler. + cleanFutures(); + //Set feature for all handlers in the pipeline from //the driver configuration. - setChannelFeatures(); + setChannelFeatures(); // Only the TCP transport supports login. logger.info("S7 Driver running in ACTIVE mode."); @@ -217,7 +231,7 @@ public void onConnect(ConversationContext context) { // in order to detect the type of PLC. if (s7DriverContext.getControllerType() != S7ControllerType.ANY) { // Send an event that connection setup is complete. - context.fireConnected(); + context.fireConnected(); return; } @@ -373,11 +387,13 @@ private CompletableFuture readInternal(S7Message request) { S7Message message = (request instanceof S7MessageUserData) ? new S7MessageUserData(tpduId, request.getParameter(), request.getPayload()) : new S7MessageRequest(tpduId, request.getParameter(), request.getPayload()); - + TPKTPacket tpktPacket = new TPKTPacket(new COTPPacketData(null, message, true, (short) tpduId)); - + // Start a new request-transaction (Is ended in the response-handler) + RequestTransactionManager.RequestTransaction transaction = tm.startRequest(); + transaction.submit(() -> context.sendRequest(tpktPacket) .onTimeout(new TransactionErrorCallback<>(future, transaction)) .onError(new TransactionErrorCallback<>(future, transaction)) @@ -391,7 +407,7 @@ private CompletableFuture readInternal(S7Message request) { active_requests.remove(future); future.complete(p); // Finish the request-transaction. - transaction.endRequest(); + transaction.endRequest(); })); active_requests.put(future, new MutablePair<>(transaction, null)); @@ -489,6 +505,8 @@ public CompletableFuture subscribe(PlcSubscriptionReque CompletableFuture response = new CompletableFuture<>(); subscriptionRequest.getTagNames().forEach(fieldname -> futures.put(fieldname, new CompletableFuture<>())); + // + futures.put("DATA_", new CompletableFuture<>()); DefaultPlcSubscriptionRequest request = (DefaultPlcSubscriptionRequest) subscriptionRequest; @@ -502,8 +520,10 @@ public CompletableFuture subscribe(PlcSubscriptionReque Thread t1 = new Thread(()->{ - for (String tagName : request.getTagNames()) { - final DefaultPlcSubscriptionTag sf = (DefaultPlcSubscriptionTag) request.getTag(tagName); + //for (String tagName : request.getTagNames()) { + //System.out.println("Aqui repite: " + tagName); + //final DefaultPlcSubscriptionTag sf = (DefaultPlcSubscriptionTag) request.getTag(tagName); + final DefaultPlcSubscriptionTag sf = (DefaultPlcSubscriptionTag) request.getTags().get(0); final S7SubscriptionTag tag = (S7SubscriptionTag) sf.getTag(); switch (tag.getTagType()) { @@ -520,69 +540,76 @@ public CompletableFuture subscribe(PlcSubscriptionReque encodeAlarmQueryRequest(request, parameterItems, payloadItems); break; case CYCLIC_SUBSCRIPTION: - encodeCycledS7ANYSubscriptionRequest(request.getTag(tagName), parameterItems, payloadItems); + encodeCycledS7ANYSubscriptionRequest(request, parameterItems, payloadItems); break; case CYCLIC_DB_SUBSCRIPTION: - encodeCycledDBREADSubscriptionRequest(request.getTag(tagName), parameterItems, payloadItems); + encodeCycledDBREADSubscriptionRequest(request, parameterItems, payloadItems); break; case CYCLIC_UNSUBSCRIPTION: - //encodeCycledUnSubscriptionRequest(request, parameterItems, payloadItems); + encodeCycledUnSubscriptionRequest(request, parameterItems, payloadItems); break; default: - } - //final PlcValue plcValue = request.getPlcValue(tagName); - //parameterItems.add(new S7VarRequestParameterItemAddress(encodeS7Address(tag))); - //payloadItems.add(serializePlcValue(tag, plcValue)); - final int tpduId = tpduGenerator.getAndIncrement(); - // If we've reached the max value for a 16 bit transaction identifier, reset back to 1 - if (tpduGenerator.get() == 0xFFFF) { - tpduGenerator.set(1); - } + } + //} //Next + + //final PlcValue plcValue = request.getPlcValue(tagName); + //parameterItems.add(new S7VarRequestParameterItemAddress(encodeS7Address(tag))); + //payloadItems.add(serializePlcValue(tag, plcValue)); + final int tpduId = tpduGenerator.getAndIncrement(); + // If we've reached the max value for a 16 bit transaction identifier, reset back to 1 + if (tpduGenerator.get() == 0xFFFF) { + tpduGenerator.set(1); + } - TPKTPacket tpktPacket = new TPKTPacket(new COTPPacketData(null, - new S7MessageUserData(tpduId, - new S7ParameterUserData(parameterItems), - new S7PayloadUserData(payloadItems)), - true, (short) tpduId)); - - // Start a new request-transaction (Is ended in the response-handler) - RequestTransactionManager.RequestTransaction transaction = tm.startRequest(); - transaction.submit(() -> context.sendRequest(tpktPacket) - .onTimeout(new TransactionErrorCallback<>(future, transaction)) - .onError(new TransactionErrorCallback<>(future, transaction)) - .expectResponse(TPKTPacket.class, REQUEST_TIMEOUT) - .check(p -> p.getPayload() instanceof COTPPacketData) - .unwrap(p -> ((COTPPacketData) p.getPayload())) - .unwrap(COTPPacket::getPayload) - .check(p -> p.getTpduReference() == tpduId) - .handle(p -> { - try { - //future.complete(decodeEventSubscriptionRequest(tagName, p, subscriptionRequest)); - futures.get(tagName).complete(p); - } catch (Exception e) { - logger.warn("Error sending 'write' message: '{}'", e.getMessage(), e); - } - // Finish the request-transaction. - transaction.endRequest(); - })); + TPKTPacket tpktPacket = new TPKTPacket(new COTPPacketData(null, + new S7MessageUserData(tpduId, + new S7ParameterUserData(parameterItems), + new S7PayloadUserData(payloadItems)), + true, (short) tpduId)); + + // Start a new request-transaction (Is ended in the response-handler) + RequestTransactionManager.RequestTransaction transaction = tm.startRequest(); + transaction.submit(() -> context.sendRequest(tpktPacket) + .onTimeout(new TransactionErrorCallback<>(future, transaction)) + .onError(new TransactionErrorCallback<>(future, transaction)) + .expectResponse(TPKTPacket.class, REQUEST_TIMEOUT) + .check(p -> p.getPayload() instanceof COTPPacketData) + .unwrap(p -> ((COTPPacketData) p.getPayload())) + .unwrap(COTPPacket::getPayload) + .check(p -> p.getTpduReference() == tpduId) + .handle(p -> { + try { + //future.complete(decodeEventSubscriptionRequest(tagName, p, subscriptionRequest)); + futures.get("DATA_").complete(p); + } catch (Exception e) { + logger.warn("Error sending 'write' message: '{}'", e.getMessage(), e); + } + // Finish the request-transaction. + transaction.endRequest(); + })); + + try { + S7Message responseMessage = futures.get("DATA_").get(); + S7ParameterUserData parameter = (S7ParameterUserData) responseMessage.getParameter(); + S7ParameterUserDataItemCPUFunctions msgparameter = (S7ParameterUserDataItemCPUFunctions) parameter.getItems().get(0); - try { - valuesResponse.put(tagName, decodeEventSubscriptionRequest(tagName, subscriptionRequest, futures.get(tagName).get())); - } catch (Exception ex) { - logger.warn(ex.toString()); - } + valuesResponse.put(Integer.toString(msgparameter.getSequenceNumber()), + decodeEventSubscriptionRequest(Integer.toString(msgparameter.getSequenceNumber()), subscriptionRequest, futures.get("DATA_").get())); - } //Next + } catch (Exception ex) { + logger.warn(ex.toString()); + } + try { - maintask.get(); + ///maintask.get(); HashMap> values = new HashMap<>(); - + valuesResponse.forEach((s,p)->{ if (p != null) values.putAll(((DefaultPlcSubscriptionResponse)p).getValues()); }); - + response.complete(new DefaultPlcSubscriptionResponse(subscriptionRequest, values)); } catch (Exception ex) { @@ -644,7 +671,7 @@ private void encodeEventSubscriptionRequest(DefaultPlcSubscriptionRequest reques S7PayloadUserDataItemCpuFunctionMsgSubscriptionRequest payload; - //System.out.println("Subsevent: " + subsevent + " : " + String.format("0x%04X", subsevent)); + if (subsevent > 0) { payload = new S7PayloadUserDataItemCpuFunctionMsgSubscriptionRequest( DataTransportErrorCode.OK, @@ -876,11 +903,15 @@ private PlcSubscriptionResponse decodeEventSubscriptionRequest(String strTagName S7ParameterUserDataItemCPUFunctions msgparameter = (S7ParameterUserDataItemCPUFunctions) parameter.getItems().get(0); + cycrequests.put(msgparameter.getSequenceNumber(), plcSubscriptionRequest); + S7CyclicEvent cycevent = new S7CyclicEvent(plcSubscriptionRequest, msgparameter.getSequenceNumber(), (S7PayloadUserDataItemCyclicServicesSubscribeResponse) payloadItems.get(0)); - eventQueue.add(cycevent); + eventQueue.add(cycevent); + + S7PlcSubscriptionHandle cycHandle = new S7PlcSubscriptionHandle(strTagName, EventType.CYC, EventLogic); values.put(strTagName, new ResponseItem(PlcResponseCode.OK, cycHandle)); return new DefaultPlcSubscriptionResponse(plcSubscriptionRequest,values); @@ -889,11 +920,15 @@ private PlcSubscriptionResponse decodeEventSubscriptionRequest(String strTagName S7ParameterUserDataItemCPUFunctions msgparameter = (S7ParameterUserDataItemCPUFunctions) parameter.getItems().get(0); + cycrequests.put(msgparameter.getSequenceNumber(), plcSubscriptionRequest); + S7CyclicEvent cycevent = new S7CyclicEvent(plcSubscriptionRequest, msgparameter.getSequenceNumber(), (S7PayloadUserDataItemCyclicServicesChangeDrivenSubscribeResponse) payloadItems.get(0)); - eventQueue.add(cycevent); + eventQueue.add(cycevent); + + S7PlcSubscriptionHandle cycHandle = new S7PlcSubscriptionHandle(strTagName, EventType.CYC, EventLogic); values.put(strTagName, new ResponseItem(PlcResponseCode.OK, cycHandle)); return new DefaultPlcSubscriptionResponse(plcSubscriptionRequest,values); @@ -1041,7 +1076,7 @@ private void encodeCycledSubscriptionRequest(DefaultPlcSubscriptionRequest reque } - private void encodeCycledS7ANYSubscriptionRequest(PlcSubscriptionTag plctag, + private void encodeCycledS7ANYSubscriptionRequest(DefaultPlcSubscriptionRequest request, List parameterItems, List payloadItems){ S7ParameterUserDataItemCPUFunctions parameter = new S7ParameterUserDataItemCPUFunctions( @@ -1059,25 +1094,46 @@ private void encodeCycledS7ANYSubscriptionRequest(PlcSubscriptionTag plctag, parameterItems.add(parameter); //TODO: Chequear la asignacionde tipo - - PlcTag tag = ((DefaultPlcSubscriptionTag) plctag).getTag(); - S7SubscriptionTag s7tag = (S7SubscriptionTag) tag; + + //PlcTag tag = ((DefaultPlcSubscriptionTag) plctag).getTag(); + //S7SubscriptionTag s7tag = (S7SubscriptionTag) tag; // - List items = new ArrayList(); + List items = new ArrayList(); + + request.getTags().forEach(tag -> { + +// PlcTag plctag = ((DefaultPlcSubscriptionTag) tag).getTag(); + S7SubscriptionTag s7tag = (S7SubscriptionTag ) ((DefaultPlcSubscriptionTag) ((PlcSubscriptionTag) tag)).getTag(); +// + for (S7Tag userfield:s7tag.getS7Tags()) { + items.add(new CycServiceItemAnyType( + (short) 0x0a, + (short) 0x10, //S7ANY + userfield.getDataType(), + userfield.getNumberOfElements(), + userfield.getBlockNumber(), + userfield.getMemoryArea(), + (long) (((userfield.getByteOffset() << 3) | (userfield.getBitOffset() & 0x0007))) + )); + } + }); + + S7SubscriptionTag s7tag_base = (S7SubscriptionTag) ((DefaultPlcSubscriptionTag) ((PlcSubscriptionTag) request.getTags().get(0))).getTag(); + // - int i=0; - for (S7Tag userfield:s7tag.getS7Tags()) { - items.add(new CycServiceItemAnyType( - (short) 0x0a, - (short) 0x10, //S7ANY - userfield.getDataType(), - userfield.getNumberOfElements(), - userfield.getBlockNumber(), - userfield.getMemoryArea(), - (long) (((userfield.getByteOffset() << 3) | (userfield.getBitOffset() & 0x0007))) - )); - i++; - } +// int i=0; +// for (S7Tag userfield:s7tag.getS7Tags()) { +// items.add(new CycServiceItemAnyType( +// (short) 0x0a, +// (short) 0x10, //S7ANY +// userfield.getDataType(), +// userfield.getNumberOfElements(), +// userfield.getBlockNumber(), +// userfield.getMemoryArea(), +// (long) (((userfield.getByteOffset() << 3) | (userfield.getBitOffset() & 0x0007))) +// )); +// i++; +// } // // //Length in bytes // //4+12*items.legth @@ -1089,17 +1145,17 @@ private void encodeCycledS7ANYSubscriptionRequest(PlcSubscriptionTag plctag, DataTransportSize.OCTET_STRING, lengthInBytes, items.size(), - s7tag.getTimeBase(), - s7tag.getMultiplier(), + s7tag_base.getTimeBase(), + s7tag_base.getMultiplier(), items ); - + payloadItems.clear(); payloadItems.add(payload); } - private void encodeCycledDBREADSubscriptionRequest(PlcSubscriptionTag plctag, + private void encodeCycledDBREADSubscriptionRequest(DefaultPlcSubscriptionRequest request, List parameterItems, List payloadItems){ S7ParameterUserDataItemCPUFunctions parameter = new S7ParameterUserDataItemCPUFunctions( @@ -1118,6 +1174,8 @@ private void encodeCycledDBREADSubscriptionRequest(PlcSubscriptionTag plctag, //TODO: Chequear la asignacionde tipo + PlcSubscriptionTag plctag = request.getTags().get(0); + PlcTag tag = ((DefaultPlcSubscriptionTag) plctag).getTag(); S7SubscriptionTag s7tag = (S7SubscriptionTag) tag; @@ -1186,25 +1244,25 @@ private void encodeCycledUnSubscriptionRequest(DefaultPlcSubscriptionRequest req parameterItems.clear(); parameterItems.add(parameter); - PlcSubscriptionTag tag = request.getTags().get(0); - S7SubscriptionTag s7tag = (S7SubscriptionTag) tag; + DefaultPlcSubscriptionTag tag = (DefaultPlcSubscriptionTag) request.getTags().get(0); + S7SubscriptionTag s7tag = (S7SubscriptionTag) tag.getTag(); //PlcField field = ((DefaultPlcSubscriptionField) plcfield).getPlcField(); //S7SubscriptionField s7field = (S7SubscriptionField) field; + payloadItems.clear(); //TODO:Check CPU type - S7PayloadUserDataItemCyclicServicesUnsubscribeRequest payload = - new S7PayloadUserDataItemCyclicServicesUnsubscribeRequest ( - DataTransportErrorCode.OK, - DataTransportSize.OCTET_STRING, - 0x02, - (short) 0x05, - s7tag.getAckAlarms().get(0).byteValue() - ); - - payloadItems.clear(); - payloadItems.add(payload); - + s7tag.getAckAlarms().forEach(jobid -> { + S7PayloadUserDataItemCyclicServicesUnsubscribeRequest payload = + new S7PayloadUserDataItemCyclicServicesUnsubscribeRequest ( + DataTransportErrorCode.OK, + DataTransportSize.OCTET_STRING, + 0x02, + (short) 0x05, + jobid.byteValue()); + + payloadItems.add(payload); + }); } /** @@ -1252,12 +1310,12 @@ protected void decode(ConversationContext context, TPKTPacket msg) t ((S7ParameterUserData) parameter).getItems().get(0); S7PayloadUserData payload = (S7PayloadUserData) s7msg.getPayload(); - + S7PayloadUserDataItemCyclicServicesPush payloaditem = (S7PayloadUserDataItemCyclicServicesPush) payload.getItems().get(0); - S7CyclicEvent cycevent = new S7CyclicEvent(null, + S7CyclicEvent cycevent = new S7CyclicEvent(cycrequests.get(parameteritem.getSequenceNumber()), parameteritem.getSequenceNumber(), payloaditem); eventQueue.add(cycevent); @@ -1740,7 +1798,12 @@ protected S7Address encodeS7Address(PlcTag tag) { s7Tag.getMemoryArea(), s7Tag.getByteOffset(), s7Tag.getBitOffset()); } - + /* + * In the case of a reconnection, there may be requests waiting, + * for which the operation must be terminated by exception and canceled + * in the transaction manager. If this does not happen, + * the driver operation can be frozen. + */ private void cleanFutures(){ //TODO: Debe ser ejecutado si la conexion esta levanta. active_requests.forEach((f,p)->{ @@ -1758,8 +1821,7 @@ private void cleanFutures(){ logger.info(ex.toString()); } }); - active_requests.clear(); - + active_requests.clear(); } private boolean isConnected(){ @@ -1777,7 +1839,7 @@ private void setChannelFeatures(){ context.getChannel().attr(S7HMuxImpl.READ_TIME_OUT).set(s7DriverContext.getReadTimeout()); context.getChannel().attr(S7HMuxImpl.IS_PING_ACTIVE).set(s7DriverContext.getPing()); context.getChannel().attr(S7HMuxImpl.PING_TIME).set(s7DriverContext.getPingTime()); - context.getChannel().attr(S7HMuxImpl.RETRY_TIME).set(s7DriverContext.getRetryTime()); + context.getChannel().attr(S7HMuxImpl.RETRY_TIME).set(s7DriverContext.getRetryTime()); } @@ -1896,13 +1958,21 @@ static class TransactionErrorCallback implements Consume @Override public void accept(TimeoutException e) { - transaction.endRequest(); + try { + transaction.endRequest(); + } catch (Exception ex) { + logger.info(ex.getMessage()); + } future.completeExceptionally(e); } @Override public void accept(TPKTPacket tpktPacket, E e) { - transaction.endRequest(); + try { + transaction.endRequest(); + } catch (Exception ex) { + logger.info(ex.getMessage()); + } future.completeExceptionally(e); } } diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/utils/S7PlcSubscriptionHandle.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/utils/S7PlcSubscriptionHandle.java index dc5d7aac94c..d1fab5d82db 100644 --- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/utils/S7PlcSubscriptionHandle.java +++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/utils/S7PlcSubscriptionHandle.java @@ -25,14 +25,26 @@ public class S7PlcSubscriptionHandle extends DefaultPlcSubscriptionHandle { private EventType eventtype; + private final String id; public S7PlcSubscriptionHandle(EventType eventtype, PlcSubscriber plcSubscriber) { super(plcSubscriber); this.eventtype = eventtype; + this.id = null; } + public S7PlcSubscriptionHandle(String id, EventType eventtype, PlcSubscriber plcSubscriber) { + super(plcSubscriber); + this.eventtype = eventtype; + this.id = id; + } + public EventType getEventType() { return eventtype; } + public String getEventId() { + return id; + } + } diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/utils/StaticHelper.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/utils/StaticHelper.java index 10917dd3831..aa294fde283 100644 --- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/utils/StaticHelper.java +++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/utils/StaticHelper.java @@ -2138,7 +2138,8 @@ public static int RightShift3(final ReadBuffer buffer) throws ParseException { public static int RightShift3(final ReadBuffer buffer, DataTransportSize tsize) throws ParseException { int value = 0; - if (tsize == DataTransportSize.OCTET_STRING){ + if ((tsize == DataTransportSize.OCTET_STRING) || + (tsize == DataTransportSize.REAL)) { value = buffer.readUnsignedInt(16); } else { value = buffer.readUnsignedInt(16) >> 3; diff --git a/plc4j/examples/plc4j-s7event/src/main/java/org/apache/plc4x/examples/plc4j/s7event/CycSubscription.java b/plc4j/examples/plc4j-s7event/src/main/java/org/apache/plc4x/examples/plc4j/s7event/CycSubscription.java index efd9b521455..58333b64720 100644 --- a/plc4j/examples/plc4j-s7event/src/main/java/org/apache/plc4x/examples/plc4j/s7event/CycSubscription.java +++ b/plc4j/examples/plc4j-s7event/src/main/java/org/apache/plc4x/examples/plc4j/s7event/CycSubscription.java @@ -19,109 +19,210 @@ package org.apache.plc4x.examples.plc4j.s7event; import java.util.Map; +import java.util.Scanner; +import java.util.concurrent.TimeUnit; import org.apache.plc4x.java.DefaultPlcDriverManager; -import org.apache.plc4x.java.api.PlcConnection; import org.apache.plc4x.java.api.messages.PlcSubscriptionRequest; import org.apache.plc4x.java.api.messages.PlcSubscriptionResponse; -import org.apache.plc4x.java.s7.events.S7AlarmEvent; import org.apache.plc4x.java.s7.events.S7CyclicEvent; -import org.apache.plc4x.java.s7.events.S7ModeEvent; -import org.apache.plc4x.java.s7.events.S7SysEvent; -import org.apache.plc4x.java.s7.events.S7UserEvent; -import org.apache.plc4x.java.s7.readwrite.protocol.S7ProtocolLogic; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.simple.SimpleLogger; import org.apache.commons.codec.binary.Hex; +import org.apache.plc4x.java.api.exceptions.PlcConnectionException; +import org.apache.plc4x.java.api.listener.ConnectionStateListener; +import org.apache.plc4x.java.api.model.PlcConsumerRegistration; +import org.apache.plc4x.java.s7.readwrite.protocol.S7HPlcConnection; /** * Example for capturing events generated from a Siemens S7-300, S7-400 or VIPA PLC. - * Support for mode events ("MODE"), system events ("SYS"), user events ("USR") - * and alarms ("ALM"). + * Support for cyclical (CYC) subscriptions. * Each consumer shows the tags and associated values of the "map" containing * the event parameters. */ -public class CycSubscription { +public class CycSubscription implements ConnectionStateListener { //01 - private static final Logger logger = LoggerFactory.getLogger(CycSubscription.class); + private static final Logger logger = LoggerFactory.getLogger(CycSubscription.class); + private S7HPlcConnection connection = null; + private PlcSubscriptionRequest.Builder subs_request_builder; + private PlcSubscriptionRequest subs_request; + + private PlcSubscriptionResponse subs_response; + + private PlcConsumerRegistration csmr; + + private String jobId; /** * @param args the command line arguments */ public static void main(String[] args) throws Exception { - System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "trace"); - - try (PlcConnection connection = new DefaultPlcDriverManager().getConnection("s7://10.10.1.33?remote-rack=0&remote-slot=3&controller-type=S7_400")) { - final PlcSubscriptionRequest.Builder subscription = connection.subscriptionRequestBuilder(); + System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "debug"); + + try { + CycSubscription cyc = new CycSubscription(); + + cyc.OpenConnection(); + cyc.RegisterPlcTags(); + cyc.GetConnections(); + cyc.RegisterCYCHandles(); + + System.out.println("Waiting for events..."); + Scanner scanner = new Scanner(System.in); + System.out.println(scanner.nextLine()); + + cyc.UnRegisterCYCHandles(); + cyc.CloseConnection(); - //subscription.addEventTagAddress("myCYC", "CYC(B01SEC:5):%DB9002.DBB0[1]"); - subscription.addEventTagAddress("myCYC", "CYC(B01SEC:5):%MB190:BYTE"); + scanner.close(); + + } catch (Exception ex) { - final PlcSubscriptionRequest sub = subscription.build(); - final PlcSubscriptionResponse subresponse = sub.execute().get(); + } + } - //Si todo va bien con la subscripciĂłn puedo -// subresponse -// .getSubscriptionHandle("myMODE") -// .register(msg -> { -// System.out.println("******** S7ModeEvent ********"); -// Map map = ((S7ModeEvent) msg).getMap(); -// map.forEach((x, y) -> { -// System.out.println(x + " : " + y); -// }); -// System.out.println("****************************"); -// }); -// -// subresponse -// .getSubscriptionHandle("mySYS") -// .register(msg -> { -// System.out.println("******** S7SysEvent ********"); -// Map map = ((S7SysEvent) msg).getMap(); -// map.forEach((x, y) -> { -// if ("INFO1".equals(x)) { -// System.out.println(x + " : " + String.format("0x%04X", y)); -// } else if ("INFO2".equals(x)) { -// System.out.println(x + " : " + String.format("0x%08X", y)); -// } else System.out.println(x + " : " + y); -// }); -// System.out.println("****************************"); -// }); -// -// subresponse -// .getSubscriptionHandle("myUSR") -// .register(msg -> { -// System.out.println("******** S7UserEvent *******"); -// Map map = ((S7UserEvent) msg).getMap(); -// map.forEach((x, y) -> { -// System.out.println(x + " : " + y); -// }); -// System.out.println("****************************"); -// }); + /* + * Open the connection to the controller. + * This connection specifies the monitoring parameters of the connection. + * read-timeout = 8 ; Maximum wait time to see input data over the + * ; TCP channel (sec.). + * ping = true ; Enable the PING function. (boolean) + * ping-time = 4 ; Run the PING every N seconds. + * retry-time = 5 ; Number of seconds to wait for connection monitoring. + * ; Default value zero (0) disables it. + */ + public void OpenConnection() { + try { + connection = (S7HPlcConnection) new DefaultPlcDriverManager(). + getConnection("s7://10.10.1.33/10.10.1.34?remote-rack=0&remote-slot=3&remote-rack2=0&remote-slot=4&controller-type=S7_400&read-timeout=8&ping=true&ping-time=4&retry-time=5"); + connection.addEventListener(this); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + /* + * + */ + public void RegisterPlcTags(){ + subs_request_builder = connection.subscriptionRequestBuilder(); + + subs_request_builder.addEventTagAddress("myCYC01", "CYC(B1SEC:2):%DB2.DBD2:REAL"); + subs_request_builder.addEventTagAddress("myCYC02", "CYC(B1SEC:2):%DB2.DBB3:BYTE"); + subs_request_builder.addEventTagAddress("myCYC03", "CYC(B1SEC:2):%MB190:BYTE"); - subresponse - .getSubscriptionHandle("myCYC") - .register(msg -> { - System.out.println("******** CYC Event *********"); - Map map = ((S7CyclicEvent) msg).getMap(); - map.forEach((x, y) -> { - if (x.startsWith("DATA_", 0)) { - System.out.println("Longitud de datos: " + ((byte[]) y).length); - System.out.println(x + ": " + Hex.encodeHexString((byte[]) y)); - } else - System.out.println(x + " : " + y); - }); + subs_request = subs_request_builder.build(); + } + + /* + * Create the subscription Tags, only the first Tag is taken into account + * to define the request time. + * Here the jobId is also captured, which is a value sent from the PLC. + * At the moment it is received instead of the Tagname assigned in + * the subscription. + */ + public void GetConnections(){ + try { + subs_response = subs_request.execute().get(); + jobId = (String) subs_response.getTagNames().toArray()[0]; + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + /* + * Closes the connection to the PLC. + */ + public void CloseConnection() { + try { + connection.close(); + } catch (PlcConnectionException ex) { + ex.printStackTrace(); + } + } + + /* + * Here I register my event consumer with the associated jobId. + */ + public void RegisterCYCHandles() { + System.out.println("JOBID: " + jobId); + csmr = subs_response + .getSubscriptionHandle(jobId) + .register( msg -> { + final S7CyclicEvent cycMsg = (S7CyclicEvent) msg; + System.out.println("******** *********"); + Map map = cycMsg.getMap(); + map.keySet().forEach(key -> {System.out.println("Field available: " + key);}); + byte[] data01 = (byte[]) map.get("myCYC01"); + byte[] data02 = (byte[]) map.get("myCYC02"); + System.out.println("myCYC01" + ": " + Hex.encodeHexString(data01)); + System.out.println("myCYC02" + ": " + Hex.encodeHexString(data02)); + System.out.println("myCYC01" + ": " + cycMsg.getFloat("myCYC01")); + System.out.println("myCYC02" + ": " + cycMsg.getByte("myCYC02")); + System.out.println("myCYC03" + ": " + cycMsg.getByte("myCYC03")); System.out.println("****************************"); }); - - System.out.println("Waiting for events"); + } + + /* + * Secure unregistration process for event consumption. + * 1. Unsubscribe from the event dispatcher. + * 2. Cancels the subscription to the PLC, with the associated jobId. + */ + public void UnRegisterCYCHandles() { + + csmr.unregister(); - Thread.sleep(10000); + PlcSubscriptionResponse subresponse03 = null; + + final PlcSubscriptionRequest.Builder subscription03 = connection.subscriptionRequestBuilder(); + subscription03.addEventTagAddress("CANCELTAG", "CANCEL:" + jobId); + + final PlcSubscriptionRequest sub03 = subscription03.build(); - System.out.println("Bye..."); + try { + subresponse03 = sub03.execute().get(500, TimeUnit.MILLISECONDS); + } catch (Exception ex) { + ex.printStackTrace(); + } + System.out.println("UnRegisterCYCHandles: " + subresponse03.getResponseCode(jobId)); + + } + + /* + * For the S7H driver, up to three connections are foreseen, + * two real TCP and one virtual or embedded. + * The connection of interest is the embedded one. + * It is the one that we must monitor until the internal + * machine changes its state to connected. + */ + @Override + public void connected() { + System.out.println("Some connection return!"); + if (connection.isConnected()) { + System.out.println("Reconnecting return!"); + System.out.println("PASO 1!"); + RegisterPlcTags(); + System.out.println("PASO 2!"); + GetConnections(); + System.out.println("PASO 3!"); + RegisterCYCHandles(); + System.out.println("Salio de aqui!!!!."); } } + /* + * For the disconnection event we must unregister the event consumer. + * For asynchronous events, subscriptions must be restarted. + */ + @Override + public void disconnected() { + System.out.println("Trouble, trouble, we're offline! Status: " + connection.isConnected()); + csmr.unregister(); + } + + } diff --git a/plc4j/examples/plc4j-s7event/src/main/java/org/apache/plc4x/examples/plc4j/s7event/EventSubscription.java b/plc4j/examples/plc4j-s7event/src/main/java/org/apache/plc4x/examples/plc4j/s7event/EventSubscription.java index fff303b6514..d21c38d83a1 100644 --- a/plc4j/examples/plc4j-s7event/src/main/java/org/apache/plc4x/examples/plc4j/s7event/EventSubscription.java +++ b/plc4j/examples/plc4j-s7event/src/main/java/org/apache/plc4x/examples/plc4j/s7event/EventSubscription.java @@ -112,7 +112,7 @@ public static void main(String[] args) throws Exception { System.out.println("Waiting for events"); - Thread.sleep(5000); + Thread.sleep(30000); System.out.println("Bye..."); diff --git a/plc4j/examples/plc4j-s7event/src/main/java/org/apache/plc4x/examples/plc4j/s7event/SzlRequest.java b/plc4j/examples/plc4j-s7event/src/main/java/org/apache/plc4x/examples/plc4j/s7event/SzlRequest.java index 9289d6c3d25..560b9dafcb2 100644 --- a/plc4j/examples/plc4j-s7event/src/main/java/org/apache/plc4x/examples/plc4j/s7event/SzlRequest.java +++ b/plc4j/examples/plc4j-s7event/src/main/java/org/apache/plc4x/examples/plc4j/s7event/SzlRequest.java @@ -61,7 +61,7 @@ public static void main(String[] args) throws Exception { System.out.println("Chapter 34 System Status Lists (SSL)."); System.out.println("URL: https://cache.industry.siemens.com/dl/files/604/44240604/att_67003/v1/s7sfc_en-EN.pdf"); System.out.println("******************************************************************************************"); - + Thread.sleep(10000); try (PlcConnection connection = new DefaultPlcDriverManager().getConnection("s7://10.10.1.33?remote-rack=0&remote-slot=3&controller-type=S7_400")) { //(01) final PlcReadRequest.Builder readrequest = connection.readRequestBuilder(); //(02) diff --git a/plc4j/integrations/apache-hop/plc4x-hop-actions/pom.xml b/plc4j/integrations/apache-hop/plc4x-hop-actions/pom.xml new file mode 100644 index 00000000000..ddc11edb5b6 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-actions/pom.xml @@ -0,0 +1,151 @@ + + + + 4.0.0 + + org.apache.plc4x + plc4j-apache-hop + 0.11.0-SNAPSHOT + + plc4x-hop-action + jar + PLC4J: Integrations: Apache Hop: Action + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + org.jboss.jandex + jandex-maven-plugin + 1.0.8 + + + make-index + + jandex + + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + org.apache.plc4x:plc4j-api:jar:${project.version} + org.apache.plc4x:plc4j-spi:jar:${project.version} + org.apache.plc4x:plc4j-driver-s7:jar:${project.version} + org.apache.plc4x:plc4j-transport-tcp:jar:${project.version} + + + + + + + + + org.apache.hop + hop-core + ${hop.version} + + + * + * + + + + + org.apache.hop + hop-ui + ${hop.version} + + + org.apache.hop + hop-engine + + + + + org.eclipse.platform + org.eclipse.swt.gtk.linux.x86_64 + ${org.eclipse.platform.version} + + + org.apache.plc4x + plc4j-driver-s7 + ${project.version} + + + org.apache.plc4x + plc4j-api + ${project.version} + + + org.apache.plc4x + plc4j-spi + ${project.version} + + + org.apache.plc4x + plc4j-transport-tcp + ${project.version} + + + ${project.groupId} + plc4x-hop-metadata + ${project.version} + + + org.apache.hop + hop-engine + ${hop.version} + + + * + * + + + + + + org.netbeans.api + org-openide-util-lookup + RELEASE170 + + + \ No newline at end of file diff --git a/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/java/org/apache/plc4x/hop/actions/ActionSampleMetaData.java b/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/java/org/apache/plc4x/hop/actions/ActionSampleMetaData.java new file mode 100644 index 00000000000..dca33626910 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/java/org/apache/plc4x/hop/actions/ActionSampleMetaData.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.plc4x.hop.actions; + +import org.apache.hop.metadata.api.HopMetadata; +import org.apache.hop.metadata.api.HopMetadataBase; +import org.apache.hop.metadata.api.IHopMetadata; + +/** + * + * @author cgarcia + */ +@HopMetadata( + key = "Xplc4xaction", + name = "PLC4x Action", + description = "A shared PLC4x connection to a PLC_Borrar", + image = "plc4x_toddy.svg", + documentationUrl = "/metadata-types/neo4j/neo4j-connection.html") +public class ActionSampleMetaData extends HopMetadataBase implements IHopMetadata { + +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/java/org/apache/plc4x/hop/actions/Plc4xCheckConnections.java b/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/java/org/apache/plc4x/hop/actions/Plc4xCheckConnections.java new file mode 100644 index 00000000000..53ffb309a41 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/java/org/apache/plc4x/hop/actions/Plc4xCheckConnections.java @@ -0,0 +1,347 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.plc4x.hop.actions; + +import org.apache.hop.core.ICheckResult; +import org.apache.hop.core.Result; +import org.apache.hop.core.annotations.Action; +import org.apache.hop.core.exception.HopXmlException; +import org.apache.hop.core.variables.IVariables; +import org.apache.hop.core.xml.XmlHandler; +import org.apache.hop.i18n.BaseMessages; +import org.apache.hop.metadata.api.IHopMetadataProvider; +import org.apache.hop.workflow.WorkflowMeta; +import org.apache.hop.workflow.action.ActionBase; +import org.apache.hop.workflow.action.IAction; + + +import java.util.List; +import org.apache.hop.core.Const; +import org.apache.hop.core.exception.HopException; +import org.apache.plc4x.hop.metadata.Plc4xConnection; +import org.apache.plc4x.hop.metadata.util.Plc4xLookup; +import org.apache.plc4x.hop.metadata.util.Plc4xWrapperConnection; +import org.apache.plc4x.java.DefaultPlcDriverManager; +import org.apache.plc4x.java.api.PlcConnection; +import org.openide.util.Lookup; +import org.w3c.dom.Node; + +/* +* The purpose of this "Action" is firstly to verify the connection to +* the PLC and secondly to create a connection that will be shared by +* the Hop environment. +*/ +@Action( + id = "CHECK_PLC4X_CONNECTIONS", + name = "i18n::Plc4xActionConnections.Name", + description = "i18n::Plc4xActionConnections.Description", + image = "plc4x_toddy_play.svg", + categoryDescription = "i18n:org.apache.hop.workflow:ActionCategory.Category.Conditions", + keywords = "i18n::Plc4xActionConnections.keyword", + documentationUrl = "/workflow/actions/plc4x.html") +public class Plc4xCheckConnections extends ActionBase implements Cloneable, IAction { + private static final Class PKG = Plc4xCheckConnections.class; // Needed by Translator + + + private Plc4xConnection[] connections; + private boolean connected = false; + private Plc4xWrapperConnection connwrapper = null; + private PlcConnection plcconn = null; + private ActionBase actionbase = null; + + private Plc4xLookup lookup = Plc4xLookup.getDefault(); + private Lookup.Template template = null; + private Lookup.Result lkresult = null; + + protected static final String[] unitTimeDesc = + new String[] { + BaseMessages.getString(PKG, "Plc4xCheckConnections.UnitTimeMilliSecond.Label"), + BaseMessages.getString(PKG, "Plc4xCheckConnections.UnitTimeSecond.Label"), + BaseMessages.getString(PKG, "Plc4xCheckConnections.UnitTimeMinute.Label"), + BaseMessages.getString(PKG, "Plc4xCheckConnections.UnitTimeHour.Label"), + }; + protected static final String[] unitTimeCode = + new String[] {"millisecond", "second", "minute", "hour"}; + + public static final int UNIT_TIME_MILLI_SECOND = 0; + public static final int UNIT_TIME_SECOND = 1; + public static final int UNIT_TIME_MINUTE = 2; + public static final int UNIT_TIME_HOUR = 3; + + private String[] waitfors; + private int[] waittimes; + + private long timeStart; + private long now; + + public Plc4xCheckConnections(String name) { + super(name, ""); + //connections = null; + waitfors = null; + waittimes = null; + } + + public Plc4xCheckConnections() { + this( ""); + } + + public Object clone() { + Plc4xCheckConnections c = (Plc4xCheckConnections) super.clone(); + return c; + } + + + public Plc4xConnection[] getConnections() { + return connections; + } + + public void setConnections(Plc4xConnection[] connections) { + this.connections = connections; + } + + public String[] getWaitfors() { + return waitfors; + } + + public void setWaitfors(String[] waitfors) { + this.waitfors = waitfors; + } + + public int[] getWaittimes() { + return waittimes; + } + + public void setWaittimes(int[] waittimes) { + this.waittimes = waittimes; + } + + public long getTimeStart() { + return timeStart; + } + + public long getNow() { + return now; + } + + private static String getWaitTimeCode(int i) { + if (i < 0 || i >= unitTimeCode.length) { + return unitTimeCode[0]; + } + return unitTimeCode[i]; + } + + public static String getWaitTimeDesc(int i) { + if (i < 0 || i >= unitTimeDesc.length) { + return unitTimeDesc[0]; + } + return unitTimeDesc[i]; + } + + public static int getWaitTimeByDesc(String tt) { + if (tt == null) { + return 0; + } + + for (int i = 0; i < unitTimeDesc.length; i++) { + if (unitTimeDesc[i].equalsIgnoreCase(tt)) { + return i; + } + } + + // If this fails, try to match using the code. + return getWaitTimeByCode(tt); + } + + private static int getWaitTimeByCode(String tt) { + if (tt == null) { + return 0; + } + + for (int i = 0; i < unitTimeCode.length; i++) { + if (unitTimeCode[i].equalsIgnoreCase(tt)) { + return i; + } + } + return 0; + } + + /** + * + * Save values to XML + * + * @return + */ + @Override + public String getXml() { + StringBuilder xml = new StringBuilder(120); + xml.append(super.getXml()); + xml.append(" ").append(Const.CR); + if (connections != null) { + for (int i = 0; i < connections.length; i++) { + xml.append(" ").append(Const.CR); + xml.append(" ") + .append( + XmlHandler.addTagValue( + "name", connections[i] == null ? null : connections[i].getName())); + xml.append(" ").append(XmlHandler.addTagValue("waitfor", waitfors[i])); + xml.append(" ") + .append(XmlHandler.addTagValue("waittime", getWaitTimeCode(waittimes[i]))); + xml.append(" ").append(Const.CR); + } + } + xml.append(" ").append(Const.CR); + + return xml.toString(); + } + + /** + * + * Read the XML and get the values needed for the acton + * + * @param entrynode + * @param metadataProvider + * @throws HopXmlException + */ + @Override + public void loadXml( Node entrynode, IHopMetadataProvider metadataProvider, IVariables variables ) throws HopXmlException { + try { + super.loadXml(entrynode); + Node fields = XmlHandler.getSubNode(entrynode, "connections"); + + // How many hosts? + int nrFields = XmlHandler.countNodes(fields, "connection"); + connections = new Plc4xConnection[nrFields]; + waitfors = new String[nrFields]; + waittimes = new int[nrFields]; + // Read them all... + for (int i = 0; i < nrFields; i++) { + Node fnode = XmlHandler.getSubNodeByNr(fields, "connection", i); + String dbname = XmlHandler.getTagValue(fnode, "name"); + + //connections[i] = Plc4xConnection.loadDatabase(metadataProvider, dbname); + if (dbname != null) { + connections[i] = metadataProvider.getSerializer(Plc4xConnection.class).load(dbname); + waitfors[i] = XmlHandler.getTagValue(fnode, "waitfor"); + waittimes[i] = getWaitTimeByCode(Const.NVL(XmlHandler.getTagValue(fnode, "waittime"), "")); + }; + } + } catch (HopXmlException xe) { + throw new HopXmlException( + BaseMessages.getString( + PKG, + "Plc4xCheckConnections.ERROR_0001_Cannot_Load_Job_Entry_From_Xml_Node", + xe.getMessage())); + } catch (HopException ex) { + throw new HopXmlException( + BaseMessages.getString( + PKG, + "Plc4xCheckConnections.ERROR_0001_Cannot_Load_Job_Entry_From_Xml_Node", + ex.getMessage())); + } + } + + /** + * Execute this action and return the result. + * In this case it means, just set the result boolean in the Result class. + * + * Check all conections metadata from the dialog (really only one). + * @param prevResult The result of the previous execution + * @return The Result of the execution. + */ + @Override + public Result execute( Result prevResult, int nr ) { + + Result result = prevResult; + result.setNrErrors(0); + connected = true; + + actionbase = null; + + for (Plc4xConnection connmeta:connections) { + + if (null == connwrapper) { //(01) + template = new Lookup.Template<>(Plc4xWrapperConnection.class, connmeta.getName(), null); + lkresult = lookup.lookup(template); + if (!lkresult.allItems().isEmpty()) { + connwrapper = (Plc4xWrapperConnection) lkresult.allInstances().toArray()[0]; //(02) + if (connwrapper != null) connwrapper.retain(); //(03) + } + }; + + if (null == connwrapper) { //(04) + try { + PlcConnection conn = new DefaultPlcDriverManager().getConnection(connmeta.getUrl()); //(05) + if (conn.isConnected()) { + connwrapper = new Plc4xWrapperConnection(conn, connmeta.getName()); + lookup.add(connwrapper); //(06) + } else { + connected = false; + plcconn = null; + } + } catch (Exception ex) { + connected = false; + plcconn = null; + } + + } else { + if (!connwrapper.getConnection().isConnected()) { //(07) + connected = false; + plcconn = null; + } + } + + if (null == connwrapper) { //(08) + try { + + PlcConnection conn = new DefaultPlcDriverManager().getConnection(connmeta.getUrl()); //(09) + + if (conn.isConnected()) { + conn.close(); //(10) + plcconn = null; + } else { + connected = false; + plcconn = null; + } + } catch (Exception ex){ + connected = false; + plcconn = null; + } + + } + } + + result.setResult(connected); + return result; + } + + @Override + public boolean resetErrorsBeforeExecution() { + return false; + } + + @Override + public boolean isEvaluation() { + return true; + } + + @Override + public boolean isUnconditional() { + return false; + } + +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/java/org/apache/plc4x/hop/actions/Plc4xCheckConnectionsDialog.java b/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/java/org/apache/plc4x/hop/actions/Plc4xCheckConnectionsDialog.java new file mode 100644 index 00000000000..791d3b88611 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/java/org/apache/plc4x/hop/actions/Plc4xCheckConnectionsDialog.java @@ -0,0 +1,371 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.plc4x.hop.actions; + +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.apache.hop.core.Const; +import org.apache.hop.core.exception.HopException; +import org.apache.hop.core.util.Utils; +import org.apache.hop.core.variables.IVariables; +import org.apache.hop.i18n.BaseMessages; +import org.apache.hop.ui.core.dialog.BaseDialog; +import org.apache.hop.ui.core.gui.WindowProperty; +import org.apache.hop.ui.core.widget.ColumnInfo; +import org.apache.hop.ui.core.widget.TableView; +import org.apache.hop.ui.pipeline.transform.BaseTransformDialog; +import org.apache.hop.ui.workflow.action.ActionDialog; +import org.apache.hop.ui.workflow.dialog.WorkflowDialog; +import org.apache.hop.workflow.WorkflowMeta; +import org.apache.hop.workflow.action.IAction; +import org.apache.hop.workflow.action.IActionDialog; +import org.apache.plc4x.hop.metadata.Plc4xConnection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.*; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.*; + +import org.apache.hop.metadata.api.IHopMetadata; +import org.apache.hop.ui.core.dialog.ErrorDialog; +import org.apache.hop.ui.core.metadata.MetadataManager; +import org.apache.hop.ui.core.widget.MetaSelectionLine; + + +public class Plc4xCheckConnectionsDialog extends ActionDialog implements IActionDialog { + private static final Class PKG = Plc4xCheckConnectionsDialog.class; // Needed by Translator + + private Shell shell; + + private Text wName; + + private Plc4xCheckConnections action; + + private boolean changed; + + private TableView wFields; + + private MetaSelectionLine wConnection; + + public Plc4xCheckConnectionsDialog(Shell parent, IAction action, WorkflowMeta workflowMeta, IVariables variables) { + super( parent, workflowMeta, variables ); + this.action = (Plc4xCheckConnections) action; + if ( this.action.getName() == null ) { + this.action.setName( BaseMessages.getString( PKG, "Plc4xCheckConnections.Label" ) ); + } + } + + @Override + public IAction open() { + Shell parent = getParent(); + + shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.MIN | SWT.MAX | SWT.RESIZE); + props.setLook(shell); + WorkflowDialog.setShellImage(shell, action); + + ModifyListener lsMod = (ModifyEvent e) -> action.setChanged(); + changed = action.hasChanged(); + + FormLayout formLayout = new FormLayout(); + formLayout.marginWidth = Const.FORM_MARGIN; + formLayout.marginHeight = Const.FORM_MARGIN; + + shell.setLayout(formLayout); + shell.setText(BaseMessages.getString(PKG, "Plc4xCheckonnections.Title")); + + int middle = props.getMiddlePct(); + int margin = Const.MARGIN; + + // Buttons at the bottom + // + Button wOk = new Button(shell, SWT.PUSH); + wOk.setText(BaseMessages.getString(PKG, "System.Button.OK")); + wOk.addListener(SWT.Selection, (Event e) -> ok()); + Button wCancel = new Button(shell, SWT.PUSH); + wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); + wCancel.addListener(SWT.Selection, (Event e) -> cancel()); + BaseTransformDialog.positionBottomButtons(shell, new Button[] {wOk, wCancel}, margin, null); + + // Filename line + Label wlName = new Label(shell, SWT.RIGHT); + wlName.setText(BaseMessages.getString(PKG, "Plc4xCheckConnections.Name.Label")); + props.setLook(wlName); + FormData fdlName = new FormData(); + fdlName.left = new FormAttachment(0, 0); + fdlName.right = new FormAttachment(middle, -margin); + fdlName.top = new FormAttachment(0, margin); + wlName.setLayoutData(fdlName); + wName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wName); + wName.addModifyListener(lsMod); + FormData fdName = new FormData(); + fdName.left = new FormAttachment(middle, 0); + fdName.top = new FormAttachment(0, margin); + fdName.right = new FormAttachment(100, 0); + wName.setLayoutData(fdName); + + Label wlFields = new Label(shell, SWT.NONE); + wlFields.setText(BaseMessages.getString(PKG, "Plc4xCheckConnections.Fields.Label")); + props.setLook(wlFields); + FormData fdlFields = new FormData(); + fdlFields.left = new FormAttachment(0, 0); + // fdlFields.right= new FormAttachment(middle, -margin); + fdlFields.top = new FormAttachment(wName, 2 * margin); + wlFields.setLayoutData(fdlFields); + + + wConnection = + new MetaSelectionLine<>( + variables, + metadataProvider, + Plc4xConnection.class, + shell, + SWT.NONE, + BaseMessages.getString(PKG, "Plc4xCheckConnections.Connection.Label"), + BaseMessages.getString(PKG, "Plc4xCheckConnections.Connection.Tooltip")); + props.setLook(wConnection); + FormData fdConnection = new FormData(); + fdConnection.left = new FormAttachment(0, 0); + fdConnection.right = new FormAttachment(100, 0); + //fdConnection.top = new FormAttachment(wTransformName, margin); + wConnection.setLayoutData(fdConnection); + + try { + wConnection.fillItems(); + } catch (Exception e) { + new ErrorDialog(shell, "Error", "Error listing Cassandra connection metadata objects", e); + } + + + // Buttons to the right of the screen... + Button wbGetConnections = new Button(shell, SWT.PUSH | SWT.CENTER); + props.setLook(wbGetConnections); + wbGetConnections.setText( + BaseMessages.getString(PKG, "Plc4xCheckConnections.GetConnections")); + wbGetConnections.setToolTipText( + BaseMessages.getString(PKG, "Plc4xCheckConnections.GetConnections.Tooltip")); + FormData fdbGetConnections = new FormData(); + fdbGetConnections.right = new FormAttachment(100, -margin); + fdbGetConnections.top = new FormAttachment(wlFields, margin); + wbGetConnections.setLayoutData(fdbGetConnections); + + // Buttons to the right of the screen... + Button wbdSourceFileFolder = new Button(shell, SWT.PUSH | SWT.CENTER); + props.setLook(wbdSourceFileFolder); + wbdSourceFileFolder.setText( + BaseMessages.getString(PKG, "Plc4xCheckConnections.DeleteEntry")); + wbdSourceFileFolder.setToolTipText( + BaseMessages.getString(PKG, "Plc4xCheckConnections.DeleteSourceFileButton.Label")); + FormData fdbdSourceFileFolder = new FormData(); + fdbdSourceFileFolder.right = new FormAttachment(100, -margin); + fdbdSourceFileFolder.top = new FormAttachment(wbGetConnections, margin); + wbdSourceFileFolder.setLayoutData(fdbdSourceFileFolder); + + int rows = + action.getConnections() == null + ? 1 + : (action.getConnections().length == 0 ? 0 : action.getConnections().length); + + final int FieldsRows = rows; + + ColumnInfo[] colinf = + new ColumnInfo[] { + new ColumnInfo( + BaseMessages.getString(PKG, "Plc4xCheckConnections.Fields.Argument.Label"), + ColumnInfo.COLUMN_TYPE_CCOMBO, + this.getWorkflowMeta().getDatabaseNames(), + false), + new ColumnInfo( + BaseMessages.getString(PKG, "Plc4xCheckConnections.Fields.WaitFor.Label"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "Plc4xCheckConnections.Fields.WaitForTime.Label"), + ColumnInfo.COLUMN_TYPE_CCOMBO, + Plc4xCheckConnections.unitTimeDesc, + false), + }; + + colinf[0].setToolTip(BaseMessages.getString(PKG, "Plc4xCheckConnections.Fields.Column")); + colinf[1].setUsingVariables(true); + colinf[1].setToolTip(BaseMessages.getString(PKG, "Plc4xCheckConnections.WaitFor.ToolTip")); + + wFields = + new TableView( + variables, + shell, + SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, + colinf, + FieldsRows, + lsMod, + props); + + FormData fdFields = new FormData(); + fdFields.left = new FormAttachment(0, 0); + fdFields.top = new FormAttachment(wlFields, margin); + fdFields.right = new FormAttachment(wbGetConnections, -margin); + fdFields.bottom = new FormAttachment(wOk, -2 * margin); + wFields.setLayoutData(fdFields); + + // Delete files from the list of files... + wbdSourceFileFolder.addListener( + SWT.Selection, + e -> { + int[] idx = wFields.getSelectionIndices(); + wFields.remove(idx); + wFields.removeEmptyRows(); + wFields.setRowNums(); + }); + + // get connections... + wbGetConnections.addListener(SWT.Selection, e -> getConnections()); + + getData(); + + BaseDialog.defaultShellHandling(shell, c -> ok(), c -> cancel()); + + return action; + } + + // public void addDatabases() { + // connections = workflowMeta.getDatabaseNames(); + // } + + public void getConnections() { + /* + this.workflowMeta.getMetadataProvider().getMetadataClasses().forEach( + (c) -> { + System.out.println("Name: " + c.getName()); + }); + IHopMetadataProvider hmdp = this.workflowMeta.getMetadataProvider(); + */ + Class metadataClass = null; + + java.util.List databases = new ArrayList<>(); //this.workflowMeta.getMetadataProvider(). + try { + metadataClass = metadataProvider.getMetadataClassForKey("plc4x-connection"); + MetadataManager manager = new MetadataManager<>(variables, metadataProvider, metadataClass, null); + manager.getNames().forEach((s)->{ + try { + databases.add((Plc4xConnection) manager.loadElement(s)); + } catch (HopException ex) { + Logger.getLogger(Plc4xCheckConnectionsDialog.class.getName()).log(Level.SEVERE, null, ex); + } + }); + + } catch (Exception ex) { + Logger.getLogger(Plc4xCheckConnectionsDialog.class.getName()).log(Level.SEVERE, null, ex); + } + + + wFields.removeAll(); + + for (Plc4xConnection ci : databases) { + if (ci != null) { + wFields.add(new String[] {ci.getName(), "0", Plc4xCheckConnections.unitTimeDesc[0]}); + } + } + wFields.removeEmptyRows(); + wFields.setRowNums(); + wFields.optWidth(true); + } + + public void dispose() { + WindowProperty winprop = new WindowProperty(shell); + props.setScreen(winprop); + shell.dispose(); + } + + /** Copy information from the meta-data input to the dialog fields. */ + public void getData() { + if (action.getName() != null) { + wName.setText(action.getName()); + } + + if (action.getConnections() != null) { + for (int i = 0; i < action.getConnections().length; i++) { + TableItem ti = wFields.table.getItem(i); + if (action.getConnections()[i] != null) { + ti.setText(1, action.getConnections()[i].getName()); + ti.setText(2, "" + Const.toInt(action.getWaitfors()[i], 0)); + ti.setText(3, Plc4xCheckConnections.getWaitTimeDesc(action.getWaittimes()[i])); + } + } + wFields.setRowNums(); + wFields.optWidth(true); + } + wName.selectAll(); + wName.setFocus(); + } + + private void cancel() { + action.setChanged(changed); + action = null; + dispose(); + } + + private void ok() { + if (Utils.isEmpty(wName.getText())) { + MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); + mb.setText(BaseMessages.getString(PKG, "System.TransformActionNameMissing.Title")); + mb.setMessage(BaseMessages.getString(PKG, "System.ActionNameMissing.Msg")); + mb.open(); + return; + } + Class metadataClass = null; + action.setName(wName.getText()); + + int nrItems = wFields.nrNonEmpty(); + System.out.println("Numero de items: " + nrItems); + + Plc4xConnection[] connections = new Plc4xConnection[nrItems]; + String[] waitfors = new String[nrItems]; + int[] waittimes = new int[nrItems]; + + + try { + metadataClass = metadataProvider.getMetadataClassForKey("plc4x-connection"); + } catch (HopException ex) { + Logger.getLogger(Plc4xCheckConnectionsDialog.class.getName()).log(Level.SEVERE, null, ex); + } + MetadataManager manager = new MetadataManager<>(variables, metadataProvider, metadataClass, null); + + for (int i = 0; i < nrItems; i++) { + String arg = wFields.getNonEmpty(i).getText(1); + Plc4xConnection conn; + try { + conn = (Plc4xConnection) manager.loadElement(arg); + if (conn != null) { + connections[i] = conn; + waitfors[i] = "" + Const.toInt(wFields.getNonEmpty(i).getText(2), 0); + waittimes[i] = + Plc4xCheckConnections.getWaitTimeByDesc(wFields.getNonEmpty(i).getText(3)); + } + } catch (HopException ex) { + Logger.getLogger(Plc4xCheckConnectionsDialog.class.getName()).log(Level.SEVERE, null, ex); + } + + } + action.setConnections(connections); + action.setWaitfors(waitfors); + action.setWaittimes(waittimes); + + dispose(); + } +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/java/org/apache/plc4x/hop/actions/Plc4xCheckDisConnections.java b/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/java/org/apache/plc4x/hop/actions/Plc4xCheckDisConnections.java new file mode 100644 index 00000000000..d92da3f85ab --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/java/org/apache/plc4x/hop/actions/Plc4xCheckDisConnections.java @@ -0,0 +1,292 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.plc4x.hop.actions; + +import org.apache.hop.core.ICheckResult; +import org.apache.hop.core.Result; +import org.apache.hop.core.annotations.Action; +import org.apache.hop.core.exception.HopXmlException; +import org.apache.hop.core.variables.IVariables; +import org.apache.hop.core.xml.XmlHandler; +import org.apache.hop.i18n.BaseMessages; +import org.apache.hop.metadata.api.IHopMetadataProvider; +import org.apache.hop.workflow.WorkflowMeta; +import org.apache.hop.workflow.action.ActionBase; +import org.apache.hop.workflow.action.IAction; + + +import java.util.List; +import org.apache.hop.core.Const; +import org.apache.hop.core.exception.HopException; +import org.apache.hop.pipeline.PipelineMeta; +import org.apache.hop.pipeline.engine.IPipelineEngine; +import org.apache.plc4x.hop.metadata.Plc4xConnection; +import org.apache.plc4x.hop.metadata.util.Plc4xLookup; +import org.apache.plc4x.hop.metadata.util.Plc4xWrapperConnection; +import org.openide.util.Lookup; +import org.w3c.dom.Node; + +/* +* The purpose of this "Action" is to release the driver resource +* within a "workflow", in case the number of accounts reaches zero, +* the wrapper will close the connection. +* The work pattern must be within the "workflow": +* +* Start -> Create connection -> Run pipeline -> Close connection -> Finish. +* +* It should always be taken into account that the connections to +* the PLCs are limited resources. +*/ +@Action( + id = "CHECK_PLC4X_DISCONNECTIONS", + name = "i18n::Plc4xActionDisConnections.Name", + description = "i18n::Plc4xActionDisConnections.Description", + image = "plc4x_toddy_stop.svg", + categoryDescription = "i18n:org.apache.hop.workflow:ActionCategory.Category.Conditions", + keywords = "i18n::Plc4xActionDisConnections.keyword", + documentationUrl = "/workflow/actions/checkdbconnection.html") +public class Plc4xCheckDisConnections extends ActionBase implements Cloneable, IAction { + + private static final Class PKG = Plc4xCheckDisConnections.class; // Needed by Translator + + + private Plc4xConnection[] connections; + private Plc4xWrapperConnection connwrapper = null; + private ActionBase actionbase = null; + + private Plc4xLookup lookup = Plc4xLookup.getDefault(); + private Lookup.Template template = null; + private Lookup.Result lkresult = null; + + protected static final String[] unitTimeDesc = + new String[] { + BaseMessages.getString(PKG, "Plc4xCheckConnections.UnitTimeMilliSecond.Label"), + BaseMessages.getString(PKG, "Plc4xCheckConnections.UnitTimeSecond.Label"), + BaseMessages.getString(PKG, "Plc4xCheckConnections.UnitTimeMinute.Label"), + BaseMessages.getString(PKG, "Plc4xCheckConnections.UnitTimeHour.Label"), + }; + protected static final String[] unitTimeCode = + new String[] {"millisecond", "second", "minute", "hour"}; + + public static final int UNIT_TIME_MILLI_SECOND = 0; + public static final int UNIT_TIME_SECOND = 1; + public static final int UNIT_TIME_MINUTE = 2; + public static final int UNIT_TIME_HOUR = 3; + + private String[] waitfors; + private int[] waittimes; + + private long timeStart; + private long now; + + public Plc4xCheckDisConnections( String name) { + super(name, ""); + //connections = null; + waitfors = null; + waittimes = null; + } + + public Plc4xCheckDisConnections() { + this( ""); + } + + public Object clone() { + Plc4xCheckDisConnections c = (Plc4xCheckDisConnections) super.clone(); + return c; + } + + + public Plc4xConnection[] getConnections() { + return connections; + } + + public void setConnections(Plc4xConnection[] connections) { + this.connections = connections; + } + + public String[] getWaitfors() { + return waitfors; + } + + public void setWaitfors(String[] waitfors) { + this.waitfors = waitfors; + } + + public int[] getWaittimes() { + return waittimes; + } + + public void setWaittimes(int[] waittimes) { + this.waittimes = waittimes; + } + + public long getTimeStart() { + return timeStart; + } + + public long getNow() { + return now; + } + + private static String getWaitTimeCode(int i) { + if (i < 0 || i >= unitTimeCode.length) { + return unitTimeCode[0]; + } + return unitTimeCode[i]; + } + + public static String getWaitTimeDesc(int i) { + if (i < 0 || i >= unitTimeDesc.length) { + return unitTimeDesc[0]; + } + return unitTimeDesc[i]; + } + + public static int getWaitTimeByDesc(String tt) { + if (tt == null) { + return 0; + } + + for (int i = 0; i < unitTimeDesc.length; i++) { + if (unitTimeDesc[i].equalsIgnoreCase(tt)) { + return i; + } + } + + // If this fails, try to match using the code. + return getWaitTimeByCode(tt); + } + + private static int getWaitTimeByCode(String tt) { + if (tt == null) { + return 0; + } + + for (int i = 0; i < unitTimeCode.length; i++) { + if (unitTimeCode[i].equalsIgnoreCase(tt)) { + return i; + } + } + return 0; + } + + + + /** + * + * Save values to XML + * + * @return + */ + @Override + public String getXml() { + StringBuilder xml = new StringBuilder(120); + xml.append(super.getXml()); + xml.append(" ").append(Const.CR); + if (connections != null) { + for (int i = 0; i < connections.length; i++) { + xml.append(" ").append(Const.CR); + xml.append(" ") + .append( + XmlHandler.addTagValue( + "name", connections[i] == null ? null : connections[i].getName())); + xml.append(" ").append(XmlHandler.addTagValue("waitfor", waitfors[i])); + xml.append(" ") + .append(XmlHandler.addTagValue("waittime", getWaitTimeCode(waittimes[i]))); + xml.append(" ").append(Const.CR); + } + } + xml.append(" ").append(Const.CR); + + return xml.toString(); + } + + /** + * + * Read the XML and get the values needed for the acton + * + * @param entrynode + * @param metadataProvider + * @throws HopXmlException + */ + @Override + public void loadXml( Node entrynode, IHopMetadataProvider metadataProvider, IVariables variables ) throws HopXmlException { + try { + super.loadXml(entrynode); + Node fields = XmlHandler.getSubNode(entrynode, "connections"); + + // How many hosts? + int nrFields = XmlHandler.countNodes(fields, "connection"); + connections = new Plc4xConnection[nrFields]; + waitfors = new String[nrFields]; + waittimes = new int[nrFields]; + // Read them all... + for (int i = 0; i < nrFields; i++) { + Node fnode = XmlHandler.getSubNodeByNr(fields, "connection", i); + String dbname = XmlHandler.getTagValue(fnode, "name"); + + //connections[i] = Plc4xConnection.loadDatabase(metadataProvider, dbname); + if (dbname != null) { + connections[i] = metadataProvider.getSerializer(Plc4xConnection.class).load(dbname); + waitfors[i] = XmlHandler.getTagValue(fnode, "waitfor"); + waittimes[i] = getWaitTimeByCode(Const.NVL(XmlHandler.getTagValue(fnode, "waittime"), "")); + }; + } + } catch (HopXmlException xe) { + throw new HopXmlException( + BaseMessages.getString( + PKG, + "Plc4xCheckConnections.ERROR_0001_Cannot_Load_Job_Entry_From_Xml_Node", + xe.getMessage())); + } catch (HopException ex) { + throw new HopXmlException( + BaseMessages.getString( + PKG, + "Plc4xCheckConnections.ERROR_0001_Cannot_Load_Job_Entry_From_Xml_Node", + ex.getMessage())); + } + } + + /** + * Execute this action and return the result. In this case it means, + * just set the result boolean in the Result class. + * + * @param result The result of the previous execution + * @return The Result of the execution. + */ + @Override + public Result execute( Result result, int nr ) { + result.setResult(true); + + for (Plc4xConnection connmeta:connections) { + template = new Lookup.Template<>(Plc4xWrapperConnection.class, connmeta.getName(), null); + lkresult = lookup.lookup(template); + if (!lkresult.allItems().isEmpty()) { + connwrapper = (Plc4xWrapperConnection) lkresult.allInstances().toArray()[0]; + if (connwrapper != null) { + connwrapper.release(); + if (connwrapper.refCnt() <= 0) + lookup.remove(connwrapper); + } + } + }; + + return result; + } + +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/java/org/apache/plc4x/hop/actions/Plc4xCheckDisConnectionsDialog.java b/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/java/org/apache/plc4x/hop/actions/Plc4xCheckDisConnectionsDialog.java new file mode 100644 index 00000000000..75336387996 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/java/org/apache/plc4x/hop/actions/Plc4xCheckDisConnectionsDialog.java @@ -0,0 +1,371 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.plc4x.hop.actions; + +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.apache.hop.core.Const; +import org.apache.hop.core.exception.HopException; +import org.apache.hop.core.util.Utils; +import org.apache.hop.core.variables.IVariables; +import org.apache.hop.i18n.BaseMessages; +import org.apache.hop.ui.core.dialog.BaseDialog; +import org.apache.hop.ui.core.gui.WindowProperty; +import org.apache.hop.ui.core.widget.ColumnInfo; +import org.apache.hop.ui.core.widget.TableView; +import org.apache.hop.ui.pipeline.transform.BaseTransformDialog; +import org.apache.hop.ui.workflow.action.ActionDialog; +import org.apache.hop.ui.workflow.dialog.WorkflowDialog; +import org.apache.hop.workflow.WorkflowMeta; +import org.apache.hop.workflow.action.IAction; +import org.apache.hop.workflow.action.IActionDialog; +import org.apache.plc4x.hop.metadata.Plc4xConnection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.*; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.*; + +import org.apache.hop.metadata.api.IHopMetadata; +import org.apache.hop.ui.core.dialog.ErrorDialog; +import org.apache.hop.ui.core.metadata.MetadataManager; +import org.apache.hop.ui.core.widget.MetaSelectionLine; + + +public class Plc4xCheckDisConnectionsDialog extends ActionDialog implements IActionDialog { + private static final Class PKG = Plc4xCheckDisConnectionsDialog.class; // Needed by Translator + + private Shell shell; + + private Text wName; + + private Plc4xCheckDisConnections action; + + private boolean changed; + + private TableView wFields; + + private MetaSelectionLine wConnection; + + public Plc4xCheckDisConnectionsDialog(Shell parent, IAction action, WorkflowMeta workflowMeta, IVariables variables) { + super( parent, workflowMeta, variables ); + this.action = (Plc4xCheckDisConnections) action; + if ( this.action.getName() == null ) { + this.action.setName( BaseMessages.getString( PKG, "Plc4xCheckConnections.Label" ) ); + } + } + + @Override + public IAction open() { + Shell parent = getParent(); + + shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.MIN | SWT.MAX | SWT.RESIZE); + props.setLook(shell); + WorkflowDialog.setShellImage(shell, action); + + ModifyListener lsMod = (ModifyEvent e) -> action.setChanged(); + changed = action.hasChanged(); + + FormLayout formLayout = new FormLayout(); + formLayout.marginWidth = Const.FORM_MARGIN; + formLayout.marginHeight = Const.FORM_MARGIN; + + shell.setLayout(formLayout); + shell.setText(BaseMessages.getString(PKG, "Plc4xCheckonnections.Title")); + + int middle = props.getMiddlePct(); + int margin = Const.MARGIN; + + // Buttons at the bottom + // + Button wOk = new Button(shell, SWT.PUSH); + wOk.setText(BaseMessages.getString(PKG, "System.Button.OK")); + wOk.addListener(SWT.Selection, (Event e) -> ok()); + Button wCancel = new Button(shell, SWT.PUSH); + wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); + wCancel.addListener(SWT.Selection, (Event e) -> cancel()); + BaseTransformDialog.positionBottomButtons(shell, new Button[] {wOk, wCancel}, margin, null); + + // Filename line + Label wlName = new Label(shell, SWT.RIGHT); + wlName.setText(BaseMessages.getString(PKG, "Plc4xCheckConnections.Name.Label")); + props.setLook(wlName); + FormData fdlName = new FormData(); + fdlName.left = new FormAttachment(0, 0); + fdlName.right = new FormAttachment(middle, -margin); + fdlName.top = new FormAttachment(0, margin); + wlName.setLayoutData(fdlName); + wName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wName); + wName.addModifyListener(lsMod); + FormData fdName = new FormData(); + fdName.left = new FormAttachment(middle, 0); + fdName.top = new FormAttachment(0, margin); + fdName.right = new FormAttachment(100, 0); + wName.setLayoutData(fdName); + + Label wlFields = new Label(shell, SWT.NONE); + wlFields.setText(BaseMessages.getString(PKG, "Plc4xCheckConnections.Fields.Label")); + props.setLook(wlFields); + FormData fdlFields = new FormData(); + fdlFields.left = new FormAttachment(0, 0); + // fdlFields.right= new FormAttachment(middle, -margin); + fdlFields.top = new FormAttachment(wName, 2 * margin); + wlFields.setLayoutData(fdlFields); + + + wConnection = + new MetaSelectionLine<>( + variables, + metadataProvider, + Plc4xConnection.class, + shell, + SWT.NONE, + BaseMessages.getString(PKG, "Plc4xCheckConnections.Connection.Label"), + BaseMessages.getString(PKG, "Plc4xCheckConnections.Connection.Tooltip")); + props.setLook(wConnection); + FormData fdConnection = new FormData(); + fdConnection.left = new FormAttachment(0, 0); + fdConnection.right = new FormAttachment(100, 0); + //fdConnection.top = new FormAttachment(wTransformName, margin); + wConnection.setLayoutData(fdConnection); + + try { + wConnection.fillItems(); + } catch (Exception e) { + new ErrorDialog(shell, "Error", "Error listing Cassandra connection metadata objects", e); + } + + + // Buttons to the right of the screen... + Button wbGetConnections = new Button(shell, SWT.PUSH | SWT.CENTER); + props.setLook(wbGetConnections); + wbGetConnections.setText( + BaseMessages.getString(PKG, "Plc4xCheckConnections.GetConnections")); + wbGetConnections.setToolTipText( + BaseMessages.getString(PKG, "Plc4xCheckConnections.GetConnections.Tooltip")); + FormData fdbGetConnections = new FormData(); + fdbGetConnections.right = new FormAttachment(100, -margin); + fdbGetConnections.top = new FormAttachment(wlFields, margin); + wbGetConnections.setLayoutData(fdbGetConnections); + + // Buttons to the right of the screen... + Button wbdSourceFileFolder = new Button(shell, SWT.PUSH | SWT.CENTER); + props.setLook(wbdSourceFileFolder); + wbdSourceFileFolder.setText( + BaseMessages.getString(PKG, "Plc4xCheckConnections.DeleteEntry")); + wbdSourceFileFolder.setToolTipText( + BaseMessages.getString(PKG, "Plc4xCheckConnections.DeleteSourceFileButton.Label")); + FormData fdbdSourceFileFolder = new FormData(); + fdbdSourceFileFolder.right = new FormAttachment(100, -margin); + fdbdSourceFileFolder.top = new FormAttachment(wbGetConnections, margin); + wbdSourceFileFolder.setLayoutData(fdbdSourceFileFolder); + + int rows = + action.getConnections() == null + ? 1 + : (action.getConnections().length == 0 ? 0 : action.getConnections().length); + + final int FieldsRows = rows; + + ColumnInfo[] colinf = + new ColumnInfo[] { + new ColumnInfo( + BaseMessages.getString(PKG, "Plc4xCheckConnections.Fields.Argument.Label"), + ColumnInfo.COLUMN_TYPE_CCOMBO, + this.getWorkflowMeta().getDatabaseNames(), + false), + new ColumnInfo( + BaseMessages.getString(PKG, "Plc4xCheckConnections.Fields.WaitFor.Label"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "Plc4xCheckConnections.Fields.WaitForTime.Label"), + ColumnInfo.COLUMN_TYPE_CCOMBO, + Plc4xCheckConnections.unitTimeDesc, + false), + }; + + colinf[0].setToolTip(BaseMessages.getString(PKG, "Plc4xCheckConnections.Fields.Column")); + colinf[1].setUsingVariables(true); + colinf[1].setToolTip(BaseMessages.getString(PKG, "Plc4xCheckConnections.WaitFor.ToolTip")); + + wFields = + new TableView( + variables, + shell, + SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, + colinf, + FieldsRows, + lsMod, + props); + + FormData fdFields = new FormData(); + fdFields.left = new FormAttachment(0, 0); + fdFields.top = new FormAttachment(wlFields, margin); + fdFields.right = new FormAttachment(wbGetConnections, -margin); + fdFields.bottom = new FormAttachment(wOk, -2 * margin); + wFields.setLayoutData(fdFields); + + // Delete files from the list of files... + wbdSourceFileFolder.addListener( + SWT.Selection, + e -> { + int[] idx = wFields.getSelectionIndices(); + wFields.remove(idx); + wFields.removeEmptyRows(); + wFields.setRowNums(); + }); + + // get connections... + wbGetConnections.addListener(SWT.Selection, e -> getConnections()); + + getData(); + + BaseDialog.defaultShellHandling(shell, c -> ok(), c -> cancel()); + + return action; + } + + // public void addDatabases() { + // connections = workflowMeta.getDatabaseNames(); + // } + + public void getConnections() { + /* + this.workflowMeta.getMetadataProvider().getMetadataClasses().forEach( + (c) -> { + System.out.println("Name: " + c.getName()); + }); + IHopMetadataProvider hmdp = this.workflowMeta.getMetadataProvider(); + */ + Class metadataClass = null; + + java.util.List databases = new ArrayList<>(); //this.workflowMeta.getMetadataProvider(). + try { + metadataClass = metadataProvider.getMetadataClassForKey("plc4x-connection"); + MetadataManager manager = new MetadataManager<>(variables, metadataProvider, metadataClass, null); + manager.getNames().forEach((s)->{ + try { + databases.add((Plc4xConnection) manager.loadElement(s)); + } catch (HopException ex) { + Logger.getLogger(Plc4xCheckDisConnectionsDialog.class.getName()).log(Level.SEVERE, null, ex); + } + }); + + } catch (Exception ex) { + Logger.getLogger(Plc4xCheckDisConnectionsDialog.class.getName()).log(Level.SEVERE, null, ex); + } + + + wFields.removeAll(); + + for (Plc4xConnection ci : databases) { + if (ci != null) { + wFields.add(new String[] {ci.getName(), "0", Plc4xCheckDisConnections.unitTimeDesc[0]}); + } + } + wFields.removeEmptyRows(); + wFields.setRowNums(); + wFields.optWidth(true); + } + + public void dispose() { + WindowProperty winprop = new WindowProperty(shell); + props.setScreen(winprop); + shell.dispose(); + } + + /** Copy information from the meta-data input to the dialog fields. */ + public void getData() { + if (action.getName() != null) { + wName.setText(action.getName()); + } + + if (action.getConnections() != null) { + for (int i = 0; i < action.getConnections().length; i++) { + TableItem ti = wFields.table.getItem(i); + if (action.getConnections()[i] != null) { + ti.setText(1, action.getConnections()[i].getName()); + ti.setText(2, "" + Const.toInt(action.getWaitfors()[i], 0)); + ti.setText(3, Plc4xCheckDisConnections.getWaitTimeDesc(action.getWaittimes()[i])); + } + } + wFields.setRowNums(); + wFields.optWidth(true); + } + wName.selectAll(); + wName.setFocus(); + } + + private void cancel() { + action.setChanged(changed); + action = null; + dispose(); + } + + private void ok() { + if (Utils.isEmpty(wName.getText())) { + MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); + mb.setText(BaseMessages.getString(PKG, "System.TransformActionNameMissing.Title")); + mb.setMessage(BaseMessages.getString(PKG, "System.ActionNameMissing.Msg")); + mb.open(); + return; + } + Class metadataClass = null; + action.setName(wName.getText()); + + int nrItems = wFields.nrNonEmpty(); + System.out.println("Numero de items: " + nrItems); + + Plc4xConnection[] connections = new Plc4xConnection[nrItems]; + String[] waitfors = new String[nrItems]; + int[] waittimes = new int[nrItems]; + + + try { + metadataClass = metadataProvider.getMetadataClassForKey("plc4x-connection"); + } catch (HopException ex) { + Logger.getLogger(Plc4xCheckDisConnectionsDialog.class.getName()).log(Level.SEVERE, null, ex); + } + MetadataManager manager = new MetadataManager<>(variables, metadataProvider, metadataClass, null); + + for (int i = 0; i < nrItems; i++) { + String arg = wFields.getNonEmpty(i).getText(1); + Plc4xConnection conn; + try { + conn = (Plc4xConnection) manager.loadElement(arg); + if (conn != null) { + connections[i] = conn; + waitfors[i] = "" + Const.toInt(wFields.getNonEmpty(i).getText(2), 0); + waittimes[i] = + Plc4xCheckDisConnections.getWaitTimeByDesc(wFields.getNonEmpty(i).getText(3)); + } + } catch (HopException ex) { + Logger.getLogger(Plc4xCheckDisConnectionsDialog.class.getName()).log(Level.SEVERE, null, ex); + } + + } + action.setConnections(connections); + action.setWaitfors(waitfors); + action.setWaittimes(waittimes); + + dispose(); + } +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/resources/org/apache/plc4x/hop/actions/messages/messages_en_US.properties b/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/resources/org/apache/plc4x/hop/actions/messages/messages_en_US.properties new file mode 100644 index 00000000000..ae7eb85d961 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/resources/org/apache/plc4x/hop/actions/messages/messages_en_US.properties @@ -0,0 +1,58 @@ +# +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +Plc4xActionConnections.Name=Plc4x Action Connections +Plc4xActionConnections.Description=Check Plc4x connections +Plc4xActionConnections.keyword=Plc4x Connections + +Plc4xActionDisConnections.Name=Plc4x Action Disconnections +Plc4xActionDisConnections.Description=Check Plc4x disconnections +Plc4xActionDisConnections.keyword=Plc4x Disconnections + + +Plc4xCheckConnections.Name=Check PLC connections +Plc4xCheckConnections.Description=Check if we can connect to one or several databases. +Plc4xCheckConnections.ConnectionOK=We can successfully connect to database [{0}] (connection [{1}]) +Plc4xCheckConnections.ERROR_0001_Cannot_Load_Job_Entry_From_Xml_Node=Unable to load action of type 'Check Db connection' from XML node. Exception : {0} +Plc4xCheckConnections.Exception=Cannot connect to database [{0}] (connection [{1}]). Exception : [{2}] +Plc4xCheckConnections.Log.Info.ConnectionsInSuccess=[{0}] connections were successfully checked. +Plc4xCheckConnections.Log.Info.ConnectionsInError=[{0}] connections were in error. +Plc4xCheckConnections.UnitTimeMilliSecond.Label=Milliseconds +Plc4xCheckConnections.UnitTimeSecond.Label=Seconds +Plc4xCheckConnections.UnitTimeMinute.Label=Minutes +Plc4xCheckConnections.UnitTimeHour.Label=Hours +Plc4xCheckConnections.Connected=Connected to database [{0}] (connection [{1}])... +Plc4xCheckConnections.Wait=We need to leave the connection open {0} {1} ... +Plc4xCheckConnections.WaitTimeIsElapsed.Label=Wait time is elapsed for plc [{0}] (connection [{1}]). The connection will be closed ... +Plc4xCheckConnections.Title=Check PLC connections +Plc4xCheckConnections.Name.Default=Check PLC connections +Plc4xCheckConnections.Name.Label=Action name +Plc4xCheckConnections.Fields.Argument.Label=Connection +Plc4xCheckConnections.Fields.Label=Connections +Plc4xCheckConnections.Fields.Column=Connections +Plc4xCheckConnections.Fields.WaitFor.Label=Wait +Plc4xCheckConnections.Fields.WaitForTime.Label=Units of time +Plc4xCheckConnections.WaitFor.ToolTip=After the connection was opened\nwait x (s, mn,..) +Plc4xCheckConnections.DeleteSourceFileButton.Label=Remove selected items from the list. +Plc4xCheckConnections.DeleteEntry=Delete +Plc4xCheckConnections.GetConnections=Get connections +Plc4xCheckConnections.GetConnections.Tooltip=Get available connections +Plc4xCheckConnections.keyword=check,plc,database,connection +Plc4xCheckConnections.Connection.Label= +Plc4xCheckConnections.Connection.Tooltip= \ No newline at end of file diff --git a/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/resources/plc4x_toddy.svg b/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/resources/plc4x_toddy.svg new file mode 100644 index 00000000000..01694ecd5df --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/resources/plc4x_toddy.svg @@ -0,0 +1,1306 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/resources/plc4x_toddy_play.svg b/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/resources/plc4x_toddy_play.svg new file mode 100644 index 00000000000..b0683725109 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/resources/plc4x_toddy_play.svg @@ -0,0 +1,1490 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/resources/plc4x_toddy_stop.svg b/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/resources/plc4x_toddy_stop.svg new file mode 100644 index 00000000000..844057852b6 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-actions/src/main/resources/plc4x_toddy_stop.svg @@ -0,0 +1,1513 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-action/pom.xml b/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-action/pom.xml new file mode 100644 index 00000000000..3f95f27e849 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-action/pom.xml @@ -0,0 +1,82 @@ + + + + 4.0.0 + + org.apache.plc4x + plc4x-hop-assemblies + 0.11.0-SNAPSHOT + + plc4x-hop-assemblies-action + pom + PLC4J: Integrations: Apache Hop: Assemblies: Action + + + + + org.apache.plc4x + plc4x-hop-action + ${project.version} + + + + + + + + maven-assembly-plugin + ${maven-assembly-plugin.version} + + + + + + + + assembly + + + ${basedir}/src/assembly/assembly.xml + + + + + + maven-assembly-plugin + + + assembly_package + compile + + single + + + ${basedir}/src/assembly + false + + + + + + + + + + \ No newline at end of file diff --git a/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-action/src/assembly/assembly.xml b/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-action/src/assembly/assembly.xml new file mode 100644 index 00000000000..84529d10bab --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-action/src/assembly/assembly.xml @@ -0,0 +1,52 @@ + + + + + plc4x-plugin-assemblies-action + + zip + + plugins/actions/plc4x + + + ${project.basedir}/src/main/resources/version.xml + . + true + + + + + lib + + **/* + + + + + + false + + org.apache.plc4x:plc4x-hop-action:jar + + + + \ No newline at end of file diff --git a/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-action/src/main/resources/version.xml b/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-action/src/main/resources/version.xml new file mode 100644 index 00000000000..2703899672c --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-action/src/main/resources/version.xml @@ -0,0 +1,20 @@ + + +${project.version} \ No newline at end of file diff --git a/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-metadata/pom.xml b/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-metadata/pom.xml new file mode 100644 index 00000000000..290099015a3 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-metadata/pom.xml @@ -0,0 +1,82 @@ + + + + 4.0.0 + + org.apache.plc4x + plc4x-hop-assemblies + 0.11.0-SNAPSHOT + + + plc4x-hop-assemblies-metadata + pom + PLC4J: Integrations: Apache Hop: Assemblies: Metadata + + + + org.apache.plc4x + plc4x-hop-metadata + ${project.version} + + + + + + + + maven-assembly-plugin + ${maven-assembly-plugin.version} + + + + + + + + assembly + + + ${basedir}/src/assembly/assembly.xml + + + + + + maven-assembly-plugin + + + assembly_package + compile + + single + + + ${basedir}/src/assembly + false + + + + + + + + + + \ No newline at end of file diff --git a/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-metadata/src/assembly/assembly.xml b/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-metadata/src/assembly/assembly.xml new file mode 100644 index 00000000000..984455a9bcb --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-metadata/src/assembly/assembly.xml @@ -0,0 +1,100 @@ + + + + + plc4x-plugin-assemblies-metadata + + zip + + plugins/metadata/plc4x + + + ${project.basedir}/src/main/resources/version.xml + . + true + + + + + lib + + **/* + + + + + + false + + org.apache.plc4x:plc4x-hop-metadata:jar + + + + + lib + false + true + runtime + + com.github.jinahya:bit-io:jar + ch.qos.logback:logback-core + + io.netty:netty-buffer + io.netty:netty-codec:jar + io.netty:netty-codec-dns:jar + io.netty:netty-codec-haproxy:jar + io.netty:netty-codec-http:jar + io.netty:netty-codec-http2:jar + io.netty:netty-codec-memcache:jar + io.netty:netty-codec-mqtt:jar + io.netty:netty-codec-redis:jar + io.netty:netty-codec-smtp:jar + io.netty:netty-codec-socks:jar + io.netty:netty-codec-stomp:jar + io.netty:netty-codec-xml:jar + io.netty:netty-common:jar + io.netty:netty-handler:jar + io.netty:netty-handler-proxy:jar + io.netty:netty-ssl-ocsp:jar + io.netty:netty-resolver:jar + io.netty:netty-resolver-dns:jar + io.netty:netty-resolver-dns-classes-macos:jar + io.netty:netty-transport:jar + io.netty:netty-transport-classes-kqueue:jar + io.netty:netty-transport-native-unix-common:jar + io.netty:netty-transport-rxtx:jar + io.netty:netty-transport-sctp:jar + io.netty:netty-transport-udt:jar + + io.vavr:vavr:jar + io.vavr:vavr-match:jar + + org.apache.plc4x:plc4j-api:jar + org.apache.plc4x:plc4j-spi:jar + org.apache.plc4x:plc4j-spi:jar + org.apache.plc4x:plc4j-transport-tcp:jar + org.apache.plc4x:plc4j-driver-s7:jar + + + + + \ No newline at end of file diff --git a/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-metadata/src/main/resources/version.xml b/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-metadata/src/main/resources/version.xml new file mode 100644 index 00000000000..2703899672c --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-metadata/src/main/resources/version.xml @@ -0,0 +1,20 @@ + + +${project.version} \ No newline at end of file diff --git a/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-transform/pom.xml b/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-transform/pom.xml new file mode 100644 index 00000000000..66253b85961 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-transform/pom.xml @@ -0,0 +1,82 @@ + + + + 4.0.0 + + org.apache.plc4x + plc4x-hop-assemblies + 0.11.0-SNAPSHOT + + plc4x-hop-assemblies-transform + pom + PLC4J: Integrations: Apache Hop: Assemblies: Transform + + + + + org.apache.plc4x + plc4x-hop-transform + ${project.version} + + + + + + + + maven-assembly-plugin + ${maven-assembly-plugin.version} + + + + + + + + assembly + + + ${basedir}/src/assembly/assembly.xml + + + + + + maven-assembly-plugin + + + assembly_package + compile + + single + + + ${basedir}/src/assembly + false + + + + + + + + + + \ No newline at end of file diff --git a/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-transform/src/assembly/assembly.xml b/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-transform/src/assembly/assembly.xml new file mode 100644 index 00000000000..bff52ed295f --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-transform/src/assembly/assembly.xml @@ -0,0 +1,101 @@ + + + + + plc4x-plugin-assemblies-transform + + zip + + plugins/transforms/plc4x + + + ${project.basedir}/src/main/resources/version.xml + . + true + + + + + lib + + **/* + + + + + + false + + org.apache.plc4x:plc4x-hop-transform:jar + + + + + + lib + false + true + runtime + + com.github.jinahya:bit-io:jar + ch.qos.logback:logback-core + + io.netty:netty-buffer + io.netty:netty-codec:jar + io.netty:netty-codec-dns:jar + io.netty:netty-codec-haproxy:jar + io.netty:netty-codec-http:jar + io.netty:netty-codec-http2:jar + io.netty:netty-codec-memcache:jar + io.netty:netty-codec-mqtt:jar + io.netty:netty-codec-redis:jar + io.netty:netty-codec-smtp:jar + io.netty:netty-codec-socks:jar + io.netty:netty-codec-stomp:jar + io.netty:netty-codec-xml:jar + io.netty:netty-common:jar + io.netty:netty-handler:jar + io.netty:netty-handler-proxy:jar + io.netty:netty-ssl-ocsp:jar + io.netty:netty-resolver:jar + io.netty:netty-resolver-dns:jar + io.netty:netty-resolver-dns-classes-macos:jar + io.netty:netty-transport:jar + io.netty:netty-transport-classes-kqueue:jar + io.netty:netty-transport-native-unix-common:jar + io.netty:netty-transport-rxtx:jar + io.netty:netty-transport-sctp:jar + io.netty:netty-transport-udt:jar + + io.vavr:vavr:jar + io.vavr:vavr-match:jar + + org.apache.plc4x:plc4j-api:jar + org.apache.plc4x:plc4j-spi:jar + org.apache.plc4x:plc4j-spi:jar + org.apache.plc4x:plc4j-transport-tcp:jar + org.apache.plc4x:plc4j-driver-s7:jar + + + + + \ No newline at end of file diff --git a/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-transform/src/main/resources/version.xml b/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-transform/src/main/resources/version.xml new file mode 100644 index 00000000000..2703899672c --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-assemblies/plc4x-hop-assemblies-transform/src/main/resources/version.xml @@ -0,0 +1,20 @@ + + +${project.version} \ No newline at end of file diff --git a/plc4j/integrations/apache-hop/plc4x-hop-assemblies/pom.xml b/plc4j/integrations/apache-hop/plc4x-hop-assemblies/pom.xml new file mode 100644 index 00000000000..ccc6d04b8e7 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-assemblies/pom.xml @@ -0,0 +1,42 @@ + + + + 4.0.0 + + + org.apache.plc4x + plc4j-apache-hop + 0.11.0-SNAPSHOT + + + plc4x-hop-assemblies + pom + PLC4J: Integrations: Apache Hop: Assemblies + + + ${project.build.directory}/assembly + + + + plc4x-hop-assemblies-metadata + plc4x-hop-assemblies-action + plc4x-hop-assemblies-transform + + \ No newline at end of file diff --git a/plc4j/integrations/apache-hop/plc4x-hop-metadata/pom.xml b/plc4j/integrations/apache-hop/plc4x-hop-metadata/pom.xml new file mode 100644 index 00000000000..7d718f1492c --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-metadata/pom.xml @@ -0,0 +1,155 @@ + + + + 4.0.0 + + org.apache.plc4x + plc4j-apache-hop + 0.11.0-SNAPSHOT + + plc4x-hop-metadata + jar + + PLC4J: Integrations: Apache Hop: Metadata + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + org.jboss.jandex + jandex-maven-plugin + 1.0.8 + + + make-index + + jandex + + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + org.apache.plc4x:plc4j-spi:jar:${project.version} + org.apache.plc4x:plc4j-driver-s7:jar:${project.version} + org.apache.plc4x:plc4j-transport-tcp:jar:${project.version} + org.apache.hop:hop-engine:jar:${hop.version} + javax.annotation:javax.annotation-api:jar:1.2 + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + + true + lib/ + + + + + + + + + + + + org.apache.hop + hop-ui + ${hop.version} + + + org.apache.hop + hop-engine + ${hop.version} + + + * + * + + + + + org.eclipse.platform + org.eclipse.swt.gtk.linux.x86_64 + 3.114.0 + + + org.apache.plc4x + plc4j-driver-s7 + ${project.version} + + + org.apache.plc4x + plc4j-api + ${project.version} + + + org.apache.plc4x + plc4j-spi + ${project.version} + + + org.apache.plc4x + plc4j-transport-tcp + ${project.version} + + + org.apache.hop + hop-core + ${hop.version} + + + * + * + + + + + io.netty + netty-common + ${netty.version} + + + org.netbeans.api + org-openide-util-lookup + RELEASE170 + + + \ No newline at end of file diff --git a/plc4j/integrations/apache-hop/plc4x-hop-metadata/src/main/java/org/apache/plc4x/hop/metadata/Plc4xConnection.java b/plc4j/integrations/apache-hop/plc4x-hop-metadata/src/main/java/org/apache/plc4x/hop/metadata/Plc4xConnection.java new file mode 100644 index 00000000000..3a2b711c53c --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-metadata/src/main/java/org/apache/plc4x/hop/metadata/Plc4xConnection.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.plc4x.hop.metadata; + +import org.apache.hop.core.gui.plugin.GuiElementType; +import org.apache.hop.core.gui.plugin.GuiPlugin; +import org.apache.hop.core.gui.plugin.GuiWidgetElement; +import org.apache.hop.metadata.api.HopMetadata; +import org.apache.hop.metadata.api.HopMetadataBase; +import org.apache.hop.metadata.api.HopMetadataProperty; +import org.apache.hop.metadata.api.IHopMetadata; + +@GuiPlugin +@HopMetadata( + key = "plc4x-connection", + name = "Plc4x Connection", + description = "Describes a connection to a PLC", + image = "plc4x_toddy.svg", + documentationUrl = "/metadata-types/plc4x/plc4x-connection.html") +public class Plc4xConnection extends HopMetadataBase implements IHopMetadata { + + public static final String WIDGET_ID_URL = "10000-url"; + + @HopMetadataProperty + @GuiWidgetElement( + id = WIDGET_ID_URL, + type = GuiElementType.TEXT, + parentId = Plc4xConnectionEditor.PARENT_WIDGET_ID, + label = "URL", + toolTip = "Specify the hostname of your cassandra server") + private String url; + + + public Plc4xConnection() {} + + public Plc4xConnection(Plc4xConnection p) { + super(p.name); + this.url = p.url; + } + + + /** + * Gets url + * + * @return value of hostname + */ + public String getUrl() { + return url; + } + + /** @param hostname The hostname to set */ + public void setUrl(String url) { + this.url = url; + } + + +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-metadata/src/main/java/org/apache/plc4x/hop/metadata/Plc4xConnectionEditor.java b/plc4j/integrations/apache-hop/plc4x-hop-metadata/src/main/java/org/apache/plc4x/hop/metadata/Plc4xConnectionEditor.java new file mode 100644 index 00000000000..75db5ca921c --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-metadata/src/main/java/org/apache/plc4x/hop/metadata/Plc4xConnectionEditor.java @@ -0,0 +1,148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.plc4x.hop.metadata; + +import org.apache.hop.core.Const; +import org.apache.hop.ui.core.PropsUi; +import org.apache.hop.ui.core.dialog.ErrorDialog; +import org.apache.hop.ui.core.gui.GuiCompositeWidgets; +import org.apache.hop.ui.core.gui.GuiCompositeWidgetsAdapter; +import org.apache.hop.ui.core.metadata.IMetadataEditor; +import org.apache.hop.ui.core.metadata.MetadataEditor; +import org.apache.hop.ui.core.metadata.MetadataManager; +import org.apache.hop.ui.hopgui.HopGui; +import org.apache.plc4x.java.DefaultPlcDriverManager; +import org.apache.plc4x.java.api.PlcDriverManager; +import org.apache.plc4x.java.api.PlcConnection; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.widgets.*; + + +public class Plc4xConnectionEditor extends MetadataEditor + implements IMetadataEditor{ + + private static final Class PKG = Plc4xConnectionEditor.class; // For Translator + + public static final String PARENT_WIDGET_ID = "Plc4xConnectionEditor.Widgets.ParentId"; + + private Composite parent; + private Text wName; + private GuiCompositeWidgets widgets; + + public Plc4xConnectionEditor(HopGui hopGui, MetadataManager manager, Plc4xConnection metadata) { + super(hopGui, manager, metadata); + } + + + @Override + public void createControl(Composite parent) { + this.parent = parent; + PropsUi props = PropsUi.getInstance(); + int margin = props.getMargin(); + int middle = props.getMiddlePct(); + // Name... + // + // What's the name + Label wlName = new Label(parent, SWT.RIGHT); + props.setLook(wlName); + wlName.setText("Plc4x url name"); + FormData fdlName = new FormData(); + fdlName.top = new FormAttachment(0, margin * 2); + fdlName.left = new FormAttachment(0, 0); + fdlName.right = new FormAttachment(middle, 0); + wlName.setLayoutData(fdlName); + wName = new Text(parent, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wName); + + FormData fdName = new FormData(); + fdName.top = new FormAttachment(wlName, 0, SWT.CENTER); + fdName.left = new FormAttachment(middle, margin); + fdName.right = new FormAttachment(100, 0); + wName.setLayoutData(fdName); + + // Rest of the widgets... + // + widgets = new GuiCompositeWidgets(manager.getVariables()); + widgets.createCompositeWidgets(getMetadata(), null, parent, PARENT_WIDGET_ID, wName); + + // Set content on the widgets... + // + setWidgetsContent(); + + // Add changed listeners + wName.addListener(SWT.Modify, e -> setChanged()); + widgets.setWidgetsListener( + new GuiCompositeWidgetsAdapter() { + @Override + public void widgetModified( + GuiCompositeWidgets compositeWidgets, Control changedWidget, String widgetId) { + setChanged(); + } + }); + } + + + @Override + public void setWidgetsContent() { + Plc4xConnection meta = getMetadata(); + wName.setText(Const.NVL(meta.getName(), "")); + widgets.setWidgetsContents(meta, parent, PARENT_WIDGET_ID); + } + + @Override + public void getWidgetsContent(Plc4xConnection meta) { + meta.setName(wName.getText()); + widgets.getWidgetsContents(meta, PARENT_WIDGET_ID); + } + + @Override + public Button[] createButtonsForButtonBar(Composite parent) { + PropsUi props = PropsUi.getInstance(); + + Button wbTest = new Button(parent, SWT.PUSH | SWT.CENTER); + props.setLook(wbTest); + wbTest.setText("Test connection."); + wbTest.addListener(SWT.Selection, e -> test_connection()); + + return new Button[] {wbTest}; + } + + public void test_connection() { + PlcConnection plcConnection; + try { + Plc4xConnection meta = getMetadata(); + plcConnection = new DefaultPlcDriverManager().getConnection(meta.getUrl()); + + Thread.sleep(100); + plcConnection.close(); + MessageBox box = new MessageBox(parent.getShell(), SWT.ICON_INFORMATION | SWT.OK); + box.setText("Success!"); + box.setMessage("It's possible to connect to Device with this metadata!"); + box.open(); + + } catch (Exception e) { + new ErrorDialog(parent.getShell(), "Error", "We couldn't connect using this information", e); + } + } + + +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-metadata/src/main/java/org/apache/plc4x/hop/metadata/util/Plc4xLookup.java b/plc4j/integrations/apache-hop/plc4x-hop-metadata/src/main/java/org/apache/plc4x/hop/metadata/util/Plc4xLookup.java new file mode 100644 index 00000000000..6289b44ffb6 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-metadata/src/main/java/org/apache/plc4x/hop/metadata/util/Plc4xLookup.java @@ -0,0 +1,92 @@ + /* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.plc4x.hop.metadata.util; + +import org.apache.plc4x.java.api.PlcConnection; +import org.openide.util.lookup.AbstractLookup; +import org.openide.util.lookup.InstanceContent; +import org.openide.util.lookup.InstanceContent.Convertor; + +/* +* Plc4xLookup is the main repository for sharing connections within a +* Hop pipeline/workflow instance. +* It's static nature limits its use within a JVM instance, +* however this is not a limitation since in general the connections to +* the PLCs are limited resources. +* A "Convertor" is included for the "Plc4xWrapperConnection" types +* to facilitate their use, without limiting their use as a container +* for other types of objects. +*/ +public class Plc4xLookup extends AbstractLookup { + private InstanceContent content = null; + private static Plc4xLookup INSTANCE = new Plc4xLookup (); + + public Plc4xLookup(InstanceContent content) { + super(content); + this.content = content; + } + + public Plc4xLookup() { + this(new InstanceContent()); + } + + public void add(Object obj) { + if (obj instanceof Plc4xWrapperConnection) + content.add((Plc4xWrapperConnection) obj, Plc4xConvertor); + else + content.add(obj); + } + + public void remove(Object obj) { + if (obj instanceof Plc4xWrapperConnection) + content.remove((Plc4xWrapperConnection) obj, Plc4xConvertor); + else + content.remove(obj); + } + + public static Plc4xLookup getDefault(){ + return INSTANCE; + } + + private static final Convertor Plc4xConvertor = + new InstanceContent.Convertor() { + + @Override + public Plc4xWrapperConnection convert(Plc4xWrapperConnection obj) { + return obj; + } + + @Override + public Class type(Plc4xWrapperConnection obj) { + return Plc4xWrapperConnection.class; + } + + @Override + public String id(Plc4xWrapperConnection obj) { + return obj.getId(); + } + + @Override + public String displayName(Plc4xWrapperConnection obj) { + return obj.getConnection().toString(); + } + + }; + +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-metadata/src/main/java/org/apache/plc4x/hop/metadata/util/Plc4xWrapperConnection.java b/plc4j/integrations/apache-hop/plc4x-hop-metadata/src/main/java/org/apache/plc4x/hop/metadata/util/Plc4xWrapperConnection.java new file mode 100644 index 00000000000..f16e6a4259f --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-metadata/src/main/java/org/apache/plc4x/hop/metadata/util/Plc4xWrapperConnection.java @@ -0,0 +1,65 @@ + /* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.plc4x.hop.metadata.util; + +import io.netty.util.AbstractReferenceCounted; +import io.netty.util.ReferenceCounted; +import org.apache.plc4x.java.api.PlcConnection; + +/** + * This is a wrapper around a PlcConnection connection from the Apache Plc4x library. + * Its goal is for it to be shared between the different transform that + * may be running simultaneously on the local or remote Hop engine. + * Its use with other kind of engines must be certified. + * The concept is very simple, "the last to leave closes the connection". + */ +public class Plc4xWrapperConnection extends AbstractReferenceCounted { + + private final PlcConnection connection; + private final String id; + + public Plc4xWrapperConnection(PlcConnection connection, String id){ + super(); + this.connection = connection; + this.id = id; + } + + public PlcConnection getConnection(){ + return this.connection; + } + + @Override + protected void deallocate() { + try{ + connection.close(); + } catch (Exception ex){ + ex.printStackTrace(); + } + } + + @Override + public ReferenceCounted touch(Object hint) { + return this; + } + + public String getId() { + return id; + } + +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-metadata/src/main/resources/org/apache/plc4x/hop/metadata/messages/messages_en_US.properties b/plc4j/integrations/apache-hop/plc4x-hop-metadata/src/main/resources/org/apache/plc4x/hop/metadata/messages/messages_en_US.properties new file mode 100644 index 00000000000..6db5c3fea39 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-metadata/src/main/resources/org/apache/plc4x/hop/metadata/messages/messages_en_US.properties @@ -0,0 +1,22 @@ + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +Plc4x.Name=Sample Transform +Plc4x.Description=Sample Transform Description +Plc4x.Shell.Title=Sample Transform Title +Plc4x.TransformName.Label=Sample Name \ No newline at end of file diff --git a/plc4j/integrations/apache-hop/plc4x-hop-metadata/src/main/resources/plc4x_toddy.svg b/plc4j/integrations/apache-hop/plc4x-hop-metadata/src/main/resources/plc4x_toddy.svg new file mode 100644 index 00000000000..01694ecd5df --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-metadata/src/main/resources/plc4x_toddy.svg @@ -0,0 +1,1306 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/pom.xml b/plc4j/integrations/apache-hop/plc4x-hop-transformer/pom.xml new file mode 100644 index 00000000000..036b24df72c --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/pom.xml @@ -0,0 +1,169 @@ + + + + 4.0.0 + + org.apache.plc4x + plc4j-apache-hop + 0.11.0-SNAPSHOT + + + plc4x-hop-transform + jar + PLC4J: Integrations: Apache Hop: Transform + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + org.jboss.jandex + jandex-maven-plugin + 1.0.8 + + + make-index + + jandex + + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + io.netty:netty-common:jar:${netty.version} + io.netty:netty-all:jar:${netty.version} + commons-lang:commons-lang:jar:2.6 + xml-apis:xml-apis:jar:1.4.01 + org.apache.plc4x:plc4j-spi:jar:${project.version} + com.fasterxml.jackson.core:jackson-annotations:jar:${jackson.version} + com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:${jackson.version} + + + + + + + + + + org.apache.hop + hop-core + ${hop.version} + compile + + + * + * + + + + + org.apache.hop + hop-engine + ${hop.version} + + + * + * + + + + + org.apache.hop + hop-ui + ${hop.version} + + + * + * + + + + + io.netty + netty-all + ${netty.version} + + + ${project.groupId} + plc4j-api + ${project.version} + + + ${project.groupId} + plc4x-hop-metadata + ${project.version} + + + org.eclipse.platform + org.eclipse.swt.gtk.linux.x86_64 + 3.114.0 + + + ${project.groupId} + plc4j-driver-s7 + ${project.version} + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + com.fasterxml.jackson.core + jackson-annotations + ${jackson.version} + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson.version} + + + org.netbeans.api + org-openide-util-lookup + RELEASE170 + + + commons-codec + commons-codec + 1.15 + + + \ No newline at end of file diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xevent/Plc4xEvent.java b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xevent/Plc4xEvent.java new file mode 100644 index 00000000000..a4d7a8d5bde --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xevent/Plc4xEvent.java @@ -0,0 +1,545 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.plc4x.hop.transforms.plc4xevent; + +import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.locks.ReentrantLock; +import org.apache.hop.core.CheckResult; +import org.apache.hop.core.Const; +import org.apache.hop.core.ICheckResult; +import org.apache.hop.core.RowMetaAndData; +import org.apache.hop.core.exception.HopException; +import org.apache.hop.core.exception.HopPluginException; +import org.apache.hop.core.logging.LogLevel; +import org.apache.hop.core.row.IRowMeta; +import org.apache.hop.core.row.IValueMeta; +import org.apache.hop.core.row.RowDataUtil; +import org.apache.hop.core.row.RowMeta; +import org.apache.hop.core.row.value.ValueMetaFactory; +import org.apache.hop.core.util.StringUtil; +import org.apache.hop.i18n.BaseMessages; +import org.apache.hop.metadata.api.IHopMetadataProvider; +import org.apache.hop.pipeline.IExecutionStoppedListener; +import org.apache.hop.pipeline.Pipeline; +import org.apache.hop.pipeline.PipelineMeta; +import org.apache.hop.pipeline.engine.IPipelineEngine; +import org.apache.hop.pipeline.transform.BaseTransform; +import org.apache.hop.pipeline.transform.TransformMeta; +import org.apache.plc4x.hop.metadata.Plc4xConnection; +import org.apache.plc4x.hop.metadata.util.Plc4xLookup; +import org.apache.plc4x.hop.metadata.util.Plc4xWrapperConnection; +import org.apache.plc4x.java.DefaultPlcDriverManager; +import org.apache.plc4x.java.api.PlcConnection; +import org.apache.plc4x.java.api.listener.ConnectionStateListener; +import org.apache.plc4x.java.api.messages.PlcReadRequest; +import org.apache.plc4x.java.api.messages.PlcSubscriptionRequest; +import org.apache.plc4x.java.api.messages.PlcSubscriptionResponse; +import org.apache.plc4x.java.api.model.PlcConsumerRegistration; +import org.apache.plc4x.java.api.types.PlcResponseCode; +import org.apache.plc4x.java.s7.events.S7Event; +import org.apache.plc4x.java.s7.events.S7ModeEvent; +import org.apache.plc4x.java.s7.events.S7SysEvent; +import org.apache.plc4x.java.s7.events.S7UserEvent; +import org.openide.util.Lookup; + +/** + * This transform receives an event from the S7 driver, of type MODE, SYS, USR + * or ALM. Only one type can be processed at a time. + * + */ +public class Plc4xEvent extends BaseTransform implements ConnectionStateListener { + + public static String FIELD_MODE_EVENT = "MODE"; + public static String FIELD_USER_EVENT = "USR"; + public static String FIELD_SYS_EVENT = "SYS"; + public static String FIELD_ALARM_EVENT = "ALM"; + + private static final Class PKG = Plc4xEvent.class; // Needed by Translator + + private Plc4xConnection connmeta = null; + private Plc4xWrapperConnection connwrapper = null; + private PlcConsumerRegistration registerMode = null; + private PlcConsumerRegistration registerUser = null; + private PlcConsumerRegistration registerSys = null; + private PlcConsumerRegistration registerAlarm = null; + private PlcSubscriptionRequest subsRequest = null; + private PlcSubscriptionResponse subresponse = null; + + private List remarks = new ArrayList<>(); // stores the errors... + + private Plc4xLookup lookup = Plc4xLookup.getDefault(); + private Lookup.Template template = null; + private Lookup.Result result = null; + + + /* + * The transfer of events is done from the driver tasks. A delay can be added + * for the execution of this transformer. + */ + private ObjectMapper mapper = new ObjectMapper(); + private ConcurrentLinkedQueue events = new ConcurrentLinkedQueue(); + private boolean stopBundle = false; + private int index = 0; + + private static final ReentrantLock lock = new ReentrantLock(); + + private static final String dummy = "dummy"; + + public Plc4xEvent(TransformMeta transformMeta, Plc4xEventMeta meta, Plc4xEventData data, int copyNr, PipelineMeta pipelineMeta, + Pipeline pipeline) { + super(transformMeta, meta, data, copyNr, pipelineMeta, pipeline); + } + + /* + * Including Date and Time field for every row + * + * @param meta Meta data from user dialog + * @param remarks Error registers + * @param origin transform instance name + */ + public static final RowMetaAndData buildRow(Plc4xEventMeta meta, + List remarks, + String origin) throws HopPluginException { + + IRowMeta rowMeta = new RowMeta(); + Object[] rowData = RowDataUtil.allocateRowData(2); + int index = 0; + + ArrayList fields = new ArrayList(); + + if (meta.isModeEvent()) { + for (S7ModeEvent.Fields field : S7ModeEvent.Fields.values()) { + fields.add(field.name()); + } + } else if (meta.isSysEvent()) { + for (S7SysEvent.Fields field : S7SysEvent.Fields.values()) { + fields.add(field.name()); + } + } else if (meta.isUserEvent()) { + for (S7UserEvent.Fields field : S7UserEvent.Fields.values()) { + fields.add(field.name()); + } + } else if (meta.isAlarmEvent()) { + fields.add("ALARM"); + } + + for (String field : fields) { + IValueMeta valueMeta + = ValueMetaFactory.createValueMeta(field, IValueMeta.TYPE_STRING); // build a + rowData[index] = StringUtil.EMPTY_STRING; + // Now add value to the row! + // This is in fact a copy from the fields row, but now with data. + rowMeta.addValueMeta(valueMeta); + index++; + } + + return new RowMetaAndData(rowMeta, rowData); + } + + /* + * 1. Block the other instances by means of a lock. + * 2. Try to locate an existing connection. + * 3. If it doesn't exist, it tries to take control of the routine to + * create an instance of PlcConnection and his wrapper. + * 4. Register the connection wrapper for global access. + * 5. If the connection to the PLC is made, then it creates the query + * and executes it. + * + */ + @Override + public boolean processRow() throws HopException { + Object[] r = getRow(); // Get row from input rowset & set row busy! + setLogLevel(LogLevel.DEBUG); + + if ((!meta.isNeverEnding() && data.rowsWritten >= data.rowLimit) && !isStopped()) { + setOutputDone(); // signal end to receiver(s) + return false; + } + + // If we do not have the jobId, it is because we have not completed + // the CYC subscription. + if (null == subsRequest) { + RegisterPlcTags(); + GetSubscriptions(); + RegisterEventHandler(); + } + + if (!events.isEmpty()) { + S7Event s7event = events.poll(); + index = 0; + r = data.outputRowMeta.cloneRow(data.outputRowData); + for (String name : data.outputRowMeta.getFieldNames()) { + if (null != s7event.getMap().get(name)) { + if ("MAP".equals(name)) { + try { + r[index++] = mapper.writer() + .writeValueAsString(s7event.getMap()); + } catch (Exception ex) { + logError(ex.getMessage()); + } + } else { + r[index++] = s7event.getMap().get(name).toString(); + }; + } else { + try { + // r[index++] = mapper.writer() + // .writeValueAsString(s7event.getMap()); + r[index++] = null; + } catch (Exception ex) { + logError(ex.getMessage()); + } + } + } + + data.prevDate = data.rowDate; + data.rowDate = new Date(); + + putRow(data.outputRowMeta, r); // return your data + data.rowsWritten++; + } + + if (isStopped()) { + setStopped(true); + return false; + } + + return true; + } + + @Override + public boolean init() { + try { + if (super.init()) { + // Determine the number of rows to generate... + data.rowLimit = Const.toLong(resolve(meta.getRowLimit()), -1L); + + if (data.rowLimit < 0L) { // Unable to parse + logError(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Wrong.RowLimit.Number")); + return false; // fail + } + + // Create a row (constants) with all the values in it... + List remarks = new ArrayList<>(); // stores the errors... + RowMetaAndData outputRow = buildRow(meta, remarks, getTransformName()); + if (!remarks.isEmpty()) { + for (int i = 0; i < remarks.size(); i++) { + CheckResult cr = (CheckResult) remarks.get(i); + logError(cr.getText()); + } + return false; + } + + data.outputRowData = outputRow.getData(); + data.outputRowMeta = outputRow.getRowMeta(); + + mapper.findAndRegisterModules(); + + getPlcConnection(); + + return true; + } + + return false; + + } catch (Exception ex) { + setErrors(1L); + logError("Error initializing transform", ex); + return false; + } + } + + /* + * Here, must perform the cleaning of any resource, main of the connection to + * the associated PLC. + */ + @Override + public void cleanup() { + super.cleanup(); + logBasic("Cleanup. Release connection."); + if (null != connwrapper) { + if (null != registerMode) { + registerMode.unregister(); + } + if (null != registerUser) { + registerUser.unregister(); + } + if (null != registerSys) { + registerSys.unregister(); + } + if (null != registerAlarm) { + registerAlarm.unregister(); + } + connwrapper.release(); + if (connwrapper.refCnt() <= 0) { + lookup.remove(connwrapper); + } + } + } + + /* + * Here, must perform the cleaning of any resource. + * 1. Check if we have reference to wrapper. + * 2. Release de reference to object. + * 3. The lastone remove the global reference to connection wrapper. + * 4. Clear local references. + */ + @Override + public void dispose() { + super.dispose(); + if (null != registerMode) { + registerMode.unregister(); + } + if (null != registerUser) { + registerUser.unregister(); + } + if (null != registerSys) { + registerSys.unregister(); + } + if (null != registerAlarm) { + registerAlarm.unregister(); + } + + if (connwrapper != null) { + logBasic("Dispose. Release connection: " + connwrapper.refCnt()); + connwrapper.release(); + if (connwrapper.refCnt() <= 0) { + lookup.remove(connwrapper); + } + connwrapper = null; + subsRequest = null; + registerMode = null; + registerUser = null; + registerSys = null; + registerAlarm = null; + + } + } + + public void stopRunning() throws HopException { + super.stopRunning(); + stopBundle = true; + } + + private void getPlcConnection() { + lock.lock(); //(01) + try { + + IHopMetadataProvider metaprovider = getMetadataProvider(); + connmeta = metaprovider.getSerializer(Plc4xConnection.class).load(meta.getConnection()); + + if (connwrapper == null) { + template = new Lookup.Template<>(Plc4xWrapperConnection.class, meta.getConnection(), null); + result = lookup.lookup(template); + if (!result.allItems().isEmpty()) { + logBasic("Using connection: " + meta.getConnection()); + connwrapper = (Plc4xWrapperConnection) result.allInstances().toArray()[0]; + if (connwrapper != null) { + connwrapper.retain(); + } + } + }; + + if (connmeta == null) { + logError( + BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.Log.SetMetadata", + meta.getConnection())); + } + + if ((connmeta != null) && (connwrapper == null)) { + subsRequest = null; + try { + final PlcConnection conn = new DefaultPlcDriverManager().getConnection(connmeta.getUrl()); //(03) + Thread.sleep(200); + if (conn.isConnected()) { + logBasic("Create new connection with url : " + connmeta.getUrl()); + connwrapper = new Plc4xWrapperConnection(conn, meta.getConnection()); + lookup.add(connwrapper); + } + + } catch (Exception ex) { + setErrors(1L); + logError("Unable to create connection to PLC. " + ex.getMessage()); + } + } + + } catch (HopException ex) { + logError("Unable to create connection to PLC. " + ex.getMessage()); + } finally { + lock.unlock(); + } + } + + /* + * Registers the tags for the cyclical subscription. + * In the first processing of the rows, a check of the tags is + * carried out in order that they are well formed, generating an exception + * if they are not. + */ + public boolean RegisterPlcTags() { + if ((connmeta != null) && (connwrapper != null)) { + if (connwrapper.getConnection().isConnected()) { + if (subsRequest == null) { + final PlcSubscriptionRequest.Builder subscription = connwrapper.getConnection().subscriptionRequestBuilder(); //(05) + if (meta.isModeEvent()) { + subscription.addEventTagAddress(FIELD_MODE_EVENT, FIELD_MODE_EVENT); + } + if (meta.isUserEvent()) { + subscription.addEventTagAddress(FIELD_USER_EVENT, FIELD_USER_EVENT); + } + if (meta.isSysEvent()) { + subscription.addEventTagAddress(FIELD_SYS_EVENT, FIELD_SYS_EVENT); + } + if (meta.isAlarmEvent()) { + subscription.addEventTagAddress(FIELD_ALARM_EVENT, FIELD_ALARM_EVENT); + } + + subsRequest = subscription.build(); + + } + + } else { + setErrors(1L); + logError("PLC is not connected."); + setOutputDone(); + return false; + } + + } else { + setErrors(1L); + logError("PLC connection don't exist."); + setOutputDone(); + return false; + } + return true; + } + + /* + * This method performs the subscription to the events within the PLC. + * 1. Take the waiting time as a reference to monitor the request. + * 2. Captures the jobId associated with the subscription + * which is assigned by the PLC. + */ + public void GetSubscriptions() { + try { + subresponse = subsRequest.execute().get(); + } catch (Exception ex) { + setErrors(1L); + logError("Unable read from PLC. " + ex.getMessage()); + } + } + + /* + * Subscribe to incoming events by transferring them to + * the local event buffer. + */ + public void RegisterEventHandler() { + + if (meta.isModeEvent() && subresponse.getResponseCode(FIELD_MODE_EVENT) == PlcResponseCode.OK) { + registerMode + = subresponse + .getSubscriptionHandle(FIELD_MODE_EVENT) + .register(msg -> { + events.add((S7Event) msg); + }); + } + + if (meta.isUserEvent() && subresponse.getResponseCode(FIELD_USER_EVENT) == PlcResponseCode.OK) { + registerUser + = subresponse + .getSubscriptionHandle(FIELD_USER_EVENT) + .register(msg -> { + events.add((S7Event) msg); + }); + } + + if (meta.isSysEvent() && subresponse.getResponseCode(FIELD_SYS_EVENT) == PlcResponseCode.OK) { + registerSys + = subresponse + .getSubscriptionHandle(FIELD_SYS_EVENT) + .register(msg -> { + events.add((S7Event) msg); + }); + } + + if (meta.isAlarmEvent() && subresponse.getResponseCode(FIELD_ALARM_EVENT) == PlcResponseCode.OK) { + registerAlarm + = subresponse + .getSubscriptionHandle(FIELD_ALARM_EVENT) + .register(msg -> { + events.add((S7Event) msg); + }); + } + } + + /* + * Unsubscribes to the event generator from the driver. + * TODO: It remains to verify the unsubscription in line. + * At the moment only with the disconnection of the PLC. + */ + public void UnRegisterCYCHandler() { + if (null != registerMode) { + registerMode.unregister(); + } + if (null != registerUser) { + registerUser.unregister(); + } + if (null != registerSys) { + registerSys.unregister(); + } + if (null != registerAlarm) { + registerAlarm.unregister(); + } + registerMode = null; + registerUser = null; + registerSys = null; + registerAlarm = null; + subsRequest = null; + } + + /* + * When the driver makes a connection this method is called. + * In the case of the S7 driver, only the connection of the embedded channel + * is served. + */ + @Override + public void connected() { + if (connwrapper.getConnection().isConnected()) { + RegisterPlcTags(); + GetSubscriptions(); + RegisterEventHandler(); + } + } + + /* + * This method is called from the driver to indicate that it has + * disconnected from the PLC. + * If the PLC is disconnected, it automatically deletes all + * the status associated with this connection. + */ + @Override + public void disconnected() { + logError("Driver disconnected!"); + UnRegisterCYCHandler(); + } + +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xevent/Plc4xEventData.java b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xevent/Plc4xEventData.java new file mode 100644 index 00000000000..ebadf2111be --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xevent/Plc4xEventData.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.plc4x.hop.transforms.plc4xevent; + +import org.apache.plc4x.hop.transforms.plc4xoutput.*; +import org.apache.plc4x.hop.transforms.plc4xinput.*; +import java.util.Date; +import org.apache.hop.core.row.IRowMeta; +import org.apache.hop.pipeline.transform.BaseTransformData; +import org.apache.hop.pipeline.transform.ITransformData; + + +public class Plc4xEventData extends BaseTransformData implements ITransformData { + + //The Plc4xConnection metadata + public String connection; + + public IRowMeta outputRowMeta; + public Object[] outputRowData; + + public long rowLimit; + public long rowsWritten; + public Date rowDate; + public Date prevDate; + public long delay; + + + + /** + * Default constructor for SampleData. + */ + public Plc4xEventData() { + super(); + } +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xevent/Plc4xEventDialog.java b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xevent/Plc4xEventDialog.java new file mode 100644 index 00000000000..3d246028774 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xevent/Plc4xEventDialog.java @@ -0,0 +1,672 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.plc4x.hop.transforms.plc4xevent; + +import org.apache.hop.core.Const; +import org.apache.hop.core.exception.HopException; +import org.apache.hop.core.util.Utils; +import org.apache.hop.core.variables.IVariables; +import org.apache.hop.i18n.BaseMessages; +import org.apache.hop.pipeline.Pipeline; +import org.apache.hop.pipeline.PipelineMeta; +import org.apache.hop.pipeline.PipelinePreviewFactory; +import org.apache.hop.pipeline.transform.BaseTransformMeta; +import org.apache.hop.pipeline.transform.ITransformDialog; +import org.apache.hop.ui.core.ConstUi; +import org.apache.hop.ui.core.dialog.BaseDialog; +import org.apache.hop.ui.core.dialog.EnterNumberDialog; +import org.apache.hop.ui.core.dialog.EnterTextDialog; +import org.apache.hop.ui.core.dialog.ErrorDialog; +import org.apache.hop.ui.core.dialog.PreviewRowsDialog; +import org.apache.hop.ui.core.widget.MetaSelectionLine; +import org.apache.hop.ui.core.widget.TableView; +import org.apache.hop.ui.core.widget.TextVar; +import org.apache.hop.ui.pipeline.dialog.PipelinePreviewProgressDialog; +import org.apache.hop.ui.pipeline.transform.BaseTransformDialog; +import org.apache.hop.ui.util.SwtSvgImageUtil; +import org.apache.plc4x.hop.metadata.Plc4xConnection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.*; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +public class Plc4xEventDialog extends BaseTransformDialog implements ITransformDialog { + private static final Class PKG = Plc4xEventDialog.class; // Needed by Translator + + private MetaSelectionLine wConnection; + + private Label wlLimit; + private TextVar wLimit; + + private Button wNeverEnding; + + private Button wModeEvent; + private Button wUserEvent; + private Button wSysEvent; + private Button wAlarmEvent; + + private Label wlMaxwait; + private TextVar wMaxwait; + + private Label wlInterval; + private TextVar wInterval; + + private Label wlRowTimeField; + private TextVar wRowTimeField; + + private Label wlLastTimeField; + private TextVar wLastTimeField; + + private TableView wFields; + + private final Plc4xEventMeta input; + + public Plc4xEventDialog(Shell parent, IVariables variables , Object in, PipelineMeta pipelineMeta, String sname ) { + super( parent, variables, (BaseTransformMeta) in, pipelineMeta, sname ); + input = (Plc4xEventMeta) in; + } + + @Override + public String open() { + Shell parent = getParent(); + + shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN); + props.setLook(shell); + setShellImage(shell, input); + + ModifyListener lsMod = e -> input.setChanged(); + changed = input.hasChanged(); + + FormLayout formLayout = new FormLayout(); + formLayout.marginWidth = Const.FORM_MARGIN; + formLayout.marginHeight = Const.FORM_MARGIN; + + shell.setLayout(formLayout); + shell.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.DialogTitle")); + + int middle = props.getMiddlePct(); + int margin = props.getMargin(); + + // Filename line + wlTransformName = new Label(shell, SWT.RIGHT); + wlTransformName.setText(BaseMessages.getString(PKG, "System.Label.TransformName")); + props.setLook(wlTransformName); + fdlTransformName = new FormData(); + fdlTransformName.left = new FormAttachment(0, 0); + fdlTransformName.right = new FormAttachment(middle, -margin); + fdlTransformName.top = new FormAttachment(0, margin); + wlTransformName.setLayoutData(fdlTransformName); + + wTransformName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + wTransformName.setText(transformName); + props.setLook(wTransformName); + wTransformName.addModifyListener(lsMod); + fdTransformName = new FormData(); + fdTransformName.left = new FormAttachment(middle, 0); + fdTransformName.top = new FormAttachment(0, margin); + fdTransformName.right = new FormAttachment(100, 0); + wTransformName.setLayoutData(fdTransformName); + + // Connection line + wConnection = + new MetaSelectionLine<>( + variables, + metadataProvider, + Plc4xConnection.class, + shell, + SWT.NONE, + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Connection.Label"), + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Connection.Tooltip")); + FormData fdConnection = new FormData(); + fdConnection.left = new FormAttachment(0, 0); + fdConnection.right = new FormAttachment(100, 0); + fdConnection.top = new FormAttachment(wTransformName, margin); + wConnection.setLayoutData(fdConnection); + props.setLook(wConnection); + try { + wConnection.fillItems(); + } catch (Exception e) { + new ErrorDialog(shell, "Error", "Error listing Cassandra connection metadata objects", e); + } + + Control lastControl = wConnection; + + wlLimit = new Label(shell, SWT.RIGHT); + wlLimit.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Limit.Label")); + props.setLook(wlLimit); + FormData fdlLimit = new FormData(); + fdlLimit.left = new FormAttachment(0, 0); + fdlLimit.right = new FormAttachment(middle, -margin); + fdlLimit.top = new FormAttachment(lastControl, margin); + wlLimit.setLayoutData(fdlLimit); + wLimit = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wLimit); + wLimit.addModifyListener(lsMod); + FormData fdLimit = new FormData(); + fdLimit.left = new FormAttachment(middle, 0); + fdLimit.top = new FormAttachment(lastControl, margin); + fdLimit.right = new FormAttachment(100, 0); + wLimit.setLayoutData(fdLimit); + lastControl = wLimit; + + /******************** + * Never Ending + ********************/ + Label wlNeverEnding = new Label(shell, SWT.RIGHT); + wlNeverEnding.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.NeverEnding.Label")); + props.setLook(wlNeverEnding); + FormData fdlNeverEnding = new FormData(); + fdlNeverEnding.left = new FormAttachment(0, 0); + fdlNeverEnding.right = new FormAttachment(middle, -margin); + fdlNeverEnding.top = new FormAttachment(lastControl, margin); + wlNeverEnding.setLayoutData(fdlNeverEnding); + wNeverEnding = new Button(shell, SWT.CHECK); + props.setLook(wNeverEnding); + wNeverEnding.addSelectionListener( + new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + setActive(); + input.setChanged(); + } + }); + + FormData fdNeverEnding = new FormData(); + fdNeverEnding.left = new FormAttachment(middle, 0); + fdNeverEnding.top = new FormAttachment(wlNeverEnding, 0, SWT.CENTER); + fdNeverEnding.right = new FormAttachment(100, 0); + wNeverEnding.setLayoutData(fdNeverEnding); + lastControl = wlNeverEnding; + + /******************** + * Mode Events + ********************/ + Label wlModeEvent = new Label(shell, SWT.RIGHT); + wlModeEvent.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.ModeEvent.Label")); + props.setLook(wlModeEvent); + FormData fdlModeEvent = new FormData(); + fdlModeEvent.left = new FormAttachment(0, 0); + fdlModeEvent.right = new FormAttachment(middle, -margin); + fdlModeEvent.top = new FormAttachment(lastControl, margin); + wlModeEvent.setLayoutData(fdlModeEvent); + wModeEvent = new Button(shell, SWT.CHECK); + props.setLook(wModeEvent); + wModeEvent.addSelectionListener( + new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + setActive(); + input.setChanged(); + } + }); + + FormData fdModeEvent = new FormData(); + fdModeEvent.left = new FormAttachment(middle, 0); + fdModeEvent.top = new FormAttachment(wlModeEvent, 0, SWT.CENTER); + fdModeEvent.right = new FormAttachment(100, 0); + wModeEvent.setLayoutData(fdModeEvent); + lastControl = wlModeEvent; + + /******************** + * User Events + ********************/ + Label wlUserEvent = new Label(shell, SWT.RIGHT); + wlUserEvent.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.UserEvent.Label")); + props.setLook(wlUserEvent); + FormData fdlUserEvent = new FormData(); + fdlUserEvent.left = new FormAttachment(0, 0); + fdlUserEvent.right = new FormAttachment(middle, -margin); + fdlUserEvent.top = new FormAttachment(lastControl, margin); + wlUserEvent.setLayoutData(fdlUserEvent); + wUserEvent = new Button(shell, SWT.CHECK); + props.setLook(wUserEvent); + wUserEvent.addSelectionListener( + new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + setActive(); + input.setChanged(); + } + }); + + FormData fdUserEvent = new FormData(); + fdUserEvent.left = new FormAttachment(middle, 0); + fdUserEvent.top = new FormAttachment(wlUserEvent, 0, SWT.CENTER); + fdUserEvent.right = new FormAttachment(100, 0); + wUserEvent.setLayoutData(fdUserEvent); + lastControl = wlUserEvent; + + /******************** + * Sys Events + ********************/ + Label wlSysEvent = new Label(shell, SWT.RIGHT); + wlSysEvent.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.SysEvent.Label")); + props.setLook(wlSysEvent); + FormData fdlSysEvent = new FormData(); + fdlSysEvent.left = new FormAttachment(0, 0); + fdlSysEvent.right = new FormAttachment(middle, -margin); + fdlSysEvent.top = new FormAttachment(lastControl, margin); + wlSysEvent.setLayoutData(fdlSysEvent); + wSysEvent = new Button(shell, SWT.CHECK); + props.setLook(wSysEvent); + wSysEvent.addSelectionListener( + new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + setActive(); + input.setChanged(); + } + }); + + FormData fdSysEvent = new FormData(); + fdSysEvent.left = new FormAttachment(middle, 0); + fdSysEvent.top = new FormAttachment(wlSysEvent, 0, SWT.CENTER); + fdSysEvent.right = new FormAttachment(100, 0); + wSysEvent.setLayoutData(fdSysEvent); + lastControl = wlSysEvent; + + /******************** + * Alarm Events + ********************/ + Label wlAlarmEvent = new Label(shell, SWT.RIGHT); + wlAlarmEvent.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.AlarmEvent.Label")); + props.setLook(wlAlarmEvent); + FormData fdlAlarmEvent = new FormData(); + fdlAlarmEvent.left = new FormAttachment(0, 0); + fdlAlarmEvent.right = new FormAttachment(middle, -margin); + fdlAlarmEvent.top = new FormAttachment(lastControl, margin); + wlAlarmEvent.setLayoutData(fdlAlarmEvent); + wAlarmEvent = new Button(shell, SWT.CHECK); + props.setLook(wAlarmEvent); + wAlarmEvent.addSelectionListener( + new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + setActive(); + input.setChanged(); + } + }); + + FormData fdAlarmEvent = new FormData(); + fdAlarmEvent.left = new FormAttachment(middle, 0); + fdAlarmEvent.top = new FormAttachment(wlAlarmEvent, 0, SWT.CENTER); + fdAlarmEvent.right = new FormAttachment(100, 0); + wAlarmEvent.setLayoutData(fdAlarmEvent); + lastControl = wlAlarmEvent; + + + wOk = new Button(shell, SWT.PUSH); + wOk.setText(BaseMessages.getString(PKG, "System.Button.OK")); + wOk.addListener(SWT.Selection, e -> ok()); + + wCancel = new Button(shell, SWT.PUSH); + wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); + wCancel.addListener(SWT.Selection, e -> cancel()); + + setButtonPositions(new Button[] {wOk, wCancel}, margin, null); + + /* + + wlMaxwait = new Label(shell, SWT.RIGHT); + wlMaxwait.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Maxwait.Label")); + props.setLook(wlMaxwait); + FormData fdlMaxwait = new FormData(); + fdlMaxwait.left = new FormAttachment(0, 0); + fdlMaxwait.right = new FormAttachment(middle, -margin); + fdlMaxwait.top = new FormAttachment(lastControl, margin); + wlMaxwait.setLayoutData(fdlMaxwait); + wMaxwait = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wMaxwait); + wMaxwait.addModifyListener(lsMod); + FormData fdMaxwait = new FormData(); + fdMaxwait.left = new FormAttachment(middle, 0); + fdMaxwait.top = new FormAttachment(lastControl, margin); + fdMaxwait.right = new FormAttachment(100, 0); + wMaxwait.setLayoutData(fdMaxwait); + lastControl = wMaxwait; + + wlInterval = new Label(shell, SWT.RIGHT); + wlInterval.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Interval.Label")); + props.setLook(wlInterval); + FormData fdlInterval = new FormData(); + fdlInterval.left = new FormAttachment(0, 0); + fdlInterval.right = new FormAttachment(middle, -margin); + fdlInterval.top = new FormAttachment(lastControl, margin); + wlInterval.setLayoutData(fdlInterval); + wInterval = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wInterval); + wInterval.addModifyListener(lsMod); + FormData fdInterval = new FormData(); + fdInterval.left = new FormAttachment(middle, 0); + fdInterval.top = new FormAttachment(lastControl, margin); + fdInterval.right = new FormAttachment(100, 0); + wInterval.setLayoutData(fdInterval); + lastControl = wInterval; + + + wlRowTimeField = new Label(shell, SWT.RIGHT); + wlRowTimeField.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.RowTimeField.Label")); + props.setLook(wlRowTimeField); + FormData fdlRowTimeField = new FormData(); + fdlRowTimeField.left = new FormAttachment(0, 0); + fdlRowTimeField.right = new FormAttachment(middle, -margin); + fdlRowTimeField.top = new FormAttachment(lastControl, margin); + wlRowTimeField.setLayoutData(fdlRowTimeField); + wRowTimeField = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wRowTimeField); + wRowTimeField.addModifyListener(lsMod); + FormData fdRowTimeField = new FormData(); + fdRowTimeField.left = new FormAttachment(middle, 0); + fdRowTimeField.top = new FormAttachment(lastControl, margin); + fdRowTimeField.right = new FormAttachment(100, 0); + wRowTimeField.setLayoutData(fdRowTimeField); + lastControl = wRowTimeField; + + wlLastTimeField = new Label(shell, SWT.RIGHT); + wlLastTimeField.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.LastTimeField.Label")); + props.setLook(wlLastTimeField); + FormData fdlLastTimeField = new FormData(); + fdlLastTimeField.left = new FormAttachment(0, 0); + fdlLastTimeField.right = new FormAttachment(middle, -margin); + fdlLastTimeField.top = new FormAttachment(lastControl, margin); + wlLastTimeField.setLayoutData(fdlLastTimeField); + wLastTimeField = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wLastTimeField); + wLastTimeField.addModifyListener(lsMod); + FormData fdLastTimeField = new FormData(); + fdLastTimeField.left = new FormAttachment(middle, 0); + fdLastTimeField.top = new FormAttachment(lastControl, margin); + fdLastTimeField.right = new FormAttachment(100, 0); + wLastTimeField.setLayoutData(fdLastTimeField); + lastControl = wLastTimeField; + + wOk = new Button(shell, SWT.PUSH); + wOk.setText(BaseMessages.getString(PKG, "System.Button.OK")); + wOk.addListener(SWT.Selection, e -> ok()); + wPreview = new Button(shell, SWT.PUSH); + wPreview.setText(BaseMessages.getString(PKG, "System.Button.Preview")); + wPreview.addListener(SWT.Selection, e -> preview()); + wCancel = new Button(shell, SWT.PUSH); + wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); + wCancel.addListener(SWT.Selection, e -> cancel()); + + setButtonPositions(new Button[] {wOk, wPreview, wCancel}, margin, null); + + Label wlFields = new Label(shell, SWT.NONE); + wlFields.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Fields.Label")); + props.setLook(wlFields); + FormData fdlFields = new FormData(); + fdlFields.left = new FormAttachment(0, 0); + fdlFields.top = new FormAttachment(lastControl, margin); + wlFields.setLayoutData(fdlFields); + lastControl = wlFields; + + final int nrFields = input.getFields().size(); + + ColumnInfo[] colinf = + new ColumnInfo[] { + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Name"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Fields.Item"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Type"), + ColumnInfo.COLUMN_TYPE_CCOMBO, + ValueMetaFactory.getValueMetaNames()), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Format"), + ColumnInfo.COLUMN_TYPE_FORMAT, + 2), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Length"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Precision"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Currency"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Decimal"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Group"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Value"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.SetEmptyString"), + ColumnInfo.COLUMN_TYPE_CCOMBO, + new String[] { + BaseMessages.getString(PKG, "System.Combo.Yes"), + BaseMessages.getString(PKG, "System.Combo.No") + }) + }; + + wFields = + new TableView( + variables, + shell, + SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, + colinf, + nrFields, + lsMod, + props); + + FormData fdFields = new FormData(); + fdFields.left = new FormAttachment(0, 0); + fdFields.top = new FormAttachment(lastControl, margin); + fdFields.right = new FormAttachment(100, 0); + fdFields.bottom = new FormAttachment(wOk, -2 * margin); + wFields.setLayoutData(fdFields); + + lsResize = + event -> { + Point size = shell.getSize(); + wFields.setSize(size.x - 10, size.y - 50); + wFields.table.setSize(size.x - 10, size.y - 50); + wFields.redraw(); + }; + */ + + //shell.addListener(SWT.Resize, lsResize); + + getData(); + input.setChanged(changed); + + BaseDialog.defaultShellHandling(shell, c -> ok(), c -> cancel()); + + return transformName; + }; + + + public void setActive() { + boolean neverEnding = wNeverEnding.getSelection(); + + wlLimit.setEnabled(!neverEnding); + wLimit.setEnabled(!neverEnding); + } + + + + private Image getImage() { + return SwtSvgImageUtil.getImage( shell.getDisplay(), getClass().getClassLoader(), "plc4x_toddy_read.svg", ConstUi.LARGE_ICON_SIZE, + ConstUi.LARGE_ICON_SIZE ); + } + + /** + * Copy information from the meta-data input to the dialog fields. + * + */ + public void getData() { + if (isDebug()) { + logDebug("getting fields info..."); + } + if (input.getConnection() == null) { + wConnection.setText(""); + } else { + wConnection.setText(input.getConnection()); + } + + wLimit.setText(input.getRowLimit()); + wNeverEnding.setSelection(input.isNeverEnding()); + + wModeEvent.setSelection(input.isModeEvent()); + wUserEvent.setSelection(input.isUserEvent()); + wSysEvent.setSelection(input.isSysEvent()); + wAlarmEvent.setSelection(input.isAlarmEvent()); + + setActive(); + + wTransformName.selectAll(); + wTransformName.setFocus(); + } + + /** + * Stores the information from the dialog box in meta-data. + * + * @param meta + */ + private void getInfo( Plc4xEventMeta meta) throws HopException { + meta.setConnection(wConnection.getText()); + meta.setRowLimit(wLimit.getText()); + meta.setNeverEnding(wNeverEnding.getSelection()); + + meta.setModeEvent(wModeEvent.getSelection()); + meta.setUserEvent(wUserEvent.getSelection()); + meta.setSysEvent(wSysEvent.getSelection()); + meta.setAlarmEvent(wAlarmEvent.getSelection()); + + } + + /** + * Cancel the dialog. + */ + private void cancel() { + transformName = null; + input.setChanged( changed ); + dispose(); + } + + private void ok() { + if (Utils.isEmpty(wTransformName.getText())) { + return; + } + + transformName = wTransformName.getText(); // return value + try { + getInfo(new Plc4xEventMeta()); // to see if there is an exception + getInfo(input); // to put the content on the input structure for real if all is well. + dispose(); + } catch (HopException e) { + new ErrorDialog( + shell, + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Title"), + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Message"), + e); + } + } + + + /** + * Preview the data generated by this transform. This generates a pipeline using this transform & + * a dummy and previews it. + */ + private void preview() { + Plc4xEventMeta oneMeta = new Plc4xEventMeta(); + try { + getInfo(oneMeta); + } catch (HopException e) { + new ErrorDialog( + shell, + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Title"), + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Message"), + e); + return; + } + + PipelineMeta previewMeta = + PipelinePreviewFactory.generatePreviewPipeline( + pipelineMeta.getMetadataProvider(), oneMeta, wTransformName.getText()); + + EnterNumberDialog numberDialog = + new EnterNumberDialog( + shell, + props.getDefaultPreviewSize(), + BaseMessages.getString(PKG, "System.Dialog.EnterPreviewSize.Title"), + BaseMessages.getString(PKG, "System.Dialog.EnterPreviewSize.Message")); + int previewSize = numberDialog.open(); + if (previewSize > 0) { + PipelinePreviewProgressDialog progressDialog = + new PipelinePreviewProgressDialog( + shell, + variables, + previewMeta, + new String[] {wTransformName.getText()}, + new int[] {previewSize}); + progressDialog.open(); + + Pipeline pipeline = progressDialog.getPipeline(); + String loggingText = progressDialog.getLoggingText(); + + if (!progressDialog.isCancelled()) { + if (pipeline.getResult() != null && pipeline.getResult().getNrErrors() > 0) { + EnterTextDialog etd = + new EnterTextDialog( + shell, + BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), + BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), + loggingText, + true); + etd.setReadOnly(); + etd.open(); + } + } + + PreviewRowsDialog prd = + new PreviewRowsDialog( + shell, + variables, + SWT.NONE, + wTransformName.getText(), + progressDialog.getPreviewRowsMeta(wTransformName.getText()), + progressDialog.getPreviewRows(wTransformName.getText()), + loggingText); + prd.open(); + } + } + +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xevent/Plc4xEventMeta.java b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xevent/Plc4xEventMeta.java new file mode 100644 index 00000000000..10de092241d --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xevent/Plc4xEventMeta.java @@ -0,0 +1,239 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.plc4x.hop.transforms.plc4xevent; + +import java.util.ArrayList; +import org.apache.hop.core.ICheckResult; +import org.apache.hop.core.annotations.Transform; +import org.apache.hop.core.exception.HopTransformException; +import org.apache.hop.core.row.IRowMeta; +import org.apache.hop.core.variables.IVariables; +import org.apache.hop.metadata.api.IHopMetadataProvider; +import org.apache.hop.pipeline.Pipeline; +import org.apache.hop.pipeline.PipelineMeta; +import org.apache.hop.pipeline.transform.BaseTransformMeta; +import org.apache.hop.pipeline.transform.ITransformMeta; +import org.apache.hop.pipeline.transform.TransformMeta; + +import java.util.List; +import org.apache.hop.core.Const; +import org.apache.hop.core.RowMetaAndData; +import org.apache.hop.core.row.IValueMeta; +import org.apache.hop.metadata.api.HopMetadataProperty; +import org.apache.hop.pipeline.transform.ITransformIOMeta; +import org.apache.hop.pipeline.transform.TransformIOMeta; + +/** + * Meta data for the sample transform. + */ +@Transform( + id = "plc4x-event", + name = "i18n::Plc4x.Read.Name", + description = "i18n::Plc4x.Read.Description", + image = "plc4x_event.svg", + categoryDescription = "i18n:org.apache.plc4x.hop.transforms.plc4xevent:Plc4x.Category.plc4x", + documentationUrl = "https://plc4x.apache.org/users/integrations/apache-hop.html" +) +public class Plc4xEventMeta extends BaseTransformMeta { + + private static final Class PKG = Plc4xEventMeta.class; // Needed by Translator + + + @HopMetadataProperty( + key = "connection", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.Connection") + private String connection; + + @HopMetadataProperty( + key = "limit", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.RowLimit") + private String rowLimit; + + @HopMetadataProperty( + key = "never_ending", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.NeverEnding") + private boolean neverEnding; + + @HopMetadataProperty( + key = "mode_event", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.ModeEvent") + private boolean modeEvent; + + @HopMetadataProperty( + key = "user_event", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.UserEvent") + private boolean userEvent; + + @HopMetadataProperty( + key = "sys_event", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.SysEvent") + private boolean sysEvent; + + @HopMetadataProperty( + key = "alarm_event", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.AlarmEvent") + private boolean alarmEvent; + + + public Plc4xEventMeta() { + rowLimit = "10"; + neverEnding = false; + modeEvent = false; + userEvent = false; + sysEvent = false; + alarmEvent = false; + + } + + public Plc4xEventMeta(Plc4xEventMeta m) { + this.connection = m.connection; + this.neverEnding = m.neverEnding; + this.modeEvent = m.modeEvent; + this.userEvent = m.userEvent; + this.sysEvent = m.sysEvent; + this.alarmEvent = m.alarmEvent; + } + + @Override + public Plc4xEventMeta clone() { + return new Plc4xEventMeta(this); + } + + + + @Override + public void getFields( IRowMeta inputRowMeta, String name, IRowMeta[] info, TransformMeta nextTransform, + IVariables variables, IHopMetadataProvider metadataProvider ) throws HopTransformException { + try { + List remarks = new ArrayList<>(); + RowMetaAndData rowMetaAndData = Plc4xEvent.buildRow(this, remarks, name); + if (!remarks.isEmpty()) { + StringBuilder stringRemarks = new StringBuilder(); + for (ICheckResult remark : remarks) { + stringRemarks.append(remark.toString()).append(Const.CR); + } + throw new HopTransformException(stringRemarks.toString()); + } + for (IValueMeta valueMeta : rowMetaAndData.getRowMeta().getValueMetaList()) { + valueMeta.setOrigin(name); + } + inputRowMeta.mergeRowMeta(rowMetaAndData.getRowMeta()); + } catch (Exception e) { + throw new HopTransformException(e); + } + } + + public Plc4xEvent createTransform(TransformMeta transformMeta, Plc4xEventData data, int copyNr, + PipelineMeta pipelineMeta, Pipeline pipeline ) { + return new Plc4xEvent( transformMeta, this, data, copyNr, pipelineMeta, pipeline ); + } + + /** + * + * @return + */ + public Plc4xEventData getTransformData() { + return new Plc4xEventData(); + } + + @Override + public void setDefault() { + //default values when creating a new transform + } + + + /** + * Returns the Input/Output metadata for this transform. + * The generator transform only produces output, does not accept input! + * TransformIOMeta(inputAcceptor, outputProducer, inputOptional, outputDynamic, inputDynamic) + */ + @Override + public ITransformIOMeta getTransformIOMeta() { + return new TransformIOMeta(false, true, false, false, false, false); + } + + /** + * Gets Plc4xConnection metadata name. + * + * @return value of intervalInMs + */ + public String getConnection() { + return connection; + } + + /** @param connection */ + public void setConnection(String connection) { + this.connection = connection; + } + + public String getRowLimit() { + return rowLimit; + } + + /** @param connection */ + public void setRowLimit(String rowLimit) { + this.rowLimit = rowLimit; + } + + /** + * Gets neverEnding + * + * @return value of neverEnding + */ + public boolean isNeverEnding() { + return neverEnding; + } + + /** @param neverEnding The neverEnding to set */ + public void setNeverEnding(boolean neverEnding) { + this.neverEnding = neverEnding; + } + + public boolean isModeEvent() { + return modeEvent; + } + + public void setModeEvent(boolean modeEvent) { + this.modeEvent = modeEvent; + } + + public boolean isUserEvent() { + return userEvent; + } + + public void setUserEvent(boolean userEvent) { + this.userEvent = userEvent; + } + + public boolean isSysEvent() { + return sysEvent; + } + + public void setSysEvent(boolean sysEvent) { + this.sysEvent = sysEvent; + } + + public boolean isAlarmEvent() { + return alarmEvent; + } + + public void setAlarmEvent(boolean alarmEvent) { + this.alarmEvent = alarmEvent; + } + +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xinput/Plc4xRead.java b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xinput/Plc4xRead.java new file mode 100644 index 00000000000..308049167af --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xinput/Plc4xRead.java @@ -0,0 +1,950 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.plc4x.hop.transforms.plc4xinput; + +import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.ReentrantLock; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.stream.Collectors; +import org.apache.commons.codec.binary.BinaryCodec; +import org.apache.commons.lang3.StringUtils; +import org.apache.hop.core.CheckResult; +import org.apache.hop.core.Const; +import org.apache.hop.core.ICheckResult; +import org.apache.hop.core.RowMetaAndData; +import org.apache.hop.core.exception.HopException; +import org.apache.hop.core.exception.HopPluginException; +import org.apache.hop.core.exception.HopTransformException; +import org.apache.hop.core.exception.HopValueException; +import org.apache.hop.core.logging.LogLevel; +import org.apache.hop.core.row.IRowMeta; +import org.apache.hop.core.row.IValueMeta; +import org.apache.hop.core.row.RowDataUtil; +import org.apache.hop.core.row.RowMeta; +import org.apache.hop.core.row.value.ValueMetaDate; +import org.apache.hop.core.row.value.ValueMetaFactory; +import org.apache.hop.core.util.StringUtil; +import org.apache.hop.core.util.Utils; +import org.apache.hop.i18n.BaseMessages; +import org.apache.hop.metadata.api.IHopMetadataProvider; +import org.apache.hop.pipeline.Pipeline; +import org.apache.hop.pipeline.PipelineMeta; +import org.apache.hop.pipeline.transform.BaseTransform; +import org.apache.hop.pipeline.transform.TransformMeta; +import org.apache.plc4x.hop.metadata.Plc4xConnection; +import org.apache.plc4x.hop.metadata.util.Plc4xLookup; +import org.apache.plc4x.hop.transforms.util.Plc4xGeneratorField; +import org.apache.plc4x.hop.transforms.util.Plc4xPlcTag; +import org.apache.plc4x.hop.metadata.util.Plc4xWrapperConnection; +import org.apache.plc4x.hop.transforms.util.Plc4xDataType; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.BYTE; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.DATE; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.DATE_AND_TIME; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.DINT; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.DWORD; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.INT; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.LDATE; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.LDATE_AND_TIME; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.LINT; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.LREAL; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.LTIME; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.LTIME_OF_DAY; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.LWORD; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.REAL; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.SINT; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.TIME; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.TIME_OF_DAY; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.UDINT; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.UINT; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.ULINT; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.USINT; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.WORD; +import org.apache.plc4x.java.DefaultPlcDriverManager; +import org.apache.plc4x.java.api.PlcConnection; +import org.apache.plc4x.java.api.messages.PlcReadRequest; +import org.apache.plc4x.java.api.messages.PlcReadResponse; +import org.apache.plc4x.java.api.types.PlcResponseCode; +import org.openide.util.Lookup; + +/** + * + * + */ +public class Plc4xRead extends BaseTransform { + + private static final Class PKG = Plc4xRead.class; // Needed by Translator + + private Object[] r = null; + + private Plc4xConnection connmeta = null; + private Plc4xWrapperConnection connwrapper = null; + private PlcReadRequest.Builder builder = null; + private PlcReadRequest readRequest = null; + private PlcReadResponse readResponse = null; + + private Plc4xLookup lookup = Plc4xLookup.getDefault(); + private Lookup.Template template = null; + private Lookup.Result result = null; + + private BinaryCodec binarycodec = new BinaryCodec(); + + private int maxwait = 0; + private int counter = 0; + private int intField = 0; + private String strField = null; + + private static final ReentrantLock lock = new ReentrantLock(); + + private static final String dummy = "dummy"; + + private Map index = new HashMap(); + private Map plctags = new HashMap(); + private Plc4xDataType valuetype = null; + + private ObjectMapper mapper = new ObjectMapper(); + + public Plc4xRead(TransformMeta transformMeta, Plc4xReadMeta meta, Plc4xReadData data, int copyNr, PipelineMeta pipelineMeta, + Pipeline pipeline) { + super(transformMeta, meta, data, copyNr, pipelineMeta, pipeline); + } + + /* + * Including Date and Time field for every row + * + * @param meta Meta data from user dialog + * @param remarks Error registers + * @param origin transform instance name + */ + public static final RowMetaAndData buildRow(Plc4xReadMeta meta, + List remarks, + String origin) throws HopPluginException { + + IRowMeta rowMeta = new RowMeta(); + Object[] rowData = RowDataUtil.allocateRowData(meta.getFields().size() + 2); + int index = 0; + + if (!Utils.isEmpty(meta.getRowTimeField())) { + rowMeta.addValueMeta(new ValueMetaDate(meta.getRowTimeField())); + rowData[index++] = null; + } + + if (!Utils.isEmpty(meta.getLastTimeField())) { + rowMeta.addValueMeta(new ValueMetaDate(meta.getLastTimeField())); + rowData[index++] = null; + } + + for (Plc4xGeneratorField field : meta.getFields()) { + int typeString = ValueMetaFactory.getIdForValueMeta(field.getType()); + if (StringUtils.isNotEmpty(field.getType())) { + + IValueMeta valueMeta + = ValueMetaFactory.createValueMeta(field.getName(), typeString); // build a + // value! + valueMeta.setLength(field.getLength()); + valueMeta.setPrecision(field.getPrecision()); + valueMeta.setConversionMask(field.getFormat()); + valueMeta.setCurrencySymbol(field.getCurrency()); + valueMeta.setGroupingSymbol(field.getGroup()); + valueMeta.setDecimalSymbol(field.getDecimal()); + valueMeta.setOrigin(origin); + + IValueMeta stringMeta = ValueMetaFactory.cloneValueMeta(valueMeta, IValueMeta.TYPE_STRING); + + if (field.isSetEmptyString()) { + // Set empty string + rowData[index] = StringUtil.EMPTY_STRING; + } else { + String stringValue = field.getValue(); + + // If the value is empty: consider it to be NULL. + if (Utils.isEmpty(stringValue)) { + rowData[index] = null; + + if (valueMeta.getType() == IValueMeta.TYPE_NONE) { + String message + = BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.CheckResult.SpecifyTypeError", + valueMeta.getName(), + stringValue); + remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, null)); + } + } else { + // Convert the data from String to the specified type ... + // + try { +// System.out.println("stringValue: " + stringValue); + rowData[index] = valueMeta.convertData(stringMeta, stringValue); + } catch (HopValueException e) { + switch (valueMeta.getType()) { + case IValueMeta.TYPE_NUMBER: + String message + = BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.BuildRow.Error.Parsing.Number", + valueMeta.getName(), + stringValue, + e.toString()); + remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, null)); + break; + + case IValueMeta.TYPE_DATE: + message + = BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.BuildRow.Error.Parsing.Date", + valueMeta.getName(), + stringValue, + e.toString()); + remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, null)); + break; + + case IValueMeta.TYPE_INTEGER: + message + = BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.BuildRow.Error.Parsing.Integer", + valueMeta.getName(), + stringValue, + e.toString()); + remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, null)); + break; + + case IValueMeta.TYPE_BIGNUMBER: + message + = BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.BuildRow.Error.Parsing.BigNumber", + valueMeta.getName(), + stringValue, + e.toString()); + remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, null)); + break; + + case IValueMeta.TYPE_TIMESTAMP: + message + = BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.BuildRow.Error.Parsing.Timestamp", + valueMeta.getName(), + stringValue, + e.toString()); + remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, null)); + break; + + default: + // Boolean and binary don't throw errors normally, so it's probably an unspecified + // error problem... + message + = BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.CheckResult.SpecifyTypeError", + valueMeta.getName(), + stringValue); + remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, null)); + break; + } + } + } + } + + // Now add value to the row! + // This is in fact a copy from the fields row, but now with data. + rowMeta.addValueMeta(valueMeta); + index++; + } + } + + return new RowMetaAndData(rowMeta, rowData); + } + + /* + * 1. Block the other instances by means of a lock. + * 2. Try to locate an existing connection. + * 3. If it doesn't exist, it tries to take control of the routine to + * create an instance of PlcConnection and his wrapper. + * 4. Register the connection wrapper for global access. + * 5. If the connection to the PLC is made, then it creates the query + * and executes it. + * TODO: Field validation. + */ + @Override + public boolean processRow() throws HopException { + + r = getRow(); // Get row from input rowset & set row busy! + setLogLevel(LogLevel.DEBUG); + + if ((!meta.isNeverEnding() && data.rowsWritten >= data.rowLimit) && !isStopped()) { + setOutputDone(); // signal end to receiver(s) + return false; + } + + if (first) { + index.clear(); + plctags.clear(); + //This performs a minimal check on the user item. + //It guarantees that the rates are within those managed by Plc4x. + meta.getFields().forEach((f) -> { + if (null == r) { + plctags.put(f.getName(), Plc4xPlcTag.of(f.getItem())); + } else { + intField = getInputRowMeta().indexOfValue(f.getItem()); + if (intField != -1) { + strField = r[intField].toString(); + plctags.put(f.getName(), Plc4xPlcTag.of(strField)); + } else { + plctags.put(f.getName(), Plc4xPlcTag.of(f.getItem())); + } + } + }); + first = false; + } + + //In case of any problem I end the processing of the row. + if (!RegisterPlcTags()) { + return false; + } + if (!GetReads()) { + return false; + } + // + int interval = Integer.parseInt(meta.getIntervalInMs()); + + try { + Thread.sleep(interval); + } catch (InterruptedException ex) { + setErrors(1L); + logError(ex.getMessage()); + } + + r = data.outputRowMeta.cloneRow(data.outputRowData); + + data.prevDate = data.rowDate; + data.rowDate = new Date(); + int index = 0; + + if (!Utils.isEmpty(meta.getRowTimeField())) { + r[index++] = data.rowDate; + } + + if (!Utils.isEmpty(meta.getLastTimeField())) { + r[index++] = data.prevDate; + } + + for (Plc4xGeneratorField field : meta.getFields()) { + try { + valuetype = plctags.get(field.getName()).getDataType(); + + if (field.getType().equalsIgnoreCase("Avro Record")) { + throw new HopException("'Avro Record' type is not supported"); + } else if (field.getType().equalsIgnoreCase("BigNumber")) { + throw new HopException("'BigNumber' type is not supported"); + } else if (field.getType().equalsIgnoreCase("Binary")) { + switch (valuetype) { + case BYTE: + r[index++] = binarycodec.toByteArray( + Long.toBinaryString(readResponse.getByte(field.getName()))); + break; + case WORD: + r[index++] = binarycodec.toByteArray( + Long.toBinaryString(readResponse.getShort(field.getName()))); + break; + case DWORD: + r[index++] = binarycodec.toByteArray( + Integer.toBinaryString(readResponse.getInteger(field.getName()))); + break; + case LWORD: + r[index++] = binarycodec.toByteArray( + Long.toBinaryString(readResponse.getLong(field.getName()))); + break; + default: + throw new HopException("Tag type is not supported. Check tag definition."); + } + + } else if (field.getType().equalsIgnoreCase("Boolean")) { + switch (valuetype) { + case BOOL: + r[index++] = readResponse.getBoolean(field.getName()); + break; + default: + } + } else if (field.getType().equalsIgnoreCase("Date")) { + switch (valuetype) { + case DATE:; + case LDATE: + r[index++] = readResponse.getDate(field.getName()); + break; + case DATE_AND_TIME:; + case LDATE_AND_TIME: + r[index++] = readResponse.getDateTime(field.getName()); + break; + default: + throw new HopException("'Date' type is not supported"); + } + } else if (field.getType().equalsIgnoreCase("Graph")) { + throw new HopException("'Graph' type is not supported"); + } else if (field.getType().equalsIgnoreCase("Integer")) { + switch (valuetype) { + case BYTE: + r[index++] = Long.valueOf(readResponse.getByte(field.getName())); + break; + case WORD: + r[index++] = Long.valueOf(readResponse.getShort(field.getName())); + break; + case DWORD: + r[index++] = Long.valueOf(readResponse.getInteger(field.getName())); + break; + case LWORD: + r[index++] = readResponse.getLong(field.getName()); + break; + case INT: + r[index++] = Long.valueOf(readResponse.getShort(field.getName())); + break; + case UINT: + r[index++] = Long.valueOf(readResponse.getShort(field.getName()) & 0xFFFF); + break; + case SINT: + r[index++] = Long.valueOf(readResponse.getByte(field.getName())); + break; + case USINT: + r[index++] = Long.valueOf(readResponse.getByte(field.getName()) & 0xFF); + break; + case DINT: + r[index++] = Long.valueOf(readResponse.getInteger(field.getName())); + break; + case UDINT: + r[index++] = Long.valueOf(readResponse.getInteger(field.getName()) & 0xFFFF); + break; + case LINT: + r[index++] = readResponse.getLong(field.getName()); + break; + case ULINT: + r[index++] = readResponse.getLong(field.getName()) & 0xFFFFFFFFL; + break; + default: + throw new HopException("Tag type is not supported. Check tag definition."); + } + } else if (field.getType().equalsIgnoreCase("Internet Address")) { + throw new HopException("'Internet Address' type is not supported"); + } else if (field.getType().equalsIgnoreCase("JSON")) { + switch (valuetype) { + case BYTE: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllBytes(field.getName()))); + break; + case WORD: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllShorts(field.getName()))); + break; + case DWORD: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllIntegers(field.getName()))); + break; + case LWORD: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllLongs(field.getName()))); + break; + case INT: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllShorts(field.getName()))); + break; + case UINT: { + List numbers = readResponse.getAllShorts(field.getName()) + .stream() + .map(n -> { + return Long.valueOf(n & 0xFFFF); + }) + .collect(Collectors.toList()); + + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + numbers)); + } + break; + case SINT: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllBytes(field.getName()))); + break; + case USINT: { + List numbers = readResponse.getAllBytes(field.getName()) + .stream() + .map(n -> { + return Long.valueOf(n & 0xFF); + }) + .collect(Collectors.toList()); + + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + numbers)); + } + break; + case DINT: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllIntegers(field.getName()))); + break; + case UDINT: { + List numbers = readResponse.getAllBytes(field.getName()) + .stream() + .map(n -> { + return Long.valueOf(n & 0xFFFF); + }) + .collect(Collectors.toList()); + + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + numbers)); + } + break; + case LINT: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllLongs(field.getName()))); + break; + case ULINT: { + List numbers = readResponse.getAllLongs(field.getName()) + .stream() + .map(n -> { + return Long.valueOf(n & 0xFFFFFFFFL); + }) + .collect(Collectors.toList()); + + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + numbers)); + } + break; + case REAL: + case LREAL: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllFloats(field.getName()))); + break; + case DATE:; + case LDATE: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllDates(field.getName()))); + break; + case DATE_AND_TIME:; + case LDATE_AND_TIME: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllDateTimes(field.getName()))); + break; + case TIME:; + case LTIME:; + case TIME_OF_DAY:; + case LTIME_OF_DAY: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllTimes(field.getName()))); + break; + default: + throw new HopException("Tag type is not supported. Check tag definition."); + + } + } else if (field.getType().equalsIgnoreCase("Number")) { + switch (valuetype) { + case REAL: + case LREAL: + r[index++] = Double.valueOf(readResponse.getFloat(field.getName())); + break; + default: + throw new HopException("Tag type is not supported. Check tag definition."); + } + + } else if (field.getType().equalsIgnoreCase("String")) { + switch (valuetype) { + case BYTE: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllBytes(field.getName()))).toString(); + break; + case WORD: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllShorts(field.getName()))).toString(); + break; + case DWORD: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllIntegers(field.getName()))).toString(); + break; + case LWORD: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllLongs(field.getName()))).toString(); + break; + case INT: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllShorts(field.getName()))).toString(); + case UINT: { + List numbers = readResponse.getAllShorts(field.getName()) + .stream() + .map(n -> { + return Long.valueOf(n & 0xFFFF); + }) + .collect(Collectors.toList()); + + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + numbers)).toString(); + } + break; + case SINT: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllBytes(field.getName()))).toString(); + break; + case USINT: { + List numbers = readResponse.getAllBytes(field.getName()) + .stream() + .map(n -> { + return Long.valueOf(n & 0xFF); + }) + .collect(Collectors.toList()); + + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + numbers)).toString(); + } + break; + case DINT: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllIntegers(field.getName()))).toString(); + break; + case UDINT: { + List numbers = readResponse.getAllBytes(field.getName()) + .stream() + .map(n -> { + return Long.valueOf(n & 0xFFFF); + }) + .collect(Collectors.toList()); + + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + numbers)).toString(); + } + break; + case LINT: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllLongs(field.getName()))).toString(); + break; + case ULINT: { + List numbers = readResponse.getAllLongs(field.getName()) + .stream() + .map(n -> { + return Long.valueOf(n & 0xFFFFFFFFL); + }) + .collect(Collectors.toList()); + + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + numbers)).toString(); + } + break; + case REAL: + case LREAL: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllFloats(field.getName()))).toString(); + case DATE:; + case LDATE: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllDates(field.getName()))).toString(); + break; + case DATE_AND_TIME:; + case LDATE_AND_TIME: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllDateTimes(field.getName()))).toString(); + break; + case TIME:; + case LTIME:; + case TIME_OF_DAY:; + case LTIME_OF_DAY: + r[index++] = mapper.createObjectNode().set(field.getName(), + mapper.valueToTree( + readResponse.getAllTimes(field.getName()))).toString(); + break; + case STRING:; + default: + throw new HopException("'STRING' type is not supported"); + } + } else if (field.getType().equalsIgnoreCase("Timestamp")) { + switch (valuetype) { + case TIME: + case LTIME: + r[index++] = readResponse.getTime(field.getName()); + break; + case TIME_OF_DAY:; + case LTIME_OF_DAY: + r[index++] = readResponse.getTime(field.getName()); + break; + default: + throw new HopException("'LTIME, LTIME_OF_DAY' type is not supported"); + } + } + } catch (Exception ex) { + try { + System.out.println("META: " + data.outputRowMeta.toStringMeta()); + putError(data.outputRowMeta, r, 1, + "Tag error!.", field.getName(), + ex.getMessage()); + } catch (HopTransformException ex1) { + logError(ex1.toString()); + } + System.out.println("TagName: " + field.getName()); + } + } // for + + readResponse = null; //To GC? + + putRow(data.outputRowMeta, r); // return your data + data.rowsWritten++; + + return true; + } + + @Override + public boolean init() { + try { + if (super.init()) { + // Determine the number of rows to generate... + data.rowLimit = Const.toLong(resolve(meta.getRowLimit()), -1L); + data.rowsWritten = 0L; + data.delay = Const.toLong(resolve(meta.getIntervalInMs()), -1L); + + if (data.rowLimit < 0L) { // Unable to parse + logError(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Wrong.RowLimit.Number")); + return false; // fail + } + + // Create a row (constants) with all the values in it... + List remarks = new ArrayList<>(); // stores the errors... + RowMetaAndData outputRow = buildRow(meta, remarks, getTransformName()); + if (!remarks.isEmpty()) { + for (int i = 0; i < remarks.size(); i++) { + CheckResult cr = (CheckResult) remarks.get(i); + logError(cr.getText()); + } + return false; + } + + data.outputRowData = outputRow.getData(); + data.outputRowMeta = outputRow.getRowMeta(); + + getPlcConnection(); + + return true; + } + return false; + } catch (Exception ex) { + setErrors(1L); + logError("Error initializing transform", ex); + return false; + } + } + + /* + * Here, must perform the cleaning of any resource, main of the connection to + * the associated PLC. + */ + @Override + public void cleanup() { + super.cleanup(); + logBasic("Cleanup. Release connection."); + if (connwrapper != null) { + connwrapper.release(); + if (connwrapper.refCnt() <= 0) { + lookup.remove(connwrapper); + } + } + } + + + /* + * Here, must perform the cleaning of any resource. + * 1. Check if we have reference to wrapper. + * 2. Release de reference to object. + * 3. The lastone remove the global reference to connection wrapper. + * 4. Clear local references. + */ + @Override + public void dispose() { + super.dispose(); + if (connwrapper != null) { + logBasic("Dispose. Release connection: " + connwrapper.refCnt()); + connwrapper.release(); + if (connwrapper.refCnt() <= 0) { + lookup.remove(connwrapper); + } + connwrapper = null; + readRequest = null; + + } + } + + private void getPlcConnection() { + lock.lock(); //(01) + try { + + IHopMetadataProvider metaprovider = getMetadataProvider(); + connmeta = metaprovider.getSerializer(Plc4xConnection.class).load(meta.getConnection()); + + if (connwrapper == null) { + template = new Lookup.Template<>(Plc4xWrapperConnection.class, meta.getConnection(), null); + result = lookup.lookup(template); + if (!result.allItems().isEmpty()) { + logBasic("Using connection: " + meta.getConnection()); + connwrapper = (Plc4xWrapperConnection) result.allInstances().toArray()[0]; + if (connwrapper != null) { + connwrapper.retain(); + } + } + }; + + if (connmeta == null) { + logError( + BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.Log.SetMetadata", + meta.getConnection())); + } + + if ((connmeta != null) && (connwrapper == null)) { + readRequest = null; + try { + final PlcConnection conn = new DefaultPlcDriverManager().getConnection(connmeta.getUrl()); //(03) + Thread.sleep(200); + if (conn.isConnected()) { + logBasic("Create new connection with url : " + connmeta.getUrl()); + connwrapper = new Plc4xWrapperConnection(conn, meta.getConnection()); + lookup.add(connwrapper); + } + + } catch (Exception ex) { + setErrors(1L); + logError("Unable to create connection to PLC. " + ex.getMessage()); + } + } + + } catch (HopException ex) { + Logger.getLogger(Plc4xRead.class.getName()).log(Level.SEVERE, null, ex); + } finally { + lock.unlock(); + } + } + + /* + * Registers the tags to write. + * In the first processing of the rows, a check of the tags is + * carried out in order that they are well formed, generating an exception + * if they are not. + */ + public boolean RegisterPlcTags() { + if ((connmeta != null) && (connwrapper != null)) { + if (connwrapper.getConnection().isConnected()) { + if (readRequest == null) { + builder = connwrapper.getConnection().readRequestBuilder(); //(05) + for (Plc4xGeneratorField field : meta.getFields()) { + if (null == r) { + builder.addTagAddress(field.getName(), field.getItem()); + } else { + intField = getInputRowMeta().indexOfValue(field.getItem()); + if (intField != -1) { + strField = r[intField].toString(); + builder.addTagAddress(field.getName(), strField); + } else { + builder.addTagAddress(field.getName(), field.getItem()); + } + } + } + readRequest = builder.build(); + } + } else { + setErrors(1L); + logError("PLC is not connected."); + setOutputDone(); + return false; + } + + } else { + setErrors(1L); + logError("PLC connection don't exist."); + setOutputDone(); + return false; + } + + return true; + } + + public boolean GetReads() { + + try { + maxwait = Integer.parseInt(meta.getMaxwaitInMs()); + maxwait = (maxwait < 100) ? 100 : maxwait; + readResponse = readRequest.execute().get(maxwait, TimeUnit.MILLISECONDS); + + for (Plc4xGeneratorField field : meta.getFields()) { + if (readResponse.getResponseCode(field.getName()) != PlcResponseCode.OK) { + logDebug(field.getName() + " : " + readResponse.getResponseCode(field.getName()).name()); + try { + putError(data.outputRowMeta, r, 1, + "Tag error.", field.getName(), + readResponse.getResponseCode(field.getName()).name()); + } catch (HopTransformException ex) { + logError(ex.toString()); + } + } + } + } catch (Exception ex) { + setErrors(1L); + try { + putError(getInputRowMeta(), r, 1, + "Tag error!.", ex.getMessage(), + ex.toString()); + } catch (HopTransformException ex1) { + logError(ex.toString()); + } + logError("Unable read from PLC. " + ex.getMessage()); + setOutputDone(); + return false; + } + + return true; + } + +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xinput/Plc4xReadData.java b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xinput/Plc4xReadData.java new file mode 100644 index 00000000000..98b5889f0a8 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xinput/Plc4xReadData.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.plc4x.hop.transforms.plc4xinput; + +import java.util.Date; +import org.apache.hop.core.row.IRowMeta; +import org.apache.hop.pipeline.transform.BaseTransformData; +import org.apache.hop.pipeline.transform.ITransformData; + + +public class Plc4xReadData extends BaseTransformData implements ITransformData { + + //The Plc4xConnection metadata + public String connection; + + public IRowMeta outputRowMeta; + public Object[] outputRowData; + + public long rowLimit; + public long rowsWritten; + public Date rowDate; + public Date prevDate; + public long delay; + + + + /** + * Default constructor for SampleData. + */ + public Plc4xReadData() { + super(); + } +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xinput/Plc4xReadDialog.java b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xinput/Plc4xReadDialog.java new file mode 100644 index 00000000000..928ee6d4956 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xinput/Plc4xReadDialog.java @@ -0,0 +1,642 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.plc4x.hop.transforms.plc4xinput; + +import org.apache.hop.core.Const; +import org.apache.hop.core.exception.HopException; +import org.apache.hop.core.row.IRowMeta; +import org.apache.hop.core.row.value.ValueMetaFactory; +import org.apache.hop.core.util.Utils; +import org.apache.hop.core.variables.IVariables; +import org.apache.hop.i18n.BaseMessages; +import org.apache.hop.pipeline.Pipeline; +import org.apache.hop.pipeline.PipelineMeta; +import org.apache.hop.pipeline.PipelinePreviewFactory; +import org.apache.hop.pipeline.transform.BaseTransformMeta; +import org.apache.hop.pipeline.transform.ITransformDialog; +import org.apache.hop.ui.core.ConstUi; +import org.apache.hop.ui.core.dialog.BaseDialog; +import org.apache.hop.ui.core.dialog.EnterNumberDialog; +import org.apache.hop.ui.core.dialog.EnterTextDialog; +import org.apache.hop.ui.core.dialog.ErrorDialog; +import org.apache.hop.ui.core.dialog.PreviewRowsDialog; +import org.apache.hop.ui.core.widget.ColumnInfo; +import org.apache.hop.ui.core.widget.MetaSelectionLine; +import org.apache.hop.ui.core.widget.TableView; +import org.apache.hop.ui.core.widget.TextVar; +import org.apache.hop.ui.pipeline.dialog.PipelinePreviewProgressDialog; +import org.apache.hop.ui.pipeline.transform.BaseTransformDialog; +import org.apache.hop.ui.pipeline.transform.ITableItemInsertListener; +import org.apache.hop.ui.util.SwtSvgImageUtil; +import org.apache.plc4x.hop.metadata.Plc4xConnection; +import org.apache.plc4x.hop.transforms.util.Plc4xGeneratorField; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.*; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; + +public class Plc4xReadDialog extends BaseTransformDialog implements ITransformDialog { + private static final Class PKG = Plc4xReadDialog.class; // Needed by Translator + + private MetaSelectionLine wConnection; + + private Label wlLimit; + private TextVar wLimit; + + private Button wNeverEnding; + + private Label wlMaxwait; + private TextVar wMaxwait; + + private Label wlInterval; + private TextVar wInterval; + + private Label wlRowTimeField; + private TextVar wRowTimeField; + + private Label wlLastTimeField; + private TextVar wLastTimeField; + + private TableView wFields; + + private final Plc4xReadMeta input; + + public Plc4xReadDialog(Shell parent, IVariables variables , Object in, PipelineMeta pipelineMeta, String sname ) { + super( parent, variables, (BaseTransformMeta) in, pipelineMeta, sname ); + input = (Plc4xReadMeta) in; + } + + @Override + public String open() { + Shell parent = getParent(); + + shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN); + props.setLook(shell); + setShellImage(shell, input); + + ModifyListener lsMod = e -> input.setChanged(); + changed = input.hasChanged(); + + FormLayout formLayout = new FormLayout(); + formLayout.marginWidth = Const.FORM_MARGIN; + formLayout.marginHeight = Const.FORM_MARGIN; + + shell.setLayout(formLayout); + shell.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.DialogTitle")); + + int middle = props.getMiddlePct(); + int margin = props.getMargin(); + + // Filename line + wlTransformName = new Label(shell, SWT.RIGHT); + wlTransformName.setText(BaseMessages.getString(PKG, "System.Label.TransformName")); + props.setLook(wlTransformName); + fdlTransformName = new FormData(); + fdlTransformName.left = new FormAttachment(0, 0); + fdlTransformName.right = new FormAttachment(middle, -margin); + fdlTransformName.top = new FormAttachment(0, margin); + wlTransformName.setLayoutData(fdlTransformName); + + wTransformName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + wTransformName.setText(transformName); + props.setLook(wTransformName); + wTransformName.addModifyListener(lsMod); + fdTransformName = new FormData(); + fdTransformName.left = new FormAttachment(middle, 0); + fdTransformName.top = new FormAttachment(0, margin); + fdTransformName.right = new FormAttachment(100, 0); + wTransformName.setLayoutData(fdTransformName); + + // Connection line + wConnection = + new MetaSelectionLine<>( + variables, + metadataProvider, + Plc4xConnection.class, + shell, + SWT.NONE, + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Connection.Label"), + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Connection.Tooltip")); + FormData fdConnection = new FormData(); + fdConnection.left = new FormAttachment(0, 0); + fdConnection.right = new FormAttachment(100, 0); + fdConnection.top = new FormAttachment(wTransformName, margin); + wConnection.setLayoutData(fdConnection); + props.setLook(wConnection); + try { + wConnection.fillItems(); + } catch (Exception e) { + new ErrorDialog(shell, "Error", "Error listing Plc4x connection metadata objects", e); + } + + Control lastControl = wConnection; + + wlLimit = new Label(shell, SWT.RIGHT); + wlLimit.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Limit.Label")); + props.setLook(wlLimit); + FormData fdlLimit = new FormData(); + fdlLimit.left = new FormAttachment(0, 0); + fdlLimit.right = new FormAttachment(middle, -margin); + fdlLimit.top = new FormAttachment(lastControl, margin); + wlLimit.setLayoutData(fdlLimit); + wLimit = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wLimit); + wLimit.addModifyListener(lsMod); + FormData fdLimit = new FormData(); + fdLimit.left = new FormAttachment(middle, 0); + fdLimit.top = new FormAttachment(lastControl, margin); + fdLimit.right = new FormAttachment(100, 0); + wLimit.setLayoutData(fdLimit); + lastControl = wLimit; + + Label wlNeverEnding = new Label(shell, SWT.RIGHT); + wlNeverEnding.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.NeverEnding.Label")); + props.setLook(wlNeverEnding); + FormData fdlNeverEnding = new FormData(); + fdlNeverEnding.left = new FormAttachment(0, 0); + fdlNeverEnding.right = new FormAttachment(middle, -margin); + fdlNeverEnding.top = new FormAttachment(lastControl, margin); + wlNeverEnding.setLayoutData(fdlNeverEnding); + wNeverEnding = new Button(shell, SWT.CHECK); + props.setLook(wNeverEnding); + wNeverEnding.addSelectionListener( + new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + setActive(); + input.setChanged(); + } + }); + FormData fdNeverEnding = new FormData(); + fdNeverEnding.left = new FormAttachment(middle, 0); + fdNeverEnding.top = new FormAttachment(wlNeverEnding, 0, SWT.CENTER); + fdNeverEnding.right = new FormAttachment(100, 0); + wNeverEnding.setLayoutData(fdNeverEnding); + lastControl = wlNeverEnding; + + wlMaxwait = new Label(shell, SWT.RIGHT); + wlMaxwait.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Maxwait.Label")); + props.setLook(wlMaxwait); + FormData fdlMaxwait = new FormData(); + fdlMaxwait.left = new FormAttachment(0, 0); + fdlMaxwait.right = new FormAttachment(middle, -margin); + fdlMaxwait.top = new FormAttachment(lastControl, margin); + wlMaxwait.setLayoutData(fdlMaxwait); + wMaxwait = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wMaxwait); + wMaxwait.addModifyListener(lsMod); + FormData fdMaxwait = new FormData(); + fdMaxwait.left = new FormAttachment(middle, 0); + fdMaxwait.top = new FormAttachment(lastControl, margin); + fdMaxwait.right = new FormAttachment(100, 0); + wMaxwait.setLayoutData(fdMaxwait); + lastControl = wMaxwait; + + wlInterval = new Label(shell, SWT.RIGHT); + wlInterval.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Interval.Label")); + props.setLook(wlInterval); + FormData fdlInterval = new FormData(); + fdlInterval.left = new FormAttachment(0, 0); + fdlInterval.right = new FormAttachment(middle, -margin); + fdlInterval.top = new FormAttachment(lastControl, margin); + wlInterval.setLayoutData(fdlInterval); + wInterval = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wInterval); + wInterval.addModifyListener(lsMod); + FormData fdInterval = new FormData(); + fdInterval.left = new FormAttachment(middle, 0); + fdInterval.top = new FormAttachment(lastControl, margin); + fdInterval.right = new FormAttachment(100, 0); + wInterval.setLayoutData(fdInterval); + lastControl = wInterval; + + /* + wlRowTimeField = new Label(shell, SWT.RIGHT); + wlRowTimeField.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.RowTimeField.Label")); + props.setLook(wlRowTimeField); + FormData fdlRowTimeField = new FormData(); + fdlRowTimeField.left = new FormAttachment(0, 0); + fdlRowTimeField.right = new FormAttachment(middle, -margin); + fdlRowTimeField.top = new FormAttachment(lastControl, margin); + wlRowTimeField.setLayoutData(fdlRowTimeField); + wRowTimeField = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wRowTimeField); + wRowTimeField.addModifyListener(lsMod); + FormData fdRowTimeField = new FormData(); + fdRowTimeField.left = new FormAttachment(middle, 0); + fdRowTimeField.top = new FormAttachment(lastControl, margin); + fdRowTimeField.right = new FormAttachment(100, 0); + wRowTimeField.setLayoutData(fdRowTimeField); + lastControl = wRowTimeField; + + wlLastTimeField = new Label(shell, SWT.RIGHT); + wlLastTimeField.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.LastTimeField.Label")); + props.setLook(wlLastTimeField); + FormData fdlLastTimeField = new FormData(); + fdlLastTimeField.left = new FormAttachment(0, 0); + fdlLastTimeField.right = new FormAttachment(middle, -margin); + fdlLastTimeField.top = new FormAttachment(lastControl, margin); + wlLastTimeField.setLayoutData(fdlLastTimeField); + wLastTimeField = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wLastTimeField); + wLastTimeField.addModifyListener(lsMod); + FormData fdLastTimeField = new FormData(); + fdLastTimeField.left = new FormAttachment(middle, 0); + fdLastTimeField.top = new FormAttachment(lastControl, margin); + fdLastTimeField.right = new FormAttachment(100, 0); + wLastTimeField.setLayoutData(fdLastTimeField); + lastControl = wLastTimeField; + */ + wOk = new Button(shell, SWT.PUSH); + wOk.setText(BaseMessages.getString(PKG, "System.Button.OK")); + wOk.addListener(SWT.Selection, e -> ok()); + + wGet = new Button(shell, SWT.PUSH); + wGet.setText(BaseMessages.getString(PKG, "Get Fields")); + wGet.addListener(SWT.Selection, e -> getfields()); + + wPreview = new Button(shell, SWT.PUSH); + wPreview.setText(BaseMessages.getString(PKG, "System.Button.Preview")); + wPreview.addListener(SWT.Selection, e -> preview()); + + wCancel = new Button(shell, SWT.PUSH); + wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); + wCancel.addListener(SWT.Selection, e -> cancel()); + + setButtonPositions(new Button[] {wOk, wPreview, wGet , wCancel}, margin, null); + + Label wlFields = new Label(shell, SWT.NONE); + wlFields.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Fields.Label")); + props.setLook(wlFields); + FormData fdlFields = new FormData(); + fdlFields.left = new FormAttachment(0, 0); + fdlFields.top = new FormAttachment(lastControl, margin); + wlFields.setLayoutData(fdlFields); + lastControl = wlFields; + + final int nrFields = input.getFields().size(); + + ColumnInfo[] colinf = + new ColumnInfo[] { + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Name"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Fields.Item"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Type"), + ColumnInfo.COLUMN_TYPE_CCOMBO, + ValueMetaFactory.getValueMetaNames()), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Format"), + ColumnInfo.COLUMN_TYPE_FORMAT, + 2), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Length"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Precision"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Currency"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Decimal"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Group"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Value"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.SetEmptyString"), + ColumnInfo.COLUMN_TYPE_CCOMBO, + new String[] { + BaseMessages.getString(PKG, "System.Combo.Yes"), + BaseMessages.getString(PKG, "System.Combo.No") + }) + }; + + wFields = + new TableView( + variables, + shell, + SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, + colinf, + nrFields, + lsMod, + props); + + FormData fdFields = new FormData(); + fdFields.left = new FormAttachment(0, 0); + fdFields.top = new FormAttachment(lastControl, margin); + fdFields.right = new FormAttachment(100, 0); + fdFields.bottom = new FormAttachment(wOk, -2 * margin); + wFields.setLayoutData(fdFields); + + lsResize = + event -> { + Point size = shell.getSize(); + wFields.setSize(size.x - 10, size.y - 50); + wFields.table.setSize(size.x - 10, size.y - 50); + wFields.redraw(); + }; + shell.addListener(SWT.Resize, lsResize); + + getData(); + input.setChanged(changed); + + BaseDialog.defaultShellHandling(shell, c -> ok(), c -> cancel()); + + return transformName; + }; + + @Override + public void setActive() { + boolean neverEnding = wNeverEnding.getSelection(); + + wlLimit.setEnabled(!neverEnding); + wLimit.setEnabled(!neverEnding); + + //wlInterval.setEnabled(neverEnding); + //wInterval.setEnabled(neverEnding); + + //wlRowTimeField.setEnabled(neverEnding); + //wRowTimeField.setEnabled(neverEnding); + + //wlLastTimeField.setEnabled(neverEnding); + //wLastTimeField.setEnabled(neverEnding); + } + + + + private Image getImage() { + return SwtSvgImageUtil.getImage( shell.getDisplay(), getClass().getClassLoader(), "plc4x_toddy_read.svg", ConstUi.LARGE_ICON_SIZE, + ConstUi.LARGE_ICON_SIZE ); + } + + /** + * Copy information from the meta-data input to the dialog fields. + * + */ + public void getData() { + if (isDebug()) { + logDebug("getting fields info..."); + } + if (input.getConnection() == null) { + wConnection.setText(""); + } else { + wConnection.setText(input.getConnection()); + } + + wLimit.setText(input.getRowLimit()); + wNeverEnding.setSelection(input.isNeverEnding()); + wMaxwait.setText(Const.NVL(input.getMaxwaitInMs(), "")); + wInterval.setText(Const.NVL(input.getIntervalInMs(), "")); + // wRowTimeField.setText(Const.NVL(input.getRowTimeField(), "")); + //wLastTimeField.setText(Const.NVL(input.getLastTimeField(), "")); + + for (int i = 0; i < input.getFields().size(); i++) { + Plc4xGeneratorField field = input.getFields().get(i); + TableItem item = wFields.table.getItem(i); + int col = 1; + item.setText(col++, Const.NVL(field.getName(), "")); + + item.setText(col++, Const.NVL(field.getItem(), "")); + + String type = field.getType(); + String format = field.getFormat(); + String length = field.getLength() < 0 ? "" : ("" + field.getLength()); + String prec = field.getPrecision() < 0 ? "" : ("" + field.getPrecision()); + + String curr = field.getCurrency(); + String group = field.getGroup(); + String decim = field.getDecimal(); + String def = field.getValue(); + + item.setText(col++, Const.NVL(type, "")); + item.setText(col++, Const.NVL(format, "")); + item.setText(col++, Const.NVL(length, "")); + item.setText(col++, Const.NVL(prec, "")); + item.setText(col++, Const.NVL(curr, "")); + item.setText(col++, Const.NVL(decim, "")); + item.setText(col++, Const.NVL(group, "")); + item.setText(col++, Const.NVL(def, "")); + item.setText( + col++, + field.isSetEmptyString() + ? BaseMessages.getString(PKG, "System.Combo.Yes") + : BaseMessages.getString(PKG, "System.Combo.No")); + } + + wFields.setRowNums(); + wFields.optWidth(true); + + setActive(); + + wTransformName.selectAll(); + wTransformName.setFocus(); + } + + /** + * Stores the information from the dialog box in meta-data. + * + * @param meta + */ + private void getInfo( Plc4xReadMeta meta) throws HopException { + meta.setConnection(wConnection.getText()); + meta.setRowLimit(wLimit.getText()); + meta.setNeverEnding(wNeverEnding.getSelection()); + meta.setMaxwaitInMs(wMaxwait.getText()); + meta.setIntervalInMs(wInterval.getText()); + //meta.setRowTimeField(wRowTimeField.getText()); + //meta.setLastTimeField(wLastTimeField.getText()); + + meta.getFields().clear(); + + // CHECKSTYLE:Indentation:OFF + for (TableItem item : wFields.getNonEmptyItems()) { + Plc4xGeneratorField field = new Plc4xGeneratorField(); + field.setName(item.getText(1)); + field.setItem(item.getText(2)); + field.setFormat(item.getText(4)); + field.setLength(Const.toInt(item.getText(5), -1)); + field.setPrecision(Const.toInt(item.getText(6), -1)); + field.setCurrency(item.getText(7)); + field.setDecimal(item.getText(8)); + field.setGroup(item.getText(9)); + field.setValue(field.isSetEmptyString() ? "" : item.getText(10)); + field.setSetEmptyString( + BaseMessages.getString(PKG, "System.Combo.Yes").equalsIgnoreCase(item.getText(11))); + field.setType(field.isSetEmptyString() ? "String" : item.getText(3)); + + meta.getFields().add(field); + } + } + + /** + * Cancel the dialog. + */ + private void cancel() { + transformName = null; + input.setChanged( changed ); + dispose(); + } + + private void ok() { + if (Utils.isEmpty(wTransformName.getText())) { + return; + } + + transformName = wTransformName.getText(); // return value + try { + getInfo(new Plc4xReadMeta()); // to see if there is an exception + getInfo(input); // to put the content on the input structure for real if all is well. + dispose(); + } catch (HopException e) { + new ErrorDialog( + shell, + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Title"), + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Message"), + e); + } + } + + private void getfields() { + try { + + IRowMeta r = pipelineMeta.getPrevTransformFields(variables, transformName); + + if (r != null && !r.isEmpty()) { + ITableItemInsertListener listener = + (tableItem, v) -> { + + tableItem.setText(2, ""); + tableItem.setText(3, v.getTypeDesc()); + tableItem.setText(4, v.getFormatMask()==null?"":v.getFormatMask()); + tableItem.setText(5, Integer.toString(v.getLength())); + tableItem.setText(6, Integer.toString(v.getPrecision())); + tableItem.setText(7, v.getCurrencySymbol()==null?"":v.getCurrencySymbol()); + tableItem.setText(8, v.getDecimalSymbol()==null?"":v.getDecimalSymbol()); + tableItem.setText(9, v.getGroupingSymbol()==null?"":v.getGroupingSymbol()); + //tableItem.setText(10, "N"); + tableItem.setText(11, "N"); + return true; + }; + BaseTransformDialog.getFieldsFromPrevious( + r, wFields, 1, new int[] {1}, null, -1, -1, listener); + } + + + } catch (Exception ex){ + new ErrorDialog( + shell, + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Title"), + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Message"), + ex); + } + } + + /** + * Preview the data generated by this transform. This generates a pipeline using this transform & + * a dummy and previews it. + */ + private void preview() { + Plc4xReadMeta oneMeta = new Plc4xReadMeta(); + try { + getInfo(oneMeta); + } catch (HopException e) { + new ErrorDialog( + shell, + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Title"), + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Message"), + e); + return; + } + + PipelineMeta previewMeta = + PipelinePreviewFactory.generatePreviewPipeline( + pipelineMeta.getMetadataProvider(), oneMeta, wTransformName.getText()); + + EnterNumberDialog numberDialog = + new EnterNumberDialog( + shell, + props.getDefaultPreviewSize(), + BaseMessages.getString(PKG, "System.Dialog.EnterPreviewSize.Title"), + BaseMessages.getString(PKG, "System.Dialog.EnterPreviewSize.Message")); + int previewSize = numberDialog.open(); + if (previewSize > 0) { + PipelinePreviewProgressDialog progressDialog = + new PipelinePreviewProgressDialog( + shell, + variables, + previewMeta, + new String[] {wTransformName.getText()}, + new int[] {previewSize}); + progressDialog.open(); + + Pipeline pipeline = progressDialog.getPipeline(); + String loggingText = progressDialog.getLoggingText(); + + if (!progressDialog.isCancelled()) { + if (pipeline.getResult() != null && pipeline.getResult().getNrErrors() > 0) { + EnterTextDialog etd = + new EnterTextDialog( + shell, + BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), + BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), + loggingText, + true); + etd.setReadOnly(); + etd.open(); + } + } + + PreviewRowsDialog prd = + new PreviewRowsDialog( + shell, + variables, + SWT.NONE, + wTransformName.getText(), + progressDialog.getPreviewRowsMeta(wTransformName.getText()), + progressDialog.getPreviewRows(wTransformName.getText()), + loggingText); + prd.open(); + } + } + +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xinput/Plc4xReadMeta.java b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xinput/Plc4xReadMeta.java new file mode 100644 index 00000000000..559dce2bd69 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xinput/Plc4xReadMeta.java @@ -0,0 +1,316 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.plc4x.hop.transforms.plc4xinput; + +import java.util.ArrayList; +import org.apache.hop.core.ICheckResult; +import org.apache.hop.core.annotations.Transform; +import org.apache.hop.core.exception.HopTransformException; +import org.apache.hop.core.row.IRowMeta; +import org.apache.hop.core.variables.IVariables; +import org.apache.hop.metadata.api.IHopMetadataProvider; +import org.apache.hop.pipeline.Pipeline; +import org.apache.hop.pipeline.PipelineMeta; +import org.apache.hop.pipeline.transform.BaseTransformMeta; +import org.apache.hop.pipeline.transform.ITransformMeta; +import org.apache.hop.pipeline.transform.TransformMeta; + +import java.util.List; +import org.apache.hop.core.Const; +import org.apache.hop.core.RowMetaAndData; +import org.apache.hop.core.row.IValueMeta; +import org.apache.hop.metadata.api.HopMetadataProperty; +import org.apache.hop.pipeline.transform.ITransformIOMeta; +import org.apache.hop.pipeline.transform.TransformIOMeta; +import org.apache.plc4x.hop.transforms.util.Plc4xGeneratorField; + +/** + * Meta data for the sample transform. + */ +@Transform( + id = "plc4x-read", + name = "i18n::Plc4x.Read.Name", + description = "i18n::Plc4x.Read.Description", + image = "plc4x_read.svg", + categoryDescription = "i18n:org.apache.plc4x.hop.transforms.plc4xinput:Plc4x.Category.plc4x", + documentationUrl = "https://plc4x.apache.org/users/integrations/apache-calcite.html" +) +public class Plc4xReadMeta extends BaseTransformMeta { + + private static final Class PKG = Plc4xReadMeta.class; // Needed by Translator + + @HopMetadataProperty( + key = "connection", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.Connection") + private String connection; + + @HopMetadataProperty( + key = "never_ending", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.NeverEnding") + private boolean neverEnding; + + @HopMetadataProperty( + key = "maxwait_in_ms", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.MaxwaitInMs") + private String maxwaitInMs; + + @HopMetadataProperty( + key = "interval_in_ms", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.IntervalInMs") + private String intervalInMs; + + @HopMetadataProperty( + key = "row_time_field", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.RowTimeField") + private String rowTimeField; + + @HopMetadataProperty( + key = "last_time_field", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.LastTimeField") + private String lastTimeField; + + @HopMetadataProperty( + key = "limit", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.RowLimit") + private String rowLimit; + + @HopMetadataProperty( + groupKey = "fields", + key = "field", + injectionGroupDescription = "Plc4x.Read.Meta.Injection.Fields", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.Fields") + private List fields; + + public Plc4xReadMeta() { + fields = new ArrayList<>(); + + rowLimit = "10"; + neverEnding = false; + maxwaitInMs = "1000"; + intervalInMs = "5000"; + rowTimeField = "now"; + lastTimeField = "last"; + } + + public Plc4xReadMeta(Plc4xReadMeta m) { + this.connection = m.connection; + this.neverEnding = m.neverEnding; + this.intervalInMs = m.intervalInMs; + this.rowTimeField = m.rowTimeField; + this.lastTimeField = m.lastTimeField; + this.rowLimit = m.rowLimit; + this.fields = new ArrayList<>(); + for (Plc4xGeneratorField field : m.fields) { + this.fields.add(new Plc4xGeneratorField(field)); + } + } + + public Plc4xReadMeta clone() { + return new Plc4xReadMeta(this); + } + + public void getFields(IRowMeta inputRowMeta, String name, IRowMeta[] info, TransformMeta nextTransform, + IVariables variables, IHopMetadataProvider metadataProvider) throws HopTransformException { + try { + List remarks = new ArrayList<>(); + RowMetaAndData rowMetaAndData = Plc4xRead.buildRow(this, remarks, name); + + if (!remarks.isEmpty()) { + StringBuilder stringRemarks = new StringBuilder(); + for (ICheckResult remark : remarks) { + stringRemarks.append(remark.toString()).append(Const.CR); + } + throw new HopTransformException(stringRemarks.toString()); + } + + for (IValueMeta valueMeta : rowMetaAndData.getRowMeta().getValueMetaList()) { + valueMeta.setOrigin(name); + } + + inputRowMeta.mergeRowMeta(rowMetaAndData.getRowMeta()); + } catch (Exception e) { + throw new HopTransformException(e); + } + } + + public Plc4xRead createTransform(TransformMeta transformMeta, Plc4xReadData data, int copyNr, + PipelineMeta pipelineMeta, Pipeline pipeline) { + return new Plc4xRead(transformMeta, this, data, copyNr, pipelineMeta, pipeline); + } + + public Plc4xReadData getTransformData() { + return new Plc4xReadData(); + } + + /* + @Override + public void loadXml( Node transformNode, IHopMetadataProvider metadataProvider ) throws HopXmlException { + //load the saved values from the transformnode + String sampleValue = XmlHandler.getTagValue( transformNode, "sampleValue" ); + + } + */ + @Override + public void setDefault() { + //default values when creating a new transform + } + + /** + * Returns the Input/Output metadata for this transform. The generator + * transform only produces output, does not accept input! + * TransformIOMeta(inputAcceptor, outputProducer, inputOptional, + * outputDynamic, inputDynamic) + */ + @Override + public ITransformIOMeta getTransformIOMeta() { + return new TransformIOMeta(true, true, false, false, false, false); + } + + /** + * Gets Plc4xConnection metadata name. + * + * @return value of intervalInMs + */ + public String getConnection() { + return connection; + } + + /** + * @param connection + */ + public void setConnection(String connection) { + this.connection = connection; + } + + /** + * Gets neverEnding + * + * @return value of neverEnding + */ + public boolean isNeverEnding() { + return neverEnding; + } + + /** + * @param neverEnding The neverEnding to set + */ + public void setNeverEnding(boolean neverEnding) { + this.neverEnding = neverEnding; + } + + /** + * Gets intervalInMs + * + * @return value of intervalInMs + */ + public String getMaxwaitInMs() { + return maxwaitInMs; + } + + /** + * @param intervalInMs The intervalInMs to set + */ + public void setMaxwaitInMs(String maxwaitInMs) { + this.maxwaitInMs = maxwaitInMs; + } + + /** + * Gets intervalInMs + * + * @return value of intervalInMs + */ + public String getIntervalInMs() { + return intervalInMs; + } + + /** + * @param intervalInMs The intervalInMs to set + */ + public void setIntervalInMs(String intervalInMs) { + this.intervalInMs = intervalInMs; + } + + /** + * Gets rowTimeField + * + * @return value of rowTimeField + */ + public String getRowTimeField() { + return rowTimeField; + } + + /** + * @param rowTimeField The rowTimeField to set + */ + public void setRowTimeField(String rowTimeField) { + this.rowTimeField = rowTimeField; + } + + /** + * Gets lastTimeField + * + * @return value of lastTimeField + */ + public String getLastTimeField() { + return lastTimeField; + } + + /** + * @param lastTimeField The lastTimeField to set + */ + public void setLastTimeField(String lastTimeField) { + this.lastTimeField = lastTimeField; + } + + /** + * Gets rowLimit + * + * @return value of rowLimit + */ + public String getRowLimit() { + return rowLimit; + } + + /** + * @param rowLimit The rowLimit to set + */ + public void setRowLimit(String rowLimit) { + this.rowLimit = rowLimit; + } + + /** + * Gets fields + * + * @return value of fields + */ + public List getFields() { + return fields; + } + + /** + * @param fields The fields to set + */ + public void setFields(List fields) { + this.fields = fields; + } + + @Override + public boolean supportsErrorHandling() { + return true; + } + +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xoutput/Plc4xWrite.java b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xoutput/Plc4xWrite.java new file mode 100644 index 00000000000..5f972d39c98 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xoutput/Plc4xWrite.java @@ -0,0 +1,553 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.plc4x.hop.transforms.plc4xoutput; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.ReentrantLock; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.apache.commons.lang3.StringUtils; +import org.apache.hop.core.CheckResult; +import org.apache.hop.core.Const; +import org.apache.hop.core.ICheckResult; +import org.apache.hop.core.RowMetaAndData; +import org.apache.hop.core.exception.HopException; +import org.apache.hop.core.exception.HopPluginException; +import org.apache.hop.core.exception.HopTransformException; +import org.apache.hop.core.exception.HopValueException; +import org.apache.hop.core.logging.LogLevel; +import org.apache.hop.core.row.IRowMeta; +import org.apache.hop.core.row.IValueMeta; +import org.apache.hop.core.row.RowDataUtil; +import org.apache.hop.core.row.RowMeta; +import org.apache.hop.core.row.value.ValueMetaDate; +import org.apache.hop.core.row.value.ValueMetaFactory; +import org.apache.hop.core.util.StringUtil; +import org.apache.hop.core.util.Utils; +import org.apache.hop.i18n.BaseMessages; +import org.apache.hop.metadata.api.IHopMetadataProvider; +import org.apache.hop.pipeline.Pipeline; +import org.apache.hop.pipeline.PipelineMeta; +import org.apache.hop.pipeline.transform.BaseTransform; +import org.apache.hop.pipeline.transform.ITransform; +import org.apache.hop.pipeline.transform.TransformMeta; +import org.apache.plc4x.hop.metadata.Plc4xConnection; +import org.apache.plc4x.hop.metadata.util.Plc4xLookup; +import org.apache.plc4x.hop.transforms.util.Plc4xGeneratorField; +import org.apache.plc4x.hop.transforms.util.Plc4xPlcTag; +import org.apache.plc4x.hop.metadata.util.Plc4xWrapperConnection; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.BOOL; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.BYTE; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.REAL; +import static org.apache.plc4x.hop.transforms.util.Plc4xDataType.WORD; +import org.apache.plc4x.java.DefaultPlcDriverManager; +import org.apache.plc4x.java.api.PlcConnection; +import org.apache.plc4x.java.api.messages.PlcWriteRequest; +import org.apache.plc4x.java.api.messages.PlcWriteResponse; +import org.apache.plc4x.java.api.types.PlcResponseCode; +import org.openide.util.Lookup; + +/** + * Transform That contains the basic skeleton needed to create your own plugin + * + */ +public class Plc4xWrite extends BaseTransform { + + private static final Class PKG = Plc4xWrite.class; // Needed by Translator + + private Object[] r = null; + + private Plc4xConnection connmeta = null; + private Plc4xWrapperConnection connwrapper = null; + private PlcWriteRequest writeRequest = null; + private PlcWriteRequest.Builder builder = null; + private PlcWriteResponse writeResponse = null; + + private Plc4xLookup lookup = Plc4xLookup.getDefault(); + private Lookup.Template template = null; + private Lookup.Result result = null; + + private static final ReentrantLock lock = new ReentrantLock(); + + private static final String dummy = "dummy"; + + private Map index = new HashMap(); + private Map plcfields = new HashMap(); + + public Plc4xWrite(TransformMeta transformMeta, Plc4xWriteMeta meta, Plc4xWriteData data, int copyNr, PipelineMeta pipelineMeta, + Pipeline pipeline) { + super(transformMeta, meta, data, copyNr, pipelineMeta, pipeline); + } + + /* + * Including Date and Time field for every row + * + * @param meta Meta data from user dialog + * @param remarks Error registers + * @param origin transform instance name + */ + public static final RowMetaAndData buildRow( + Plc4xWriteMeta meta, List remarks, String origin) throws HopPluginException { + IRowMeta rowMeta = new RowMeta(); + Object[] rowData = RowDataUtil.allocateRowData(meta.getFields().size() + 2); + int index = 0; + + if (!Utils.isEmpty(meta.getRowTimeField())) { + rowMeta.addValueMeta(new ValueMetaDate(meta.getRowTimeField())); + rowData[index++] = null; + } + + if (!Utils.isEmpty(meta.getLastTimeField())) { + rowMeta.addValueMeta(new ValueMetaDate(meta.getLastTimeField())); + rowData[index++] = null; + } + + for (Plc4xGeneratorField field : meta.getFields()) { + int typeString = ValueMetaFactory.getIdForValueMeta(field.getType()); + if (StringUtils.isNotEmpty(field.getType())) { + IValueMeta valueMeta + = ValueMetaFactory.createValueMeta(field.getName(), typeString); // build a + // value! + valueMeta.setLength(field.getLength()); + valueMeta.setPrecision(field.getPrecision()); + valueMeta.setConversionMask(field.getFormat()); + valueMeta.setCurrencySymbol(field.getCurrency()); + valueMeta.setGroupingSymbol(field.getGroup()); + valueMeta.setDecimalSymbol(field.getDecimal()); + valueMeta.setOrigin(origin); + + IValueMeta stringMeta = ValueMetaFactory.cloneValueMeta(valueMeta, IValueMeta.TYPE_STRING); + + if (field.isSetEmptyString()) { + // Set empty string + rowData[index] = StringUtil.EMPTY_STRING; + } else { + String stringValue = field.getValue(); + + // If the value is empty: consider it to be NULL. + if (Utils.isEmpty(stringValue)) { + rowData[index] = null; + + if (valueMeta.getType() == IValueMeta.TYPE_NONE) { + String message + = BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.CheckResult.SpecifyTypeError", + valueMeta.getName(), + stringValue); + remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, null)); + } + } else { + // Convert the data from String to the specified type ... + // + try { + rowData[index] = valueMeta.convertData(stringMeta, stringValue); + } catch (HopValueException e) { + switch (valueMeta.getType()) { + case IValueMeta.TYPE_NUMBER: + String message + = BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.BuildRow.Error.Parsing.Number", + valueMeta.getName(), + stringValue, + e.toString()); + remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, null)); + break; + + case IValueMeta.TYPE_DATE: + message + = BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.BuildRow.Error.Parsing.Date", + valueMeta.getName(), + stringValue, + e.toString()); + remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, null)); + break; + + case IValueMeta.TYPE_INTEGER: + message + = BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.BuildRow.Error.Parsing.Integer", + valueMeta.getName(), + stringValue, + e.toString()); + remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, null)); + break; + + case IValueMeta.TYPE_BIGNUMBER: + message + = BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.BuildRow.Error.Parsing.BigNumber", + valueMeta.getName(), + stringValue, + e.toString()); + remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, null)); + break; + + case IValueMeta.TYPE_TIMESTAMP: + message + = BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.BuildRow.Error.Parsing.Timestamp", + valueMeta.getName(), + stringValue, + e.toString()); + remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, null)); + break; + + default: + // Boolean and binary don't throw errors normally, so it's probably an unspecified + // error problem... + message + = BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.CheckResult.SpecifyTypeError", + valueMeta.getName(), + stringValue); + remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, null)); + break; + } + } + } + } + + // Now add value to the row! + // This is in fact a copy from the fields row, but now with data. + rowMeta.addValueMeta(valueMeta); + index++; + } + } + + return new RowMetaAndData(rowMeta, rowData); + } + + /* + * 1. Stores the indexes of the incoming fields from the user's selection. + * It is only done during the first cycle. + * 2. Block the other instances by means of a lock. + * 3. Try to locate an existing connection. + * 4. If it doesn't exist, it tries to take control of the routine to + * create an instance of PlcConnection and his wrapper. + * 5. Register the connection wrapper for global access. + * 6. If the connection to the PLC is made, then it creates the query + * and executes it. + * + */ + @Override + public boolean processRow() throws HopException { +// final Object[] r = getRow(); // Get row from input rowset & set row busy! + r = getRow(); + + if (r == null) { + setOutputDone(); + return false; + } + + data.outputRowMeta = getInputRowMeta(); + + first = true; + if (first) { + index.clear(); + plcfields.clear(); + meta.getFields().forEach((f) -> { + final Integer i = getInputRowMeta().indexOfValue(f.getName()); //(01) + if (i >= 0) { + index.put(f.getName(), i); + plcfields.put(f.getName(), Plc4xPlcTag.of(f.getItem())); + } + }); + first = false; + } + + if ((!meta.isNeverEnding() && data.rowsWritten >= data.rowLimit) && !isStopped()) { + setOutputDone(); // signal end to receiver(s) + return false; + } + + if (!RegisterPlcTags()) { + return false; + } + GetWrites(); + + putRow(data.outputRowMeta, r); // return your data + data.rowsWritten++; + return true; + } + + @Override + public boolean init() { + try { + if (super.init()) { + // Determine the number of rows to generate... + data.rowLimit = Const.toLong(resolve(meta.getRowLimit()), -1L); + data.rowsWritten = 0L; + data.delay = Const.toLong(resolve(meta.getIntervalInMs()), -1L); + + if (data.rowLimit < 0L) { // Unable to parse + logError(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Wrong.RowLimit.Number")); + return false; // fail + } + + // Create a row (constants) with all the values in it... + List remarks = new ArrayList<>(); // stores the errors... + RowMetaAndData outputRow = buildRow(meta, remarks, getTransformName()); + if (!remarks.isEmpty()) { + for (int i = 0; i < remarks.size(); i++) { + CheckResult cr = (CheckResult) remarks.get(i); + logError(cr.getText()); + } + return false; + } + + data.outputRowData = outputRow.getData(); + data.outputRowMeta = outputRow.getRowMeta(); + + getPlcConnection(); + + return true; + } + return false; + } catch (Exception ex) { + setErrors(1L); + logError("Error initializing transform", ex); + return false; + } + + } + + /* + * Here, must perform the cleaning of any resource, main of the connection to + * the associated PLC. + */ + @Override + public void cleanup() { + super.cleanup(); + logBasic("Cleanup. Release connection."); + if (connwrapper != null) { + connwrapper.release(); + if (connwrapper.refCnt() <= 0) { + lookup.remove(connwrapper); + } + } + } + + + /* + * Here, must perform the cleaning of any resource. + * 1. Check if we have reference to wrapper. + * 2. Release de reference to object. + * 3. The lastone remove the global reference to connection wrapper. + * 4. Clear local references. + */ + @Override + public void dispose() { + super.dispose(); + if (connwrapper != null) { + logBasic("Dispose. Release connection: " + connwrapper.refCnt()); + connwrapper.release(); + if (connwrapper.refCnt() <= 0) { + lookup.remove(connwrapper); + } + connwrapper = null; + writeRequest = null; + + } + } + + private void getPlcConnection() { + lock.lock(); //(01) + try { + + IHopMetadataProvider metaprovider = getMetadataProvider(); + connmeta = metaprovider.getSerializer(Plc4xConnection.class).load(meta.getConnection()); + + if (connwrapper == null) { + template = new Lookup.Template<>(Plc4xWrapperConnection.class, meta.getConnection(), null); + result = lookup.lookup(template); + if (!result.allItems().isEmpty()) { + logBasic("Using connection: " + meta.getConnection()); + connwrapper = (Plc4xWrapperConnection) result.allInstances().toArray()[0]; + if (connwrapper != null) { + connwrapper.retain(); + } + } + }; + + if (connmeta == null) { + logError( + BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.Log.SetMetadata", + meta.getConnection())); + } + + if ((connmeta != null) && (connwrapper == null)) { + writeRequest = null; + try { + final PlcConnection conn = new DefaultPlcDriverManager().getConnection(connmeta.getUrl()); //(03) + Thread.sleep(200); + if (conn.isConnected()) { + logBasic("Create new connection with url : " + connmeta.getUrl()); + connwrapper = new Plc4xWrapperConnection(conn, meta.getConnection()); + lookup.add(connwrapper); + } + + } catch (Exception ex) { + setErrors(1L); + logError("Unable to create connection to PLC. " + ex.getMessage()); + } + } + + } catch (HopException ex) { + Logger.getLogger(Plc4xWrite.class.getName()).log(Level.SEVERE, null, ex); + } finally { + lock.unlock(); + } + } + + /* + * Registers the tags to write. + * In the first processing of the rows, a check of the tags is + * carried out in order that they are well formed, generating an exception + * if they are not. + */ + public boolean RegisterPlcTags() { + if ((connmeta != null) && (connwrapper != null)) { + if (connwrapper.getConnection().isConnected()) { + builder = null; + builder = connwrapper.getConnection().writeRequestBuilder(); //(05) + Integer i = null; + + for (Plc4xGeneratorField field : meta.getFields()) { + try { + i = index.get(field.getName()); + if (i != null) { + //From Input Type + if (getInputRowMeta().getValueMeta(i).getTypeDesc(). + equalsIgnoreCase(field.getType())) { + switch (getInputRowMeta().getValueMeta(i).getType()) { + case IValueMeta.TYPE_BOOLEAN: + case IValueMeta.TYPE_INTEGER: + case IValueMeta.TYPE_NUMBER: + case IValueMeta.TYPE_BIGNUMBER: + Object value = null; + switch (plcfields.get(field.getName()).getDataType()) { + case BOOL: + case BYTE: + case WORD: + value = Short.parseShort(r[i].toString()); + break; + case REAL: + value = Float.parseFloat(r[i].toString()); + break; + } + + builder.addTagAddress(field.getName(), + field.getItem(), + value); + break; + case IValueMeta.TYPE_DATE: + builder.addTagAddress(field.getName(), + field.getItem(), + Double.parseDouble(getInputRowMeta().getString(r, i))); + break; + case IValueMeta.TYPE_TIMESTAMP: + builder.addTagAddress(field.getName(), + field.getItem(), + Double.parseDouble(getInputRowMeta().getString(r, i))); + break; + case IValueMeta.TYPE_INET: + builder.addTagAddress(field.getName(), + field.getItem(), + Double.parseDouble(getInputRowMeta().getString(r, i))); + break; + case IValueMeta.TYPE_STRING: + builder.addTagAddress(field.getName(), + field.getItem(), + Double.parseDouble(getInputRowMeta().getString(r, i))); + break; + case IValueMeta.TYPE_SERIALIZABLE: + builder.addTagAddress(field.getName(), + field.getItem(), + Double.parseDouble(getInputRowMeta().getString(r, i))); + break; + + } + } + //field.setValue(inputRowMeta.getString(r, i)); + }; + } catch (HopValueException ex) { + try { + putError(getInputRowMeta(), r, 1, + "Tag error!.", r[i].toString(), + ex.getMessage()); + } catch (HopTransformException ex1) { + logError(ex1.toString()); + } + } + } + + writeRequest = builder.build(); + + } else { + setErrors(1L); + logError("PLC is not connected."); + setOutputDone(); + return false; + } + + } else { + setErrors(1L); + logError("PLC connection don't exist."); + setOutputDone(); + return false; + } + + return true; + } + + public void GetWrites() { + try { + int maxwait = Integer.parseInt(meta.getMaxwaitInMs()); + maxwait = (maxwait < 100) ? 100 : maxwait; + writeResponse = writeRequest.execute().get(2 * maxwait, TimeUnit.MILLISECONDS); + index.forEach((n, y) -> { + logDebug("Result: " + writeResponse.getResponseCode(n)); + if (writeResponse.getResponseCode(n) != PlcResponseCode.OK) { + try { + putError(getInputRowMeta(), r, 1, + "Tag error.", n, + writeResponse.getResponseCode(n).toString()); + } catch (HopTransformException ex) { + logError(ex.toString()); + } + } + }); + } catch (Exception ex) { + setErrors(1L); + logError("Unable write to PLC. " + ex.getMessage()); + } + } +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xoutput/Plc4xWriteData.java b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xoutput/Plc4xWriteData.java new file mode 100644 index 00000000000..81f9c909b81 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xoutput/Plc4xWriteData.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.plc4x.hop.transforms.plc4xoutput; + +import org.apache.plc4x.hop.transforms.plc4xinput.*; +import java.util.Date; +import org.apache.hop.core.row.IRowMeta; +import org.apache.hop.pipeline.transform.BaseTransformData; +import org.apache.hop.pipeline.transform.ITransformData; + + +public class Plc4xWriteData extends BaseTransformData implements ITransformData { + + //The Plc4xConnection metadata + public String connection; + + public IRowMeta outputRowMeta; + public Object[] outputRowData; + + public long rowLimit; + public long rowsWritten; + public Date rowDate; + public Date prevDate; + public long delay; + + + + /** + * Default constructor for SampleData. + */ + public Plc4xWriteData() { + super(); + } +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xoutput/Plc4xWriteDialog.java b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xoutput/Plc4xWriteDialog.java new file mode 100644 index 00000000000..1e2b3107ca5 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xoutput/Plc4xWriteDialog.java @@ -0,0 +1,674 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.plc4x.hop.transforms.plc4xoutput; + +import org.apache.plc4x.hop.transforms.plc4xinput.*; +import org.apache.hop.core.Const; +import org.apache.hop.core.exception.HopException; +import org.apache.hop.core.row.IRowMeta; +import org.apache.hop.core.row.value.ValueMetaFactory; +import org.apache.hop.core.util.Utils; +import org.apache.hop.core.variables.IVariables; +import org.apache.hop.i18n.BaseMessages; +import org.apache.hop.pipeline.Pipeline; +import org.apache.hop.pipeline.PipelineMeta; +import org.apache.hop.pipeline.PipelinePreviewFactory; +import org.apache.hop.pipeline.transform.BaseTransformMeta; +import org.apache.hop.pipeline.transform.ITransformDialog; +import org.apache.hop.ui.core.ConstUi; +import org.apache.hop.ui.core.dialog.BaseDialog; +import org.apache.hop.ui.core.dialog.EnterNumberDialog; +import org.apache.hop.ui.core.dialog.EnterTextDialog; +import org.apache.hop.ui.core.dialog.ErrorDialog; +import org.apache.hop.ui.core.dialog.PreviewRowsDialog; +import org.apache.hop.ui.core.widget.ColumnInfo; +import org.apache.hop.ui.core.widget.MetaSelectionLine; +import org.apache.hop.ui.core.widget.TableView; +import org.apache.hop.ui.core.widget.TextVar; +import org.apache.hop.ui.pipeline.dialog.PipelinePreviewProgressDialog; +import org.apache.hop.ui.pipeline.transform.BaseTransformDialog; +import org.apache.hop.ui.pipeline.transform.ITableItemInsertListener; +import org.apache.hop.ui.util.SwtSvgImageUtil; +import org.apache.plc4x.hop.metadata.Plc4xConnection; +import org.apache.plc4x.hop.transforms.util.Plc4xGeneratorField; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.*; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; + +public class Plc4xWriteDialog extends BaseTransformDialog implements ITransformDialog { + private static final Class PKG = Plc4xWriteDialog.class; // Needed by Translator + + private MetaSelectionLine wConnection; + + private Label wlLimit; + private TextVar wLimit; + + private Button wNeverEnding; + + private Label wlMaxwait; + private TextVar wMaxwait; + + private Label wlInterval; + private TextVar wInterval; + + private Label wlRowTimeField; + private TextVar wRowTimeField; + + private Label wlLastTimeField; + private TextVar wLastTimeField; + + private TableView wFields; + + private Button wGetPrvFields; + + private final Plc4xWriteMeta input; + + public Plc4xWriteDialog(Shell parent, IVariables variables , Object in, PipelineMeta pipelineMeta, String sname ) { + super( parent, variables, (BaseTransformMeta) in, pipelineMeta, sname ); + input = (Plc4xWriteMeta) in; + } + + @Override + public String open() { + Shell parent = getParent(); + + shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN); + props.setLook(shell); + setShellImage(shell, input); + + ModifyListener lsMod = e -> input.setChanged(); + changed = input.hasChanged(); + + FormLayout formLayout = new FormLayout(); + formLayout.marginWidth = Const.FORM_MARGIN; + formLayout.marginHeight = Const.FORM_MARGIN; + + shell.setLayout(formLayout); + shell.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.DialogTitle")); + + int middle = props.getMiddlePct(); + int margin = props.getMargin(); + + // Filename line + wlTransformName = new Label(shell, SWT.RIGHT); + wlTransformName.setText(BaseMessages.getString(PKG, "System.Label.TransformName")); + props.setLook(wlTransformName); + fdlTransformName = new FormData(); + fdlTransformName.left = new FormAttachment(0, 0); + fdlTransformName.right = new FormAttachment(middle, -margin); + fdlTransformName.top = new FormAttachment(0, margin); + wlTransformName.setLayoutData(fdlTransformName); + + wTransformName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + wTransformName.setText(transformName); + props.setLook(wTransformName); + wTransformName.addModifyListener(lsMod); + fdTransformName = new FormData(); + fdTransformName.left = new FormAttachment(middle, 0); + fdTransformName.top = new FormAttachment(0, margin); + fdTransformName.right = new FormAttachment(100, 0); + wTransformName.setLayoutData(fdTransformName); + + // Connection line + wConnection = + new MetaSelectionLine<>( + variables, + metadataProvider, + Plc4xConnection.class, + shell, + SWT.NONE, + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Connection.Label"), + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Connection.Tooltip")); + FormData fdConnection = new FormData(); + fdConnection.left = new FormAttachment(0, 0); + fdConnection.right = new FormAttachment(100, 0); + fdConnection.top = new FormAttachment(wTransformName, margin); + wConnection.setLayoutData(fdConnection); + props.setLook(wConnection); + try { + wConnection.fillItems(); + } catch (Exception e) { + new ErrorDialog(shell, "Error", "Error listing Cassandra connection metadata objects", e); + } + + Control lastControl = wConnection; + + wlLimit = new Label(shell, SWT.RIGHT); + wlLimit.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Limit.Label")); + props.setLook(wlLimit); + FormData fdlLimit = new FormData(); + fdlLimit.left = new FormAttachment(0, 0); + fdlLimit.right = new FormAttachment(middle, -margin); + fdlLimit.top = new FormAttachment(lastControl, margin); + wlLimit.setLayoutData(fdlLimit); + wLimit = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wLimit); + wLimit.addModifyListener(lsMod); + FormData fdLimit = new FormData(); + fdLimit.left = new FormAttachment(middle, 0); + fdLimit.top = new FormAttachment(lastControl, margin); + fdLimit.right = new FormAttachment(100, 0); + wLimit.setLayoutData(fdLimit); + lastControl = wLimit; + + Label wlNeverEnding = new Label(shell, SWT.RIGHT); + wlNeverEnding.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.NeverEnding.Label")); + props.setLook(wlNeverEnding); + FormData fdlNeverEnding = new FormData(); + fdlNeverEnding.left = new FormAttachment(0, 0); + fdlNeverEnding.right = new FormAttachment(middle, -margin); + fdlNeverEnding.top = new FormAttachment(lastControl, margin); + wlNeverEnding.setLayoutData(fdlNeverEnding); + wNeverEnding = new Button(shell, SWT.CHECK); + props.setLook(wNeverEnding); + wNeverEnding.addSelectionListener( + new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + setActive(); + input.setChanged(); + } + }); + FormData fdNeverEnding = new FormData(); + fdNeverEnding.left = new FormAttachment(middle, 0); + fdNeverEnding.top = new FormAttachment(wlNeverEnding, 0, SWT.CENTER); + fdNeverEnding.right = new FormAttachment(100, 0); + wNeverEnding.setLayoutData(fdNeverEnding); + lastControl = wlNeverEnding; + + wlMaxwait = new Label(shell, SWT.RIGHT); + wlMaxwait.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Maxwait.Label")); + props.setLook(wlMaxwait); + FormData fdlMaxwait = new FormData(); + fdlMaxwait.left = new FormAttachment(0, 0); + fdlMaxwait.right = new FormAttachment(middle, -margin); + fdlMaxwait.top = new FormAttachment(lastControl, margin); + wlMaxwait.setLayoutData(fdlMaxwait); + wMaxwait = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wMaxwait); + wMaxwait.addModifyListener(lsMod); + FormData fdMaxwait = new FormData(); + fdMaxwait.left = new FormAttachment(middle, 0); + fdMaxwait.top = new FormAttachment(lastControl, margin); + fdMaxwait.right = new FormAttachment(100, 0); + wMaxwait.setLayoutData(fdMaxwait); + lastControl = wMaxwait; + + wlInterval = new Label(shell, SWT.RIGHT); + wlInterval.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Interval.Label")); + props.setLook(wlInterval); + FormData fdlInterval = new FormData(); + fdlInterval.left = new FormAttachment(0, 0); + fdlInterval.right = new FormAttachment(middle, -margin); + fdlInterval.top = new FormAttachment(lastControl, margin); + wlInterval.setLayoutData(fdlInterval); + wInterval = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wInterval); + wInterval.addModifyListener(lsMod); + FormData fdInterval = new FormData(); + fdInterval.left = new FormAttachment(middle, 0); + fdInterval.top = new FormAttachment(lastControl, margin); + fdInterval.right = new FormAttachment(100, 0); + wInterval.setLayoutData(fdInterval); + lastControl = wInterval; + + /* + wlRowTimeField = new Label(shell, SWT.RIGHT); + wlRowTimeField.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.RowTimeField.Label")); + props.setLook(wlRowTimeField); + FormData fdlRowTimeField = new FormData(); + fdlRowTimeField.left = new FormAttachment(0, 0); + fdlRowTimeField.right = new FormAttachment(middle, -margin); + fdlRowTimeField.top = new FormAttachment(lastControl, margin); + wlRowTimeField.setLayoutData(fdlRowTimeField); + wRowTimeField = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wRowTimeField); + wRowTimeField.addModifyListener(lsMod); + FormData fdRowTimeField = new FormData(); + fdRowTimeField.left = new FormAttachment(middle, 0); + fdRowTimeField.top = new FormAttachment(lastControl, margin); + fdRowTimeField.right = new FormAttachment(100, 0); + wRowTimeField.setLayoutData(fdRowTimeField); + lastControl = wRowTimeField; + + wlLastTimeField = new Label(shell, SWT.RIGHT); + wlLastTimeField.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.LastTimeField.Label")); + props.setLook(wlLastTimeField); + FormData fdlLastTimeField = new FormData(); + fdlLastTimeField.left = new FormAttachment(0, 0); + fdlLastTimeField.right = new FormAttachment(middle, -margin); + fdlLastTimeField.top = new FormAttachment(lastControl, margin); + wlLastTimeField.setLayoutData(fdlLastTimeField); + wLastTimeField = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wLastTimeField); + wLastTimeField.addModifyListener(lsMod); + FormData fdLastTimeField = new FormData(); + fdLastTimeField.left = new FormAttachment(middle, 0); + fdLastTimeField.top = new FormAttachment(lastControl, margin); + fdLastTimeField.right = new FormAttachment(100, 0); + wLastTimeField.setLayoutData(fdLastTimeField); + lastControl = wLastTimeField; + */ + wOk = new Button(shell, SWT.PUSH); + wOk.setText(BaseMessages.getString(PKG, "System.Button.OK")); + wOk.addListener(SWT.Selection, e -> ok()); + + wGet = new Button(shell, SWT.PUSH); + wGet.setText(BaseMessages.getString(PKG, "Get Fields")); + wGet.addListener(SWT.Selection, e -> getfields()); + + wPreview = new Button(shell, SWT.PUSH); + wPreview.setText(BaseMessages.getString(PKG, "System.Button.Preview")); + wPreview.addListener(SWT.Selection, e -> preview()); + + wCancel = new Button(shell, SWT.PUSH); + wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); + wCancel.addListener(SWT.Selection, e -> cancel()); + + setButtonPositions(new Button[] {wOk, wPreview, wGet, wCancel}, margin, null); + + Label wlFields = new Label(shell, SWT.NONE); + wlFields.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Fields.Label")); + props.setLook(wlFields); + FormData fdlFields = new FormData(); + fdlFields.left = new FormAttachment(0, 0); + fdlFields.top = new FormAttachment(lastControl, margin); + wlFields.setLayoutData(fdlFields); + lastControl = wlFields; + + final int nrFields = input.getFields().size(); + + ColumnInfo[] colinf = + new ColumnInfo[] { + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Name"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Fields.Item"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Type"), + ColumnInfo.COLUMN_TYPE_CCOMBO, + ValueMetaFactory.getValueMetaNames()), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Format"), + ColumnInfo.COLUMN_TYPE_FORMAT, + 2), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Length"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Precision"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Currency"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Decimal"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Group"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Value"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.SetEmptyString"), + ColumnInfo.COLUMN_TYPE_CCOMBO, + new String[] { + BaseMessages.getString(PKG, "System.Combo.Yes"), + BaseMessages.getString(PKG, "System.Combo.No") + }) + }; + + wFields = + new TableView( + variables, + shell, + SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, + colinf, + nrFields, + lsMod, + props); + + FormData fdFields = new FormData(); + fdFields.left = new FormAttachment(0, 0); + fdFields.top = new FormAttachment(lastControl, margin); + fdFields.right = new FormAttachment(100, 0); + fdFields.bottom = new FormAttachment(wOk, -2 * margin); + wFields.setLayoutData(fdFields); + + lsResize = + event -> { + Point size = shell.getSize(); + wFields.setSize(size.x - 10, size.y - 50); + wFields.table.setSize(size.x - 10, size.y - 50); + wFields.redraw(); + }; + shell.addListener(SWT.Resize, lsResize); + + getData(); + input.setChanged(changed); + + BaseDialog.defaultShellHandling(shell, c -> ok(), c -> cancel()); + + return transformName; + }; + + public void setActive() { + boolean neverEnding = wNeverEnding.getSelection(); + + wlLimit.setEnabled(!neverEnding); + wLimit.setEnabled(!neverEnding); + + //wlInterval.setEnabled(neverEnding); + //wInterval.setEnabled(neverEnding); + + //wlRowTimeField.setEnabled(neverEnding); + //wRowTimeField.setEnabled(neverEnding); + + //wlLastTimeField.setEnabled(neverEnding); + //wLastTimeField.setEnabled(neverEnding); + } + + + + private Image getImage() { + return SwtSvgImageUtil.getImage( shell.getDisplay(), getClass().getClassLoader(), "plc4x_toddy_read.svg", ConstUi.LARGE_ICON_SIZE, + ConstUi.LARGE_ICON_SIZE ); + } + + /** + * Copy information from the meta-data input to the dialog fields. + * + */ + public void getData() { + if (isDebug()) { + logDebug("getting fields info..."); + } + if (input.getConnection() == null) { + wConnection.setText(""); + } else { + wConnection.setText(input.getConnection()); + } + + wLimit.setText(input.getRowLimit()); + wNeverEnding.setSelection(input.isNeverEnding()); + wMaxwait.setText(Const.NVL(input.getMaxwaitInMs(), "")); + wInterval.setText(Const.NVL(input.getIntervalInMs(), "")); + // wRowTimeField.setText(Const.NVL(input.getRowTimeField(), "")); + //wLastTimeField.setText(Const.NVL(input.getLastTimeField(), "")); + + for (int i = 0; i < input.getFields().size(); i++) { + Plc4xGeneratorField field = input.getFields().get(i); + TableItem item = wFields.table.getItem(i); + int col = 1; + item.setText(col++, Const.NVL(field.getName(), "")); + + item.setText(col++, Const.NVL(field.getItem(), "")); + + String type = field.getType(); + String format = field.getFormat(); + String length = field.getLength() < 0 ? "" : ("" + field.getLength()); + String prec = field.getPrecision() < 0 ? "" : ("" + field.getPrecision()); + + String curr = field.getCurrency(); + String group = field.getGroup(); + String decim = field.getDecimal(); + String def = field.getValue(); + + item.setText(col++, Const.NVL(type, "")); + item.setText(col++, Const.NVL(format, "")); + item.setText(col++, Const.NVL(length, "")); + item.setText(col++, Const.NVL(prec, "")); + item.setText(col++, Const.NVL(curr, "")); + item.setText(col++, Const.NVL(decim, "")); + item.setText(col++, Const.NVL(group, "")); + item.setText(col++, Const.NVL(def, "")); + item.setText( + col++, + field.isSetEmptyString() + ? BaseMessages.getString(PKG, "System.Combo.Yes") + : BaseMessages.getString(PKG, "System.Combo.No")); + } + + wFields.setRowNums(); + wFields.optWidth(true); + + setActive(); + + wTransformName.selectAll(); + wTransformName.setFocus(); + } + + /** + * Stores the information from the dialog box in meta-data. + * + * @param meta + */ + private void getInfo( Plc4xWriteMeta meta) throws HopException { + meta.setConnection(wConnection.getText()); + meta.setRowLimit(wLimit.getText()); + meta.setNeverEnding(wNeverEnding.getSelection()); + meta.setMaxwaitInMs(wMaxwait.getText()); + meta.setIntervalInMs(wInterval.getText()); + //meta.setRowTimeField(wRowTimeField.getText()); + //meta.setLastTimeField(wLastTimeField.getText()); + + meta.getFields().clear(); + + // CHECKSTYLE:Indentation:OFF + for (TableItem item : wFields.getNonEmptyItems()) { + Plc4xGeneratorField field = new Plc4xGeneratorField(); + field.setName(item.getText(1)); + field.setItem(item.getText(2)); + field.setFormat(item.getText(4)); + field.setLength(Const.toInt(item.getText(5), -1)); + field.setPrecision(Const.toInt(item.getText(6), -1)); + field.setCurrency(item.getText(7)); + field.setDecimal(item.getText(8)); + field.setGroup(item.getText(9)); + field.setValue(field.isSetEmptyString() ? "" : item.getText(10)); + field.setSetEmptyString( + BaseMessages.getString(PKG, "System.Combo.Yes").equalsIgnoreCase(item.getText(11))); + field.setType(field.isSetEmptyString() ? "String" : item.getText(3)); + + meta.getFields().add(field); + } + } + + /** + * Get previos transform fields. + * Clear all information in actual fields. + * + * @param meta + */ + private void getPrevFields(Plc4xWriteMeta meta) throws HopException { + IRowMeta r = pipelineMeta.getPrevTransformFields(variables, transformMeta); + if (r != null){ + meta.getFields().clear(); + r.getValueMetaList().forEach((f)->{ + Plc4xGeneratorField field = new Plc4xGeneratorField(); + field.setName(f.getName()); + field.setItem(""); + field.setType(f.getTypeDesc()); + field.setFormat(f.getFormatMask()); + field.setLength(f.getLength()); + field.setPrecision(f.getPrecision()); + field.setCurrency(f.getCurrencySymbol()); + field.setDecimal(f.getDecimalSymbol()); + field.setGroup(f.getGroupingSymbol()); + field.setValue(f.getStringEncoding()); + meta.getFields().add(field); + }); + } + } + + + /** + * Cancel the dialog. + */ + private void cancel() { + transformName = null; + input.setChanged( changed ); + dispose(); + } + + private void ok() { + if (Utils.isEmpty(wTransformName.getText())) { + return; + } + + transformName = wTransformName.getText(); // return value + try { + getInfo(new Plc4xWriteMeta()); // to see if there is an exception + getInfo(input); // to put the content on the input structure for real if all is well. + dispose(); + } catch (HopException e) { + new ErrorDialog( + shell, + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Title"), + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Message"), + e); + } + } + +private void getfields() { + try { + + IRowMeta r = pipelineMeta.getPrevTransformFields(variables, transformName); + + if (r != null && !r.isEmpty()) { + ITableItemInsertListener listener = + (tableItem, v) -> { + + tableItem.setText(2, ""); + tableItem.setText(3, v.getTypeDesc()); + tableItem.setText(4, v.getFormatMask()==null?"":v.getFormatMask()); + tableItem.setText(5, Integer.toString(v.getLength())); + tableItem.setText(6, Integer.toString(v.getPrecision())); + tableItem.setText(7, v.getCurrencySymbol()==null?"":v.getCurrencySymbol()); + tableItem.setText(8, v.getDecimalSymbol()==null?"":v.getDecimalSymbol()); + tableItem.setText(9, v.getGroupingSymbol()==null?"":v.getGroupingSymbol()); + //tableItem.setText(10, "N"); + tableItem.setText(11, "N"); + return true; + }; + BaseTransformDialog.getFieldsFromPrevious( + r, wFields, 1, new int[] {1}, null, -1, -1, listener); + } + + + + + } catch (Exception ex){ + new ErrorDialog( + shell, + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Title"), + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Message"), + ex); + } +} + + /** + * Preview the data generated by this transform. This generates a pipeline using this transform & + * a dummy and previews it. + */ + private void preview() { + Plc4xWriteMeta oneMeta = new Plc4xWriteMeta(); + try { + getInfo(oneMeta); + } catch (HopException e) { + new ErrorDialog( + shell, + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Title"), + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Message"), + e); + return; + } + + PipelineMeta previewMeta = + PipelinePreviewFactory.generatePreviewPipeline( + pipelineMeta.getMetadataProvider(), oneMeta, wTransformName.getText()); + + EnterNumberDialog numberDialog = + new EnterNumberDialog( + shell, + props.getDefaultPreviewSize(), + BaseMessages.getString(PKG, "System.Dialog.EnterPreviewSize.Title"), + BaseMessages.getString(PKG, "System.Dialog.EnterPreviewSize.Message")); + int previewSize = numberDialog.open(); + if (previewSize > 0) { + PipelinePreviewProgressDialog progressDialog = + new PipelinePreviewProgressDialog( + shell, + variables, + previewMeta, + new String[] {wTransformName.getText()}, + new int[] {previewSize}); + progressDialog.open(); + + Pipeline pipeline = progressDialog.getPipeline(); + String loggingText = progressDialog.getLoggingText(); + + if (!progressDialog.isCancelled()) { + if (pipeline.getResult() != null && pipeline.getResult().getNrErrors() > 0) { + EnterTextDialog etd = + new EnterTextDialog( + shell, + BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), + BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), + loggingText, + true); + etd.setReadOnly(); + etd.open(); + } + } + + PreviewRowsDialog prd = + new PreviewRowsDialog( + shell, + variables, + SWT.NONE, + wTransformName.getText(), + progressDialog.getPreviewRowsMeta(wTransformName.getText()), + progressDialog.getPreviewRows(wTransformName.getText()), + loggingText); + prd.open(); + } + } + +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xoutput/Plc4xWriteMeta.java b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xoutput/Plc4xWriteMeta.java new file mode 100644 index 00000000000..d32959fe587 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xoutput/Plc4xWriteMeta.java @@ -0,0 +1,309 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.plc4x.hop.transforms.plc4xoutput; + +import org.apache.plc4x.hop.transforms.plc4xinput.*; +import java.util.ArrayList; +import org.apache.hop.core.ICheckResult; +import org.apache.hop.core.annotations.Transform; +import org.apache.hop.core.exception.HopTransformException; +import org.apache.hop.core.exception.HopXmlException; +import org.apache.hop.core.row.IRowMeta; +import org.apache.hop.core.variables.IVariables; +import org.apache.hop.core.xml.XmlHandler; +import org.apache.hop.metadata.api.IHopMetadataProvider; +import org.apache.hop.pipeline.Pipeline; +import org.apache.hop.pipeline.PipelineMeta; +import org.apache.hop.pipeline.transform.BaseTransformMeta; +import org.apache.hop.pipeline.transform.ITransformMeta; +import org.apache.hop.pipeline.transform.TransformMeta; +import org.w3c.dom.Node; + +import java.util.List; +import org.apache.hop.core.Const; +import org.apache.hop.core.RowMetaAndData; +import org.apache.hop.core.row.IValueMeta; +import org.apache.hop.metadata.api.HopMetadataProperty; +import org.apache.hop.pipeline.transform.ITransformIOMeta; +import org.apache.hop.pipeline.transform.TransformIOMeta; +import org.apache.plc4x.hop.transforms.util.Plc4xGeneratorField; + +/** + * Meta data for the sample transform. + */ +@Transform( + id = "plc4x-write", + name = "i18n::Plc4x.Read.Name", + description = "i18n::Plc4x.Read.Description", + image = "plc4x_write.svg", + categoryDescription = "i18n:org.apache.plc4x.hop.transforms.plc4xoutput:Plc4x.Category.plc4x", + documentationUrl = "https://plc4x.apache.org/users/integrations/apache-calcite.html" +) +public class Plc4xWriteMeta extends BaseTransformMeta { + + private static final Class PKG = Plc4xWriteMeta.class; // Needed by Translator + + + @HopMetadataProperty( + key = "connection", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.Connection") + private String connection; + + @HopMetadataProperty( + key = "never_ending", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.NeverEnding") + private boolean neverEnding; + + @HopMetadataProperty( + key = "maxwait_in_ms", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.MaxwaitInMs") + private String maxwaitInMs; + + @HopMetadataProperty( + key = "interval_in_ms", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.IntervalInMs") + private String intervalInMs; + + @HopMetadataProperty( + key = "row_time_field", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.RowTimeField") + private String rowTimeField; + + @HopMetadataProperty( + key = "last_time_field", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.LastTimeField") + private String lastTimeField; + + @HopMetadataProperty( + key = "limit", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.RowLimit") + private String rowLimit; + + @HopMetadataProperty( + groupKey = "fields", + key = "field", + injectionGroupDescription = "Plc4x.Read.Meta.Injection.Fields", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.Fields") + private List fields; + + public Plc4xWriteMeta() { + fields = new ArrayList<>(); + + rowLimit = "10"; + neverEnding = false; + maxwaitInMs = "1000"; + intervalInMs = "5000"; + rowTimeField = "now"; + lastTimeField = "last"; + } + + public Plc4xWriteMeta(Plc4xWriteMeta m) { + this.connection = m.connection; + this.neverEnding = m.neverEnding; + this.intervalInMs = m.intervalInMs; + this.rowTimeField = m.rowTimeField; + this.lastTimeField = m.lastTimeField; + this.rowLimit = m.rowLimit; + this.fields = new ArrayList<>(); + for (Plc4xGeneratorField field : m.fields) { + this.fields.add(new Plc4xGeneratorField(field)); + } + } + + @Override + public Plc4xWriteMeta clone() { + return new Plc4xWriteMeta(this); + } + + + @Override + public void getFields( IRowMeta inputRowMeta, String name, IRowMeta[] info, TransformMeta nextTransform, + IVariables variables, IHopMetadataProvider metadataProvider ) throws HopTransformException { + try { + List remarks = new ArrayList<>(); + RowMetaAndData rowMetaAndData = Plc4xWrite.buildRow(this, remarks, name); + + if (!remarks.isEmpty()) { + StringBuilder stringRemarks = new StringBuilder(); + for (ICheckResult remark : remarks) { + stringRemarks.append(remark.toString()).append(Const.CR); + } + throw new HopTransformException(stringRemarks.toString()); + } + for (IValueMeta valueMeta : rowMetaAndData.getRowMeta().getValueMetaList()) { + valueMeta.setOrigin(name); + } + + inputRowMeta.mergeRowMeta(rowMetaAndData.getRowMeta()); + } catch (Exception e) { + throw new HopTransformException(e); + } + } + + + public Plc4xWrite createTransform(TransformMeta transformMeta, Plc4xWriteData data, int copyNr, + PipelineMeta pipelineMeta, Pipeline pipeline ) { + return new Plc4xWrite( transformMeta, this, data, copyNr, pipelineMeta, pipeline ); + } + + public Plc4xWriteData getTransformData() { + return new Plc4xWriteData(); + } +/* + @Override + public void loadXml( Node transformNode, IHopMetadataProvider metadataProvider ) throws HopXmlException { + //load the saved values from the transformnode + String sampleValue = XmlHandler.getTagValue( transformNode, "sampleValue" ); + + } +*/ + @Override + public void setDefault() { + //default values when creating a new transform + } + + + /** + * Returns the Input/Output metadata for this transform. + * The generator transform only produces output, does not accept input! + * TransformIOMeta(inputAcceptor, outputProducer, inputOptional, outputDynamic, inputDynamic) + */ + @Override + public ITransformIOMeta getTransformIOMeta() { + return new TransformIOMeta(true, true, false, false, false, false); + } + + /** + * Gets Plc4xConnection metadata name. + * + * @return value of intervalInMs + */ + public String getConnection() { + return connection; + } + + /** @param connection */ + public void setConnection(String connection) { + this.connection = connection; + } + + + /** + * Gets neverEnding + * + * @return value of neverEnding + */ + public boolean isNeverEnding() { + return neverEnding; + } + + /** @param neverEnding The neverEnding to set */ + public void setNeverEnding(boolean neverEnding) { + this.neverEnding = neverEnding; + } + + /** + * Gets intervalInMs + * + * @return value of intervalInMs + */ + public String getMaxwaitInMs() { + return maxwaitInMs; + } + + /** @param intervalInMs The intervalInMs to set */ + public void setMaxwaitInMs(String maxwaitInMs) { + this.maxwaitInMs = maxwaitInMs; + } + + /** + * Gets intervalInMs + * + * @return value of intervalInMs + */ + public String getIntervalInMs() { + return intervalInMs; + } + + /** @param intervalInMs The intervalInMs to set */ + public void setIntervalInMs(String intervalInMs) { + this.intervalInMs = intervalInMs; + } + + /** + * Gets rowTimeField + * + * @return value of rowTimeField + */ + public String getRowTimeField() { + return rowTimeField; + } + + /** @param rowTimeField The rowTimeField to set */ + public void setRowTimeField(String rowTimeField) { + this.rowTimeField = rowTimeField; + } + + /** + * Gets lastTimeField + * + * @return value of lastTimeField + */ + public String getLastTimeField() { + return lastTimeField; + } + + /** @param lastTimeField The lastTimeField to set */ + public void setLastTimeField(String lastTimeField) { + this.lastTimeField = lastTimeField; + } + + /** + * Gets rowLimit + * + * @return value of rowLimit + */ + public String getRowLimit() { + return rowLimit; + } + + /** @param rowLimit The rowLimit to set */ + public void setRowLimit(String rowLimit) { + this.rowLimit = rowLimit; + } + + /** + * Gets fields + * + * @return value of fields + */ + public List getFields() { + return fields; + } + + /** @param fields The fields to set */ + public void setFields(List fields) { + this.fields = fields; + } + + @Override + public boolean supportsErrorHandling() { + return true; + } + +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xsubs/Plc4xSubs.java b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xsubs/Plc4xSubs.java new file mode 100644 index 00000000000..efc1dc7df9c --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xsubs/Plc4xSubs.java @@ -0,0 +1,784 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.plc4x.hop.transforms.plc4xsubs; + +import java.time.Duration; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.ReentrantLock; +import java.util.function.Consumer; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.apache.commons.codec.binary.BinaryCodec; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.hop.core.CheckResult; +import org.apache.hop.core.Const; +import org.apache.hop.core.ICheckResult; +import org.apache.hop.core.RowMetaAndData; +import org.apache.hop.core.exception.HopException; +import org.apache.hop.core.exception.HopPluginException; +import org.apache.hop.core.exception.HopValueException; +import org.apache.hop.core.logging.LogLevel; +import org.apache.hop.core.row.IRowMeta; +import org.apache.hop.core.row.IValueMeta; +import org.apache.hop.core.row.RowDataUtil; +import org.apache.hop.core.row.RowMeta; +import org.apache.hop.core.row.value.ValueMetaDate; +import org.apache.hop.core.row.value.ValueMetaFactory; +import org.apache.hop.core.util.StringUtil; +import org.apache.hop.core.util.Utils; +import org.apache.hop.i18n.BaseMessages; +import org.apache.hop.metadata.api.IHopMetadataProvider; +import org.apache.hop.pipeline.Pipeline; +import org.apache.hop.pipeline.PipelineMeta; +import org.apache.hop.pipeline.transform.BaseTransform; +import org.apache.hop.pipeline.transform.ITransform; +import org.apache.hop.pipeline.transform.TransformMeta; +import org.apache.plc4x.hop.metadata.Plc4xConnection; +import org.apache.plc4x.hop.metadata.util.Plc4xLookup; +import org.apache.plc4x.hop.transforms.util.Plc4xGeneratorField; +import org.apache.plc4x.hop.transforms.util.Plc4xPlcTag; +import org.apache.plc4x.hop.transforms.util.Plc4xPlcSubscriptionTag; +import org.apache.plc4x.hop.metadata.util.Plc4xWrapperConnection; +import org.apache.plc4x.hop.transforms.plc4xinput.Plc4xRead; +import org.apache.plc4x.java.DefaultPlcDriverManager; +import org.apache.plc4x.java.api.PlcConnection; +import org.apache.plc4x.java.api.exceptions.PlcProtocolException; +import org.apache.plc4x.java.api.listener.ConnectionStateListener; +import org.apache.plc4x.java.api.messages.PlcReadRequest; +import org.apache.plc4x.java.api.messages.PlcReadResponse; +import org.apache.plc4x.java.api.messages.PlcSubscriptionEvent; +import org.apache.plc4x.java.api.messages.PlcSubscriptionRequest; +import org.apache.plc4x.java.api.messages.PlcSubscriptionResponse; +import org.apache.plc4x.java.api.model.PlcConsumerRegistration; +import org.apache.plc4x.java.api.model.PlcTag; +import org.apache.plc4x.java.api.types.PlcValueType; +import static org.apache.plc4x.java.api.types.PlcValueType.BYTE; +import static org.apache.plc4x.java.api.types.PlcValueType.DATE; +import static org.apache.plc4x.java.api.types.PlcValueType.DATE_AND_TIME; +import static org.apache.plc4x.java.api.types.PlcValueType.DWORD; +import static org.apache.plc4x.java.api.types.PlcValueType.LDATE; +import static org.apache.plc4x.java.api.types.PlcValueType.LDATE_AND_TIME; +import static org.apache.plc4x.java.api.types.PlcValueType.LTIME; +import static org.apache.plc4x.java.api.types.PlcValueType.LWORD; +import static org.apache.plc4x.java.api.types.PlcValueType.STRING; +import static org.apache.plc4x.java.api.types.PlcValueType.TIME; +import static org.apache.plc4x.java.api.types.PlcValueType.WORD; +import org.apache.plc4x.java.s7.events.S7CyclicEvent; +import org.apache.plc4x.java.s7.events.S7Event; +import org.apache.plc4x.java.s7.readwrite.protocol.S7HPlcConnection; +import org.apache.plc4x.java.s7.readwrite.tag.S7SubscriptionTag; +import org.apache.plc4x.java.spi.utils.hex.Hex; +import org.openide.util.Lookup; + +/** + * + * + */ +public class Plc4xSubs extends BaseTransform implements ConnectionStateListener { + + private static final Class PKG = Plc4xSubs.class; // Needed by Translator + + private Plc4xConnection connmeta = null; + private Plc4xWrapperConnection connwrapper = null; + private PlcSubscriptionRequest subsRequest = null; + private PlcSubscriptionResponse subsResponse = null; + + private PlcConsumerRegistration csmr; + + private int maxwait = 0; + private static final ReentrantLock lock = new ReentrantLock(); + + private Plc4xLookup lookup = Plc4xLookup.getDefault(); + private Lookup.Template template = null; + private Lookup.Result result = null; + + private ConcurrentLinkedQueue events = new ConcurrentLinkedQueue(); + private boolean stopBundle = false; + private boolean isConnected = false; + + private String jobId = null; + + private BinaryCodec binarycodec = new BinaryCodec(); + + private static final String DUMMY = "dummy"; + private static final String DATA = "DATA_"; + + private int counter = 0; + private String strData; + private PlcValueType valuetype = null; + + private Map tags_index = new HashMap(); + private Map> plctags = new HashMap(); + + public Plc4xSubs(TransformMeta transformMeta, Plc4xSubsMeta meta, Plc4xSubsData data, int copyNr, PipelineMeta pipelineMeta, + Pipeline pipeline) { + super(transformMeta, meta, data, copyNr, pipelineMeta, pipeline); + } + + /* + * Including Date and Time field for every row + * + * @param meta Meta data from user dialog + * @param remarks Error registers + * @param origin transform instance name + */ + public static final RowMetaAndData buildRow( + Plc4xSubsMeta meta, List remarks, String origin) throws HopPluginException { + IRowMeta rowMeta = new RowMeta(); + Object[] rowData = RowDataUtil.allocateRowData(meta.getFields().size() + 2); + int index = 0; + + if (!Utils.isEmpty(meta.getRowTimeField())) { + rowMeta.addValueMeta(new ValueMetaDate(meta.getRowTimeField())); + rowData[index++] = null; + } + + if (!Utils.isEmpty(meta.getLastTimeField())) { + rowMeta.addValueMeta(new ValueMetaDate(meta.getLastTimeField())); + rowData[index++] = null; + } + + for (Plc4xGeneratorField field : meta.getFields()) { + int typeString = ValueMetaFactory.getIdForValueMeta(field.getType()); + if (StringUtils.isNotEmpty(field.getType())) { + + IValueMeta valueMeta + = ValueMetaFactory.createValueMeta(field.getName(), typeString); // build a + // value! + valueMeta.setLength(field.getLength()); + valueMeta.setPrecision(field.getPrecision()); + valueMeta.setConversionMask(field.getFormat()); + valueMeta.setCurrencySymbol(field.getCurrency()); + valueMeta.setGroupingSymbol(field.getGroup()); + valueMeta.setDecimalSymbol(field.getDecimal()); + valueMeta.setOrigin(origin); + + IValueMeta stringMeta = ValueMetaFactory.cloneValueMeta(valueMeta, IValueMeta.TYPE_STRING); + + if (field.isSetEmptyString()) { + // Set empty string + rowData[index] = StringUtil.EMPTY_STRING; + } else { + String stringValue = field.getValue(); + + // If the value is empty: consider it to be NULL. + if (Utils.isEmpty(stringValue)) { + rowData[index] = null; + + if (valueMeta.getType() == IValueMeta.TYPE_NONE) { + String message + = BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.CheckResult.SpecifyTypeError", + valueMeta.getName(), + stringValue); + remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, null)); + } + } else { + // Convert the data from String to the specified type ... + // + try { + System.out.println("stringValue: " + stringValue); + rowData[index] = valueMeta.convertData(stringMeta, stringValue); + } catch (HopValueException e) { + switch (valueMeta.getType()) { + case IValueMeta.TYPE_NUMBER: + String message + = BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.BuildRow.Error.Parsing.Number", + valueMeta.getName(), + stringValue, + e.toString()); + remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, null)); + break; + + case IValueMeta.TYPE_DATE: + message + = BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.BuildRow.Error.Parsing.Date", + valueMeta.getName(), + stringValue, + e.toString()); + remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, null)); + break; + + case IValueMeta.TYPE_INTEGER: + message + = BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.BuildRow.Error.Parsing.Integer", + valueMeta.getName(), + stringValue, + e.toString()); + remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, null)); + break; + + case IValueMeta.TYPE_BIGNUMBER: + message + = BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.BuildRow.Error.Parsing.BigNumber", + valueMeta.getName(), + stringValue, + e.toString()); + remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, null)); + break; + + case IValueMeta.TYPE_TIMESTAMP: + message + = BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.BuildRow.Error.Parsing.Timestamp", + valueMeta.getName(), + stringValue, + e.toString()); + remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, null)); + break; + + default: + // Boolean and binary don't throw errors normally, so it's probably an unspecified + // error problem... + message + = BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.CheckResult.SpecifyTypeError", + valueMeta.getName(), + stringValue); + remarks.add(new CheckResult(ICheckResult.TYPE_RESULT_ERROR, message, null)); + break; + } + } + } + } + + // Now add value to the row! + // This is in fact a copy from the fields row, but now with data. + rowMeta.addValueMeta(valueMeta); + index++; + } + } + + return new RowMetaAndData(rowMeta, rowData); + } + + /* + * 1. Block the other instances by means of a lock. + * 2. Try to locate an existing connection. + * 3. If it doesn't exist, it tries to take control of the routine to + * create an instance of PlcConnection and his wrapper. + * 4. Register the connection wrapper for global access. + * 5. If the connection to the PLC is made, then it creates the query + * and executes it. + * + */ + @Override + public boolean processRow() throws HopException { + Object[] r = getRow(); // Get row from input rowset & set row busy! + setLogLevel(LogLevel.DEBUG); + + if ((!meta.isNeverEnding() && data.rowsWritten >= data.rowLimit) && !isStopped()) { + setOutputDone(); // signal end to receiver(s) + return false; + } + + if (first) { + plctags.clear(); + //This performs a minimal check on the user item. + //It guarantees that the rates are within those managed by Plc4x. + meta.getFields().forEach((f) -> { + plctags.put(f.getName(), new ImmutablePair(f.getName(), S7SubscriptionTag.of(f.getItem()))); + }); + first = false; + } + + // If we do not have the jobId, it is because we have not completed + // the CYC subscription. + if ((null == jobId) && (null == subsRequest)) { + RegisterPlcTags(); + GetSubscriptions(); + RegisterCYCHandler(); + } + + while (events.size() == 0) { + try { + Thread.sleep(100); + if (stopBundle) { + setOutputDone(); // signal end to receiver(s) + return false; + } + } catch (InterruptedException ex) { + break; + } + } + + S7CyclicEvent s7event = (S7CyclicEvent) events.poll(); + //System.out.println("Ejecuto el consumidor en el cliente..." + s7event.getTagNames()); + + r = data.outputRowMeta.cloneRow(data.outputRowData); + + //s7event.getTimestamp() Takes the time sent by the PLC + data.prevDate = data.rowDate; + data.rowDate = Date.from(s7event.getTimestamp()); + int index = 0; + if (!Utils.isEmpty(meta.getRowTimeField())) { + r[index++] = data.rowDate; + } + if (!Utils.isEmpty(meta.getLastTimeField())) { + r[index++] = data.prevDate; + } + + counter = 0; + for (Plc4xGeneratorField field : meta.getFields()) { + valuetype = ((S7SubscriptionTag) plctags.get(field.getName()).getRight()).getS7Tags()[0].getPlcValueType(); + if (null != valuetype) { + System.out.println("Tipo enviado desde el PLC: " + valuetype.name()); + } else { + System.out.println("El tipo de NULL."); + } + + if (field.getType().equalsIgnoreCase("Avro Record")) { + throw new HopException("'Avro Record' type is not supported"); + } else if (field.getType().equalsIgnoreCase("BigNumber")) { + throw new HopException("'BigNumber' type is not supported"); + } else if (field.getType().equalsIgnoreCase("Binary")) { + switch (valuetype) { + case BYTE: + r[index++] = binarycodec.toByteArray( + Long.toBinaryString(Long.valueOf(s7event.getByte(field.getName())))); + break; + case WORD: + r[index++] = binarycodec.toByteArray( + Long.toBinaryString(Long.valueOf(s7event.getShort(field.getName())))); + break; + case DWORD: + r[index++] = binarycodec.toByteArray( + Integer.toBinaryString(s7event.getInteger(field.getName()))); + break; + case LWORD: + r[index++] = binarycodec.toByteArray( + Long.toBinaryString(s7event.getLong(field.getName()))); + break; + default: + throw new HopException("'DATE, LDATE, DATE_AND_TIME, LDATE_AND_TIME' type is not supported"); + } + + } else if (field.getType().equalsIgnoreCase("Boolean")) { + switch (valuetype) { + case BOOL: + r[index++] = s7event.getBoolean(plctags.get(field.getName()).getKey()); + break; + default: + } + } else if (field.getType().equalsIgnoreCase("Date")) { + switch (valuetype) { + case DATE:; + break; + case LDATE:; + break; + case DATE_AND_TIME:; + break; + case LDATE_AND_TIME:; + break; + default: + throw new HopException("'DATE, LDATE, DATE_AND_TIME, LDATE_AND_TIME' type is not supported"); + } + } else if (field.getType().equalsIgnoreCase("Graph")) { + throw new HopException("'Graph' type is not supported"); + } else if (field.getType().equalsIgnoreCase("Integer")) { + switch (valuetype) { + case BYTE: + r[index++] = Long.valueOf(s7event.getByte(field.getName())); + break; + case WORD: + r[index++] = Long.valueOf(s7event.getShort(field.getName())); + break; + case DWORD: + r[index++] = Long.valueOf(s7event.getInteger(field.getName())); + break; + case LWORD: + r[index++] = s7event.getLong(field.getName()); + break; + case INT: + r[index++] = Long.valueOf(s7event.getShort(field.getName())); + break; + case UINT: + r[index++] = Long.valueOf((s7event.getShort(field.getName())) & 0xFFFF); + break; + case SINT: + r[index++] = Long.valueOf(s7event.getByte(field.getName())); + break; + case USINT: + r[index++] = Long.valueOf(s7event.getByte(field.getName()) & 0xFF); + break; + case DINT: + r[index++] = Long.valueOf(s7event.getInteger(field.getName())); + break; + case UDINT: + r[index++] = Long.valueOf(s7event.getInteger(field.getName()) & 0xFFFF); + break; + case LINT: + r[index++] = s7event.getLong(field.getName()); + break; + case ULINT: + r[index++] = (s7event.getLong(field.getName())) & 0xFFFFFFFFL; + break; + default: + throw new HopException("Tag type is not supported. Check tag definition."); + } + } else if (field.getType().equalsIgnoreCase("Internet Address")) { + throw new HopException("'Internet Address' type is not supported"); + } else if (field.getType().equalsIgnoreCase("JSON")) { + throw new HopException("'JSON' type is not supported"); + } else if (field.getType().equalsIgnoreCase("Number")) { + switch (valuetype) { + case REAL: + System.out.println("Hex: " + Hex.dump((byte[]) s7event.getMap().get(field.getName()))); + r[index++] = Double.valueOf(s7event.getFloat(field.getName())); + break; + case LREAL: + r[index++] = s7event.getDouble(field.getName()); + break; + default: + throw new HopException("Tag type is not supported. Check tag definition."); + } + + } else if (field.getType().equalsIgnoreCase("String")) { + switch (valuetype) { + case STRING:; + case DWORD: + r[index++] = String.valueOf(s7event.getFloat(field.getName())); + break; + default: + throw new HopException("'STRING' type is not supported"); + } + } else if (field.getType().equalsIgnoreCase("Timestamp")) { + switch (valuetype) { + case TIME:; + r[index++] = s7event.getTime(plctags.get(field.getName()).getKey()); + break; + case LTIME:; + break; + case TIME_OF_DAY:; + r[index++] = s7event.getTime(plctags.get(field.getName()).getKey()); + break; + case LTIME_OF_DAY:; + break; + default: + throw new HopException("'LTIME, LTIME_OF_DAY' type is not supported"); + } + } + } + + putRow(data.outputRowMeta, r); // return your data + data.rowsWritten++; + return true; + } + + @Override + public boolean init() { + try { + if (super.init()) { + // Determine the number of rows to generate... + data.rowLimit = Const.toLong(resolve(meta.getRowLimit()), -1L); + data.rowsWritten = 0L; + data.delay = Const.toLong(resolve(meta.getIntervalInMs()), -1L); + + if (data.rowLimit < 0L) { // Unable to parse + logError(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Wrong.RowLimit.Number")); + return false; // fail + } + + // Create a row (constants) with all the values in it... + List remarks = new ArrayList<>(); // stores the errors... + RowMetaAndData outputRow = buildRow(meta, remarks, getTransformName()); + if (!remarks.isEmpty()) { + for (int i = 0; i < remarks.size(); i++) { + CheckResult cr = (CheckResult) remarks.get(i); + logError(cr.getText()); + } + + return false; + } + + data.outputRowData = outputRow.getData(); + data.outputRowMeta = outputRow.getRowMeta(); + + jobId = null; + subsRequest = null; + subsResponse = null; + + getPlcConnection(); + + final S7HPlcConnection conn = (S7HPlcConnection) connwrapper.getConnection(); + conn.addEventListener(this); + + return true; + } + return false; + } catch (Exception ex) { + setErrors(1L); + logError("Error initializing transform", ex); + return false; + } + } + + /* + * Here, must perform the cleaning of any resource, main of the connection to + * the associated PLC. + */ + @Override + public void cleanup() { + super.cleanup(); + super.cleanup(); + logBasic("Cleanup. Release connection."); + if (connwrapper != null) { + connwrapper.release(); + if (connwrapper.refCnt() <= 0) { + lookup.remove(connwrapper); + } + connwrapper = null; + subsRequest = null; + } + } + + + /* + * Here, must perform the cleaning of any resource. + * 1. Check if we have reference to wrapper. + * 2. Release de reference to object. + * 3. The lastone remove the global reference to connection wrapper. + * 4. Clear local references. + */ + @Override + public void dispose() { + + UnRegisterCYCHandler(); + + if (connwrapper.getConnection() instanceof S7HPlcConnection) { + final S7HPlcConnection conn = (S7HPlcConnection) connwrapper.getConnection(); + conn.removeEventListener(this); + } + + super.dispose(); + if (connwrapper != null) { + logBasic("Dispose. Release connection: " + connwrapper.refCnt()); + connwrapper.release(); + if (connwrapper.refCnt() <= 0) { + lookup.remove(connwrapper); + } + connwrapper = null; + subsRequest = null; + } + } + + @Override + public void stopRunning() throws HopException { + super.stopRunning(); + stopBundle = true; + } + + private void getPlcConnection() { + lock.lock(); //(01) + try { + + IHopMetadataProvider metaprovider = getMetadataProvider(); + connmeta = metaprovider.getSerializer(Plc4xConnection.class).load(meta.getConnection()); + + if (connwrapper == null) { + template = new Lookup.Template<>(Plc4xWrapperConnection.class, meta.getConnection(), null); + result = lookup.lookup(template); + if (!result.allItems().isEmpty()) { + logBasic("Using connection: " + meta.getConnection()); + connwrapper = (Plc4xWrapperConnection) result.allInstances().toArray()[0]; + if (connwrapper != null) { + connwrapper.retain(); + } + } + }; + + if (connmeta == null) { + logError( + BaseMessages.getString( + PKG, + "Plc4x.Read.Meta.Log.SetMetadata", + meta.getConnection())); + } + + if ((connmeta != null) && (connwrapper == null)) { + subsRequest = null; + try { + final PlcConnection conn = new DefaultPlcDriverManager().getConnection(connmeta.getUrl()); //(03) + Thread.sleep(200); + if (conn.isConnected()) { + logBasic("Create new connection with url : " + connmeta.getUrl()); + connwrapper = new Plc4xWrapperConnection(conn, meta.getConnection()); + lookup.add(connwrapper); + } + + } catch (Exception ex) { + setErrors(1L); + logError("Unable to create connection to PLC. " + ex.getMessage()); + } + } + + } catch (HopException ex) { + logError(ex.getMessage()); + } finally { + lock.unlock(); + } + } + + /* + * Registers the tags for the cyclical subscription. + * In the first processing of the rows, a check of the tags is + * carried out in order that they are well formed, generating an exception + * if they are not. + */ + public boolean RegisterPlcTags() { + if ((connmeta != null) && (connwrapper != null)) { + if (connwrapper.getConnection().isConnected()) { + if (subsRequest == null) { + final PlcSubscriptionRequest.Builder builder = connwrapper.getConnection().subscriptionRequestBuilder(); //(05) + for (Plc4xGeneratorField field : meta.getFields()) { + builder.addEventTagAddress(field.getName(), field.getItem().toString()); + } + + subsRequest = builder.build(); + + } + } else { + setErrors(1L); + logError("PLC is not connected."); + setOutputDone(); + return false; + } + + } else { + setErrors(1L); + logError("PLC connection don't exist."); + setOutputDone(); + return false; + } + return true; + } + + /* + * This method performs the subscription to the events within the PLC. + * 1. Take the waiting time as a reference to monitor the request. + * 2. Captures the jobId associated with the subscription + * which is assigned by the PLC. + */ + public void GetSubscriptions() { + jobId = null; + try { + if (null != subsRequest) { + maxwait = Integer.parseInt(meta.getMaxwaitInMs()); + maxwait = (maxwait < 1000) ? 1000 : maxwait; + + subsResponse = subsRequest.execute().get(maxwait * 2, TimeUnit.MILLISECONDS); + + //Only for Siemens S7 +// subsResponse.getTagNames().forEach(s -> logDebug("Capture JobID: " + s)); + //Only one JobId per subscription will be obtained. + jobId = (String) subsResponse.getTagNames().toArray()[0]; + } + } catch (Exception ex) { + logError(ex.toString()); + jobId = null; + subsResponse = null; + } + } + + /* + * Subscribe to incoming events by transferring them to + * the local event buffer. + */ + public void RegisterCYCHandler() { + if (null != subsResponse) { + csmr = subsResponse + .getSubscriptionHandle(jobId) + .register(evt -> { + events.add(evt); + }); + } + } + + /* + * Unsubscribes to the event generator from the driver and requests + * to cancel the sending of PLC events for the specified job. + */ + public void UnRegisterCYCHandler() { + if (null != csmr) { + csmr.unregister(); + + PlcSubscriptionResponse unregister_response = null; + + final PlcSubscriptionRequest.Builder unregister_builder = connwrapper.getConnection().subscriptionRequestBuilder(); + unregister_builder.addEventTagAddress("CANCELTAG", "CANCEL:" + jobId); + + final PlcSubscriptionRequest unregister_request = unregister_builder.build(); + + try { + unregister_response = unregister_request.execute().get(500, TimeUnit.MILLISECONDS); + } catch (Exception ex) { + logError(ex.getMessage()); + } + + logBasic("UnRegisterCYCHandles: " + unregister_response.getResponseCode(jobId)); + } + } + + /* + * When the driver makes a connection this method is called. + * In the case of the S7 driver, only the connection of the embedded channel + * is served. + */ + @Override + public void connected() { + if (connwrapper.getConnection().isConnected()) { + RegisterPlcTags(); + GetSubscriptions(); + RegisterCYCHandler(); + } + } + + /* + * This method is called from the driver to indicate that it has + * disconnected from the PLC. + * If the PLC is disconnected, it automatically deletes all + * the status associated with this connection. + */ + @Override + public void disconnected() { + logError("Driver disconnected!"); + isConnected = false; + csmr.unregister(); + csmr = null; + subsRequest = null; + } + +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xsubs/Plc4xSubsData.java b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xsubs/Plc4xSubsData.java new file mode 100644 index 00000000000..e39dad14568 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xsubs/Plc4xSubsData.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.plc4x.hop.transforms.plc4xsubs; + +import org.apache.plc4x.hop.transforms.plc4xinput.*; +import java.util.Date; +import org.apache.hop.core.row.IRowMeta; +import org.apache.hop.pipeline.transform.BaseTransformData; +import org.apache.hop.pipeline.transform.ITransformData; + + +public class Plc4xSubsData extends BaseTransformData implements ITransformData { + + //The Plc4xConnection metadata + public String connection; + + public IRowMeta outputRowMeta; + public Object[] outputRowData; + + public long rowLimit; + public long rowsWritten; + public Date rowDate; + public Date prevDate; + public long delay; + + + + /** + * Default constructor for SampleData. + */ + public Plc4xSubsData() { + super(); + } +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xsubs/Plc4xSubsDialog.java b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xsubs/Plc4xSubsDialog.java new file mode 100644 index 00000000000..e5d14f2c8b0 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xsubs/Plc4xSubsDialog.java @@ -0,0 +1,601 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.plc4x.hop.transforms.plc4xsubs; + +import org.apache.plc4x.hop.transforms.plc4xinput.*; +import org.apache.hop.core.Const; +import org.apache.hop.core.exception.HopException; +import org.apache.hop.core.row.value.ValueMetaFactory; +import org.apache.hop.core.util.Utils; +import org.apache.hop.core.variables.IVariables; +import org.apache.hop.i18n.BaseMessages; +import org.apache.hop.pipeline.Pipeline; +import org.apache.hop.pipeline.PipelineMeta; +import org.apache.hop.pipeline.PipelinePreviewFactory; +import org.apache.hop.pipeline.transform.BaseTransformMeta; +import org.apache.hop.pipeline.transform.ITransformDialog; +import org.apache.hop.ui.core.ConstUi; +import org.apache.hop.ui.core.dialog.BaseDialog; +import org.apache.hop.ui.core.dialog.EnterNumberDialog; +import org.apache.hop.ui.core.dialog.EnterTextDialog; +import org.apache.hop.ui.core.dialog.ErrorDialog; +import org.apache.hop.ui.core.dialog.PreviewRowsDialog; +import org.apache.hop.ui.core.widget.ColumnInfo; +import org.apache.hop.ui.core.widget.MetaSelectionLine; +import org.apache.hop.ui.core.widget.TableView; +import org.apache.hop.ui.core.widget.TextVar; +import org.apache.hop.ui.pipeline.dialog.PipelinePreviewProgressDialog; +import org.apache.hop.ui.pipeline.transform.BaseTransformDialog; +import org.apache.hop.ui.util.SwtSvgImageUtil; +import org.apache.plc4x.hop.metadata.Plc4xConnection; +import org.apache.plc4x.hop.transforms.util.Plc4xGeneratorField; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.*; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; + +public class Plc4xSubsDialog extends BaseTransformDialog implements ITransformDialog { + private static final Class PKG = Plc4xSubsDialog.class; // Needed by Translator + + private MetaSelectionLine wConnection; + + private Label wlLimit; + private TextVar wLimit; + + private Button wNeverEnding; + + private Label wlMaxwait; + private TextVar wMaxwait; + + private Label wlInterval; + private TextVar wInterval; + + private Label wlRowTimeField; + private TextVar wRowTimeField; + + private Label wlLastTimeField; + private TextVar wLastTimeField; + + private TableView wFields; + + private final Plc4xSubsMeta input; + + public Plc4xSubsDialog(Shell parent, IVariables variables , Object in, PipelineMeta pipelineMeta, String sname ) { + super( parent, variables, (BaseTransformMeta) in, pipelineMeta, sname ); + input = (Plc4xSubsMeta) in; + } + + @Override + public String open() { + Shell parent = getParent(); + + shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN); + props.setLook(shell); + setShellImage(shell, input); + + ModifyListener lsMod = e -> input.setChanged(); + changed = input.hasChanged(); + + FormLayout formLayout = new FormLayout(); + formLayout.marginWidth = Const.FORM_MARGIN; + formLayout.marginHeight = Const.FORM_MARGIN; + + shell.setLayout(formLayout); + shell.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.DialogTitle")); + + int middle = props.getMiddlePct(); + int margin = props.getMargin(); + + // Filename line + wlTransformName = new Label(shell, SWT.RIGHT); + wlTransformName.setText(BaseMessages.getString(PKG, "System.Label.TransformName")); + props.setLook(wlTransformName); + fdlTransformName = new FormData(); + fdlTransformName.left = new FormAttachment(0, 0); + fdlTransformName.right = new FormAttachment(middle, -margin); + fdlTransformName.top = new FormAttachment(0, margin); + wlTransformName.setLayoutData(fdlTransformName); + + wTransformName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + wTransformName.setText(transformName); + props.setLook(wTransformName); + wTransformName.addModifyListener(lsMod); + fdTransformName = new FormData(); + fdTransformName.left = new FormAttachment(middle, 0); + fdTransformName.top = new FormAttachment(0, margin); + fdTransformName.right = new FormAttachment(100, 0); + wTransformName.setLayoutData(fdTransformName); + + // Connection line + wConnection = + new MetaSelectionLine<>( + variables, + metadataProvider, + Plc4xConnection.class, + shell, + SWT.NONE, + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Connection.Label"), + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Connection.Tooltip")); + FormData fdConnection = new FormData(); + fdConnection.left = new FormAttachment(0, 0); + fdConnection.right = new FormAttachment(100, 0); + fdConnection.top = new FormAttachment(wTransformName, margin); + wConnection.setLayoutData(fdConnection); + props.setLook(wConnection); + try { + wConnection.fillItems(); + } catch (Exception e) { + new ErrorDialog(shell, "Error", "Error listing Cassandra connection metadata objects", e); + } + + Control lastControl = wConnection; + + wlLimit = new Label(shell, SWT.RIGHT); + wlLimit.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Limit.Label")); + props.setLook(wlLimit); + FormData fdlLimit = new FormData(); + fdlLimit.left = new FormAttachment(0, 0); + fdlLimit.right = new FormAttachment(middle, -margin); + fdlLimit.top = new FormAttachment(lastControl, margin); + wlLimit.setLayoutData(fdlLimit); + wLimit = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wLimit); + wLimit.addModifyListener(lsMod); + FormData fdLimit = new FormData(); + fdLimit.left = new FormAttachment(middle, 0); + fdLimit.top = new FormAttachment(lastControl, margin); + fdLimit.right = new FormAttachment(100, 0); + wLimit.setLayoutData(fdLimit); + lastControl = wLimit; + + Label wlNeverEnding = new Label(shell, SWT.RIGHT); + wlNeverEnding.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.NeverEnding.Label")); + props.setLook(wlNeverEnding); + FormData fdlNeverEnding = new FormData(); + fdlNeverEnding.left = new FormAttachment(0, 0); + fdlNeverEnding.right = new FormAttachment(middle, -margin); + fdlNeverEnding.top = new FormAttachment(lastControl, margin); + wlNeverEnding.setLayoutData(fdlNeverEnding); + wNeverEnding = new Button(shell, SWT.CHECK); + props.setLook(wNeverEnding); + wNeverEnding.addSelectionListener( + new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + setActive(); + input.setChanged(); + } + }); + FormData fdNeverEnding = new FormData(); + fdNeverEnding.left = new FormAttachment(middle, 0); + fdNeverEnding.top = new FormAttachment(wlNeverEnding, 0, SWT.CENTER); + fdNeverEnding.right = new FormAttachment(100, 0); + wNeverEnding.setLayoutData(fdNeverEnding); + lastControl = wlNeverEnding; + + wlMaxwait = new Label(shell, SWT.RIGHT); + wlMaxwait.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Maxwait.Label")); + props.setLook(wlMaxwait); + FormData fdlMaxwait = new FormData(); + fdlMaxwait.left = new FormAttachment(0, 0); + fdlMaxwait.right = new FormAttachment(middle, -margin); + fdlMaxwait.top = new FormAttachment(lastControl, margin); + wlMaxwait.setLayoutData(fdlMaxwait); + wMaxwait = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wMaxwait); + wMaxwait.addModifyListener(lsMod); + FormData fdMaxwait = new FormData(); + fdMaxwait.left = new FormAttachment(middle, 0); + fdMaxwait.top = new FormAttachment(lastControl, margin); + fdMaxwait.right = new FormAttachment(100, 0); + wMaxwait.setLayoutData(fdMaxwait); + lastControl = wMaxwait; + + wlInterval = new Label(shell, SWT.RIGHT); + wlInterval.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Interval.Label")); + props.setLook(wlInterval); + FormData fdlInterval = new FormData(); + fdlInterval.left = new FormAttachment(0, 0); + fdlInterval.right = new FormAttachment(middle, -margin); + fdlInterval.top = new FormAttachment(lastControl, margin); + wlInterval.setLayoutData(fdlInterval); + wInterval = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wInterval); + wInterval.addModifyListener(lsMod); + FormData fdInterval = new FormData(); + fdInterval.left = new FormAttachment(middle, 0); + fdInterval.top = new FormAttachment(lastControl, margin); + fdInterval.right = new FormAttachment(100, 0); + wInterval.setLayoutData(fdInterval); + lastControl = wInterval; + + /* + wlRowTimeField = new Label(shell, SWT.RIGHT); + wlRowTimeField.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.RowTimeField.Label")); + props.setLook(wlRowTimeField); + FormData fdlRowTimeField = new FormData(); + fdlRowTimeField.left = new FormAttachment(0, 0); + fdlRowTimeField.right = new FormAttachment(middle, -margin); + fdlRowTimeField.top = new FormAttachment(lastControl, margin); + wlRowTimeField.setLayoutData(fdlRowTimeField); + wRowTimeField = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wRowTimeField); + wRowTimeField.addModifyListener(lsMod); + FormData fdRowTimeField = new FormData(); + fdRowTimeField.left = new FormAttachment(middle, 0); + fdRowTimeField.top = new FormAttachment(lastControl, margin); + fdRowTimeField.right = new FormAttachment(100, 0); + wRowTimeField.setLayoutData(fdRowTimeField); + lastControl = wRowTimeField; + + wlLastTimeField = new Label(shell, SWT.RIGHT); + wlLastTimeField.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.LastTimeField.Label")); + props.setLook(wlLastTimeField); + FormData fdlLastTimeField = new FormData(); + fdlLastTimeField.left = new FormAttachment(0, 0); + fdlLastTimeField.right = new FormAttachment(middle, -margin); + fdlLastTimeField.top = new FormAttachment(lastControl, margin); + wlLastTimeField.setLayoutData(fdlLastTimeField); + wLastTimeField = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wLastTimeField); + wLastTimeField.addModifyListener(lsMod); + FormData fdLastTimeField = new FormData(); + fdLastTimeField.left = new FormAttachment(middle, 0); + fdLastTimeField.top = new FormAttachment(lastControl, margin); + fdLastTimeField.right = new FormAttachment(100, 0); + wLastTimeField.setLayoutData(fdLastTimeField); + lastControl = wLastTimeField; + */ + wOk = new Button(shell, SWT.PUSH); + wOk.setText(BaseMessages.getString(PKG, "System.Button.OK")); + wOk.addListener(SWT.Selection, e -> ok()); + wPreview = new Button(shell, SWT.PUSH); + wPreview.setText(BaseMessages.getString(PKG, "System.Button.Preview")); + wPreview.addListener(SWT.Selection, e -> preview()); + wCancel = new Button(shell, SWT.PUSH); + wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); + wCancel.addListener(SWT.Selection, e -> cancel()); + + setButtonPositions(new Button[] {wOk, wPreview, wCancel}, margin, null); + + Label wlFields = new Label(shell, SWT.NONE); + wlFields.setText(BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Fields.Label")); + props.setLook(wlFields); + FormData fdlFields = new FormData(); + fdlFields.left = new FormAttachment(0, 0); + fdlFields.top = new FormAttachment(lastControl, margin); + wlFields.setLayoutData(fdlFields); + lastControl = wlFields; + + final int nrFields = input.getFields().size(); + + ColumnInfo[] colinf = + new ColumnInfo[] { + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Name"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Fields.Item"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Type"), + ColumnInfo.COLUMN_TYPE_CCOMBO, + ValueMetaFactory.getValueMetaNames()), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Format"), + ColumnInfo.COLUMN_TYPE_FORMAT, + 2), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Length"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Precision"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Currency"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Decimal"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Group"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.Value"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "System.Column.SetEmptyString"), + ColumnInfo.COLUMN_TYPE_CCOMBO, + new String[] { + BaseMessages.getString(PKG, "System.Combo.Yes"), + BaseMessages.getString(PKG, "System.Combo.No") + }) + }; + + wFields = + new TableView( + variables, + shell, + SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, + colinf, + nrFields, + lsMod, + props); + + FormData fdFields = new FormData(); + fdFields.left = new FormAttachment(0, 0); + fdFields.top = new FormAttachment(lastControl, margin); + fdFields.right = new FormAttachment(100, 0); + fdFields.bottom = new FormAttachment(wOk, -2 * margin); + wFields.setLayoutData(fdFields); + + lsResize = + event -> { + Point size = shell.getSize(); + wFields.setSize(size.x - 10, size.y - 50); + wFields.table.setSize(size.x - 10, size.y - 50); + wFields.redraw(); + }; + shell.addListener(SWT.Resize, lsResize); + + getData(); + input.setChanged(changed); + + BaseDialog.defaultShellHandling(shell, c -> ok(), c -> cancel()); + + return transformName; + }; + + @Override + public void setActive() { + boolean neverEnding = wNeverEnding.getSelection(); + + wlLimit.setEnabled(!neverEnding); + wLimit.setEnabled(!neverEnding); + + //wlInterval.setEnabled(neverEnding); + //wInterval.setEnabled(neverEnding); + + //wlRowTimeField.setEnabled(neverEnding); + //wRowTimeField.setEnabled(neverEnding); + + //wlLastTimeField.setEnabled(neverEnding); + //wLastTimeField.setEnabled(neverEnding); + } + + + + private Image getImage() { + return SwtSvgImageUtil.getImage( shell.getDisplay(), getClass().getClassLoader(), "plc4x_toddy_read.svg", ConstUi.LARGE_ICON_SIZE, + ConstUi.LARGE_ICON_SIZE ); + } + + /** + * Copy information from the meta-data input to the dialog fields. + * + */ + public void getData() { + if (isDebug()) { + logDebug("getting fields info..."); + } + if (input.getConnection() == null) { + wConnection.setText(""); + } else { + wConnection.setText(input.getConnection()); + } + + wLimit.setText(input.getRowLimit()); + wNeverEnding.setSelection(input.isNeverEnding()); + wMaxwait.setText(Const.NVL(input.getMaxwaitInMs(), "")); + wInterval.setText(Const.NVL(input.getIntervalInMs(), "")); + // wRowTimeField.setText(Const.NVL(input.getRowTimeField(), "")); + //wLastTimeField.setText(Const.NVL(input.getLastTimeField(), "")); + + for (int i = 0; i < input.getFields().size(); i++) { + Plc4xGeneratorField field = input.getFields().get(i); + TableItem item = wFields.table.getItem(i); + int col = 1; + item.setText(col++, Const.NVL(field.getName(), "")); + + item.setText(col++, Const.NVL(field.getItem(), "")); + + String type = field.getType(); + String format = field.getFormat(); + String length = field.getLength() < 0 ? "" : ("" + field.getLength()); + String prec = field.getPrecision() < 0 ? "" : ("" + field.getPrecision()); + + String curr = field.getCurrency(); + String group = field.getGroup(); + String decim = field.getDecimal(); + String def = field.getValue(); + + item.setText(col++, Const.NVL(type, "")); + item.setText(col++, Const.NVL(format, "")); + item.setText(col++, Const.NVL(length, "")); + item.setText(col++, Const.NVL(prec, "")); + item.setText(col++, Const.NVL(curr, "")); + item.setText(col++, Const.NVL(decim, "")); + item.setText(col++, Const.NVL(group, "")); + item.setText(col++, Const.NVL(def, "")); + item.setText( + col++, + field.isSetEmptyString() + ? BaseMessages.getString(PKG, "System.Combo.Yes") + : BaseMessages.getString(PKG, "System.Combo.No")); + } + + wFields.setRowNums(); + wFields.optWidth(true); + + setActive(); + + wTransformName.selectAll(); + wTransformName.setFocus(); + } + + /** + * Stores the information from the dialog box in meta-data. + * + * @param meta + */ + private void getInfo( Plc4xSubsMeta meta) throws HopException { + meta.setConnection(wConnection.getText()); + meta.setRowLimit(wLimit.getText()); + meta.setNeverEnding(wNeverEnding.getSelection()); + meta.setMaxwaitInMs(wMaxwait.getText()); + meta.setIntervalInMs(wInterval.getText()); + //meta.setRowTimeField(wRowTimeField.getText()); + //meta.setLastTimeField(wLastTimeField.getText()); + + meta.getFields().clear(); + + // CHECKSTYLE:Indentation:OFF + for (TableItem item : wFields.getNonEmptyItems()) { + Plc4xGeneratorField field = new Plc4xGeneratorField(); + field.setName(item.getText(1)); + field.setItem(item.getText(2)); + field.setFormat(item.getText(4)); + field.setLength(Const.toInt(item.getText(5), -1)); + field.setPrecision(Const.toInt(item.getText(6), -1)); + field.setCurrency(item.getText(7)); + field.setDecimal(item.getText(8)); + field.setGroup(item.getText(9)); + field.setValue(field.isSetEmptyString() ? "" : item.getText(10)); + field.setSetEmptyString( + BaseMessages.getString(PKG, "System.Combo.Yes").equalsIgnoreCase(item.getText(11))); + field.setType(field.isSetEmptyString() ? "String" : item.getText(3)); + + meta.getFields().add(field); + } + } + + /** + * Cancel the dialog. + */ + private void cancel() { + transformName = null; + input.setChanged( changed ); + dispose(); + } + + private void ok() { + if (Utils.isEmpty(wTransformName.getText())) { + return; + } + + transformName = wTransformName.getText(); // return value + try { + getInfo(new Plc4xSubsMeta()); // to see if there is an exception + getInfo(input); // to put the content on the input structure for real if all is well. + dispose(); + } catch (HopException e) { + new ErrorDialog( + shell, + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Title"), + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Message"), + e); + } + } + + + /** + * Preview the data generated by this transform. This generates a pipeline using this transform & + * a dummy and previews it. + */ + private void preview() { + Plc4xSubsMeta oneMeta = new Plc4xSubsMeta(); + try { + getInfo(oneMeta); + } catch (HopException e) { + new ErrorDialog( + shell, + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Title"), + BaseMessages.getString(PKG, "Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Message"), + e); + return; + } + + PipelineMeta previewMeta = + PipelinePreviewFactory.generatePreviewPipeline( + pipelineMeta.getMetadataProvider(), oneMeta, wTransformName.getText()); + + EnterNumberDialog numberDialog = + new EnterNumberDialog( + shell, + props.getDefaultPreviewSize(), + BaseMessages.getString(PKG, "System.Dialog.EnterPreviewSize.Title"), + BaseMessages.getString(PKG, "System.Dialog.EnterPreviewSize.Message")); + int previewSize = numberDialog.open(); + if (previewSize > 0) { + PipelinePreviewProgressDialog progressDialog = + new PipelinePreviewProgressDialog( + shell, + variables, + previewMeta, + new String[] {wTransformName.getText()}, + new int[] {previewSize}); + progressDialog.open(); + + Pipeline pipeline = progressDialog.getPipeline(); + String loggingText = progressDialog.getLoggingText(); + + if (!progressDialog.isCancelled()) { + if (pipeline.getResult() != null && pipeline.getResult().getNrErrors() > 0) { + EnterTextDialog etd = + new EnterTextDialog( + shell, + BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), + BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), + loggingText, + true); + etd.setReadOnly(); + etd.open(); + } + } + + PreviewRowsDialog prd = + new PreviewRowsDialog( + shell, + variables, + SWT.NONE, + wTransformName.getText(), + progressDialog.getPreviewRowsMeta(wTransformName.getText()), + progressDialog.getPreviewRows(wTransformName.getText()), + loggingText); + prd.open(); + } + } + +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xsubs/Plc4xSubsMeta.java b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xsubs/Plc4xSubsMeta.java new file mode 100644 index 00000000000..12943301d71 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/plc4xsubs/Plc4xSubsMeta.java @@ -0,0 +1,306 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.plc4x.hop.transforms.plc4xsubs; + +import org.apache.plc4x.hop.transforms.plc4xinput.*; +import java.util.ArrayList; +import org.apache.hop.core.ICheckResult; +import org.apache.hop.core.annotations.Transform; +import org.apache.hop.core.exception.HopTransformException; +import org.apache.hop.core.exception.HopXmlException; +import org.apache.hop.core.row.IRowMeta; +import org.apache.hop.core.variables.IVariables; +import org.apache.hop.core.xml.XmlHandler; +import org.apache.hop.metadata.api.IHopMetadataProvider; +import org.apache.hop.pipeline.Pipeline; +import org.apache.hop.pipeline.PipelineMeta; +import org.apache.hop.pipeline.transform.BaseTransformMeta; +import org.apache.hop.pipeline.transform.ITransformMeta; +import org.apache.hop.pipeline.transform.TransformMeta; +import org.w3c.dom.Node; + +import java.util.List; +import org.apache.hop.core.Const; +import org.apache.hop.core.RowMetaAndData; +import org.apache.hop.core.row.IValueMeta; +import org.apache.hop.metadata.api.HopMetadataProperty; +import org.apache.hop.pipeline.transform.ITransformIOMeta; +import org.apache.hop.pipeline.transform.TransformIOMeta; +import org.apache.plc4x.hop.transforms.util.Plc4xGeneratorField; + +/** + * Meta data for the sample transform. + */ +@Transform( + id = "plc4x-subs", + name = "i18n::Plc4x.Read.Name", + description = "i18n::Plc4x.Read.Description", + image = "plc4x_subs.svg", + categoryDescription = "i18n:org.apache.plc4x.hop.transforms.plc4xinput:Plc4x.Category.plc4x", + documentationUrl = "https://plc4x.apache.org/users/integrations/apache-calcite.html" +) +public class Plc4xSubsMeta extends BaseTransformMeta{ + + private static final Class PKG = Plc4xSubsMeta.class; // Needed by Translator + + + @HopMetadataProperty( + key = "connection", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.Connection") + private String connection; + + @HopMetadataProperty( + key = "never_ending", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.NeverEnding") + private boolean neverEnding; + + @HopMetadataProperty( + key = "maxwait_in_ms", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.MaxwaitInMs") + private String maxwaitInMs; + + @HopMetadataProperty( + key = "interval_in_ms", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.IntervalInMs") + private String intervalInMs; + + @HopMetadataProperty( + key = "row_time_field", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.RowTimeField") + private String rowTimeField; + + @HopMetadataProperty( + key = "last_time_field", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.LastTimeField") + private String lastTimeField; + + @HopMetadataProperty( + key = "limit", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.RowLimit") + private String rowLimit; + + @HopMetadataProperty( + groupKey = "fields", + key = "field", + injectionGroupDescription = "Plc4x.Read.Meta.Injection.Fields", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.Fields") + private List fields; + + public Plc4xSubsMeta() { + fields = new ArrayList<>(); + + rowLimit = "10"; + neverEnding = false; + maxwaitInMs = "1000"; + intervalInMs = "5000"; + rowTimeField = "now"; + lastTimeField = "last"; + } + + public Plc4xSubsMeta(Plc4xSubsMeta m) { + this.connection = m.connection; + this.neverEnding = m.neverEnding; + this.intervalInMs = m.intervalInMs; + this.rowTimeField = m.rowTimeField; + this.lastTimeField = m.lastTimeField; + this.rowLimit = m.rowLimit; + this.fields = new ArrayList<>(); + for (Plc4xGeneratorField field : m.fields) { + this.fields.add(new Plc4xGeneratorField(field)); + } + } + + @Override + public Plc4xSubsMeta clone() { + return new Plc4xSubsMeta(this); + } + + + + @Override + public void getFields( IRowMeta inputRowMeta, String name, IRowMeta[] info, TransformMeta nextTransform, + IVariables variables, IHopMetadataProvider metadataProvider ) throws HopTransformException { + try { + List remarks = new ArrayList<>(); + RowMetaAndData rowMetaAndData = Plc4xSubs.buildRow(this, remarks, name); + + if (!remarks.isEmpty()) { + StringBuilder stringRemarks = new StringBuilder(); + for (ICheckResult remark : remarks) { + stringRemarks.append(remark.toString()).append(Const.CR); + } + throw new HopTransformException(stringRemarks.toString()); + } + + for (IValueMeta valueMeta : rowMetaAndData.getRowMeta().getValueMetaList()) { + valueMeta.setOrigin(name); + } + + inputRowMeta.mergeRowMeta(rowMetaAndData.getRowMeta()); + } catch (Exception e) { + throw new HopTransformException(e); + } + } + + + public Plc4xSubs createTransform(TransformMeta transformMeta, Plc4xSubsData data, int copyNr, + PipelineMeta pipelineMeta, Pipeline pipeline ) { + return new Plc4xSubs( transformMeta, this, data, copyNr, pipelineMeta, pipeline ); + } + + public Plc4xSubsData getTransformData() { + return new Plc4xSubsData(); + } +/* + @Override + public void loadXml( Node transformNode, IHopMetadataProvider metadataProvider ) throws HopXmlException { + //load the saved values from the transformnode + String sampleValue = XmlHandler.getTagValue( transformNode, "sampleValue" ); + + } +*/ + @Override + public void setDefault() { + //default values when creating a new transform + } + + + /** + * Returns the Input/Output metadata for this transform. + * The generator transform only produces output, does not accept input! + * TransformIOMeta(inputAcceptor, outputProducer, inputOptional, outputDynamic, inputDynamic) + */ + @Override + public ITransformIOMeta getTransformIOMeta() { + return new TransformIOMeta(false, true, false, false, false, false); + } + + /** + * Gets Plc4xConnection metadata name. + * + * @return value of intervalInMs + */ + public String getConnection() { + return connection; + } + + /** @param connection */ + public void setConnection(String connection) { + this.connection = connection; + } + + + /** + * Gets neverEnding + * + * @return value of neverEnding + */ + public boolean isNeverEnding() { + return neverEnding; + } + + /** @param neverEnding The neverEnding to set */ + public void setNeverEnding(boolean neverEnding) { + this.neverEnding = neverEnding; + } + + /** + * Gets intervalInMs + * + * @return value of intervalInMs + */ + public String getMaxwaitInMs() { + return maxwaitInMs; + } + + /** @param intervalInMs The intervalInMs to set */ + public void setMaxwaitInMs(String maxwaitInMs) { + this.maxwaitInMs = maxwaitInMs; + } + + /** + * Gets intervalInMs + * + * @return value of intervalInMs + */ + public String getIntervalInMs() { + return intervalInMs; + } + + /** @param intervalInMs The intervalInMs to set */ + public void setIntervalInMs(String intervalInMs) { + this.intervalInMs = intervalInMs; + } + + /** + * Gets rowTimeField + * + * @return value of rowTimeField + */ + public String getRowTimeField() { + return rowTimeField; + } + + /** @param rowTimeField The rowTimeField to set */ + public void setRowTimeField(String rowTimeField) { + this.rowTimeField = rowTimeField; + } + + /** + * Gets lastTimeField + * + * @return value of lastTimeField + */ + public String getLastTimeField() { + return lastTimeField; + } + + /** @param lastTimeField The lastTimeField to set */ + public void setLastTimeField(String lastTimeField) { + this.lastTimeField = lastTimeField; + } + + /** + * Gets rowLimit + * + * @return value of rowLimit + */ + public String getRowLimit() { + return rowLimit; + } + + /** @param rowLimit The rowLimit to set */ + public void setRowLimit(String rowLimit) { + this.rowLimit = rowLimit; + } + + /** + * Gets fields + * + * @return value of fields + */ + public List getFields() { + return fields; + } + + /** @param fields The fields to set */ + public void setFields(List fields) { + this.fields = fields; + } + +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/util/Plc4xDataType.java b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/util/Plc4xDataType.java new file mode 100644 index 00000000000..dc6df28d2a2 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/util/Plc4xDataType.java @@ -0,0 +1,115 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.plc4x.hop.transforms.util; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +// Code generated by code-generation. DO NOT EDIT. + +public enum Plc4xDataType { + BOOL((short) 1, (short) 1), + BYTE((short) 2, (short) 1), + WORD((short) 3, (short) 2), + DWORD((short) 4, (short) 4), + LWORD((short) 5, (short) 8), + SINT((short) 6, (short) 1), + INT((short) 7, (short) 2), + DINT((short) 8, (short) 4), + LINT((short) 9, (short) 8), + USINT((short) 10, (short) 1), + UINT((short) 11, (short) 2), + UDINT((short) 12, (short) 4), + ULINT((short) 13, (short) 8), + REAL((short) 14, (short) 4), + LREAL((short) 15, (short) 8), + TIME((short) 16, (short) 8), + LTIME((short) 17, (short) 8), + DATE((short) 18, (short) 8), + LDATE((short) 19, (short) 8), + TIME_OF_DAY((short) 20, (short) 8), + LTIME_OF_DAY((short) 21, (short) 8), + DATE_AND_TIME((short) 22, (short) 8), + LDATE_AND_TIME((short) 23, (short) 8), + CHAR((short) 24, (short) 1), + WCHAR((short) 25, (short) 2), + STRING((short) 26, (short) 1), + WSTRING((short) 27, (short) 2); + + private static final Logger logger = LoggerFactory.getLogger(Plc4xDataType.class); + + private static final Map map; + + static { + map = new HashMap<>(); + for (Plc4xDataType value : Plc4xDataType.values()) { + map.put((short) value.getValue(), value); + } + } + + private short value; + private short dataTypeSize; + + Plc4xDataType(short value, short dataTypeSize) { + this.value = value; + this.dataTypeSize = dataTypeSize; + } + + public short getValue() { + return value; + } + + public short getDataTypeSize() { + return dataTypeSize; + } + + public static Plc4xDataType firstEnumForFieldDataTypeSize(short fieldValue) { + for (Plc4xDataType _val : Plc4xDataType.values()) { + if (_val.getDataTypeSize() == fieldValue) { + return _val; + } + } + return null; + } + + public static List enumsForFieldDataTypeSize(short fieldValue) { + List _values = new ArrayList(); + for (Plc4xDataType _val : Plc4xDataType.values()) { + if (_val.getDataTypeSize() == fieldValue) { + _values.add(_val); + } + } + return _values; + } + + public static Plc4xDataType enumForValue(short value) { + if (!map.containsKey(value)) { + logger.error("No Plc4xDataType for value {}", value); + } + return map.get(value); + } + + public static Boolean isDefined(short value) { + return map.containsKey(value); + } +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/util/Plc4xGeneratorField.java b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/util/Plc4xGeneratorField.java new file mode 100644 index 00000000000..a676ee34221 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/util/Plc4xGeneratorField.java @@ -0,0 +1,275 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.plc4x.hop.transforms.util; + +import org.apache.hop.metadata.api.HopMetadataProperty; + +import java.util.Objects; + +public class Plc4xGeneratorField { + + @HopMetadataProperty(injectionKeyDescription = "Plc4x.Read.Meta.Injection.Field.Name") + private String name; + + @HopMetadataProperty(injectionKeyDescription = "Plc4x.Read.Meta.Injection.Field.Item") + private String item; + + @HopMetadataProperty(injectionKeyDescription = "Plc4x.Read.Meta.Injection.Field.Type") + private String type; + + @HopMetadataProperty(injectionKeyDescription = "Plc4x.Read.Meta.Injection.Field.Format") + private String format; + + @HopMetadataProperty(injectionKeyDescription = "Plc4x.Read.Meta.Injection.Field.Length") + private int length; + + @HopMetadataProperty(injectionKeyDescription = "Plc4x.Read.Meta.Injection.Field.Precision") + private int precision; + + @HopMetadataProperty(injectionKeyDescription = "Plc4x.Read.Meta.Injection.Field.Currency") + private String currency; + + @HopMetadataProperty(injectionKeyDescription = "Plc4x.Read.Meta.Injection.Field.Decimal") + private String decimal; + + @HopMetadataProperty(injectionKeyDescription = "Plc4x.Read.Meta.Injection.Field.Group") + private String group; + + // Yeah, it has a key of "nullif", keep it for backward compatibility + @HopMetadataProperty( + key = "nullif", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.Field.Value") + private String value; + + @HopMetadataProperty( + key = "set_empty_string", + injectionKeyDescription = "Plc4x.Read.Meta.Injection.Field.SetEmptyString") + private boolean setEmptyString; + + public Plc4xGeneratorField() {} + + public Plc4xGeneratorField(Plc4xGeneratorField f) { + this.name = f.name; + this.item = f.item; + this.type = f.type; + this.format = f.format; + this.length = f.length; + this.precision = f.precision; + this.currency = f.currency; + this.decimal = f.decimal; + this.group = f.group; + this.value = f.value; + this.setEmptyString = f.setEmptyString; + } + + public Plc4xGeneratorField( + String name, + String item, + String type, + String format, + int length, + int precision, + String currency, + String decimal, + String group, + String value, + boolean setEmptyString) { + this.name = name; + this.item = item; + this.type = type; + this.format = format; + this.length = length; + this.precision = precision; + this.currency = currency; + this.decimal = decimal; + this.group = group; + this.value = value; + this.setEmptyString = setEmptyString; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Plc4xGeneratorField that = (Plc4xGeneratorField) o; + return Objects.equals(name, that.name); + } + + @Override + public int hashCode() { + return Objects.hash(name); + } + + /** + * Gets name + * + * @return value of name + */ + public String getName() { + return name; + } + + /** @param name The name to set */ + public void setName(String name) { + this.name = name; + } + + /** + * Gets Item + * + * @return value of name + */ + public String getItem() { + return item; + } + + /** @param name The name to set */ + public void setItem(String item) { + this.item = item; + } + + /** + * Gets type + * + * @return value of type + */ + public String getType() { + return type; + } + + /** @param type The type to set */ + public void setType(String type) { + this.type = type; + } + + /** + * Gets format + * + * @return value of format + */ + public String getFormat() { + return format; + } + + /** @param format The format to set */ + public void setFormat(String format) { + this.format = format; + } + + /** + * Gets length + * + * @return value of length + */ + public int getLength() { + return length; + } + + /** @param length The length to set */ + public void setLength(int length) { + this.length = length; + } + + /** + * Gets precision + * + * @return value of precision + */ + public int getPrecision() { + return precision; + } + + /** @param precision The precision to set */ + public void setPrecision(int precision) { + this.precision = precision; + } + + /** + * Gets currency + * + * @return value of currency + */ + public String getCurrency() { + return currency; + } + + /** @param currency The currency to set */ + public void setCurrency(String currency) { + this.currency = currency; + } + + /** + * Gets decimal + * + * @return value of decimal + */ + public String getDecimal() { + return decimal; + } + + /** @param decimal The decimal to set */ + public void setDecimal(String decimal) { + this.decimal = decimal; + } + + /** + * Gets group + * + * @return value of group + */ + public String getGroup() { + return group; + } + + /** @param group The group to set */ + public void setGroup(String group) { + this.group = group; + } + + /** + * Gets value + * + * @return value of value + */ + public String getValue() { + return value; + } + + /** @param value The value to set */ + public void setValue(String value) { + this.value = value; + } + + /** + * Gets setEmptyString + * + * @return value of setEmptyString + */ + public boolean isSetEmptyString() { + return setEmptyString; + } + + /** @param setEmptyString The setEmptyString to set */ + public void setSetEmptyString(boolean setEmptyString) { + this.setEmptyString = setEmptyString; + } +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/util/Plc4xPlcField.java b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/util/Plc4xPlcField.java new file mode 100644 index 00000000000..295dc9f1765 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/util/Plc4xPlcField.java @@ -0,0 +1,148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.plc4x.hop.transforms.util; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.apache.plc4x.java.api.exceptions.PlcInvalidTagException; +import org.apache.plc4x.java.api.model.PlcTag; +import org.apache.plc4x.java.spi.generation.ParseException; +import org.apache.plc4x.java.spi.generation.SerializationException; +import org.apache.plc4x.java.spi.generation.WriteBuffer; +import org.apache.plc4x.java.spi.utils.Serializable; + +import java.nio.charset.StandardCharsets; +import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/* +* Code taken from the Modbus driver implementation. +* This allows me to make the correct interpretation of the "Hop" values +* towards the writing fields. +* +* TODO: The HOP interpreter generates an error when processing +* the "Integer" fields. +*/ + +public class Plc4xPlcField implements PlcTag, Serializable { + + public static final Pattern ADDRESS_PATTERN = Pattern.compile("(?
[\\%a-zA-Z_\\.0-9]+)(:(?[a-zA-Z_]+))?(\\[(?\\d+)])?"); + + protected static final int PROTOCOL_ADDRESS_OFFSET = 1; + + private final String address; + + private final int quantity; + + private final Plc4xDataType dataType; + + public static Plc4xPlcField of(String addressString) { + if (Plc4xPlcField.matches(addressString)) { + Matcher matcher = ADDRESS_PATTERN.matcher(addressString); + + matcher.matches(); + + String address = matcher.group("address"); + + String quantityString = matcher.group("quantity"); + int quantity = quantityString != null ? Integer.parseInt(quantityString) : 1; + + Plc4xDataType dataType = (matcher.group("datatype") != null) ? Plc4xDataType.valueOf(matcher.group("datatype")) : Plc4xDataType.BOOL; + + + return new Plc4xPlcField(address, quantity, dataType); + } + + throw new PlcInvalidTagException("Unable to parse address: " + addressString); + } + + protected Plc4xPlcField(String address, Integer quantity, Plc4xDataType dataType) { + this.address = address; + + this.quantity = quantity != null ? quantity : 1; + + this.dataType = dataType != null ? dataType : Plc4xDataType.INT; + } + + public static boolean matches(String addressString) { + return ADDRESS_PATTERN.matcher(addressString).matches(); + } + + public String getAddress() { + return address; + } + + public int getNumberOfElements() { + return quantity; + } + + public int getLengthBytes() { + return quantity * dataType.getDataTypeSize(); + } + + @JsonIgnore + public int getLengthWords() { + return (int) ((quantity * (float) dataType.getDataTypeSize()) / 2.0f); + } + + public Plc4xDataType getDataType() { + return dataType; + } + + public String getPlcDataType() { + return dataType.name(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Plc4xPlcField)) { + return false; + } + Plc4xPlcField that = (Plc4xPlcField) o; + return address == that.address; + } + + @Override + public int hashCode() { + return Objects.hash(address); + } + + @Override + public String toString() { + return "Plc4xPlcField{" + + " address=" + address + + " datatype=" + dataType + + " quantity=" + quantity + + " }"; + } + + @Override + public void serialize(WriteBuffer wb) throws SerializationException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public String getAddressString() { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/util/Plc4xPlcSubscriptionTag.java b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/util/Plc4xPlcSubscriptionTag.java new file mode 100644 index 00000000000..2a261a39062 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/util/Plc4xPlcSubscriptionTag.java @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.plc4x.hop.transforms.util; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import java.time.Duration; +import org.apache.plc4x.java.api.exceptions.PlcInvalidTagException; +import org.apache.plc4x.java.api.model.PlcSubscriptionTag; +import org.apache.plc4x.java.spi.generation.SerializationException; +import org.apache.plc4x.java.spi.generation.WriteBuffer; +import org.apache.plc4x.java.spi.utils.Serializable; + +import java.util.Objects; +import java.util.Optional; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.apache.plc4x.java.api.model.PlcTag; +import org.apache.plc4x.java.api.types.PlcSubscriptionType; + +/* +* Code taken from the Modbus driver implementation. +* This allows me to make the correct interpretation of the "Hop" values +* towards the writing fields. +* +* TODO: The HOP interpreter generates an error when processing +* the "Integer" fields. +*/ + +public class Plc4xPlcSubscriptionTag implements PlcTag, Serializable { + + public static final Pattern ADDRESS_PATTERN = Pattern.compile("(?
[\\%a-zA-Z_\\.0-9]+)(:(?[a-zA-Z_]+))?(\\[(?\\d+)])?"); + + protected static final int PROTOCOL_ADDRESS_OFFSET = 1; + + private final String address; + + private final int quantity; + + private final Plc4xDataType dataType; + + public static Plc4xPlcSubscriptionTag of(String addressString) { + if (Plc4xPlcSubscriptionTag.matches(addressString)) { + Matcher matcher = ADDRESS_PATTERN.matcher(addressString); + + matcher.matches(); + + String address = matcher.group("address"); + + String quantityString = matcher.group("quantity"); + int quantity = quantityString != null ? Integer.parseInt(quantityString) : 1; + + Plc4xDataType dataType = (matcher.group("datatype") != null) ? Plc4xDataType.valueOf(matcher.group("datatype")) : Plc4xDataType.BOOL; + + + return new Plc4xPlcSubscriptionTag(address, quantity, dataType); + } + + throw new PlcInvalidTagException("Unable to parse address: " + addressString); + } + + protected Plc4xPlcSubscriptionTag(String address, Integer quantity, Plc4xDataType dataType) { + this.address = address; + + this.quantity = quantity != null ? quantity : 1; + + this.dataType = dataType != null ? dataType : Plc4xDataType.INT; + } + + public static boolean matches(String addressString) { + return ADDRESS_PATTERN.matcher(addressString).matches(); + } + + public String getAddress() { + return address; + } + + public int getNumberOfElements() { + return quantity; + } + + public int getLengthBytes() { + return quantity * dataType.getDataTypeSize(); + } + + @JsonIgnore + public int getLengthWords() { + return (int) ((quantity * (float) dataType.getDataTypeSize()) / 2.0f); + } + + public Plc4xDataType getDataType() { + return dataType; + } + + public String getPlcDataType() { + return dataType.name(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Plc4xPlcSubscriptionTag)) { + return false; + } + Plc4xPlcSubscriptionTag that = (Plc4xPlcSubscriptionTag) o; + return address == that.address; + } + + @Override + public int hashCode() { + return Objects.hash(address); + } + + @Override + public String toString() { + return "Plc4xPlcSubscriptionField{" + + " address=" + address + + " datatype=" + dataType + + " quantity=" + quantity + + " }"; + } + + @Override + public void serialize(WriteBuffer wb) throws SerializationException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getAddressString() { + throw new UnsupportedOperationException("Not supported yet."); + } + +// @Override +// public PlcSubscriptionType getPlcSubscriptionType() { +// throw new UnsupportedOperationException("Not supported yet."); +// } +// +// @Override +// public Optional getDuration() { +// throw new UnsupportedOperationException("Not supported yet."); +// } + +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/util/Plc4xPlcTag.java b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/util/Plc4xPlcTag.java new file mode 100644 index 00000000000..d89cbfabc73 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/java/org/apache/plc4x/hop/transforms/util/Plc4xPlcTag.java @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.plc4x.hop.transforms.util; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.apache.plc4x.java.api.exceptions.PlcInvalidTagException; +import org.apache.plc4x.java.api.model.PlcTag; +import org.apache.plc4x.java.spi.generation.SerializationException; +import org.apache.plc4x.java.spi.generation.WriteBuffer; +import org.apache.plc4x.java.spi.utils.Serializable; + +import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/* +* Code taken from the Modbus driver implementation. +* This allows me to make the correct interpretation of the "Hop" values +* towards the writing fields. +* +* TODO: The HOP interpreter generates an error when processing +* the "Integer" fields. +*/ + +public class Plc4xPlcTag implements PlcTag, Serializable { + + public static final Pattern ADDRESS_PATTERN = Pattern.compile("(?
[\\%a-zA-Z_\\.0-9]+)(:(?[a-zA-Z_]+))?(\\[(?\\d+)])?"); + + protected static final int PROTOCOL_ADDRESS_OFFSET = 1; + + private final String address; + + private final int quantity; + + private final Plc4xDataType dataType; + + public static Plc4xPlcTag of(String addressString) { + if (Plc4xPlcTag.matches(addressString)) { + Matcher matcher = ADDRESS_PATTERN.matcher(addressString); + + matcher.matches(); + + String address = matcher.group("address"); + + String quantityString = matcher.group("quantity"); + int quantity = quantityString != null ? Integer.parseInt(quantityString) : 1; + + Plc4xDataType dataType = (matcher.group("datatype") != null) ? Plc4xDataType.valueOf(matcher.group("datatype")) : Plc4xDataType.BOOL; + + + return new Plc4xPlcTag(address, quantity, dataType); + } + + throw new PlcInvalidTagException("Unable to parse address: " + addressString); + } + + protected Plc4xPlcTag(String address, Integer quantity, Plc4xDataType dataType) { + this.address = address; + + this.quantity = quantity != null ? quantity : 1; + + this.dataType = dataType != null ? dataType : Plc4xDataType.INT; + } + + public static boolean matches(String addressString) { + return ADDRESS_PATTERN.matcher(addressString).matches(); + } + + public String getAddress() { + return address; + } + + public int getNumberOfElements() { + return quantity; + } + + public int getLengthBytes() { + return quantity * dataType.getDataTypeSize(); + } + + @JsonIgnore + public int getLengthWords() { + return (int) ((quantity * (float) dataType.getDataTypeSize()) / 2.0f); + } + + public Plc4xDataType getDataType() { + return dataType; + } + + public String getPlcDataType() { + return dataType.name(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Plc4xPlcTag)) { + return false; + } + Plc4xPlcTag that = (Plc4xPlcTag) o; + return address == that.address; + } + + @Override + public int hashCode() { + return Objects.hash(address); + } + + @Override + public String toString() { + return "Plc4xPlcField{" + + " address=" + address + + " datatype=" + dataType + + " quantity=" + quantity + + " }"; + } + + @Override + public void serialize(WriteBuffer wb) throws SerializationException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getAddressString() { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xevent/messages/messages_en_US.properties b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xevent/messages/messages_en_US.properties new file mode 100644 index 00000000000..70a5e66f92e --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xevent/messages/messages_en_US.properties @@ -0,0 +1,81 @@ + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +Plc4x.Category.plc4x=Plc4x +Plc4x.Read.Name=Plc4x Event Transform +Plc4x.Read.Description=Plc4x Event Transform Description +Plc4x.Read.Shell.Title=Plc4x Event Transform Title +Plc4x.Read.TransformName.Label=Plc4x Event Sample Name + +Plc4x.Read.Meta.Injection.Connection=Connection +Plc4x.Read.Meta.Injection.NeverEnding=Nerverending +Plc4x.Read.Meta.Injection.MaxwaitInMs=MaxwaitIn +Plc4x.Read.Meta.Injection.IntervalInMs=IntervalIn +Plc4x.Read.Meta.Injection.RowTimeField=RowTimeField +Plc4x.Read.Meta.Injection.LastTimeField=LastTimeField +Plc4x.Read.Meta.Injection.RowLimit=RowLimit +Plc4x.Read.Meta.Injection.Fields=Fields + +Plc4x.Read.Meta.Injection.ModeEvent=ModeEvent +Plc4x.Read.Meta.Injection.UserEvent=UserEvent +Plc4x.Read.Meta.Injection.SysEvent=SysEvent +Plc4x.Read.Meta.Injection.AlarmEvent=AlarmEvent + +Plc4x.Read.Meta.Injection.Field.Name=Name +Plc4x.Read.Meta.Injection.Field.Item=Item +Plc4x.Read.Meta.Injection.Field.Type=Type +Plc4x.Read.Meta.Injection.Field.Format=Format +Plc4x.Read.Meta.Injection.Field.Length=Length +Plc4x.Read.Meta.Injection.Field.Precision=Precision +Plc4x.Read.Meta.Injection.Field.Units=Units +Plc4x.Read.Meta.Injection.Field.Decimal=Decimal +Plc4x.Read.Meta.Injection.Field.Group=Group +Plc4x.Read.Meta.Injection.Field.Value=Value +Plc4x.Read.Meta.Injection.Field.SetEmptyString=Empty + +Plc4x.Read.Meta.Illegal.Dialog.Settings.Message=The Message +Plc4x.Read.Meta.Dialog.Settings.Title=Dialog +Plc4x.Read.Meta.Dialog.DialogTitle=Plc4x Read transformer +Plc4x.Read.Meta.Dialog.Limit.Label=Limit +Plc4x.Read.Meta.Dialog.NeverEnding.Label=Never ending + +Plc4x.Read.Meta.Dialog.ModeEvent.Label=Mode event +Plc4x.Read.Meta.Dialog.UserEvent.Label=User event +Plc4x.Read.Meta.Dialog.SysEvent.Label=Sys event +Plc4x.Read.Meta.Dialog.UserEvent.Label=User event +Plc4x.Read.Meta.Dialog.AlarmEvent.Label=Alarm event + +Plc4x.Read.Meta.Dialog.Maxwait.Label=Max waiting +Plc4x.Read.Meta.Dialog.Interval.Label=Interval +Plc4x.Read.Meta.Dialog.RowTimeField.Label=Time +Plc4x.Read.Meta.Dialog.LastTimeField.Label=Last Time +Plc4x.Read.Meta.Dialog.Fields.Label=Fields +Plc4x.Read.Meta.Dialog.Fields.Item=Item +Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Title=Alert +Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Message=Message +Plc4x.Read.Meta.Dialog.Connection.Label=Connection EN +Plc4x.Read.Meta.Dialog.Connection.Tooltip=Plc4x connection metadata EN +Plc4x.Read.Meta.BuildRow.Error.Parsing.Number=Error parsing number +Plc4x.Read.Meta.BuildRow.Error.Parsing.Date=Error parsing date +Plc4x.Read.Meta.BuildRow.Error.Parsing.Integer=Error parsing integer +Plc4x.Read.Meta.BuildRow.Error.Parsing.BigNumber=Error parsing bignumber +Plc4x.Read.Meta.BuildRow.Error.Parsing.Timestamp=Error parsing timestamp +Plc4x.Read.Meta.CheckResult.SpecifyTypeError=Errot type +Plc4x.Read.Meta.Wrong.RowLimit.Number=Error in the number of row +System.Column.SetEmptyString=Set empty string? +Plc4x.Read.Meta.Log.SetMetadata=Check your connection setings +Plc4x.Read.Meta.Log.UnableToCreateConnection=Unable to create connection to PLC diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xevent/messages/messages_es_ES.properties b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xevent/messages/messages_es_ES.properties new file mode 100644 index 00000000000..4fba5312296 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xevent/messages/messages_es_ES.properties @@ -0,0 +1,69 @@ + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +Plc4x.Category.plc4x=Plc4x +Plc4x.Read.Name=Plc4x Event Transform +Plc4x.Read.Description=Plc4x Event Transform Description +Plc4x.Read.Shell.Title=Plc4x Event Transform Title +Plc4x.Read.TransformName.Label=Plc4x Event Sample Name + +Plc4x.Read.Meta.Injection.NeverEnding=Connection +Plc4x.Read.Meta.Injection.NeverEnding=Nerverending +Plc4x.Read.Meta.Injection.MaxwaitInMs=MaxwaitIn +Plc4x.Read.Meta.Injection.IntervalInMs=IntervalIn +Plc4x.Read.Meta.Injection.RowTimeField=RowTimeField +Plc4x.Read.Meta.Injection.LastTimeField=LastTimeField +Plc4x.Read.Meta.Injection.RowLimit=RowLimit +Plc4x.Read.Meta.Injection.Fields=Fields + +Plc4x.Read.Meta.Injection.Field.Name=Name +Plc4x.Read.Meta.Injection.Field.Item=Item +Plc4x.Read.Meta.Injection.Field.Type=Type +Plc4x.Read.Meta.Injection.Field.Format=Format +Plc4x.Read.Meta.Injection.Field.Length=Length +Plc4x.Read.Meta.Injection.Field.Precision=Precision +Plc4x.Read.Meta.Injection.Field.Units=Units +Plc4x.Read.Meta.Injection.Field.Decimal=Decimal +Plc4x.Read.Meta.Injection.Field.Group=Group +Plc4x.Read.Meta.Injection.Field.Value=Value +Plc4x.Read.Meta.Injection.Field.SetEmptyString=Empty + +Plc4x.Read.Meta.Illegal.Dialog.Settings.Message=The Message +Plc4x.Read.Meta.Dialog.Settings.Title=Dialog +Plc4x.Read.Meta.Dialog.DialogTitle=Plc4x Read transformer +Plc4x.Read.Meta.Dialog.Limit.Label=Limit +Plc4x.Read.Meta.Dialog.NeverEnding.Label=Bucle sin fin +Plc4x.Read.Meta.Dialog.Maxwait.Label=Max waiting +Plc4x.Read.Meta.Dialog.Interval.Label=Interval +Plc4x.Read.Meta.Dialog.RowTimeField.Label=Time +Plc4x.Read.Meta.Dialog.LastTimeField.Label=Last Time +Plc4x.Read.Meta.Dialog.Fields.Label=Fields +Plc4x.Read.Meta.Dialog.Fields.Item=Item +Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Title=Alert +Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Message=Message +Plc4x.Read.Meta.Dialog.Connection.Label=Connection ES +Plc4x.Read.Meta.Dialog.Connection.Tooltip=Plc4x connection metadata ES +Plc4x.Read.Meta.BuildRow.Error.Parsing.Number=Error parsing number +Plc4x.Read.Meta.BuildRow.Error.Parsing.Date=Error parsing date +Plc4x.Read.Meta.BuildRow.Error.Parsing.Integer=Error parsing integer +Plc4x.Read.Meta.BuildRow.Error.Parsing.BigNumber=Error parsing bignumber +Plc4x.Read.Meta.BuildRow.Error.Parsing.Timestamp=Error parsing timestamp +Plc4x.Read.Meta.CheckResult.SpecifyTypeError=Errot type +Plc4x.Read.Meta.Wrong.RowLimit.Number=Error in the number of row +System.Column.SetEmptyString=Set empty string? +Plc4x.Read.Meta.Log.SetMetadata=Check your connection setings +Plc4x.Read.Meta.Log.UnableToCreateConnection=Unable to create connection to PLC diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xinput/messages/messages_en_US.properties b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xinput/messages/messages_en_US.properties new file mode 100644 index 00000000000..59072612a7e --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xinput/messages/messages_en_US.properties @@ -0,0 +1,69 @@ + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +Plc4x.Category.plc4x=Plc4x +Plc4x.Read.Name=Plc4x Read Transform +Plc4x.Read.Description=Plc4x Read Transform Description +Plc4x.Read.Shell.Title=Plc4x Read Transform Title +Plc4x.Read.TransformName.Label=Plc4x Read Sample Name + +Plc4x.Read.Meta.Injection.NeverEnding=Connection +Plc4x.Read.Meta.Injection.NeverEnding=Nerverending +Plc4x.Read.Meta.Injection.MaxwaitInMs=MaxwaitIn +Plc4x.Read.Meta.Injection.IntervalInMs=IntervalIn +Plc4x.Read.Meta.Injection.RowTimeField=RowTimeField +Plc4x.Read.Meta.Injection.LastTimeField=LastTimeField +Plc4x.Read.Meta.Injection.RowLimit=RowLimit +Plc4x.Read.Meta.Injection.Fields=Fields + +Plc4x.Read.Meta.Injection.Field.Name=Name +Plc4x.Read.Meta.Injection.Field.Item=Item +Plc4x.Read.Meta.Injection.Field.Type=Type +Plc4x.Read.Meta.Injection.Field.Format=Format +Plc4x.Read.Meta.Injection.Field.Length=Length +Plc4x.Read.Meta.Injection.Field.Precision=Precision +Plc4x.Read.Meta.Injection.Field.Units=Units +Plc4x.Read.Meta.Injection.Field.Decimal=Decimal +Plc4x.Read.Meta.Injection.Field.Group=Group +Plc4x.Read.Meta.Injection.Field.Value=Value +Plc4x.Read.Meta.Injection.Field.SetEmptyString=Empty + +Plc4x.Read.Meta.Illegal.Dialog.Settings.Message=The Message +Plc4x.Read.Meta.Dialog.Settings.Title=Dialog +Plc4x.Read.Meta.Dialog.DialogTitle=Plc4x Read transformer +Plc4x.Read.Meta.Dialog.Limit.Label=Limit +Plc4x.Read.Meta.Dialog.NeverEnding.Label=Never ending +Plc4x.Read.Meta.Dialog.Maxwait.Label=Max waiting +Plc4x.Read.Meta.Dialog.Interval.Label=Interval +Plc4x.Read.Meta.Dialog.RowTimeField.Label=Time +Plc4x.Read.Meta.Dialog.LastTimeField.Label=Last Time +Plc4x.Read.Meta.Dialog.Fields.Label=Fields +Plc4x.Read.Meta.Dialog.Fields.Item=Item +Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Title=Alert +Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Message=Message +Plc4x.Read.Meta.Dialog.Connection.Label=Connection EN +Plc4x.Read.Meta.Dialog.Connection.Tooltip=Plc4x connection metadata EN +Plc4x.Read.Meta.BuildRow.Error.Parsing.Number=Error parsing number +Plc4x.Read.Meta.BuildRow.Error.Parsing.Date=Error parsing date +Plc4x.Read.Meta.BuildRow.Error.Parsing.Integer=Error parsing integer +Plc4x.Read.Meta.BuildRow.Error.Parsing.BigNumber=Error parsing bignumber +Plc4x.Read.Meta.BuildRow.Error.Parsing.Timestamp=Error parsing timestamp +Plc4x.Read.Meta.CheckResult.SpecifyTypeError=Errot type +Plc4x.Read.Meta.Wrong.RowLimit.Number=Error in the number of row +System.Column.SetEmptyString=Set empty string? +Plc4x.Read.Meta.Log.SetMetadata=Check your connection setings +Plc4x.Read.Meta.Log.UnableToCreateConnection=Unable to create connection to PLC diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xinput/messages/messages_es_ES.properties b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xinput/messages/messages_es_ES.properties new file mode 100644 index 00000000000..20a5d8f4b2f --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xinput/messages/messages_es_ES.properties @@ -0,0 +1,69 @@ + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +Plc4x.Category.plc4x=Plc4x +Plc4x.Read.Name=Plc4x Read Transform +Plc4x.Read.Description=Plc4x Read Transform Description +Plc4x.Read.Shell.Title=Plc4x Read Transform Title +Plc4x.Read.TransformName.Label=Plc4x Read Sample Name + +Plc4x.Read.Meta.Injection.NeverEnding=Connection +Plc4x.Read.Meta.Injection.NeverEnding=Nerverending +Plc4x.Read.Meta.Injection.MaxwaitInMs=MaxwaitIn +Plc4x.Read.Meta.Injection.IntervalInMs=IntervalIn +Plc4x.Read.Meta.Injection.RowTimeField=RowTimeField +Plc4x.Read.Meta.Injection.LastTimeField=LastTimeField +Plc4x.Read.Meta.Injection.RowLimit=RowLimit +Plc4x.Read.Meta.Injection.Fields=Fields + +Plc4x.Read.Meta.Injection.Field.Name=Name +Plc4x.Read.Meta.Injection.Field.Item=Item +Plc4x.Read.Meta.Injection.Field.Type=Type +Plc4x.Read.Meta.Injection.Field.Format=Format +Plc4x.Read.Meta.Injection.Field.Length=Length +Plc4x.Read.Meta.Injection.Field.Precision=Precision +Plc4x.Read.Meta.Injection.Field.Units=Units +Plc4x.Read.Meta.Injection.Field.Decimal=Decimal +Plc4x.Read.Meta.Injection.Field.Group=Group +Plc4x.Read.Meta.Injection.Field.Value=Value +Plc4x.Read.Meta.Injection.Field.SetEmptyString=Empty + +Plc4x.Read.Meta.Illegal.Dialog.Settings.Message=The Message +Plc4x.Read.Meta.Dialog.Settings.Title=Dialog +Plc4x.Read.Meta.Dialog.DialogTitle=Plc4x Read transformer +Plc4x.Read.Meta.Dialog.Limit.Label=Limit +Plc4x.Read.Meta.Dialog.NeverEnding.Label=Bucle sin fin +Plc4x.Read.Meta.Dialog.Maxwait.Label=Max waiting +Plc4x.Read.Meta.Dialog.Interval.Label=Interval +Plc4x.Read.Meta.Dialog.RowTimeField.Label=Time +Plc4x.Read.Meta.Dialog.LastTimeField.Label=Last Time +Plc4x.Read.Meta.Dialog.Fields.Label=Fields +Plc4x.Read.Meta.Dialog.Fields.Item=Item +Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Title=Alert +Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Message=Message +Plc4x.Read.Meta.Dialog.Connection.Label=Connection ES +Plc4x.Read.Meta.Dialog.Connection.Tooltip=Plc4x connection metadata ES +Plc4x.Read.Meta.BuildRow.Error.Parsing.Number=Error parsing number +Plc4x.Read.Meta.BuildRow.Error.Parsing.Date=Error parsing date +Plc4x.Read.Meta.BuildRow.Error.Parsing.Integer=Error parsing integer +Plc4x.Read.Meta.BuildRow.Error.Parsing.BigNumber=Error parsing bignumber +Plc4x.Read.Meta.BuildRow.Error.Parsing.Timestamp=Error parsing timestamp +Plc4x.Read.Meta.CheckResult.SpecifyTypeError=Errot type +Plc4x.Read.Meta.Wrong.RowLimit.Number=Error in the number of row +System.Column.SetEmptyString=Set empty string? +Plc4x.Read.Meta.Log.SetMetadata=Check your connection setings +Plc4x.Read.Meta.Log.UnableToCreateConnection=Unable to create connection to PLC diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xoutput/messages/messages_en_US.properties b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xoutput/messages/messages_en_US.properties new file mode 100644 index 00000000000..8bdd7fd697a --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xoutput/messages/messages_en_US.properties @@ -0,0 +1,69 @@ + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +Plc4x.Category.plc4x=Plc4x +Plc4x.Read.Name=Plc4x Write Transform +Plc4x.Read.Description=Plc4x Write Transform Description +Plc4x.Read.Shell.Title=Plc4x Write Transform Title +Plc4x.Read.TransformName.Label=Plc4x Write Sample Name + +Plc4x.Read.Meta.Injection.NeverEnding=Connection +Plc4x.Read.Meta.Injection.NeverEnding=Nerverending +Plc4x.Read.Meta.Injection.MaxwaitInMs=MaxwaitIn +Plc4x.Read.Meta.Injection.IntervalInMs=IntervalIn +Plc4x.Read.Meta.Injection.RowTimeField=RowTimeField +Plc4x.Read.Meta.Injection.LastTimeField=LastTimeField +Plc4x.Read.Meta.Injection.RowLimit=RowLimit +Plc4x.Read.Meta.Injection.Fields=Fields + +Plc4x.Read.Meta.Injection.Field.Name=Name +Plc4x.Read.Meta.Injection.Field.Item=Item +Plc4x.Read.Meta.Injection.Field.Type=Type +Plc4x.Read.Meta.Injection.Field.Format=Format +Plc4x.Read.Meta.Injection.Field.Length=Length +Plc4x.Read.Meta.Injection.Field.Precision=Precision +Plc4x.Read.Meta.Injection.Field.Units=Units +Plc4x.Read.Meta.Injection.Field.Decimal=Decimal +Plc4x.Read.Meta.Injection.Field.Group=Group +Plc4x.Read.Meta.Injection.Field.Value=Value +Plc4x.Read.Meta.Injection.Field.SetEmptyString=Empty + +Plc4x.Read.Meta.Illegal.Dialog.Settings.Message=The Message +Plc4x.Read.Meta.Dialog.Settings.Title=Dialog +Plc4x.Read.Meta.Dialog.DialogTitle=Plc4x Read transformer +Plc4x.Read.Meta.Dialog.Limit.Label=Limit +Plc4x.Read.Meta.Dialog.NeverEnding.Label=Never ending +Plc4x.Read.Meta.Dialog.Maxwait.Label=Max waiting +Plc4x.Read.Meta.Dialog.Interval.Label=Interval +Plc4x.Read.Meta.Dialog.RowTimeField.Label=Time +Plc4x.Read.Meta.Dialog.LastTimeField.Label=Last Time +Plc4x.Read.Meta.Dialog.Fields.Label=Fields +Plc4x.Read.Meta.Dialog.Fields.Item=Item +Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Title=Alert +Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Message=Message +Plc4x.Read.Meta.Dialog.Connection.Label=Connection EN +Plc4x.Read.Meta.Dialog.Connection.Tooltip=Plc4x connection metadata EN +Plc4x.Read.Meta.BuildRow.Error.Parsing.Number=Error parsing number +Plc4x.Read.Meta.BuildRow.Error.Parsing.Date=Error parsing date +Plc4x.Read.Meta.BuildRow.Error.Parsing.Integer=Error parsing integer +Plc4x.Read.Meta.BuildRow.Error.Parsing.BigNumber=Error parsing bignumber +Plc4x.Read.Meta.BuildRow.Error.Parsing.Timestamp=Error parsing timestamp +Plc4x.Read.Meta.CheckResult.SpecifyTypeError=Errot type +Plc4x.Read.Meta.Wrong.RowLimit.Number=Error in the number of row +System.Column.SetEmptyString=Set empty string? +Plc4x.Read.Meta.Log.SetMetadata=Check your connection setings +Plc4x.Read.Meta.Log.UnableToCreateConnection=Unable to create connection to PLC diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xoutput/messages/messages_es_ES.properties b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xoutput/messages/messages_es_ES.properties new file mode 100644 index 00000000000..b4d048a18c5 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xoutput/messages/messages_es_ES.properties @@ -0,0 +1,69 @@ + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +Plc4x.Category.plc4x=Plc4x +Plc4x.Read.Name=Plc4x Write Transform +Plc4x.Read.Description=Plc4x Write Transform Description +Plc4x.Read.Shell.Title=Plc4x Write Transform Title +Plc4x.Read.TransformName.Label=Plc4x Write Sample Name + +Plc4x.Read.Meta.Injection.NeverEnding=Connection +Plc4x.Read.Meta.Injection.NeverEnding=Nerverending +Plc4x.Read.Meta.Injection.MaxwaitInMs=MaxwaitIn +Plc4x.Read.Meta.Injection.IntervalInMs=IntervalIn +Plc4x.Read.Meta.Injection.RowTimeField=RowTimeField +Plc4x.Read.Meta.Injection.LastTimeField=LastTimeField +Plc4x.Read.Meta.Injection.RowLimit=RowLimit +Plc4x.Read.Meta.Injection.Fields=Fields + +Plc4x.Read.Meta.Injection.Field.Name=Name +Plc4x.Read.Meta.Injection.Field.Item=Item +Plc4x.Read.Meta.Injection.Field.Type=Type +Plc4x.Read.Meta.Injection.Field.Format=Format +Plc4x.Read.Meta.Injection.Field.Length=Length +Plc4x.Read.Meta.Injection.Field.Precision=Precision +Plc4x.Read.Meta.Injection.Field.Units=Units +Plc4x.Read.Meta.Injection.Field.Decimal=Decimal +Plc4x.Read.Meta.Injection.Field.Group=Group +Plc4x.Read.Meta.Injection.Field.Value=Value +Plc4x.Read.Meta.Injection.Field.SetEmptyString=Empty + +Plc4x.Read.Meta.Illegal.Dialog.Settings.Message=The Message +Plc4x.Read.Meta.Dialog.Settings.Title=Dialog +Plc4x.Read.Meta.Dialog.DialogTitle=Plc4x Read transformer +Plc4x.Read.Meta.Dialog.Limit.Label=Limit +Plc4x.Read.Meta.Dialog.NeverEnding.Label=Bucle sin fin +Plc4x.Read.Meta.Dialog.Maxwait.Label=Max waiting +Plc4x.Read.Meta.Dialog.Interval.Label=Interval +Plc4x.Read.Meta.Dialog.RowTimeField.Label=Time +Plc4x.Read.Meta.Dialog.LastTimeField.Label=Last Time +Plc4x.Read.Meta.Dialog.Fields.Label=Fields +Plc4x.Read.Meta.Dialog.Fields.Item=Item +Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Title=Alert +Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Message=Message +Plc4x.Read.Meta.Dialog.Connection.Label=Connection ES +Plc4x.Read.Meta.Dialog.Connection.Tooltip=Plc4x connection metadata ES +Plc4x.Read.Meta.BuildRow.Error.Parsing.Number=Error parsing number +Plc4x.Read.Meta.BuildRow.Error.Parsing.Date=Error parsing date +Plc4x.Read.Meta.BuildRow.Error.Parsing.Integer=Error parsing integer +Plc4x.Read.Meta.BuildRow.Error.Parsing.BigNumber=Error parsing bignumber +Plc4x.Read.Meta.BuildRow.Error.Parsing.Timestamp=Error parsing timestamp +Plc4x.Read.Meta.CheckResult.SpecifyTypeError=Errot type +Plc4x.Read.Meta.Wrong.RowLimit.Number=Error in the number of row +System.Column.SetEmptyString=Set empty string? +Plc4x.Read.Meta.Log.SetMetadata=Check your connection setings +Plc4x.Read.Meta.Log.UnableToCreateConnection=Unable to create connection to PLC diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xsubs/messages/messages_en_US.properties b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xsubs/messages/messages_en_US.properties new file mode 100644 index 00000000000..cbcf6a63dac --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xsubs/messages/messages_en_US.properties @@ -0,0 +1,69 @@ + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +Plc4x.Category.plc4x=Plc4x +Plc4x.Read.Name=Plc4x Subscription Transform +Plc4x.Read.Description=Plc4x Subscription Transform Description +Plc4x.Read.Shell.Title=Plc4x Subscription Transform Title +Plc4x.Read.TransformName.Label=Plc4x Subscription Sample Name + +Plc4x.Read.Meta.Injection.NeverEnding=Connection +Plc4x.Read.Meta.Injection.NeverEnding=Nerverending +Plc4x.Read.Meta.Injection.MaxwaitInMs=MaxwaitIn +Plc4x.Read.Meta.Injection.IntervalInMs=IntervalIn +Plc4x.Read.Meta.Injection.RowTimeField=RowTimeField +Plc4x.Read.Meta.Injection.LastTimeField=LastTimeField +Plc4x.Read.Meta.Injection.RowLimit=RowLimit +Plc4x.Read.Meta.Injection.Fields=Fields + +Plc4x.Read.Meta.Injection.Field.Name=Name +Plc4x.Read.Meta.Injection.Field.Item=Item +Plc4x.Read.Meta.Injection.Field.Type=Type +Plc4x.Read.Meta.Injection.Field.Format=Format +Plc4x.Read.Meta.Injection.Field.Length=Length +Plc4x.Read.Meta.Injection.Field.Precision=Precision +Plc4x.Read.Meta.Injection.Field.Units=Units +Plc4x.Read.Meta.Injection.Field.Decimal=Decimal +Plc4x.Read.Meta.Injection.Field.Group=Group +Plc4x.Read.Meta.Injection.Field.Value=Value +Plc4x.Read.Meta.Injection.Field.SetEmptyString=Empty + +Plc4x.Read.Meta.Illegal.Dialog.Settings.Message=The Message +Plc4x.Read.Meta.Dialog.Settings.Title=Dialog +Plc4x.Read.Meta.Dialog.DialogTitle=Plc4x Read transformer +Plc4x.Read.Meta.Dialog.Limit.Label=Limit +Plc4x.Read.Meta.Dialog.NeverEnding.Label=Never ending +Plc4x.Read.Meta.Dialog.Maxwait.Label=Max waiting +Plc4x.Read.Meta.Dialog.Interval.Label=Interval +Plc4x.Read.Meta.Dialog.RowTimeField.Label=Time +Plc4x.Read.Meta.Dialog.LastTimeField.Label=Last Time +Plc4x.Read.Meta.Dialog.Fields.Label=Fields +Plc4x.Read.Meta.Dialog.Fields.Item=Item +Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Title=Alert +Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Message=Message +Plc4x.Read.Meta.Dialog.Connection.Label=Connection EN +Plc4x.Read.Meta.Dialog.Connection.Tooltip=Plc4x connection metadata EN +Plc4x.Read.Meta.BuildRow.Error.Parsing.Number=Error parsing number +Plc4x.Read.Meta.BuildRow.Error.Parsing.Date=Error parsing date +Plc4x.Read.Meta.BuildRow.Error.Parsing.Integer=Error parsing integer +Plc4x.Read.Meta.BuildRow.Error.Parsing.BigNumber=Error parsing bignumber +Plc4x.Read.Meta.BuildRow.Error.Parsing.Timestamp=Error parsing timestamp +Plc4x.Read.Meta.CheckResult.SpecifyTypeError=Errot type +Plc4x.Read.Meta.Wrong.RowLimit.Number=Error in the number of row +System.Column.SetEmptyString=Set empty string? +Plc4x.Read.Meta.Log.SetMetadata=Check your connection setings +Plc4x.Read.Meta.Log.UnableToCreateConnection=Unable to create connection to PLC diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xsubs/messages/messages_es_ES.properties b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xsubs/messages/messages_es_ES.properties new file mode 100644 index 00000000000..44279b8dec2 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/org/apache/plc4x/hop/transforms/plc4xsubs/messages/messages_es_ES.properties @@ -0,0 +1,69 @@ + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +Plc4x.Category.plc4x=Plc4x +Plc4x.Read.Name=Plc4x Subscription Transform +Plc4x.Read.Description=Plc4x Subscription Transform Description +Plc4x.Read.Shell.Title=Plc4x Subscription Transform Title +Plc4x.Read.TransformName.Label=Plc4x Subscription Sample Name + +Plc4x.Read.Meta.Injection.NeverEnding=Connection +Plc4x.Read.Meta.Injection.NeverEnding=Nerverending +Plc4x.Read.Meta.Injection.MaxwaitInMs=MaxwaitIn +Plc4x.Read.Meta.Injection.IntervalInMs=IntervalIn +Plc4x.Read.Meta.Injection.RowTimeField=RowTimeField +Plc4x.Read.Meta.Injection.LastTimeField=LastTimeField +Plc4x.Read.Meta.Injection.RowLimit=RowLimit +Plc4x.Read.Meta.Injection.Fields=Fields + +Plc4x.Read.Meta.Injection.Field.Name=Name +Plc4x.Read.Meta.Injection.Field.Item=Item +Plc4x.Read.Meta.Injection.Field.Type=Type +Plc4x.Read.Meta.Injection.Field.Format=Format +Plc4x.Read.Meta.Injection.Field.Length=Length +Plc4x.Read.Meta.Injection.Field.Precision=Precision +Plc4x.Read.Meta.Injection.Field.Units=Units +Plc4x.Read.Meta.Injection.Field.Decimal=Decimal +Plc4x.Read.Meta.Injection.Field.Group=Group +Plc4x.Read.Meta.Injection.Field.Value=Value +Plc4x.Read.Meta.Injection.Field.SetEmptyString=Empty + +Plc4x.Read.Meta.Illegal.Dialog.Settings.Message=The Message +Plc4x.Read.Meta.Dialog.Settings.Title=Dialog +Plc4x.Read.Meta.Dialog.DialogTitle=Plc4x Read transformer +Plc4x.Read.Meta.Dialog.Limit.Label=Limit +Plc4x.Read.Meta.Dialog.NeverEnding.Label=Bucle sin fin +Plc4x.Read.Meta.Dialog.Maxwait.Label=Max waiting +Plc4x.Read.Meta.Dialog.Interval.Label=Interval +Plc4x.Read.Meta.Dialog.RowTimeField.Label=Time +Plc4x.Read.Meta.Dialog.LastTimeField.Label=Last Time +Plc4x.Read.Meta.Dialog.Fields.Label=Fields +Plc4x.Read.Meta.Dialog.Fields.Item=Item +Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Title=Alert +Plc4x.Read.Meta.Dialog.Illegal.Dialog.Settings.Message=Message +Plc4x.Read.Meta.Dialog.Connection.Label=Connection ES +Plc4x.Read.Meta.Dialog.Connection.Tooltip=Plc4x connection metadata ES +Plc4x.Read.Meta.BuildRow.Error.Parsing.Number=Error parsing number +Plc4x.Read.Meta.BuildRow.Error.Parsing.Date=Error parsing date +Plc4x.Read.Meta.BuildRow.Error.Parsing.Integer=Error parsing integer +Plc4x.Read.Meta.BuildRow.Error.Parsing.BigNumber=Error parsing bignumber +Plc4x.Read.Meta.BuildRow.Error.Parsing.Timestamp=Error parsing timestamp +Plc4x.Read.Meta.CheckResult.SpecifyTypeError=Errot type +Plc4x.Read.Meta.Wrong.RowLimit.Number=Error in the number of row +System.Column.SetEmptyString=Set empty string? +Plc4x.Read.Meta.Log.SetMetadata=Check your connection setings +Plc4x.Read.Meta.Log.UnableToCreateConnection=Unable to create connection to PLC diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/plc4x_action.svg b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/plc4x_action.svg new file mode 100644 index 00000000000..01694ecd5df --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/plc4x_action.svg @@ -0,0 +1,1306 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/plc4x_event.svg b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/plc4x_event.svg new file mode 100644 index 00000000000..21ed5ecb1ed --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/plc4x_event.svg @@ -0,0 +1,822 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/plc4x_read.svg b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/plc4x_read.svg new file mode 100644 index 00000000000..c67b42523ad --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/plc4x_read.svg @@ -0,0 +1,813 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/plc4x_subs.svg b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/plc4x_subs.svg new file mode 100644 index 00000000000..87f84f3f855 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/plc4x_subs.svg @@ -0,0 +1,743 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/plc4x_write.svg b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/plc4x_write.svg new file mode 100644 index 00000000000..9b295c3ea71 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-transformer/src/main/resources/plc4x_write.svg @@ -0,0 +1,810 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/pom.xml b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/pom.xml new file mode 100644 index 00000000000..214a8dc009f --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/pom.xml @@ -0,0 +1,138 @@ + + + + 4.0.0 + + org.apache.plc4x + hop-plc4x-utils + 0.11.0-SNAPSHOT + + plc4x-hop-grafana + jar + PLC4J: Integrations: Apache Hop: Grafana Post + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + org.jboss.jandex + jandex-maven-plugin + 1.0.8 + + + make-index + + jandex + + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + io.netty:netty-common:jar:${netty.version} + io.netty:netty-all:jar:${netty.version} + commons-lang:commons-lang:jar:2.6 + xml-apis:xml-apis:jar:1.4.01 + + + + + + + + + org.apache.httpcomponents + httpclient + 4.5.13 + + + org.apache.hop + hop-core + ${hop.version} + + + * + * + + + + + org.apache.hop + hop-engine + ${hop.version} + + + * + * + + + + + org.apache.hop + hop-ui + ${hop.version} + + + * + * + + + + + com.google.guava + guava + 30.1.1-jre + + + com.googlecode.json-simple + json-simple + 1.1.1 + + + commons-lang + commons-lang + 2.6 + + + org.eclipse.platform + org.eclipse.swt.gtk.linux.x86_64 + 3.114.0 + + + org.apache.httpcomponents + httpcore + 4.4.16 + + + \ No newline at end of file diff --git a/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPost.java b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPost.java new file mode 100644 index 00000000000..ba590cd0ca8 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPost.java @@ -0,0 +1,589 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.plc4x.hop.utils.transforms.grafana; + +import com.google.common.annotations.VisibleForTesting; +import org.apache.commons.lang.StringUtils; +import org.apache.hop.core.Const; +import org.apache.hop.core.exception.HopException; +import org.apache.hop.core.exception.HopTransformException; +import org.apache.hop.core.row.RowDataUtil; +import org.apache.hop.core.util.HttpClientManager; +import org.apache.hop.core.util.StringUtil; +import org.apache.hop.core.util.Utils; +import org.apache.hop.i18n.BaseMessages; +import org.apache.hop.pipeline.Pipeline; +import org.apache.hop.pipeline.PipelineMeta; +import org.apache.hop.pipeline.transform.BaseTransform; +import org.apache.hop.pipeline.transform.ITransform; +import org.apache.hop.pipeline.transform.TransformMeta; +import org.apache.http.*; +import org.apache.http.client.AuthCache; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.protocol.HttpClientContext; +import org.apache.http.client.utils.URIBuilder; +import org.apache.http.entity.ByteArrayEntity; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.InputStreamEntity; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.auth.BasicScheme; +import org.apache.http.impl.client.BasicAuthCache; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.message.BasicNameValuePair; +import org.apache.http.util.EntityUtils; +import org.json.simple.JSONObject; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.net.HttpURLConnection; +import java.net.URLEncoder; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.apache.plc4x.hop.utils.transforms.grafana.GrafanaPostMeta.DEFAULT_ENCODING; + +/** Make a HTTP Post call */ +public class GrafanaPost extends BaseTransform implements ITransform { + + private static final Class PKG = GrafanaPostMeta.class; // For Translator + + private static final String CONTENT_TYPE = "Content-type"; + private static final String CONTENT_TYPE_TEXT_XML = "text/xml"; + private static final String PKG_HEADER_VALUE = "HTTPPOST.Log.HeaderValue"; + private static final String PKG_ERROR_FINDING_FIELD = "HTTPPOST.Log.ErrorFindingField"; + + public GrafanaPost( + TransformMeta transformMeta, + GrafanaPostMeta meta, + GrafanaPostData data, + int copyNr, + PipelineMeta pipelineMeta, + Pipeline pipeline) { + super(transformMeta, meta, data, copyNr, pipelineMeta, pipeline); + } + + private Object[] callHttpPOST(Object[] rowData) throws HopException { + HttpClientManager.HttpClientBuilderFacade clientBuilder = + HttpClientManager.getInstance().createBuilder(); + + if (data.realConnectionTimeout > -1) { + clientBuilder.setConnectionTimeout(data.realConnectionTimeout); + } + if (data.realSocketTimeout > -1) { + clientBuilder.setSocketTimeout(data.realSocketTimeout); + } + if (StringUtils.isNotBlank(data.realHttpLogin)) { + clientBuilder.setCredentials(data.realHttpLogin, data.realHttpPassword); + } + if (StringUtils.isNotBlank(data.realProxyHost)) { + clientBuilder.setProxy(data.realProxyHost, data.realProxyPort); + } + + CloseableHttpClient httpClient = clientBuilder.build(); + + // get dynamic url ? + if (meta.isUrlInField()) { + data.realUrl = data.inputRowMeta.getString(rowData, data.indexOfUrlField); + } + // Prepare HTTP POST + FileInputStream fis = null; + try { + if (isDetailed()) { + logDetailed(BaseMessages.getString(PKG, "HTTPPOST.Log.ConnectingToURL", data.realUrl)); + } + URIBuilder uriBuilder = new URIBuilder(data.realUrl); + org.apache.http.client.methods.HttpPost post = + new org.apache.http.client.methods.HttpPost(uriBuilder.build()); + + // Specify content type and encoding + // If content encoding is not explicitly specified + // ISO-8859-1 is assumed by the POSTMethod + if (!data.contentTypeHeaderOverwrite) { // can be overwritten now + if (Utils.isEmpty(data.realEncoding)) { + post.setHeader(CONTENT_TYPE, CONTENT_TYPE_TEXT_XML); + if (isDebug()) { + logDebug( + BaseMessages.getString(PKG, PKG_HEADER_VALUE, CONTENT_TYPE, CONTENT_TYPE_TEXT_XML)); + } + } else { + post.setHeader(CONTENT_TYPE, CONTENT_TYPE_TEXT_XML + "; " + data.realEncoding); + if (isDebug()) { + logDebug( + BaseMessages.getString( + PKG, + PKG_HEADER_VALUE, + CONTENT_TYPE, + CONTENT_TYPE_TEXT_XML + "; " + data.realEncoding)); + } + } + } + + // HEADER PARAMETERS + if (data.useHeaderParameters) { + // set header parameters that we want to send + for (int i = 0; i < data.header_parameters_nrs.length; i++) { + post.addHeader( + data.headerParameters[i].getName(), + data.inputRowMeta.getString(rowData, data.header_parameters_nrs[i])); + if (isDebug()) { + logDebug( + BaseMessages.getString( + PKG, + PKG_HEADER_VALUE, + data.headerParameters[i].getName(), + data.inputRowMeta.getString(rowData, data.header_parameters_nrs[i]))); + } + } + } + + // BODY PARAMETERS + if (data.useBodyParameters) { + // set body parameters that we want to send + for (int i = 0; i < data.body_parameters_nrs.length; i++) { + String bodyParameterName = data.bodyParameters[i].getName(); + String bodyParameterValue = + data.inputRowMeta.getString(rowData, data.body_parameters_nrs[i]); + data.bodyParameters[i] = new BasicNameValuePair(bodyParameterName, bodyParameterValue); + if (isDebug()) { + logDebug( + BaseMessages.getString( + PKG, "HTTPPOST.Log.BodyValue", bodyParameterName, bodyParameterValue)); + } + } + String bodyParams = getRequestBodyParamsAsStr(data.bodyParameters, data.realEncoding); + post.setEntity( + (new StringEntity(bodyParams, ContentType.TEXT_XML.withCharset("US-ASCII")))); + } + + // QUERY PARAMETERS + if (data.useQueryParameters) { + for (int i = 0; i < data.query_parameters_nrs.length; i++) { + String queryParameterName = data.queryParameters[i].getName(); + String queryParameterValue = + data.inputRowMeta.getString(rowData, data.query_parameters_nrs[i]); + data.queryParameters[i] = new BasicNameValuePair(queryParameterName, queryParameterValue); + if (isDebug()) { + logDebug( + BaseMessages.getString( + PKG, "HTTPPOST.Log.QueryValue", queryParameterName, queryParameterValue)); + } + } + post.setEntity(new UrlEncodedFormEntity(Arrays.asList(data.queryParameters))); + } + + // Set request entity? + if (data.indexOfRequestEntity >= 0) { + String tmp = data.inputRowMeta.getString(rowData, data.indexOfRequestEntity); + // Request content will be retrieved directly + // from the input stream + // Per default, the request content needs to be buffered + // in order to determine its length. + // Request body buffering can be avoided when + // content length is explicitly specified + + if (meta.isPostAFile()) { + File input = new File(tmp); + fis = new FileInputStream(input); + post.setEntity(new InputStreamEntity(fis, input.length())); + } else { + byte[] bytes; + if ((data.realEncoding != null) && (data.realEncoding.length() > 0)) { + bytes = tmp.getBytes(data.realEncoding); + } else { + bytes = tmp.getBytes(); + } + post.setEntity(new ByteArrayEntity(bytes)); + } + } + + // Execute request + Object[] newRow = null; + if (rowData != null) { + newRow = rowData.clone(); + } + CloseableHttpResponse httpResponse = null; + try { + // used for calculating the responseTime + long startTime = System.currentTimeMillis(); + + // Execute the POST method + if (StringUtils.isNotBlank(data.realProxyHost)) { + HttpHost target = new HttpHost(data.realProxyHost, data.realProxyPort, "http"); + // Create AuthCache instance + AuthCache authCache = new BasicAuthCache(); + // Generate BASIC scheme object and add it to the local + // auth cache + BasicScheme basicAuth = new BasicScheme(); + authCache.put(target, basicAuth); + // Add AuthCache to the execution context + HttpClientContext localContext = HttpClientContext.create(); + localContext.setAuthCache(authCache); + httpResponse = httpClient.execute(target, post, localContext); + } else { + httpResponse = httpClient.execute(post); + } + int statusCode = requestStatusCode(httpResponse); + + // calculate the responseTime + long responseTime = System.currentTimeMillis() - startTime; + + if (isDetailed()) { + logDetailed( + BaseMessages.getString(PKG, "HTTPPOST.Log.ResponseTime", responseTime, data.realUrl)); + } + + // Display status code + if (isDebug()) { + logDebug( + BaseMessages.getString(PKG, "HTTPPOST.Log.ResponseCode", String.valueOf(statusCode))); + } + + String body; + String headerString = ""; + switch (statusCode) { + case HttpURLConnection.HTTP_UNAUTHORIZED: + throw new HopTransformException( + BaseMessages.getString(PKG, "HTTPPOST.Exception.Authentication", data.realUrl)); + case -1: + throw new HopTransformException( + BaseMessages.getString(PKG, "HTTPPOST.Exception.IllegalStatusCode", data.realUrl)); + case HttpURLConnection.HTTP_NO_CONTENT: + body = ""; + break; + default: + HttpEntity entity = httpResponse.getEntity(); + if (entity != null) { + body = EntityUtils.toString(entity); + } else { + body = ""; + } + Header[] headers = searchForHeaders(httpResponse); + // Use request encoding if specified in component to avoid strange response encodings + + JSONObject json = new JSONObject(); + for (Header header : headers) { + Object previousValue = json.get(header.getName()); + if (previousValue == null) { + json.put(header.getName(), header.getValue()); + } else if (previousValue instanceof List) { + List list = (List) previousValue; + list.add(header.getValue()); + } else { + ArrayList list = new ArrayList<>(); + list.add((String) previousValue); + list.add(header.getValue()); + json.put(header.getName(), list); + } + } + headerString = json.toJSONString(); + } + + if (isDebug()) { + logDebug(BaseMessages.getString(PKG, "HTTPPOST.Log.ResponseBody", body)); + } + + int returnFieldsOffset = data.inputRowMeta.size(); + if (!Utils.isEmpty(meta.getHttpPostResultField().get(0).getName())) { + newRow = RowDataUtil.addValueData(newRow, returnFieldsOffset, body); + returnFieldsOffset++; + } + + if (!Utils.isEmpty(meta.getHttpPostResultField().get(0).getCode())) { + newRow = RowDataUtil.addValueData(newRow, returnFieldsOffset, Long.valueOf(statusCode)); + returnFieldsOffset++; + } + if (!Utils.isEmpty(meta.getHttpPostResultField().get(0).getResponseTimeFieldName())) { + newRow = RowDataUtil.addValueData(newRow, returnFieldsOffset, Long.valueOf(responseTime)); + returnFieldsOffset++; + } + if (!Utils.isEmpty(meta.getHttpPostResultField().get(0).getResponseHeaderFieldName())) { + newRow = RowDataUtil.addValueData(newRow, returnFieldsOffset, headerString); + } + } finally { + // Release current connection to the connection pool once you are done + post.releaseConnection(); + if (httpResponse != null) { + httpResponse.close(); + } + } + return newRow; + } catch (UnknownHostException uhe) { + throw new HopException( + BaseMessages.getString(PKG, "HTTPPOST.Error.UnknownHostException", uhe.getMessage())); + } catch (Exception e) { + throw new HopException( + BaseMessages.getString(PKG, "HTTPPOST.Error.CanNotReadURL", data.realUrl), e); + + } finally { + if (fis != null) { + BaseTransform.closeQuietly(fis); + } + } + } + + protected int requestStatusCode(HttpResponse httpResponse) { + return httpResponse.getStatusLine().getStatusCode(); + } + + protected InputStreamReader openStream(String encoding, HttpResponse httpResponse) + throws Exception { + if (!Utils.isEmpty(encoding)) { + return new InputStreamReader(httpResponse.getEntity().getContent(), encoding); + } else { + return new InputStreamReader(httpResponse.getEntity().getContent()); + } + } + + protected Header[] searchForHeaders(HttpResponse response) { + return response.getAllHeaders(); + } + + @Override + public boolean processRow() throws HopException { + + Object[] r = getRow(); // Get row from input rowset & set row busy! + if (r == null) { // no more input to be expected... + setOutputDone(); + return false; + } + if (first) { + first = false; + data.inputRowMeta = getInputRowMeta(); + data.outputRowMeta = getInputRowMeta().clone(); + meta.getFields(data.outputRowMeta, getTransformName(), null, null, this, metadataProvider); + + if (meta.isUrlInField()) { + if (Utils.isEmpty(meta.getUrlField())) { + logError(BaseMessages.getString(PKG, "HTTPPOST.Log.NoField")); + throw new HopException(BaseMessages.getString(PKG, "HTTPPOST.Log.NoField")); + } + + // cache the position of the field + if (data.indexOfUrlField < 0) { + String realUrlfieldName = resolve(meta.getUrlField()); + data.indexOfUrlField = data.inputRowMeta.indexOfValue((realUrlfieldName)); + if (data.indexOfUrlField < 0) { + // The field is unreachable ! + logError(BaseMessages.getString(PKG, PKG_ERROR_FINDING_FIELD, realUrlfieldName)); + throw new HopException( + BaseMessages.getString( + PKG, "HTTPPOST.Exception.ErrorFindingField", realUrlfieldName)); + } + } + } else { + data.realUrl = resolve(meta.getUrl()); + } + // set body parameters + int nrargs = meta.getLookupfield().get(0).getArgumentField().size(); + if (nrargs > 0) { + data.useBodyParameters = false; + data.useHeaderParameters = false; + data.contentTypeHeaderOverwrite = false; + int nrheader = 0; + int nrbody = 0; + for (int i = 0; i < nrargs; i++) { // split into body / header + if (meta.getLookupfield().get(0).getArgumentField().get(i).isHeader()) { + data.useHeaderParameters = true; // at least one header parameter + nrheader++; + } else { + data.useBodyParameters = true; // at least one body parameter + nrbody++; + } + } + data.header_parameters_nrs = new int[nrheader]; + data.headerParameters = new NameValuePair[nrheader]; + data.body_parameters_nrs = new int[nrbody]; + data.bodyParameters = new NameValuePair[nrbody]; + int posHeader = 0; + int posBody = 0; + for (int i = 0; i < nrargs; i++) { + int fieldIndex = + data.inputRowMeta.indexOfValue( + meta.getLookupfield().get(0).getArgumentField().get(i).getName()); + if (fieldIndex < 0) { + logError( + BaseMessages.getString(PKG, PKG_ERROR_FINDING_FIELD) + + meta.getLookupfield().get(0).getArgumentField().get(i).getName() + + "]"); + throw new HopTransformException( + BaseMessages.getString( + PKG, + "HTTPPOST.Exception.CouldnotFindField", + meta.getLookupfield().get(0).getArgumentField().get(i).getName())); + } + if (meta.getLookupfield().get(0).getArgumentField().get(i).isHeader()) { + data.header_parameters_nrs[posHeader] = fieldIndex; + data.headerParameters[posHeader] = + new BasicNameValuePair( + resolve(meta.getLookupfield().get(0).getArgumentField().get(i).getParameter()), + data.outputRowMeta.getString(r, data.header_parameters_nrs[posHeader])); + posHeader++; + if (CONTENT_TYPE.equalsIgnoreCase( + meta.getLookupfield().get(0).getArgumentField().get(i).getParameter())) { + data.contentTypeHeaderOverwrite = true; // Content-type will be overwritten + } + } else { + data.body_parameters_nrs[posBody] = fieldIndex; + data.bodyParameters[posBody] = + new BasicNameValuePair( + resolve(meta.getLookupfield().get(0).getArgumentField().get(i).getParameter()), + data.outputRowMeta.getString(r, data.body_parameters_nrs[posBody])); + posBody++; + } + } + } + // set query parameters + int nrQuery = meta.getLookupfield().get(0).getQueryField().size(); + if (nrQuery > 0) { + data.useQueryParameters = true; + data.query_parameters_nrs = new int[nrQuery]; + data.queryParameters = new NameValuePair[nrQuery]; + for (int i = 0; i < nrQuery; i++) { + data.query_parameters_nrs[i] = + data.inputRowMeta.indexOfValue( + meta.getLookupfield().get(0).getQueryField().get(i).getName()); + if (data.query_parameters_nrs[i] < 0) { + logError( + BaseMessages.getString(PKG, PKG_ERROR_FINDING_FIELD) + + meta.getLookupfield().get(0).getQueryField().get(i).getName() + + "]"); + throw new HopTransformException( + BaseMessages.getString( + PKG, + "HTTPPOST.Exception.CouldnotFindField", + meta.getLookupfield().get(0).getQueryField().get(i).getName())); + } + data.queryParameters[i] = + new BasicNameValuePair( + resolve(meta.getLookupfield().get(0).getQueryField().get(i).getParameter()), + data.outputRowMeta.getString(r, data.query_parameters_nrs[i])); + } + } + // set request entity? + if (!Utils.isEmpty(meta.getRequestEntity())) { + data.indexOfRequestEntity = + data.inputRowMeta.indexOfValue(resolve(meta.getRequestEntity())); + if (data.indexOfRequestEntity < 0) { + throw new HopTransformException( + BaseMessages.getString( + PKG, + "HTTPPOST.Exception.CouldnotFindRequestEntityField", + meta.getRequestEntity())); + } + } + data.realEncoding = resolve(meta.getEncoding()); + } // end if first + + try { + Object[] outputRowData = callHttpPOST(r); + putRow(data.outputRowMeta, outputRowData); // copy row to output rowset(s) + + if (checkFeedback(getLinesRead()) && isDetailed()) { + logDetailed(BaseMessages.getString(PKG, "HTTPPOST.LineNumber") + getLinesRead()); + } + } catch (HopException e) { + boolean sendToErrorRow = false; + String errorMessage = null; + + if (getTransformMeta().isDoingErrorHandling()) { + sendToErrorRow = true; + errorMessage = e.toString(); + } else { + logError(BaseMessages.getString(PKG, "HTTPPOST.ErrorInTransformRunning") + e.getMessage()); + setErrors(1); + logError(Const.getStackTracker(e)); + stopAll(); + setOutputDone(); // signal end to receiver(s) + return false; + } + + if (sendToErrorRow) { + // Simply add this row to the error row + putError(getInputRowMeta(), r, 1, errorMessage, null, "HTTPPOST001"); + } + } + + return true; + } + + @VisibleForTesting + String getRequestBodyParamsAsStr(NameValuePair[] pairs, String charset) throws HopException { + StringBuilder buf = new StringBuilder(); + try { + for (int i = 0; i < pairs.length; ++i) { + NameValuePair pair = pairs[i]; + if (pair.getName() != null) { + if (i > 0) { + buf.append("&"); + } + System.out.println("Caracter set: " + charset); + + if (!charset.matches("US-ASCII")) { + buf.append( + URLEncoder.encode( + pair.getName(), !StringUtil.isEmpty(charset) ? charset : DEFAULT_ENCODING)); + + if (!StringUtil.isEmpty(pair.getName())) + buf.append("="); + + if (pair.getValue() != null) { + buf.append( + URLEncoder.encode( + pair.getValue(), !StringUtil.isEmpty(charset) ? charset : DEFAULT_ENCODING)); + } + } else { + buf.append(pair.getName()); + + if (!StringUtil.isEmpty(pair.getName())) + buf.append("="); + + buf.append(pair.getValue()); + } + } + } + return buf.toString(); + } catch (UnsupportedEncodingException e) { + throw new HopException(e.getMessage(), e.getCause()); + } + } + + @Override + public boolean init() { + + if (super.init()) { + // get authentication settings once + data.realProxyHost = resolve(meta.getProxyHost()); + data.realProxyPort = Const.toInt(resolve(meta.getProxyPort()), 8080); + data.realHttpLogin = resolve(meta.getHttpLogin()); + data.realHttpPassword = Utils.resolvePassword(variables, meta.getHttpPassword()); + + data.realSocketTimeout = Const.toInt(resolve(meta.getSocketTimeout()), -1); + data.realConnectionTimeout = Const.toInt(resolve(meta.getSocketTimeout()), -1); + data.realcloseIdleConnectionsTime = + Const.toInt(resolve(meta.getCloseIdleConnectionsTime()), -1); + + return true; + } + return false; + } +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPostArgumentField.java b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPostArgumentField.java new file mode 100644 index 00000000000..29af6b04749 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPostArgumentField.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.plc4x.hop.utils.transforms.grafana; + +import org.apache.hop.metadata.api.HopMetadataProperty; + +public class GrafanaPostArgumentField { + + @HopMetadataProperty(injectionKeyDescription = "HTTPPOST.Injection.ArgumentFieldName") + private String name; + + @HopMetadataProperty(injectionKeyDescription = "HTTPPOST.Injection.ArgumentFieldParameter") + private String parameter; + + @HopMetadataProperty(injectionKeyDescription = "HTTPPOST.Injection.ArgumentFieldHeader") + private boolean header; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getParameter() { + return parameter; + } + + public void setParameter(String parameter) { + this.parameter = parameter; + } + + public boolean isHeader() { + return header; + } + + public void setHeader(boolean header) { + this.header = header; + } + + public GrafanaPostArgumentField(String name, String parameter, boolean header) { + this.name = name; + this.parameter = parameter; + this.header = header; + } + + public GrafanaPostArgumentField(GrafanaPostArgumentField httpPostArgumentField) { + this.name = httpPostArgumentField.name; + this.parameter = httpPostArgumentField.parameter; + this.header = httpPostArgumentField.header; + } + + public GrafanaPostArgumentField() {} +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPostData.java b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPostData.java new file mode 100644 index 00000000000..106ae9f0d28 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPostData.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.plc4x.hop.utils.transforms.grafana; + +import org.apache.hop.core.row.IRowMeta; +import org.apache.hop.pipeline.transform.BaseTransformData; +import org.apache.hop.pipeline.transform.ITransformData; +import org.apache.http.NameValuePair; + +public class GrafanaPostData extends BaseTransformData implements ITransformData { + public IRowMeta outputRowMeta; + public IRowMeta inputRowMeta; + public String realEncoding; + public int[] header_parameters_nrs; + public int[] body_parameters_nrs; + public int[] query_parameters_nrs; + public int indexOfUrlField; + public String realUrl; + public NameValuePair[] headerParameters; + public NameValuePair[] bodyParameters; + public NameValuePair[] queryParameters; + public boolean useHeaderParameters; + public boolean contentTypeHeaderOverwrite; + public boolean useBodyParameters; + public boolean useQueryParameters; + public int indexOfRequestEntity; + + public String realProxyHost; + public int realProxyPort; + public String realHttpLogin; + public String realHttpPassword; + + public int realSocketTimeout; + public int realConnectionTimeout; + public int realcloseIdleConnectionsTime; + + public GrafanaPostData() { + super(); + indexOfUrlField = -1; + useHeaderParameters = false; + contentTypeHeaderOverwrite = false; + useBodyParameters = false; + useQueryParameters = false; + indexOfRequestEntity = -1; + realEncoding = null; + realProxyHost = null; + realProxyPort = 8080; + realHttpLogin = null; + realHttpPassword = null; + } +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPostDialog.java b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPostDialog.java new file mode 100644 index 00000000000..6c8cd720457 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPostDialog.java @@ -0,0 +1,1098 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.plc4x.hop.utils.transforms.grafana; + +import org.apache.hop.core.Const; +import org.apache.hop.core.Props; +import org.apache.hop.core.exception.HopException; +import org.apache.hop.core.row.IRowMeta; +import org.apache.hop.core.util.Utils; +import org.apache.hop.core.variables.IVariables; +import org.apache.hop.i18n.BaseMessages; +import org.apache.hop.pipeline.PipelineMeta; +import org.apache.hop.pipeline.transform.BaseTransformMeta; +import org.apache.hop.pipeline.transform.ITransformDialog; +import org.apache.hop.pipeline.transform.TransformMeta; +import org.apache.hop.ui.core.dialog.BaseDialog; +import org.apache.hop.ui.core.dialog.ErrorDialog; +import org.apache.hop.ui.core.widget.*; +import org.apache.hop.ui.pipeline.transform.BaseTransformDialog; +import org.apache.hop.ui.pipeline.transform.ComponentSelectionListener; +import org.apache.hop.ui.pipeline.transform.ITableItemInsertListener; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CTabFolder; +import org.eclipse.swt.custom.CTabItem; +import org.eclipse.swt.events.*; +import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.*; + +import java.nio.charset.Charset; +import java.util.List; +import java.util.*; + +public class GrafanaPostDialog extends BaseTransformDialog implements ITransformDialog { + private static final Class PKG = GrafanaPostMeta.class; // For Translator + + private static final String[] YES_NO_COMBO = + new String[] { + BaseMessages.getString(PKG, "System.Combo.No"), + BaseMessages.getString(PKG, "System.Combo.Yes") + }; + private static final String YES = BaseMessages.getString(PKG, "System.Combo.Yes"); + private static final String NO = BaseMessages.getString(PKG, "System.Combo.No"); + + private Label wlUrl; + private TextVar wUrl; + + private TextVar wResult; + + private TextVar wResultCode; + + private TextVar wResponseTime; + private TextVar wResponseHeader; + + private TableView wFields; + + private TableView wQuery; + + private Button wUrlInField; + + private Label wlUrlField; + private ComboVar wUrlField; + + private ComboVar wRequestEntity; + + private TextVar wHttpLogin; + + private TextVar wHttpPassword; + + private TextVar wProxyHost; + + private TextVar wProxyPort; + + private final GrafanaPostMeta input; + + private final Map inputFields; + + private ColumnInfo[] colinf; + private ColumnInfo[] colinfquery; + + private String[] fieldNames; + + private boolean gotPreviousFields = false; + + private ComboVar wEncoding; + + private Button wPostAFile; + + private boolean gotEncodings = false; + + private TextVar wConnectionTimeOut; + + private TextVar wSocketTimeOut; + + private TextVar wCloseIdleConnectionsTime; + + public GrafanaPostDialog( + Shell parent, IVariables variables, Object in, PipelineMeta pipelineMeta, String sname) { + super(parent, variables, (BaseTransformMeta) in, pipelineMeta, sname); + input = (GrafanaPostMeta) in; + inputFields = new HashMap<>(); + } + + @Override + public String open() { + Shell parent = getParent(); + + shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN); + props.setLook(shell); + setShellImage(shell, input); + + ModifyListener lsMod = e -> input.setChanged(); + + changed = input.hasChanged(); + + FormLayout formLayout = new FormLayout(); + formLayout.marginWidth = Const.FORM_MARGIN; + formLayout.marginHeight = Const.FORM_MARGIN; + + shell.setLayout(formLayout); + shell.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.Shell.Title")); + + int middle = props.getMiddlePct(); + int margin = props.getMargin(); + + // THE BUTTONS + wOk = new Button(shell, SWT.PUSH); + wOk.setText(BaseMessages.getString(PKG, "System.Button.OK")); + wOk.addListener(SWT.Selection, e -> ok()); + wCancel = new Button(shell, SWT.PUSH); + wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); + wCancel.addListener(SWT.Selection, e -> cancel()); + setButtonPositions(new Button[] {wOk, wCancel}, margin, null); + + // TransformName line + wlTransformName = new Label(shell, SWT.RIGHT); + wlTransformName.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.TransformName.Label")); + props.setLook(wlTransformName); + fdlTransformName = new FormData(); + fdlTransformName.left = new FormAttachment(0, 0); + fdlTransformName.right = new FormAttachment(middle, -margin); + fdlTransformName.top = new FormAttachment(0, margin); + wlTransformName.setLayoutData(fdlTransformName); + wTransformName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + wTransformName.setText(transformName); + props.setLook(wTransformName); + wTransformName.addModifyListener(lsMod); + fdTransformName = new FormData(); + fdTransformName.left = new FormAttachment(middle, 0); + fdTransformName.top = new FormAttachment(0, margin); + fdTransformName.right = new FormAttachment(100, 0); + wTransformName.setLayoutData(fdTransformName); + + CTabFolder wTabFolder = new CTabFolder(shell, SWT.BORDER); + props.setLook(wTabFolder, Props.WIDGET_STYLE_TAB); + + // //////////////////////// + // START OF GENERAL TAB /// + // //////////////////////// + CTabItem wGeneralTab = new CTabItem(wTabFolder, SWT.NONE); + wGeneralTab.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.GeneralTab.Title")); + + Composite wGeneralComp = new Composite(wTabFolder, SWT.NONE); + props.setLook(wGeneralComp); + + FormLayout fileLayout = new FormLayout(); + fileLayout.marginWidth = 3; + fileLayout.marginHeight = 3; + wGeneralComp.setLayout(fileLayout); + + // //////////////////////// + // START Settings GROUP + + Group gSettings = new Group(wGeneralComp, SWT.SHADOW_ETCHED_IN); + gSettings.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.SettingsGroup.Label")); + FormLayout settingsLayout = new FormLayout(); + settingsLayout.marginWidth = 3; + settingsLayout.marginHeight = 3; + gSettings.setLayout(settingsLayout); + props.setLook(gSettings); + + wlUrl = new Label(gSettings, SWT.RIGHT); + wlUrl.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.URL.Label")); + props.setLook(wlUrl); + FormData fdlUrl = new FormData(); + fdlUrl.left = new FormAttachment(0, 0); + fdlUrl.right = new FormAttachment(middle, -margin); + fdlUrl.top = new FormAttachment(wTransformName, margin); + wlUrl.setLayoutData(fdlUrl); + + wUrl = new TextVar(variables, gSettings, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wUrl); + wUrl.addModifyListener(lsMod); + FormData fdUrl = new FormData(); + fdUrl.left = new FormAttachment(middle, 0); + fdUrl.top = new FormAttachment(wTransformName, margin); + fdUrl.right = new FormAttachment(100, 0); + wUrl.setLayoutData(fdUrl); + + // UrlInField line + Label wlUrlInField = new Label(gSettings, SWT.RIGHT); + wlUrlInField.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.UrlInField.Label")); + props.setLook(wlUrlInField); + FormData fdlUrlInField = new FormData(); + fdlUrlInField.left = new FormAttachment(0, 0); + fdlUrlInField.top = new FormAttachment(wUrl, margin); + fdlUrlInField.right = new FormAttachment(middle, -margin); + wlUrlInField.setLayoutData(fdlUrlInField); + wUrlInField = new Button(gSettings, SWT.CHECK); + props.setLook(wUrlInField); + FormData fdUrlInField = new FormData(); + fdUrlInField.left = new FormAttachment(middle, 0); + fdUrlInField.top = new FormAttachment(wlUrlInField, 0, SWT.CENTER); + fdUrlInField.right = new FormAttachment(100, 0); + wUrlInField.setLayoutData(fdUrlInField); + wUrlInField.addSelectionListener( + new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + input.setChanged(); + activeUrlInfield(); + } + }); + + // UrlField Line + wlUrlField = new Label(gSettings, SWT.RIGHT); + wlUrlField.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.UrlField.Label")); + props.setLook(wlUrlField); + FormData fdlUrlField = new FormData(); + fdlUrlField.left = new FormAttachment(0, 0); + fdlUrlField.right = new FormAttachment(middle, -margin); + fdlUrlField.top = new FormAttachment(wUrlInField, margin); + wlUrlField.setLayoutData(fdlUrlField); + + wUrlField = new ComboVar(variables, gSettings, SWT.BORDER | SWT.READ_ONLY); + wUrlField.setEditable(true); + props.setLook(wUrlField); + wUrlField.addModifyListener(lsMod); + FormData fdUrlField = new FormData(); + fdUrlField.left = new FormAttachment(middle, 0); + fdUrlField.top = new FormAttachment(wUrlInField, margin); + fdUrlField.right = new FormAttachment(100, -margin); + wUrlField.setLayoutData(fdUrlField); + wUrlField.addFocusListener( + new FocusListener() { + @Override + public void focusLost(FocusEvent e) { + // Disable focuslost event + } + + @Override + public void focusGained(FocusEvent e) { + Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT); + shell.setCursor(busy); + setStreamFields(); + shell.setCursor(null); + busy.dispose(); + } + }); + + Label wlEncoding = new Label(gSettings, SWT.RIGHT); + wlEncoding.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.Encoding.Label")); + props.setLook(wlEncoding); + FormData fdlEncoding = new FormData(); + fdlEncoding.left = new FormAttachment(0, 0); + fdlEncoding.top = new FormAttachment(wUrlField, margin); + fdlEncoding.right = new FormAttachment(middle, -margin); + wlEncoding.setLayoutData(fdlEncoding); + wEncoding = new ComboVar(variables, gSettings, SWT.BORDER | SWT.READ_ONLY); + wEncoding.setEditable(true); + props.setLook(wEncoding); + wEncoding.addModifyListener(lsMod); + FormData fdEncoding = new FormData(); + fdEncoding.left = new FormAttachment(middle, 0); + fdEncoding.top = new FormAttachment(wUrlField, margin); + fdEncoding.right = new FormAttachment(100, -margin); + wEncoding.setLayoutData(fdEncoding); + wEncoding.addFocusListener( + new FocusListener() { + @Override + public void focusLost(FocusEvent e) { + // Disable focuslost event + } + + @Override + public void focusGained(FocusEvent e) { + Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT); + shell.setCursor(busy); + setEncodings(); + shell.setCursor(null); + busy.dispose(); + } + }); + + // requestEntity Line + Label wlRequestEntity = new Label(gSettings, SWT.RIGHT); + wlRequestEntity.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.requestEntity.Label")); + props.setLook(wlRequestEntity); + FormData fdlRequestEntity = new FormData(); + fdlRequestEntity.left = new FormAttachment(0, 0); + fdlRequestEntity.right = new FormAttachment(middle, -margin); + fdlRequestEntity.top = new FormAttachment(wEncoding, margin); + wlRequestEntity.setLayoutData(fdlRequestEntity); + + wRequestEntity = new ComboVar(variables, gSettings, SWT.BORDER | SWT.READ_ONLY); + wRequestEntity.setEditable(true); + props.setLook(wRequestEntity); + wRequestEntity.addModifyListener(lsMod); + FormData fdRequestEntity = new FormData(); + fdRequestEntity.left = new FormAttachment(middle, 0); + fdRequestEntity.top = new FormAttachment(wEncoding, margin); + fdRequestEntity.right = new FormAttachment(100, -margin); + wRequestEntity.setLayoutData(fdRequestEntity); + wRequestEntity.addFocusListener( + new FocusListener() { + @Override + public void focusLost(FocusEvent e) { + // Disable focuslost event + } + + @Override + public void focusGained(FocusEvent e) { + Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT); + shell.setCursor(busy); + setStreamFields(); + shell.setCursor(null); + busy.dispose(); + } + }); + + // Post file? + Label wlPostAFile = new Label(gSettings, SWT.RIGHT); + wlPostAFile.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.postAFile.Label")); + props.setLook(wlPostAFile); + FormData fdlPostAFile = new FormData(); + fdlPostAFile.left = new FormAttachment(0, 0); + fdlPostAFile.right = new FormAttachment(middle, -margin); + fdlPostAFile.top = new FormAttachment(wRequestEntity, margin); + wlPostAFile.setLayoutData(fdlPostAFile); + wPostAFile = new Button(gSettings, SWT.CHECK); + wPostAFile.setToolTipText(BaseMessages.getString(PKG, "HTTPPOSTDialog.postAFile.Tooltip")); + props.setLook(wPostAFile); + FormData fdPostAFile = new FormData(); + fdPostAFile.left = new FormAttachment(middle, 0); + fdPostAFile.top = new FormAttachment(wlPostAFile, 0, SWT.CENTER); + fdPostAFile.right = new FormAttachment(100, 0); + wPostAFile.setLayoutData(fdPostAFile); + wPostAFile.addSelectionListener(new ComponentSelectionListener(input)); + + Label wlConnectionTimeOut = new Label(gSettings, SWT.RIGHT); + wlConnectionTimeOut.setText( + BaseMessages.getString(PKG, "HTTPPOSTDialog.ConnectionTimeOut.Label")); + props.setLook(wlConnectionTimeOut); + FormData fdlConnectionTimeOut = new FormData(); + fdlConnectionTimeOut.top = new FormAttachment(wPostAFile, margin); + fdlConnectionTimeOut.left = new FormAttachment(0, 0); + fdlConnectionTimeOut.right = new FormAttachment(middle, -margin); + wlConnectionTimeOut.setLayoutData(fdlConnectionTimeOut); + wConnectionTimeOut = new TextVar(variables, gSettings, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + wConnectionTimeOut.addModifyListener(lsMod); + wConnectionTimeOut.setToolTipText( + BaseMessages.getString(PKG, "HTTPPOSTDialog.ConnectionTimeOut.Tooltip")); + props.setLook(wConnectionTimeOut); + FormData fdConnectionTimeOut = new FormData(); + fdConnectionTimeOut.top = new FormAttachment(wPostAFile, margin); + fdConnectionTimeOut.left = new FormAttachment(middle, 0); + fdConnectionTimeOut.right = new FormAttachment(100, 0); + wConnectionTimeOut.setLayoutData(fdConnectionTimeOut); + + Label wlSocketTimeOut = new Label(gSettings, SWT.RIGHT); + wlSocketTimeOut.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.SocketTimeOut.Label")); + props.setLook(wlSocketTimeOut); + FormData fdlSocketTimeOut = new FormData(); + fdlSocketTimeOut.top = new FormAttachment(wConnectionTimeOut, margin); + fdlSocketTimeOut.left = new FormAttachment(0, 0); + fdlSocketTimeOut.right = new FormAttachment(middle, -margin); + wlSocketTimeOut.setLayoutData(fdlSocketTimeOut); + wSocketTimeOut = new TextVar(variables, gSettings, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + wSocketTimeOut.addModifyListener(lsMod); + wSocketTimeOut.setToolTipText( + BaseMessages.getString(PKG, "HTTPPOSTDialog.SocketTimeOut.Tooltip")); + props.setLook(wSocketTimeOut); + FormData fdSocketTimeOut = new FormData(); + fdSocketTimeOut.top = new FormAttachment(wConnectionTimeOut, margin); + fdSocketTimeOut.left = new FormAttachment(middle, 0); + fdSocketTimeOut.right = new FormAttachment(100, 0); + wSocketTimeOut.setLayoutData(fdSocketTimeOut); + + Label wlCloseIdleConnectionsTime = new Label(gSettings, SWT.RIGHT); + wlCloseIdleConnectionsTime.setText( + BaseMessages.getString(PKG, "HTTPPOSTDialog.CloseIdleConnectionsTime.Label")); + props.setLook(wlCloseIdleConnectionsTime); + FormData fdlCloseIdleConnectionsTime = new FormData(); + fdlCloseIdleConnectionsTime.top = new FormAttachment(wSocketTimeOut, margin); + fdlCloseIdleConnectionsTime.left = new FormAttachment(0, 0); + fdlCloseIdleConnectionsTime.right = new FormAttachment(middle, -margin); + wlCloseIdleConnectionsTime.setLayoutData(fdlCloseIdleConnectionsTime); + wCloseIdleConnectionsTime = + new TextVar(variables, gSettings, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + wCloseIdleConnectionsTime.addModifyListener(lsMod); + wCloseIdleConnectionsTime.setToolTipText( + BaseMessages.getString(PKG, "HTTPPOSTDialog.CloseIdleConnectionsTime.Tooltip")); + props.setLook(wCloseIdleConnectionsTime); + FormData fdCloseIdleConnectionsTime = new FormData(); + fdCloseIdleConnectionsTime.top = new FormAttachment(wSocketTimeOut, margin); + fdCloseIdleConnectionsTime.left = new FormAttachment(middle, 0); + fdCloseIdleConnectionsTime.right = new FormAttachment(100, 0); + wCloseIdleConnectionsTime.setLayoutData(fdCloseIdleConnectionsTime); + + FormData fdSettings = new FormData(); + fdSettings.left = new FormAttachment(0, 0); + fdSettings.right = new FormAttachment(100, 0); + fdSettings.top = new FormAttachment(wTransformName, margin); + gSettings.setLayoutData(fdSettings); + + // END Output Settings GROUP + // //////////////////////// + + // //////////////////////// + // START Output Fields GROUP + + Group gOutputFields = new Group(wGeneralComp, SWT.SHADOW_ETCHED_IN); + gOutputFields.setText(BaseMessages.getString(PKG, "HTTPDialog.OutputFieldsGroup.Label")); + FormLayout outputFieldsLayout = new FormLayout(); + outputFieldsLayout.marginWidth = 3; + outputFieldsLayout.marginHeight = 3; + gOutputFields.setLayout(outputFieldsLayout); + props.setLook(gOutputFields); + + // Result line... + Label wlResult = new Label(gOutputFields, SWT.RIGHT); + wlResult.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.Result.Label")); + props.setLook(wlResult); + FormData fdlResult = new FormData(); + fdlResult.left = new FormAttachment(0, 0); + fdlResult.right = new FormAttachment(middle, -margin); + fdlResult.top = new FormAttachment(wPostAFile, margin); + wlResult.setLayoutData(fdlResult); + wResult = new TextVar(variables, gOutputFields, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wResult); + wResult.addModifyListener(lsMod); + FormData fdResult = new FormData(); + fdResult.left = new FormAttachment(middle, 0); + fdResult.top = new FormAttachment(wPostAFile, margin); + fdResult.right = new FormAttachment(100, -margin); + wResult.setLayoutData(fdResult); + + // Resultcode line... + Label wlResultCode = new Label(gOutputFields, SWT.RIGHT); + wlResultCode.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.ResultCode.Label")); + props.setLook(wlResultCode); + FormData fdlResultCode = new FormData(); + fdlResultCode.left = new FormAttachment(0, 0); + fdlResultCode.right = new FormAttachment(middle, -margin); + fdlResultCode.top = new FormAttachment(wResult, margin); + wlResultCode.setLayoutData(fdlResultCode); + wResultCode = new TextVar(variables, gOutputFields, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wResultCode); + wResultCode.addModifyListener(lsMod); + FormData fdResultCode = new FormData(); + fdResultCode.left = new FormAttachment(middle, 0); + fdResultCode.top = new FormAttachment(wResult, margin); + fdResultCode.right = new FormAttachment(100, -margin); + wResultCode.setLayoutData(fdResultCode); + + // Response time line... + Label wlResponseTime = new Label(gOutputFields, SWT.RIGHT); + wlResponseTime.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.ResponseTime.Label")); + props.setLook(wlResponseTime); + FormData fdlResponseTime = new FormData(); + fdlResponseTime.left = new FormAttachment(0, 0); + fdlResponseTime.right = new FormAttachment(middle, -margin); + fdlResponseTime.top = new FormAttachment(wResultCode, margin); + wlResponseTime.setLayoutData(fdlResponseTime); + wResponseTime = new TextVar(variables, gOutputFields, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wResponseTime); + wResponseTime.addModifyListener(lsMod); + FormData fdResponseTime = new FormData(); + fdResponseTime.left = new FormAttachment(middle, 0); + fdResponseTime.top = new FormAttachment(wResultCode, margin); + fdResponseTime.right = new FormAttachment(100, 0); + wResponseTime.setLayoutData(fdResponseTime); + // Response header line... + Label wlResponseHeader = new Label(gOutputFields, SWT.RIGHT); + wlResponseHeader.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.ResponseHeader.Label")); + props.setLook(wlResponseHeader); + FormData fdlResponseHeader = new FormData(); + fdlResponseHeader.left = new FormAttachment(0, 0); + fdlResponseHeader.right = new FormAttachment(middle, -margin); + fdlResponseHeader.top = new FormAttachment(wResponseTime, margin); + wlResponseHeader.setLayoutData(fdlResponseHeader); + wResponseHeader = new TextVar(variables, gOutputFields, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wResponseHeader); + wResponseHeader.addModifyListener(lsMod); + FormData fdResponseHeader = new FormData(); + fdResponseHeader.left = new FormAttachment(middle, 0); + fdResponseHeader.top = new FormAttachment(wResponseTime, margin); + fdResponseHeader.right = new FormAttachment(100, 0); + wResponseHeader.setLayoutData(fdResponseHeader); + + FormData fdOutputFields = new FormData(); + fdOutputFields.left = new FormAttachment(0, 0); + fdOutputFields.right = new FormAttachment(100, 0); + fdOutputFields.top = new FormAttachment(gSettings, margin); + gOutputFields.setLayoutData(fdOutputFields); + + // END Output Fields GROUP + // //////////////////////// + + // //////////////////////// + // START HTTP AUTH GROUP + + Group gHttpAuth = new Group(wGeneralComp, SWT.SHADOW_ETCHED_IN); + gHttpAuth.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.HttpAuthGroup.Label")); + FormLayout httpAuthLayout = new FormLayout(); + httpAuthLayout.marginWidth = 3; + httpAuthLayout.marginHeight = 3; + gHttpAuth.setLayout(httpAuthLayout); + props.setLook(gHttpAuth); + + // HTTP Login + Label wlHttpLogin = new Label(gHttpAuth, SWT.RIGHT); + wlHttpLogin.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.HttpLogin.Label")); + props.setLook(wlHttpLogin); + FormData fdlHttpLogin = new FormData(); + fdlHttpLogin.top = new FormAttachment(0, margin); + fdlHttpLogin.left = new FormAttachment(0, 0); + fdlHttpLogin.right = new FormAttachment(middle, -margin); + wlHttpLogin.setLayoutData(fdlHttpLogin); + wHttpLogin = new TextVar(variables, gHttpAuth, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + wHttpLogin.addModifyListener(lsMod); + wHttpLogin.setToolTipText(BaseMessages.getString(PKG, "HTTPPOSTDialog.HttpLogin.Tooltip")); + props.setLook(wHttpLogin); + FormData fdHttpLogin = new FormData(); + fdHttpLogin.top = new FormAttachment(0, margin); + fdHttpLogin.left = new FormAttachment(middle, 0); + fdHttpLogin.right = new FormAttachment(100, 0); + wHttpLogin.setLayoutData(fdHttpLogin); + + // HTTP Password + Label wlHttpPassword = new Label(gHttpAuth, SWT.RIGHT); + wlHttpPassword.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.HttpPassword.Label")); + props.setLook(wlHttpPassword); + FormData fdlHttpPassword = new FormData(); + fdlHttpPassword.top = new FormAttachment(wHttpLogin, margin); + fdlHttpPassword.left = new FormAttachment(0, 0); + fdlHttpPassword.right = new FormAttachment(middle, -margin); + wlHttpPassword.setLayoutData(fdlHttpPassword); + wHttpPassword = new PasswordTextVar(variables, gHttpAuth, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + wHttpPassword.addModifyListener(lsMod); + wHttpPassword.setToolTipText( + BaseMessages.getString(PKG, "HTTPPOSTDialog.HttpPassword.Tooltip")); + props.setLook(wHttpPassword); + FormData fdHttpPassword = new FormData(); + fdHttpPassword.top = new FormAttachment(wHttpLogin, margin); + fdHttpPassword.left = new FormAttachment(middle, 0); + fdHttpPassword.right = new FormAttachment(100, 0); + wHttpPassword.setLayoutData(fdHttpPassword); + + FormData fdHttpAuth = new FormData(); + fdHttpAuth.left = new FormAttachment(0, 0); + fdHttpAuth.right = new FormAttachment(100, 0); + fdHttpAuth.top = new FormAttachment(gOutputFields, margin); + gHttpAuth.setLayoutData(fdHttpAuth); + + // END HTTP AUTH GROUP + // //////////////////////// + + // //////////////////////// + // START PROXY GROUP + + Group gProxy = new Group(wGeneralComp, SWT.SHADOW_ETCHED_IN); + gProxy.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.ProxyGroup.Label")); + FormLayout proxyLayout = new FormLayout(); + proxyLayout.marginWidth = 3; + proxyLayout.marginHeight = 3; + gProxy.setLayout(proxyLayout); + props.setLook(gProxy); + + // HTTP Login + Label wlProxyHost = new Label(gProxy, SWT.RIGHT); + wlProxyHost.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.ProxyHost.Label")); + props.setLook(wlProxyHost); + FormData fdlProxyHost = new FormData(); + fdlProxyHost.top = new FormAttachment(0, margin); + fdlProxyHost.left = new FormAttachment(0, 0); + fdlProxyHost.right = new FormAttachment(middle, -margin); + wlProxyHost.setLayoutData(fdlProxyHost); + wProxyHost = new TextVar(variables, gProxy, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + wProxyHost.addModifyListener(lsMod); + wProxyHost.setToolTipText(BaseMessages.getString(PKG, "HTTPPOSTDialog.ProxyHost.Tooltip")); + props.setLook(wProxyHost); + FormData fdProxyHost = new FormData(); + fdProxyHost.top = new FormAttachment(0, margin); + fdProxyHost.left = new FormAttachment(middle, 0); + fdProxyHost.right = new FormAttachment(100, 0); + wProxyHost.setLayoutData(fdProxyHost); + + // HTTP Password + Label wlProxyPort = new Label(gProxy, SWT.RIGHT); + wlProxyPort.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.ProxyPort.Label")); + props.setLook(wlProxyPort); + FormData fdlProxyPort = new FormData(); + fdlProxyPort.top = new FormAttachment(wProxyHost, margin); + fdlProxyPort.left = new FormAttachment(0, 0); + fdlProxyPort.right = new FormAttachment(middle, -margin); + wlProxyPort.setLayoutData(fdlProxyPort); + wProxyPort = new TextVar(variables, gProxy, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + wProxyPort.addModifyListener(lsMod); + wProxyPort.setToolTipText(BaseMessages.getString(PKG, "HTTPPOSTDialog.ProxyPort.Tooltip")); + props.setLook(wProxyPort); + FormData fdProxyPort = new FormData(); + fdProxyPort.top = new FormAttachment(wProxyHost, margin); + fdProxyPort.left = new FormAttachment(middle, 0); + fdProxyPort.right = new FormAttachment(100, 0); + wProxyPort.setLayoutData(fdProxyPort); + + FormData fdProxy = new FormData(); + fdProxy.left = new FormAttachment(0, 0); + fdProxy.right = new FormAttachment(100, 0); + fdProxy.top = new FormAttachment(gHttpAuth, margin); + gProxy.setLayoutData(fdProxy); + + // END HTTP AUTH GROUP + // //////////////////////// + + FormData fdGeneralComp = new FormData(); + fdGeneralComp.left = new FormAttachment(0, 0); + fdGeneralComp.top = new FormAttachment(wTransformName, margin); + fdGeneralComp.right = new FormAttachment(100, 0); + fdGeneralComp.bottom = new FormAttachment(100, 0); + wGeneralComp.setLayoutData(fdGeneralComp); + + wGeneralComp.layout(); + wGeneralTab.setControl(wGeneralComp); + + // /////////////////////////////////////////////////////////// + // / END OF GENERAL TAB + // /////////////////////////////////////////////////////////// + + // Additional tab... + // + CTabItem wAdditionalTab = new CTabItem(wTabFolder, SWT.NONE); + wAdditionalTab.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.FieldsTab.Title")); + + FormLayout addLayout = new FormLayout(); + addLayout.marginWidth = Const.FORM_MARGIN; + addLayout.marginHeight = Const.FORM_MARGIN; + + Composite wAdditionalComp = new Composite(wTabFolder, SWT.NONE); + wAdditionalComp.setLayout(addLayout); + props.setLook(wAdditionalComp); + + Label wlFields = new Label(wAdditionalComp, SWT.NONE); + wlFields.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.Parameters.Label")); + props.setLook(wlFields); + FormData fdlFields = new FormData(); + fdlFields.left = new FormAttachment(0, 0); + fdlFields.top = new FormAttachment(gProxy, margin); + wlFields.setLayoutData(fdlFields); + + int fieldsRows = 0; + if (input.getLookupfield().get(0).getArgumentField() != null) { + fieldsRows = input.getLookupfield().get(0).getArgumentField().size(); + } + + colinf = + new ColumnInfo[] { + new ColumnInfo( + BaseMessages.getString(PKG, "HTTPPOSTDialog.ColumnInfo.Name"), + ColumnInfo.COLUMN_TYPE_CCOMBO, + new String[] {""}, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "HTTPPOSTDialog.ColumnInfo.Parameter"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "HTTPPOSTDialog.ColumnInfo.Header"), + ColumnInfo.COLUMN_TYPE_CCOMBO, + YES_NO_COMBO), + }; + colinf[1].setUsingVariables(true); + wFields = + new TableView( + variables, + wAdditionalComp, + SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, + colinf, + fieldsRows, + lsMod, + props); + + Button wGetBodyParam = new Button(wAdditionalComp, SWT.PUSH); + wGetBodyParam.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.GetFields.Button")); + FormData fdGetBodyParam = new FormData(); + fdGetBodyParam.top = new FormAttachment(wlFields, margin); + fdGetBodyParam.right = new FormAttachment(100, 0); + wGetBodyParam.setLayoutData(fdGetBodyParam); + + FormData fdFields = new FormData(); + fdFields.left = new FormAttachment(0, 0); + fdFields.top = new FormAttachment(wlFields, margin); + fdFields.right = new FormAttachment(wGetBodyParam, -margin); + fdFields.bottom = new FormAttachment(wlFields, 200); + wFields.setLayoutData(fdFields); + + Label wlQuery = new Label(wAdditionalComp, SWT.NONE); + wlQuery.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.QueryParameters.Label")); + props.setLook(wlQuery); + FormData fdlQuery = new FormData(); + fdlQuery.left = new FormAttachment(0, 0); + fdlQuery.top = new FormAttachment(wFields, margin); + wlQuery.setLayoutData(fdlQuery); + + int queryRows = 0; + if (input.getLookupfield().get(0).getQueryField() != null) { + queryRows = input.getLookupfield().get(0).getQueryField().size(); + } + + colinfquery = + new ColumnInfo[] { + new ColumnInfo( + BaseMessages.getString(PKG, "HTTPPOSTDialog.ColumnInfo.QueryName"), + ColumnInfo.COLUMN_TYPE_CCOMBO, + new String[] {""}, + false), + new ColumnInfo( + BaseMessages.getString(PKG, "HTTPPOSTDialog.ColumnInfo.QueryParameter"), + ColumnInfo.COLUMN_TYPE_TEXT, + false), + }; + colinfquery[1].setUsingVariables(true); + wQuery = + new TableView( + variables, + wAdditionalComp, + SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, + colinfquery, + queryRows, + lsMod, + props); + + wGet = new Button(wAdditionalComp, SWT.PUSH); + wGet.setText(BaseMessages.getString(PKG, "HTTPPOSTDialog.GetFields.Button")); + fdGet = new FormData(); + fdGet.top = new FormAttachment(wlQuery, margin); + fdGet.right = new FormAttachment(100, 0); + wGet.setLayoutData(fdGet); + + FormData fdQuery = new FormData(); + fdQuery.left = new FormAttachment(0, 0); + fdQuery.top = new FormAttachment(wlQuery, margin); + fdQuery.right = new FormAttachment(wGet, -margin); + fdQuery.bottom = new FormAttachment(100, -margin); + wQuery.setLayoutData(fdQuery); + + // + // Search the fields in the background + // + + final Runnable runnable = + () -> { + TransformMeta transformMeta = pipelineMeta.findTransform(transformName); + if (transformMeta != null) { + try { + IRowMeta row = pipelineMeta.getPrevTransformFields(variables, transformMeta); + + // Remember these fields... + for (int i = 0; i < row.size(); i++) { + inputFields.put(row.getValueMeta(i).getName(), i); + } + + setComboBoxes(); + } catch (HopException e) { + logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message")); + } + } + }; + new Thread(runnable).start(); + FormData fdAdditionalComp = new FormData(); + fdAdditionalComp.left = new FormAttachment(0, 0); + fdAdditionalComp.top = new FormAttachment(wTransformName, margin); + fdAdditionalComp.right = new FormAttachment(100, 0); + fdAdditionalComp.bottom = new FormAttachment(100, 0); + wAdditionalComp.setLayoutData(fdAdditionalComp); + + wAdditionalComp.layout(); + wAdditionalTab.setControl(wAdditionalComp); + // ////// END of Additional Tab + + FormData fdTabFolder = new FormData(); + fdTabFolder.left = new FormAttachment(0, 0); + fdTabFolder.top = new FormAttachment(wTransformName, margin); + fdTabFolder.right = new FormAttachment(100, 0); + fdTabFolder.bottom = new FormAttachment(wOk, -2 * margin); + wTabFolder.setLayoutData(fdTabFolder); + + // Add listeners + wGet.addListener(SWT.Selection, e -> getQueryFields()); + wGetBodyParam.addListener(SWT.Selection, e -> get()); + + lsResize = + event -> { + Point size = shell.getSize(); + wFields.setSize(size.x - 10, size.y - 50); + wFields.table.setSize(size.x - 10, size.y - 50); + wFields.redraw(); + }; + shell.addListener(SWT.Resize, lsResize); + + wTabFolder.setSelection(0); + getData(); + activeUrlInfield(); + input.setChanged(changed); + + BaseDialog.defaultShellHandling(shell, c -> ok(), c -> cancel()); + + return transformName; + } + + protected void setComboBoxes() { + // Something was changed in the row. + // + final Map fields = new HashMap<>(); + + // Add the currentMeta fields... + fields.putAll(inputFields); + + Set keySet = fields.keySet(); + List entries = new ArrayList<>(keySet); + + fieldNames = entries.toArray(new String[entries.size()]); + + Const.sortStrings(fieldNames); + colinf[0].setComboValues(fieldNames); + colinfquery[0].setComboValues(fieldNames); + } + + private void setStreamFields() { + if (!gotPreviousFields) { + String urlfield = wUrlField.getText(); + wUrlField.removeAll(); + wUrlField.setItems(fieldNames); + if (urlfield != null) { + wUrlField.setText(urlfield); + } + + String request = wRequestEntity.getText(); + wRequestEntity.removeAll(); + wRequestEntity.setItems(fieldNames); + if (request != null) { + wRequestEntity.setText(request); + } + + gotPreviousFields = true; + } + } + + private void setEncodings() { + // Encoding of the text file: + if (!gotEncodings) { + gotEncodings = true; + + wEncoding.removeAll(); + List values = new ArrayList<>(Charset.availableCharsets().values()); + for (Charset charSet : values) { + wEncoding.add(charSet.displayName()); + } + + // Now select the default! + String defEncoding = Const.getEnvironmentVariable("file.encoding", "UTF-8"); + int idx = Const.indexOfString(defEncoding, wEncoding.getItems()); + if (idx >= 0) { + wEncoding.select(idx); + } + } + } + + private void activeUrlInfield() { + wlUrlField.setEnabled(wUrlInField.getSelection()); + wUrlField.setEnabled(wUrlInField.getSelection()); + wlUrl.setEnabled(!wUrlInField.getSelection()); + wUrl.setEnabled(!wUrlInField.getSelection()); + } + + /** Copy information from the meta-data input to the dialog fields. */ + public void getData() { + if (log.isDebug()) { + logDebug(BaseMessages.getString(PKG, "HTTPPOSTDialog.Log.GettingKeyInfo")); + } + + if (input.getLookupfield().get(0).getArgumentField() != null) { + for (int i = 0; i < input.getLookupfield().get(0).getArgumentField().size(); i++) { + TableItem item = wFields.table.getItem(i); + if (input.getLookupfield().get(0).getArgumentField().get(i).getName() != null) { + item.setText(1, input.getLookupfield().get(0).getArgumentField().get(i).getName()); + } + if (input.getLookupfield().get(0).getArgumentField().get(i).getParameter() != null) { + item.setText(2, input.getLookupfield().get(0).getArgumentField().get(i).getParameter()); + } + item.setText( + 3, (input.getLookupfield().get(0).getArgumentField().get(i).isHeader()) ? YES : NO); + } + } + if (input.getLookupfield().get(0).getQueryField() != null) { + for (int i = 0; i < input.getLookupfield().get(0).getQueryField().size(); i++) { + TableItem item = wQuery.table.getItem(i); + if (input.getLookupfield().get(0).getQueryField().get(i).getName() != null) { + item.setText(1, input.getLookupfield().get(0).getQueryField().get(i).getName()); + } + if (input.getLookupfield().get(0).getQueryField().get(i).getParameter() != null) { + item.setText(2, input.getLookupfield().get(0).getQueryField().get(i).getParameter()); + } + } + } + if (input.getUrl() != null) { + wUrl.setText(input.getUrl()); + } + wUrlInField.setSelection(input.isUrlInField()); + if (input.getUrlField() != null) { + wUrlField.setText(input.getUrlField()); + } + if (input.getRequestEntity() != null) { + wRequestEntity.setText(input.getRequestEntity()); + } + if (input.getHttpPostResultField().get(0).getName() != null) { + wResult.setText(input.getHttpPostResultField().get(0).getName()); + } + if (input.getHttpPostResultField().get(0).getCode() != null) { + wResultCode.setText(input.getHttpPostResultField().get(0).getCode()); + } + if (input.getHttpPostResultField().get(0).getResponseTimeFieldName() != null) { + wResponseTime.setText(input.getHttpPostResultField().get(0).getResponseTimeFieldName()); + } + if (input.getEncoding() != null) { + wEncoding.setText(input.getEncoding()); + } + wPostAFile.setSelection(input.isPostAFile()); + + if (input.getHttpLogin() != null) { + wHttpLogin.setText(input.getHttpLogin()); + } + if (input.getHttpPassword() != null) { + wHttpPassword.setText(input.getHttpPassword()); + } + if (input.getProxyHost() != null) { + wProxyHost.setText(input.getProxyHost()); + } + if (input.getProxyPort() != null) { + wProxyPort.setText(input.getProxyPort()); + } + if (input.getHttpPostResultField().get(0).getResponseHeaderFieldName() != null) { + wResponseHeader.setText(input.getHttpPostResultField().get(0).getResponseHeaderFieldName()); + } + + wSocketTimeOut.setText(Const.NVL(input.getSocketTimeout(), "")); + wConnectionTimeOut.setText(Const.NVL(input.getConnectionTimeout(), "")); + wCloseIdleConnectionsTime.setText(Const.NVL(input.getCloseIdleConnectionsTime(), "")); + + wFields.setRowNums(); + wFields.optWidth(true); + + wTransformName.selectAll(); + wTransformName.setFocus(); + } + + private void cancel() { + transformName = null; + input.setChanged(changed); + dispose(); + } + + private void ok() { + GrafanaPostLoookupField loookupField = new GrafanaPostLoookupField(); + if (Utils.isEmpty(wTransformName.getText())) { + return; + } + + int nrargs = wFields.nrNonEmpty(); + + if (log.isDebug()) { + logDebug( + BaseMessages.getString(PKG, "HTTPPOSTDialog.Log.FoundArguments", String.valueOf(nrargs))); + } + // CHECKSTYLE:Indentation:OFF + for (int i = 0; i < nrargs; i++) { + TableItem item = wFields.getNonEmpty(i); + GrafanaPostArgumentField argumentField = + new GrafanaPostArgumentField(item.getText(1), item.getText(2), YES.equals(item.getText(3))); + loookupField.getArgumentField().add(argumentField); + } + + int nrqueryparams = wQuery.nrNonEmpty(); + + if (log.isDebug()) { + logDebug( + BaseMessages.getString( + PKG, "HTTPPOSTDialog.Log.FoundQueryParameters", String.valueOf(nrqueryparams))); + } + // CHECKSTYLE:Indentation:OFF + for (int i = 0; i < nrqueryparams; i++) { + TableItem item = wQuery.getNonEmpty(i); + input.getLookupfield().get(0).getQueryField().clear(); + GrafanaPostQuery httpPostQuery = new GrafanaPostQuery(item.getText(1), item.getText(2)); + loookupField.getQueryField().add(httpPostQuery); + } + + List listLookupField = new ArrayList<>(); + listLookupField.add(loookupField); + input.setLookupfield(listLookupField); + + input.setUrl(wUrl.getText()); + input.setUrlField(wUrlField.getText()); + input.setRequestEntity(wRequestEntity.getText()); + input.setUrlInField(wUrlInField.getSelection()); + + GrafanaPostResultField httpPostResultField = + new GrafanaPostResultField( + wResultCode.getText(), + wResult.getText(), + wResponseTime.getText(), + wResponseHeader.getText()); + + List listHttpPostResultField = new ArrayList<>(); + listHttpPostResultField.add(httpPostResultField); + input.setHttpPostResultField(listHttpPostResultField); + + input.setEncoding(wEncoding.getText()); + input.setPostAFile(wPostAFile.getSelection()); + input.setHttpLogin(wHttpLogin.getText()); + input.setHttpPassword(wHttpPassword.getText()); + input.setProxyHost(wProxyHost.getText()); + input.setProxyPort(wProxyPort.getText()); + input.setSocketTimeout(wSocketTimeOut.getText()); + input.setConnectionTimeout(wConnectionTimeOut.getText()); + input.setCloseIdleConnectionsTime(wCloseIdleConnectionsTime.getText()); + + transformName = wTransformName.getText(); // return value + + dispose(); + } + + private void get() { + try { + IRowMeta r = pipelineMeta.getPrevTransformFields(variables, transformName); + if (r != null && !r.isEmpty()) { + ITableItemInsertListener listener = + (tableItem, v) -> { + tableItem.setText(3, NO); // default is "N" + return true; + }; + BaseTransformDialog.getFieldsFromPrevious( + r, wFields, 1, new int[] {1, 2}, null, -1, -1, listener); + } + } catch (HopException ke) { + new ErrorDialog( + shell, + BaseMessages.getString(PKG, "HTTPPOSTDialog.FailedToGetFields.DialogTitle"), + BaseMessages.getString(PKG, "HTTPPOSTDialog.FailedToGetFields.DialogMessage"), + ke); + } + } + + private void getQueryFields() { + try { + IRowMeta r = pipelineMeta.getPrevTransformFields(variables, transformName); + if (r != null && !r.isEmpty()) { + BaseTransformDialog.getFieldsFromPrevious( + r, wQuery, 1, new int[] {1, 2}, new int[] {3}, -1, -1, null); + } + } catch (HopException ke) { + new ErrorDialog( + shell, + BaseMessages.getString(PKG, "HTTPPOSTDialog.FailedToGetFields.DialogTitle"), + BaseMessages.getString(PKG, "HTTPPOSTDialog.FailedToGetFields.DialogMessage"), + ke); + } + } +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPostLoookupField.java b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPostLoookupField.java new file mode 100644 index 00000000000..71036ba13f7 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPostLoookupField.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.plc4x.hop.utils.transforms.grafana; + +import org.apache.hop.metadata.api.HopMetadataProperty; + +import java.util.ArrayList; +import java.util.List; + +public class GrafanaPostLoookupField { + + @HopMetadataProperty( + key = "query", + injectionGroupDescription = "HTTPPOST.Injection.LookupQueryField") + private List queryField = new ArrayList<>(); + + @HopMetadataProperty( + key = "arg", + injectionGroupDescription = "HTTPPOST.Injection.LookupArgumentField") + private List argumentField = new ArrayList<>(); + + public List getQueryField() { + return queryField; + } + + public void setQueryField(List queryField) { + this.queryField = queryField; + } + + public List getArgumentField() { + return argumentField; + } + + public void setArgumentField(List argumentField) { + this.argumentField = argumentField; + } + + public GrafanaPostLoookupField( + List postQuery, List argumentField) { + this.queryField = postQuery; + this.argumentField = argumentField; + } + + public GrafanaPostLoookupField(GrafanaPostLoookupField httpPostLoookupField) { + this.queryField = httpPostLoookupField.queryField; + this.argumentField = httpPostLoookupField.argumentField; + } + + public GrafanaPostLoookupField() {} +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPostMeta.java b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPostMeta.java new file mode 100644 index 00000000000..c01736e6e30 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPostMeta.java @@ -0,0 +1,425 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.plc4x.hop.utils.transforms.grafana; + +import org.apache.hop.core.CheckResult; +import org.apache.hop.core.ICheckResult; +import org.apache.hop.core.annotations.Transform; +import org.apache.hop.core.exception.HopTransformException; +import org.apache.hop.core.row.IRowMeta; +import org.apache.hop.core.row.IValueMeta; +import org.apache.hop.core.row.value.ValueMetaInteger; +import org.apache.hop.core.row.value.ValueMetaString; +import org.apache.hop.core.util.Utils; +import org.apache.hop.core.variables.IVariables; +import org.apache.hop.i18n.BaseMessages; +import org.apache.hop.metadata.api.HopMetadataProperty; +import org.apache.hop.metadata.api.IHopMetadataProvider; +import org.apache.hop.pipeline.Pipeline; +import org.apache.hop.pipeline.PipelineMeta; +import org.apache.hop.pipeline.transform.BaseTransformMeta; +import org.apache.hop.pipeline.transform.ITransformMeta; +import org.apache.hop.pipeline.transform.TransformMeta; + +import java.util.ArrayList; +import java.util.List; + +/* +* This code is taken from the "HttpPost" transform to be adapted for use +* with the Grafana APIs. +* In the future, its integration with the original version should be proposed +* to the working group of Apache Hop +*/ + +@Transform( + id = "grafana-post", + image = "grafana.svg", + name = "i18n::BaseTransform.TypeLongDesc.GrafanaPost", + description = "i18n::BaseTransform.TypeTooltipDesc.HTTPPOST", + categoryDescription = "i18n:org.apache.plc4x.hop.transforms.plc4xinput.messages:Plc4x.Category.plc4x", + keywords = "i18n::HttpPostMeta.keyword", + documentationUrl = "/pipeline/transforms/httppost.html") +public class GrafanaPostMeta extends BaseTransformMeta implements ITransformMeta { + private static final Class PKG = GrafanaPostMeta.class; // For Translator + + // the timeout for waiting for data (milliseconds) + public static final int DEFAULT_SOCKET_TIMEOUT = 10000; + + // the timeout until a connection is established (milliseconds) + public static final int DEFAULT_CONNECTION_TIMEOUT = 10000; + + // the time to wait till a connection is closed (milliseconds)? -1 is no not close. + public static final int DEFAULT_CLOSE_CONNECTIONS_TIME = -1; + + public static final String DEFAULT_ENCODING = "UTF-8"; + + @HopMetadataProperty(injectionKeyDescription = "HTTPPOST.Injection.socketTimeout") + private String socketTimeout; + + @HopMetadataProperty(injectionKeyDescription = "HTTPPOST.Injection.connectionTimeout") + private String connectionTimeout; + + @HopMetadataProperty(injectionKeyDescription = "HTTPPOST.Injection.closeIdleConnectionsTime") + private String closeIdleConnectionsTime; + + /** URL / service to be called */ + @HopMetadataProperty(injectionKeyDescription = "HTTPPOST.Injection.url") + private String url; + + @HopMetadataProperty(key = "lookup", injectionGroupDescription = "HTTPPOST.Injection.lookupfield") + private List lookupfield = new ArrayList<>(); + + @HopMetadataProperty(injectionKeyDescription = "HTTPPOST.Injection.urlInField") + private boolean urlInField; + + @HopMetadataProperty(injectionKeyDescription = "HTTPPOST.Injection.urlField") + private String urlField; + + @HopMetadataProperty(injectionKeyDescription = "HTTPPOST.Injection.requestEntity") + private String requestEntity; + + @HopMetadataProperty(injectionKeyDescription = "HTTPPOST.Injection.encoding") + private String encoding; + + @HopMetadataProperty(key = "postafile", injectionKeyDescription = "HTTPPOST.Injection.postAFile") + private boolean postAFile; + + @HopMetadataProperty(injectionKeyDescription = "HTTPPOST.Injection.proxyHost") + private String proxyHost; + + @HopMetadataProperty(injectionKeyDescription = "HTTPPOST.Injection.proxyPort") + private String proxyPort; + + @HopMetadataProperty(injectionKeyDescription = "HTTPPOST.Injection.httpLogin") + private String httpLogin; + + @HopMetadataProperty(password = true, injectionKeyDescription = "HTTPPOST.Injection.httpPassword") + private String httpPassword; + + @HopMetadataProperty( + key = "result", + injectionGroupDescription = "HTTPPOST.Injection.httpPostResultField") + private List httpPostResultField = new ArrayList<>(); + + public GrafanaPostMeta() { + super(); // allocate BaseTransformMeta + } + + public String getEncoding() { + return encoding; + } + + public void setEncoding(String encoding) { + this.encoding = encoding; + } + + /** @return Returns the connectionTimeout. */ + public String getConnectionTimeout() { + return connectionTimeout; + } + + /** @param connectionTimeout The connectionTimeout to set. */ + public void setConnectionTimeout(String connectionTimeout) { + this.connectionTimeout = connectionTimeout; + } + + /** @return Returns the closeIdleConnectionsTime. */ + public String getCloseIdleConnectionsTime() { + return closeIdleConnectionsTime; + } + + /** @param closeIdleConnectionsTime The connectionTimeout to set. */ + public void setCloseIdleConnectionsTime(String closeIdleConnectionsTime) { + this.closeIdleConnectionsTime = closeIdleConnectionsTime; + } + + /** @return Returns the socketTimeout. */ + public String getSocketTimeout() { + return socketTimeout; + } + + /** @param socketTimeout The socketTimeout to set. */ + public void setSocketTimeout(String socketTimeout) { + this.socketTimeout = socketTimeout; + } + + /** @return Returns the procedure. */ + public String getUrl() { + return url; + } + + /** @param procedure The procedure to set. */ + public void setUrl(String procedure) { + this.url = procedure; + } + + /** @return Is the url coded in a field? */ + public boolean isUrlInField() { + return urlInField; + } + + public boolean isPostAFile() { + return postAFile; + } + + public void setPostAFile(boolean postafile) { + this.postAFile = postafile; + } + + /** @param urlInField Is the url coded in a field? */ + public void setUrlInField(boolean urlInField) { + this.urlInField = urlInField; + } + + /** @return The field name that contains the url. */ + public String getUrlField() { + return urlField; + } + + /** @param urlField name of the field that contains the url */ + public void setUrlField(String urlField) { + this.urlField = urlField; + } + + /** @param requestEntity the requestEntity to set */ + public void setRequestEntity(String requestEntity) { + this.requestEntity = requestEntity; + } + + /** @return requestEntity */ + public String getRequestEntity() { + return requestEntity; + } + + public List getLookupfield() { + return lookupfield; + } + + public void setLookupfield(List lookupfield) { + this.lookupfield = lookupfield; + } + + public List getHttpPostResultField() { + return httpPostResultField; + } + + public void setHttpPostResultField(List httpPostResultField) { + this.httpPostResultField = httpPostResultField; + } + + @Override + public Object clone() { + GrafanaPostMeta retval = (GrafanaPostMeta) super.clone(); + + return retval; + } + + @Override + public void setDefault() { + encoding = DEFAULT_ENCODING; + postAFile = false; + lookupfield.add(new GrafanaPostLoookupField()); + httpPostResultField.add(new GrafanaPostResultField()); + socketTimeout = String.valueOf(DEFAULT_SOCKET_TIMEOUT); + connectionTimeout = String.valueOf(DEFAULT_CONNECTION_TIMEOUT); + closeIdleConnectionsTime = String.valueOf(DEFAULT_CLOSE_CONNECTIONS_TIME); + } + + @Override + public void getFields( + IRowMeta inputRowMeta, + String name, + IRowMeta[] info, + TransformMeta nextTransform, + IVariables variables, + IHopMetadataProvider metadataProvider) + throws HopTransformException { + if (!Utils.isEmpty(httpPostResultField.get(0).getName())) { + IValueMeta v = new ValueMetaString(httpPostResultField.get(0).getName()); + inputRowMeta.addValueMeta(v); + } + + if (!Utils.isEmpty(httpPostResultField.get(0).getCode())) { + IValueMeta v = new ValueMetaInteger(httpPostResultField.get(0).getCode()); + inputRowMeta.addValueMeta(v); + } + if (!Utils.isEmpty(httpPostResultField.get(0).getResponseTimeFieldName())) { + IValueMeta v = + new ValueMetaInteger( + variables.resolve(httpPostResultField.get(0).getResponseTimeFieldName())); + inputRowMeta.addValueMeta(v); + } + String headerFieldName = + variables.resolve(httpPostResultField.get(0).getResponseHeaderFieldName()); + if (!Utils.isEmpty(headerFieldName)) { + IValueMeta v = new ValueMetaString(headerFieldName); + v.setOrigin(name); + inputRowMeta.addValueMeta(v); + } + } + + @Override + public void check( + List remarks, + PipelineMeta pipelineMeta, + TransformMeta transformMeta, + IRowMeta prev, + String[] input, + String[] output, + IRowMeta info, + IVariables variables, + IHopMetadataProvider metadataProvider) { + CheckResult cr; + + // See if we have input streams leading to this transform! + if (input.length > 0) { + cr = + new CheckResult( + ICheckResult.TYPE_RESULT_OK, + BaseMessages.getString( + PKG, "HTTPPOSTMeta.CheckResult.ReceivingInfoFromOtherTransforms"), + transformMeta); + remarks.add(cr); + } else { + cr = + new CheckResult( + ICheckResult.TYPE_RESULT_ERROR, + BaseMessages.getString(PKG, "HTTPPOSTMeta.CheckResult.NoInpuReceived"), + transformMeta); + remarks.add(cr); + } + + // check Url + if (urlInField) { + if (Utils.isEmpty(urlField)) { + cr = + new CheckResult( + ICheckResult.TYPE_RESULT_ERROR, + BaseMessages.getString(PKG, "HTTPPOSTMeta.CheckResult.UrlfieldMissing"), + transformMeta); + } else { + cr = + new CheckResult( + ICheckResult.TYPE_RESULT_ERROR, + BaseMessages.getString(PKG, "HTTPPOSTMeta.CheckResult.UrlfieldOk"), + transformMeta); + } + + } else { + if (Utils.isEmpty(url)) { + cr = + new CheckResult( + ICheckResult.TYPE_RESULT_ERROR, + BaseMessages.getString(PKG, "HTTPPOSTMeta.CheckResult.UrlMissing"), + transformMeta); + } else { + cr = + new CheckResult( + ICheckResult.TYPE_RESULT_OK, + BaseMessages.getString(PKG, "HTTPPOSTMeta.CheckResult.UrlOk"), + transformMeta); + } + } + remarks.add(cr); + } + + public GrafanaPost createTransform( + TransformMeta transformMeta, + GrafanaPostData data, + int cnr, + PipelineMeta pipelineMeta, + Pipeline pipeline) { + return new GrafanaPost(transformMeta, this, data, cnr, pipelineMeta, pipeline); + } + + public GrafanaPostData getTransformData() { + return new GrafanaPostData(); + } + + @Override + public boolean supportsErrorHandling() { + return true; + } + + /** + * ISetter + * + * @param proxyHost + */ + public void setProxyHost(String proxyHost) { + this.proxyHost = proxyHost; + } + + /** + * IGetter + * + * @return + */ + public String getProxyHost() { + return proxyHost; + } + + /** + * ISetter + * + * @param proxyPort + */ + public void setProxyPort(String proxyPort) { + this.proxyPort = proxyPort; + } + + /** + * IGetter + * + * @return + */ + public String getProxyPort() { + return this.proxyPort; + } + + /** + * ISetter + * + * @param httpLogin + */ + public void setHttpLogin(String httpLogin) { + this.httpLogin = httpLogin; + } + + /** + * IGetter + * + * @return + */ + public String getHttpLogin() { + return httpLogin; + } + + /** + * ISetter + * + * @param httpPassword + */ + public void setHttpPassword(String httpPassword) { + this.httpPassword = httpPassword; + } + + /** @return */ + public String getHttpPassword() { + return httpPassword; + } +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPostQuery.java b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPostQuery.java new file mode 100644 index 00000000000..6e6f259a393 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPostQuery.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.plc4x.hop.utils.transforms.grafana; + +import org.apache.hop.metadata.api.HopMetadataProperty; + +public class GrafanaPostQuery { + + @HopMetadataProperty(injectionKeyDescription = "HTTPPOST.Injection.QueryFieldName") + private String name; + + @HopMetadataProperty(injectionKeyDescription = "HTTPPOST.Injection.QueryFieldParameter") + private String parameter; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getParameter() { + return parameter; + } + + public void setParameter(String parameter) { + this.parameter = parameter; + } + + public GrafanaPostQuery(String name, String parameter) { + this.name = name; + this.parameter = parameter; + } + + public GrafanaPostQuery(GrafanaPostQuery httpPostQuery) { + this.name = httpPostQuery.name; + this.parameter = httpPostQuery.parameter; + } + + public GrafanaPostQuery() {} +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPostResultField.java b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPostResultField.java new file mode 100644 index 00000000000..afdd547fb95 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/java/org/apache/plc4x/hop/utils/transforms/grafana/GrafanaPostResultField.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.plc4x.hop.utils.transforms.grafana; + +import org.apache.hop.metadata.api.HopMetadataProperty; + +public class GrafanaPostResultField { + + @HopMetadataProperty(injectionKeyDescription = "HTTPPOST.Injection.ResultFieldCode") + private String code; + + @HopMetadataProperty(injectionKeyDescription = "HTTPPOST.Injection.ResultFieldName") + private String name; + + @HopMetadataProperty( + key = "response_time", + injectionKeyDescription = "HTTPPOST.Injection.ResultFieldResponseTime") + private String responseTimeFieldName; + + @HopMetadataProperty( + key = "response_header", + injectionKeyDescription = "HTTPPOST.Injection.ResultFieldResponseHeader") + private String responseHeaderFieldName; + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getResponseTimeFieldName() { + return responseTimeFieldName; + } + + public void setResponseTimeFieldName(String responseTimeFieldName) { + this.responseTimeFieldName = responseTimeFieldName; + } + + public String getResponseHeaderFieldName() { + return responseHeaderFieldName; + } + + public void setResponseHeaderFieldName(String responseHeaderFieldName) { + this.responseHeaderFieldName = responseHeaderFieldName; + } + + public GrafanaPostResultField( + String code, String name, String responseTimeFieldName, String responseHeaderFieldName) { + this.code = code; + this.name = name; + this.responseTimeFieldName = responseTimeFieldName; + this.responseHeaderFieldName = responseHeaderFieldName; + } + + public GrafanaPostResultField(GrafanaPostResultField httpPostResultField) { + this.code = httpPostResultField.code; + this.name = httpPostResultField.name; + this.responseTimeFieldName = httpPostResultField.responseTimeFieldName; + this.responseHeaderFieldName = httpPostResultField.responseHeaderFieldName; + } + + public GrafanaPostResultField() { + this.code = "result"; + } +} diff --git a/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/resources/grafana.svg b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/resources/grafana.svg new file mode 100644 index 00000000000..ff8c2c5fabd --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/resources/grafana.svg @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/resources/org/apache/plc4x/hop/utils/transforms/grafana/messages/messages_en_US.properties b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/resources/org/apache/plc4x/hop/utils/transforms/grafana/messages/messages_en_US.properties new file mode 100644 index 00000000000..3904e5caa47 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-utils/hop-plc4x-grafana/src/main/resources/org/apache/plc4x/hop/utils/transforms/grafana/messages/messages_en_US.properties @@ -0,0 +1,138 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +BaseTransform.TypeTooltipDesc.HTTPPOST=Call a web service request over HTTP by supplying a base URL by allowing parameters to be set dynamically +BaseTransform.TypeLongDesc.GrafanaPost=Grafana post +HTTPPOSTMeta.Exception.UnableToReadTransformMeta=Unable to read transform information from XML +HTTPPOST.Log.StartingToRun=Starting to run ... +HTTPPOSTDialog.UrlInField.Label=Accept URL from field? +HTTPPOSTDialog.QueryParameters.Label=Query parameters +HTTPPOSTDialog.ColumnInfo.Name=Name +HTTPPOSTDialog.InvalidConnection.DialogMessage=Please select a valid connection\! +HTTPPOSTDialog.UrlField.Tooltip=URL field name +HTTPPOST.Exception.CouldnotFindRequestEntityField=Can not find request entity field [{0}]\! +HTTPPOSTMeta.CheckResult.UrlMissing=URL is missing\! +HTTPPOST.Log.ConnectingToURL=Connecting to [{0}] ... +HTTPPOSTDialog.Log.GettingKeyInfo=getting key info... +HTTPPOSTDialog.URL.Label=URL +HTTPPOST.Log.ResponseCode=The response code is {0} +HTTPPOSTDialog.Log.FoundQueryParameters=Found {0} query parameters +HTTPPOSTDialog.TransformName.Label=Transform name +HTTPPOSTDialog.ColumnInfo.Parameter=Parameter +HTTPPOSTDialog.ColumnInfo.Header=Put in Header? +HTTPPOSTMeta.CheckResult.UrlfieldMissing=URL field is missing\! +HTTPPOSTDialog.AutoCommit.Tooltip=Enable auto commit on this database connection.\nWhen the auto commit is off, a commit is done after the last row is processed. +HTTPPOSTDialog.requestEntity.Label=Request entity field +HTTPPOST.ErrorInTransformRunning=Because of an error, this transform can''t continue\: +HTTPPOSTDialog.UrlField.Label=URL field name +HTTPPOSTMeta.CheckResult.ReceivingInfoFromOtherTransforms=Transform is receiving info from other transforms. +HTTPPOST.LineNumber=linenr +HTTPPOST.Log.DBException=An error occurred, processing will be stopped\: +HTTPPOSTDialog.GetFields.Button=\ &Get Fields +HTTPPOST.Log.ResponseStatusCode=Response status code\: {0} +HTTPPOST.Log.UnableCreateUrl=Unable to create URL. +HTTPPOSTDialog.postAFile.Label=Post a file +HTTPPOST.Log.UnableGetResult=Unable to get result from specified URL \: {0} +HTTPPOSTDialog.postAFile.Tooltip=Post a file +HTTPPOST.Exception.ErrorFindingField=Error finding field [{0}] \! +HTTPPOSTDialog.FailedToGetFields.DialogTitle=Error getting fields +HTTPPOSTMeta.CheckResult.AllArgumentsOK=All arguments found in the input stream. +HTTPPOSTDialog.Log.FoundArguments=Found {0} arguments +HTTPPOSTMeta.CheckResult.UrlOk=URL is specified. +HTTPPOST.Log.ResponseBody=The response body is {0} +HTTPPOSTDialog.ColumnInfo.QueryParameter=Value +HTTPPOST.Log.ErrorFindingField=We can not find field [{0}] in the input stream\! +HTTPPOSTMeta.CheckResult.CouldNotReadFields=Couldn''t read fields from the previous transform. +HTTPPOSTDialog.InvalidConnection.DialogTitle=ERROR +HTTPPOSTDialog.ResultType.Label=Result type +HTTPPOSTDialog.Shell.Title=HTTP post +HTTPPOST.Log.ConnectedToDB=Connected to database... +HTTPPOST.Log.HeaderValue=Header parameter [{0}]=''{1}'' +HTTPPOST.Log.BodyValue=Body parameter [{0}]=''{1}'' +HTTPPOST.Log.QueryValue=Query parameter [{0}]=''{1}'' +HTTPPOSTDialog.Encoding.Label=Encoding +HTTPPOST.Log.Encoding=Header content encoding \: {0} +HTTPPOST.Log.Connecting=Connecting to \: [{0}] +HTTPPOSTMeta.CheckResult.NoInpuReceived=No input received from other transforms\! +HTTPPOSTDialog.FailedToGetFields.DialogMessage=We failed to get fields from previous transform\! +HTTPPOSTMeta.CheckResult.ErrorOccurred=An error occurred\: +HTTPPOSTDialog.Parameters.Label=Body (Header) Parameters \: +HTTPPOSTMeta.CheckResult.MissingArguments=Missing arguments, not found in input from previous transforms\: +HTTPPOST.Log.NoField=URL field name is missing\! +HTTPPOSTMeta.CheckResult.UrlfieldOk=URL field is specified. +HTTPPOSTDialog.Result.Label=Result field name +HTTPPOSTDialog.ResponseTime.Label=Response time (milliseconds) field name +HTTPPOSTDialog.ResponseHeader.Label=Response header field name +HTTPPOSTDialog.ResultCode.Label=HTTP status code field name +HTTPPOSTMeta.CheckResult.WrongTypeArguments=\ (found but wrong type\: {0} vs. {1}) +HTTPPOSTDialog.AutoCommit.Label=Enable auto commit +HTTPPOST.Error.CanNotReadURL=Can not result from [{0}] +HTTPPOST.Log.UnexpectedError=Unexpected error +HTTPPOST.Log.ResponseTime=Response time (milliseconds)\: [{0}] for [{1}] +HTTPPOST.Exception.CouldnotFindField=Couldn''t find field ''{0}'' in row\! +HTTPPOSTMeta.CheckResult.InvalidConnection=Please select or create a connection\! +HTTPPOSTDialog.ColumnInfo.QueryName=Name +HTTPPOSTDialog.HttpAuthGroup.Label=HTTP authentication +HTTPPOSTDialog.HttpLogin.Label=HTTP Login +HTTPPOSTDialog.HttpLogin.Tooltip=HTTP login used to authenticate the call +HTTPPOSTDialog.HttpPassword.Label=HTTP Password +HTTPPOSTDialog.HttpPassword.Tooltip=HTTP password used to authenticate the call +HTTPPOSTDialog.ProxyGroup.Label=Proxy to use +HTTPPOSTDialog.ProxyHost.Label=Proxy Host +HTTPPOSTDialog.ProxyHost.Tooltip=Proxy Host +HTTPPOSTDialog.ProxyPort.Label=Proxy Port +HTTPPOSTDialog.ProxyPort.Tooltip=Proxy Port +HTTPPOST.Exception.Authentication=You need to be authenticated to access the resource at {0}. +HTTPPOST.Exception.IllegalStatusCode=Status code is Illegal: {0}. +HTTPPOST.Error.UnknownHostException=Unknown host {0}. +HTTPPOSTDialog.GeneralTab.Title=General +HTTPPOSTDialog.FieldsTab.Title=Fields +HTTPPOSTDialog.SettingsGroup.Label=Settings +HTTPDialog.OutputFieldsGroup.Label=Output fields +HTTPPOSTDialog.ConnectionTimeOut.Label=Connection timeout +HTTPPOSTDialog.ConnectionTimeOut.Tooltip=The timeout until a connection is established (milliseconds) +HTTPPOSTDialog.SocketTimeOut.Label=Socket timeout +HTTPPOSTDialog.SocketTimeOut.Tooltip=The timeout for waiting for data (milliseconds) +HTTPPOSTDialog.CloseIdleConnectionsTime.Label=Connection close wait time +HTTPPOSTDialog.CloseIdleConnectionsTime.Tooltip=Close all connections older than x milliseconds. +HTTPPOST.Injection.socketTimeout=Socket timeout value (miliseconds) +HTTPPOST.Injection.connectionTimeout=Connection timeout value (miliseconds) +HTTPPOST.Injection.closeIdleConnectionsTime=Connection close wait time (miliseconds) +HTTPPOST.Injection.url=Endpoint URL +HTTPPOST.Injection.lookupfield=Query parameters +HTTPPOST.Injection.urlInField=Accept URL from fieldname (Y/N) +HTTPPOST.Injection.urlField=URL Fieldname +HTTPPOST.Injection.requestEntity=Request entity Fieldname +HTTPPOST.Injection.encoding=Encoding +HTTPPOST.Injection.postAFile=Post a file (Y/N) +HTTPPOST.Injection.proxyHost=Proxy Hostname +HTTPPOST.Injection.proxyPort=Proxy Port +HTTPPOST.Injection.httpLogin=HTTP Login +HTTPPOST.Injection.httpPassword=HTTP Password +HTTPPOST.Injection.httpPostResultField=Result fields +HTTPPOST.Injection.LookupQueryField=Http Post Query fields +HTTPPOST.Injection.LookupArgumentField=Http Post Argument fields +HTTPPOST.Injection.ArgumentFieldName=Body (Header) Field name +HTTPPOST.Injection.ArgumentFieldParameter=Body (Header) value +HTTPPOST.Injection.ArgumentFieldHeader=Put in Header (Y/N) +HTTPPOST.Injection.QueryFieldName=Query parameter field name +HTTPPOST.Injection.QueryFieldParameter=Query parameter value +HTTPPOST.Injection.ResultFieldName=Result field name +HTTPPOST.Injection.ResultFieldCode=HTTP status code field name +HTTPPOST.Injection.ResultFieldResponseTime=Response time (milliseconds) +HTTPPOST.Injection.ResultFieldResponseHeader=Response header field name +HttpPostMeta.keyword=http,post + diff --git a/plc4j/integrations/apache-hop/plc4x-hop-utils/pom.xml b/plc4j/integrations/apache-hop/plc4x-hop-utils/pom.xml new file mode 100644 index 00000000000..d7d3d520904 --- /dev/null +++ b/plc4j/integrations/apache-hop/plc4x-hop-utils/pom.xml @@ -0,0 +1,33 @@ + + + + 4.0.0 + + org.apache.plc4x + plc4j-apache-hop + 0.11.0-SNAPSHOT + + hop-plc4x-utils + pom + PLC4J: Integrations: Apache Hop: Utils + + hop-plc4x-grafana + + \ No newline at end of file diff --git a/plc4j/integrations/apache-hop/pom.xml b/plc4j/integrations/apache-hop/pom.xml new file mode 100644 index 00000000000..a1b43bdce79 --- /dev/null +++ b/plc4j/integrations/apache-hop/pom.xml @@ -0,0 +1,251 @@ + + + + 4.0.0 + + org.apache.plc4x + plc4j-integrations + 0.11.0-SNAPSHOT + + + plc4j-apache-hop + pom + PLC4J: Integrations: Apache Hop + + + + + + 2.4.0 + + /home/hans/Documents/test + + 3.114.0 + 3.1.0 + + 2.2.2.Final + + 0.11.0-SNAPSHOT + 1.4.01 + + + + + plc4x-hop-actions + plc4x-hop-metadata + plc4x-hop-transformer + plc4x-hop-assemblies + plc4x-hop-utils + + + + + + swt-unix + + + unix + + + + org.eclipse.swt.gtk.linux.x86_64 + linux + + + + + org.eclipse.platform + ${swt.artifactId} + ${org.eclipse.platform.version} + + + * + * + + + + + + + + swt-mac + + + mac + + + + org.eclipse.swt.cocoa.macosx.x86_64 + mac + + + + + org.eclipse.platform + ${swt.artifactId} + ${org.eclipse.platform.version} + + + * + * + + + + + + + + swt-windows + + + windows + + + + org.eclipse.swt.win32.win32.x86_64 + windows + + + + + org.eclipse.platform + ${swt.artifactId} + ${org.eclipse.platform.version} + + + * + * + + + + + + + + + + + + central + https://repo1.maven.org/maven2/ + Maven Central + + false + + + true + + + + Apache + https://repository.apache.org/snapshots/ + Apache Repository + + true + + + false + + + + + + apache.snapshots + https://repository.apache.org/snapshots/ + + true + + + false + + + + + + + + + org.apache.rat + apache-rat-plugin + 0.13 + + false + true + + + + DISCLAIMER + LICENSE + NOTICE + **/licenses/* + **/target/** + **/*.svg + **/*.json + **/PUT_JDBC_HERE + **/hop.pwd + **/*.iml + + + **/test/**/*.txt + **/test/**/*.xml + **/test/**/*.xsd + **/test/**/*.csv + **/test/**/*.csv.bz2 + **/test/**/*.csv.gz + **/test/**/*.ods + **/test/**/*.xls + **/test/**/*.xlsx + **/test/**/*.edi + **/test/**/*.avro + **/test/**/*.snippet + + + **/datasets/*.csv + **/it/**/*.csv + + + **/integration-tests/**/*.txt + **/integration-tests/**/*.json + **/integration-tests/**/*.json.old + + + + **/src/main/samples/**/*.txt + **/src/main/samples/**/*.csv + + + docs/content/** + docs/resources/** + docs/node_modules/** + docs/.pnp/** + docs/.pnp.js + docs/yarn.lock + + + + + + + + + + + + \ No newline at end of file diff --git a/plc4j/integrations/pom.xml b/plc4j/integrations/pom.xml index 253dcb038b5..28c39abc3d8 100644 --- a/plc4j/integrations/pom.xml +++ b/plc4j/integrations/pom.xml @@ -37,6 +37,7 @@ apache-nifi apache-calcite opcua-server + apache-hop diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/DefaultNettyPlcConnection.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/DefaultNettyPlcConnection.java index 7e301043182..58353c27dc6 100644 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/DefaultNettyPlcConnection.java +++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/DefaultNettyPlcConnection.java @@ -40,6 +40,7 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; import java.util.stream.Stream; public class DefaultNettyPlcConnection extends AbstractPlcConnection implements ChannelExposingConnection, EventPlcConnection { diff --git a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xConnectRequest.java b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xConnectRequest.java index c632933923f..b1146e15775 100644 --- a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xConnectRequest.java +++ b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xConnectRequest.java @@ -58,7 +58,6 @@ public String getConnectionString() { protected void serializePlc4xMessageChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("Plc4xConnectRequest"); // Implicit Field (connectionStringLen) (Used for parsing, but its value is not stored as it's @@ -104,8 +103,6 @@ public static Plc4xMessageBuilder staticParsePlc4xMessageBuilder(ReadBuffer read throws ParseException { readBuffer.pullContext("Plc4xConnectRequest"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short connectionStringLen = diff --git a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xConnectResponse.java b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xConnectResponse.java index 60178785e18..c3f74bc29fa 100644 --- a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xConnectResponse.java +++ b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xConnectResponse.java @@ -64,7 +64,6 @@ public Plc4xResponseCode getResponseCode() { protected void serializePlc4xMessageChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("Plc4xConnectResponse"); // Simple Field (connectionId) @@ -112,8 +111,6 @@ public static Plc4xMessageBuilder staticParsePlc4xMessageBuilder(ReadBuffer read throws ParseException { readBuffer.pullContext("Plc4xConnectResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); int connectionId = diff --git a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xConstants.java b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xConstants.java index 5891b021226..686c63b4b13 100644 --- a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xConstants.java +++ b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xConstants.java @@ -51,7 +51,6 @@ public int getPlc4xTcpDefaultPort() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("Plc4xConstants"); // Const Field (plc4xTcpDefaultPort) @@ -86,8 +85,6 @@ public static Plc4xConstants staticParse(ReadBuffer readBuffer, Object... args) public static Plc4xConstants staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("Plc4xConstants"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); int plc4xTcpDefaultPort = diff --git a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xMessage.java b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xMessage.java index e8019cd783d..dfb051e649c 100644 --- a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xMessage.java +++ b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xMessage.java @@ -65,7 +65,6 @@ protected abstract void serializePlc4xMessageChild(WriteBuffer writeBuffer) public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("Plc4xMessage"); // Const Field (version) @@ -143,8 +142,6 @@ public static Plc4xMessage staticParse(ReadBuffer readBuffer, Object... args) public static Plc4xMessage staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("Plc4xMessage"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short version = diff --git a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xReadRequest.java b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xReadRequest.java index b8426a5ac02..5d24a78136f 100644 --- a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xReadRequest.java +++ b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xReadRequest.java @@ -64,7 +64,6 @@ public List getTags() { protected void serializePlc4xMessageChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("Plc4xReadRequest"); // Simple Field (connectionId) @@ -123,8 +122,6 @@ public static Plc4xMessageBuilder staticParsePlc4xMessageBuilder(ReadBuffer read throws ParseException { readBuffer.pullContext("Plc4xReadRequest"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); int connectionId = diff --git a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xReadResponse.java b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xReadResponse.java index 96a85cd71cc..e57738d1f8c 100644 --- a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xReadResponse.java +++ b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xReadResponse.java @@ -74,7 +74,6 @@ public List getTags() { protected void serializePlc4xMessageChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("Plc4xReadResponse"); // Simple Field (connectionId) @@ -147,8 +146,6 @@ public static Plc4xMessageBuilder staticParsePlc4xMessageBuilder(ReadBuffer read throws ParseException { readBuffer.pullContext("Plc4xReadResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); int connectionId = diff --git a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xRequestType.java b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xRequestType.java index 4e118f5bd43..712be6fdf5e 100644 --- a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xRequestType.java +++ b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xRequestType.java @@ -45,7 +45,7 @@ public enum Plc4xRequestType { } } - private short value; + private final short value; Plc4xRequestType(short value) { this.value = value; diff --git a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xResponseCode.java b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xResponseCode.java index 36b32de966a..03cef96a869 100644 --- a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xResponseCode.java +++ b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xResponseCode.java @@ -44,7 +44,7 @@ public enum Plc4xResponseCode { } } - private short value; + private final short value; Plc4xResponseCode(short value) { this.value = value; diff --git a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xSubscriptionType.java b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xSubscriptionType.java index 9340c3c5547..60f730b3991 100644 --- a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xSubscriptionType.java +++ b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xSubscriptionType.java @@ -36,7 +36,7 @@ public enum Plc4xSubscriptionType { } } - private short value; + private final short value; Plc4xSubscriptionType(short value) { this.value = value; diff --git a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xTag.java b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xTag.java index 110c3072856..c5a9b366bcd 100644 --- a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xTag.java +++ b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xTag.java @@ -58,7 +58,6 @@ public String getTagQuery() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("Plc4xTag"); // Implicit Field (nameLen) (Used for parsing, but its value is not stored as it's implicitly @@ -114,8 +113,6 @@ public static Plc4xTag staticParse(ReadBuffer readBuffer, Object... args) throws public static Plc4xTag staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("Plc4xTag"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); short nameLen = readImplicitField("nameLen", readUnsignedShort(readBuffer, 8)); diff --git a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xTagRequest.java b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xTagRequest.java index 0a30976e34d..6eec2a4b7a7 100644 --- a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xTagRequest.java +++ b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xTagRequest.java @@ -52,7 +52,6 @@ public Plc4xTag getTag() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("Plc4xTagRequest"); // Simple Field (tag) @@ -87,8 +86,6 @@ public static Plc4xTagRequest staticParse(ReadBuffer readBuffer, Object... args) public static Plc4xTagRequest staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("Plc4xTagRequest"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); Plc4xTag tag = diff --git a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xTagResponse.java b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xTagResponse.java index b603c118756..03db129e010 100644 --- a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xTagResponse.java +++ b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xTagResponse.java @@ -58,7 +58,6 @@ public Plc4xResponseCode getResponseCode() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("Plc4xTagResponse"); // Simple Field (tag) @@ -106,8 +105,6 @@ public static Plc4xTagResponse staticParse(ReadBuffer readBuffer, Object... args public static Plc4xTagResponse staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("Plc4xTagResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); Plc4xTag tag = diff --git a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xTagValueRequest.java b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xTagValueRequest.java index cc092c5a803..7b5f5dc1d86 100644 --- a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xTagValueRequest.java +++ b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xTagValueRequest.java @@ -64,7 +64,6 @@ public PlcValue getValue() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("Plc4xTagValueRequest"); // Simple Field (tag) @@ -123,8 +122,6 @@ public static Plc4xTagValueRequest staticParse(ReadBuffer readBuffer, Object... public static Plc4xTagValueRequest staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("Plc4xTagValueRequest"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); Plc4xTag tag = diff --git a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xTagValueResponse.java b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xTagValueResponse.java index af2af4f8cad..ebfc6c35e51 100644 --- a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xTagValueResponse.java +++ b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xTagValueResponse.java @@ -71,7 +71,6 @@ public PlcValue getValue() { public void serialize(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("Plc4xTagValueResponse"); // Simple Field (tag) @@ -143,8 +142,6 @@ public static Plc4xTagValueResponse staticParse(ReadBuffer readBuffer, Object... public static Plc4xTagValueResponse staticParse(ReadBuffer readBuffer) throws ParseException { readBuffer.pullContext("Plc4xTagValueResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); Plc4xTag tag = diff --git a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xValueType.java b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xValueType.java index 78ae46a27fb..58e6216e8dc 100644 --- a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xValueType.java +++ b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xValueType.java @@ -64,7 +64,7 @@ public enum Plc4xValueType { } } - private short value; + private final short value; Plc4xValueType(short value) { this.value = value; diff --git a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xWriteRequest.java b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xWriteRequest.java index 6a0cb1486ba..8020ba0d7ca 100644 --- a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xWriteRequest.java +++ b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xWriteRequest.java @@ -64,7 +64,6 @@ public List getTags() { protected void serializePlc4xMessageChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("Plc4xWriteRequest"); // Simple Field (connectionId) @@ -123,8 +122,6 @@ public static Plc4xMessageBuilder staticParsePlc4xMessageBuilder(ReadBuffer read throws ParseException { readBuffer.pullContext("Plc4xWriteRequest"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); int connectionId = diff --git a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xWriteResponse.java b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xWriteResponse.java index 0c50b76159f..7966508f0c6 100644 --- a/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xWriteResponse.java +++ b/plc4j/tools/plc4x-server/src/main/generated/org/apache/plc4x/java/plc4x/readwrite/Plc4xWriteResponse.java @@ -74,7 +74,6 @@ public List getTags() { protected void serializePlc4xMessageChild(WriteBuffer writeBuffer) throws SerializationException { PositionAware positionAware = writeBuffer; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); - int startPos = positionAware.getPos(); writeBuffer.pushContext("Plc4xWriteResponse"); // Simple Field (connectionId) @@ -147,8 +146,6 @@ public static Plc4xMessageBuilder staticParsePlc4xMessageBuilder(ReadBuffer read throws ParseException { readBuffer.pullContext("Plc4xWriteResponse"); PositionAware positionAware = readBuffer; - int startPos = positionAware.getPos(); - int curPos; boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get(); int connectionId = diff --git a/pom.xml b/pom.xml index 4e114e4089c..324c0f7ded2 100644 --- a/pom.xml +++ b/pom.xml @@ -818,6 +818,8 @@ **/hs_err_pid* **/replay_pid* + + **/*.svg diff --git a/protocols/s7/src/main/resources/protocols/s7/s7.mspec b/protocols/s7/src/main/resources/protocols/s7/s7.mspec index d6df405d0d5..c6cfcdd4eca 100644 --- a/protocols/s7/src/main/resources/protocols/s7/s7.mspec +++ b/protocols/s7/src/main/resources/protocols/s7/s7.mspec @@ -285,10 +285,10 @@ ] ] -//TODO: Se debe modificar el calculo para incluir el tipo -// . si es tipo 4 usa el desplazamiento -// . si es tipo 3, la longitud es la indicada -// . verificar calculo con los otros tipos +//TODO: The calculation must be modified to include the type +// . if it is type 0x07(REAL) or 0x09 (OCTET_STRING), the length is indicated +// . another type uses scrolling +// . verify calculation with the other types [type AssociatedValueType [simple DataTransportErrorCode returnCode] [simple DataTransportSize transportSize] @@ -439,7 +439,8 @@ [simple uint 8 syntaxId] [typeSwitch syntaxId ['0x10' CycServiceItemAnyType - [simple TransportSize transportSize] + //[simple TransportSize transportSize] + [enum TransportSize transportSize code] [simple uint 16 length] [simple uint 16 dbNumber] [simple MemoryArea memoryArea] diff --git a/src/site/asciidoc/developers/protocols/ads/images/ads-statemachine.svg b/src/site/asciidoc/developers/protocols/ads/images/ads-statemachine.svg new file mode 100644 index 00000000000..b3923580aec --- /dev/null +++ b/src/site/asciidoc/developers/protocols/ads/images/ads-statemachine.svg @@ -0,0 +1 @@ +ConnectedConnectBrowseReadWriteSubscribeUnsubscribeinitializingSend 'Add Or Update AMS Routes'Send 'ADS Read Device Info'Receive 'Add Or Update AMS Routes'Receive 'ADS Read Device Info'Init Read Online and Offline VersionReset Symbol and Data-Type DataSend 'Read Online-Version (Symbolic)'Send 'Read Offline-Version'Receive 'Read Online-Version (Symbolic)'Receive 'Read Offline-Version'Send 'Read Symbol- and Data-Type-Table sizes'Receive 'Read Symbol- and Data-Type-Table sizes'Send 'Read Data-Type-Table'Receive 'Read Data-Type-Table'Send 'Read Symbol-Table'Receive 'Read Symbol-Table'Subscribe to changes to the Online- and Offline VersionBrowseBrowse: Send 'Read Symbol- and Data-Type-Table sizes'Browse: Receive 'Read Symbol- and Data-Type-Table sizes'Browse: Send 'Read Data-Type-Table'Browse: Receive 'Read Data-Type-Table'Browse: Send 'Read Symbol-Table'Browse: Receive 'Read Symbol-Table'Return API Browse ResultReadRead: Send 'Multi Item Address Resolution' for unresolvedRead: Receive 'Multi Item Address Resolution' for unresolvedRead: Send 'Multi Item Read'Read: Receive 'Multi Item Read'Read: Return API Read ResultRead: Send 'Single Item Address Resolution'Read: Receive 'Single Item Address Resolution'Read: Send 'Single Item Read'Read: Receive 'Single Item Read'WriteWrite: Send 'Multi Item Address Resolution' for unresolvedWrite: Receive 'Multi Item Address Resolution' for unresolvedWrite: Send 'Multi Item Write'Write: Receive 'Multi Item Write'Write: Return API Write ResultWrite: Send 'Single Item Address Resolution'Write: Receive 'Single Item Address Resolution'Write: Send 'Single Item Write'Write: Receive 'Single Item Write'SubscribeSubscribe: Send 'Multi Item Address Resolution' for unresolvedSubscribe: Receive 'Multi Item Address Resolution' for unresolvedSubscribe: Send 'Single Item Address Resolution'Subscribe: Receive 'Single Item Address Resolution'Subscribe: Send 'Single Item 1 Subscibe'Subscribe: Receive 'Single Item 1 Subscibe'Subscribe: Send 'Single Item 2 Subscibe'Subscribe: Receive 'Single Item 2 Subscibe'Subscribe: Send 'Single Item n Subscibe'Subscribe: Receive 'Single Item n Subscibe'Subscribe: Return API Write ResultUnsubscribeUnsubscribe: Send 'Single Item 1 Unsubscribe'Unsubscribe: Receive 'Single Item 1 Unsubscribe'Unsubscribe: Send 'Single Item 2 Unsubscribe'Unsubscribe: Receive 'Single Item 2 Unsubscribe'Unsubscribe: Send 'Single Item n Unsubscribe'Unsubscribe: Receive 'Single Item n Unsubscribe'Unsubscribe: Return API Unsubscribe ResultAPI Browse RequestAPI Read RequestAPI Write RequestAPI Subscription RequestAPI Unsubscription RequestUsing Authentication?truefalseConfig: Monitor PLC changes?truefalseConfig: Load Symbol- and Data-Type-Tables?truefalseConfig: Monitor PLC changes?trueUpdate the online- or offline version (Depending on wich one changed)Is symbol- and data-type-table loaded?truefalseIs single item read request?falseAre all field addresses resolved?unresolvedresolvedtrueIs the field address resolved?falsetrueIs single item write request?falseAre all field addresses resolved?unresolvedresolvedtrueIs the field address resolved?falsetrueIs single item subscription request?falseAre all field addresses resolved?unresolvedresolvedtrueIs the field address resolved?falsetrue \ No newline at end of file diff --git a/src/site/asciidoc/images/01.png b/src/site/asciidoc/images/01.png new file mode 100644 index 00000000000..cdaee053bf2 Binary files /dev/null and b/src/site/asciidoc/images/01.png differ diff --git a/src/site/asciidoc/images/dt0.png b/src/site/asciidoc/images/dt0.png new file mode 100644 index 00000000000..cdaee053bf2 Binary files /dev/null and b/src/site/asciidoc/images/dt0.png differ diff --git a/src/site/asciidoc/images/dt01.png b/src/site/asciidoc/images/dt01.png new file mode 100644 index 00000000000..317499115f6 Binary files /dev/null and b/src/site/asciidoc/images/dt01.png differ diff --git a/src/site/asciidoc/images/dt02.png b/src/site/asciidoc/images/dt02.png new file mode 100644 index 00000000000..dea5bdbc7ec Binary files /dev/null and b/src/site/asciidoc/images/dt02.png differ diff --git a/src/site/asciidoc/images/plc4x-architecture.png b/src/site/asciidoc/images/plc4x-architecture.png new file mode 100644 index 00000000000..4891a28c492 Binary files /dev/null and b/src/site/asciidoc/images/plc4x-architecture.png differ diff --git a/src/site/asciidoc/index.adoc b/src/site/asciidoc/index.adoc index 5ecb4db6614..cbed626f264 100644 --- a/src/site/asciidoc/index.adoc +++ b/src/site/asciidoc/index.adoc @@ -165,6 +165,20 @@ +