aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/RemoveLocationMessage.java
blob: 7cbad4b8dcc9d943872d54a0968e24d80aeea3f9 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.documentapi.messagebus.protocol;

import com.yahoo.document.*;
import com.yahoo.document.select.BucketSelector;
import java.util.Set;

/**
 * Message (VDS only) to remove an entire location for users using n= or g= schemes.
 * We use a document selection so the user can specify a subset of those documents to be deleted
 * if they wish.
 */
public class RemoveLocationMessage extends DocumentMessage {
    String documentSelection;
    BucketId bucketId;

    public RemoveLocationMessage(String documentSelection) {
        try {
            this.documentSelection = documentSelection;
            BucketSelector bucketSel = new BucketSelector(new BucketIdFactory());
            Set<BucketId> rawBuckets = bucketSel.getBucketList(documentSelection);
            if (rawBuckets == null || rawBuckets.size() != 1) {
                throw new IllegalArgumentException("Document selection for remove location must map to a single location (user or group)");
            } else {
                // There can only be one.
                for (BucketId id : rawBuckets) {
                    bucketId = id;
                }
            }
        } catch (com.yahoo.document.select.parser.ParseException p) {
            throw new IllegalArgumentException(p);
        }
    }

    public String getDocumentSelection() {
        return documentSelection;
    }

    @Override
    public DocumentReply createReply() {
        return new DocumentReply(DocumentProtocol.REPLY_REMOVELOCATION);
    }

    @Override
    public int getType() {
        return DocumentProtocol.MESSAGE_REMOVELOCATION;
    }

    public BucketId getBucketId() {
        return bucketId;
    }
}