hmis-tools / hmis-api-server

Version 2 of OpenHMIS
Mozilla Public License 2.0
15 stars 11 forks source link

Null values for PathClientVeteranInfo cause 500 response #52

Closed cecilia-donnelly closed 8 years ago

cecilia-donnelly commented 8 years ago

On the feature-validations branch (see PR #50), sending null values for the following fields causes a server error and a 500 response.

Fields:

    "worldWarII": null,
    "koreanWar": null,
    "vietnamWar": null,
    "desertStorm": null,
    "afghanistanOEF": null,
    "iraqOIF": null,
    "iraqOND": null,
    "otherTheater": null,
    "militaryBranch": null,
    "dischargeStatus": null

and the server error:

java.lang.NullPointerException
    at org.openhmis.manager.ClientManager.generatePathVeteranInfo(ClientManager.java:459)
    at org.openhmis.manager.ClientManager.addClient(ClientManager.java:102)
    at org.openhmis.webservice.ClientService.createClient(ClientService.java:62)

I'm guessing that this may have to do with YesNoReason, but it looks like that should be able to handle null values, and store them as -1? In any case, new clients with nulls in those fields are stored correctly. The issue is just that the server sends a 500 response, so the user wouldn't know that their POST was successful.

cecilia-donnelly commented 8 years ago

@slifty, @kfogel: I think I see what's going on here but I don't know how I should address it. It looks like getCode in YesNoReason doesn't return a code for null input, and so lines like veteranInfo.setWorldWarIi(clientDTO.getWorldWarII().getCode()); fail to find a code and thus send the user a 500 response. Should this just be another validation, along the lines of "Input can't be null"? Or should we convert nulls to ERR_UNKNOWN or NOT_COLLECTED?