Author: jleroux
Date: Mon Oct 15 14:52:32 2018 New Revision: 1843916 URL: http://svn.apache.org/viewvc?rev=1843916&view=rev Log: Improved: Refactor ICalendar support (OFBIZ-10602) Rewrites documentation to remove Javadoc warnings and improves implementation by avoiding classes with only one method. Thanks: Mathieu Lirzin Modified: ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalHandlerFactory.java ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/RequestHandler.java ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/RequestHandlerFactory.java Modified: ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java?rev=1843916&r1=1843915&r2=1843916&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java Mon Oct 15 14:52:32 2018 @@ -382,7 +382,7 @@ public class ICalConverter { * @param context The conversion context * @return An iCalendar as a <code>String</code>, or <code>null</code> * if <code>workEffortId</code> is invalid. - * @throws GenericEntityException + * @throws GenericEntityException if communications with the database failed */ public static ResponseProperties getICalendar(String workEffortId, Map<String, Object> context) throws GenericEntityException { Delegator delegator = (Delegator) context.get("delegator"); @@ -680,15 +680,20 @@ public class ICalConverter { } } - /** Update work efforts from an incoming iCalendar request. - * @param is - * @param context - * @throws IOException - * @throws ParserException - * @throws GenericEntityException - * @throws GenericServiceException + /** + * Updates work efforts from an incoming iCalendar request. + * + * @param is the input feeding the calendar parser + * @param context parameters from the execution environment + * @return the response from the ICalWorker + * @throws IOException if there is an issue with {@code is} + * @throws ParserException if the calendar build process failed + * @throws GenericEntityException if communications with the database failed + * @throws GenericServiceException if {@code createWorkEffortICalData} or {@code updateWorkEffortICalData} + * service invocation failed */ - public static ResponseProperties storeCalendar(InputStream is, Map<String, Object> context) throws IOException, ParserException, GenericEntityException, GenericServiceException { + public static ResponseProperties storeCalendar(InputStream is, Map<String, Object> context) + throws IOException, ParserException, GenericEntityException, GenericServiceException { CalendarBuilder builder = new CalendarBuilder(); Calendar calendar = null; try { Modified: ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalHandlerFactory.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalHandlerFactory.java?rev=1843916&r1=1843915&r2=1843916&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalHandlerFactory.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalHandlerFactory.java Mon Oct 15 14:52:32 2018 @@ -32,77 +32,71 @@ import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.webapp.webdav.RequestHandler; import org.apache.ofbiz.webapp.webdav.RequestHandlerFactory; -/** WebDAV request handler factory for iCalendar. This class is a simple connector - * between the WebDAV servlet and the <code>ICalWorker</code> class. +/** + * WebDAV request handler factory for iCalendar. + * + * This class is a simple connector between the WebDAV servlet and + * the {@code ICalWorker} class. */ public class ICalHandlerFactory implements RequestHandlerFactory { public static final String module = ICalHandlerFactory.class.getName(); - protected final Map<String, RequestHandler> handlerMap; - protected final RequestHandler invalidMethodHandler = new InvalidMethodHandler(); - protected final RequestHandler doNothingHandler = new DoNothingHandler(); public ICalHandlerFactory() { - this.handlerMap = new HashMap<>(); - this.handlerMap.put("COPY", doNothingHandler); - this.handlerMap.put("DELETE", doNothingHandler); - this.handlerMap.put("GET", new GetHandler()); - this.handlerMap.put("HEAD", doNothingHandler); - this.handlerMap.put("LOCK", doNothingHandler); - this.handlerMap.put("MKCOL", doNothingHandler); - this.handlerMap.put("MOVE", doNothingHandler); - this.handlerMap.put("POST", doNothingHandler); - this.handlerMap.put("PROPFIND", new PropFindHandler()); - this.handlerMap.put("PROPPATCH", doNothingHandler); - this.handlerMap.put("PUT", new PutHandler()); - this.handlerMap.put("UNLOCK", doNothingHandler); + handlerMap = new HashMap<>(); + handlerMap.put("COPY", ICalHandlerFactory::doNothing); + handlerMap.put("DELETE", ICalHandlerFactory::doNothing); + handlerMap.put("GET", ICalHandlerFactory::doGet); + handlerMap.put("HEAD", ICalHandlerFactory::doNothing); + handlerMap.put("LOCK", ICalHandlerFactory::doNothing); + handlerMap.put("MKCOL", ICalHandlerFactory::doNothing); + handlerMap.put("MOVE", ICalHandlerFactory::doNothing); + handlerMap.put("POST", ICalHandlerFactory::doNothing); + handlerMap.put("PROPFIND", ICalHandlerFactory::doPropFind); + handlerMap.put("PROPPATCH", ICalHandlerFactory::doNothing); + handlerMap.put("PUT", ICalHandlerFactory::doPut); + handlerMap.put("UNLOCK", ICalHandlerFactory::doNothing); } public RequestHandler getHandler(String method) { - RequestHandler handler = this.handlerMap.get(method); + RequestHandler handler = handlerMap.get(method); if (handler == null) { - return invalidMethodHandler; + return ICalHandlerFactory::handleInvalidMethod; } return handler; } - protected static class InvalidMethodHandler implements RequestHandler { - public void handleRequest(HttpServletRequest request, HttpServletResponse response, ServletContext context) throws ServletException, IOException { - Debug.logInfo("[InvalidMethodHandler] method = " + request.getMethod(), module); - response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); - } + protected static void handleInvalidMethod (HttpServletRequest req, HttpServletResponse resp, ServletContext ctx) + throws ServletException, IOException { + Debug.logInfo("[InvalidMethodHandler] method = " + req.getMethod(), module); + resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); } - protected static class DoNothingHandler implements RequestHandler { - public void handleRequest(HttpServletRequest request, HttpServletResponse response, ServletContext context) throws ServletException, IOException { - Debug.logInfo("[DoNothingHandler] method = " + request.getMethod(), module); - response.setStatus(HttpServletResponse.SC_OK); - } + protected static void doNothing(HttpServletRequest req, HttpServletResponse resp, ServletContext ctx) + throws ServletException, IOException { + Debug.logInfo("[DoNothingHandler] method = " + req.getMethod(), module); + resp.setStatus(HttpServletResponse.SC_OK); } - protected static class GetHandler implements RequestHandler { - public void handleRequest(HttpServletRequest request, HttpServletResponse response, ServletContext context) throws ServletException, IOException { - Debug.logInfo("[GetHandler] starting request", module); - ICalWorker.handleGetRequest(request, response, context); - Debug.logInfo("[GetHandler] finished request", module); - } + protected static void doGet(HttpServletRequest req, HttpServletResponse resp, ServletContext ctx) + throws ServletException, IOException { + Debug.logInfo("[GetHandler] starting request", module); + ICalWorker.handleGetRequest(req, resp, ctx); + Debug.logInfo("[GetHandler] finished request", module); } - protected static class PutHandler implements RequestHandler { - public void handleRequest(HttpServletRequest request, HttpServletResponse response, ServletContext context) throws ServletException, IOException { - Debug.logInfo("[PutHandler] starting request", module); - ICalWorker.handlePutRequest(request, response, context); - Debug.logInfo("[PutHandler] finished request", module); - } + protected static void doPut(HttpServletRequest req, HttpServletResponse resp, ServletContext ctx) + throws ServletException, IOException { + Debug.logInfo("[PutHandler] starting request", module); + ICalWorker.handlePutRequest(req, resp, ctx); + Debug.logInfo("[PutHandler] finished request", module); } - protected static class PropFindHandler implements RequestHandler { - public void handleRequest(HttpServletRequest request, HttpServletResponse response, ServletContext context) throws ServletException, IOException { - Debug.logInfo("[PropFindHandler] starting request", module); - ICalWorker.handlePropFindRequest(request, response, context); - Debug.logInfo("[PropFindHandler] finished request", module); - } + protected static void doPropFind(HttpServletRequest req, HttpServletResponse resp, ServletContext ctx) + throws ServletException, IOException { + Debug.logInfo("[PropFindHandler] starting request", module); + ICalWorker.handlePropFindRequest(req, resp, ctx); + Debug.logInfo("[PropFindHandler] finished request", module); } - } Modified: ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/RequestHandler.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/RequestHandler.java?rev=1843916&r1=1843915&r2=1843916&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/RequestHandler.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/RequestHandler.java Mon Oct 15 14:52:32 2018 @@ -25,15 +25,18 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +@FunctionalInterface public interface RequestHandler { /** - * Called by the the WebDAV servlet to handle a WebDAV request. - * <table cellspacing="0" cellpadding="2" border="1"> - * <caption>HTTPServletRequest attributes</caption> - * <tr><td>delegator</td><td>A <code>GenericDelgator</code> instance</td></tr> - * <tr><td>dispatcher</td><td>A <code>LocalDispatcher</code> instance</td></tr> - * <tr><td>security</td><td>A <code>Security</code> instance</td></tr> - * </table> + * Method called by the the WebDAV servlet to handle a WebDAV request. + * + * @param req the HTTP request to handle which contains the {@link GenericDelegator delegator}, + * {@link LocalDispatcher dispatcher}, and {@link Security security} attributes + * @param resp the HTTP response to send + * @param ctx the context of the current servlet + * @throws ServletException if servlet execution failed + * @throws IOException if communication with the HTTP request/response buffers failed */ - public void handleRequest(HttpServletRequest request, HttpServletResponse response, ServletContext context) throws ServletException, IOException; + void handleRequest(HttpServletRequest req, HttpServletResponse resp, ServletContext ctx) + throws ServletException, IOException; } Modified: ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/RequestHandlerFactory.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/RequestHandlerFactory.java?rev=1843916&r1=1843915&r2=1843916&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/RequestHandlerFactory.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/webdav/RequestHandlerFactory.java Mon Oct 15 14:52:32 2018 @@ -18,15 +18,14 @@ *******************************************************************************/ package org.apache.ofbiz.webapp.webdav; +@FunctionalInterface public interface RequestHandlerFactory { - /** Returns a <code>RequestHandler</code> instance appropriate - * for the WebDAV HTTP method. + /** + * Returns a {@link RequestHandler} instance appropriate for the WebDAV HTTP methods. * - * @param method The WebDAV HTTP method. Implementations MUST - * provide handlers for the following methods: PROPFIND, PROPPATCH, - * MKCOL, GET, HEAD, POST, DELETE, PUT, COPY, MOVE, LOCK, UNLOCK. - * @return A <code>RequestHandler</code> instance. Implementations - * of this interface MUST NOT return <code>null</code>. + * @param method the WebDAV HTTP method which can be PROPFIND, PROPPATCH, + * MKCOL, GET, HEAD, POST, DELETE, PUT, COPY, MOVE, LOCK, or UNLOCK. + * @return a <code>RequestHandler</code> instance which can't be null. */ - public RequestHandler getHandler(String method); + RequestHandler getHandler(String method); } |
Free forum by Nabble | Edit this page |