diff --git a/.gemini/GEMINI.md b/.gemini/GEMINI.md new file mode 100644 index 00000000..0f175c59 --- /dev/null +++ b/.gemini/GEMINI.md @@ -0,0 +1,12 @@ +# Overview + +This codebase is part of the Google Workspace GitHub organization, https://github.com/googleworkspace. + +## Style Guide + +Use open source best practices for code style and formatting with a preference for Google's style guides. + +## Tools + +- Verify against Google Workspace documentation with the `workspace-developer` MCP server tools. +- Use `gh` for GitHub interactions. diff --git a/.gemini/config.yaml b/.gemini/config.yaml new file mode 100644 index 00000000..a4814a5f --- /dev/null +++ b/.gemini/config.yaml @@ -0,0 +1,12 @@ +# Config for the Gemini Pull Request Review Bot. +# https://github.com/marketplace/gemini-code-assist +have_fun: false +code_review: + disable: false + comment_severity_threshold: "HIGH" + max_review_comments: -1 + pull_request_opened: + help: false + summary: true + code_review: true +ignore_patterns: [] diff --git a/.gemini/settings.json b/.gemini/settings.json new file mode 100644 index 00000000..ec3565d5 --- /dev/null +++ b/.gemini/settings.json @@ -0,0 +1,8 @@ +{ + "mcpServers": { + "workspace-developer": { + "httpUrl": "https://workspace-developer.goog/mcp", + "trust": true + } + } +} \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 00000000..4a9deaa4 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "google-workspace.google-workspace-developer-tools" + ] +} \ No newline at end of file diff --git a/drive/snippets/drive_v3/src/main/java/SearchFile.java b/drive/snippets/drive_v3/src/main/java/SearchFile.java index 08f574b1..2e5e7f01 100644 --- a/drive/snippets/drive_v3/src/main/java/SearchFile.java +++ b/drive/snippets/drive_v3/src/main/java/SearchFile.java @@ -60,7 +60,7 @@ public static List searchFile() throws IOException { FileList result = service.files().list() .setQ("mimeType='image/jpeg'") .setSpaces("drive") - .setFields("nextPageToken, items(id, title)") + .setFields("nextPageToken, files(id, title)") .setPageToken(pageToken) .execute(); for (File file : result.getFiles()) { diff --git a/sheets/snippets/src/main/java/SheetsFilterViews.java b/sheets/snippets/src/main/java/SheetsFilterViews.java new file mode 100644 index 00000000..06a1f939 --- /dev/null +++ b/sheets/snippets/src/main/java/SheetsFilterViews.java @@ -0,0 +1,175 @@ +/ * +Copyright 2026 Google LLC + +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. +* / + +// [START sheets_filter_views] + +/* + * Dependencies (Maven): + * com.google.apis:google-api-services-sheets:v4-rev20220927-2.0.0 + * com.google.auth:google-auth-library-oauth2-http:1.19.0 + */ + +import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; +import com.google.api.client.json.gson.GsonFactory; +import com.google.api.services.sheets.v4.Sheets; +import com.google.api.services.sheets.v4.SheetsScopes; +import com.google.api.services.sheets.v4.model.*; +import com.google.auth.http.HttpCredentialsAdapter; +import com.google.auth.oauth2.GoogleCredentials; + +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.util.*; + +public class SheetsFilterViews { + + public static void main(String... args) { + filterViews("1CM29gwKIzeXsAppeNwrc8lbYaVMmUclprLuLYuHog4k"); + } + + public static void filterViews(String spreadsheetId) { + try { + // Load pre-authorized user credentials from the environment. + // TODO(developer) - See https://developers.google.com/identity for guides on implementing OAuth2. + GoogleCredentials credentials = GoogleCredentials.getApplicationDefault() + .createScoped(Collections.singleton(SheetsScopes.SPREADSHEETS)); + + Sheets service = new Sheets.Builder( + GoogleNetHttpTransport.newTrustedTransport(), + GsonFactory.getDefaultInstance(), + new HttpCredentialsAdapter(credentials)) + .setApplicationName("Sheets Filter Views Sample") + .build(); + + // --- Step 1: Add Filter View --- + GridRange myRange = new GridRange() + .setSheetId(0) + .setStartRowIndex(0) + .setStartColumnIndex(0); + + // Construct Criteria for Column 0 (Hidden Values) + FilterCriteria criteria0 = new FilterCriteria() + .setHiddenValues(Collections.singletonList("Panel")); + + // Construct Criteria for Column 6 (Date Condition) + ConditionValue dateValue = new ConditionValue().setUserEnteredValue("4/30/2016"); + BooleanCondition dateCondition = new BooleanCondition() + .setType("DATE_BEFORE") + .setValues(Collections.singletonList(dateValue)); + FilterCriteria criteria6 = new FilterCriteria().setCondition(dateCondition); + + // Map criteria to column indices (Note: keys are Strings in Java map) + Map criteriaMap = new HashMap(); + criteriaMap.put("0", criteria0); + criteriaMap.put("6", criteria6); + + FilterView filterView = new FilterView() + .setTitle("Sample Filter") + .setRange(myRange) + .setSortSpecs(Collections.singletonList( + new SortSpec().setDimensionIndex(3).setSortOrder("DESCENDING") + )) + .setCriteria(criteriaMap); + + // --- Step 1: Add Filter View --- + // (Request construction remains the same) + // ... + AddFilterViewRequest addFilterViewRequest = new AddFilterViewRequest().setFilter(filterView); + + BatchUpdateSpreadsheetRequest batchRequest1 = new BatchUpdateSpreadsheetRequest() + .setRequests(Collections.singletonList(new Request().setAddFilterView(addFilterViewRequest))); + + BatchUpdateSpreadsheetResponse response1 = service.spreadsheets() + .batchUpdate(spreadsheetId, batchRequest1) + .execute(); + + if (response1.getReplies() == null || response1.getReplies().isEmpty()) { + System.err.println("Error: No replies returned from AddFilterView request."); + return; + } + + Response reply1 = response1.getReplies().get(0); + if (reply1.getAddFilterView() == null || reply1.getAddFilterView().getFilter() == null) { + System.err.println("Error: Response did not contain AddFilterView data."); + return; + } + + int filterId = reply1.getAddFilterView().getFilter().getFilterViewId(); + + // --- Step 2: Duplicate Filter View --- + DuplicateFilterViewRequest duplicateRequest = new DuplicateFilterViewRequest() + .setFilterId(filterId); + + BatchUpdateSpreadsheetRequest batchRequest2 = new BatchUpdateSpreadsheetRequest() + .setRequests(Collections.singletonList(new Request().setDuplicateFilterView(duplicateRequest))); + + BatchUpdateSpreadsheetResponse response2 = service.spreadsheets() + .batchUpdate(spreadsheetId, batchRequest2) + .execute(); + + if (response2.getReplies() == null || response2.getReplies().isEmpty()) { + System.err.println("Error: No replies returned from DuplicateFilterView request."); + return; + } + + Response reply2 = response2.getReplies().get(0); + if (reply2.getDuplicateFilterView() == null || reply2.getDuplicateFilterView().getFilter() == null) { + System.err.println("Error: Response did not contain DuplicateFilterView data."); + return; + } + + int newFilterId = reply2.getDuplicateFilterView().getFilter().getFilterViewId(); + + // --- Step 3: Update Filter View --- + // Extract the new ID from the duplicate response + int newFilterId = response2.getReplies().get(0) + .getDuplicateFilterView().getFilter().getFilterViewId(); + + // Create update criteria + Map updateCriteriaMap = new HashMap(); + updateCriteriaMap.put("0", new FilterCriteria()); // Empty criteria + + ConditionValue numValue = new ConditionValue().setUserEnteredValue("5"); + BooleanCondition numCondition = new BooleanCondition() + .setType("NUMBER_GREATER") + .setValues(Collections.singletonList(numValue)); + updateCriteriaMap.put("3", new FilterCriteria().setCondition(numCondition)); + + FilterView updateFilterView = new FilterView() + .setFilterViewId(newFilterId) + .setTitle("Updated Filter") + .setCriteria(updateCriteriaMap); + + UpdateFilterViewRequest updateRequest = new UpdateFilterViewRequest() + .setFilter(updateFilterView) + .setFields("criteria,title"); + + BatchUpdateSpreadsheetRequest batchRequest3 = new BatchUpdateSpreadsheetRequest() + .setRequests(Collections.singletonList(new Request().setUpdateFilterView(updateRequest))); + + BatchUpdateSpreadsheetResponse response3 = service.spreadsheets() + .batchUpdate(spreadsheetId, batchRequest3) + .execute(); + + System.out.println(response3.toPrettyString()); + + } catch (IOException | GeneralSecurityException e) { + System.err.println("An error occurred: " + e); + } + } +} + +// [END sheets_filter_views] diff --git a/solutions/webhook-chat-app/README.md b/solutions/webhook-chat-app/README.md new file mode 100644 index 00000000..59643860 --- /dev/null +++ b/solutions/webhook-chat-app/README.md @@ -0,0 +1,4 @@ +# Google Chat App Webhook + +Please see related guide on how to +[send messages to Google Chat with incoming webhooks](https://developers.google.com/workspace/chat/quickstart/webhooks). diff --git a/solutions/webhook-chat-app/pom.xml b/solutions/webhook-chat-app/pom.xml new file mode 100644 index 00000000..be47addd --- /dev/null +++ b/solutions/webhook-chat-app/pom.xml @@ -0,0 +1,52 @@ + + + + + + 4.0.0 + + com.google.chat.webhook + webhook-app + 0.1.0 + webhook-app + + + 11 + 11 + + + + + com.google.code.gson + gson + 2.9.1 + + + + + + + + maven-compiler-plugin + 3.8.0 + + + + + + diff --git a/solutions/webhook-chat-app/src/main/java/com/google/chat/webhook/App.java b/solutions/webhook-chat-app/src/main/java/com/google/chat/webhook/App.java new file mode 100644 index 00000000..3f9f4032 --- /dev/null +++ b/solutions/webhook-chat-app/src/main/java/com/google/chat/webhook/App.java @@ -0,0 +1,45 @@ +/** + * Copyright 2022 Google LLC. + * + * 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 com.google.chat.webhook; + +// [START chat_webhook] +import com.google.gson.Gson; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.util.Map; +import java.net.URI; + +public class App { + private static final String URL = "https://chat.googleapis.com/v1/spaces/SPACE_ID/messages?key=KEY&token=TOKEN"; + private static final Gson gson = new Gson(); + private static final HttpClient client = HttpClient.newHttpClient(); + + public static void main(String[] args) throws Exception { + String message = gson.toJson(Map.of( + "text", "Hello from Java!" + )); + + HttpRequest request = HttpRequest.newBuilder(URI.create(URL)) + .header("accept", "application/json; charset=UTF-8") + .POST(HttpRequest.BodyPublishers.ofString(message)).build(); + + HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + + System.out.println(response.body()); + } +} +// [END chat_webhook] diff --git a/solutions/webhook-chat-app/src/main/java/com/google/chat/webhook/AppThread.java b/solutions/webhook-chat-app/src/main/java/com/google/chat/webhook/AppThread.java new file mode 100644 index 00000000..d5c5fb52 --- /dev/null +++ b/solutions/webhook-chat-app/src/main/java/com/google/chat/webhook/AppThread.java @@ -0,0 +1,48 @@ +/** + * Copyright 2025 Google LLC. + * + * 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 com.google.chat.webhook; + +// [START chat_webhook_thread] +import com.google.gson.Gson; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.util.Map; +import java.net.URI; + +public class App { + private static final String URL = "https://chat.googleapis.com/v1/spaces/SPACE_ID/messages?key=KEY&token=TOKEN&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD"; + private static final Gson gson = new Gson(); + private static final HttpClient client = HttpClient.newHttpClient(); + + public static void main(String[] args) throws Exception { + String message = gson.toJson(Map.of( + "text", "Hello from Java!", + "thread", Map.of( + "threadKey", "THREAD_KEY_VALUE" + ) + )); + + HttpRequest request = HttpRequest.newBuilder(URI.create(URL)) + .header("accept", "application/json; charset=UTF-8") + .POST(HttpRequest.BodyPublishers.ofString(message)).build(); + + HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + + System.out.println(response.body()); + } +} +// [END chat_webhook_thread]

AltStyle によって変換されたページ (->オリジナル) /