aboutsummaryrefslogtreecommitdiffstats
path: root/docproc/src/main/java/com/yahoo/docproc/proxy/ProxyDocumentUpdate.java
blob: 517f44cb983ce04000e0ec08bc061a8a65e55300 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright 2017 Yahoo Holdings. 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.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.List;
import java.util.Map;

/**
 * Schema mapped facade to a DocumentUpdate
 * 
 * @author vegardh
 */
// TODO Vespa 7 Remove all deprecated methods
public class ProxyDocumentUpdate extends DocumentUpdate implements DocumentOperationWrapper {

    private 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 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
    @Deprecated
    @SuppressWarnings( "deprecation" )
    public FieldUpdate getFieldUpdate(int index) {
        return docU.getFieldUpdate(index);
    }

    @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
    @Deprecated
    @SuppressWarnings( "deprecation" )
    public List<FieldUpdate> getFieldUpdates() {
        return docU.getFieldUpdates();
    }
    @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;
    }

}