-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP][MIG] connector_jira: Migration to 17.0
- Loading branch information
Showing
104 changed files
with
3,554 additions
and
3,587 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,53 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import base | ||
from . import backend_adapter | ||
from . import binder | ||
from . import exporter | ||
from . import importer | ||
from . import mapper | ||
# ⚠️⚠️⚠️ | ||
# 1) in order to ease readability and maintainability, components have been split into | ||
# multiple files, each containing exactly 1 component | ||
# 2) components' import is sorted so that no dependency issue should arise | ||
# 3) next to each import, a comment will describe the components' dependencies | ||
# 4) when adding new components, please make sure it inherits (directly or indirectly) | ||
# from ``jira.base`` | ||
# ⚠️⚠️⚠️ | ||
|
||
# Base abstract component | ||
from . import jira_base # base.connector | ||
|
||
# Inheriting abstract components | ||
from . import jira_base_exporter # base.exporter, jira.base | ||
from . import jira_batch_importer # base.importer, jira.base | ||
from . import jira_delayed_batch_importer # jira.batch.importer | ||
from . import jira_direct_batch_importer # jira.batch.importer | ||
from . import jira_import_mapper # base.import.mapper, jira.base | ||
from . import jira_timestamp_batch_importer # base.importer, jira.base | ||
|
||
# Generic components | ||
from . import jira_binder # base.binder, jira.base | ||
from . import jira_deleter # base.deleter, jira.base | ||
from . import jira_exporter # jira.base.exporter | ||
from . import jira_importer # base.importer, jira.base | ||
from . import jira_webservice_adapter # base.backend.adapter.crud, jira.base | ||
|
||
# Specific components | ||
from . import jira_analytic_line_batch_importer # jira.timestamp.batch.importer | ||
from . import jira_analytic_line_importer # jira.importer | ||
from . import jira_analytic_line_mapper # jira.import.mapper | ||
from . import jira_analytic_line_timestamp_batch_deleter # base.synchronizer, jira.base | ||
from . import jira_backend_adapter # jira.webservice.adapter | ||
from . import jira_issue_type_adapter # jira.webservice.adapter | ||
from . import jira_issue_type_batch_importer # jira.direct.batch.importer | ||
from . import jira_issue_type_mapper # jira.import.mapper | ||
from . import jira_mapper_from_attrs # jira.base | ||
from . import jira_model_binder # base.binder, jira.base | ||
from . import jira_project_adapter # jira.webservice.adapter | ||
from . import jira_project_binder # jira.binder | ||
from . import jira_project_project_listener # base.connector.listener, jira.base | ||
from . import jira_project_project_exporter # jira.exporter | ||
from . import jira_project_task_adapter # jira.webservice.adapter | ||
from . import jira_project_task_batch_importer # jira.timestamp.batch.importer | ||
from . import jira_project_task_importer # jira.importer | ||
from . import jira_project_task_mapper # jira.import.mapper | ||
from . import jira_res_users_adapter # jira.webservice.adapter | ||
from . import jira_res_users_importer # jira.importer | ||
from . import jira_task_project_matcher # jira.base | ||
from . import jira_worklog_adapter # jira.webservice.adapter | ||
from . import project_project_listener # base.connector.listener, jira.base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
connector_jira/components/jira_analytic_line_batch_importer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Copyright 2016 Camptocamp SA | ||
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo.addons.component.core import Component | ||
|
||
from ..fields import MilliDatetime | ||
|
||
|
||
class JiraAnalyticLineBatchImporter(Component): | ||
"""Import the Jira worklogs | ||
For every ID in the list, a delayed job is created. | ||
Import is executed starting from a given date. | ||
""" | ||
|
||
_name = "jira.analytic.line.batch.importer" | ||
_inherit = "jira.timestamp.batch.importer" | ||
_apply_on = ["jira.account.analytic.line"] | ||
|
||
def _search(self, timestamp): | ||
unix_timestamp = MilliDatetime.to_timestamp(timestamp.last_timestamp) | ||
result = self.backend_adapter.updated_since(since=unix_timestamp) | ||
worklog_ids = self._filter_update(result.updated_worklogs) | ||
# We need issue_id + worklog_id for the worklog importer (the jira | ||
# "read" method for worklogs asks both), get it from yield_read. | ||
# TODO we might consider to optimize the import process here: | ||
# yield_read reads worklogs data, then the individual | ||
# import will do a request again (and 2 with the tempo module) | ||
next_timestamp = MilliDatetime.from_timestamp(result.until) | ||
return next_timestamp, self.backend_adapter.yield_read(worklog_ids) | ||
|
||
def _handle_records(self, records, force=False): | ||
number = 0 # Cannot use ``len(records)`` cause ``records`` is a generator | ||
for worklog in records: | ||
number += 1 | ||
self._import_record(worklog["issueId"], worklog["id"], force=force) | ||
return number | ||
|
||
def _filter_update(self, updated_worklogs): | ||
"""Filter only the worklogs needing an update | ||
The result from Jira contains the worklog id and | ||
the last update on Jira. So we keep only the worklog | ||
ids with a sync_date before the Jira last update. | ||
""" | ||
if not updated_worklogs: | ||
return [] | ||
self.env.cr.execute( | ||
""" | ||
SELECT external_id, jira_updated_at | ||
FROM jira_account_analytic_line | ||
WHERE external_id IN %s | ||
""", | ||
(tuple(str(r.worklog_id) for r in updated_worklogs),), | ||
) | ||
bindings = dict(self.env.cr.fetchall()) | ||
td, ft = MilliDatetime.to_datetime, MilliDatetime.from_timestamp | ||
worklog_ids = [] | ||
for worklog in updated_worklogs: | ||
worklog_id = worklog.worklog_id | ||
# we store the latest "updated_at" value on the binding | ||
# so we can check if we already know the latest value, | ||
# for instance because we imported the record from a | ||
# webhook before, we can skip the import | ||
binding_updated_at = bindings.get(str(worklog_id)) | ||
if not binding_updated_at or td(binding_updated_at) < ft(worklog.updated): | ||
worklog_ids.append(worklog_id) | ||
return worklog_ids | ||
|
||
def _import_record(self, issue_id, worklog_id, force=False, **kwargs): | ||
"""Delay the import of the records""" | ||
self.model.with_delay(**kwargs).import_record( | ||
self.backend_record, | ||
issue_id, | ||
worklog_id, | ||
force=force, | ||
) |
Oops, something went wrong.