Search in sources :

Example 1 with RouteId

use of org.webpieces.router.api.routes.RouteId in project webpieces by deanhiller.

the class ScopedRouteBuilderImpl method addCrud.

/*
	 * Adds routes like the following all in one method
	 * 
	 * 	//addRoute(GET ,   "/user/list",        "crud/CrudUserController.userList", listRoute);
	 *	//addRoute(GET ,   "/user/new",         "crud/CrudUserController.userAddEdit", addRoute);
	 *	//addRoute(GET ,   "/user/edit/{id}",   "crud/CrudUserController.userAddEdit", editRoute);
	 *	//addRoute(POST,   "/user/post",        "crud/CrudUserController.postSaveUser", saveRoute);
	 *	//addRoute(GET,    "/user/delete/{id}", "crud/CrudUserController.postDeleteUser", deleteRoute);
	 */
@Override
public void addCrud(Port port, String entity, String controller, CrudRouteIds routeIds) {
    RouteId listRoute = routeIds.getListRoute();
    RouteId addRoute = routeIds.getAddRoute();
    RouteId editRoute = routeIds.getEditRoute();
    RouteId postSaveRoute = routeIds.getPostSaveRoute();
    RouteId confirmDelete = routeIds.getConfirmDelete();
    RouteId postDeleteRoute = routeIds.getPostDeleteRoute();
    String entityWithCapital = entity.substring(0, 1).toUpperCase() + entity.substring(1);
    addRoute(port, GET, "/" + entity + "/list", controller + "." + entity + "List", listRoute);
    addRoute(port, GET, "/" + entity + "/new", controller + "." + entity + "AddEdit", addRoute);
    addRoute(port, GET, "/" + entity + "/edit/{id}", controller + "." + entity + "AddEdit", editRoute);
    addRoute(port, POST, "/" + entity + "/post", controller + ".postSave" + entityWithCapital, postSaveRoute);
    // get the confirm delete page
    addRoute(port, GET, "/" + entity + "/confirmdelete/{id}", controller + ".confirmDelete" + entityWithCapital, confirmDelete);
    // NOTE: Browsers don't support DELETE.  POST might make more sense here for delete but GET is way way less html
    // code(ok, 1 line instead of 3).  There are hacks with javascript to support DELETE but seriously, we should just
    // KISS and YAGNI (google that if you don't know).
    // HOWEVER, If you don't like this, copy and paste this method and modify to be a POST OR DELETE and add the
    // javascript for next time
    addRoute(port, POST, "/" + entity + "/delete/{id}", controller + ".postDelete" + entityWithCapital, postDeleteRoute);
}
Also used : RouteId(org.webpieces.router.api.routes.RouteId)

Example 2 with RouteId

use of org.webpieces.router.api.routes.RouteId in project webpieces by deanhiller.

the class ReverseRoutes method getByClassAndName.

private ReversableRouter getByClassAndName(String name) {
    if (duplicateClassAndNames.contains(name)) {
        Set<RouteId> keySet = routeIdToRoute.keySet();
        String routes = "";
        for (RouteId id : keySet) {
            String potentialName = id.getClass().getSimpleName() + "." + id.name();
            if (name.equals(potentialName))
                routes += "\nroute=" + id.getClass().getName() + "." + id.name();
        }
        throw new RouteNotFoundException("There is more than one route matching the class and name.  Qualify it with the package like org.web." + name + ".  These are the conflicting ids which is why you need to be more specific=" + routes);
    }
    ReversableRouter routeMeta = classAndNameToRoute.get(name);
    if (routeMeta == null)
        throw new RouteNotFoundException("route=" + name + " not found");
    return routeMeta;
}
Also used : RouteId(org.webpieces.router.api.routes.RouteId) RouteNotFoundException(org.webpieces.router.api.exceptions.RouteNotFoundException)

Example 3 with RouteId

use of org.webpieces.router.api.routes.RouteId in project webpieces by deanhiller.

the class ReverseRoutes method getByName.

private ReversableRouter getByName(String name) {
    if (duplicateNames.contains(name)) {
        Set<RouteId> keySet = routeIdToRoute.keySet();
        String routes = "";
        for (RouteId id : keySet) {
            if (name.equals(id.name()))
                routes += "\nroute=" + id.getClass();
        }
        throw new RouteNotFoundException("There is more than one route matching the name.  Qualify it with the class like XXXRouteId." + name + ".  Same names are found in these enum classes=" + routes);
    }
    ReversableRouter routeMeta = routeNameToRoute.get(name);
    if (routeMeta == null)
        throw new RouteNotFoundException("route=" + name + " not found.");
    return routeMeta;
}
Also used : RouteId(org.webpieces.router.api.routes.RouteId) RouteNotFoundException(org.webpieces.router.api.exceptions.RouteNotFoundException)

Aggregations

RouteId (org.webpieces.router.api.routes.RouteId)3 RouteNotFoundException (org.webpieces.router.api.exceptions.RouteNotFoundException)2