Author: jtravis Date: 2007-03-23 17:50:27 -0800 (Fri, 23 Mar 2007) New Revision: 3855 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=3855 Added: trunk/ui_plugins/rendit_sys/ trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/BaseController.groovy trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/dispatcher.groovy trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/helpers/LiveDataHelper.groovy trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/helpers/ResourceHelper.groovy Removed: trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/ trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/BaseController.groovy trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/dispatcher.groovy trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/helpers/LiveDataHelper.groovy trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/helpers/ResourceHelper.groovy Log: Move rendit_sys to the ui_plugins directory Copied: trunk/ui_plugins/rendit_sys (from rev 3844, trunk/src/org/hyperic/hq/ui/rendit/rendit_sys) Deleted: trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/BaseController.groovy =================================================================== --- trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/BaseController.groovy 2007-03-23 23:49:12 UTC (rev 3844) +++ trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/BaseController.groovy 2007-03-24 01:50:27 UTC (rev 3855) @@ -1,92 +0,0 @@ -package org.hyperic.hq.ui.rendit - -import java.io.OutputStreamWriter - -import org.apache.commons.logging.Log -import org.apache.commons.logging.LogFactory - -import org.hyperic.hq.authz.server.session.AuthzSubject -import org.hyperic.hq.ui.util.ContextUtils -import org.hyperic.hq.ui.util.RequestUtils - -import org.hyperic.hq.ui.rendit.helpers.LiveDataHelper -import org.hyperic.hq.ui.rendit.helpers.ResourceHelper - -import groovy.text.SimpleTemplateEngine -import java.io.File - -abstract class BaseController - extends Expando -{ - Log log = LogFactory.getLog(this.getClass()) - String action - File pluginDir - def invokeArgs - private AuthzSubject user - - private void setAction(String action) { - this.action = action - } - - def setInvokeArgs(def args) { - this.invokeArgs = args - } - - def setPluginDir(File pluginDir) { - this.pluginDir = pluginDir - } - - def getResourceHelper() { return new ResourceHelper(getUser()) } - def getLiveDataHelper() { return new LiveDataHelper(getUser()) } - - /** - * Retreives the currently logged-in user - */ - protected AuthzSubject getUser() { - if (this.user != null) - return this.user - - def sessId = RequestUtils.getSessionId(invokeArgs.request) - def ctx = invokeArgs.request.session.servletContext - - this.user = ContextUtils.getAuthzBoss(ctx).getCurrentSubject(sessId) - } - - /** - * Render a .gsp. - * - * This method takes a map of arguments. Valid arguments include: - * file: The file to render. If not specified, the name of the - * current action will be used - * args: A map of key/value pairs to send to the .gsp to use when - * rendering - * - * Examples: - * To render the file 'listView.gsp' to the browser - * > render file:'listView' - * - * To render the current action to the browser and pass in parameters - * needed by the .gsp - * > render args:[userName:'Jeff', favouriteDrink:'Vodka'] - * - */ - protected void render(args) { - args = (args == null) ? [:] : args - def gspArgs = args.remove("args") - def gspFile = args.remove("file") - def useAction - - if (gspFile == null) - useAction = action - else - useAction = gspFile - - new File(pluginDir, useAction + '.gsp').withReader { reader -> - def eng = new SimpleTemplateEngine(false) - def template = eng.createTemplate(reader) - def outStream = invokeArgs.response.outputStream - def outWriter = new OutputStreamWriter(outStream) - template.make(gspArgs).writeTo(outWriter) - } - } -} Copied: trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/BaseController.groovy (from rev 3850, trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/BaseController.groovy) =================================================================== --- trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/BaseController.groovy (rev 0) +++ trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/BaseController.groovy 2007-03-24 01:50:27 UTC (rev 3855) @@ -0,0 +1,122 @@ +package org.hyperic.hq.ui.rendit + +import org.apache.commons.lang.StringEscapeUtils + +import java.io.OutputStreamWriter + +import org.apache.commons.logging.Log +import org.apache.commons.logging.LogFactory + +import org.hyperic.hq.authz.server.session.AuthzSubject +import org.hyperic.hq.ui.util.ContextUtils +import org.hyperic.hq.ui.util.RequestUtils + +import org.hyperic.hq.ui.rendit.helpers.LiveDataHelper +import org.hyperic.hq.ui.rendit.helpers.ResourceHelper + +import groovy.text.SimpleTemplateEngine +import java.io.File + +abstract class BaseController { + Log log = LogFactory.getLog(this.getClass()) + String action + File pluginDir + + private invokeArgs + private AuthzSubject user + + private void setAction(String action) { + this.action = action + } + + protected setInvokeArgs(args) { + this.invokeArgs = args + } + + def getInvokeArgs() { invokeArgs } + + def setPluginDir(File pluginDir) { + this.pluginDir = pluginDir + } + + def getResourceHelper() { return new ResourceHelper(getUser()) } + def getLiveDataHelper() { return new LiveDataHelper(getUser()) } + + /** + * Retreives the currently logged-in user + */ + protected AuthzSubject getUser() { + if (this.user != null) + return this.user + + def sessId = RequestUtils.getSessionId(invokeArgs.request) + def ctx = invokeArgs.request.session.servletContext + + this.user = ContextUtils.getAuthzBoss(ctx).getCurrentSubject(sessId) + } + + public String h(str) { + StringEscapeUtils.escapeHtml(str) + } + + public RENDER_BUILTINS = [ + link_to : { text, Object[] args -> + def url = "" + def opts = (args.length > 0) ? args[0] : [:] + def htmlOpts = (args.length > 1) ? args[1] : [:] + + if (opts.containsKey('action')) + url += h(opts['action']) + + url += '?' + for (o in htmlOpts) { + url += URLEncoder.encode("" + o.key, "UTF-8") + "=" + + URLEncoder.encode("" + o.value, "UTF-8") + "&" + } + + return "<a href=\"$url\">$text</a>" + }, + + h : { str -> h(str) } + ] + + /** + * Render a .gsp. + * + * This method takes a map of arguments. Valid arguments include: + * file: The file to render. If not specified, the name of the + * current action will be used + * args: A map of key/value pairs to send to the .gsp to use when + * rendering + * + * Examples: + * To render the file 'listView.gsp' to the browser + * > render file:'listView' + * + * To render the current action to the browser and pass in parameters + * needed by the .gsp + * > render args:[userName:'Jeff', favouriteDrink:'Vodka'] + * + */ + protected void render(args) { + args = (args == null) ? [:] : args + def gspArgs = args.remove("args") + def gspFile = args.remove("file") + def useAction + + if (gspFile == null) + useAction = action + else + useAction = gspFile + + new File(pluginDir, useAction + '.gsp').withReader { reader -> + def eng = new SimpleTemplateEngine(false) + def template = eng.createTemplate(reader) + def outStream = invokeArgs.response.outputStream + def outWriter = new OutputStreamWriter(outStream) + + gspArgs.putAll(RENDER_BUILTINS) + template.make(gspArgs).writeTo(outWriter) + } + } +} Deleted: trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/dispatcher.groovy =================================================================== --- trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/dispatcher.groovy 2007-03-23 23:49:12 UTC (rev 3844) +++ trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/dispatcher.groovy 2007-03-24 01:50:27 UTC (rev 3855) @@ -1,59 +0,0 @@ -package org.hyperic.hq.ui.rendit - -import org.apache.commons.logging.Log -import org.apache.commons.logging.LogFactory - -/** - * The Dispatcher is the direct invocation target called from the HQ - * RenditServer. It has the responsibility of locating the controllers, - * setting up the environment, and invoking the request. - */ -class Dispatcher { - private Log log = LogFactory.getLog(Dispatcher.class); - - private File pluginDir - private String controllerName - private String action - private def invokeArgs - - private String capitalize(String s) { - if (s.length() == 0) - return s; - return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase(); - } - - def Dispatcher(def invokeArgs) { - def path = invokeArgs.requestPath - - if (path.size() < 3) { - throw new IllegalArgumentException("Path must have at least 3 " + - "components"); - } - - pluginDir = invokeArgs.pluginDir - controllerName = capitalize(path[1]) + "Controller" - action = path[2] - this.invokeArgs = invokeArgs - } - - def invoke() { - def controller = Class.forName(controllerName, true, - this.class.classLoader).newInstance() - - controller.setAction(action) - controller.setPluginDir(pluginDir) - controller.setInvokeArgs(invokeArgs) - - def runner = controller."$action" - if (runner == null) { - throw new IllegalArgumentException("Unknown action [$action]") - } - - def start = System.currentTimeMillis() - runner(invokeArgs.request.parameterMap) - log.info """Executed $controllerName:$action in - ${System.currentTimeMillis() - start} ms""" - } -} - -new Dispatcher(invokeArgs).invoke() Copied: trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/dispatcher.groovy (from rev 3847, trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/dispatcher.groovy) =================================================================== --- trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/dispatcher.groovy (rev 0) +++ trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/dispatcher.groovy 2007-03-24 01:50:27 UTC (rev 3855) @@ -0,0 +1,59 @@ +package org.hyperic.hq.ui.rendit + +import org.apache.commons.logging.Log +import org.apache.commons.logging.LogFactory + +/** + * The Dispatcher is the direct invocation target called from the HQ + * RenditServer. It has the responsibility of locating the controllers, + * setting up the environment, and invoking the request. + */ +class Dispatcher { + private Log log = LogFactory.getLog(Dispatcher.class); + + private File pluginDir + private String controllerName + private String action + private def invokeArgs + + private String capitalize(String s) { + if (s.length() == 0) + return s; + return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase(); + } + + def Dispatcher(def invokeArgs) { + def path = invokeArgs.requestPath + + if (path.size() < 3) { + throw new IllegalArgumentException("Path must have at least 3 " + + "components"); + } + + pluginDir = invokeArgs.pluginDir + controllerName = capitalize(path[1]) + "Controller" + action = path[2] + this.invokeArgs = invokeArgs + } + + def invoke() { + def controller = Class.forName(controllerName, true, + this.class.classLoader).newInstance() + + controller.setAction(action) + controller.setPluginDir(pluginDir) + controller.setInvokeArgs(invokeArgs) + + def runner = controller."$action" + if (runner == null) { + throw new IllegalArgumentException("Unknown action [$action]") + } + + def start = System.currentTimeMillis() + runner(invokeArgs.request.parameterMap) + log.info "Executed $controllerName:$action in " + + "${System.currentTimeMillis() - start} ms" + } +} + +new Dispatcher(invokeArgs).invoke() Deleted: trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/helpers/LiveDataHelper.groovy =================================================================== --- trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/helpers/LiveDataHelper.groovy 2007-03-23 23:49:12 UTC (rev 3844) +++ trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/helpers/LiveDataHelper.groovy 2007-03-24 01:50:27 UTC (rev 3855) @@ -1,23 +0,0 @@ -package org.hyperic.hq.ui.rendit.helpers - -import org.hyperic.hq.livedata.server.session.LiveDataManagerEJBImpl -import org.json.JSONArray - -class LiveDataHelper - extends BaseHelper -{ - LiveDataHelper(user) { - super(user) - } - - private getDataMan() { LiveDataManagerEJBImpl.one } - - String[] getCommands(resource) { - dataMan.getCommands(userVal, resource.entityId) - } - - JSONArray getData(resource, command) { - new JSONArray(dataMan.getData(userVal, resource.entityId, command)) - } -} - Copied: trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/helpers/LiveDataHelper.groovy (from rev 3849, trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/helpers/LiveDataHelper.groovy) =================================================================== --- trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/helpers/LiveDataHelper.groovy (rev 0) +++ trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/helpers/LiveDataHelper.groovy 2007-03-24 01:50:27 UTC (rev 3855) @@ -0,0 +1,29 @@ +package org.hyperic.hq.ui.rendit.helpers + +import org.hyperic.hq.appdef.shared.AppdefResourceValue +import org.hyperic.util.config.ConfigResponse +import org.hyperic.hq.livedata.server.session.LiveDataManagerEJBImpl +import org.hyperic.hq.livedata.shared.LiveDataResult +import org.json.JSONArray + +class LiveDataHelper + extends BaseHelper +{ + LiveDataHelper(user) { + super(user) + } + + private getDataMan() { LiveDataManagerEJBImpl.one } + + String[] getCommands(AppdefResourceValue resource) { + dataMan.getCommands(userVal, resource.entityId) + } + + LiveDataResult getData(AppdefResourceValue resource, String command, + config) + { + dataMan.getData(userVal, resource.entityId, command, + config as ConfigResponse) + } +} + Deleted: trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/helpers/ResourceHelper.groovy =================================================================== --- trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/helpers/ResourceHelper.groovy 2007-03-23 23:49:12 UTC (rev 3844) +++ trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/helpers/ResourceHelper.groovy 2007-03-24 01:50:27 UTC (rev 3855) @@ -1,60 +0,0 @@ -package org.hyperic.hq.ui.rendit.helpers - -import org.hyperic.hq.appdef.shared.AppdefResourceValue -import org.hyperic.hq.appdef.server.session.PlatformManagerEJBImpl - -class ResourceHelper - extends BaseHelper -{ - private final NAME_FINDERS = [ - platform: [ - str: {name -> platMan.getPlatformByName(userVal, name)}, - int: {id -> platMan.getPlatformValueById(userVal, id)}], - platformType: [ - str: {name -> platMan.findPlatformTypeByName(name)}, - int: {id -> platMan.findPlatformTypeValueById(id)}], - ] - - ResourceHelper(user) { - super(user) - } - - private getPlatMan() { PlatformManagerEJBImpl.one } - - /** - * Generic method to find resources. - * - * args: The arguments are a map of options. Currently the only - * options are to find a platform or platformType by name or id. - * - * Examples: - * - * To find a platform by name: - * > find platform:'My Platform' - * - * To find a platform by id: - * > find platform:44123 - */ - AppdefResourceValue find(args) { - def resourceType - for (i in args) { - if (NAME_FINDERS.containsKey(i.key)) { - if (resourceType != null) { - throw new IllegalArgumentException("""Cannot specify more - than one resource type [$resourceType] and - [$i.key]""") - } - resourceType = i.key - } - } - - if (resourceType == null) - throw new IllegalArgumentException(""""No resource type specified. - Must be one of - $NAME_FINDERS.keySet()""") - - def resourceVal = args[resourceType] - def argType = (resourceVal instanceof String) ? 'str' : 'int' - NAME_FINDERS[resourceType][argType].call(resourceVal) - } -} Copied: trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/helpers/ResourceHelper.groovy (from rev 3853, trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/helpers/ResourceHelper.groovy) =================================================================== --- trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/helpers/ResourceHelper.groovy (rev 0) +++ trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/helpers/ResourceHelper.groovy 2007-03-24 01:50:27 UTC (rev 3855) @@ -0,0 +1,85 @@ +package org.hyperic.hq.ui.rendit.helpers + +import org.hyperic.util.pager.PageControl + +import org.hyperic.hq.appdef.shared.AppdefResourceValue +import org.hyperic.hq.appdef.server.session.PlatformManagerEJBImpl + +class ResourceHelper + extends BaseHelper +{ + private final NAME_FINDERS = [ + platform: [ + str: {name -> platMan.getPlatformByName(userVal, name)}, + int: {id -> platMan.getPlatformValueById(userVal, id)}], + platformType: [ + str: {name -> platMan.findPlatformTypeByName(name)}, + int: {id -> platMan.findPlatformTypeValueById(id)}], + ] + + private final ALL_FINDERS = [ + platforms: {platMan.getAllPlatforms(userVal, PageControl.PAGE_ALL)}, + ] + + ResourceHelper(user) { + super(user) + } + + private getPlatMan() { PlatformManagerEJBImpl.one } + + /** + * Generic method to find resources. The results are constrained by the + * authorization of the current user. The result objects are subclasses + * of AppdefResourceValue + * + * Examples: + * + * To find a platform by name: + * > find platform:'My Platform' + * + * To find a platform by id: + * > find platform:44123 + * + * To find all the platforms: + * > find all:'platforms' + */ + def find(args) { + if (args.containsKey('all')) { + return findAll(args) + } + findSingle(args) + } + + private def findAll(args) { + def type = args['all'] + if (!ALL_FINDERS.containsKey(type)) { + throw new IllegalArgumentException("Unknown resource type [$type]" + + ". Must be one of " + + ALL_FINDERS.keySet()); + } + ALL_FINDERS[type]() + } + + private def findSingle(args) { + def resourceType + for (i in args) { + if (NAME_FINDERS.containsKey(i.key)) { + if (resourceType != null) { + throw new IllegalArgumentException("Cannot specify more " + + "than one resource type [$resourceType] and " + + "[$i.key]") + } + resourceType = i.key + } + } + + if (resourceType == null) + throw new IllegalArgumentException("No resource type specified. "+ + "Must be one of " + + NAME_FINDERS.keySet()) + + def resourceVal = args[resourceType] + def argType = (resourceVal instanceof String) ? 'str' : 'int' + NAME_FINDERS[resourceType][argType](resourceVal) + } +} |