Compare commits
4 Commits
main
...
irt-parser
Author | SHA1 | Date |
---|---|---|
dancingCycle | 072298f9d7 | |
dancingCycle | b2671d2421 | |
dancingCycle | b13d264414 | |
dancingCycle | 492b803a18 |
|
@ -1,3 +1,8 @@
|
||||||
|
##############################
|
||||||
|
## Other
|
||||||
|
##############################
|
||||||
|
log.txt
|
||||||
|
|
||||||
##############################
|
##############################
|
||||||
## Java
|
## Java
|
||||||
##############################
|
##############################
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# TGP: Telegram Parser
|
# IVU radio telegram parser
|
||||||
|
|
||||||
# Links
|
# Links
|
||||||
|
|
||||||
|
|
14
pom.xml
14
pom.xml
|
@ -6,16 +6,16 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>de.swingbe.ifleet</groupId>
|
<groupId>de.swingbe.ifleet</groupId>
|
||||||
<artifactId>tgp</artifactId>
|
<artifactId>irt-parser</artifactId>
|
||||||
<version>0.2.0</version>
|
<version>1.1.0</version>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
This project is a library for parsing ifleet telegrams in Java.
|
IVU radio telegram parser.
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<url>https://swingbe.de</url>
|
<url>https://swingbe.de</url>
|
||||||
|
|
||||||
<name>tgp</name>
|
<name>irt-parser</name>
|
||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
<license>
|
<license>
|
||||||
|
@ -35,12 +35,12 @@
|
||||||
|
|
||||||
<scm>
|
<scm>
|
||||||
<connection>
|
<connection>
|
||||||
scm:git:git@github.com:Software-Ingenieur-Begerad/ifleett.git
|
scm:git:git@git.wtf-eg.de/dancesWithCycles/irt-parser
|
||||||
</connection>
|
</connection>
|
||||||
<developerConnection>
|
<developerConnection>
|
||||||
scm:git:ssh://github.com:Software-Ingenieur-Begerad/ifleett.git
|
scm:git:ssh://git.wtf-eg.de/dancesWithCycles/irt-parser
|
||||||
</developerConnection>
|
</developerConnection>
|
||||||
<url>https://github.com/Software-Ingenieur-Begerad/ifleett/tree/main
|
<url>https://git.wtf-eg.de/dancesWithCycles/irt-parser/src/branch/main
|
||||||
</url>
|
</url>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class Comm {
|
||||||
|
private final Header header;
|
||||||
|
private final Telegr telegr;
|
||||||
|
public Comm(Header header, Telegr telegr) {
|
||||||
|
this.header = header;
|
||||||
|
this.telegr = telegr;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Communication{" + "header=" + header + ", telegr=" + telegr + '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public Header getHeader() {
|
||||||
|
return header;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Telegr getTelegr() {
|
||||||
|
return telegr;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Comm that = (Comm) o;
|
||||||
|
return header.equals(that.header) && telegr.equals(that.telegr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(header, telegr);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,81 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class Enty {
|
||||||
|
private final String date;
|
||||||
|
private final String time;
|
||||||
|
private final String logLevel;
|
||||||
|
private final String addressPartA;
|
||||||
|
private final String addressPartB;
|
||||||
|
private final String peer;
|
||||||
|
private final String addressNext;
|
||||||
|
private final String direction;
|
||||||
|
private final Comm comm;
|
||||||
|
|
||||||
|
public Enty(String date, String time, String logLevel, String addressPartA, String addressPartB, String peer, String addressNext, String direction, Comm comm) {
|
||||||
|
this.date = date;
|
||||||
|
this.time = time;
|
||||||
|
this.logLevel = logLevel;
|
||||||
|
this.addressPartA = addressPartA;
|
||||||
|
this.addressPartB = addressPartB;
|
||||||
|
this.peer = peer;
|
||||||
|
this.addressNext = addressNext;
|
||||||
|
this.direction = direction;
|
||||||
|
this.comm = comm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTime() {
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Entity{" + "date='" + date + '\'' + ", time='" + time + '\'' + ", logLevel='" + logLevel + '\'' + ", addressPartA='" + addressPartA + '\'' + ", addressPartB='" + addressPartB + '\'' + ", peer='" + peer + '\'' + ", addressNext='" + addressNext + '\'' + ", direction='" + direction + '\'' + ", comm=" + comm + '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLogLevel() {
|
||||||
|
return logLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAddressPartA() {
|
||||||
|
return addressPartA;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAddressPartB() {
|
||||||
|
return addressPartB;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPeer() {
|
||||||
|
return peer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAddressNext() {
|
||||||
|
return addressNext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDirection() {
|
||||||
|
return direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Comm getComm() {
|
||||||
|
return comm;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Enty entity = (Enty) o;
|
||||||
|
return date.equals(entity.date) && time.equals(entity.time) && logLevel.equals(entity.logLevel) && addressPartA.equals(entity.addressPartA) && addressPartB.equals(entity.addressPartB) && peer.equals(entity.peer) && addressNext.equals(entity.addressNext) && direction.equals(entity.direction) && comm.equals(entity.comm);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(date, time, logLevel, addressPartA, addressPartB, peer, addressNext, direction, comm);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class TcLctMsg extends TelegrCntnt{
|
||||||
|
|
||||||
|
private final Position position;
|
||||||
|
private final String driverNumber;
|
||||||
|
private final Trip trip;
|
||||||
|
|
||||||
|
public TcLctMsg(final String type, final Position position, final String driverNumber, final Trip trip) {
|
||||||
|
super(type);
|
||||||
|
this.position = position;
|
||||||
|
this.driverNumber = driverNumber;
|
||||||
|
this.trip = trip;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "LocationMsg{" + "position=" + position + ", driverNumber='" + driverNumber + '\'' + ", trip=" + trip + '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDriverNumber() {
|
||||||
|
return driverNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Trip getTrip() {
|
||||||
|
return trip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Position getPosition() {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
TcLctMsg that = (TcLctMsg) o;
|
||||||
|
return position.equals(that.position) && driverNumber.equals(that.driverNumber) && trip.equals(that.trip);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(position, driverNumber, trip);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class Telegr {
|
||||||
|
|
||||||
|
private final TelegramHdr teleHeader;
|
||||||
|
private final TelegrCntnt telegrCntnt;
|
||||||
|
|
||||||
|
public Telegr(TelegramHdr teleHeader, TelegrCntnt telegrCntnt) {
|
||||||
|
this.teleHeader = teleHeader;
|
||||||
|
this.telegrCntnt = telegrCntnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TelegramHdr getTeleHeader() {
|
||||||
|
return teleHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TelegrCntnt getTelegrCntnt() {
|
||||||
|
return telegrCntnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Telegram{" + "teleHeader=" + teleHeader + ", telegrCntnt=" + telegrCntnt + '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Telegr telegram = (Telegr) o;
|
||||||
|
return teleHeader.equals(telegram.teleHeader) && telegrCntnt.equals(telegram.telegrCntnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(teleHeader, telegrCntnt);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package de.swingbe.ifleet.model;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class TelegrCntnt {
|
||||||
|
private final static Logger LOG = LoggerFactory.getLogger(TelegrCntnt.class);
|
||||||
|
private final String type;
|
||||||
|
|
||||||
|
public TelegrCntnt(String type) {
|
||||||
|
LOG.debug("parse() type: " + type);
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package de.swingbe.ifleet.parser;
|
||||||
|
|
||||||
|
import de.swingbe.ifleet.model.Comm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a {@link Comm}.
|
||||||
|
*/
|
||||||
|
interface CommParser {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new {@link Comm} that holds the parses fields.
|
||||||
|
*
|
||||||
|
* @param input the {@link String} to be parsed
|
||||||
|
* @return the parsed {@link Comm}
|
||||||
|
*/
|
||||||
|
Comm parse(final String input);
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package de.swingbe.ifleet.parser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory for creating instances of {@link CommParser}.
|
||||||
|
*/
|
||||||
|
class CommParserFactory {
|
||||||
|
|
||||||
|
private CommParserFactory() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance of {@link CommParser}.
|
||||||
|
*
|
||||||
|
* @return the new instance
|
||||||
|
*/
|
||||||
|
public static CommParser createCommParser() {
|
||||||
|
return new CommParserImpl();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package de.swingbe.ifleet.parser;
|
||||||
|
|
||||||
|
import de.swingbe.ifleet.model.Comm;
|
||||||
|
import de.swingbe.ifleet.model.Header;
|
||||||
|
import de.swingbe.ifleet.model.Telegr;
|
||||||
|
import de.swingbe.ifleet.utils.TelegramUtils;
|
||||||
|
|
||||||
|
class CommParserImpl implements CommParser {
|
||||||
|
|
||||||
|
CommParserImpl() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Comm parse(final String input) {
|
||||||
|
|
||||||
|
Header header = null;
|
||||||
|
Telegr telegr = null;
|
||||||
|
|
||||||
|
if (input.contains("<")) {
|
||||||
|
|
||||||
|
String inputSup = input.substring(input.indexOf("<") + 1,
|
||||||
|
input.lastIndexOf(">"));
|
||||||
|
|
||||||
|
//parse Header
|
||||||
|
header = HeaderParserFactory.createHeaderParser().parse(input);
|
||||||
|
|
||||||
|
//parse Telegram
|
||||||
|
String inputSupPop = TelegramUtils.popField(inputSup, 4);
|
||||||
|
telegr = TelegrParserFactory.createTelegrParser().parse(inputSupPop);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Comm(header, telegr);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package de.swingbe.ifleet.parser;
|
||||||
|
|
||||||
|
import de.swingbe.ifleet.model.Enty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses an {@link Enty}.
|
||||||
|
*/
|
||||||
|
public interface EntyParser {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new {@link Enty} that holds the parses fields.
|
||||||
|
*
|
||||||
|
* @param input the {@link String} to be parsed
|
||||||
|
* @return the parsed {@link Enty}
|
||||||
|
*/
|
||||||
|
Enty parse(final String input);
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package de.swingbe.ifleet.parser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory for creating instances of {@link EntyParser}.
|
||||||
|
*/
|
||||||
|
public class EntyParserFactory {
|
||||||
|
|
||||||
|
private EntyParserFactory() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance of {@link EntyParser}.
|
||||||
|
*
|
||||||
|
* @return the new instance
|
||||||
|
*/
|
||||||
|
public static EntyParser createEntyParser() {
|
||||||
|
return new EntyParserImpl();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
package de.swingbe.ifleet.parser;
|
||||||
|
|
||||||
|
import de.swingbe.ifleet.model.Comm;
|
||||||
|
import de.swingbe.ifleet.model.Enty;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
class EntyParserImpl implements EntyParser {
|
||||||
|
|
||||||
|
EntyParserImpl() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Enty parse(final String input) {
|
||||||
|
|
||||||
|
String[] splits = input.split(" ");
|
||||||
|
|
||||||
|
//parse date
|
||||||
|
String date = "";
|
||||||
|
if (splits.length > 0) {
|
||||||
|
date = splits[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
//parse time
|
||||||
|
String time = "";
|
||||||
|
if (splits.length > 1) {
|
||||||
|
time = splits[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
//parse log level
|
||||||
|
String logLevel = "";
|
||||||
|
if (splits.length > 2) {
|
||||||
|
logLevel = splits[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
//index three is empty
|
||||||
|
|
||||||
|
//parse addressPartA
|
||||||
|
String addressPartA = "";
|
||||||
|
if (splits.length > 4) {
|
||||||
|
addressPartA = splits[4].replaceFirst("\\[", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
//parse addressPartB
|
||||||
|
String addressPartB = "";
|
||||||
|
if (splits.length > 5) {
|
||||||
|
addressPartB = splits[5].replaceFirst("/", "")
|
||||||
|
.replaceFirst("\\]", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
//parse peer
|
||||||
|
String peer = "";
|
||||||
|
if (splits.length > 6) {
|
||||||
|
peer = splits[6];
|
||||||
|
}
|
||||||
|
//parse address next
|
||||||
|
String addressNext = "";
|
||||||
|
if (splits.length > 7) {
|
||||||
|
addressNext = splits[7].replaceFirst("/", "");
|
||||||
|
}
|
||||||
|
//parse direction
|
||||||
|
String direction = "";
|
||||||
|
if (splits.length > 8) {
|
||||||
|
direction = splits[8];
|
||||||
|
}
|
||||||
|
//parse comm
|
||||||
|
Comm comm = null;
|
||||||
|
if (splits.length > 9) {
|
||||||
|
String[] splitsSup = Arrays.copyOfRange(splits, 9, splits.length);
|
||||||
|
String inputSup = String.join(" ", splitsSup);
|
||||||
|
comm = CommParserFactory.createCommParser().parse(inputSup);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Enty(date, time, logLevel, addressPartA, addressPartB, peer,
|
||||||
|
addressNext, direction, comm);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package de.swingbe.ifleet.parser;
|
||||||
|
|
||||||
|
import de.swingbe.ifleet.model.TcLctMsg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a {@link TcLctMsg}.
|
||||||
|
*/
|
||||||
|
interface LctMsgParser {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new {@link TcLctMsg} that holds the parses fields.
|
||||||
|
*
|
||||||
|
* @param type the telegram type
|
||||||
|
* @param input the {@link String} to be parsed
|
||||||
|
* @return the parsed {@link TcLctMsg}
|
||||||
|
*/
|
||||||
|
TcLctMsg parse(final String type, final String input);
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package de.swingbe.ifleet.parser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory for creating instances of {@link LctMsgParser}.
|
||||||
|
*/
|
||||||
|
class LctMsgParserFactory {
|
||||||
|
|
||||||
|
private LctMsgParserFactory() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance of {@link LctMsgParser}.
|
||||||
|
*
|
||||||
|
* @return the new instance
|
||||||
|
*/
|
||||||
|
public static LctMsgParser createLctMsgParer() {
|
||||||
|
return new LctMsgParserImpl();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package de.swingbe.ifleet.parser;
|
||||||
|
|
||||||
|
import de.swingbe.ifleet.model.TcLctMsg;
|
||||||
|
import de.swingbe.ifleet.model.Position;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import static de.swingbe.ifleet.model.Position.POSITION_FIELD_NO;
|
||||||
|
import static de.swingbe.ifleet.utils.TelegramUtils.popField;
|
||||||
|
|
||||||
|
class LctMsgParserImpl implements LctMsgParser {
|
||||||
|
private final static Logger LOG = LoggerFactory.getLogger(LctMsgParserImpl.class);
|
||||||
|
|
||||||
|
public final static int DRIVER_NO_FIELD_NO = 1;
|
||||||
|
|
||||||
|
public TcLctMsg parse(final String type, final String input) {
|
||||||
|
LOG.debug("parse() type: " + type);
|
||||||
|
|
||||||
|
//parse position
|
||||||
|
Position position = PositionParserFactory.createPositionParser().parse(input);
|
||||||
|
|
||||||
|
//parse driver number
|
||||||
|
String inputNew = popField(input, POSITION_FIELD_NO);
|
||||||
|
|
||||||
|
String[] splits = inputNew.split("#");
|
||||||
|
|
||||||
|
String driverNo = "";
|
||||||
|
if (splits.length > 0) {
|
||||||
|
driverNo = splits[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
//parse trip
|
||||||
|
inputNew = popField(inputNew, DRIVER_NO_FIELD_NO);
|
||||||
|
return new TcLctMsg(type, position, driverNo, TripParserFactory.createTripParser().parse(inputNew));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package de.swingbe.ifleet.parser;
|
||||||
|
|
||||||
|
import de.swingbe.ifleet.model.Telegr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a {@link Telegr}.
|
||||||
|
*/
|
||||||
|
interface TelegrParser {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new {@link Telegr} that holds the parses fields.
|
||||||
|
*
|
||||||
|
* @param input the {@link String} to be parsed
|
||||||
|
* @return the parsed {@link Telegr
|
||||||
|
*/
|
||||||
|
Telegr parse(final String input);
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package de.swingbe.ifleet.parser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory for creating instances of {@link TelegrParser}.
|
||||||
|
*/
|
||||||
|
class TelegrParserFactory {
|
||||||
|
|
||||||
|
private TelegrParserFactory() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance of {@link TelegrParser}.
|
||||||
|
*
|
||||||
|
* @return the new instance
|
||||||
|
*/
|
||||||
|
public static TelegrParser createTelegrParser() {
|
||||||
|
return new TelegrParserImpl();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package de.swingbe.ifleet.parser;
|
||||||
|
|
||||||
|
import de.swingbe.ifleet.model.Telegr;
|
||||||
|
import de.swingbe.ifleet.model.TelegrCntnt;
|
||||||
|
import de.swingbe.ifleet.model.TelegramHdr;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import static de.swingbe.ifleet.model.TelegramHdr.TELEGRAM_HDR_FIELD_NO;
|
||||||
|
import static de.swingbe.ifleet.utils.TelegramUtils.popField;
|
||||||
|
|
||||||
|
class TelegrParserImpl implements TelegrParser {
|
||||||
|
private final static Logger LOG = LoggerFactory.getLogger(TelegrParserImpl.class);
|
||||||
|
|
||||||
|
TelegrParserImpl() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Telegr parse(final String input) {
|
||||||
|
|
||||||
|
TelegramHdr teleHeader = TelegramHdrParserFactory.createTelegramHdrParser().parse(input);
|
||||||
|
final String type = teleHeader.getTeleType();
|
||||||
|
LOG.debug("parse() teleHeader.getTeleType(): " + type);
|
||||||
|
|
||||||
|
String inputNew = popField(input, TELEGRAM_HDR_FIELD_NO);
|
||||||
|
|
||||||
|
TelegrCntnt telegrCntnt = null;
|
||||||
|
switch (type){
|
||||||
|
case "1":
|
||||||
|
default:
|
||||||
|
telegrCntnt = LctMsgParserFactory.createLctMsgParer().parse(type,inputNew);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return new Telegr(teleHeader, telegrCntnt);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,94 @@
|
||||||
|
package de.swingbe.ifleet;
|
||||||
|
|
||||||
|
import de.swingbe.ifleet.model.*;
|
||||||
|
import de.swingbe.ifleet.parser.EntyParserFactory;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test telegram parsing.
|
||||||
|
* <p>
|
||||||
|
* Note that this class is package-private, so that the client can not use it.
|
||||||
|
*/
|
||||||
|
class TelegrParserImplTest {
|
||||||
|
|
||||||
|
private final Enty eSendLctMsg = new Enty("2021-11-30", "11:24:13,438", "INFO", "BON", "195.30.103.89:58713", "(NpmTCPAcceptedChannel)", "(195.30.103.89:58713)", "sent", new Comm(new Header(new Sender("I", "WOL/234"), new Receiver("B", "")), new Telegr(new TelegramHdr("1", "1.8", "1"), new TcLctMsg("1", new Position("1501303H", "280", "87263783", "529019052", "0", "420", "162"), "29", new Trip("711", "1101", "1101099", "", "452", "0", "2", "2")))));
|
||||||
|
private final String strSendLctMsg = "2021-11-30 11:24:13,438 INFO [BON /195.30.103.89:58713] (NpmTCPAcceptedChannel) (/195.30.103.89:58713) sent <I#WOL/234#B##1#1.8#1#1501303H#280#87263783#529019052#0#420#162#29#711#1101#1101099##452#0#2#37500#0#6.>";
|
||||||
|
private final Enty eFromStrSendLctMsg = EntyParserFactory.createEntyParser().parse(strSendLctMsg);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getDate() {
|
||||||
|
assertThat(eFromStrSendLctMsg.getDate()).isEqualTo(eSendLctMsg.getDate());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getTime() {
|
||||||
|
assertThat(eFromStrSendLctMsg.getTime()).isEqualTo(eSendLctMsg.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getLogLevel() {
|
||||||
|
assertThat(eFromStrSendLctMsg.getLogLevel()).isEqualTo(eSendLctMsg.getLogLevel());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getAddressPartA() {
|
||||||
|
assertThat(eFromStrSendLctMsg.getAddressPartA()).isEqualTo(eSendLctMsg.getAddressPartA());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void parse() {
|
||||||
|
assertThat(eFromStrSendLctMsg).isEqualTo(eSendLctMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getAddressPartB() {
|
||||||
|
assertThat(eFromStrSendLctMsg.getAddressPartB()).isEqualTo(eSendLctMsg.getAddressPartB());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getPeer() {
|
||||||
|
assertThat(eFromStrSendLctMsg.getPeer()).isEqualTo(eSendLctMsg.getPeer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getAddressNext() {
|
||||||
|
assertThat(eFromStrSendLctMsg.getAddressNext()).isEqualTo(eSendLctMsg.getAddressNext());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getDirection() {
|
||||||
|
assertThat(eFromStrSendLctMsg.getDirection()).isEqualTo(eSendLctMsg.getDirection());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getSenderTyp() {
|
||||||
|
assertThat(eFromStrSendLctMsg.getComm().getHeader().getSender().getType()).isEqualTo(eSendLctMsg.getComm().getHeader().getSender().getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getSenderId() {
|
||||||
|
assertThat(eFromStrSendLctMsg.getComm().getHeader().getSender().getId()).isEqualTo(eSendLctMsg.getComm().getHeader().getSender().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getReceiverTyp() {
|
||||||
|
assertThat(eFromStrSendLctMsg.getComm().getHeader().getReceiver().getType()).isEqualTo(eSendLctMsg.getComm().getHeader().getReceiver().getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getReceiverId() {
|
||||||
|
assertThat(eFromStrSendLctMsg.getComm().getHeader().getReceiver().getId()).isEqualTo(eSendLctMsg.getComm().getHeader().getReceiver().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getTeleType() {
|
||||||
|
assertThat(eFromStrSendLctMsg.getComm().getTelegr().getTeleHeader().getTeleType()).isEqualTo(eSendLctMsg.getComm().getTelegr().getTeleHeader().getTeleType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getTeleId() {
|
||||||
|
assertThat(eFromStrSendLctMsg.getComm().getTelegr().getTeleHeader().getTeleId()).isEqualTo(eSendLctMsg.getComm().getTelegr().getTeleHeader().getTeleId());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue