| 4237 |
dpurdie |
1 |
<%@LANGUAGE="VBSCRIPT"%>
|
|
|
2 |
<%
|
|
|
3 |
'=====================================================
|
|
|
4 |
' Jira Issues Enquiry
|
|
|
5 |
' Designed to be called via AJAX and to return
|
|
|
6 |
' JSON formatted data to dynamic page
|
|
|
7 |
'=====================================================
|
|
|
8 |
%>
|
|
|
9 |
<%
|
|
|
10 |
Option explicit
|
|
|
11 |
' Good idea to set when using redirect
|
|
|
12 |
Response.Expires = 0 ' always load the page, dont store
|
|
|
13 |
%>
|
|
|
14 |
<!--#include file="common/conf.asp"-->
|
|
|
15 |
<!--#include file="common/globals.asp"-->
|
|
|
16 |
<!--#include file="common/qstr.asp"-->
|
|
|
17 |
<!--#include file="common/common_subs.asp"-->
|
|
|
18 |
<!--#include file="common/formating.asp"-->
|
| 4254 |
dpurdie |
19 |
<SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="common/base64encode.vbs"></SCRIPT>
|
|
|
20 |
<SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="class/classaspJSON.vbs"></SCRIPT>
|
| 4237 |
dpurdie |
21 |
<%
|
|
|
22 |
'------------ Variable Definition -------------
|
|
|
23 |
Dim parOpr
|
|
|
24 |
Dim parPv_id
|
|
|
25 |
Dim result
|
|
|
26 |
Dim iJSON,jJSON, el, this, post, newitem
|
|
|
27 |
Dim allIssues
|
|
|
28 |
|
|
|
29 |
' Basic Parameters
|
|
|
30 |
parOpr = QStrPar("Opr")
|
|
|
31 |
parPv_id = QStrPar("pv_id")
|
|
|
32 |
result = -1
|
|
|
33 |
post = "None"
|
|
|
34 |
|
|
|
35 |
' Init the output JSON class
|
|
|
36 |
' Operations can add data
|
|
|
37 |
' Default data will be added at the end
|
|
|
38 |
Dim oJSON
|
|
|
39 |
Set oJSON = New aspJSON
|
|
|
40 |
|
|
|
41 |
'
|
|
|
42 |
' getIssues - Get issues for the current PV_ID and create a hash
|
|
|
43 |
'
|
|
|
44 |
Sub getIssues
|
|
|
45 |
Set allIssues = CreateObject ("Scripting.Dictionary")
|
|
|
46 |
Dim rsTemp, sqlstr, key
|
|
|
47 |
sqlstr = "SELECT iss_key FROM JIRA_ISSUES WHERE pv_id="& parPv_id
|
|
|
48 |
Set rsTemp = OraDatabase.DbCreateDynaset( sqlstr, cint(0))
|
|
|
49 |
While ((NOT rsTemp.BOF) AND (NOT rsTemp.EOF))
|
|
|
50 |
key = rsTemp("iss_key")
|
|
|
51 |
If NOT allIssues.Exists(key) Then
|
|
|
52 |
allIssues.add key, 1
|
|
|
53 |
End If
|
|
|
54 |
rsTemp.MoveNext
|
|
|
55 |
WEnd
|
|
|
56 |
rsTemp.Close()
|
|
|
57 |
Set rsTemp = nothing
|
|
|
58 |
End Sub
|
|
|
59 |
|
|
|
60 |
'
|
|
|
61 |
' Determine the operation to be performed
|
|
|
62 |
'
|
|
|
63 |
If (parOpr = "getAllKeys") Then
|
|
|
64 |
|
|
|
65 |
' Examine the Jira subsystem and determine ALL available project keys
|
|
|
66 |
' Return an HTML string that is a <select></select> box
|
|
|
67 |
' This is designed to be inserted into an element
|
|
|
68 |
'
|
|
|
69 |
result = 0
|
|
|
70 |
|
|
|
71 |
'
|
|
|
72 |
Dim objXML, qry
|
|
|
73 |
qry = "/rest/api/2/project"
|
|
|
74 |
|
|
|
75 |
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
|
| 5375 |
dpurdie |
76 |
objXML.Open "GET", Application("JIRA_URL") & qry, false
|
|
|
77 |
objXML.setRequestHeader "Authorization", "Basic " & Base64Encode(Application("JIRA_CREDENTIALS"))
|
| 4237 |
dpurdie |
78 |
On Error Resume Next
|
|
|
79 |
objXML.Send("")
|
|
|
80 |
if Err.Number <> 0 then
|
|
|
81 |
result = 1
|
|
|
82 |
oJSON.data("emsgSummary") = Err.Description
|
|
|
83 |
On Error Goto 0
|
|
|
84 |
else
|
|
|
85 |
On Error Goto 0
|
| 4988 |
dpurdie |
86 |
If objXML.status = 403 then
|
| 4237 |
dpurdie |
87 |
result = 1
|
| 4988 |
dpurdie |
88 |
oJSON.data("emsgSummary") = "Jira Server Access Denied"
|
|
|
89 |
|
|
|
90 |
ElseIf objXML.status <> 200 then
|
|
|
91 |
result = 1
|
| 4237 |
dpurdie |
92 |
oJSON.data("emsgSummary") = objXML.responseText
|
|
|
93 |
Else
|
|
|
94 |
Set jJSON = New aspJSON
|
|
|
95 |
jJSON.loadJSON( objXML.responseText )
|
|
|
96 |
|
|
|
97 |
oJSON.data("keyListCount") = jJSON.data.Count
|
|
|
98 |
|
|
|
99 |
Dim str
|
|
|
100 |
str = "<select id='keyListSelect'>"
|
|
|
101 |
For Each el In jJSON.data
|
|
|
102 |
Set this = jJSON.data.item(el)
|
|
|
103 |
str = str & "<option value='"&this.item("key")&"'>" &_
|
|
|
104 |
this.item("key") & ":" & this.item("name") &_
|
|
|
105 |
"</option>"
|
|
|
106 |
Next
|
|
|
107 |
str = str & "</select>"
|
|
|
108 |
end if
|
|
|
109 |
end if
|
|
|
110 |
oJSON.data("keyList") = str
|
|
|
111 |
'
|
|
|
112 |
' getIssues
|
|
|
113 |
ElseIf (parOpr = "getIssues") Then
|
|
|
114 |
Dim project, projectList, issues, issueList, query, order, parCount, parStartAt
|
|
|
115 |
getIssues()
|
|
|
116 |
project = QStrPar("Project")
|
|
|
117 |
issues = QStrPar("Issue")
|
|
|
118 |
parStartAt = QStrPar("StartAt")
|
|
|
119 |
parCount = QStrPar("Count")
|
|
|
120 |
|
|
|
121 |
qry = "/rest/api/2/search"
|
|
|
122 |
order = " ORDER BY key DESC"
|
|
|
123 |
|
|
|
124 |
projectList = ""
|
|
|
125 |
If project = "ALL" Then
|
|
|
126 |
projectList = ""
|
|
|
127 |
Else
|
|
|
128 |
projectList = "project=" & project
|
|
|
129 |
End If
|
|
|
130 |
|
|
|
131 |
' Convert comma or space seperated list into and 'IN' query
|
|
|
132 |
issueList = ""
|
|
|
133 |
Dim aList, entry, del
|
|
|
134 |
If issues <> "ALL" AND issues <> "" AND project <> "ALL" Then
|
|
|
135 |
issueList = issueList & " AND key in ("
|
|
|
136 |
del = ""
|
|
|
137 |
issues = Replace(issues ," ",",",1,-1)
|
|
|
138 |
aList = Split(issues, ",")
|
|
|
139 |
For Each entry in aList
|
|
|
140 |
If entry <> "" Then
|
|
|
141 |
issueList = issueList & del & project & "-" & entry
|
|
|
142 |
del = ","
|
|
|
143 |
End If
|
|
|
144 |
Next
|
|
|
145 |
issueList = issueList & ")"
|
|
|
146 |
End If
|
|
|
147 |
|
|
|
148 |
' Create the JSON input via code
|
|
|
149 |
' Can do it as a string, as thats all we want
|
|
|
150 |
set iJSON = New aspJSON
|
|
|
151 |
With iJSON.data
|
|
|
152 |
.Add "jql", projectList & issueList & order
|
|
|
153 |
.Add "validateQuery", "false"
|
|
|
154 |
.Add "startAt", CStr(parStartAt)
|
|
|
155 |
.Add "maxResults", CStr(parCount)
|
|
|
156 |
.Add "fields", iJSON.Collection()
|
|
|
157 |
With .item("fields")
|
|
|
158 |
.Add 0, "key"
|
|
|
159 |
.Add 1, "summary"
|
|
|
160 |
.Add 2, "status"
|
|
|
161 |
.Add 3, "priority"
|
|
|
162 |
.Add 4, "issuetype"
|
|
|
163 |
End With
|
|
|
164 |
End With
|
|
|
165 |
post = iJSON.JSONoutput()
|
|
|
166 |
|
|
|
167 |
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
|
| 5375 |
dpurdie |
168 |
objXML.Open "POST", Application("JIRA_URL") & qry , false
|
|
|
169 |
objXML.setRequestHeader "Authorization", "Basic " & Base64Encode(Application("JIRA_CREDENTIALS"))
|
| 4237 |
dpurdie |
170 |
objXML.setRequestHeader "Content-Type", "application/json"
|
|
|
171 |
On Error Resume Next
|
|
|
172 |
objXML.Send(post)
|
|
|
173 |
if Err.Number <> 0 then
|
|
|
174 |
result = 1
|
|
|
175 |
oJSON.data("emsgSummary") = Err.Description
|
|
|
176 |
On Error Goto 0
|
|
|
177 |
else
|
|
|
178 |
On Error Goto 0
|
|
|
179 |
If objXML.status = 400 then
|
|
|
180 |
result = 1
|
|
|
181 |
Set jJSON = New aspJSON
|
|
|
182 |
jJSON.loadJSON( objXML.responseText )
|
|
|
183 |
oJSON.data("emsgSummary") = jJSON.data("errorMessages").item(0)
|
|
|
184 |
|
| 4988 |
dpurdie |
185 |
ElseIf objXML.status = 403 then
|
|
|
186 |
result = 1
|
|
|
187 |
oJSON.data("emsgSummary") = "Jira Server Access Denied"
|
|
|
188 |
|
| 4237 |
dpurdie |
189 |
ElseIf objXML.status <> 200 then
|
|
|
190 |
result = 1
|
|
|
191 |
oJSON.data("emsgSummary") = objXML.responseText
|
|
|
192 |
Else
|
|
|
193 |
Set jJSON = New aspJSON
|
|
|
194 |
jJSON.loadJSON( objXML.responseText )
|
|
|
195 |
|
|
|
196 |
' Response.Write "<br>Pretty JSON display<pre>"
|
|
|
197 |
' Response.Write jJSON.JSONoutput()
|
|
|
198 |
' Response.Write "</pre>"
|
|
|
199 |
'
|
|
|
200 |
|
|
|
201 |
oJSON.data("issueCount") = jJSON.data("total")
|
|
|
202 |
oJSON.data("startAt") = jJSON.data("startAt")
|
|
|
203 |
oJSON.data("maxResults") = jJSON.data("maxResults")
|
|
|
204 |
|
|
|
205 |
Set oJSON.data("issues") = oJSON.Collection()
|
|
|
206 |
|
|
|
207 |
' Select the fields to be returned
|
|
|
208 |
Dim fields
|
|
|
209 |
'On Error Resume Next
|
|
|
210 |
For Each el In jJSON.data("issues")
|
|
|
211 |
Set this = jJSON.data("issues").item(el)
|
|
|
212 |
Set fields = this.item("fields")
|
|
|
213 |
|
|
|
214 |
Set newitem = oJSON.AddToCollection(oJSON.data("issues"))
|
|
|
215 |
newitem.add "key",this.item("key")
|
| 5375 |
dpurdie |
216 |
newitem.add "url",Application("JIRA_URL") & "/browse/" & this.item("key")
|
| 4237 |
dpurdie |
217 |
newitem.add "statusIcon",fields.item("status").item("iconUrl")
|
|
|
218 |
newitem.add "status",fields.item("status").item("name")
|
|
|
219 |
newitem.add "issuetypeIcon",fields.item("issuetype").item("iconUrl")
|
|
|
220 |
newitem.add "issuetype",fields.item("issuetype").item("name")
|
|
|
221 |
newitem.add "priorityIcon",fields.item("priority").item("iconUrl")
|
|
|
222 |
newitem.add "priority",fields.item("priority").item("name")
|
|
|
223 |
newitem.add "summary",fields.item("summary")
|
|
|
224 |
|
|
|
225 |
If allIssues.Exists(this.item("key")) Then
|
|
|
226 |
newitem.add "inuse",1
|
|
|
227 |
End If
|
|
|
228 |
Next
|
|
|
229 |
result = 0
|
|
|
230 |
end if
|
|
|
231 |
end if
|
|
|
232 |
'
|
|
|
233 |
' insertIssues
|
|
|
234 |
' Insert Issues into the Release Manager entry
|
|
|
235 |
'
|
|
|
236 |
ElseIf (parOpr = "insertIssues") Then
|
|
|
237 |
issues = QStrPar("Issue")
|
|
|
238 |
If parPv_id = "" OR issues = "" Then
|
|
|
239 |
result = 1
|
|
|
240 |
oJSON.data("emsgSummary") = "Action called with invalid arguments." & parPv_id & issues
|
|
|
241 |
Else
|
|
|
242 |
Dim SqlQry, issArr , iss_id, rsQry
|
|
|
243 |
issArr = Split ( issues, ",")
|
|
|
244 |
|
|
|
245 |
objEH.ErrorRedirect = FALSE
|
|
|
246 |
objEH.TryORA ( OraSession )
|
|
|
247 |
On Error Resume Next
|
|
|
248 |
|
|
|
249 |
' Import issues if they do not already exist
|
|
|
250 |
For Each iss_id In issArr
|
|
|
251 |
If Err.Number = 0 Then
|
|
|
252 |
SqlQry = "SELECT * FROM JIRA_ISSUES WHERE pv_id=" & parPv_id & " AND iss_key='"& LTrim(iss_id) & "'"
|
|
|
253 |
Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
|
|
|
254 |
OraDatabase.ExecuteSQL SqlQry
|
|
|
255 |
If ((rsQry.BOF) OR (rsQry.EOF)) Then
|
|
|
256 |
SqlQry = " INSERT INTO JIRA_ISSUES ( pv_id, iss_key, date_time_stamp )" &_
|
|
|
257 |
" VALUES ( " & parPv_id & ", '"& LTrim(iss_id) &"', "& ORA_SYSDATETIME &")"
|
|
|
258 |
OraDatabase.ExecuteSQL SqlQry
|
|
|
259 |
|
|
|
260 |
If Err.Number = 0 Then
|
|
|
261 |
SqlQry = "BEGIN Log_Action ( "& parPv_id &", 'jira_issue_added', "& objAccessControl.UserId &", 'Issue number: "& LTrim(iss_id) &"' ); END;"
|
|
|
262 |
OraDatabase.ExecuteSQL SqlQry
|
|
|
263 |
End If
|
|
|
264 |
Set rsQry = nothing
|
|
|
265 |
End If
|
|
|
266 |
End If
|
|
|
267 |
Next
|
|
|
268 |
|
|
|
269 |
' SQL error detection and reporting
|
|
|
270 |
objEH.CatchORA ( OraSession )
|
|
|
271 |
If objEH.LastOraFailed Then
|
|
|
272 |
result = 2
|
|
|
273 |
oJSON.data("error") = 1
|
|
|
274 |
|
|
|
275 |
oJSON.data("emsgSummary") = objEH.MessageSummary
|
|
|
276 |
oJSON.data("emsgDetails") = objEH.MessageDetails
|
|
|
277 |
oJSON.data("SqlQry") = SqlQry
|
|
|
278 |
Else
|
|
|
279 |
result = 0
|
|
|
280 |
End If
|
|
|
281 |
End If
|
|
|
282 |
Else
|
|
|
283 |
oJSON.data("emsgSummary") = "Unknown operation requested:" & parOpr
|
|
|
284 |
End If
|
|
|
285 |
|
|
|
286 |
'
|
|
|
287 |
' Create JSON data for the user
|
|
|
288 |
' Important fields
|
|
|
289 |
' result
|
|
|
290 |
'
|
|
|
291 |
' Debug fields
|
|
|
292 |
' Request (Array)
|
|
|
293 |
'
|
|
|
294 |
'Write single value
|
|
|
295 |
oJSON.data("result") = result
|
|
|
296 |
|
|
|
297 |
' DEBUG: An array of the user provided requests
|
|
|
298 |
oJSON.data("JiraPost") = post
|
|
|
299 |
Set oJSON.data("Request") = oJSON.Collection()
|
|
|
300 |
Set newitem = oJSON.AddToCollection(oJSON.data("Request"))
|
|
|
301 |
Dim variableName
|
|
|
302 |
for each variableName in Request.QueryString
|
|
|
303 |
newitem.add variableName, Request.QueryString(variableName)
|
|
|
304 |
next
|
|
|
305 |
|
|
|
306 |
'Return the object
|
|
|
307 |
Response.Write oJSON.JSONoutput()
|
|
|
308 |
%>
|