Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

APEX connects Jira

710 views

Published on

the presentation describes how to connect the issue tracker software atlassian jira with apex, using REST Webservices.
The slides were presented in Rotterdam at the APEX World conference in the netherlands.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

APEX connects Jira

  1. 1. APEX connects Jira Oliver Lemm APEX World 07.03.2016
  2. 2. Facts & Figures Independent Technology House with Cross-Industry Expertise Headquarter Ratingen (North Rhine – Westphalia) 240 Employees Founded 1994 Branches Dortmund, Cologne, Frankfurt Top Company for Trainees & Students Privately- Owned Corporation Oracle Platinum Partner 24 Mio. Euro Revenue 2
  3. 3. about me  Oliver Lemm  since february 2007 working for MT AG in Ratingen  Junior Consultant > Consultant > Senior Consultant > Competence Center Leader APEX & Service Center Leader APEX  Diploma applied computer science at the university of Duisburg-Essen  Projectleader, IT-Architect and Developer  working with Oracle Databases and Oracle Application Express since 2007  Blog http://oliverlemm.blogspot.de  Twitter https://twitter.com/OliverLemm 3
  4. 4. APEX Connect 26th – 28th April 2016 in Berlin Get your early-bird ticket now! APEX.DOAG.ORG#APEXCONN16
  5. 5. Agenda 1. Motivation 2. Jira 3. Webservices 4. JSON 5. Livedemo 5
  6. 6. Motivation „Working with one tool to handle the developing process, controlling and all other processes in one project“ „Calculating key figures based on Jira values which are not delivered by Jira itself.“ „Using integrated Jira Plugins and adding additional functionality by using APEX as known technology“ 6 requirements
  7. 7. Jira  https://www.atlassian.com/JIRA  Issue tracking and code integration  Supporting Dashboards & Plugins  perfect integration from Confluence (wiki) and Subversion (versioning)  supporting complex workflows  Issue import from Bugzilla, Mantis, GitHub, …  Supporting von REST-Webservices 7
  8. 8. 8
  9. 9. Jira 9 Workflow
  10. 10. Jira  supporting a huge number of attributes  time tracking (estimated, time spent, remaining)  Components (can be used for APEX pages and database objects)  versions  fields and screens adjustable per project  external issue numbers, date of commision, date of payment  Supporting own workflows  Describing a whole process, usable for non developing processes  Every step can be defined by user rights or issue dependencies  Using „JIRA Timesheet Reports and Gadgets Plugin“ 10 Integrated features
  11. 11. Jira  key figures not in desired aggregation  time per year/month  no further support for SOAP Webservices in Jira  SOAP Interface doesn‘t return all values  Using Jira-Plugins  Listed Plugins not fullfilling all requiremends  Developing own Jira-Plugins is complex and time consuming 11 lack of features
  12. 12. Jira  API documentation for Jira REST-Webservices https://docs.atlassian.com/jira/REST/latest/  URL structure  http://host:port/context/rest/api-name/api-version/resource-name  Using an issue identfiied by the key JRA-9 would be like:  https://jira.atlassian.com/rest/api/latest/issue/JRA-9  Using JQL Language (syntax) https://jira.mt-ag.com/rest/api/2/search?jql=project=BP  Returning values in JSON Format (testable also in browser) 12 REST-Webservice
  13. 13. Jira 13 JQL https://jira.mt-ag.com/rest/api/2/search?jql=project=BP
  14. 14. Jira  addional information when getting REST-Webservice Result  Default max 50 entries  1. solution: add parameter &maxResults=XXX  2. solution: add Parameter &startAt=50  Sort the results  If no Authentication needed, don‘t submit username/password -> you get Unauthorized (401) 14 REST-Webservice "expand":"schema,names","startAt":0,"maxResults":50,"total":827,"issues":[….]} https://jira.mt-ag.com/rest/api/latest/search?jql=project=BP&maxResults=1000 https://jira.mt-ag.com/rest/api/latest/search?jql=project=BP&startAt=50 https://jira.mt-ag.com/rest/api/latest/search?jql=project=BP+order+by+duedate
  15. 15. Webservices  getting Error:  Example: https://jira.atlassian.com/rest/api/latest/issue/JRA-9 15 ACL ORA-29273: HTTP request failed ORA-24247: network access denied by access control list (ACL) begin dbms_network_acl_admin.create_acl(acl => 'jira.atlassian.com.xml' ,description => 'An ACL for Calling REST Webservices.' ,principal => l_principal ,is_grant => true ,privilege => 'connect' ,start_date => systimestamp ,end_date => null); dbms_network_acl_admin.assign_acl(acl => 'jira.atlassian.com.xml' ,host => 'jira.atlassian.com' ,lower_port => 443 ,upper_port => 443); commit; end;
  16. 16. Webservices  Getting existing ACL Entries  Important for ACL  Using Web Service References (shared components or the APEX_WEB_SERVICE (package)  principal = APEX_050000  using utl_http or other packages calling external resources  principal = my_schema_name 16 ACL select a.acl ,a.host ,a.lower_port ,a.upper_port ,p.principal ,p.privilege ,p.is_grant ,to_char(p.start_date ,'DD-MON-YYYY') as start_date ,to_char(p.end_date ,'DD-MON-YYYY') as end_date from dba_network_acl_privileges p left join dba_network_acls a on a.acl = p.acl
  17. 17. Webservices 17 exporting certificate
  18. 18. Webservices  calling https:  To solve this problem, you have to get the certificates which are used by the server which runs Jira  Getting certificate  use your browser and call the URL from the REST-Webservice or even from Jira  click on the lock symbol  click show certificate 18 exporting certificate ORA-29273: HTTP request failed ORA-29024: Certificate validation failure
  19. 19. Webservices 19 importing certificate
  20. 20. Webservices  use the Oracle Wallet Manager (OWM) to import the certificate  run ORACLE_HOMEbinowm.cl (on windows a link is created)  Import of the certificate is also possible using the command line  create a wallet for the certificate using a path like this ORACLE_BASEadmin<SID><name_wallet>  Use automatic login for your wallet (otherwise you have to use the wallet always with your password in your plsql code) 20 importing certificate
  21. 21. Webservice  APEX documentation http://docs.oracle.com/cd/E59726_01/doc.50/e39151/adm_wrkspc002.htm#BABHEHAG  Login into your INTERNAL Workspace Manage Instance Instance Settings Wallet 21 certificate in APEX
  22. 22. Webservices  Shared Components  Web Service References  Create  Problems  based on single items  authentification  result as CLOB only in Collection. No support in  apex_items  report columns  JSON Format 23 Web Service Reference
  23. 23. Webservices 24 Web Service Reference
  24. 24. Webservice  Call REST  p_http_method GET, HEAD, POST, PUT, DELETE  Username & Password supporting Basic Authentication  Parameter if parameter beside the URL itself are needed 25 APEX_WEB_SERVICE l_clob := apex_web_service.make_rest_request( p_url => 'https://jira.atlassian.com/rest/api/latest/issue/JRA-9' ,p_http_method => 'GET' ,p_wallet_path => 'file:C:oracleadminorclmein_wallet' ,p_username => 'lemmo' ,p_password => '123456 '‚ ,p_parm_name => apex_util.string_to_table('param1:param2'), ,p_parm_value => apex_util.string_to_table('val1:val2') );
  25. 25. JSON  Datentypen  String  "QS - Demo Feature"  "2015-11-03T13:48:16.630+0100"  Number  20  Boolean  true / false  Null  null  Array  [ {…}, {…}] 26 format { "id": "17149", "self": "https://jira.mt-ag.com/rest/api/latest/issue/17149", "key": "BP-7", "fields": { “summary": "QS - Demo Feature", "progress": { "progress": ​19800, "total": ​19800, "percent": ​100 }, "created": "2015-11-03T13:48:16.630+0100", worklog": { "startAt": ​0, "maxResults": ​20, "total": ​2, "worklogs": [ { ... }, { ... } ] } } }
  26. 26. JSON  convert clob to JSON object  looping entries  get value 27 processing l_values apex_json.t_values; …. apex_json.parse(p_values => l_values ,p_source => l_clob); for i in 1 .. apex_json.get_count(p_values => l_values ,p_path => '.') loop … end loop l_jira_issue.key := apex_json.get_varchar2(p_values => pi_json_issue ,p_path => 'key'); l_jira_issue.timespent := apex_json.get_number(p_values => pi_json_issue ,p_path => 'fields.timespent');
  27. 27. JSON  Number as String  you have to convert  Datetime as String  Converting with apex_json.get_date doesn‘t work because of format  custom fields in Jira are named like customfield_xxxxx 28 special cases "id": "17149" "created": "2015-11-03T13:48:16.630+0100" l_timestamp := to_timestamp_tz(pi_string ,'YYYY-MM-DD"T"hh24:mi:ss.FF3TZHTZM'); l_string := to_char(l_timestamp ,'yyyy.mm.dd hh24:mi:ss'); l_date := to_date(l_string ,'yyyy.mm.dd hh24:mi:ss'); apex_json.get_varchar2(p_values => pi_json_issue ,p_path => 'fields.customfield_10000');
  28. 28. JSON  Time worked / Worklog not with information by day encapsuleted in issue  you have call the worklog for every single ticket by one REST Call 29 special cases for i in 1 .. apex_json.get_count(p_values => l_values, p_path => 'issues') loop l_rest_response := make_rest_request(pi_url => pi_jira_base_url || c_jira_rest_base_path || '/issue/' || apex_json.get_varchar2(p_values => l_values, p_path => 'issues[' || i || '].key' ,pi_username => pi_username ,pi_password => pi_password); apex_json.parse(p_values => l_values_issue, p_source => l_rest_response); l_jira_issue := get_issue_from_json(pi_json_issue => l_values_issue); for j in 1 .. apex_json.get_count(p_values => l_values_issue ,p_path => 'fields.worklog.worklogs') loop l_jira_issue_worklog := get_issue_worklog_from_json(pi_json_issue_worklog => l_values_issue ,pi_path => 'fields.worklog.worklogs[' || j || '].' ,pi_jira_issue_id => l_jira_issue.id ,pi_jira_issue_key => l_jira_issue.key); pipe row(l_jira_issue_worklog);
  29. 29. JSON  transform JSON into type  easier to use  Transformation in package instead APEX  testing possible by using sql  Entities defined as column names  documentation von CollectionSpalte – JSON – Spaltenname im Type  using table function based on defined types 30 processing create or replace type t_jira_issue force as object ( -- { id: "16276" -- c001 id number, -- Jira Issue ID -- { self: https://jira.mt- ag.com/rest/api/2/issue/16276 -- c003 url_json varchar2(32767), -- c003 - JSON URL -- { key: "UITFPP-1057„ -- c001 key varchar2(32767), -- Issue Key select * from table(jira_rest_ws_pkg.get_projects(pi_base_url => 'https://jira.atlassian.com'))
  30. 30. APEX  using APEX_COLLECTIONS  not every search means new webservice call  loading page doesn‘t call a webservice  APEX itself relies also on collections when working with Web Service References  problem authentication for webservice call  every call needs a username & password  using Web Service Reference it‘s inconvenient  using Application Items instead  when logging into the apex application password is saved on server-side by application item  attention the password value is visible in session state 31
  31. 31. APEX 32 Livedemo
  32. 32. Conclusion  complexity is huge because of many different technical aspects  all important key facts are calculateable  transforming JSON in JavaScript or PL/SQL is not easy in the beginning  first time parsing JSON even with APEX_JSON needs practice remember in 12c you can directly parse JSON by SQL  Using APEX integrated „Web Service Reference“ only for simple examples 33
  33. 33. @OliverLemm http://oliverlemm.blogspot.de/ http://de.linkedin.com/in/OliverLemm https://www.xing.com/profile/Oliver_Lemm Thanks!

×