/src/main/resources/com/onresolve/jira/groovy/canned/admin/GetUser.groovy
Groovy | 96 lines | 79 code | 15 blank | 2 comment | 11 complexity | 556a08543db62c2bbea462a3c3312592 MD5 | raw file
- package com.onresolve.jira.groovy.canned.admin
-
- import com.atlassian.jira.ComponentManager
- import com.atlassian.jira.user.util.UserUtil
- import com.atlassian.jira.util.ErrorCollection
- import com.atlassian.jira.util.SimpleErrorCollection
- import com.onresolve.jira.groovy.canned.CannedScript
- import org.apache.log4j.Category
-
- public class GetUser implements CannedScript {
-
- Category log = Category.getInstance(GetUser.class)
- UserUtil userUtil = ComponentManager.getInstance().getUserUtil()
-
- public static final String FIELD_USER = 'FIELD_USER'
- public static final String FIELD_SOME_TEXT = 'FIELD_SOME_TEXT'
-
- public String getName() {
- "Gets a user and spits it out"
- }
-
- public String getDescription() {
- "do something desc III"
- }
-
- List getCategories() {
- ["ADMIN"]
- }
-
- public Boolean isFinalParamsPage(Map params) {
- log.debug("isFinalParamsPage: " + params.inspect())
- params[FIELD_USER]
- }
-
- public List getParameters(Map params) {
- log.debug("getParameters: " + params)
- if ( isFinalParamsPage(params) && (params.containsKey(FIELD_SOME_TEXT) || ! doValidate(params, false).hasAnyErrors())) {
- [
- [
- Name: FIELD_SOME_TEXT,
- Label: "SomethingEvenElse",
- Description: "Something even else ...",
- ],
- ]
- }
- else {
- [
- [
- Name: FIELD_USER,
- Label: "User",
- Description: "Enter the user id",
- Step: 1,
- ],
- ]
- }
- }
-
- ErrorCollection doValidate(Map params, boolean forPreview) {
- log.debug("validate params: $params")
- SimpleErrorCollection errorCollection = new SimpleErrorCollection()
- String userId = params[FIELD_USER] as String
- String someText = params[FIELD_SOME_TEXT] as String
-
- if(! userId) {
- errorCollection.addError(FIELD_USER, "enter a user")
- }
- else {
- if (! userUtil.getUser(userId)) {
- errorCollection.addError(FIELD_USER, "Invalid user")
- }
- }
-
- if (params.containsKey(FIELD_SOME_TEXT)) {
- if (!someText) {
- errorCollection.addError(FIELD_SOME_TEXT, "please enter text")
- }
- else if (someText.size() < 5) {
- errorCollection.addError(FIELD_SOME_TEXT, "please enter 5 chars")
- }
- }
-
- log.debug("doValidate: $errorCollection")
- errorCollection
- }
-
- Map doScript(Map params) {
- // magic goes here
- log.debug(params)
- // params["output"] = UserManager.getInstance().getUser(params["User"] as String).getFullName()
- params
- }
-
- String getDescription(Map params, boolean forPreview) {
- "Returns a user record... yada yada EEEE"
- }
- }