Commit 8546f2f4 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin Committed by Cédric Le Ninivin

erp5_api_style: Add alarm to check consistency of jio_api_revision documents

parent f4c47fc0
......@@ -101,6 +101,22 @@ class JIOAPIRevisionMixin:
)
return
security.declareProtected(Permissions.ManagePortal, 'markUnmatchingJIOAPIrevisionHash')
def markUnmatchingJIOAPIrevisionHash(self):
"""
Check if the calculated hash match the stored one.
If not set jio_api_revision timestamp to 0 to triger reprocessing by alarm
"""
calculated_hash = self._calculateHash()
_, stored_hash, _ = self._getJIOAPIRevisionTuple()
if calculated_hash != stored_hash:
# Marking jIO API revision timestamp to zero will trigger reprocessing
self.Base_zUpdateTimeStampjIOAPIRevisionTable(
uid=self.getUid(),
indexation_timestamp=0,
)
security.declareProtected(Permissions.AccessContentsInformation,
'checkJIOAPIRevisionConstraint')
def checkJIOAPIRevisionConstraint(self, **kw):
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Alarm" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_local_properties</string> </key>
<value>
<tuple>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>configuration_form_id</string> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>string</string> </value>
</item>
</dictionary>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>catalog_query_string</string> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>string</string> </value>
</item>
</dictionary>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>module_list</string> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>lines</string> </value>
</item>
</dictionary>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>incremental_check</string> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>int</string> </value>
</item>
</dictionary>
</tuple>
</value>
</item>
<item>
<key> <string>active_sense_method_id</string> </key>
<value> <string>Alarm_activateCheckAndFixUnmatchingJIOAPIRevisionHash</string> </value>
</item>
<item>
<key> <string>automatic_solve</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>catalog_query_string</string> </key>
<value> <string>validation_state:!=deleted</string> </value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>configuration_form_id</string> </key>
<value> <string>Alarm_viewConsistencyCheckConfiguration</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>jio_api_revision_check_consistency</string> </value>
</item>
<item>
<key> <string>incremental_check</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>module_list</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_day_frequency</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>periodicity_hour</string> </key>
<value>
<tuple>
<int>0</int>
</tuple>
</value>
</item>
<item>
<key> <string>periodicity_hour_frequency</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>periodicity_minute</string> </key>
<value>
<tuple>
<int>0</int>
</tuple>
</value>
</item>
<item>
<key> <string>periodicity_minute_frequency</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>periodicity_month</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_month_day</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_start_date</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1230768000.0</float>
<string>GMT</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>periodicity_week</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_week_day</string> </key>
<value>
<tuple>
<string>Sunday</string>
</tuple>
</value>
</item>
<item>
<key> <string>periodicity_week_frequency</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Alarm</string> </value>
</item>
<item>
<key> <string>report_method_id</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>solve_method_id</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>jIO API Revision Consistency Check</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
if not context.Base_zCheckjIOAPIRevisionTableExists():
context.Base_zCreatejIOAPIRevisionTable()
kw = {}
if context.getProperty('incremental_check'):
last_active_process = context.getLastActiveProcess(include_active=True)
if last_active_process is not None:
kw['indexation_timestamp'] = {
'query': last_active_process.getStartDate(),
'range': '>='
}
active_process = context.newActiveProcess().getRelativeUrl()
query_string = context.getProperty('catalog_query_string', '')
# the query sould be something like "validation_state:!=deleted validation_state:!=draft portal_type:Organisation" etc
portal = context.getPortalObject()
if query_string is not None:
kw.update(SearchableText=query_string)
parent_uid =[portal.restrictedTraverse(module).getUid()
for module in context.getProperty('module_list') or []]
if parent_uid:
kw.update(parent_uid=parent_uid)
portal.portal_catalog.searchAndActivate(
method_id='markUnmatchingJIOAPIrevisionHash',
activate_kw={'tag':tag, 'priority': 8},
**kw)
context.activate(after_tag=tag).getId()
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>tag, fixit=False, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Alarm_activateCheckAndFixUnmatchingJIOAPIRevisionHash</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal_alarms/jio_api_revision_check_consistency
portal_alarms/update_jio_api_revision_template
portal_callables/Base_asJSONTextFromJSON
web_page_module/api-style_alldocs-response-schema.json
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment