|
|
|
|
@ -4,12 +4,7 @@ import mock.dataInput.PolarParser;
|
|
|
|
|
import mock.exceptions.EventConstructionException;
|
|
|
|
|
import mock.model.*;
|
|
|
|
|
import mock.model.commandFactory.CompositeCommand;
|
|
|
|
|
import mock.model.MockRace;
|
|
|
|
|
import mock.model.Polars;
|
|
|
|
|
import mock.xml.RaceXMLCreator;
|
|
|
|
|
import mock.model.RaceLogic;
|
|
|
|
|
import mock.model.SourceIdAllocator;
|
|
|
|
|
import mock.model.commandFactory.CompositeCommand;
|
|
|
|
|
import network.Messages.LatestMessages;
|
|
|
|
|
import org.xml.sax.SAXException;
|
|
|
|
|
import shared.dataInput.*;
|
|
|
|
|
@ -20,13 +15,11 @@ import shared.exceptions.InvalidRegattaDataException;
|
|
|
|
|
import shared.exceptions.XMLReaderException;
|
|
|
|
|
import shared.model.Bearing;
|
|
|
|
|
import shared.model.Constants;
|
|
|
|
|
import shared.xml.Race.XMLRace;
|
|
|
|
|
import shared.xml.XMLUtilities;
|
|
|
|
|
|
|
|
|
|
import javax.xml.bind.JAXBException;
|
|
|
|
|
import javax.xml.parsers.ParserConfigurationException;
|
|
|
|
|
import javax.xml.transform.TransformerException;
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.net.UnknownHostException;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
@ -93,55 +86,32 @@ public class Event {
|
|
|
|
|
|
|
|
|
|
//Read XML files.
|
|
|
|
|
try {
|
|
|
|
|
this.raceXML = RaceXMLCreator.alterRaceToWind("mock/mockXML/raceSchemaTest.xml", 90);
|
|
|
|
|
this.raceXML = RaceXMLCreator.alterRaceToWind(raceXMLFile, 90);
|
|
|
|
|
this.boatXML = XMLReader.readXMLFileToString(boatsXMLFile, StandardCharsets.UTF_8);
|
|
|
|
|
this.regattaXML = XMLReader.readXMLFileToString(regattaXMLFile, StandardCharsets.UTF_8);
|
|
|
|
|
|
|
|
|
|
} catch (XMLReaderException e) {
|
|
|
|
|
throw new EventConstructionException("Could not read XML files.", e);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (ParserConfigurationException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (SAXException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (InvalidRaceDataException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (JAXBException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.xmlFileType = XMLFileType.Contents;
|
|
|
|
|
|
|
|
|
|
this.boatPolars = PolarParser.parse("mock/polars/acc_polars.csv");
|
|
|
|
|
|
|
|
|
|
this.latestMessages = new LatestMessages();
|
|
|
|
|
this.connectionAcceptor = new ConnectionAcceptor(latestMessages);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Event getEvent() {
|
|
|
|
|
return theEvent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getAddress() throws UnknownHostException {
|
|
|
|
|
return connectionAcceptor.getAddress();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getPort() {
|
|
|
|
|
return connectionAcceptor.getServerPort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sends the initial race data and then begins race simulation.
|
|
|
|
|
* @throws InvalidRaceDataException Thrown if the race xml file cannot be parsed.
|
|
|
|
|
* @throws XMLReaderException Thrown if any of the xml files cannot be parsed.
|
|
|
|
|
* @throws InvalidBoatDataException Thrown if the boat xml file cannot be parsed.
|
|
|
|
|
* @throws InvalidRegattaDataException Thrown if the regatta xml file cannot be parsed.
|
|
|
|
|
* @throws ParserConfigurationException Error in parsing XML
|
|
|
|
|
* @throws JAXBException error in mapping the xml to a schema
|
|
|
|
|
* @throws SAXException error in reading the schema
|
|
|
|
|
* @throws IOException error in finding the schema
|
|
|
|
|
*/
|
|
|
|
|
public void start() throws InvalidRaceDataException, XMLReaderException, InvalidBoatDataException, InvalidRegattaDataException, ParserConfigurationException, JAXBException, SAXException, IOException {
|
|
|
|
|
new Thread(connectionAcceptor, "Event.Start()->ConnectionAcceptor thread").start();
|
|
|
|
|
|
|
|
|
|
sendXMLs();
|
|
|
|
|
|
|
|
|
|
//Parse the XML files into data sources.
|
|
|
|
|
try {
|
|
|
|
|
this.raceDataSource = new RaceXMLReader(this.raceXML, this.xmlFileType);
|
|
|
|
|
XMLRace race = (XMLRace) XMLUtilities.xmlToClass(raceXML,
|
|
|
|
|
RaceXMLCreator.class.getClassLoader().getResource("mock/mockXML/schema/raceSchema.xsd"),
|
|
|
|
|
XMLRace.class);
|
|
|
|
|
this.boatDataSource = new BoatXMLReader(this.boatXML, this.xmlFileType);
|
|
|
|
|
this.regattaDataSource = new RegattaXMLReader(this.regattaXML, this.xmlFileType);
|
|
|
|
|
|
|
|
|
|
@ -215,21 +185,4 @@ public class Event {
|
|
|
|
|
|
|
|
|
|
connectionAcceptor.setBoatsXml(boatXML);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//The start time is current time + 4 minutes. prestart is 3 minutes, and we add another minute.
|
|
|
|
|
long millisecondsToAdd = Constants.RacePreStartTime + Duration.ofMinutes(1).toMillis();
|
|
|
|
|
long secondsToAdd = millisecondsToAdd / 1000;
|
|
|
|
|
//Scale the time using our time scalar.
|
|
|
|
|
secondsToAdd = secondsToAdd / Constants.RaceTimeScale;
|
|
|
|
|
|
|
|
|
|
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
|
|
|
|
|
ZonedDateTime creationTime = ZonedDateTime.now();
|
|
|
|
|
raceXML = raceXML.replace("CREATION_TIME", dateFormat.format(creationTime));
|
|
|
|
|
|
|
|
|
|
raceXML = raceXML.replace("START_TIME", dateFormat.format(creationTime.plusSeconds(secondsToAdd)));
|
|
|
|
|
|
|
|
|
|
return raceXML;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|