aboutsummaryrefslogtreecommitdiffstats
path: root/ydb/core/cms/cms_tx_reject_notification.cpp
blob: 5612dd9fbb1f50c96c7435ed29a75bbf9588649c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "cms_impl.h"
#include "scheme.h"

#include <google/protobuf/text_format.h>

namespace NKikimr {
namespace NCms {

class TCms::TTxRejectNotification : public TTransactionBase<TCms> {
public:
    TTxRejectNotification(TCms *self, TEvCms::TEvManageNotificationRequest::TPtr ev)
        : TBase(self)
        , Event(ev)
    {
    }

    bool Execute(TTransactionContext &txc, const TActorContext &ctx) override
    {
        LOG_DEBUG(ctx, NKikimrServices::CMS, "TTxRejectNotification Execute");

        auto &rec = Event->Get()->Record;
        Response = new TEvCms::TEvManageNotificationResponse;

        auto &id = rec.GetNotificationId();
        const TString &user = rec.GetUser();
        bool dry = rec.GetDryRun();

        TErrorInfo error;
        if (Self->RemoveNotification(id, user, !dry, error)) {
            if (!dry) {
                Self->AuditLog(ctx, TStringBuilder() << "Remove notification"
                    << ": id# " << id
                    << ", reason# " << "explicit remove");

                NIceDb::TNiceDb db(txc.DB);
                db.Table<Schema::Notification>().Key(id).Delete();
            }

            Response->Record.MutableStatus()->SetCode(NKikimrCms::TStatus::OK);
        } else {
            Response->Record.MutableStatus()->SetCode(error.Code);
            Response->Record.MutableStatus()->SetReason(error.Reason);
        }

        LOG_INFO(ctx, NKikimrServices::CMS, "Response status: %s %s",
                  ToString(Response->Record.GetStatus().GetCode()).data(),
                  Response->Record.GetStatus().GetReason().data());

        return true;
    }

    void Complete(const TActorContext &ctx) override
    {
        LOG_DEBUG(ctx, NKikimrServices::CMS, "TTxRejectNotification Complete");

        Self->Reply(Event, std::move(Response), ctx);
    }

private:
    TEvCms::TEvManageNotificationRequest::TPtr Event;
    TAutoPtr<TEvCms::TEvManageNotificationResponse> Response;
};

ITransaction *TCms::CreateTxRejectNotification(TEvCms::TEvManageNotificationRequest::TPtr &ev)
{
    return new TTxRejectNotification(this, ev.Release());
}

} // NCms
} // NKikimr