use of javax.xml.datatype.DatatypeConfigurationException in project OpenOLAT by OpenOLAT.
the class ManifestMetadataBuilder method setOpenOLATMetadataCopiedAt.
public void setOpenOLATMetadataCopiedAt(Date date) {
try {
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
getOpenOLATMetadata(true).setCopiedAt(DatatypeFactory.newInstance().newXMLGregorianCalendar(cal));
} catch (DatatypeConfigurationException e) {
log.error("", e);
}
}
use of javax.xml.datatype.DatatypeConfigurationException in project herd by FINRAOS.
the class ExampleXmlGenerator method processClass.
/**
* Processes a class by returning the "example" instance of the class.
*
* @param clazz the class.
*
* @return the instance of the class.
* @throws MojoExecutionException if any errors were encountered.
*/
private Object processClass(Class<?> clazz) throws MojoExecutionException {
log.debug("Generating example XML for class \"" + clazz.getName() + "\".");
Object instance = null;
try {
if (String.class.isAssignableFrom(clazz)) {
instance = "string";
} else if (Integer.class.isAssignableFrom(clazz) || int.class.isAssignableFrom(clazz)) {
instance = 0;
} else if (Long.class.isAssignableFrom(clazz) || long.class.isAssignableFrom(clazz)) {
instance = 0L;
} else if (BigDecimal.class.isAssignableFrom(clazz)) {
instance = BigDecimal.ZERO;
} else if (Double.class.isAssignableFrom(clazz)) {
instance = 0.0;
} else if (XMLGregorianCalendar.class.isAssignableFrom(clazz)) {
DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
instance = datatypeFactory.newXMLGregorianCalendar(EXAMPLE_GREGORIAN_CALENDAR);
} else if (Boolean.class.isAssignableFrom(clazz) || boolean.class.isAssignableFrom(clazz)) {
instance = true;
} else if (clazz.isEnum()) {
// If we have an enum, use the first value if at least one value is present.
Enum<?>[] enums = (Enum<?>[]) clazz.getEnumConstants();
if (enums != null && enums.length > 0) {
instance = enums[0];
}
} else if (clazz.getAnnotation(XmlType.class) != null) {
// We can't instantiate interfaces.
if (!clazz.isInterface()) {
// Create a new instance of the class.
instance = clazz.newInstance();
// loop.
if (!callStack.contains(clazz.getName())) {
// Push this class on the stack to show we've processed this class.
callStack.push(clazz.getName());
// Process all the fields of the class.
for (Field field : clazz.getDeclaredFields()) {
field.setAccessible(true);
processField(instance, field);
}
// Remove this class from the stack since we've finished processing it.
callStack.pop();
}
}
} else {
// Default to string in all other cases.
instance = "string";
}
} catch (IllegalAccessException | InstantiationException | DatatypeConfigurationException e) {
throw new MojoExecutionException("Unable to create example XML for class \"" + clazz.getName() + "\". Reason: " + e.getMessage(), e);
}
return instance;
}
use of javax.xml.datatype.DatatypeConfigurationException in project photon-model by vmware.
the class VimUtils method convertMillisToXmlCalendar.
public static XMLGregorianCalendar convertMillisToXmlCalendar(long timeMillis) {
try {
GregorianCalendar cal = new GregorianCalendar();
cal.setTimeInMillis(timeMillis);
return DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
} catch (DatatypeConfigurationException e) {
throw new AssertionError(e);
}
}
use of javax.xml.datatype.DatatypeConfigurationException in project ili2db by claeis.
the class FromXtfRecordConverter method addAttrValue.
public int addAttrValue(IomObject iomObj, String sqlType, long sqlId, String sqlTableName, PreparedStatement ps, int valuei, AttributeDef attr, ArrayList structQueue) throws SQLException, ConverterException {
if (attr.getExtending() == null) {
String attrName = attr.getName();
if (attr.isDomainBoolean()) {
String value = iomObj.getattrvalue(attrName);
if (value != null) {
if (value.equals("true")) {
geomConv.setBoolean(ps, valuei, true);
} else {
geomConv.setBoolean(ps, valuei, false);
}
} else {
ps.setNull(valuei, Types.BIT);
}
valuei++;
} else if (attr.isDomainIliUuid()) {
String value = iomObj.getattrvalue(attrName);
if (value == null) {
geomConv.setUuidNull(ps, valuei);
} else {
Object toInsertUUID = geomConv.fromIomUuid(value);
ps.setObject(valuei, toInsertUUID);
}
valuei++;
} else if (attr.isDomainIli1Date()) {
String value = iomObj.getattrvalue(attrName);
if (value != null) {
GregorianCalendar gdate = new GregorianCalendar(Integer.parseInt(value.substring(0, 4)), Integer.parseInt(value.substring(4, 6)) - 1, Integer.parseInt(value.substring(6, 8)));
java.sql.Date date = new java.sql.Date(gdate.getTimeInMillis());
geomConv.setDate(ps, valuei, date);
} else {
ps.setNull(valuei, Types.DATE);
}
valuei++;
} else if (attr.isDomainIli2Date()) {
String value = iomObj.getattrvalue(attrName);
if (value != null) {
XMLGregorianCalendar xmldate;
try {
xmldate = javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(value);
} catch (DatatypeConfigurationException e) {
throw new ConverterException(e);
}
java.sql.Date date = new java.sql.Date(xmldate.toGregorianCalendar().getTimeInMillis());
geomConv.setDate(ps, valuei, date);
} else {
ps.setNull(valuei, Types.DATE);
}
valuei++;
} else if (attr.isDomainIli2Time()) {
String value = iomObj.getattrvalue(attrName);
if (value != null) {
XMLGregorianCalendar xmldate;
try {
xmldate = javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(value);
} catch (DatatypeConfigurationException e) {
throw new ConverterException(e);
}
java.sql.Time time = new java.sql.Time(xmldate.toGregorianCalendar().getTimeInMillis());
geomConv.setTime(ps, valuei, time);
} else {
ps.setNull(valuei, Types.TIME);
}
valuei++;
} else if (attr.isDomainIli2DateTime()) {
String value = iomObj.getattrvalue(attrName);
if (value != null) {
XMLGregorianCalendar xmldate;
try {
xmldate = javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(value);
} catch (DatatypeConfigurationException e) {
throw new ConverterException(e);
}
java.sql.Timestamp datetime = new java.sql.Timestamp(xmldate.toGregorianCalendar().getTimeInMillis());
geomConv.setTimestamp(ps, valuei, datetime);
} else {
ps.setNull(valuei, Types.TIMESTAMP);
}
valuei++;
} else {
Type type = attr.getDomainResolvingAliases();
if (type instanceof CompositionType) {
int structc = iomObj.getattrvaluecount(attrName);
if (TrafoConfigNames.CATALOGUE_REF_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.CATALOGUE_REF_TRAFO))) {
IomObject catref = iomObj.getattrobj(attrName, 0);
String refoid = null;
if (catref != null) {
IomObject structvalue = catref.getattrobj(IliNames.CHBASE1_CATALOGUEREFERENCE_REFERENCE, 0);
if (structvalue != null) {
refoid = structvalue.getobjectrefoid();
}
}
if (refoid != null) {
String targetClassName = IliNames.CHBASE1_CATALOGUES_ITEM;
long refsqlId = oidPool.getObjSqlId(targetClassName, refoid);
ps.setLong(valuei, refsqlId);
} else {
ps.setNull(valuei, Types.BIGINT);
}
valuei++;
} else if (TrafoConfigNames.MULTISURFACE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTISURFACE_TRAFO))) {
IomObject iomValue = iomObj.getattrobj(attrName, 0);
IomObject iomMultisurface = null;
MultiSurfaceMapping attrMapping = null;
if (iomValue != null) {
attrMapping = multiSurfaceAttrs.getMapping(attr);
int surfacec = iomValue.getattrvaluecount(attrMapping.getBagOfSurfacesAttrName());
for (int surfacei = 0; surfacei < surfacec; surfacei++) {
IomObject iomSurfaceStructure = iomValue.getattrobj(attrMapping.getBagOfSurfacesAttrName(), surfacei);
IomObject iomPoly = iomSurfaceStructure.getattrobj(attrMapping.getSurfaceAttrName(), 0);
IomObject iomSurface = iomPoly.getattrobj("surface", 0);
if (iomMultisurface == null) {
iomMultisurface = new ch.interlis.iom_j.Iom_jObject("MULTISURFACE", null);
}
iomMultisurface.addattrobj("surface", iomSurface);
}
}
if (iomMultisurface != null) {
AttributeDef surfaceAttr = getMultiSurfaceAttrDef(type, attrMapping);
SurfaceType surface = ((SurfaceType) surfaceAttr.getDomainResolvingAliases());
CoordType coord = (CoordType) surface.getControlPointDomain().getType();
boolean is3D = coord.getDimensions().length == 3;
Object geomObj = geomConv.fromIomMultiSurface(iomMultisurface, getSrsid(surfaceAttr), surface.getLineAttributeStructure() != null, is3D, getP(surface));
ps.setObject(valuei, geomObj);
} else {
geomConv.setSurfaceNull(ps, valuei);
}
valuei++;
} else if (TrafoConfigNames.MULTILINE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINE_TRAFO))) {
IomObject iomValue = iomObj.getattrobj(attrName, 0);
IomObject iomMultiline = null;
MultiLineMapping attrMapping = null;
if (iomValue != null) {
attrMapping = multiLineAttrs.getMapping(attr);
int polylinec = iomValue.getattrvaluecount(attrMapping.getBagOfLinesAttrName());
for (int polylinei = 0; polylinei < polylinec; polylinei++) {
IomObject iomPolylineStructure = iomValue.getattrobj(attrMapping.getBagOfLinesAttrName(), polylinei);
IomObject iomPoly = iomPolylineStructure.getattrobj(attrMapping.getLineAttrName(), 0);
if (iomMultiline == null) {
iomMultiline = new ch.interlis.iom_j.Iom_jObject(Wkb2iox.OBJ_MULTIPOLYLINE, null);
}
iomMultiline.addattrobj(Wkb2iox.ATTR_POLYLINE, iomPoly);
}
}
if (iomMultiline != null) {
AttributeDef polylineAttr = getMultiLineAttrDef(type, attrMapping);
PolylineType line = ((PolylineType) polylineAttr.getDomainResolvingAliases());
CoordType coord = (CoordType) line.getControlPointDomain().getType();
boolean is3D = coord.getDimensions().length == 3;
Object geomObj = geomConv.fromIomMultiPolyline(iomMultiline, getSrsid(polylineAttr), is3D, getP(line));
ps.setObject(valuei, geomObj);
} else {
geomConv.setPolylineNull(ps, valuei);
}
valuei++;
} else if (TrafoConfigNames.MULTIPOINT_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTIPOINT_TRAFO))) {
IomObject iomValue = iomObj.getattrobj(attrName, 0);
IomObject iomMultipoint = null;
MultiPointMapping attrMapping = null;
if (iomValue != null) {
attrMapping = multiPointAttrs.getMapping(attr);
int pointc = iomValue.getattrvaluecount(attrMapping.getBagOfPointsAttrName());
for (int pointi = 0; pointi < pointc; pointi++) {
IomObject iomPointStructure = iomValue.getattrobj(attrMapping.getBagOfPointsAttrName(), pointi);
IomObject iomPoint = iomPointStructure.getattrobj(attrMapping.getPointAttrName(), 0);
if (iomMultipoint == null) {
iomMultipoint = new ch.interlis.iom_j.Iom_jObject(Wkb2iox.OBJ_MULTIPOINT, null);
}
iomMultipoint.addattrobj(Wkb2iox.ATTR_COORD, iomPoint);
}
}
if (iomMultipoint != null) {
AttributeDef coordAttr = getMultiPointAttrDef(type, attrMapping);
CoordType coord = ((CoordType) coordAttr.getDomainResolvingAliases());
boolean is3D = coord.getDimensions().length == 3;
Object geomObj = geomConv.fromIomMultiCoord(iomMultipoint, getSrsid(coordAttr), is3D);
ps.setObject(valuei, geomObj);
} else {
geomConv.setCoordNull(ps, valuei);
}
valuei++;
} else if (TrafoConfigNames.ARRAY_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.ARRAY_TRAFO))) {
int valuec = iomObj.getattrvaluecount(attrName);
String[] iomArray = new String[valuec];
ArrayMapping attrMapping = arrayAttrs.getMapping(attr);
for (int elei = 0; elei < valuec; elei++) {
IomObject iomValue = iomObj.getattrobj(attrName, elei);
String value = iomValue.getattrvalue(attrMapping.getValueAttr().getName());
iomArray[elei] = value;
}
if (iomArray.length > 0) {
Object geomObj = geomConv.fromIomArray(attrMapping.getValueAttr(), iomArray, enumTypes);
ps.setObject(valuei, geomObj);
} else {
geomConv.setArrayNull(ps, valuei);
}
valuei++;
} else if (TrafoConfigNames.MULTILINGUAL_TRAFO_EXPAND.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINGUAL_TRAFO))) {
IomObject iomMulti = iomObj.getattrobj(attrName, 0);
for (String sfx : DbNames.MULTILINGUAL_TXT_COL_SUFFIXS) {
if (iomMulti != null) {
String value = getMultilingualText(iomMulti, sfx);
if (value != null) {
ps.setString(valuei, value);
} else {
ps.setNull(valuei, Types.VARCHAR);
}
} else {
ps.setNull(valuei, Types.VARCHAR);
}
valuei++;
}
} else {
// enqueue struct values
for (int structi = 0; structi < structc; structi++) {
IomObject struct = iomObj.getattrobj(attrName, structi);
String sqlAttrName = ili2sqlName.mapIliAttributeDef(attr, sqlTableName, null);
enqueStructValue(structQueue, sqlId, sqlType, sqlAttrName, struct, structi, attr);
}
}
} else if (type instanceof PolylineType) {
IomObject value = iomObj.getattrobj(attrName, 0);
if (value != null) {
boolean is3D = ((CoordType) ((PolylineType) type).getControlPointDomain().getType()).getDimensions().length == 3;
ps.setObject(valuei, geomConv.fromIomPolyline(value, getSrsid(attr), is3D, getP((PolylineType) type)));
} else {
geomConv.setPolylineNull(ps, valuei);
}
valuei++;
} else if (type instanceof SurfaceOrAreaType) {
if (createItfLineTables) {
} else {
IomObject value = iomObj.getattrobj(attrName, 0);
if (value != null) {
boolean is3D = ((CoordType) ((SurfaceOrAreaType) type).getControlPointDomain().getType()).getDimensions().length == 3;
Object geomObj = geomConv.fromIomSurface(value, getSrsid(attr), ((SurfaceOrAreaType) type).getLineAttributeStructure() != null, is3D, getP((SurfaceOrAreaType) type));
ps.setObject(valuei, geomObj);
} else {
geomConv.setSurfaceNull(ps, valuei);
}
valuei++;
}
if (createItfAreaRef) {
if (type instanceof AreaType) {
IomObject value = null;
if (isItfReader) {
value = iomObj.getattrobj(attrName, 0);
} else {
value = iomObj.getattrobj(ItfReader2.SAVED_GEOREF_PREFIX + attrName, 0);
}
if (value != null) {
boolean is3D = ((CoordType) ((SurfaceOrAreaType) type).getControlPointDomain().getType()).getDimensions().length == 3;
ps.setObject(valuei, geomConv.fromIomCoord(value, getSrsid(attr), is3D));
} else {
geomConv.setCoordNull(ps, valuei);
}
valuei++;
}
}
} else if (type instanceof CoordType) {
IomObject value = iomObj.getattrobj(attrName, 0);
if (value != null) {
boolean is3D = ((CoordType) type).getDimensions().length == 3;
ps.setObject(valuei, geomConv.fromIomCoord(value, getSrsid(attr), is3D));
} else {
geomConv.setCoordNull(ps, valuei);
}
valuei++;
} else if (type instanceof NumericType) {
String value = iomObj.getattrvalue(attrName);
if (type.isAbstract()) {
} else {
PrecisionDecimal min = ((NumericType) type).getMinimum();
PrecisionDecimal max = ((NumericType) type).getMaximum();
if (min.getAccuracy() > 0) {
if (value != null) {
try {
ps.setDouble(valuei, Double.parseDouble(value));
} catch (java.lang.NumberFormatException ex) {
EhiLogger.logError(ex);
}
} else {
geomConv.setDecimalNull(ps, valuei);
}
} else {
if (value != null) {
try {
int val = (int) Math.round(Double.parseDouble(value));
ps.setInt(valuei, val);
} catch (java.lang.NumberFormatException ex) {
EhiLogger.logError(ex);
}
} else {
ps.setNull(valuei, Types.INTEGER);
}
}
valuei++;
}
} else if (type instanceof EnumerationType) {
String value = iomObj.getattrvalue(attrName);
if (createEnumColAsItfCode) {
if (value != null) {
int itfCode = mapXtfCode2ItfCode((EnumerationType) type, value);
ps.setInt(valuei, itfCode);
} else {
ps.setNull(valuei, Types.INTEGER);
}
} else {
if (value != null) {
ps.setString(valuei, value);
} else {
ps.setNull(valuei, Types.VARCHAR);
}
}
valuei++;
if (createEnumTxtCol) {
if (value != null) {
ps.setString(valuei, beautifyEnumDispName(value));
} else {
ps.setNull(valuei, Types.VARCHAR);
}
valuei++;
}
} else if (type instanceof ReferenceType) {
IomObject structvalue = iomObj.getattrobj(attrName, 0);
String refoid = null;
if (structvalue != null) {
refoid = structvalue.getobjectrefoid();
}
Holder<Integer> valueiRef = new Holder<Integer>(valuei);
setReferenceColumn(ps, ((ReferenceType) type).getReferred(), refoid, valueiRef);
valuei = valueiRef.value;
} else if (type instanceof BlackboxType) {
String value = iomObj.getattrvalue(attrName);
if (((BlackboxType) type).getKind() == BlackboxType.eXML) {
if (value == null) {
geomConv.setXmlNull(ps, valuei);
} else {
Object toInsertXml = geomConv.fromIomXml(value);
ps.setObject(valuei, toInsertXml);
}
valuei++;
} else {
if (value == null) {
geomConv.setBlobNull(ps, valuei);
} else {
Object toInsertBlob = geomConv.fromIomBlob(value);
ps.setObject(valuei, toInsertBlob);
}
valuei++;
}
} else {
String value = iomObj.getattrvalue(attrName);
if (value != null) {
ps.setString(valuei, value);
} else {
ps.setNull(valuei, Types.VARCHAR);
}
valuei++;
}
}
}
return valuei;
}
use of javax.xml.datatype.DatatypeConfigurationException in project OpenTripPlanner by opentripplanner.
the class RoutingResource method buildRequest.
/**
* Range/sanity check the query parameter fields and build a Request object from them.
*
* @throws ParameterException when there is a problem interpreting a query parameter
*/
protected RoutingRequest buildRequest() throws ParameterException {
Router router = otpServer.getRouter(routerId);
RoutingRequest request = router.defaultRoutingRequest.clone();
request.routerId = routerId;
// router configuration and cloned. We check whether each parameter was supplied before overwriting the default.
if (fromPlace != null)
request.setFromString(fromPlace);
if (toPlace != null)
request.setToString(toPlace);
{
// FIXME: move into setter method on routing request
TimeZone tz;
tz = router.graph.getTimeZone();
if (date == null && time != null) {
// Time was provided but not date
LOG.debug("parsing ISO datetime {}", time);
try {
// If the time query param doesn't specify a timezone, use the graph's default. See issue #1373.
DatatypeFactory df = javax.xml.datatype.DatatypeFactory.newInstance();
XMLGregorianCalendar xmlGregCal = df.newXMLGregorianCalendar(time);
GregorianCalendar gregCal = xmlGregCal.toGregorianCalendar();
if (xmlGregCal.getTimezone() == DatatypeConstants.FIELD_UNDEFINED) {
gregCal.setTimeZone(tz);
}
Date d2 = gregCal.getTime();
request.setDateTime(d2);
} catch (DatatypeConfigurationException e) {
request.setDateTime(date, time, tz);
}
} else {
request.setDateTime(date, time, tz);
}
}
if (wheelchair != null)
request.setWheelchairAccessible(wheelchair);
if (numItineraries != null)
request.setNumItineraries(numItineraries);
if (maxWalkDistance != null) {
request.setMaxWalkDistance(maxWalkDistance);
request.maxTransferWalkDistance = maxWalkDistance;
}
if (maxPreTransitTime != null)
request.setMaxPreTransitTime(maxPreTransitTime);
if (walkReluctance != null)
request.setWalkReluctance(walkReluctance);
if (waitReluctance != null)
request.setWaitReluctance(waitReluctance);
if (waitAtBeginningFactor != null)
request.setWaitAtBeginningFactor(waitAtBeginningFactor);
if (walkSpeed != null)
request.walkSpeed = walkSpeed;
if (bikeSpeed != null)
request.bikeSpeed = bikeSpeed;
if (bikeSwitchTime != null)
request.bikeSwitchTime = bikeSwitchTime;
if (bikeSwitchCost != null)
request.bikeSwitchCost = bikeSwitchCost;
if (optimize != null) {
// Optimize types are basically combined presets of routing parameters, except for triangle
request.setOptimize(optimize);
if (optimize == OptimizeType.TRIANGLE) {
if (triangleSafetyFactor == null || triangleSlopeFactor == null || triangleTimeFactor == null) {
throw new ParameterException(Message.UNDERSPECIFIED_TRIANGLE);
}
if (triangleSafetyFactor == null && triangleSlopeFactor == null && triangleTimeFactor == null) {
throw new ParameterException(Message.TRIANGLE_VALUES_NOT_SET);
}
// FIXME couldn't this be simplified by only specifying TWO of the values?
if (Math.abs(triangleSafetyFactor + triangleSlopeFactor + triangleTimeFactor - 1) > Math.ulp(1) * 3) {
throw new ParameterException(Message.TRIANGLE_NOT_AFFINE);
}
request.setTriangleSafetyFactor(triangleSafetyFactor);
request.setTriangleSlopeFactor(triangleSlopeFactor);
request.setTriangleTimeFactor(triangleTimeFactor);
}
}
if (arriveBy != null)
request.setArriveBy(arriveBy);
if (showIntermediateStops != null)
request.showIntermediateStops = showIntermediateStops;
if (intermediatePlaces != null)
request.setIntermediatePlacesFromStrings(intermediatePlaces);
if (preferredRoutes != null)
request.setPreferredRoutes(preferredRoutes);
if (otherThanPreferredRoutesPenalty != null)
request.setOtherThanPreferredRoutesPenalty(otherThanPreferredRoutesPenalty);
if (preferredAgencies != null)
request.setPreferredAgencies(preferredAgencies);
if (unpreferredRoutes != null)
request.setUnpreferredRoutes(unpreferredRoutes);
if (unpreferredAgencies != null)
request.setUnpreferredAgencies(unpreferredAgencies);
if (walkBoardCost != null)
request.setWalkBoardCost(walkBoardCost);
if (bikeBoardCost != null)
request.setBikeBoardCost(bikeBoardCost);
if (bannedRoutes != null)
request.setBannedRoutes(bannedRoutes);
if (bannedAgencies != null)
request.setBannedAgencies(bannedAgencies);
HashMap<AgencyAndId, BannedStopSet> bannedTripMap = makeBannedTripMap(bannedTrips);
if (bannedTripMap != null)
request.bannedTrips = bannedTripMap;
if (bannedStops != null)
request.setBannedStops(bannedStops);
if (bannedStopsHard != null)
request.setBannedStopsHard(bannedStopsHard);
// See comment on RoutingRequest.transferPentalty.
if (transferPenalty != null)
request.transferPenalty = transferPenalty;
if (optimize == OptimizeType.TRANSFERS) {
optimize = OptimizeType.QUICK;
request.transferPenalty += 1800;
}
if (batch != null)
request.batch = batch;
if (optimize != null)
request.setOptimize(optimize);
/* Temporary code to get bike/car parking and renting working. */
if (modes != null) {
modes.applyToRoutingRequest(request);
request.setModes(request.modes);
}
if (request.allowBikeRental && bikeSpeed == null) {
// slower bike speed for bike sharing, based on empirical evidence from DC.
request.bikeSpeed = 4.3;
}
if (boardSlack != null)
request.boardSlack = boardSlack;
if (alightSlack != null)
request.alightSlack = alightSlack;
if (minTransferTime != null)
// TODO rename field in routingrequest
request.transferSlack = minTransferTime;
if (nonpreferredTransferPenalty != null)
request.nonpreferredTransferPenalty = nonpreferredTransferPenalty;
if (request.boardSlack + request.alightSlack > request.transferSlack) {
throw new RuntimeException("Invalid parameters: " + "transfer slack must be greater than or equal to board slack plus alight slack");
}
if (maxTransfers != null)
request.maxTransfers = maxTransfers;
final long NOW_THRESHOLD_MILLIS = 15 * 60 * 60 * 1000;
boolean tripPlannedForNow = Math.abs(request.getDateTime().getTime() - new Date().getTime()) < NOW_THRESHOLD_MILLIS;
// TODO the same thing for GTFS-RT
request.useBikeRentalAvailabilityInformation = (tripPlannedForNow);
if (startTransitStopId != null && !startTransitStopId.isEmpty())
request.startingTransitStopId = AgencyAndId.convertFromString(startTransitStopId);
if (startTransitTripId != null && !startTransitTripId.isEmpty())
request.startingTransitTripId = AgencyAndId.convertFromString(startTransitTripId);
if (clampInitialWait != null)
request.clampInitialWait = clampInitialWait;
if (reverseOptimizeOnTheFly != null)
request.reverseOptimizeOnTheFly = reverseOptimizeOnTheFly;
if (ignoreRealtimeUpdates != null)
request.ignoreRealtimeUpdates = ignoreRealtimeUpdates;
if (disableRemainingWeightHeuristic != null)
request.disableRemainingWeightHeuristic = disableRemainingWeightHeuristic;
if (maxHours != null)
request.maxHours = maxHours;
if (useRequestedDateTimeInMaxHours != null)
request.useRequestedDateTimeInMaxHours = useRequestedDateTimeInMaxHours;
if (disableAlertFiltering != null)
request.disableAlertFiltering = disableAlertFiltering;
if (geoidElevation != null)
request.geoidElevation = geoidElevation;
// getLocale function returns defaultLocale if locale is null
request.locale = ResourceBundleSingleton.INSTANCE.getLocale(locale);
return request;
}
Aggregations