summaryrefslogtreecommitdiff
path: root/tests/appsearch/testutils/src/android/app/appsearch/testutil/external/testutil/AppSearchEmail.java
blob: c133aa311af426f1ccbed1fb41eb896e7a7fd29c (plain)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
 * Copyright 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.app.appsearch.testutil;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.appsearch.AppSearchSchema;
import android.app.appsearch.AppSearchSchema.PropertyConfig;
import android.app.appsearch.AppSearchSchema.StringPropertyConfig;
import android.app.appsearch.GenericDocument;
import android.app.appsearch.annotation.CanIgnoreReturnValue;

/**
 * Encapsulates a {@link GenericDocument} that represent an email.
 *
 * <p>This class is a higher level implement of {@link GenericDocument}.
 *
 * @hide
 */
public class AppSearchEmail extends GenericDocument {
    /** The name of the schema type for {@link AppSearchEmail} documents. */
    public static final String SCHEMA_TYPE = "builtin:Email";

    private static final String KEY_FROM = "from";
    private static final String KEY_TO = "to";
    private static final String KEY_CC = "cc";
    private static final String KEY_BCC = "bcc";
    private static final String KEY_SUBJECT = "subject";
    private static final String KEY_BODY = "body";

    public static final AppSearchSchema SCHEMA =
            new AppSearchSchema.Builder(SCHEMA_TYPE)
                    .addProperty(
                            new StringPropertyConfig.Builder(KEY_FROM)
                                    .setCardinality(PropertyConfig.CARDINALITY_OPTIONAL)
                                    .setTokenizerType(StringPropertyConfig.TOKENIZER_TYPE_PLAIN)
                                    .setIndexingType(StringPropertyConfig.INDEXING_TYPE_PREFIXES)
                                    .build())
                    .addProperty(
                            new StringPropertyConfig.Builder(KEY_TO)
                                    .setCardinality(PropertyConfig.CARDINALITY_REPEATED)
                                    .setTokenizerType(StringPropertyConfig.TOKENIZER_TYPE_PLAIN)
                                    .setIndexingType(StringPropertyConfig.INDEXING_TYPE_PREFIXES)
                                    .build())
                    .addProperty(
                            new StringPropertyConfig.Builder(KEY_CC)
                                    .setCardinality(PropertyConfig.CARDINALITY_REPEATED)
                                    .setTokenizerType(StringPropertyConfig.TOKENIZER_TYPE_PLAIN)
                                    .setIndexingType(StringPropertyConfig.INDEXING_TYPE_PREFIXES)
                                    .build())
                    .addProperty(
                            new StringPropertyConfig.Builder(KEY_BCC)
                                    .setCardinality(PropertyConfig.CARDINALITY_REPEATED)
                                    .setTokenizerType(StringPropertyConfig.TOKENIZER_TYPE_PLAIN)
                                    .setIndexingType(StringPropertyConfig.INDEXING_TYPE_PREFIXES)
                                    .build())
                    .addProperty(
                            new StringPropertyConfig.Builder(KEY_SUBJECT)
                                    .setCardinality(PropertyConfig.CARDINALITY_OPTIONAL)
                                    .setTokenizerType(StringPropertyConfig.TOKENIZER_TYPE_PLAIN)
                                    .setIndexingType(StringPropertyConfig.INDEXING_TYPE_PREFIXES)
                                    .build())
                    .addProperty(
                            new StringPropertyConfig.Builder(KEY_BODY)
                                    .setCardinality(PropertyConfig.CARDINALITY_OPTIONAL)
                                    .setTokenizerType(StringPropertyConfig.TOKENIZER_TYPE_PLAIN)
                                    .setIndexingType(StringPropertyConfig.INDEXING_TYPE_PREFIXES)
                                    .build())
                    .build();

    /**
     * Creates a new {@link AppSearchEmail} from the contents of an existing {@link
     * GenericDocument}.
     *
     * @param document The {@link GenericDocument} containing the email content.
     */
    public AppSearchEmail(@NonNull GenericDocument document) {
        super(document);
    }

    /**
     * Gets the from address of {@link AppSearchEmail}.
     *
     * @return The subject of {@link AppSearchEmail} or {@code null} if it's not been set yet.
     */
    @Nullable
    public String getFrom() {
        return getPropertyString(KEY_FROM);
    }

    /**
     * Gets the destination addresses of {@link AppSearchEmail}.
     *
     * @return The destination addresses of {@link AppSearchEmail} or {@code null} if it's not been
     *     set yet.
     */
    @Nullable
    public String[] getTo() {
        return getPropertyStringArray(KEY_TO);
    }

    /**
     * Gets the CC list of {@link AppSearchEmail}.
     *
     * @return The CC list of {@link AppSearchEmail} or {@code null} if it's not been set yet.
     */
    @Nullable
    public String[] getCc() {
        return getPropertyStringArray(KEY_CC);
    }

    /**
     * Gets the BCC list of {@link AppSearchEmail}.
     *
     * @return The BCC list of {@link AppSearchEmail} or {@code null} if it's not been set yet.
     */
    @Nullable
    public String[] getBcc() {
        return getPropertyStringArray(KEY_BCC);
    }

    /**
     * Gets the subject of {@link AppSearchEmail}.
     *
     * @return The value subject of {@link AppSearchEmail} or {@code null} if it's not been set yet.
     */
    @Nullable
    public String getSubject() {
        return getPropertyString(KEY_SUBJECT);
    }

    /**
     * Gets the body of {@link AppSearchEmail}.
     *
     * @return The body of {@link AppSearchEmail} or {@code null} if it's not been set yet.
     */
    @Nullable
    public String getBody() {
        return getPropertyString(KEY_BODY);
    }

    /** The builder class for {@link AppSearchEmail}. */
    public static class Builder extends GenericDocument.Builder<Builder> {
        /**
         * Creates a new {@link Builder}
         *
         * @param namespace The namespace of the Email.
         * @param id The ID of the Email.
         */
        public Builder(@NonNull String namespace, @NonNull String id) {
            super(namespace, id, SCHEMA_TYPE);
        }

        /** Sets the from address of {@link AppSearchEmail} */
        @CanIgnoreReturnValue
        @NonNull
        public Builder setFrom(@NonNull String from) {
            return setPropertyString(KEY_FROM, from);
        }

        /** Sets the destination address of {@link AppSearchEmail} */
        @CanIgnoreReturnValue
        @NonNull
        public Builder setTo(@NonNull String... to) {
            return setPropertyString(KEY_TO, to);
        }

        /** Sets the CC list of {@link AppSearchEmail} */
        @CanIgnoreReturnValue
        @NonNull
        public Builder setCc(@NonNull String... cc) {
            return setPropertyString(KEY_CC, cc);
        }

        /** Sets the BCC list of {@link AppSearchEmail} */
        @CanIgnoreReturnValue
        @NonNull
        public Builder setBcc(@NonNull String... bcc) {
            return setPropertyString(KEY_BCC, bcc);
        }

        /** Sets the subject of {@link AppSearchEmail} */
        @CanIgnoreReturnValue
        @NonNull
        public Builder setSubject(@NonNull String subject) {
            return setPropertyString(KEY_SUBJECT, subject);
        }

        /** Sets the body of {@link AppSearchEmail} */
        @CanIgnoreReturnValue
        @NonNull
        public Builder setBody(@NonNull String body) {
            return setPropertyString(KEY_BODY, body);
        }

        /** Builds the {@link AppSearchEmail} object. */
        @NonNull
        @Override
        public AppSearchEmail build() {
            return new AppSearchEmail(super.build());
        }
    }
}