I would use two classes, but you could do it in one. Something like this:
class PatientResource extends ServerResrouce
String id;
@Override
protected void doInit() throws ResourceException {
this.id = getEscapedAttribute("PATIENT_ID");
}
@Post
addPatent(Form form) {
//this.id should be null. Your return the new Id in the results. If you want
the user to supply an id, use PUT!
}
@Delete
deletePatient() {
//this.id to identify patient.
}
@Get
getPatient() {
//this.id to identify patient.
}
@Put
updatePatient(Form) {
//this.id to identify the patient. new address is in form. if id is missing,
invalid call. New address is in form.
}
}
Routing would be something like:
router.attach( "/patient", PatientResource.class );
router.attach( "/patient/{PATIENT_ID}", PatientResource.class );
For the two-class case:
class PatientWithIdResource extends ServerResrouce {
String id;
@Override
protected void doInit() throws ResourceException {
this.id = getEscapedAttribute("PATIENT_ID");
}
@Delete
deletePatient() {
//this.id to identify patient.
}
@Get
getPatient() {
//this.id to identify patient.
}
@Put
updatePatient(Form) {
//this.id to identify the patient. new address is in form.
}
}
class PatientWithoutIdResource extends ServerResrouce {
@Post
addPatent(Form form) {
//this.id should be null. Your return that in the results. If you want the user
to supply an id, use PUT!
}
}
with routing like this:
router.attach( "/patient", PatientWithoutIdResource.class );
router.attach( "/patient/{PATIENT_ID}", PatientWithIdResource.class );
Note that the annotations can also take arguments, and I left out return values
and so on.
bjorn
On Apr 24, 2012, at 4:37 PM, Dalia Sobhy wrote:
> If I have a patient resource class which contains 4 methods:
> 1. AddPatient (Patient p)
> 2. DeletePatient (String ID)
> 3. RetrievePatient(String ID)
> 4.UpdatePatientAddress(String ID, String Address)
>
> Can I implement them in one resource class, if so how could I perform the
> server-side routing??
>
> Thanks in advance, you are saving me....
>
> --
> View this message in context:
> http://restlet-discuss.1400322.n2.nabble.com/Restlet-Resources-tp7497363p7497363.html
> Sent from the Restlet Discuss mailing list archive at Nabble.com.
>
> ------------------------------------------------------
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2951527
-----------------------------
Bjorn Roche
http://www.xonami.com
Audio Collaboration
http://blog.bjornroche.com
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2951531