Skip navigation links
Project Wonder 7.5-SNAPSHOT

Package er.rest.routes

See: Description

Package er.rest.routes Description

ERRest Routes

Application

public class Application extends ERXApplication { public Application() { ... ERXRouteRequestHandler routeRequestHandler = new ERXRouteRequestHandler(); routeRequestHandler.addRoutes(Reminder.ENTITY_NAME); // addRoutes looks for an addRoutes method on RemindersController routeRequestHandler.addRoutes(Person.ENTITY_NAME); // addRoutes looks for an addRoutes method on PeopleController routeRequestHandler.addDefaultRoutes(Task.ENTITY_NAME); ERXRouteRequestHandler.register(routeRequestHandler); } ... }

Entity Controller

public class PeopleController extends ERXDefaultRouteController { public PeopleController(WORequest request) { super(request); } public static void addRoutes(String entityName, ERXRouteRequestHandler requestHandler) { requestHandler.addRoute(new ERXRoute("/person/{userName}/login", PeopleController.class, "login")); requestHandler.addRoute(new ERXRoute("/person/{person:Person}/reminders", ERXRoute.Method.Post, PeopleController.class, "createReminder")); requestHandler.addRoute(new ERXRoute("/person/{person:Person}/reminders/{date:String:\\d\\d\\d\\d-\\d\\d-\\d\\d}", PeopleController.class, "reminders")); requestHandler.addDefaultRoutes(entityName); } public Person person() { Person person = (Person) routeObjectForKey("person"); return person; } public static ERXKeyFilter showFilter() { ERXKeyFilter filter = ERXKeyFilter.filterWithAttributes(); filter.exclude(Person.PASSWORD); filter.include(Person.COMPANY); filter.exclude(Person.AUTH_TOKEN); return filter; } public static ERXKeyFilter updateFilter() { ERXKeyFilter filter = ERXKeyFilter.filterWithAttributes(); filter.exclude(Person.PASSWORD); filter.include(Person.COMPANY); filter.exclude(Person.AUTH_TOKEN); filter.include(Person.COMPANY); return filter; } protected void checkCurrentPerson(Person person) { /* check that the given person is the logged in person */ } protected void checkAdminAccess() { /* check for administrator access */ } public WOActionResults loginAction() throws Exception { String userName = routeStringForKey("userName"); String password = request().stringFormValueForKey("password"); IPerson person = /* authenticate your user */ ((Session)session()).accessManager().authenticate(userName, password); return response(person, showFilter()); } public WOActionResults createAction() throws Exception { checkAdminAccess(); ERXKeyFilter personFilter = showFilter(); personFilter.include(Person.COMPANY); Person person = (Person) create(Person.ENTITY_NAME, personFilter); editingContext().saveChanges(); return response(person, showFilter()); } public WOActionResults updateAction() throws Exception { checkAdminAccess(); Person person = person(); update(person, updateFilter()); editingContext().saveChanges(); return response(person, showFilter()); } public WOActionResults showAction() { Person person = person(); return response(person, showFilter()); } public WOActionResults indexAction() throws Exception { ERXRestFetchSpecification fetchSpec = new ERXRestFetchSpecification(Person.ENTITY_NAME, null, null, showFilter(), Person.LAST_NAME.ascInsensitive().then(Person.FIRST_NAME.ascInsensitive()), -1); return response(editingContext(), Person.ENTITY_NAME, fetchSpec.objects(editingContext(), request()), showFilter()); } public WOActionResults createReminderAction() throws Exception { Person person = person(); Reminder reminder = Reminder.createReminder(person, null); update(reminder, RemindersController.updateFilter()); editingContext().saveChanges(); return response(reminder, RemindersController.showFilter()); } public WOActionResults remindersAction() throws Exception { return controller(RemindersController.class).indexAction(); // Reminders controller looks for an optional {person} request object and an optional {date} } public WOActionResults destroyAction() throws Throwable { checkAdminAccess(); Person person = person(); person.delete(); editingContext().saveChanges(); return response(person, showFilter()); } public WOActionResults newAction() throws Throwable { checkAdminAccess(); ERXKeyFilter personFilter = showFilter(); personFilter.include(Person.COMPANY); Person person = Person.createPerson(editingContext(), "Unknown Name"); // don't save here we're just returning a blank one for them to fill in return response(person, showFilter()); } }
Skip navigation links
Last updated: Fri, Nov 22, 2024 • 08:08 AM CET

Copyright © 2002 – 2024 Project Wonder.