Skip to content

Commit

Permalink
Hotfix 1.3.1 for issue with SMS handling last name (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
abobwhite authored Apr 6, 2018
1 parent 12e0b49 commit 84f24d8
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 65 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.civtechstl</groupId>
<version>1.3.0</version>
<version>1.3.1</version>
<packaging>jar</packaging>

<parent>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/svc/managers/DemoManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public List<DemoCitation> createCitationsAndViolations(){
}
}
DemoCitation demoCitation = new DemoCitation();
demoCitation.lastName = citation.last_name;
demoCitation.citationNumber = citation.citation_number;
demoCitation.dob = citation.date_of_birth;
demoCitation.driversLicenseNumber = citation.drivers_license_number;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/svc/managers/SMSAlertManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private List<SMSAlertNotification> getNotificationsToSend(List<SMSAlert> dailyAl
criteria.citationNumber = dailyAlert.citationNumber;
List<Citation> citations = citationManager.findCitations(criteria);
Court court = courtManager.getCourtById(citations.get(0).court_id.getValue());
String link = clientURL+"/citations/"+citations.get(0).citation_number;
String link = clientURL+"/tickets/"+citations.get(0).citation_number+"/info";

boolean canSendMessage = true;
if (!isAlertDateStillCurrent(dailyAlert.courtDate,citations.get(0))){
Expand Down
130 changes: 74 additions & 56 deletions src/main/java/svc/managers/SMSManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,39 +45,40 @@ public class SMSManager {
SMSAlertManager smsAlertManager;
@Inject
SMSNotifier smsNotifier;

@Value("${stlcourts.clientURL}")
String clientURL;

@Autowired
private TwilioConfiguration twilioConfiguration;

private enum SMS_STAGE{
WELCOME(0),
READ_DOB(1),
READ_LICENSE(2),
READ_STATE(3),
VIEW_CITATION(4),
READ_MENU_CHOICE_VIEW_CITATIONS_AGAIN(5);

READ_LASTNAME(1),
READ_DOB(2),
READ_LICENSE(3),
READ_STATE(4),
VIEW_CITATION(5),
READ_MENU_CHOICE_VIEW_CITATIONS_AGAIN(6);

private int numVal;

SMS_STAGE(int numVal){
this.numVal =numVal;
}

public int getNumVal() {
return numVal;
}
}

public SMSInfo getInfo(){
SMSInfo info = new SMSInfo();
info.phoneNumber = twilioConfiguration.phoneNumber;
return info;
}


//a empty String means validDOB, otherwise a message is returned to pass on to user
private String validateDOBString(String dob){
String errMsg = "";
Expand All @@ -100,20 +101,20 @@ private String validateDOBString(String dob){
errMsg = "You must be at least 18 years old to use www.yourSTLcourts.com";
}
}
}
}
return errMsg;
}


private MessagingResponse createTwimlResponse(String msg){
Message sms = new Message.Builder().body(new Body(msg)).build();
MessagingResponse twimlResponse = new MessagingResponse.Builder().message(sms).build();
return twimlResponse;
}

private SMS_STAGE getStageFromSession(HttpSession session){
SMS_STAGE stage;

Integer stageNumber = (Integer) session.getAttribute("stage");
if (stageNumber == null){
stage = SMS_STAGE.WELCOME;
Expand All @@ -124,20 +125,30 @@ private SMS_STAGE getStageFromSession(HttpSession session){
stage = SMS_STAGE.WELCOME;
}
}

return stage;
}

private void setNextStageInSession(HttpSession session, SMS_STAGE nextTextStage){
session.setAttribute("stage", new Integer(nextTextStage.getNumVal()));
}

private String generateWelcomeStageMessage(HttpSession session){
String message = "Welcome to www.yourSTLcourts.com. Please enter your birthdate using MM/DD/YYYY";
setNextStageInSession(session,SMS_STAGE.READ_DOB);
String message = "Welcome to www.yourSTLcourts.com. Please enter your last name";
setNextStageInSession(session,SMS_STAGE.READ_LASTNAME);
return message;
}


private String generateReadLastNameMessage(HttpSession session, String lastName){
SMS_STAGE nextTextStage;
lastName = (lastName != null)?lastName:(String)session.getAttribute("last_name");
session.setAttribute("last_name", lastName);
String message = "Thank you. Now please enter your birthdate using MM/DD/YYYY";
nextTextStage = SMS_STAGE.READ_DOB;
setNextStageInSession(session,nextTextStage);
return message;
}

private String generateReadDobMessage(HttpSession session, String dob){
SMS_STAGE nextTextStage;
String message = validateDOBString(dob);
Expand All @@ -152,21 +163,22 @@ private String generateReadDobMessage(HttpSession session, String dob){
setNextStageInSession(session,nextTextStage);
return message;
}
private String ListCitations(LocalDate dob, String license, String licenseState){

private String ListCitations(LocalDate dob, String license, String licenseState, String lastName){
CitationSearchCriteria criteria = new CitationSearchCriteria();
criteria.dateOfBirth = dob;
criteria.driversLicenseNumber = license;
criteria.driversLicenseState = licenseState;
criteria.lastName = lastName;
List<Citation> citations = citationManager.findCitations(criteria);

ListCitationsTextMessage listCitationsTM = new ListCitationsTextMessage(citations);

String message = listCitationsTM.toTextMessage();

return message;
}

private String generateReadLicenseMessage(HttpSession session, String licenseNumber){
SMS_STAGE nextTextStage;
licenseNumber = (licenseNumber != null)?licenseNumber:(String)session.getAttribute("license_number");
Expand All @@ -176,25 +188,26 @@ private String generateReadLicenseMessage(HttpSession session, String licenseNum
setNextStageInSession(session,nextTextStage);
return message;
}

private String generateReadStateMessage(HttpSession session){
String message = generateReadStateMessage(session, null);
return message;
}

private String generateReadStateMessage(HttpSession session, String licenseState){
String message = "";
SMS_STAGE nextTextStage;

licenseState = (licenseState != null)?licenseState:(String)session.getAttribute("license_state");
licenseState = licenseState.toUpperCase();
String licenseNumber = (String)session.getAttribute("license_number");
String dob = (String)session.getAttribute("dob");

String lastName = (String)session.getAttribute("last_name");

try{
LocalDate date_of_birth = DatabaseUtilities.convertUSStringDateToLD(dob);
session.setAttribute("license_state", licenseState);
message = ListCitations(date_of_birth, licenseNumber,licenseState);
message = ListCitations(date_of_birth, licenseNumber,licenseState, lastName);
if (message == ""){
message = "No tickets were found. If you have entered your information correctly, please visit the following link for possible reasons: \n\n";
message += clientURL+"/tickets/error/notFound";
Expand Down Expand Up @@ -306,11 +319,13 @@ private String generateViewCitationMessage(HttpSession session, String citationN
String dob = (String)session.getAttribute("dob");
String license = (String)session.getAttribute("license_number");
String licenseState = (String)session.getAttribute("license_state");
String lastName = (String)session.getAttribute("last_name");
criteria = new CitationSearchCriteria();
try{
criteria.dateOfBirth = DatabaseUtilities.convertUSStringDateToLD(dob);
criteria.driversLicenseNumber = license;
criteria.driversLicenseState = licenseState;
criteria.lastName = lastName;
citations = citationManager.findCitations(criteria);
int citationNumberToView = Integer.parseInt(citationNumber) - 1;
if (citationNumberToView >= 0 && citationNumberToView < citations.size()){
Expand All @@ -328,7 +343,7 @@ private String generateViewCitationMessage(HttpSession session, String citationN
message = "Invalid entry. Please enter only the number of the ticket you would like to view.";
nextTextStage = SMS_STAGE.VIEW_CITATION;
}


}catch (DateTimeParseException e){
//something went wrong here this shouldn't happen since dob has already been parsed
Expand All @@ -355,24 +370,27 @@ public MessagingResponse getTwimlResponse(TwimlMessageRequest twimlMessageReques
session.setAttribute("phoneNumber", twimlMessageRequest.getFrom());

switch(currentTextStage){
case WELCOME:
message = generateWelcomeStageMessage(session);
break;
case READ_DOB:
message = generateReadDobMessage(session, content);
break;
case READ_LICENSE:
message = generateReadLicenseMessage(session, content);
break;
case READ_STATE:
message = generateReadStateMessage(session, content);
break;
case VIEW_CITATION:
message = generateViewCitationMessage(session, content);
break;
case READ_MENU_CHOICE_VIEW_CITATIONS_AGAIN:
message = generateViewCitationsAgainMessage(session, request, content);
break;
case WELCOME:
message = generateWelcomeStageMessage(session);
break;
case READ_LASTNAME:
message = generateReadLastNameMessage(session, content);
break;
case READ_DOB:
message = generateReadDobMessage(session, content);
break;
case READ_LICENSE:
message = generateReadLicenseMessage(session, content);
break;
case READ_STATE:
message = generateReadStateMessage(session, content);
break;
case VIEW_CITATION:
message = generateViewCitationMessage(session, content);
break;
case READ_MENU_CHOICE_VIEW_CITATIONS_AGAIN:
message = generateViewCitationsAgainMessage(session, request, content);
break;
}

twimlResponse = createTwimlResponse(message);
Expand All @@ -381,4 +399,4 @@ public MessagingResponse getTwimlResponse(TwimlMessageRequest twimlMessageReques
return twimlResponse;
}

}
}
1 change: 1 addition & 0 deletions src/main/java/svc/models/DemoCitation.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.LocalDate;

public class DemoCitation {
public String lastName;
public String citationNumber;
public LocalDate dob;
public String driversLicenseNumber;
Expand Down
25 changes: 18 additions & 7 deletions src/test/java/svc/managers/SMSManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ public class SMSManagerTest {

private enum SMS_STAGE{
WELCOME(0),
READ_DOB(1),
READ_LICENSE(2),
READ_STATE(3),
VIEW_CITATION(4),
READ_MENU_CHOICE_VIEW_CITATIONS_AGAIN(5);

READ_LASTNAME(1),
READ_DOB(2),
READ_LICENSE(3),
READ_STATE(4),
VIEW_CITATION(5),
READ_MENU_CHOICE_VIEW_CITATIONS_AGAIN(6);

private int numVal;

SMS_STAGE(int numVal){
Expand Down Expand Up @@ -98,10 +99,20 @@ public void welcomeMessageGetsGenerated() throws TwiMLException{
setStageInSession(session,SMS_STAGE.WELCOME);
TwimlMessageRequest twimlMessageRequest = new TwimlMessageRequest();
twimlMessageRequest.setBody("");
String message = "Welcome to www.yourSTLcourts.com. Please enter your birthdate using MM/DD/YYYY";
String message = "Welcome to www.yourSTLcourts.com. Please enter your last name";
MessagingResponse twimlResponse = manager.getTwimlResponse(twimlMessageRequest,requestMock, session);
assertEquals(createTwimlResponse(message).toXml(),twimlResponse.toXml());
}

@Test
public void lastNameReadMessageGetsGenerated() throws TwiMLException{
setStageInSession(session,SMS_STAGE.READ_LASTNAME);
TwimlMessageRequest twimlMessageRequest = new TwimlMessageRequest();
twimlMessageRequest.setBody("Max");
String message = "Thank you. Now please enter your birthdate using MM/DD/YYYY";
MessagingResponse twimlResponse = manager.getTwimlResponse(twimlMessageRequest, requestMock,session);
assertEquals(createTwimlResponse(message).toXml(),twimlResponse.toXml());
}

@Test
public void dobReadMessageGetsGenerated() throws TwiMLException{
Expand Down

0 comments on commit 84f24d8

Please sign in to comment.