|
@@ -9,33 +9,71 @@
|
|
|
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
|
# specific language governing permissions and limitations under the License.
|
|
|
|
|
|
-from typing import Dict, Set
|
|
|
+from typing import Optional
|
|
|
|
|
|
+from ..data.data_node import DataNodeId
|
|
|
|
|
|
-class Reasons:
|
|
|
- def __init__(self, entity_id: str) -> None:
|
|
|
- self.entity_id: str = entity_id
|
|
|
- self._reasons: Dict[str, Set[str]] = {}
|
|
|
|
|
|
- def _add_reason(self, entity_id: str, reason: str) -> "Reasons":
|
|
|
- if entity_id not in self._reasons:
|
|
|
- self._reasons[entity_id] = set()
|
|
|
- self._reasons[entity_id].add(reason)
|
|
|
- return self
|
|
|
+class Reason:
|
|
|
+ """
|
|
|
+ TODO - NOT DOCUMENTED
|
|
|
+ """
|
|
|
+ def __init__(self, reason: str):
|
|
|
+ self.reason = reason
|
|
|
|
|
|
- def _remove_reason(self, entity_id: str, reason: str) -> "Reasons":
|
|
|
- if entity_id in self._reasons and reason in self._reasons[entity_id]:
|
|
|
- self._reasons[entity_id].remove(reason)
|
|
|
- if len(self._reasons[entity_id]) == 0:
|
|
|
- del self._reasons[entity_id]
|
|
|
- return self
|
|
|
+ def __str__(self):
|
|
|
+ return self.reason
|
|
|
|
|
|
- def _entity_id_exists_in_reason(self, entity_id: str) -> bool:
|
|
|
- return entity_id in self._reasons
|
|
|
+ def __repr__(self):
|
|
|
+ return self.reason
|
|
|
|
|
|
- def __bool__(self) -> bool:
|
|
|
- return len(self._reasons) == 0
|
|
|
+
|
|
|
+class _DataNodeReasonMixin:
|
|
|
+ def __init__(self, datanode_id: DataNodeId):
|
|
|
+ self.datanode_id = datanode_id
|
|
|
|
|
|
@property
|
|
|
- def reasons(self) -> str:
|
|
|
- return "; ".join("; ".join(reason) for reason in self._reasons.values()) + "." if self._reasons else ""
|
|
|
+ def datanode(self):
|
|
|
+ from ..data._data_manager_factory import _DataManagerFactory
|
|
|
+ return _DataManagerFactory._build_manager()._get(self.datanode_id)
|
|
|
+
|
|
|
+
|
|
|
+class DataNodeEditInProgress(Reason, _DataNodeReasonMixin):
|
|
|
+ """
|
|
|
+ TODO - NOT DOCUMENTED
|
|
|
+ """
|
|
|
+ def __init__(self, datanode_id: DataNodeId):
|
|
|
+ Reason.__init__(self, f"DataNode {datanode_id} is being edited")
|
|
|
+ _DataNodeReasonMixin.__init__(self, datanode_id)
|
|
|
+
|
|
|
+
|
|
|
+class DataNodeIsNotWritten(Reason, _DataNodeReasonMixin):
|
|
|
+ """
|
|
|
+ TODO - NOT DOCUMENTED
|
|
|
+ """
|
|
|
+ def __init__(self, datanode_id: DataNodeId):
|
|
|
+ Reason.__init__(self, f"DataNode {datanode_id} is not written")
|
|
|
+ _DataNodeReasonMixin.__init__(self, datanode_id)
|
|
|
+
|
|
|
+
|
|
|
+def _build_data_node_is_being_edited_reason(dn_id: DataNodeId) -> str:
|
|
|
+ return f"DataNode {dn_id} is not written"
|
|
|
+
|
|
|
+
|
|
|
+def _build_data_node_is_not_written(dn_id: DataNodeId) -> str:
|
|
|
+ return f"DataNode {dn_id} is not written"
|
|
|
+
|
|
|
+
|
|
|
+def _build_not_submittable_entity_reason(entity_id: str) -> str:
|
|
|
+ return f"Entity {entity_id} is not a submittable entity"
|
|
|
+
|
|
|
+
|
|
|
+def _build_wrong_config_type_reason(config_id: str, config_type: Optional[str]) -> str:
|
|
|
+ if config_type:
|
|
|
+ return f'Object "{config_id}" must be a valid {config_type}'
|
|
|
+
|
|
|
+ return f'Object "{config_id}" is not a valid config to be created'
|
|
|
+
|
|
|
+
|
|
|
+def _build_not_global_scope_reason(config_id: str) -> str:
|
|
|
+ return f'Data node config "{config_id}" does not have GLOBAL scope'
|