aboutsummaryrefslogtreecommitdiffstats
path: root/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandler.java
blob: cfa77455f41318f1733cfbda72c11a0162e04464 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document.restapi;

import com.yahoo.vespaxmlparser.VespaXMLFeedReader;

import java.util.Optional;

/**
 * Abstract the backend stuff for the REST API, such as retrieving or updating documents.
 *
 * @author Haakon Dybdahl
 */
public interface OperationHandler {

    class VisitResult {

        public final Optional<String> token;
        public final String documentsAsJsonList;

        public VisitResult(Optional<String> token, String documentsAsJsonList) {
            this.token = token;
            this.documentsAsJsonList = documentsAsJsonList;
        }
    }

    class VisitOptions {
        public final Optional<String> cluster;
        public final Optional<String> continuation;
        public final Optional<Integer> wantedDocumentCount;
        public final Optional<String> fieldSet;
        public final Optional<Integer> concurrency;
        public final Optional<String> bucketSpace;

        private VisitOptions(Builder builder) {
            this.cluster = Optional.ofNullable(builder.cluster);
            this.continuation = Optional.ofNullable(builder.continuation);
            this.wantedDocumentCount = Optional.ofNullable(builder.wantedDocumentCount);
            this.fieldSet = Optional.ofNullable(builder.fieldSet);
            this.concurrency = Optional.ofNullable(builder.concurrency);
            this.bucketSpace = Optional.ofNullable(builder.bucketSpace);
        }

        public static class Builder {
            String cluster;
            String continuation;
            Integer wantedDocumentCount;
            String fieldSet;
            Integer concurrency;
            String bucketSpace;

            public Builder cluster(String cluster) {
                this.cluster = cluster;
                return this;
            }

            public Builder continuation(String continuation) {
                this.continuation = continuation;
                return this;
            }

            public Builder wantedDocumentCount(Integer count) {
                this.wantedDocumentCount = count;
                return this;
            }

            public Builder fieldSet(String fieldSet) {
                this.fieldSet = fieldSet;
                return this;
            }

            public Builder concurrency(Integer concurrency) {
                this.concurrency = concurrency;
                return this;
            }

            public Builder bucketSpace(String bucketSpace) {
                this.bucketSpace = bucketSpace;
                return this;
            }

            public VisitOptions build() {
                return new VisitOptions(this);
            }
        }

        public static Builder builder() {
            return new Builder();
        }
    }

    VisitResult visit(RestUri restUri, String documentSelection, VisitOptions options) throws RestApiException;

    void put(RestUri restUri, VespaXMLFeedReader.Operation data, Optional<String> route) throws RestApiException;

    void update(RestUri restUri, VespaXMLFeedReader.Operation data, Optional<String> route) throws RestApiException;

    void delete(RestUri restUri, String condition, Optional<String> route) throws RestApiException;

    Optional<String> get(RestUri restUri) throws RestApiException;

    default Optional<String> get(RestUri restUri, Optional<String> fieldSet) throws RestApiException {
        return get(restUri);
    }
    
    /** Called just before this is disposed of */
    default void shutdown() {}

}