Skip to content

Commit b9b441f

Browse files
committed
changed name formatter
1 parent 6562a55 commit b9b441f

File tree

1 file changed

+11
-9
lines changed
  • container-registry/container-analysis/src/main/java/com/example/containeranalysis

1 file changed

+11
-9
lines changed

container-registry/container-analysis/src/main/java/com/example/containeranalysis/Samples.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import com.google.cloud.pubsub.v1.MessageReceiver;
2727
import com.google.cloud.pubsub.v1.Subscriber;
2828
import com.google.cloud.pubsub.v1.SubscriptionAdminClient;
29+
import com.google.containeranalysis.v1beta1.NoteName;
30+
import com.google.containeranalysis.v1beta1.ProjectName;
2931
import com.google.pubsub.v1.ProjectSubscriptionName;
3032
import com.google.pubsub.v1.ProjectTopicName;
3133
import com.google.pubsub.v1.PubsubMessage;
@@ -66,7 +68,7 @@ public static Note createNote(GrafeasV1Beta1Client client, String noteId, String
6668
noteBuilder.setVulnerability(vulBuilder);
6769
Note newNote = noteBuilder.build();
6870

69-
final String projectName = client.formatProjectName(projectId);
71+
final ProjectName projectName = ProjectName.format(projectId);
7072
return client.createNote(projectName, noteId, newNote);
7173
}
7274
// [END create_note]
@@ -85,8 +87,8 @@ public static Note createNote(GrafeasV1Beta1Client client, String noteId, String
8587
*/
8688
public static Occurrence createOccurrence(GrafeasV1Beta1Client client, String imageUrl,
8789
String noteId, String occProjectId, String noteProjectId) {
88-
final String noteName = client.formatNoteName(noteProjectId, noteId);
89-
final String occProjectName = client.formatProjectName(occProjectId);
90+
final NoteName noteName = NoteName.of(noteProjectId, noteId);
91+
final ProjectName occProjectName = ProjectName.format(occProjectId);
9092

9193
Occurrence.Builder occBuilder = Occurrence.newBuilder();
9294
occBuilder.setNoteName(noteName);
@@ -112,7 +114,7 @@ public static Occurrence createOccurrence(GrafeasV1Beta1Client client, String im
112114
*/
113115
public static Note updateNote(GrafeasV1Beta1Client client, Note updated, String noteId,
114116
String projectId) {
115-
final String noteName = client.formatNoteName(projectId, noteId);
117+
final NoteName noteName = NoteName.of(projectId, noteId);
116118
UpdateNoteRequest request = UpdateNoteRequest.newBuilder()
117119
.setName(noteName)
118120
.setNote(updated)
@@ -147,7 +149,7 @@ public static Occurrence updateOccurrence(GrafeasV1Beta1Client client, String oc
147149
* @param projectId the GCP project the Note belongs to
148150
*/
149151
public static void deleteNote(GrafeasV1Beta1Client client, String noteId, String projectId) {
150-
final String noteName = client.formatNoteName(projectId, noteId);
152+
final NoteName noteName = NoteName.of(projectId, noteId);
151153
client.deleteNote(noteName);
152154
}
153155
// [END delete_note]
@@ -189,7 +191,7 @@ public static Occurrence getOccurrence(GrafeasV1Beta1Client client, String occur
189191
* @return the requested Note object
190192
*/
191193
public static Note getNote(GrafeasV1Beta1Client client, String noteId, String projectId) {
192-
final String noteName = client.formatNoteName(projectId, noteId);
194+
final NoteName noteName = NoteName.of(projectId, noteId);
193195

194196
Note n = client.getNote(noteName);
195197
System.out.println(n);
@@ -209,7 +211,7 @@ public static Note getNote(GrafeasV1Beta1Client client, String noteId, String pr
209211
public static void getDiscoveryInfo(GrafeasV1Beta1Client client, String imageUrl,
210212
String projectId) {
211213
String filterStr = "kind=\"DISCOVERY\" AND resourceUrl=\"" + imageUrl + "\"";
212-
final String projectName = client.formatProjectName(projectId);
214+
final ProjectName projectName = ProjectName.format(projectId);
213215

214216
for (Occurrence o : client.listOccurrences(projectName, filterStr).iterateAll()) {
215217
System.out.println(o);
@@ -228,7 +230,7 @@ public static void getDiscoveryInfo(GrafeasV1Beta1Client client, String imageUrl
228230
*/
229231
public static int getOccurrencesForNote(GrafeasV1Beta1Client client, String noteId,
230232
String projectId) {
231-
final String noteName = client.formatNoteName(projectId, noteId);
233+
final NoteName noteName = NoteName.of(projectId, noteId);
232234
int i = 0;
233235

234236
ListNoteOccurrencesRequest request = ListNoteOccurrencesRequest.newBuilder()
@@ -257,7 +259,7 @@ public static int getOccurrencesForNote(GrafeasV1Beta1Client client, String note
257259
public static int getOccurrencesForImage(GrafeasV1Beta1Client client, String imageUrl,
258260
String projectId) {
259261
final String filterStr = "resourceUrl=\"" + imageUrl + "\"";
260-
final String projectName = client.formatProjectName(projectId);
262+
final ProjectName projectName = ProjectName.format(projectId);
261263
int i = 0;
262264

263265
for (Occurrence o : client.listOccurrences(projectName, filterStr).iterateAll()) {

0 commit comments

Comments
 (0)