Class Jira4R::JiraTool
In: lib/jira4r/jira_tool.rb
Parent: Object

Methods

Attributes

enhanced  [RW] 

Public Class methods

Create a new JiraTool

where: version … the version of the SOAP API you wish to use - currently supported versions [ 2 ] base_url … the base URL of the JIRA instance - eg. confluence.atlassian.com

[Source]

    # File lib/jira4r/jira_tool.rb, line 15
15:     def initialize(version, base_url)
16:       @version = version
17:       @base_url = base_url  
18:       @logger = Logger.new(STDERR)
19:       @endpoint_url = "#{@base_url}/rpc/soap/jirasoapservice-v#{version}"
20:     end

Public Instance methods

Call a method on the driver, adding in the authentication token previously determined using login()

[Source]

    # File lib/jira4r/jira_tool.rb, line 63
63:     def call_driver(method_name, *args)
64:       @logger.debug("Finding method #{method_name}")
65:       method = driver().method(method_name)     
66:       
67:       if args.length > 0
68:         method.call(@token, *args)     
69:       else
70:         method.call(@token)
71:       end
72:     end

Retrieve the driver, creating as required.

[Source]

    # File lib/jira4r/jira_tool.rb, line 28
28:     def driver()
29:       if not @driver
30:         @logger.info( "Connecting driver to #{@endpoint_url}" )
31: 
32:         require "jira4r/v#{@version}/jiraService.rb"
33:         require "jira4r/v#{@version}/JiraSoapServiceDriver.rb"
34:         require "jira4r/v#{@version}/jiraServiceMappingRegistry.rb"
35:         
36:         service_classname = "Jira4R::V#{@version}::JiraSoapService"
37:         puts "Service: #{service_classname}"
38:         service = eval(service_classname)
39:         @driver = service.send(:new, @endpoint_url)
40:       end
41:       @driver
42:     end

[Source]

     # File lib/jira4r/jira_tool.rb, line 159
159:     def findEntityInPermissionMapping(permissionMapping, entityName)
160:       permissionMapping.remoteEntities.each { |entity|
161:             return entity if entity.name == entityName
162:           }
163:           return nil
164:         end

[Source]

     # File lib/jira4r/jira_tool.rb, line 151
151:     def findPermission(allowedPermissions, permissionName)
152:                 allowedPermissions.each { |allowedPermission|
153:                    #puts "Checking #{allowedPermission.name} against #{permissionName} "
154:                    return allowedPermission if allowedPermission.name == permissionName
155:                 }
156:                 return nil    
157:     end

[Source]

     # File lib/jira4r/jira_tool.rb, line 105
105:     def getGroup( groupName )
106:       begin
107:         return call_driver( "getGroup", groupName )
108:       rescue SOAP::FaultError => soap_error
109:         #XXX surely there is a better way to detect this kind of condition in the JIRA server
110:         if soap_error.faultcode.to_s == "soapenv:Server.userException" and soap_error.faultstring.to_s == "com.atlassian.jira.rpc.exception.RemoteValidationException: no group found for that groupName: #{groupName}"
111:           return nil
112:         else
113:           raise soap_error
114:         end
115:       end
116:     end

[Source]

     # File lib/jira4r/jira_tool.rb, line 131
131:     def getNotificationScheme( notificationSchemeName )
132:       self.getNotificationSchemes().each { |notification_scheme| 
133:         return notification_scheme if notification_scheme.name == notificationSchemeName
134:       }
135:       return nil
136:     end

[Source]

     # File lib/jira4r/jira_tool.rb, line 138
138:     def getPermission( permissionName )
139:       if not @permissions
140:         @permissions = self.getAllPermissions()
141:       end
142:       
143:       @permissions.each { |permission|
144:         return permission if permission.name.downcase == permissionName.downcase
145:       }
146:       
147:       @logger.warn("No permission #{permissionName} found")
148:       return nil
149:     end

[Source]

     # File lib/jira4r/jira_tool.rb, line 124
124:     def getPermissionScheme( permissionSchemeName )
125:       self.getPermissionSchemes().each { |permission_scheme| 
126:         return permission_scheme if permission_scheme.name == permissionSchemeName
127:       }
128:       return nil
129:     end

[Source]

    # File lib/jira4r/jira_tool.rb, line 86
86:     def getProject(key)
87:       #Jira > 3.10 has been patched to support this method directly as getProjectByKey
88:       puts "Using deprecated JIRA4R API call getProject(key); replace with getProjectByKey(key)"
89:       return getProjectByKey(key)
90:     end

[Source]

     # File lib/jira4r/jira_tool.rb, line 92
 92:     def getProjectByKey( projectKey )
 93:       begin
 94:         return call_driver( "getProjectByKey", projectKey )
 95:       rescue SOAP::FaultError => soap_error
 96:         #XXX surely there is a better way to detect this kind of condition in the JIRA server
 97:         if soap_error.faultcode.to_s == "soapenv:Server.userException" and soap_error.faultstring.to_s == "com.atlassian.jira.rpc.exception.RemoteException: Project: #{projectKey} does not exist"
 98:           return nil
 99:         else
100:           raise soap_error
101:         end
102:       end
103:     end

Retrieve a project without the associated PermissionScheme. This will be significantly faster for larger Jira installations. See: JRA-10660

[Source]

    # File lib/jira4r/jira_tool.rb, line 77
77:     def getProjectNoScheme(key)
78:       puts "getProjectNoScheme is deprecated. Please call getProjectNoSchemes."
79:       getProjectNoSchemes(key)
80:     end

[Source]

    # File lib/jira4r/jira_tool.rb, line 82
82:     def getProjectNoSchemes(key)
83:       self.getProjectsNoSchemes().find { |project| project.key == key }
84:     end

[Source]

     # File lib/jira4r/jira_tool.rb, line 118
118:     def getProjectRoleByName( projectRoleName )
119:       getProjectRoles.each{ |projectRole|
120:         return projectRole if projectRole.name == projectRoleName
121:       }
122:     end

Assign a new logger to the tool. By default a STDERR logger is used.

[Source]

    # File lib/jira4r/jira_tool.rb, line 23
23:     def logger=(logger)
24:       @logger = logger
25:     end

Login to the JIRA instance, storing the token for later calls.

This is typically the first call that is made on the JiraTool.

[Source]

    # File lib/jira4r/jira_tool.rb, line 53
53:     def login(username, password)
54:       @token = driver().login(username, password)
55:     end

Removes entity

[Source]

     # File lib/jira4r/jira_tool.rb, line 167
167:     def setPermissions( permissionScheme, allowedPermissions, entity)
168:       allowedPermissions = [ allowedPermissions ].flatten.compact
169:       #Remove permissions that are no longer allowed
170:       permissionScheme.permissionMappings.each { |mapping|
171:         next unless findEntityInPermissionMapping(mapping, entity.name)
172:       
173:         allowedPermission = findPermission(allowedPermissions, mapping.permission.name)
174:             if allowedPermission
175:               puts "Already has #{allowedPermission.name} in #{permissionScheme.name} for #{entity.name}"
176:                   allowedPermissions.delete(allowedPermission)
177:               next
178:             end
179: 
180:                 puts "Deleting #{mapping.permission.name} from #{permissionScheme.name} for #{entity.name}"
181:         deletePermissionFrom( permissionScheme, mapping.permission, entity)
182:       }
183:       
184:       puts allowedPermissions.inspect
185:       allowedPermissions.each { |allowedPermission|
186:                 puts "Granting #{allowedPermission.name} to #{permissionScheme.name} for #{entity.name}"
187:                 addPermissionTo(permissionScheme, allowedPermission, entity) 
188:           }   
189:     end

Clients should avoid using the authentication token directly.

[Source]

    # File lib/jira4r/jira_tool.rb, line 58
58:     def token()
59:       @token
60:     end

Assign a wiredump file prefix to the driver.

[Source]

    # File lib/jira4r/jira_tool.rb, line 45
45:     def wiredump_file_base=(base)
46:       driver().wiredump_file_base = base
47:     end

[Validate]