Coverage for oc_ocdm / counter_handler / counter_handler.py: 70%
20 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-28 18:52 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-28 18:52 +0000
1#!/usr/bin/python
3# SPDX-FileCopyrightText: 2020-2022 Simone Persiani <iosonopersia@gmail.com>
4# SPDX-FileCopyrightText: 2024 Arcangelo Massari <arcangelo.massari@unibo.it>
5#
6# SPDX-License-Identifier: ISC
8# -*- coding: utf-8 -*-
9from abc import ABC, abstractmethod
12class CounterHandler(ABC):
13 """Abstract class representing the interface for every concrete counter handler."""
15 @abstractmethod
16 def set_counter(self, new_value: int, entity_short_name: str, prov_short_name: str = "",
17 identifier: int = 1, supplier_prefix: str = "") -> None:
18 """
19 Method signature for concrete implementations that allow setting the counter value
20 of graph and provenance entities.
22 :param new_value: The new counter value to be set
23 :type new_value: int
24 :param entity_short_name: The short name associated either to the type of the entity itself
25 or, in case of a provenance entity, to the type of the relative graph entity.
26 :type entity_short_name: str
27 :param prov_short_name: In case of a provenance entity, the short name associated to the type
28 of the entity itself. An empty string otherwise.
29 :type prov_short_name: str
30 :param identifier: In case of a provenance entity, the counter value that identifies the relative
31 graph entity. The integer value '1' otherwise.
32 :type identifier: int
33 :raises NotImplementedError: always
34 :return: None
35 """
36 raise NotImplementedError
38 @abstractmethod
39 def read_counter(self, entity_short_name: str, prov_short_name: str = "", identifier: int = 1, supplier_prefix: str = "") -> int:
40 """
41 Method signature for concrete implementations that allow reading the counter value
42 of graph and provenance entities.
44 :param entity_short_name: The short name associated either to the type of the entity itself
45 or, in case of a provenance entity, to the type of the relative graph entity.
46 :type entity_short_name: str
47 :param prov_short_name: In case of a provenance entity, the short name associated to the type
48 of the entity itself. An empty string otherwise.
49 :type prov_short_name: str
50 :param identifier: In case of a provenance entity, the counter value that identifies the relative
51 graph entity. The integer value '1' otherwise.
52 :type identifier: int
53 :raises NotImplementedError: always
54 :return: The requested counter value.
55 """
56 raise NotImplementedError
58 @abstractmethod
59 def increment_counter(self, entity_short_name: str, prov_short_name: str = "", identifier: int = 1, supplier_prefix: str = "") -> int:
60 """
61 Method signature for concrete implementations that allow incrementing by one unit
62 the counter value of graph and provenance entities.
64 :param entity_short_name: The short name associated either to the type of the entity itself
65 or, in case of a provenance entity, to the type of the relative graph entity.
66 :type entity_short_name: str
67 :param prov_short_name: In case of a provenance entity, the short name associated to the type
68 of the entity itself. An empty string otherwise.
69 :type prov_short_name: str
70 :param identifier: In case of a provenance entity, the counter value that identifies the relative
71 graph entity. The integer value '1' otherwise.
72 :type identifier: int
73 :raises NotImplementedError: always
74 :return: The newly-updated (already incremented) counter value.
75 """
76 raise NotImplementedError
78 @abstractmethod
79 def set_metadata_counter(self, new_value: int, entity_short_name: str, dataset_name: str) -> None:
80 """
81 Method signature for concrete implementations that allow setting the counter value
82 of metadata entities.
84 :param new_value: The new counter value to be set
85 :type new_value: int
86 :param entity_short_name: The short name associated either to the type of the entity itself.
87 :type entity_short_name: str
88 :param dataset_name: In case of a ``Dataset``, its name. Otherwise, the name of the relative dataset.
89 :type dataset_name: str
90 :raises NotImplementedError: always
91 :return: None
92 """
93 raise NotImplementedError
95 @abstractmethod
96 def read_metadata_counter(self, entity_short_name: str, dataset_name: str) -> int:
97 """
98 Method signature for concrete implementations that allow reading the counter value
99 of metadata entities.
101 :param entity_short_name: The short name associated either to the type of the entity itself.
102 :type entity_short_name: str
103 :param dataset_name: In case of a ``Dataset``, its name. Otherwise, the name of the relative dataset.
104 :type dataset_name: str
105 :raises NotImplementedError: always
106 :return: The requested counter value.
107 """
108 raise NotImplementedError
110 @abstractmethod
111 def increment_metadata_counter(self, entity_short_name: str, dataset_name: str) -> int:
112 """
113 Method signature for concrete implementations that allow incrementing by one unit
114 the counter value of metadata entities.
116 :param entity_short_name: The short name associated either to the type of the entity itself.
117 :type entity_short_name: str
118 :param dataset_name: In case of a ``Dataset``, its name. Otherwise, the name of the relative dataset.
119 :type dataset_name: str
120 :raises NotImplementedError: always
121 :return: The newly-updated (already incremented) counter value.
122 """
123 raise NotImplementedError