adding shit

This commit is contained in:
2020-06-16 11:20:35 +02:00
parent a1f69cd581
commit ca70d5ce0a
14 changed files with 1605 additions and 138 deletions
+146 -137
View File
@@ -1,139 +1,148 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>fun.manuel</groupId>
<artifactId>eddn-fleetcarier-radar</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus-plugin.version>1.5.0.Final</quarkus-plugin.version>
<quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>1.5.0.Final</quarkus.platform.version>
<surefire-plugin.version>2.22.1</surefire-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>${quarkus.platform.artifact-id}</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-h2</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-qute</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-reactive-messaging</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-config-yaml</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>fun.manuel</groupId>
<artifactId>eddn-fleetcarier-radar</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus-plugin.version>1.5.0.Final</quarkus-plugin.version>
<quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>1.5.0.Final</quarkus.platform.version>
<surefire-plugin.version>2.22.1</surefire-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>${quarkus.platform.artifact-id}</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-h2</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-qute</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-reactive-messaging</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-config-yaml</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.zeromq/jeromq -->
<dependency>
<groupId>org.zeromq</groupId>
<artifactId>jeromq</artifactId>
<version>0.5.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>
</project>
@@ -0,0 +1,106 @@
package fun.manuel;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.transaction.Transactional;
import org.eclipse.microprofile.reactive.messaging.Channel;
import org.eclipse.microprofile.reactive.messaging.Emitter;
import org.eclipse.microprofile.reactive.messaging.Incoming;
import org.eclipse.microprofile.reactive.messaging.Outgoing;
import io.smallrye.reactive.messaging.annotations.Broadcast;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fun.manuel.data.Carrier;
import fun.manuel.data.CarrierAnalysesContext;
import fun.manuel.data.EddnJournal;
import fun.manuel.data.Message;
import fun.manuel.data.Message.Event;
import fun.manuel.service.CarrierService;
import io.agroal.api.AgroalDataSource;
import io.quarkus.runtime.Startup;
@Startup
@ApplicationScoped
public class CarrierAnalyser {
@Inject
CarrierService service;
@Inject
@Broadcast
@Channel("carrier-context") Emitter<CarrierAnalysesContext> contextEmitter;
@Inject
@Broadcast
@Channel("carrier-update1") Emitter<CarrierAnalysesContext> updateEmitter1;
@Inject
@Broadcast
@Channel("carrier-update2") Emitter<CarrierAnalysesContext> updateEmitter2;
Logger logger = LoggerFactory.getLogger("Carrier Eventanalyser");
@Incoming(value = "eddn-carrier")
public void toContext(EddnJournal journal) {
Event ev = journal.getMessage().getEvent();
Carrier freshCarrier = convertToCarrier(journal);
Carrier storedCarrier = service.getOrNull(freshCarrier.getId());
//logger.info("Carrier Event: " + freshCarrier.getId() + " | " + ev.toString());
contextEmitter.send(new CarrierAnalysesContext(freshCarrier, storedCarrier, journal));
}
@Incoming(value = "carrier-context")
@Broadcast
@Outgoing("carrier-update")
public CarrierAnalysesContext filterUpdate(CarrierAnalysesContext context) {
//logger.info(context.toString());
if(context.getStoredCarrier()==null) {
//new carrier
updateEmitter1.send(context);
updateEmitter2.send(context);
return context;
}
if(!context.getFreshCarrier().equals(context.getStoredCarrier())) {
Carrier fresh=context.getFreshCarrier();
Carrier stored=context.getStoredCarrier();
if(!fresh.getSystem().equals(stored.getSystem())) {
//new system
updateEmitter1.send(context);
updateEmitter2.send(context);
return context;
}
if(!(fresh.getBody().equals("")&&!stored.equals(""))) {
//adding body,
updateEmitter1.send(context);
updateEmitter2.send(context);
return context;
}
}
return null;
}
@Incoming("carrier-update1")
@Transactional
public void updateCarrier(CarrierAnalysesContext context) {
Carrier tostore=service.getOrCreate(context.getFreshCarrier());
tostore.setBody(context.getFreshCarrier().getBody());
tostore.setSystem(context.getFreshCarrier().getSystem());
service.save(tostore);
}
private Carrier convertToCarrier(EddnJournal journal) {
Event ev = journal.getMessage().getEvent();
Message msg = journal.getMessage();
boolean process = false;
String name = (String) msg.getAdditionalProperties().get("StationName");
String body = (String) msg.getAdditionalProperties().getOrDefault("Body", "");
String system = msg.getStarSystem();
return new Carrier(system, body, name);
}
}
+12
View File
@@ -0,0 +1,12 @@
package fun.manuel;
import io.quarkus.runtime.Quarkus;
import io.quarkus.runtime.annotations.QuarkusMain;
@QuarkusMain
public class Core {
public static void main(String ... args) {
// System.out.println("Running main method");
Quarkus.run(args);
}
}
+111
View File
@@ -0,0 +1,111 @@
package fun.manuel.data;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Carrier {
@Id
private String id;
private String name;
private String System;
private String Body;
public Carrier() {
}
public String getSystem() {
return System;
}
public void setSystem(String system) {
System = system;
}
public String getBody() {
return Body;
}
public void setBody(String body) {
Body = body;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Carrier(String system, String body, String id) {
super();
System = system;
Body = body;
this.id = id;
}
@Override
public String toString() {
return "Carrier [System=" + System + ", Body=" + Body + ", id=" + id + "]";
}
@Override
public Object clone() {
// TODO Auto-generated method stub
try {
return super.clone();
} catch (CloneNotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((Body == null) ? 0 : Body.hashCode());
result = prime * result + ((System == null) ? 0 : System.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Carrier other = (Carrier) obj;
if (Body == null) {
if (other.Body != null)
return false;
} else if (!Body.equals(other.Body))
return false;
if (System == null) {
if (other.System != null)
return false;
} else if (!System.equals(other.System))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
}
@@ -0,0 +1,38 @@
package fun.manuel.data;
public class CarrierAnalysesContext {
private Carrier freshCarrier;
private Carrier storedCarrier;
private EddnJournal entry;
public CarrierAnalysesContext(Carrier freshCarrier, Carrier storedCarrier, EddnJournal entry) {
super();
this.freshCarrier = freshCarrier;
this.storedCarrier = storedCarrier;
this.entry = entry;
}
public Carrier getFreshCarrier() {
return freshCarrier;
}
public void setFreshCarrier(Carrier freshCarrier) {
this.freshCarrier = freshCarrier;
}
public Carrier getStoredCarrier() {
return storedCarrier;
}
public void setStoredCarrier(Carrier storedCarrier) {
this.storedCarrier = storedCarrier;
}
public EddnJournal getEntry() {
return entry;
}
public void setEntry(EddnJournal entry) {
this.entry = entry;
}
@Override
public String toString() {
return "CarrierAnalysesContext [freshCarrier=" + freshCarrier + ", storedCarrier=" + storedCarrier + ", entry="
+ entry + "]";
}
}
@@ -0,0 +1,106 @@
package fun.manuel.data;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"$schemaRef",
"header",
"message"
})
public class EddnJournal {
/**
*
* (Required)
*
*/
@JsonProperty("$schemaRef")
private String $schemaRef;
/**
*
* (Required)
*
*/
@JsonProperty("header")
private Header header;
/**
* Contains all properties from the listed events in the client's journal minus Localised strings and the properties marked below as 'disallowed'
* (Required)
*
*/
@JsonProperty("message")
@JsonPropertyDescription("Contains all properties from the listed events in the client's journal minus Localised strings and the properties marked below as 'disallowed'")
private Message message;
/**
*
* (Required)
*
*/
@JsonProperty("$schemaRef")
public String get$schemaRef() {
return $schemaRef;
}
/**
*
* (Required)
*
*/
@JsonProperty("$schemaRef")
public void set$schemaRef(String $schemaRef) {
this.$schemaRef = $schemaRef;
}
/**
*
* (Required)
*
*/
@JsonProperty("header")
public Header getHeader() {
return header;
}
/**
*
* (Required)
*
*/
@JsonProperty("header")
public void setHeader(Header header) {
this.header = header;
}
/**
* Contains all properties from the listed events in the client's journal minus Localised strings and the properties marked below as 'disallowed'
* (Required)
*
*/
@JsonProperty("message")
public Message getMessage() {
return message;
}
/**
* Contains all properties from the listed events in the client's journal minus Localised strings and the properties marked below as 'disallowed'
* (Required)
*
*/
@JsonProperty("message")
public void setMessage(Message message) {
this.message = message;
}
@Override
public String toString() {
return "EddnJournal [$schemaRef=" + $schemaRef + ", header=" + header + ", message=" + message + "]";
}
}
@@ -0,0 +1,90 @@
package fun.manuel.data;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"HappiestSystem",
"HomeSystem",
"MyReputation",
"SquadronFaction"
})
public class Faction {
@JsonProperty("HappiestSystem")
private Object happiestSystem;
@JsonProperty("HomeSystem")
private Object homeSystem;
@JsonProperty("MyReputation")
private Object myReputation;
@JsonProperty("SquadronFaction")
private Object squadronFaction;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
@JsonProperty("HappiestSystem")
public Object getHappiestSystem() {
return happiestSystem;
}
@JsonProperty("HappiestSystem")
public void setHappiestSystem(Object happiestSystem) {
this.happiestSystem = happiestSystem;
}
@JsonProperty("HomeSystem")
public Object getHomeSystem() {
return homeSystem;
}
@JsonProperty("HomeSystem")
public void setHomeSystem(Object homeSystem) {
this.homeSystem = homeSystem;
}
@JsonProperty("MyReputation")
public Object getMyReputation() {
return myReputation;
}
@JsonProperty("MyReputation")
public void setMyReputation(Object myReputation) {
this.myReputation = myReputation;
}
@JsonProperty("SquadronFaction")
public Object getSquadronFaction() {
return squadronFaction;
}
@JsonProperty("SquadronFaction")
public void setSquadronFaction(Object squadronFaction) {
this.squadronFaction = squadronFaction;
}
@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
@Override
public String toString() {
return "Faction [happiestSystem=" + happiestSystem + ", homeSystem=" + homeSystem + ", myReputation="
+ myReputation + ", squadronFaction=" + squadronFaction + ", additionalProperties="
+ additionalProperties + "]";
}
}
+150
View File
@@ -0,0 +1,150 @@
package fun.manuel.data;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"uploaderID",
"softwareName",
"softwareVersion",
"gatewayTimestamp"
})
public class Header {
/**
*
* (Required)
*
*/
@JsonProperty("uploaderID")
private String uploaderID;
/**
*
* (Required)
*
*/
@JsonProperty("softwareName")
private String softwareName;
/**
*
* (Required)
*
*/
@JsonProperty("softwareVersion")
private String softwareVersion;
/**
* Timestamp upon receipt at the gateway. If present, this property will be overwritten by the gateway; submitters are not intended to populate this property.
*
*/
@JsonProperty("gatewayTimestamp")
@JsonPropertyDescription("Timestamp upon receipt at the gateway. If present, this property will be overwritten by the gateway; submitters are not intended to populate this property.")
private Date gatewayTimestamp;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
/**
*
* (Required)
*
*/
@JsonProperty("uploaderID")
public String getUploaderID() {
return uploaderID;
}
/**
*
* (Required)
*
*/
@JsonProperty("uploaderID")
public void setUploaderID(String uploaderID) {
this.uploaderID = uploaderID;
}
/**
*
* (Required)
*
*/
@JsonProperty("softwareName")
public String getSoftwareName() {
return softwareName;
}
/**
*
* (Required)
*
*/
@JsonProperty("softwareName")
public void setSoftwareName(String softwareName) {
this.softwareName = softwareName;
}
/**
*
* (Required)
*
*/
@JsonProperty("softwareVersion")
public String getSoftwareVersion() {
return softwareVersion;
}
/**
*
* (Required)
*
*/
@JsonProperty("softwareVersion")
public void setSoftwareVersion(String softwareVersion) {
this.softwareVersion = softwareVersion;
}
/**
* Timestamp upon receipt at the gateway. If present, this property will be overwritten by the gateway; submitters are not intended to populate this property.
*
*/
@JsonProperty("gatewayTimestamp")
public Date getGatewayTimestamp() {
return gatewayTimestamp;
}
/**
* Timestamp upon receipt at the gateway. If present, this property will be overwritten by the gateway; submitters are not intended to populate this property.
*
*/
@JsonProperty("gatewayTimestamp")
public void setGatewayTimestamp(Date gatewayTimestamp) {
this.gatewayTimestamp = gatewayTimestamp;
}
@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
@Override
public String toString() {
return "Header [uploaderID=" + uploaderID + ", softwareName=" + softwareName + ", softwareVersion="
+ softwareVersion + ", gatewayTimestamp=" + gatewayTimestamp + ", additionalProperties="
+ additionalProperties + "]";
}
}
+379
View File
@@ -0,0 +1,379 @@
package fun.manuel.data;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonValue;
/**
* Contains all properties from the listed events in the client's journal minus Localised strings and the properties marked below as 'disallowed'
*
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"timestamp",
"event",
"StarSystem",
"StarPos",
"SystemAddress",
"Factions",
"ActiveFine",
"CockpitBreach",
"BoostUsed",
"FuelLevel",
"FuelUsed",
"JumpDist",
"Latitude",
"Longitude",
"Wanted"
})
public class Message {
/**
*
* (Required)
*
*/
@JsonProperty("timestamp")
private Date timestamp;
/**
*
* (Required)
*
*/
@JsonProperty("event")
private Message.Event event;
/**
* Must be added by the sender if not present in the journal event
* (Required)
*
*/
@JsonProperty("StarSystem")
@JsonPropertyDescription("Must be added by the sender if not present in the journal event")
private String starSystem;
/**
* Must be added by the sender if not present in the journal event
* (Required)
*
*/
@JsonProperty("StarPos")
@JsonPropertyDescription("Must be added by the sender if not present in the journal event")
private List<Double> starPos = null;
/**
* Should be added by the sender if not present in the journal event
* (Required)
*
*/
@JsonProperty("SystemAddress")
@JsonPropertyDescription("Should be added by the sender if not present in the journal event")
private Long systemAddress;
/**
* Present in Location, FSDJump and CarrierJump messages
*
*/
@JsonProperty("Factions")
@JsonPropertyDescription("Present in Location, FSDJump and CarrierJump messages")
private List<Faction> factions = null;
@JsonProperty("ActiveFine")
private Object activeFine;
@JsonProperty("CockpitBreach")
private Object cockpitBreach;
@JsonProperty("BoostUsed")
private Object boostUsed;
@JsonProperty("FuelLevel")
private Object fuelLevel;
@JsonProperty("FuelUsed")
private Object fuelUsed;
@JsonProperty("JumpDist")
private Object jumpDist;
@JsonProperty("Latitude")
private Object latitude;
@JsonProperty("Longitude")
private Object longitude;
@JsonProperty("Wanted")
private Object wanted;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
/**
*
* (Required)
*
*/
@JsonProperty("timestamp")
public Date getTimestamp() {
return timestamp;
}
/**
*
* (Required)
*
*/
@JsonProperty("timestamp")
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
/**
*
* (Required)
*
*/
@JsonProperty("event")
public Message.Event getEvent() {
return event;
}
/**
*
* (Required)
*
*/
@JsonProperty("event")
public void setEvent(Message.Event event) {
this.event = event;
}
/**
* Must be added by the sender if not present in the journal event
* (Required)
*
*/
@JsonProperty("StarSystem")
public String getStarSystem() {
return starSystem;
}
/**
* Must be added by the sender if not present in the journal event
* (Required)
*
*/
@JsonProperty("StarSystem")
public void setStarSystem(String starSystem) {
this.starSystem = starSystem;
}
/**
* Must be added by the sender if not present in the journal event
* (Required)
*
*/
@JsonProperty("StarPos")
public List<Double> getStarPos() {
return starPos;
}
/**
* Must be added by the sender if not present in the journal event
* (Required)
*
*/
@JsonProperty("StarPos")
public void setStarPos(List<Double> starPos) {
this.starPos = starPos;
}
/**
* Should be added by the sender if not present in the journal event
* (Required)
*
*/
@JsonProperty("SystemAddress")
public Long getSystemAddress() {
return systemAddress;
}
/**
* Should be added by the sender if not present in the journal event
* (Required)
*
*/
@JsonProperty("SystemAddress")
public void setSystemAddress(Long systemAddress) {
this.systemAddress = systemAddress;
}
/**
* Present in Location, FSDJump and CarrierJump messages
*
*/
@JsonProperty("Factions")
public List<Faction> getFactions() {
return factions;
}
/**
* Present in Location, FSDJump and CarrierJump messages
*
*/
@JsonProperty("Factions")
public void setFactions(List<Faction> factions) {
this.factions = factions;
}
@JsonProperty("ActiveFine")
public Object getActiveFine() {
return activeFine;
}
@JsonProperty("ActiveFine")
public void setActiveFine(Object activeFine) {
this.activeFine = activeFine;
}
@JsonProperty("CockpitBreach")
public Object getCockpitBreach() {
return cockpitBreach;
}
@JsonProperty("CockpitBreach")
public void setCockpitBreach(Object cockpitBreach) {
this.cockpitBreach = cockpitBreach;
}
@JsonProperty("BoostUsed")
public Object getBoostUsed() {
return boostUsed;
}
@JsonProperty("BoostUsed")
public void setBoostUsed(Object boostUsed) {
this.boostUsed = boostUsed;
}
@JsonProperty("FuelLevel")
public Object getFuelLevel() {
return fuelLevel;
}
@JsonProperty("FuelLevel")
public void setFuelLevel(Object fuelLevel) {
this.fuelLevel = fuelLevel;
}
@JsonProperty("FuelUsed")
public Object getFuelUsed() {
return fuelUsed;
}
@JsonProperty("FuelUsed")
public void setFuelUsed(Object fuelUsed) {
this.fuelUsed = fuelUsed;
}
@JsonProperty("JumpDist")
public Object getJumpDist() {
return jumpDist;
}
@JsonProperty("JumpDist")
public void setJumpDist(Object jumpDist) {
this.jumpDist = jumpDist;
}
@JsonProperty("Latitude")
public Object getLatitude() {
return latitude;
}
@JsonProperty("Latitude")
public void setLatitude(Object latitude) {
this.latitude = latitude;
}
@JsonProperty("Longitude")
public Object getLongitude() {
return longitude;
}
@JsonProperty("Longitude")
public void setLongitude(Object longitude) {
this.longitude = longitude;
}
@JsonProperty("Wanted")
public Object getWanted() {
return wanted;
}
@JsonProperty("Wanted")
public void setWanted(Object wanted) {
this.wanted = wanted;
}
@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
public enum Event {
DOCKED("Docked"),
FSD_JUMP("FSDJump"),
SCAN("Scan"),
LOCATION("Location"),
SAA_SIGNALS_FOUND("SAASignalsFound"),
CARRIER_JUMP("CarrierJump");
private final String value;
private final static Map<String, Message.Event> CONSTANTS = new HashMap<String, Message.Event>();
static {
for (Message.Event c: values()) {
CONSTANTS.put(c.value, c);
}
}
private Event(String value) {
this.value = value;
}
@Override
public String toString() {
return this.value;
}
@JsonValue
public String value() {
return this.value;
}
@JsonCreator
public static Message.Event fromValue(String value) {
Message.Event constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
} else {
return constant;
}
}
}
@Override
public String toString() {
return "Message [timestamp=" + timestamp + ", event=" + event + ", starSystem=" + starSystem + ", starPos="
+ starPos + ", systemAddress=" + systemAddress + ", factions=" + factions + ", activeFine=" + activeFine
+ ", cockpitBreach=" + cockpitBreach + ", boostUsed=" + boostUsed + ", fuelLevel=" + fuelLevel
+ ", fuelUsed=" + fuelUsed + ", jumpDist=" + jumpDist + ", latitude=" + latitude + ", longitude="
+ longitude + ", wanted=" + wanted + ", additionalProperties=" + additionalProperties + "]";
}
}
@@ -0,0 +1,39 @@
package fun.manuel.filter;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import org.eclipse.microprofile.reactive.messaging.Channel;
import org.eclipse.microprofile.reactive.messaging.Emitter;
import org.eclipse.microprofile.reactive.messaging.Incoming;
import org.eclipse.microprofile.reactive.messaging.Outgoing;
import fun.manuel.data.EddnJournal;
import fun.manuel.data.Message;
import fun.manuel.data.Message.Event;
import io.smallrye.reactive.messaging.annotations.Broadcast;
@ApplicationScoped
public class CarrierFilter {
@Inject
@Channel(value = "eddn-carrier")
@Broadcast
Emitter<EddnJournal> filtered;
@Incoming(value = "eddn-full")
public void filterCarrierOnlyEvents(EddnJournal ju) {
Event ev = ju.getMessage().getEvent();
Message msg = ju.getMessage();
if (ev == Event.CARRIER_JUMP) {
filtered.send(ju);
}
if (msg.getAdditionalProperties().containsKey("StationType")) {
if (msg.getAdditionalProperties().get("StationType").equals("FleetCarrier")) {
filtered.send(ju);
}
}
}
}
@@ -0,0 +1,28 @@
package fun.manuel.handler;
import javax.enterprise.context.ApplicationScoped;
import org.eclipse.microprofile.reactive.messaging.Incoming;
import fun.manuel.data.CarrierAnalysesContext;
import fun.manuel.data.Message.Event;
@ApplicationScoped
public class PrintToConsole {
@Incoming("carrier-update2")
public void printUpdate(CarrierAnalysesContext context) {
System.out.println("Carrier Event: " + context.getFreshCarrier().getId() + " | " + context.getEntry().getMessage().getEvent().toString());
if(context.getStoredCarrier()!=null) {
if (context.getEntry().getMessage().getEvent() == Event.CARRIER_JUMP) {
System.out.println("\t" + context.getStoredCarrier().getSystem() + " -> " + context.getFreshCarrier().getSystem());
}else {
System.out.println("\tUpdated: " + context.getFreshCarrier().toString());
}
}else {
System.out.println("\tRegisterd: " + context.getFreshCarrier().toString());
}
}
}
@@ -0,0 +1,72 @@
package fun.manuel.service;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.NonUniqueResultException;
import javax.persistence.Query;
import javax.transaction.Transactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fun.manuel.data.Carrier;
@ApplicationScoped
public class CarrierService {
@Inject
EntityManager em;
Logger log = LoggerFactory.getLogger("Carrier DB Service");
public Carrier getCarrier(String id) throws NoResultException, NonUniqueResultException {
String query = "select c from Carrier c where c.id=:id";
return (Carrier) em.createQuery(query).setParameter("id", id).getSingleResult();
}
public Carrier getOrCreate(Carrier carrier) {
Carrier car = carrier;
try {
car = getCarrier(carrier.getId());
} catch (Exception e) {
}
return car;
}
public Carrier getOrNull(String id) {
Carrier car = null;
try {
car = getCarrier(id);
} catch (Exception e) {
}
return car;
}
public boolean exsists(String id) {
String query = "select c from Carrier c where c.id=:id";
return em.createQuery(query).setParameter("id", id).getResultList().size() != 0;
}
@Transactional
public void save(Carrier car) {
org.hibernate.Session session=em.unwrap(org.hibernate.Session.class);
session.saveOrUpdate(car);
session.close();
em.flush();
}
@PostConstruct
public void startupMessage() {
String query="select count(c) from Carrier c";
long size=(long) em.createQuery(query).getSingleResult();
log.info(size+" Carriers loaded");
}
}
+324
View File
@@ -0,0 +1,324 @@
package org.eddn;
import org.eclipse.microprofile.reactive.messaging.Channel;
import org.eclipse.microprofile.reactive.messaging.Emitter;
import org.zeromq.ZContext;
import org.zeromq.ZMQ;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import fun.manuel.data.Carrier;
import fun.manuel.data.EddnJournal;
import fun.manuel.data.Message;
import fun.manuel.data.Message.Event;
import io.quarkus.runtime.Startup;
import io.smallrye.reactive.messaging.annotations.Broadcast;
import java.awt.AWTException;
import java.awt.Image;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.TrayIcon.MessageType;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
/**
* Subscribe to zmq relay from EDDN
*/
@ApplicationScoped
@Startup
public class EddnPump extends Thread {
public static final String SCHEMA_KEY = "$schemaRef";
public static final String RELAY = "tcp://eddn.edcd.io:9500";
public static final ArrayList<EddnJournal> list = new ArrayList<EddnJournal>();
public static final File dbfile = new File("stream.json");
public static FileWriter writer = null;
public static ExecutorService computeservice = Executors.newCachedThreadPool();
public static HashMap<String, Carrier> carrierMap = new HashMap<String, Carrier>();
public TrayIcon trayIcon;
public boolean init = true;
@Inject
@Channel(value = "eddn-full")
@Broadcast
Emitter<EddnJournal> fulllog;
public void msg(String msg) {
ObjectMapper mapper = new ObjectMapper();
try {
EddnJournal journal = mapper.readValue(msg, EddnJournal.class);
fulllog.send(journal).toCompletableFuture().join();
} catch (JsonMappingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void run() {
pump();
}
public synchronized void pump() {
ZContext ctx = new ZContext();
ZMQ.Socket client = ctx.createSocket(ZMQ.SUB);
client.subscribe("".getBytes());
client.setReceiveTimeOut(30000);
client.connect(RELAY);
System.out.println("EDDN Relay connected");
ZMQ.Poller poller = ctx.createPoller(2);
poller.register(client, ZMQ.Poller.POLLIN);
byte[] output = new byte[256 * 1024];
while (true) {
int poll = poller.poll(10);
if (poll == ZMQ.Poller.POLLIN) {
ZMQ.PollItem item = poller.getItem(poll);
if (poller.pollin(0)) {
byte[] recv = client.recv(ZMQ.NOBLOCK);
if (recv.length > 0) {
// decompress
Inflater inflater = new Inflater();
inflater.setInput(recv);
try {
int outlen = inflater.inflate(output);
String outputString = new String(output, 0, outlen, "UTF-8");
// outputString contains a json message
if (outputString.contains(SCHEMA_KEY)) {
msg(outputString);
}
} catch (DataFormatException | IOException e) {
e.printStackTrace();
}
}
}
}
}
}
public Runnable analyse(EddnJournal journal) {
Runnable analyse = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
getCarrierLocation(journal).run();
}
};
return analyse;
}
private Runnable getCarrierLocation(EddnJournal journal) {
return new Runnable() {
@Override
public void run() {
try {
Event ev = journal.getMessage().getEvent();
Message msg = journal.getMessage();
boolean process = false;
if (ev == Event.CARRIER_JUMP) {
process = true;
}
if (msg.getAdditionalProperties().containsKey("StationType")) {
if (msg.getAdditionalProperties().get("StationType").equals("FleetCarrier")) {
process = true;
}
}
if (!process) {
return;
}
String name = (String) msg.getAdditionalProperties().get("StationName");
String body = (String) msg.getAdditionalProperties().getOrDefault("Body", "");
String system = msg.getStarSystem();
Carrier car = carrierMap.getOrDefault(name, new Carrier(system, body, name));
String prevsystem=car.getSystem();
// Update
car.setSystem(system);
car.setBody(body);
System.out.println("Carrier Event: " + car.getId() + " | " + ev.toString());
Carrier prev = carrierMap.get(name);
if (ev == Event.CARRIER_JUMP) {
System.out.println("\t" + prevsystem + " -> " + car.getSystem());
if (!init) {
//trayIcon.displayMessage("Carrier Jump", prev.getSystem() + " -> " + car.getSystem(),
// MessageType.INFO);
}
}
if(car.getId().equals("V61-W9H")) {
System.out.println("\tFCC Noms Event: " + journal.getMessage().toString());
trayIcon.displayMessage("FCC Noms ALERT","FCC Noms event detected",
MessageType.INFO);
}
if (carrierMap.containsKey(name)) {
if(!car.getSystem().equals(prevsystem)) {
System.out.println("\tUpdated: " + car.toString());
if (prev.getSystem().contains("COL 285 SECTOR XN-D A28-2")) {
if (!init) {
trayIcon.displayMessage("Carrier TARGET ALERT","Carrier Jump to targeted system detected",
MessageType.INFO);
}
System.out.println("\tCarrier Jump from targeted system detected");
}
if (car.getSystem().contains("COL 285 SECTOR XN-D A28-2")) {
if (!init) {
trayIcon.displayMessage("Carrier TARGET ALERT","Carrier Jump to targeted system detected",
MessageType.INFO);
}
System.out.println("\tCarrier Jump to targeted system detected");
}
if (car.getSystem().contains("COL 285 SECTOR CC-K A38-2")) {
if (!init) {
trayIcon.displayMessage("Carrier TARGET ALERT","Carrier Jump to targeted system detected",
MessageType.INFO);
}
System.out.println("\tCarrier Jump to targeted system detected");
}
}
} else {
System.out.println("\tRegisterd: " + car.toString());
}
// Save
carrierMap.put(name, car);
} catch (Exception e) {
// TODO: handle exception
}
}
};
}
private Runnable sayJumpDetected(EddnJournal journal) {
return new Runnable() {
@Override
public void run() {
}
};
}
public static Runnable printCarrierLoc() {
return new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
while (true) {
HashMap<String, Integer> map = new HashMap<String, Integer>();
carrierMap.forEach((name, car) -> {
int temp = map.getOrDefault(car.getSystem(), 0);
temp++;
map.put(car.getSystem(), temp);
});
System.out.println();
System.out.println("====== Carrier Star Map ======");
System.out.println("Total Carrier registerd: " + carrierMap.size());
System.out.println("------------------------------");
LinkedHashMap<String, Integer> mapsort = sortHashMapByValues(map);
mapsort.forEach((systen, carrier) -> {
if (carrier > 2) {
System.out.println(systen);
System.out.println("\t" + carrier);
}
});
try {
System.out.println("==============================");
Thread.sleep(60000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};
}
public static LinkedHashMap<String, Integer> sortHashMapByValues(HashMap<String, Integer> passedMap) {
List<String> mapKeys = new ArrayList<>(passedMap.keySet());
List<Integer> mapValues = new ArrayList<>(passedMap.values());
Collections.sort(mapValues);
Collections.sort(mapKeys);
LinkedHashMap<String, Integer> sortedMap = new LinkedHashMap<>();
Iterator<Integer> valueIt = mapValues.iterator();
while (valueIt.hasNext()) {
int val = valueIt.next();
Iterator<String> keyIt = mapKeys.iterator();
while (keyIt.hasNext()) {
String key = keyIt.next();
int comp1 = passedMap.get(key);
int comp2 = val;
if (comp1 == comp2) {
keyIt.remove();
sortedMap.put(key, val);
break;
}
}
}
return sortedMap;
}
@PostConstruct
private void startup()
throws IOException, InterruptedException, LineUnavailableException, AWTException {
ObjectMapper mapper = new ObjectMapper();
start();
}
}
+4 -1
View File
@@ -1,2 +1,5 @@
# Configuration file
# key = value
# key = value
quarkus.datasource.db-kind=h2
quarkus.datasource.jdbc.url=jdbc:h2:~\\default
quarkus.hibernate-orm.database.generation=create