diff --git a/requests/correcting_replication_service.py b/requests/correcting_replication_service.py new file mode 100644 index 0000000..e0def4f --- /dev/null +++ b/requests/correcting_replication_service.py @@ -0,0 +1,61 @@ +from datetime import datetime, timedelta +from enumerations import ReplicationPackageStatusEnum +from models import CorrectingReplicationOutPackage, ReplicantInfo +from typing import List + + +class CorrectingReplicationService: + EVENT_TYPE: str = 'correcting_replication' + object_list_size: int = 0 + deleted_objects_count: int = 0 + PACKAGE_TAG_NAME: str = 'package' + PACKAGE_ID_ATTRIBUTE_NAME: str = 'pkg_id' + SERVER_VERSION_ATTRIBUTE_NAME: str = 'server_version' + SERVER_ID_ATTRIBUTE_NAME: str = 'server_id' + OBJECTS_TAG_NAME: str = 'objects' + OBJECT_TAG_NAME: str = 'object' + OBJECT_ID_ATTRIBUTE_NAME: str = 'id' + IS_RSC_OBJECT: str = 'is_rsc' + OBJECT_SOURCE_ATTRIBUTE_NAME: str = 'source' + OBJECT_VERSION_ATTRIBUTE_NAME: str = 'version' + METADATA_VERSION_ATTRIBUTE_NAME: str = 'md_version' + ACTUAL_VERSION_DATE_ATTRIBUTE_NAME: str = 'version_date' + OBJECT_MISSING_ATTRIBUTE_NAME: str = 'missing' + CLASSIFIER_VERSION_ATTRIBUTE_NAME: str = 'metadata_clientVersion' + RESULT_TAG_NAME: str = 'result' + RESULT_MESSAGE_ATTRIBUTE_NAME: str = 'result_message' + VERSION_ID_ATTRIBUTE_NAME: str = 'version_id' + VERSION_SOURCE_ATTRIBUTE_NAME: str = 'version_source' + + def start_correcting_replication(self, replicant_id: str, replication_period: int, replication_timeout: int, + manual_run: bool): + replicant = ReplicantInfo() + self.start_correcting_replication(replicant, replication_period, replication_timeout, manual_run) + + def start_correcting_replication(self, except_replicant_id: List[str], replication_period: int, + replication_timeout: int, manual_run: bool): + pass + + def start_correcting_replication(self, replicant: ReplicantInfo, replication_period: int, replication_timeout: int, + manual_run: bool): + pass + + def create_replication_package(self, replicant: ReplicantInfo, replication_period: int, replication_timeout: int) -> CorrectingReplicationOutPackage: + pkg = CorrectingReplicationOutPackage() + pkg.filter_string = replicant.filter_string + pkg.replicant_id = replicant.replicant_id + pkg.server_address = replicant.server_address + pkg.replication_period = replication_period + pkg.replication_timeout = replication_timeout + pkg.status = ReplicationPackageStatusEnum.SENT_REQUEST_TO_CHILD + date = datetime.now() + pkg.replication_date = date + if replication_period: + delta = timedelta(days=-replication_period) + pkg.from_date = date + delta + if replication_timeout: + delta = timedelta(seconds=replication_timeout) + pkg.replication_timeout_date = date + delta + return pkg + + def get_package_xml(self) -> str: \ No newline at end of file diff --git a/requests/enumerations.py b/requests/enumerations.py new file mode 100644 index 0000000..b55aa0d --- /dev/null +++ b/requests/enumerations.py @@ -0,0 +1,10 @@ +from enum import Enum + + +class ReplicationPackageStatusEnum(Enum): + CANCELLED = -4 + TIMEDOUT = -3 + ERROR = -2 + SENT_REQUEST_TO_CHILD = 1 + SENT_PACKAGE_TO_CHILD = 2 + COMPLETED = 3 diff --git a/requests/models.py b/requests/models.py new file mode 100644 index 0000000..e7f21c9 --- /dev/null +++ b/requests/models.py @@ -0,0 +1,23 @@ +from datetime import datetime + + +class ReplicantInfo: + server_address: str + filter_string: str + replicant_id: str + replicant_user_id: str + replicate_classifiers: bool + + +class CorrectingReplicationOutPackage: + package_id: int + status: int + from_date: datetime + replication_date: datetime + replication_timeout_date: datetime + end_date: datetime + replicant_id: str + server_address: str + filter_string: str + replication_period: int + replication_timeout: int