aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/vespa/documentapi/messagebus/messages/removelocationmessage.cpp
blob: 05f16639edaa79e4f990f0a405f570cff0372fe3 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "removelocationmessage.h"
#include <vespa/documentapi/messagebus/documentprotocol.h>
#include <vespa/document/select/parser.h>
#include <vespa/document/bucket/bucketselector.h>
#include <vespa/vespalib/util/exceptions.h>

namespace documentapi {

RemoveLocationMessage::RemoveLocationMessage(
        const document::BucketIdFactory& factory,
        document::select::Parser& parser,
        const string& documentSelection)
    : _documentSelection(documentSelection),
      _bucketId(),
      _bucketSpace()
{
    document::BucketSelector bucketSel(factory);
    std::unique_ptr<document::BucketSelector::BucketVector> exprResult(
            bucketSel.select(*parser.parse(documentSelection)));

    if (exprResult.get() && exprResult->size() == 1) {
        _bucketId = (*exprResult)[0];
    } else {
        throw vespalib::IllegalArgumentException(
                "Document selection doesn't map to a single bucket!",
                VESPA_STRLOC);
    }
}

RemoveLocationMessage::~RemoveLocationMessage() {
}

DocumentReply::UP
RemoveLocationMessage::doCreateReply() const {
    return DocumentReply::UP(
            new DocumentReply(DocumentProtocol::REPLY_REMOVELOCATION));
}

uint32_t
RemoveLocationMessage::getType() const {
    return DocumentProtocol::MESSAGE_REMOVELOCATION;
}

}