aboutsummaryrefslogtreecommitdiffstats
path: root/docproc/src/main/java/com/yahoo/docproc/proxy/ProxyDocumentUpdate.java
blob: d9c12409128e5dff0caf3ae90f34bb25de0858cf (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
109
110
111
112
113
114
115
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.docproc.proxy;
import com.yahoo.docproc.impl.DocumentOperationWrapper;
import com.yahoo.document.Document;
import com.yahoo.document.DocumentId;
import com.yahoo.document.DocumentOperation;
import com.yahoo.document.DocumentType;
import com.yahoo.document.DocumentUpdate;
import com.yahoo.document.Field;
import com.yahoo.document.serialization.DocumentUpdateWriter;
import com.yahoo.document.update.FieldUpdate;

import java.util.Collection;
import java.util.Map;

/**
 * Schema mapped facade to a DocumentUpdate
 * 
 * @author vegardh
 */
public class ProxyDocumentUpdate extends DocumentUpdate implements DocumentOperationWrapper {

    private final DocumentUpdate docU;

    /**
     * The field name map for schema mapping. The key is the field name that the docproc uses. 
     * The value is the actual name of the field in the document.
     */
    private final Map<String, String> fieldMap;

    public ProxyDocumentUpdate(DocumentUpdate docUpd, Map<String, String> fieldMap) {
        super(docUpd.getType(), docUpd.getId().toString()+"-schemamappedupdate");
        this.docU=docUpd;
        this.fieldMap=fieldMap;
    }

    @Override
    public DocumentType getDocumentType() {
        return docU.getDocumentType();
    }

    @Override
    public FieldUpdate getFieldUpdate(Field field) {
        return docU.getFieldUpdate(field);
    }

    @Override
    public FieldUpdate getFieldUpdate(String fieldName) {
        String mapped = fieldMap.get(fieldName);
        if (mapped==null) {
            return docU.getFieldUpdate(fieldName);
        }
        // TODO how about structs here?
        return docU.getFieldUpdate(mapped);
    }

    @Override
    public Collection<FieldUpdate> fieldUpdates() {
        return docU.fieldUpdates();
    }
    @Override
    public DocumentId getId() {
        return docU.getId();
    }

    @Override
    public DocumentType getType() {
        return docU.getType();
    }

    @Override
    public DocumentUpdate addFieldUpdate(FieldUpdate fieldUpdate) {
        return docU.addFieldUpdate(fieldUpdate);
    }

    @Override
    public DocumentUpdate applyTo(Document doc) {
        return docU.applyTo(doc);
    }

    @Override
    public boolean equals(Object o) {
        return docU.equals(o);
    }

    @Override
    public int hashCode() {
        return docU.hashCode();
    }

    @Override
    public void serialize(DocumentUpdateWriter data) {
        docU.serialize(data);
    }

    @Override
    public int size() {
        return docU.size();
    }

    @Override
    public String toString() {
        return docU.toString();
    }

    @Override
    public DocumentOperation getWrappedDocumentOperation() {
        DocumentOperation innermostDocOp = docU;
        while (innermostDocOp instanceof DocumentOperationWrapper) {
            innermostDocOp = ((DocumentOperationWrapper) innermostDocOp).getWrappedDocumentOperation();
        }
        return innermostDocOp;
    }

}