• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.google.android.libraries.mobiledatadownload;
17 
18 import android.accounts.Account;
19 import com.google.auto.value.AutoValue;
20 import com.google.common.base.Optional;
21 import com.google.common.collect.ImmutableList;
22 import com.google.common.collect.ImmutableMap;
23 import com.google.mobiledatadownload.DownloadConfigProto.DataFile;
24 import com.google.protobuf.Any;
25 import com.google.protobuf.ByteString;
26 import javax.annotation.concurrent.Immutable;
27 
28 /** Request to import files into an existing DataFileGroup. */
29 @AutoValue
30 @Immutable
31 public abstract class ImportFilesRequest {
32 
ImportFilesRequest()33   ImportFilesRequest() {}
34 
35   /** Name that identifies the file group to import files into. */
groupName()36   public abstract String groupName();
37 
38   /** Build id that identifies the file group to import files into. */
buildId()39   public abstract long buildId();
40 
41   /** Variant id that identifies the file group to import files into. */
variantId()42   public abstract String variantId();
43 
44   /**
45    * Custom property that identifies the file group to import files into.
46    *
47    * <p>If a file group supports this field, it is required to identify the file group. In most
48    * cases, this field does not need to be included to identify the file group.
49    *
50    * <p>Contact <internal>@ if you think this field is required for your use-case.
51    */
customPropertyOptional()52   public abstract Optional<Any> customPropertyOptional();
53 
54   /** List of {@link DataFile}s to import into the existing file group. */
updatedDataFileList()55   public abstract ImmutableList<DataFile> updatedDataFileList();
56 
57   /**
58    * Map of inline file content that should be imported.
59    *
60    * <p>The Map is keyed by the {@link DataFile#fileId} that represents the file content and the
61    * values are the file content contained in a {@link ByteString}.
62    */
inlineFileMap()63   public abstract ImmutableMap<String, FileSource> inlineFileMap();
64 
65   /** Account associated with the file group. */
accountOptional()66   public abstract Optional<Account> accountOptional();
67 
newBuilder()68   public static Builder newBuilder() {
69     // Set updatedDataFileList as empty by default
70     return new AutoValue_ImportFilesRequest.Builder().setUpdatedDataFileList(ImmutableList.of());
71   }
72 
73   /** Builder for {@link ImportFilesRequest}. */
74   @AutoValue.Builder
75   public abstract static class Builder {
Builder()76     Builder() {}
77 
78     /**
79      * Sets the name of the file group to import files into.
80      *
81      * <p>This is required to identify the file group.
82      */
setGroupName(String groupName)83     public abstract Builder setGroupName(String groupName);
84 
85     /**
86      * Sets the build id of the file group to import files into.
87      *
88      * <p>This is required to identify the file group.
89      */
setBuildId(long buildId)90     public abstract Builder setBuildId(long buildId);
91 
92     /**
93      * Sets the variant id of the file group to import files into.
94      *
95      * <p>This is required to identify the file group.
96      */
setVariantId(String variantId)97     public abstract Builder setVariantId(String variantId);
98 
99     /**
100      * Sets the custom property of the file group to import files into.
101      *
102      * <p>This should only be provided if the file group supports this field. Most cases do not
103      * require this.
104      *
105      * <p>Contact <internal>@ if you think this field is required for your use-case.
106      */
setCustomPropertyOptional(Optional<Any> customPropertyOptional)107     public abstract Builder setCustomPropertyOptional(Optional<Any> customPropertyOptional);
108 
109     /**
110      * Sets the List of inline DataFiles that should be updated in the file group.
111      *
112      * <p>This list can be included to update DataFiles in the existing file group identified by the
113      * other parameters in the request ({@link #groupName}, {@link #buildId}, and {@link
114      * #variantId}).
115      *
116      * <p>Files in this list are merged into the existing file group based on {@link
117      * DataFile#fileId}. That is:
118      *
119      * <ul>
120      *   <li>If a File exists with the same fileId, it is replaced by the File in this List
121      *   <li>If a File does not exist with the same fileId, it is added to the file group
122      * </ul>
123      *
124      * <p>This list is only required if inline files need to be added/updated in the existing file
125      * group. If the existing file group has inline files added with {@link
126      * MobileDataDownload#addFileGroup}, this list may be empty and the existing inline files that
127      * need to be imported can be included in {@link ImportFilesRequest#inlineFileMap}.
128      */
setUpdatedDataFileList(ImmutableList<DataFile> updatedDataFileList)129     public abstract Builder setUpdatedDataFileList(ImmutableList<DataFile> updatedDataFileList);
130 
131     /**
132      * Sets the map of inline file content to import.
133      *
134      * <p>The keys of this map should be fileIds of DataFiles that need to be imported. The values
135      * of the map should be FileSource.
136      *
137      * <p>NOTE: Key/Value pairs included in this map can references inline files already in the
138      * existing file group (added via {@link MobileDataDownload#addFileGroup}) or inline files
139      * included in the {@link ImportFilesRequest#updatedDataFileList}.
140      */
setInlineFileMap(ImmutableMap<String, FileSource> inlineFileMap)141     public abstract Builder setInlineFileMap(ImmutableMap<String, FileSource> inlineFileMap);
142 
143     /** Sets the optional account that is associated with the file group. */
setAccountOptional(Optional<Account> accountOptional)144     public abstract Builder setAccountOptional(Optional<Account> accountOptional);
145 
build()146     public abstract ImportFilesRequest build();
147   }
148 }
149