From b62e63306a781e6fcbb3db7ee8400c946f870317 Mon Sep 17 00:00:00 2001 From: Stefano Mazzocchi Date: Wed, 29 Sep 2010 01:50:57 +0000 Subject: [PATCH] - make the correct version + revision available also to the java side (thru web.xml) - add @Override metadata to the commands that were missing it - make the version information appear even when using trunk (Fixes Issue 136) git-svn-id: http://google-refine.googlecode.com/svn/trunk@1406 7d457c2a-affb-35e4-300a-418c747d4874 --- build.xml | 5 ++++ main/.classpath | 2 +- main/src/com/google/refine/RefineServlet.java | 30 ++++++++++++------- .../refine/commands/GetVersionCommand.java | 24 +++++++++++++++ .../commands/OpenWorkspaceDirCommand.java | 8 ++--- .../commands/auth/AuthorizeCommand.java | 1 + .../commands/auth/DeAuthorizeCommand.java | 1 + .../commands/auth/GetUserBadgesCommand.java | 3 +- .../browsing/GetScatterplotCommand.java | 1 + .../column/GetColumnsInfoCommand.java | 1 + .../commands/project/ExportRowsCommand.java | 1 + .../refine/commands/row/GetRowsCommand.java | 1 + .../com/google/refine/history/History.java | 2 +- main/src/com/google/refine/model/Project.java | 2 +- .../google/refine/oauth/GoogleProvider.java | 17 +++++++++++ .../google/refine/oauth/OAuthUtilities.java | 2 +- .../src/com/google/refine/oauth/Provider.java | 3 ++ .../com/google/refine/util/FreebaseUtils.java | 5 ++-- main/src/com/google/refine/util/Pool.java | 2 +- main/webapp/WEB-INF/web.xml | 8 +++++ .../webapp/modules/core/MOD-INF/controller.js | 4 ++- .../modules/core/MOD-INF/module.properties | 1 - main/webapp/modules/core/index.vt | 9 +++--- main/webapp/modules/core/scripts/index.js | 8 ++--- 24 files changed, 106 insertions(+), 35 deletions(-) create mode 100644 main/src/com/google/refine/commands/GetVersionCommand.java create mode 100644 main/src/com/google/refine/oauth/GoogleProvider.java diff --git a/build.xml b/build.xml index 0f998a77f..17a09940b 100644 --- a/build.xml +++ b/build.xml @@ -229,6 +229,11 @@ + + + + + diff --git a/main/.classpath b/main/.classpath index aa0faa656..ceeefc0e1 100644 --- a/main/.classpath +++ b/main/.classpath @@ -3,7 +3,7 @@ - + diff --git a/main/src/com/google/refine/RefineServlet.java b/main/src/com/google/refine/RefineServlet.java index 43de3a38b..828baf66b 100644 --- a/main/src/com/google/refine/RefineServlet.java +++ b/main/src/com/google/refine/RefineServlet.java @@ -25,28 +25,28 @@ import edu.mit.simile.butterfly.ButterflyModule; public class RefineServlet extends Butterfly { - static private final String VERSION = "2.0"; + static public String VERSION = ""; + static public String REVISION = ""; + static public String FULLNAME = "Google Refine "; - private static final long serialVersionUID = 2386057901503517403L; + static public final String AGENT_ID = "/en/google_refine"; + + static final long serialVersionUID = 2386057901503517403L; - private static final String JAVAX_SERVLET_CONTEXT_TEMPDIR = "javax.servlet.context.tempdir"; + static private final String JAVAX_SERVLET_CONTEXT_TEMPDIR = "javax.servlet.context.tempdir"; static private RefineServlet s_singleton; - static private File s_dataDir; + static private File s_dataDir; static final private Map commands = new HashMap(); // timer for periodically saving projects static private Timer _timer; - final static Logger logger = LoggerFactory.getLogger("refine"); - - public static String getVersion() { - return VERSION; - } - - final static protected long s_autoSavePeriod = 1000 * 60 * 5; // 5 minutes + static final Logger logger = LoggerFactory.getLogger("refine"); + static final protected long s_autoSavePeriod = 1000 * 60 * 5; // 5 minutes + static protected class AutoSaveTimerTask extends TimerTask { public void run() { try { @@ -64,6 +64,12 @@ public class RefineServlet extends Butterfly { @Override public void init() throws ServletException { super.init(); + + VERSION = getInitParameter("refine.version"); + REVISION = getInitParameter("refine.revision"); + FULLNAME += VERSION + " [" + REVISION + "]"; + + logger.info("Starting " + FULLNAME + "..."); s_singleton = this; @@ -114,10 +120,12 @@ public class RefineServlet extends Butterfly { Command command = commands.get(commandKey); if (command != null) { if (request.getMethod().equals("GET")) { + if (!logger.isTraceEnabled()) logger.info("GET {}", request.getPathInfo()); logger.trace("> GET {}", commandKey); command.doGet(request, response); logger.trace("< GET {}", commandKey); } else if (request.getMethod().equals("POST")) { + if (!logger.isTraceEnabled()) logger.info("POST {}", request.getPathInfo()); logger.trace("> POST {}", commandKey); command.doPost(request, response); logger.trace("< POST {}", commandKey); diff --git a/main/src/com/google/refine/commands/GetVersionCommand.java b/main/src/com/google/refine/commands/GetVersionCommand.java new file mode 100644 index 000000000..b19925cb2 --- /dev/null +++ b/main/src/com/google/refine/commands/GetVersionCommand.java @@ -0,0 +1,24 @@ +package com.google.refine.commands; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.google.refine.RefineServlet; + +public class GetVersionCommand extends Command { + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + try { + response.setCharacterEncoding("UTF-8"); + response.setHeader("Content-Type", "text/plain"); + response.getWriter().write(RefineServlet.VERSION); + } catch (Exception e) { + respondException(response, e); + } + } + +} diff --git a/main/src/com/google/refine/commands/OpenWorkspaceDirCommand.java b/main/src/com/google/refine/commands/OpenWorkspaceDirCommand.java index 631c9b339..3cfd29cf7 100644 --- a/main/src/com/google/refine/commands/OpenWorkspaceDirCommand.java +++ b/main/src/com/google/refine/commands/OpenWorkspaceDirCommand.java @@ -27,10 +27,10 @@ public class OpenWorkspaceDirCommand extends Command { Desktop desktop = Desktop.getDesktop(); desktop.open(dir); } else /* if Mac */ { - Process p = Runtime.getRuntime().exec( - "open .", - new String[] {}, - dir + Runtime.getRuntime().exec( + "open .", + new String[] {}, + dir ); } diff --git a/main/src/com/google/refine/commands/auth/AuthorizeCommand.java b/main/src/com/google/refine/commands/auth/AuthorizeCommand.java index 6fe5fdd23..04a896b93 100644 --- a/main/src/com/google/refine/commands/auth/AuthorizeCommand.java +++ b/main/src/com/google/refine/commands/auth/AuthorizeCommand.java @@ -21,6 +21,7 @@ public class AuthorizeCommand extends Command { private static final String OAUTH_VERIFIER_PARAM = "oauth_verifier"; + @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // get the provider from the request diff --git a/main/src/com/google/refine/commands/auth/DeAuthorizeCommand.java b/main/src/com/google/refine/commands/auth/DeAuthorizeCommand.java index f21a8da37..668f07c4b 100644 --- a/main/src/com/google/refine/commands/auth/DeAuthorizeCommand.java +++ b/main/src/com/google/refine/commands/auth/DeAuthorizeCommand.java @@ -13,6 +13,7 @@ import com.google.refine.oauth.Provider; public class DeAuthorizeCommand extends Command { + @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { diff --git a/main/src/com/google/refine/commands/auth/GetUserBadgesCommand.java b/main/src/com/google/refine/commands/auth/GetUserBadgesCommand.java index 70979702e..66b2289a3 100644 --- a/main/src/com/google/refine/commands/auth/GetUserBadgesCommand.java +++ b/main/src/com/google/refine/commands/auth/GetUserBadgesCommand.java @@ -16,8 +16,9 @@ import com.google.refine.util.FreebaseUtils; public class GetUserBadgesCommand extends Command { - final static Logger logger = LoggerFactory.getLogger("check-authorization_command"); + final static Logger logger = LoggerFactory.getLogger("get-version_command"); + @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { diff --git a/main/src/com/google/refine/commands/browsing/GetScatterplotCommand.java b/main/src/com/google/refine/commands/browsing/GetScatterplotCommand.java index 40a21d639..514ce3db7 100644 --- a/main/src/com/google/refine/commands/browsing/GetScatterplotCommand.java +++ b/main/src/com/google/refine/commands/browsing/GetScatterplotCommand.java @@ -32,6 +32,7 @@ public class GetScatterplotCommand extends Command { final static Logger logger = LoggerFactory.getLogger("get-scatterplot_command"); + @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { diff --git a/main/src/com/google/refine/commands/column/GetColumnsInfoCommand.java b/main/src/com/google/refine/commands/column/GetColumnsInfoCommand.java index 9e483c279..2cf673bab 100644 --- a/main/src/com/google/refine/commands/column/GetColumnsInfoCommand.java +++ b/main/src/com/google/refine/commands/column/GetColumnsInfoCommand.java @@ -21,6 +21,7 @@ import com.google.refine.model.Project; public class GetColumnsInfoCommand extends Command { + @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { diff --git a/main/src/com/google/refine/commands/project/ExportRowsCommand.java b/main/src/com/google/refine/commands/project/ExportRowsCommand.java index 0ede35eae..ebdbed118 100644 --- a/main/src/com/google/refine/commands/project/ExportRowsCommand.java +++ b/main/src/com/google/refine/commands/project/ExportRowsCommand.java @@ -31,6 +31,7 @@ public class ExportRowsCommand extends Command { return options; } + @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { diff --git a/main/src/com/google/refine/commands/row/GetRowsCommand.java b/main/src/com/google/refine/commands/row/GetRowsCommand.java index 0f5c00b5d..fad9e3b2c 100644 --- a/main/src/com/google/refine/commands/row/GetRowsCommand.java +++ b/main/src/com/google/refine/commands/row/GetRowsCommand.java @@ -29,6 +29,7 @@ import com.google.refine.util.Pool; public class GetRowsCommand extends Command { + @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { internalRespond(request, response); diff --git a/main/src/com/google/refine/history/History.java b/main/src/com/google/refine/history/History.java index b0b1e8417..06e516ce0 100644 --- a/main/src/com/google/refine/history/History.java +++ b/main/src/com/google/refine/history/History.java @@ -68,7 +68,7 @@ public class History implements Jsonizable { } static public void writeOneChange(Writer writer, Change change, Properties options) throws IOException { - writer.write(RefineServlet.getVersion()); writer.write('\n'); + writer.write(RefineServlet.VERSION); writer.write('\n'); writer.write(change.getClass().getName()); writer.write('\n'); change.save(writer, options); diff --git a/main/src/com/google/refine/model/Project.java b/main/src/com/google/refine/model/Project.java index 36cf9fb18..7b9eac237 100644 --- a/main/src/com/google/refine/model/Project.java +++ b/main/src/com/google/refine/model/Project.java @@ -122,7 +122,7 @@ public class Project { } protected void saveToWriter(Writer writer, Properties options) throws IOException { - writer.write(RefineServlet.getVersion()); writer.write('\n'); + writer.write(RefineServlet.VERSION); writer.write('\n'); writer.write("columnModel=\n"); columnModel.save(writer, options); writer.write("history=\n"); history.save(writer, options); diff --git a/main/src/com/google/refine/oauth/GoogleProvider.java b/main/src/com/google/refine/oauth/GoogleProvider.java new file mode 100644 index 000000000..76bd567e7 --- /dev/null +++ b/main/src/com/google/refine/oauth/GoogleProvider.java @@ -0,0 +1,17 @@ +package com.google.refine.oauth; + +public class GoogleProvider extends Provider { + + public String getRequestTokenServiceURL() { + return "https://www.google.com/accounts/OAuthGetRequestToken"; + } + + public String getAccessTokenServiceURL() { + return "https://www.google.com/accounts/OAuthGetAccessToken"; + } + + public String getUserAuthorizationURL() { + return "https://www.google.com/accounts/OAuthAuthorizeToken"; + } + +} diff --git a/main/src/com/google/refine/oauth/OAuthUtilities.java b/main/src/com/google/refine/oauth/OAuthUtilities.java index 1d12940f8..c822f1947 100644 --- a/main/src/com/google/refine/oauth/OAuthUtilities.java +++ b/main/src/com/google/refine/oauth/OAuthUtilities.java @@ -17,7 +17,7 @@ public class OAuthUtilities { static final private Map providers = new HashMap(); static final private Map infos = new HashMap(); - static private final String[] FREEBASE_OAUTH_INFO = { "#9202a8c04000641f80000000150979b7" , "8ded7babfad2f94f4c77e39bbd6c90f31939999b"}; + static private final String[] FREEBASE_OAUTH_INFO = { "#9202a8c04000641f80000000185352db" , "4561ee02279e6f04ebd88a1557e4292489380adf"}; static { Provider freebase = new FreebaseProvider(FreebaseUtils.FREEBASE_HOST); diff --git a/main/src/com/google/refine/oauth/Provider.java b/main/src/com/google/refine/oauth/Provider.java index 02d0f12f2..895b19a81 100644 --- a/main/src/com/google/refine/oauth/Provider.java +++ b/main/src/com/google/refine/oauth/Provider.java @@ -5,6 +5,9 @@ public abstract class Provider { protected String host; + public Provider() { + } + public Provider(String host) { this.host = host; } diff --git a/main/src/com/google/refine/util/FreebaseUtils.java b/main/src/com/google/refine/util/FreebaseUtils.java index c1bef4c76..04a0a102a 100644 --- a/main/src/com/google/refine/util/FreebaseUtils.java +++ b/main/src/com/google/refine/util/FreebaseUtils.java @@ -35,7 +35,6 @@ import com.google.refine.oauth.Provider; public class FreebaseUtils { static final public String FREEBASE_HOST = "www.freebase.com"; - static final public String FREEBASE_SANDBOX_HOST = "www.sandbox-freebase.com"; static final private String FREEQ_URL = "http://data.labs.freebase.com/freeq/gridworks"; //static final private String FREEQ_URL = "http://data.labs.freebase.com/freeq/refine"; @@ -55,7 +54,7 @@ public class FreebaseUtils { } private static String getUserAgent() { - return "Google Refine " + RefineServlet.getVersion(); + return RefineServlet.FULLNAME; } public static String getUserInfo(Credentials credentials, Provider provider) @@ -190,7 +189,7 @@ public class FreebaseUtils { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8"); HttpPost httpRequest = new HttpPost(getFreeQUrl()); - httpRequest.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Google Refine " + RefineServlet.getVersion()); + httpRequest.getParams().setParameter(CoreProtocolPNames.USER_AGENT, getUserAgent()); httpRequest.setEntity(entity); HttpPost surrogateRequest = new HttpPost(getUserInfoURL(FREEBASE_HOST)); diff --git a/main/src/com/google/refine/util/Pool.java b/main/src/com/google/refine/util/Pool.java index 544eb05f2..f5d5d58f2 100644 --- a/main/src/com/google/refine/util/Pool.java +++ b/main/src/com/google/refine/util/Pool.java @@ -62,7 +62,7 @@ public class Pool implements Jsonizable { } public void save(Writer writer) throws IOException { - writer.write(RefineServlet.getVersion()); writer.write('\n'); + writer.write(RefineServlet.VERSION); writer.write('\n'); Properties options = new Properties(); options.setProperty("mode", "save"); diff --git a/main/webapp/WEB-INF/web.xml b/main/webapp/WEB-INF/web.xml index 6750c16ab..d5f8a2687 100644 --- a/main/webapp/WEB-INF/web.xml +++ b/main/webapp/WEB-INF/web.xml @@ -21,6 +21,14 @@ refine com.google.refine.RefineServlet + + refine.version + $VERSION + + + refine.revision + $REVISION + diff --git a/main/webapp/modules/core/MOD-INF/controller.js b/main/webapp/modules/core/MOD-INF/controller.js index 02497290e..467fb4fdc 100644 --- a/main/webapp/modules/core/MOD-INF/controller.js +++ b/main/webapp/modules/core/MOD-INF/controller.js @@ -13,7 +13,9 @@ var templatedFiles = { function registerCommands() { var RS = Packages.com.google.refine.RefineServlet; - + + RS.registerCommand(module, "get-version", new Packages.com.google.refine.commands.GetVersionCommand()); + RS.registerCommand(module, "create-project-from-upload", new Packages.com.google.refine.commands.project.CreateProjectCommand()); RS.registerCommand(module, "import-project", new Packages.com.google.refine.commands.project.ImportProjectCommand()); RS.registerCommand(module, "export-project", new Packages.com.google.refine.commands.project.ExportProjectCommand()); diff --git a/main/webapp/modules/core/MOD-INF/module.properties b/main/webapp/modules/core/MOD-INF/module.properties index 63dfff601..53ae3bb40 100644 --- a/main/webapp/modules/core/MOD-INF/module.properties +++ b/main/webapp/modules/core/MOD-INF/module.properties @@ -1,4 +1,3 @@ description = Google Refine Core Module implements = core templating.macros = macros.vm - diff --git a/main/webapp/modules/core/index.vt b/main/webapp/modules/core/index.vt index 475112079..87193b392 100644 --- a/main/webapp/modules/core/index.vt +++ b/main/webapp/modules/core/index.vt @@ -95,16 +95,15 @@
use 0 if there is no header line
-
-
Ignore Quotation Marks
-
Ignore quotation marks,
using all newlines and separators
-
+
+
Ignore Quotation Marks
+
Ignore quotation marks,
using all newlines and separators
+
-