Coverage for oc_ocdm/counter_handler/counter_handler.py: 70%
20 statements
« prev ^ index » next coverage.py v6.5.0, created at 2025-05-30 22:05 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2025-05-30 22:05 +0000
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3# Copyright (c) 2016, Silvio Peroni <essepuntato@gmail.com>
4#
5# Permission to use, copy, modify, and/or distribute this software for any purpose
6# with or without fee is hereby granted, provided that the above copyright notice
7# and this permission notice appear in all copies.
8#
9# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
11# FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
12# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
13# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
14# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
15# SOFTWARE.
16from abc import ABC, abstractmethod
19class CounterHandler(ABC):
20 """Abstract class representing the interface for every concrete counter handler."""
22 @abstractmethod
23 def set_counter(self, new_value: int, entity_short_name: str, prov_short_name: str = "",
24 identifier: int = 1, supplier_prefix: str = "") -> None:
25 """
26 Method signature for concrete implementations that allow setting the counter value
27 of graph and provenance entities.
29 :param new_value: The new counter value to be set
30 :type new_value: int
31 :param entity_short_name: The short name associated either to the type of the entity itself
32 or, in case of a provenance entity, to the type of the relative graph entity.
33 :type entity_short_name: str
34 :param prov_short_name: In case of a provenance entity, the short name associated to the type
35 of the entity itself. An empty string otherwise.
36 :type prov_short_name: str
37 :param identifier: In case of a provenance entity, the counter value that identifies the relative
38 graph entity. The integer value '1' otherwise.
39 :type identifier: int
40 :raises NotImplementedError: always
41 :return: None
42 """
43 raise NotImplementedError
45 @abstractmethod
46 def read_counter(self, entity_short_name: str, prov_short_name: str = "", identifier: int = 1, supplier_prefix: str = "") -> int:
47 """
48 Method signature for concrete implementations that allow reading the counter value
49 of graph and provenance entities.
51 :param entity_short_name: The short name associated either to the type of the entity itself
52 or, in case of a provenance entity, to the type of the relative graph entity.
53 :type entity_short_name: str
54 :param prov_short_name: In case of a provenance entity, the short name associated to the type
55 of the entity itself. An empty string otherwise.
56 :type prov_short_name: str
57 :param identifier: In case of a provenance entity, the counter value that identifies the relative
58 graph entity. The integer value '1' otherwise.
59 :type identifier: int
60 :raises NotImplementedError: always
61 :return: The requested counter value.
62 """
63 raise NotImplementedError
65 @abstractmethod
66 def increment_counter(self, entity_short_name: str, prov_short_name: str = "", identifier: int = 1, supplier_prefix: str = "") -> int:
67 """
68 Method signature for concrete implementations that allow incrementing by one unit
69 the counter value of graph and provenance entities.
71 :param entity_short_name: The short name associated either to the type of the entity itself
72 or, in case of a provenance entity, to the type of the relative graph entity.
73 :type entity_short_name: str
74 :param prov_short_name: In case of a provenance entity, the short name associated to the type
75 of the entity itself. An empty string otherwise.
76 :type prov_short_name: str
77 :param identifier: In case of a provenance entity, the counter value that identifies the relative
78 graph entity. The integer value '1' otherwise.
79 :type identifier: int
80 :raises NotImplementedError: always
81 :return: The newly-updated (already incremented) counter value.
82 """
83 raise NotImplementedError
85 @abstractmethod
86 def set_metadata_counter(self, new_value: int, entity_short_name: str, dataset_name: str) -> None:
87 """
88 Method signature for concrete implementations that allow setting the counter value
89 of metadata entities.
91 :param new_value: The new counter value to be set
92 :type new_value: int
93 :param entity_short_name: The short name associated either to the type of the entity itself.
94 :type entity_short_name: str
95 :param dataset_name: In case of a ``Dataset``, its name. Otherwise, the name of the relative dataset.
96 :type dataset_name: str
97 :raises NotImplementedError: always
98 :return: None
99 """
100 raise NotImplementedError
102 @abstractmethod
103 def read_metadata_counter(self, entity_short_name: str, dataset_name: str) -> int:
104 """
105 Method signature for concrete implementations that allow reading the counter value
106 of metadata entities.
108 :param entity_short_name: The short name associated either to the type of the entity itself.
109 :type entity_short_name: str
110 :param dataset_name: In case of a ``Dataset``, its name. Otherwise, the name of the relative dataset.
111 :type dataset_name: str
112 :raises NotImplementedError: always
113 :return: The requested counter value.
114 """
115 raise NotImplementedError
117 @abstractmethod
118 def increment_metadata_counter(self, entity_short_name: str, dataset_name: str) -> int:
119 """
120 Method signature for concrete implementations that allow incrementing by one unit
121 the counter value of metadata entities.
123 :param entity_short_name: The short name associated either to the type of the entity itself.
124 :type entity_short_name: str
125 :param dataset_name: In case of a ``Dataset``, its name. Otherwise, the name of the relative dataset.
126 :type dataset_name: str
127 :raises NotImplementedError: always
128 :return: The newly-updated (already incremented) counter value.
129 """
130 raise NotImplementedError