The time period format should be in format dd,MMM,yyyy,hh,mm

Viewed 279

Hi I am sending JSON data and the JSON will have to validated at the backend. The time period should be in this format--- dd,MMM,yyyy,hh,mm.

This is my JSON

{
    "equipmentID":"234",
    "modality":"healthcaare",
    "facilityID":"manipal",
    "countryCode":"abc",
    "isoCode":"1234",
     "problemType":"234",
    "problemArea":"priyanka",
    "equipmentStatus":"sdsd",
    "name":"taneja",
    "phoneNumber":"13333344",
    "extension":"12123",
    "description":"x ray machine error",
    "shortDescription":"2",
     "timePeriod":"03-12-2011 04-37",
     "serviceCode":"sdfdf",
     "locale":"werfd",
    "requestingApp":"icenter", 
    "examNumber":"sdd", 
    "seriesNumber":"dfdf", 
    "imageNumber":"dfdfd"
}

This is the validation class public class RequestValidator implements Validator {

    @Override
    public ValidationResult validate(String objectName, RequestData rqdata) {
        // TODO Auto-generated method stub

        ValidationResult result = new ValidationResult();

        if (rqdata == null) {
            result.addError("error.invalidObjectGraph", "Object graph not initialized correctly");
            return result;
        }
        Validation.rule("EquipmentId", rqdata.getEquipmentID()).required().run(result);
        Validation.rule("Modality", rqdata.getModality()).required().run(result);
        Validation.rule("FacilityID", rqdata.getFacilityID()).required().run(result);
        Validation.rule("CountryCode", rqdata.getCountryCode()).required().maxLength(3).matches("^[a-zA-Z]*$")
                .run(result);
        Validation.rule("ProblemType", rqdata.getProblemType()).required().run(result);
        Validation.rule("Name", rqdata.getName()).required().maxLength(20).run(result);
        Validation.rule("PhoneNumber", rqdata.getPhoneNumber()).required().maxLength(25).matches("[0-9]+").run(result);
        Validation.rule("Extension", rqdata.getExtension()).required().maxLength(10).matches("[0-9]+").run(result);
        Validation.rule("Description", rqdata.getDescription()).required().maxLength(300).run(result);
        Validation.rule("ShortDescription", rqdata.getShortDescription()).required().maxLength(80).run(result);
        Validation.rule("TimePeriod", rqdata.getTimePeriod()).required().matches("dd-MMM-yyyy hh-mm").run(result);
        Validation.rule("Locale", rqdata.getLocale()).required().run(result);

        System.out.println("value of requesting app is:" + rqdata.getRequestingApp());
        Validation.rule("RequestingApp", rqdata.getRequestingApp()).required().matches("icenter").run(result);
        System.out.println(result.getErrorDetails());
        return result;
    }
}

But i am getting an error that the date is not in appropriate format. Please help me out. Thanks

1 Answers
Related