
at.gridgears.held.internal.parser.LocationParser Maven / Gradle / Ivy
package at.gridgears.held.internal.parser;
import at.gridgears.held.AmlData;
import at.gridgears.held.Location;
import at.gridgears.schemas.held.*;
import org.apache.commons.lang3.mutable.MutableObject;
import javax.annotation.Nullable;
import javax.xml.datatype.XMLGregorianCalendar;
import java.time.Instant;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import static at.gridgears.held.internal.parser.ParseUtils.getValue;
import static at.gridgears.held.internal.parser.ParseUtils.toInstant;
final class LocationParser {
private final AmlDataParser amlDataParser = new AmlDataParser();
List parse(LocationResponseType locationResponseType) {
MutableObject timestamp = new MutableObject<>();
MutableObject amlData = new MutableObject<>();
List result = new LinkedList<>();
ParseUtils.getValue(locationResponseType.getAny(), Presence.class)
.map(Presence::getTuple)
.map(ParseUtils::first)
.map(storeTimestamp(timestamp))
.map(storeAml(amlData))
.map(Tuple::getStatus)
.map(Status::getAny)
.map(ParseUtils::first)
.map(LocationParser::getGeopriv)
.ifPresent(geopriv -> result.addAll(parseLocation(geopriv, timestamp.getValue(), amlData.getValue())));
return result;
}
private List parseLocation(Geopriv geopriv, Instant timestamp, AmlData amlData) {
List result = new LinkedList<>();
LocInfoType locationInfo = geopriv.getLocationInfo();
if (locationInfo != null) {
result.addAll(parseLocations(locationInfo.getAny(), timestamp, amlData));
}
return result;
}
private List parseLocations(List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy