Search in sources :

Example 1 with ListNoteOccurrencesPagedResponse

use of com.google.cloud.devtools.containeranalysis.v1alpha1.PagedResponseWrappers.ListNoteOccurrencesPagedResponse in project java-docs-samples by GoogleCloudPlatform.

the class Samples method getOccurrencesForNote.

// [END discovery_info]
// [START occurrences_for_note]
/**
 * Retrieves all the occurrences associated with a specified note
 *
 * @param noteId the note's unique identifier
 * @param projectId the project's unique identifier
 * @return number of occurrences found
 * @throws Exception on errors while closing the client
 */
public static int getOccurrencesForNote(String noteId, String projectId) throws Exception {
    try (ContainerAnalysisClient client = ContainerAnalysisClient.create()) {
        final String parentNoteName = client.formatNoteName(projectId, noteId);
        int i = 0;
        ListNoteOccurrencesPagedResponse response = client.listNoteOccurrences(parentNoteName);
        for (Occurrence o : response.iterateAll()) {
            // print and count each occurrence found
            System.out.println(o.getName());
            i = i + 1;
        }
        return i;
    }
}
Also used : ListNoteOccurrencesPagedResponse(com.google.cloud.devtools.containeranalysis.v1alpha1.PagedResponseWrappers.ListNoteOccurrencesPagedResponse) ContainerAnalysisClient(com.google.cloud.devtools.containeranalysis.v1alpha1.ContainerAnalysisClient) Occurrence(com.google.containeranalysis.v1alpha1.Occurrence)

Aggregations

ContainerAnalysisClient (com.google.cloud.devtools.containeranalysis.v1alpha1.ContainerAnalysisClient)1 ListNoteOccurrencesPagedResponse (com.google.cloud.devtools.containeranalysis.v1alpha1.PagedResponseWrappers.ListNoteOccurrencesPagedResponse)1 Occurrence (com.google.containeranalysis.v1alpha1.Occurrence)1