com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.actions.manual
Class ManualTriggerAction

java.lang.Object
  extended by com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.actions.manual.ManualTriggerAction
All Implemented Interfaces:
hudson.ExtensionPoint, hudson.model.Action, hudson.model.ModelObject, hudson.model.RootAction

@Extension
public class ManualTriggerAction
extends Object
implements hudson.model.RootAction

RootAction for manually triggering a "Gerrit-build".

Author:
Robert Sandell <robert.sandell@sonyericsson.com>

Nested Class Summary
static class ManualTriggerAction.Approval
          Represents a "vote"-type or Approval of a change in the JSON structure.
static class ManualTriggerAction.HighLow
          A tuple of a high and a low number.
 
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
hudson.ExtensionPoint.LegacyInstancesAreScopedToHudson
 
Field Summary
static int EXPECTED_NR_OF_PARTS_IN_A_GENERATED_ID
          The expected number of parts separated by _ in a generated id.
static String ID_SEPARATOR
          The char that separates the different id components in a search-result-row.
 
Constructor Summary
ManualTriggerAction()
           
 
Method Summary
 void doBuild(String selectedIds, org.kohsuke.stapler.StaplerRequest request, org.kohsuke.stapler.StaplerResponse response)
          Builds the selected patch-set(s).
 void doGerritSearch(String queryString, String selectedServer, org.kohsuke.stapler.StaplerRequest request, org.kohsuke.stapler.StaplerResponse response)
          Does a search.
 String generateTheId(net.sf.json.JSONObject change, net.sf.json.JSONObject patch)
          Generates a "unique" id for the change and/or patch.
 ManualTriggerAction.HighLow getCodeReview(net.sf.json.JSONObject res)
          Finds the highest and lowest code review vote for the provided patch set.
 String getDisplayName()
           
 ArrayList<String> getEnabledServers()
          Returns the list of servers allowed to be queried and manually triggered.
 String getGerritUrl(net.sf.json.JSONObject change, String serverName)
          Generates the URL to the provided change in Gerrit If the change already has a URL provided, that URL will be used.
 String getIconFileName()
           
 String getJsUrl(String jsName)
          Gets the full path to the provided javascript file.
 List<hudson.model.ParameterValue> getParametersForPatchSet(net.sf.json.JSONObject jsonChange, net.sf.json.JSONObject jsonPatchSet, String serverName)
          Creates a list of the parameters as they would be in a scheduled build.
 hudson.security.Permission getRequiredPermission()
          Serves the permission required to perform this action.
 String getUrlName()
           
 ManualTriggerAction.HighLow getVerified(net.sf.json.JSONObject res)
          Finds the lowest and highest verified vote for the provided patch set.
 boolean hasEnabledServers()
          If this page/link is enabled or not, depending on whether at least one server is enabled.
 boolean hasUrl(hudson.model.ParameterValue parameterValue)
          Tells if the given parameter should have a URL or not.
 String toReadableHtml(String subject)
          Cuts the string to a max length of MAX_SUBJECT_STR_LENGTH and escapes unsafe HTML characters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXPECTED_NR_OF_PARTS_IN_A_GENERATED_ID

public static final int EXPECTED_NR_OF_PARTS_IN_A_GENERATED_ID
The expected number of parts separated by _ in a generated id. Each part is actually another id.

See Also:
generateTheId(net.sf.json.JSONObject, net.sf.json.JSONObject), Constant Field Values

ID_SEPARATOR

public static final String ID_SEPARATOR
The char that separates the different id components in a search-result-row.

See Also:
Constant Field Values
Constructor Detail

ManualTriggerAction

public ManualTriggerAction()
Method Detail

getIconFileName

public String getIconFileName()
Specified by:
getIconFileName in interface hudson.model.Action

getDisplayName

public String getDisplayName()
Specified by:
getDisplayName in interface hudson.model.Action
Specified by:
getDisplayName in interface hudson.model.ModelObject

getUrlName

public String getUrlName()
Specified by:
getUrlName in interface hudson.model.Action

hasEnabledServers

public boolean hasEnabledServers()
If this page/link is enabled or not, depending on whether at least one server is enabled.

Returns:
true if at least one server is enabled, false otherwise.
See Also:
IGerritHudsonTriggerConfig.isEnableManualTrigger()

getEnabledServers

public ArrayList<String> getEnabledServers()
Returns the list of servers allowed to be queried and manually triggered.

Returns:
the enabled server names

getRequiredPermission

public hudson.security.Permission getRequiredPermission()
Serves the permission required to perform this action. Used by index.jelly

Returns:
the permission.

getJsUrl

public String getJsUrl(String jsName)
Gets the full path to the provided javascript file. For use by jelly files to give to the client browser.

Parameters:
jsName - the javascript filename.
Returns:
the full path from the web-context root.

getCodeReview

public ManualTriggerAction.HighLow getCodeReview(net.sf.json.JSONObject res)
Finds the highest and lowest code review vote for the provided patch set.

Parameters:
res - the patch set.
Returns:
the highest and lowest code review vote for the patch set.

getVerified

public ManualTriggerAction.HighLow getVerified(net.sf.json.JSONObject res)
Finds the lowest and highest verified vote for the provided patch set.

Parameters:
res - the patch-set.
Returns:
the highest and lowest verified vote.

toReadableHtml

public String toReadableHtml(String subject)
Cuts the string to a max length of MAX_SUBJECT_STR_LENGTH and escapes unsafe HTML characters.

Parameters:
subject - the string to fix if needed.
Returns:
the fixed string.
See Also:
Util.escape(String)

doGerritSearch

public void doGerritSearch(@QueryParameter(value="queryString")
                           String queryString,
                           @QueryParameter(value="selectedServer")
                           String selectedServer,
                           org.kohsuke.stapler.StaplerRequest request,
                           org.kohsuke.stapler.StaplerResponse response)
                    throws IOException
Does a search.

Parameters:
queryString - the query to send to Gerrit.
request - the request.
selectedServer - the selected Gerrit server.
response - the response.
Throws:
IOException - if the query fails.

doBuild

public void doBuild(@QueryParameter(value="selectedIds")
                    String selectedIds,
                    org.kohsuke.stapler.StaplerRequest request,
                    org.kohsuke.stapler.StaplerResponse response)
             throws IOException
Builds the selected patch-set(s).

Parameters:
selectedIds - the selected rows in the form's search-result separated by "[]".
request - the request.
response - the response.
Throws:
IOException - if the query fails.

generateTheId

public String generateTheId(net.sf.json.JSONObject change,
                            net.sf.json.JSONObject patch)
Generates a "unique" id for the change and/or patch. So it can be identified as a single row in the search result.

Parameters:
change - the change.
patch - the patch-set in the change.
Returns:
the generated id.

getParametersForPatchSet

public List<hudson.model.ParameterValue> getParametersForPatchSet(net.sf.json.JSONObject jsonChange,
                                                                  net.sf.json.JSONObject jsonPatchSet,
                                                                  String serverName)
Creates a list of the parameters as they would be in a scheduled build. Without escaped quotes.

Parameters:
jsonChange - the JSON data for the change.
jsonPatchSet - the JSON data for the patch-set.
serverName - the name of the GerritServer from the current session.
Returns:
a list of the parameters.

hasUrl

public boolean hasUrl(hudson.model.ParameterValue parameterValue)
Tells if the given parameter should have a URL or not. i.e. if the parameter represents GerritTriggerParameters.GERRIT_CHANGE_URL.

Parameters:
parameterValue - the parameter.
Returns:
true if so.

getGerritUrl

public String getGerritUrl(net.sf.json.JSONObject change,
                           String serverName)
Generates the URL to the provided change in Gerrit If the change already has a URL provided, that URL will be used.

Parameters:
change - the change to link to.
serverName - the name of the selected Gerrit server.
Returns:
the URL to the change.


Copyright © 2004-2013. All Rights Reserved.