/**
 *    Copyright 2013 Talend Inc.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package com.sheepdog.mashmesh.resources;

import com.sheepdog.mashmesh.models.RideRequest;
import com.sheepdog.mashmesh.tasks.SendNotificationTask;
import org.joda.time.DateTime;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

@Path("/notification")
public class SendNotificationResource {
    private static final String QUEUE_NAME = "notifications";

    @POST
    @Produces({MediaType.TEXT_PLAIN})
    public String scheduleNotification(@FormParam("patientEmail") String patientEmail,
                                       @FormParam("appointmentAddress") String appointmentAddress,
                                       @FormParam("appointmentTime") String appointmentTimeRfc339) {
        if (patientEmail == null || patientEmail.isEmpty() ||
                appointmentAddress == null || appointmentAddress.isEmpty() ||
                appointmentTimeRfc339 == null || appointmentTimeRfc339.isEmpty()) {
            // TODO: Actually report errors with bean validation.
            throw new WebApplicationException(400);
        }

        DateTime appointmentTime = DateTime.parse(appointmentTimeRfc339);
        RideRequest request = SendNotificationTask.createRequest(patientEmail, appointmentAddress, appointmentTime);
        SendNotificationTask.scheduleRequest(request);

        return "OK";
    }
}

@@ -710,16 +710,65 @@
 equest;%0A
+import com.sheepdog.mashmesh.models.UserProfile;%0A
 import c
@@ -816,16 +816,16 @@
 onTask;%0A
-
 import o
@@ -904,16 +904,50 @@
 diaType;
+%0Aimport javax.ws.rs.core.Response;
 %0A%0A@Path(
@@ -1066,16 +1066,491 @@
 ions%22;%0A%0A
+    private void verifyPatientEmail(String patientEmail) %7B%0A        UserProfile patientProfile = UserProfile.getByEmail(patientEmail);%0A        if (patientProfile == null %7C%7C patientProfile.getType() != UserProfile.UserType.PATIENT) %7B%0A            Response response = Response.status(Response.Status.NOT_FOUND)%0A                    .entity(%22No such patient: %22 + patientEmail)%0A                    .build();%0A            throw new WebApplicationException(response);%0A        %7D%0A    %7D%0A%0A
     @POS
@@ -2218,16 +2218,16 @@
 n(400);%0A
-
         
@@ -2225,24 +2225,67 @@
 %0A        %7D%0A%0A
+        verifyPatientEmail(patientEmail);%0A%0A
         Date

Verify patient addresses when they are received