Esempio n. 1
0
    def find_by_key_and_version(self, entity_name: str, key: str, version: str) -> Optional[AbstractBusinessEntity]:
        business_entity_class = BusinessEntityUtils.get_entity_class(entity_name)

        try:
            business_entity = business_entity_class.objects.get(key=key, version=version)
        except business_entity_class.DoesNotExist:
            business_entity = None

        return business_entity
Esempio n. 2
0
 def send_entity_create_message(self, entity: AbstractBusinessEntity, tags=None):
     if tags is None:
         tags = []
     self._send_message(
         EntityCreateMessage(
             BusinessEntityUtils.get_entity_type_name(entity),
             entity.key,
             entity.version,
             entity.data,
             entity.created,
             tags,
         )
     )
Esempio n. 3
0
    def update_or_create(
        self, entity_name: str, key: str, version: str, user: User, data: str
    ) -> (AbstractBusinessEntity, bool):
        business_entity_class = BusinessEntityUtils.get_entity_class(entity_name)
        business_entity, created = business_entity_class.objects.update_or_create(
            key=key, version=version, defaults={"key": key, "version": version, "publisher": user, "data": data}
        )

        if created:
            self._message_publisher.send_entity_create_message(business_entity)
        else:
            self._message_publisher.send_entity_update_message(business_entity)

        return created
Esempio n. 4
0
    def send_entity_delete_message(self, entity: AbstractBusinessEntity):
        delete_message = EntityDeleteMessage(
            BusinessEntityUtils.get_entity_type_name(entity), entity.key, entity.version
        )

        self._send_message(delete_message)
Esempio n. 5
0
 def delete_by_key(self, entity_name: str, key: str) -> int:
     business_entity_class = BusinessEntityUtils.get_entity_class(entity_name)
     return self.delete_by_queryset(business_entity_class.objects.filter(key=key))
Esempio n. 6
0
 def find_all(self, entity_name: str) -> QuerySet:
     business_entity_class = BusinessEntityUtils.get_entity_class(entity_name)
     return business_entity_class.objects.all()