Skip to content

Commit c25db47

Browse files
google-genai-botcopybara-github
authored andcommitted
refactor: Deprecate methods in BaseArtifactService that use individual session parameters
PiperOrigin-RevId: 890411230
1 parent 4b53375 commit c25db47

File tree

1 file changed

+96
-5
lines changed

1 file changed

+96
-5
lines changed

core/src/main/java/com/google/adk/artifacts/BaseArtifactService.java

Lines changed: 96 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@
2323
import io.reactivex.rxjava3.core.Maybe;
2424
import io.reactivex.rxjava3.core.Single;
2525
import org.jspecify.annotations.Nullable;
26+
import org.slf4j.Logger;
27+
import org.slf4j.LoggerFactory;
2628

2729
/** Base interface for artifact services. */
2830
public interface BaseArtifactService {
2931

32+
Logger logger = LoggerFactory.getLogger(BaseArtifactService.class);
33+
3034
/**
3135
* Saves an artifact.
3236
*
@@ -36,12 +40,21 @@ public interface BaseArtifactService {
3640
* @param filename the filename
3741
* @param artifact the artifact
3842
* @return the revision ID (version) of the saved artifact.
43+
* @deprecated Use {@link #saveArtifact(SessionKey, String, Part)} instead.
3944
*/
45+
@Deprecated
4046
Single<Integer> saveArtifact(
4147
String appName, String userId, String sessionId, String filename, Part artifact);
4248

43-
/** Saves an artifact. */
49+
/**
50+
* Saves an artifact.
51+
*
52+
* <p><b>Deprecation warning:</b> The default implementation will be removed and all implementing
53+
* classes must provide their own implementation.
54+
*/
4455
default Single<Integer> saveArtifact(SessionKey sessionKey, String filename, Part artifact) {
56+
logger.warn(
57+
"This method relies on the default implementation, which will be removed in the future.");
4558
return saveArtifact(
4659
sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename, artifact);
4760
}
@@ -58,56 +71,118 @@ default Single<Integer> saveArtifact(SessionKey sessionKey, String filename, Par
5871
* @param filename the filename
5972
* @param artifact the artifact to save
6073
* @return the saved artifact with fileData if available.
74+
* @deprecated Use {@link #saveAndReloadArtifact(SessionKey, String, Part)} instead.
6175
*/
76+
@Deprecated
6277
default Single<Part> saveAndReloadArtifact(
6378
String appName, String userId, String sessionId, String filename, Part artifact) {
79+
logger.warn(
80+
"This method relies on the default implementation, which will be removed in the future.");
6481
return saveArtifact(appName, userId, sessionId, filename, artifact)
6582
.flatMap(version -> loadArtifact(appName, userId, sessionId, filename, version).toSingle());
6683
}
6784

68-
/** Saves an artifact and returns it with fileData if available. */
85+
/**
86+
* Saves an artifact and returns it with fileData if available.
87+
*
88+
* <p><b>Deprecation warning:</b> The default implementation will be removed and all implementing
89+
* classes must provide their own implementation.
90+
*/
6991
default Single<Part> saveAndReloadArtifact(
7092
SessionKey sessionKey, String filename, Part artifact) {
93+
logger.warn(
94+
"This method relies on the default implementation, which will be removed in the future.");
7195
return saveAndReloadArtifact(
7296
sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename, artifact);
7397
}
7498

75-
/** Loads the latest version of an artifact from the service. */
99+
/**
100+
* Loads the latest version of an artifact from the service.
101+
*
102+
* @deprecated Use {@link #loadArtifact(SessionKey, String)} instead.
103+
*/
104+
@Deprecated
76105
default Maybe<Part> loadArtifact(
77106
String appName, String userId, String sessionId, String filename) {
107+
logger.warn(
108+
"This method relies on the default implementation, which will be removed in the future.");
78109
return loadArtifact(appName, userId, sessionId, filename, /* version= */ (Integer) null);
79110
}
80111

81-
/** Loads the latest version of an artifact from the service. */
112+
/**
113+
* Loads the latest version of an artifact from the service.
114+
*
115+
* <p><b>Deprecation warning:</b> The default implementation will be removed and all implementing
116+
* classes must provide their own implementation.
117+
*/
82118
default Maybe<Part> loadArtifact(SessionKey sessionKey, String filename) {
119+
logger.warn(
120+
"This method relies on the default implementation, which will be removed in the future.");
83121
return loadArtifact(sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename);
84122
}
85123

86-
/** Loads a specific version of an artifact from the service. */
124+
/**
125+
* Loads a specific version of an artifact from the service.
126+
*
127+
* @deprecated Use {@link #loadArtifact(SessionKey, String, int)} instead.
128+
*/
129+
@Deprecated
87130
default Maybe<Part> loadArtifact(
88131
String appName, String userId, String sessionId, String filename, int version) {
132+
logger.warn(
133+
"This method relies on the default implementation, which will be removed in the future.");
89134
return loadArtifact(appName, userId, sessionId, filename, Integer.valueOf(version));
90135
}
91136

137+
/**
138+
* <b>Deprecation warning:</b> The default implementation will be removed and all implementing
139+
* classes must provide their own implementation.
140+
*/
92141
default Maybe<Part> loadArtifact(SessionKey sessionKey, String filename, int version) {
142+
logger.warn(
143+
"This method relies on the default implementation, which will be removed in the future.");
93144
return loadArtifact(
94145
sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename, version);
95146
}
96147

148+
/**
149+
* @deprecated Use {@link #loadArtifact(SessionKey, String, Integer)} instead.
150+
*/
151+
@Deprecated
97152
Maybe<Part> loadArtifact(
98153
String appName, String userId, String sessionId, String filename, @Nullable Integer version);
99154

155+
/**
156+
* <b>Deprecation warning:</b> The default implementation will be removed and all implementing
157+
* classes must provide their own implementation.
158+
*/
159+
default Maybe<Part> loadArtifact(
160+
SessionKey sessionKey, String filename, @Nullable Integer version) {
161+
logger.warn(
162+
"This method relies on the default implementation, which will be removed in the future.");
163+
return loadArtifact(
164+
sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename, version);
165+
}
166+
100167
/**
101168
* Lists all the artifact filenames within a session.
102169
*
103170
* @param appName the app name
104171
* @param userId the user ID
105172
* @param sessionId the session ID
106173
* @return the list artifact response containing filenames
174+
* @deprecated Use {@link #listArtifactKeys(SessionKey)} instead.
107175
*/
176+
@Deprecated
108177
Single<ListArtifactsResponse> listArtifactKeys(String appName, String userId, String sessionId);
109178

179+
/**
180+
* <b>Deprecation warning:</b> The default implementation will be removed and all implementing
181+
* classes must provide their own implementation.
182+
*/
110183
default Single<ListArtifactsResponse> listArtifactKeys(SessionKey sessionKey) {
184+
logger.warn(
185+
"This method relies on the default implementation, which will be removed in the future.");
111186
return listArtifactKeys(sessionKey.appName(), sessionKey.userId(), sessionKey.id());
112187
}
113188

@@ -118,10 +193,18 @@ default Single<ListArtifactsResponse> listArtifactKeys(SessionKey sessionKey) {
118193
* @param userId the user ID
119194
* @param sessionId the session ID
120195
* @param filename the filename
196+
* @deprecated Use {@link #deleteArtifact(SessionKey, String)} instead.
121197
*/
198+
@Deprecated
122199
Completable deleteArtifact(String appName, String userId, String sessionId, String filename);
123200

201+
/**
202+
* <b>Deprecation warning:</b> The default implementation will be removed and all implementing
203+
* classes must provide their own implementation.
204+
*/
124205
default Completable deleteArtifact(SessionKey sessionKey, String filename) {
206+
logger.warn(
207+
"This method relies on the default implementation, which will be removed in the future.");
125208
return deleteArtifact(sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename);
126209
}
127210

@@ -133,11 +216,19 @@ default Completable deleteArtifact(SessionKey sessionKey, String filename) {
133216
* @param sessionId the session ID
134217
* @param filename the artifact filename
135218
* @return A list of integer version numbers.
219+
* @deprecated Use {@link #listVersions(SessionKey, String)} instead.
136220
*/
221+
@Deprecated
137222
Single<ImmutableList<Integer>> listVersions(
138223
String appName, String userId, String sessionId, String filename);
139224

225+
/**
226+
* <b>Deprecation warning:</b> The default implementation will be removed and all implementing
227+
* classes must provide their own implementation.
228+
*/
140229
default Single<ImmutableList<Integer>> listVersions(SessionKey sessionKey, String filename) {
230+
logger.warn(
231+
"This method relies on the default implementation, which will be removed in the future.");
141232
return listVersions(sessionKey.appName(), sessionKey.userId(), sessionKey.id(), filename);
142233
}
143234
}

0 commit comments

Comments
 (0)