Re-enabled source id allocator check.
Re-enabled rotation of map at startup. Changed race.xml schema so that yacht elements aren't required inside the participants element. #story[1185]
This commit is contained in:
@@ -21,7 +21,7 @@ import shared.model.Constants;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
@@ -92,14 +92,16 @@ public class Event {
|
||||
|
||||
//Read XML files.
|
||||
try {
|
||||
//this.raceXML = RaceXMLCreator.alterRaceToWind(raceXMLFile, 90);
|
||||
this.raceXML = XMLReader.readXMLFileToString(raceXMLFile, StandardCharsets.UTF_8);
|
||||
|
||||
//this.raceXML = XMLReader.readXMLFileToString(raceXMLFile, StandardCharsets.UTF_8);
|
||||
this.raceXML = Event.setRaceXMLAtCurrentTimeToNow(XMLReader.readXMLFileToString(raceXMLFile, StandardCharsets.UTF_8));
|
||||
|
||||
this.raceXML = RaceXMLCreator.alterRaceToWind(this.raceXML, XMLFileType.Contents, 300);
|
||||
|
||||
this.boatXML = XMLReader.readXMLFileToString(boatsXMLFile, StandardCharsets.UTF_8);
|
||||
this.regattaXML = XMLReader.readXMLFileToString(regattaXMLFile, StandardCharsets.UTF_8);
|
||||
|
||||
} catch (XMLReaderException e) {
|
||||
} catch (XMLReaderException | InvalidRaceDataException e) {
|
||||
throw new EventConstructionException("Could not read XML files.", e);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,10 +36,10 @@ public class SourceIdAllocator {
|
||||
*/
|
||||
public synchronized int allocateSourceID() throws SourceIDAllocationException {
|
||||
|
||||
/*if (!((mockRace.getRaceStatusEnum() == RaceStatusEnum.PRESTART)
|
||||
if (!((mockRace.getRaceStatusEnum() == RaceStatusEnum.PRESTART)
|
||||
|| (mockRace.getRaceStatusEnum() == RaceStatusEnum.WARNING))) {
|
||||
throw new SourceIDAllocationException("Could not allocate a source ID. Can only allocate during pre-start period. It is currently: " + mockRace.getRaceStatusEnum());
|
||||
}*///TEMP DISABLED FOR TESTING - RE-ENABLE THIS
|
||||
}
|
||||
|
||||
List<Integer> allocatedIDs = mockRace.getRaceDataSource().getParticipants();
|
||||
List<Integer> allIDs = new ArrayList<>(mockRace.getBoatDataSource().getBoats().keySet());
|
||||
|
||||
@@ -26,6 +26,7 @@ import javax.xml.validation.SchemaFactory;
|
||||
import javax.xml.validation.Validator;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URL;
|
||||
@@ -64,33 +65,37 @@ public class RaceXMLCreator {
|
||||
|
||||
/**
|
||||
* Rotates the race in a specified direction.
|
||||
* @param s xml file name
|
||||
* @param s xml file name or contents.
|
||||
* @param fileType Whether s is a file name or contents.
|
||||
* @param degrees degrees to rotate
|
||||
* @return the new xml file as a string
|
||||
* @throws XMLReaderException if the xml is not readable
|
||||
* @throws InvalidRaceDataException if the race is invalid
|
||||
* @throws JAXBException if the Race class cannot be parsed into a xml.
|
||||
* @throws IOException if the schema file cannot be found
|
||||
* @throws SAXException error in schema file
|
||||
* @throws ParserConfigurationException error in parsing the schema file
|
||||
*/
|
||||
public static String alterRaceToWind(String s, double degrees) throws XMLReaderException, InvalidRaceDataException, JAXBException, IOException, SAXException, ParserConfigurationException {
|
||||
RaceXMLReader reader = new RaceXMLReader(s, XMLFileType.ResourcePath);
|
||||
public static String alterRaceToWind(String s, XMLFileType fileType, double degrees) throws XMLReaderException, InvalidRaceDataException {
|
||||
|
||||
XMLRace race = XMLUtilities.xmlToClass(
|
||||
RaceXMLCreator.class.getClassLoader().getResourceAsStream(s),
|
||||
RaceXMLCreator.class.getClassLoader().getResource("mock/mockXML/schema/raceSchema.xsd"),
|
||||
XMLRace.class);
|
||||
RaceXMLReader reader = new RaceXMLReader(s, fileType);
|
||||
|
||||
setRaceXMLAtCurrentTimeToNow(race);
|
||||
try {
|
||||
|
||||
double raceOriginalBearing = getLineAngle(getLeewardGate(reader).getMark1Position(), getWindwardGate(reader).getMark1Position());
|
||||
XMLRace race = XMLUtilities.xmlToClass(
|
||||
s,
|
||||
RaceXMLCreator.class.getClassLoader().getResource("mock/mockXML/schema/raceSchema.xsd"),
|
||||
XMLRace.class);
|
||||
|
||||
double degreesToRotate = degrees - raceOriginalBearing;
|
||||
setRaceXMLAtCurrentTimeToNow(race);
|
||||
|
||||
alterRaceRotation(race, degreesToRotate);
|
||||
double raceOriginalBearing = getLineAngle(getLeewardGate(reader).getMark1Position(), getWindwardGate(reader).getMark1Position());
|
||||
|
||||
return XMLUtilities.classToXML(race);
|
||||
double degreesToRotate = degrees - raceOriginalBearing;
|
||||
|
||||
alterRaceRotation(race, degreesToRotate);
|
||||
|
||||
return XMLUtilities.classToXML(race);
|
||||
|
||||
} catch (ParserConfigurationException | IOException | SAXException | JAXBException e) {
|
||||
throw new InvalidRaceDataException("Could not parse or marshall race data file.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,7 +50,7 @@ import javax.xml.bind.annotation.XmlType;
|
||||
})
|
||||
public class XMLParticipants {
|
||||
|
||||
@XmlElement(name = "Yacht", required = true)
|
||||
@XmlElement(name = "Yacht", required = false)
|
||||
protected List<XMLYacht> yacht;
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,7 +49,7 @@ public class XMLUtilities {
|
||||
return xmlToClass(document, schemaURL, c);
|
||||
}
|
||||
|
||||
public static Object xmlToClass(String xml, URL schemaURL, Class c) throws ParserConfigurationException, IOException, SAXException, JAXBException {
|
||||
public static <T> T xmlToClass(String xml, URL schemaURL, Class<T> c) throws ParserConfigurationException, IOException, SAXException, JAXBException {
|
||||
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Document document = parser.parse(new InputSource(new ByteArrayInputStream(xml.getBytes("utf-8"))));
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<xs:element name="Participants">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="Yacht" maxOccurs="unbounded">
|
||||
<xs:element name="Yacht" maxOccurs="unbounded" minOccurs="0">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="SourceID" type="xs:int" use="required"/>
|
||||
<xs:attribute name="Entry" type="xs:string"/>
|
||||
@@ -77,4 +77,4 @@
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
</xs:schema>
|
||||
|
||||
Reference in New Issue
Block a user