feat: enable empty telegrams

This commit is contained in:
dancingCycle 2022-01-24 06:21:21 -05:00
parent ce3f0d21b7
commit c1a847c700
15 changed files with 78 additions and 93 deletions

View File

@ -7,7 +7,7 @@
<groupId>de.swingbe.ifleet</groupId> <groupId>de.swingbe.ifleet</groupId>
<artifactId>tgp</artifactId> <artifactId>tgp</artifactId>
<version>0.0.4</version> <version>0.0.6</version>
<description> <description>
This project is a library for parsing ifleet telegrams in Java. This project is a library for parsing ifleet telegrams in Java.

View File

@ -20,10 +20,12 @@ public class Communication {
@Override @Override
public String toString() { public String toString() {
return "Communication{" + String ccString = "Communication{";
"header=" + header + ccString += header != null ? "header=" + header : "";
", telegram=" + telegram + ccString += telegram != null ? "telegram=" + telegram : "";
'}'; ccString += '}';
return ccString;
} }
} }

View File

@ -61,17 +61,18 @@ public class Entity {
@Override @Override
public String toString() { public String toString() {
return "Entity{" + String eString = "Entity{";
"date='" + date + '\'' + eString += date != null ? "date='" + date + '\'' : "";
", time='" + time + '\'' + eString += time != null ? ", time='" + time + '\'' : "";
", logLevel='" + logLevel + '\'' + eString += logLevel != null ? ", logLevel='" + logLevel + '\'' : "";
", addressPartA='" + addressPartA + '\'' + eString += addressPartA != null ? ", addressPartA='" + addressPartA + '\'' : "";
", addressPartB='" + addressPartB + '\'' + eString += addressPartB != null ? ", addressPartB='" + addressPartB + '\'' : "";
", peer='" + peer + '\'' + eString += peer != null ? ", peer='" + peer + '\'' : "";
", addressNext='" + addressNext + '\'' + eString += addressNext != null ? ", addressNext='" + addressNext + '\'' : "";
", direction='" + direction + '\'' + eString += direction != null ? ", direction='" + direction + '\'' : "";
", cc=" + cc + eString += cc != null ? ", cc=" + cc : "";
'}'; eString += '}';
return eString;
} }
} }

View File

@ -20,9 +20,10 @@ public class Header {
@Override @Override
public String toString() { public String toString() {
return "Header{" + String hString = "Header{";
"sender=" + sender + hString += sender != null ? "sender=" + sender : "";
", receiver=" + receiver + hString += receiver != null ? ", receiver=" + receiver : "";
'}'; hString += '}';
return hString;
} }
} }

View File

@ -14,8 +14,9 @@ public class LocationMessage {
@Override @Override
public String toString() { public String toString() {
return "LocationMessage{" + String positionString = "LocationMessage{";
"position=" + position + positionString += position != null ? "position=" + position : "";
'}'; positionString += '}';
return positionString;
} }
} }

View File

@ -14,8 +14,9 @@ public class Receiver {
@Override @Override
public String toString() { public String toString() {
return "Receiver{" + String rString = "Receiver{";
"receiver='" + receiver + '\'' + rString += receiver != null ? "receiver='" + receiver + '\'' : "";
'}'; rString += '}';
return rString;
} }
} }

View File

@ -14,8 +14,9 @@ public class Sender {
@Override @Override
public String toString() { public String toString() {
return "Sender{" + String sString = "Sender{";
"sender='" + sender + '\'' + sString += sender != null ? "sender='" + sender + '\'' : "";
'}'; sString += '}';
return sString;
} }
} }

View File

@ -20,9 +20,10 @@ public class Telegram {
@Override @Override
public String toString() { public String toString() {
return "Telegram{" + String telegramString = "Telegram{";
"teleHeader=" + teleHeader + telegramString += teleHeader != null ? "teleHeader=" + teleHeader : "";
", locationMessage=" + locationMessage + telegramString += locationMessage != null ? ", locationMessage=" + locationMessage : "";
'}'; telegramString += '}';
return telegramString;
} }
} }

View File

@ -40,7 +40,6 @@ class ComParserImpl implements ComParser {
@Override @Override
public Communication parse(final String input) { public Communication parse(final String input) {
Communication com = null;
Header header = null; Header header = null;
Telegram telegram = null; Telegram telegram = null;
@ -59,12 +58,6 @@ class ComParserImpl implements ComParser {
LOG.warn("telegram NOT included"); LOG.warn("telegram NOT included");
} }
//create Communication return new Communication(header, telegram);
if (telegram != null && header != null) {
com = new Communication(header, telegram);
} else {
LOG.warn("telegram NOT available");
}
return com;
} }
} }

View File

@ -13,7 +13,6 @@ class EntityParserImpl implements EntityParser {
@Override @Override
public Entity parse(final String input) { public Entity parse(final String input) {
Entity entity = null;
String[] splits = input.split(" "); String[] splits = input.split(" ");
//parse date //parse date
@ -39,13 +38,14 @@ class EntityParserImpl implements EntityParser {
//parse addressPartA //parse addressPartA
String addressPartA = null; String addressPartA = null;
if (splits.length > 4) { if (splits.length > 4) {
addressPartA = splits[4]; addressPartA = splits[4].replaceFirst("\\[", "");
} }
//parse addressPartB //parse addressPartB
String addressPartB = null; String addressPartB = null;
if (splits.length > 5) { if (splits.length > 5) {
addressPartB = splits[5]; addressPartB = splits[5].replaceFirst("/", "")
.replaceFirst("\\]", "");
} }
//parse peer //parse peer
@ -56,7 +56,7 @@ class EntityParserImpl implements EntityParser {
//parse address next //parse address next
String addressNext = null; String addressNext = null;
if (splits.length > 7) { if (splits.length > 7) {
addressNext = splits[7]; addressNext = splits[7].replaceFirst("/", "");
} }
//parse direction //parse direction
String direction = null; String direction = null;
@ -71,10 +71,7 @@ class EntityParserImpl implements EntityParser {
communication = ComParserFactory.createComParser().parse(inputSup); communication = ComParserFactory.createComParser().parse(inputSup);
} }
if (date != null && time != null && logLevel != null && addressPartA != null && addressPartB != null && peer != null && addressNext != null && direction != null && communication != null) { return new Entity(date, time, logLevel, addressPartA, addressPartB, peer,
entity = new Entity(date, time, logLevel, addressPartA, addressPartB, peer, addressNext, direction, communication); addressNext, direction, communication);
}
return entity;
} }
} }

View File

@ -13,20 +13,14 @@ class HeaderParserImpl implements HeaderParser {
public Header parse(final String input) { public Header parse(final String input) {
Header header = null;
Sender sender; Sender sender;
Receiver receiver;
//parse Sender //parse Sender
sender = SenderParserFactory.createSenderParser().parse(input); sender = SenderParserFactory.createSenderParser().parse(input);
//parse Receiver //parse Receiver
String inputPop = popFieldFromCom(input, 2); String inputPop = popFieldFromCom(input, 2);
receiver = ReceiverParserFactory.createReceiverParser().parse(inputPop);
if (sender != null && receiver != null) { return new Header(sender, ReceiverParserFactory.createReceiverParser().parse(inputPop));
header = new Header(sender, receiver);
}
return header;
} }
} }

View File

@ -1,20 +1,10 @@
package de.swingbe.ifleet.parser; package de.swingbe.ifleet.parser;
import de.swingbe.ifleet.model.LocationMessage; import de.swingbe.ifleet.model.LocationMessage;
import de.swingbe.ifleet.model.Position;
class LocationMsgParserImpl implements LocationMsgParser { class LocationMsgParserImpl implements LocationMsgParser {
public LocationMessage parse(String input) { public LocationMessage parse(String input) {
return new LocationMessage(PositionParserFactory.createPositionParser().parse(input));
LocationMessage locationMessage = null;
Position position = PositionParserFactory.createPositionParser().parse(input);
if (position != null) {
locationMessage = new LocationMessage(position);
}
return locationMessage;
} }
} }

View File

@ -21,41 +21,47 @@ public class PositionParserImpl implements PositionParser {
//parse NetPoint //parse NetPoint
//parse RelPosition //parse RelPosition
//parse lat //parse lat
String lat = null; String lat = "";
if (splits.length > 2) { if (splits.length > 2) {
lat = splits[2]; lat = splits[2];
} else {
LOG.warn("lat unavailable");
} }
//parse lon //parse lon
String lon = null; String lon = "";
if (splits.length > 3) { if (splits.length > 3) {
lon = splits[3]; lon = splits[3];
} else {
LOG.warn("lon unavailable");
} }
//parse vel //parse vel
String vel = null; String vel = "";
if (splits.length > 4) { if (splits.length > 4) {
vel = splits[4]; vel = splits[4];
} else {
LOG.warn("vel unavailable");
} }
//parse hdg //parse hdg
String hdg = null; String hdg = "";
if (splits.length > 5) { if (splits.length > 5) {
hdg = splits[5]; hdg = splits[5];
} else {
LOG.warn("hdg unavailable");
} }
if (lat != null && lon != null && vel != null && hdg != null) { boolean latIsNumeric = isNumeric(lat);
boolean latIsNumeric = isNumeric(lat); boolean lonIsNumeric = isNumeric(lon);
boolean lonIsNumeric = isNumeric(lon); boolean velIsNumeric = isNumeric(vel);
boolean velIsNumeric = isNumeric(vel); boolean hdgIsNumeric = isNumeric(hdg);
boolean hdgIsNumeric = isNumeric(hdg);
if (latIsNumeric && lonIsNumeric && velIsNumeric && hdgIsNumeric) { if (latIsNumeric && lonIsNumeric && velIsNumeric && hdgIsNumeric) {
try { try {
position = new Position(Long.parseLong(lat), Long.parseLong(lon), Integer.parseInt(vel), Integer.parseInt(hdg)); position = new Position(Long.parseLong(lat), Long.parseLong(lon), Integer.parseInt(vel), Integer.parseInt(hdg));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
LOG.error("parsing position failed, message: " + e.getMessage() + ", trace: " + Arrays.toString(e.getStackTrace())); LOG.error("parsing position failed, message: " + e.getMessage() + ", trace: " + Arrays.toString(e.getStackTrace()));
}
} }
} }
return position; return position;

View File

@ -47,9 +47,12 @@ class TelegramHdrParserImpl implements TelegramHdrParser {
if (typeIsNumeric && idIsNumeric) { if (typeIsNumeric && idIsNumeric) {
try { try {
teleHeader = new TelegramHdr(Integer.parseInt(type), version, Integer.parseInt(id)); teleHeader = new TelegramHdr(Integer.parseInt(type), version,
Integer.parseInt(id));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
LOG.error("parsing telegram header failed, message: " + e.getMessage() + ", trace: " + Arrays.toString(e.getStackTrace())); LOG.error("parsing telegram header failed, message: "
+ e.getMessage() + ", trace: "
+ Arrays.toString(e.getStackTrace()));
} }
} }
} }

View File

@ -1,6 +1,5 @@
package de.swingbe.ifleet.parser; package de.swingbe.ifleet.parser;
import de.swingbe.ifleet.model.LocationMessage;
import de.swingbe.ifleet.model.Telegram; import de.swingbe.ifleet.model.Telegram;
import de.swingbe.ifleet.model.TelegramHdr; import de.swingbe.ifleet.model.TelegramHdr;
@ -13,17 +12,12 @@ class TelegramParserImpl implements TelegramParser {
public Telegram parse(final String input) { public Telegram parse(final String input) {
Telegram telegram = null;
TelegramHdr teleHeader = TelegramHdrParserFactory.createTelegramHdrParser().parse(input); TelegramHdr teleHeader = TelegramHdrParserFactory.createTelegramHdrParser().parse(input);
String inputNew = popFieldFromCom(input, 3); String inputNew = popFieldFromCom(input, 3);
LocationMessage locationMessage = LocationMsgParserFactory.createLocationMsgParer().parse(inputNew); return new Telegram(teleHeader,
LocationMsgParserFactory.createLocationMsgParer().parse(inputNew));
if (teleHeader != null && locationMessage != null) {
telegram = new Telegram(teleHeader, locationMessage);
}
return telegram;
} }
} }