Skip to content

Commit

Permalink
OTP-888 Refactor mobilityProfile into its own object
Browse files Browse the repository at this point in the history
  • Loading branch information
JymDyerIBI committed Nov 30, 2023
1 parent e91b138 commit b145e75
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.eclipse.jetty.http.HttpStatus;
import org.opentripplanner.middleware.auth.Auth0Connection;
import org.opentripplanner.middleware.auth.RequestingUser;
import org.opentripplanner.middleware.models.MobilityProfile;
import org.opentripplanner.middleware.models.OtpUser;
import org.opentripplanner.middleware.persistence.Persistence;
import org.opentripplanner.middleware.utils.JsonUtils;
Expand Down Expand Up @@ -55,13 +56,19 @@ OtpUser preCreateHook(OtpUser user, Request req) {
Auth0Connection.ensureApiUserHasApiKey(req);
user.applicationId = requestingUser.apiUser.id;
}
user.mobilityMode = calculateMobilityMode(user);
if (user.mobilityProfile == null) {
user.mobilityProfile = new MobilityProfile();
}
user.mobilityProfile.mobilityMode = calculateMobilityMode(user);
return super.preCreateHook(user, req);
}

@Override
OtpUser preUpdateHook(OtpUser user, OtpUser preExistingUser, Request req) {
user.mobilityMode = calculateMobilityMode(user);
if (user.mobilityProfile == null) {
user.mobilityProfile = new MobilityProfile();
}
user.mobilityProfile.mobilityMode = calculateMobilityMode(user);
return super.preUpdateHook(user, preExistingUser, req);
}

Expand Down Expand Up @@ -184,8 +191,8 @@ public static boolean isPhoneNumberValidE164(String phoneNumber) {

/**
* Calculate and return the "mobility mode", a keyword or compound keyword specified by Georgia Tech,
* based on a number {@code OtpUser} fields related to mobility.
* @param user with fields that are consulted to calculate mobility mode
* based on a number of {@code OtpUser} moblity profile fields.
* @param user whose mobility profile is consulted to calculate mobility mode
* @return mobility mode as a single string
*/
private static String calculateMobilityMode(OtpUser user) {
Expand All @@ -195,42 +202,44 @@ private static String calculateMobilityMode(OtpUser user) {
String mModeTemp = "None";
String visionTemp = "None";

if (user.mobilityDevices == null) {
user.mobilityDevices = Collections.EMPTY_LIST;
}
if (user.mobilityDevices.isEmpty() || user.mobilityDevices.contains("none")) {
user.mobilityDevices.clear();
} else {
if (user.mobilityDevices.contains("white cane")) {
if (user.mobilityProfile.mobilityDevices == null) {
user.mobilityProfile.mobilityDevices = Collections.EMPTY_LIST;
}
if (user.mobilityProfile.mobilityDevices.isEmpty() || user.mobilityProfile.mobilityDevices.contains("none")) {
user.mobilityProfile.mobilityDevices.clear();
} else {
if (user.mobilityProfile.mobilityDevices.contains("white cane")) {
visionTemp = "Blind";
}
if (user.mobilityDevices.contains("manual walker")
|| user.mobilityDevices.contains("wheeled walker")
|| user.mobilityDevices.contains("cane")
|| user.mobilityDevices.contains("crutches")
|| user.mobilityDevices.contains("stroller")
|| user.mobilityDevices.contains("service animal")) {
if (user.mobilityProfile.mobilityDevices.contains("manual walker")
|| user.mobilityProfile.mobilityDevices.contains("wheeled walker")
|| user.mobilityProfile.mobilityDevices.contains("cane")
|| user.mobilityProfile.mobilityDevices.contains("crutches")
|| user.mobilityProfile.mobilityDevices.contains("stroller")
|| user.mobilityProfile.mobilityDevices.contains("service animal")) {
mModeTemp = "Device";
}
if (user.mobilityDevices.contains("mobility scooter")) {
if (user.mobilityProfile.mobilityDevices.contains("mobility scooter")) {
mModeTemp = "MScooter";
}
if (user.mobilityDevices.contains("electric wheelchair")) {
if (user.mobilityProfile.mobilityDevices.contains("electric wheelchair")) {
mModeTemp = "WChairE";
}
if (user.mobilityDevices.contains("manual wheelchair")) {
if (user.mobilityProfile.mobilityDevices.contains("manual wheelchair")) {
mModeTemp = "WChairM";
}

if ("None".equals(mModeTemp) && user.isMobilityLimited) {
if ("None".equals(mModeTemp) && user.mobilityProfile.isMobilityLimited) {
mModeTemp = "Some";
}
}

if (visionTemp.isEmpty() && "low-vision".equals(user.visionLimitation)) {
visionTemp = "LowVision";
} else if (visionTemp.isEmpty() && "legally blind".equals(user.visionLimitation)) {
visionTemp = "Blind";
if (visionTemp.isEmpty()) {
if (MobilityProfile.VisionLimitation.LOW_VISION == user.mobilityProfile.visionLimitation) {
visionTemp = "LowVision";
} else if (MobilityProfile.VisionLimitation.LEGALLY_BLIND == user.mobilityProfile.visionLimitation) {
visionTemp = "Blind";
}
}

// Create combinations for mobility mode and vision
Expand All @@ -239,7 +248,7 @@ private static String calculateMobilityMode(OtpUser user) {
return visionTemp;
} else if (MOBILITY_DEVICES.contains(mModeTemp)) {
return mModeTemp + "-" + visionTemp;
}
}
} else if (MOBILITY_DEVICES.contains(mModeTemp)) {
return mModeTemp;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.opentripplanner.middleware.models;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;
import java.util.Collection;

/**
* Mobility profile data
*/
public class MobilityProfile implements Serializable {
public enum VisionLimitation {
@JsonProperty("legally blind") LEGALLY_BLIND,
@JsonProperty("low-vision") LOW_VISION,
@JsonProperty("none") NONE
}

/** Whether the user indicates that their mobility is limited (slower). */
public boolean isMobilityLimited;

/** User may indicate zero or more mobility devices. */
public Collection<String> mobilityDevices;

/** Compound keyword that controller calculates from mobility and vision values. */
@JsonIgnore
public String mobilityMode;

/** User may indicate levels of vision limitation. */
public VisionLimitation visionLimitation;
}
14 changes: 2 additions & 12 deletions src/main/java/org/opentripplanner/middleware/models/OtpUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,11 @@ public enum Notification {
/** Whether the user has consented to terms of use. */
public boolean hasConsentedToTerms;

/** Whether the user has indicated that their mobility is limited (slower). */
public boolean isMobilityLimited;

/** Whether the phone number has been verified. */
public boolean isPhoneNumberVerified;

/** User may have indicated zero or more mobility devices. */
public Collection<String> mobilityDevices;

/** Compound keyword that controller calculates from mobility and vision values. */
@JsonIgnore
public String mobilityMode;

/** One of "low-vision" "legally blind" "none" */
public String visionLimitation;
/** Mobilty profile. */
public MobilityProfile mobilityProfile;

/**
* Notification preferences for this user
Expand Down
29 changes: 19 additions & 10 deletions src/main/resources/latest-spark-swagger-output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2550,18 +2550,10 @@ definitions:
type: "boolean"
hasConsentedToTerms:
type: "boolean"
isMobilityLimited:
type: "boolean"
isPhoneNumberVerified:
type: "boolean"
mobilityDevices:
type: "array"
items:
type: "string"
mobilityMode:
type: "string"
visionLimitation:
type: "string"
mobilityProfile:
$ref: "#/definitions/MobilityProfile"
notificationChannel:
type: "array"
items:
Expand All @@ -2588,6 +2580,23 @@ definitions:
type: "boolean"
applicationId:
type: "string"
MobilityProfile:
type: "object"
properties:
isMobilityLimited:
type: "boolean"
mobilityDevices:
type: "array"
items:
type: "string"
mobilityMode:
type: "string"
visionLimitation:
type: "string"
enum:
- "LEGALLY_BLIND"
- "LOW_VISION"
- "NONE"
GetUsageResult:
type: "object"
properties:
Expand Down

0 comments on commit b145e75

Please sign in to comment.