Skip to content

docs: add SheetsFilterViews Java sample#1747

Open
kencenerelli wants to merge 2 commits intomainfrom
kencenerelli-patch-1
Open

docs: add SheetsFilterViews Java sample#1747
kencenerelli wants to merge 2 commits intomainfrom
kencenerelli-patch-1

Conversation

@kencenerelli
Copy link

Adds Java sample for filter views. Based on the sheets_filter_views sample from Python.

Description

This sample demonstrates how to:

  • Create a filter view using AddFilterViewRequest.
  • Duplicate a filter view using DuplicateFilterViewRequest.
  • Update filter criteria and titles using UpdateFilterViewRequest.

Fixes # (issue)

Is it been tested?

  • Development testing done

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have performed a peer-reviewed with team member(s)
  • I have commented my code, particularly in hard-to-understand areas
  • [x ] I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Adds Java sample for filter views.  Based on the `sheets_filter_views` sample from Python.
@gemini-code-assist
Copy link

Summary of Changes

Hello @kencenerelli, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new Java sample for the Google Sheets API, focusing on the management of filter views. The sample provides practical examples for developers to understand and implement the creation, duplication, and modification of filter views within their applications, mirroring existing Python samples to ensure feature parity across client libraries.

Highlights

  • New Java Sample: Introduced a new Java sample, SheetsFilterViews.java, to demonstrate Google Sheets API functionalities related to filter views, based on an existing Python sample.
  • Filter View Creation: The sample illustrates how to create a filter view using AddFilterViewRequest, defining criteria for hidden values and date conditions within a specified range.
  • Filter View Duplication: Demonstrated the duplication of an existing filter view using DuplicateFilterViewRequest, leveraging the ID from a previously created filter.
  • Filter View Updates: Showcased how to update filter criteria and the title of a filter view using UpdateFilterViewRequest, including clearing existing criteria and setting new conditions.
Changelog
  • sheets/snippets/src/main/java/SheetsFilterViews.java
    • Added a new Java sample demonstrating Google Sheets filter view operations, including creation, duplication, and updates.
Activity
  • The author performed development testing for the new sample.
  • Corresponding changes to the documentation have been made to reflect the addition of this sample.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a new Java sample for Sheets Filter Views. However, the new file contains critical syntax errors as it appears to be a direct translation from a Python sample, using Python-style comments and docstrings in a Java file. This will prevent the code from compiling. Additionally, there are some redundant code region tags and a lack of robust error handling for API responses, which could lead to runtime exceptions. My review includes suggestions to correct these issues to make the sample valid and robust.

Comment on lines 1 to 17
"""
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.
"""

# [START sheets_filter_views]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This file contains Python-style syntax that will cause compilation errors in Java. The file header (lines 1-15) uses a Python docstring ("""...""") instead of a Java block comment (/* ... */), and the region tag on line 17 uses a Python comment character (#) instead of //.

/*
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.
*/

// [START sheets_filter_views]

}
}

# [END sheets_filter_views]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This line uses a Python-style comment (#) which is a syntax error in Java. Please use // for single-line comments.

Suggested change
# [END sheets_filter_views]
// [END sheets_filter_views]

Comment on lines 40 to 42
// [START sheets_filter_views]
filterViews("1CM29gwKIzeXsAppeNwrc8lbYaVMmUclprLuLYuHog4k");
// [END sheets_filter_views]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

These [START ...] and [END ...] region tags appear to be redundant. The entire file content relevant to the sample is already wrapped in sheets_filter_views region tags (on lines 17 and 152, though they currently have incorrect syntax). Having nested tags for the same region can cause issues with sample processing tools. Please remove these inner tags.

        filterViews("1CM29gwKIzeXsAppeNwrc8lbYaVMmUclprLuLYuHog4k");

Comment on lines +100 to +101
int filterId = response1.getReplies().get(0)
.getAddFilterView().getFilter().getFilterViewId();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The code directly accesses nested properties of the API responses (response1 on this line, and response2 on line 115) without any validation. If an API call doesn't return the expected structure (e.g., due to an error or an empty list of replies), this will cause a NullPointerException or IndexOutOfBoundsException at runtime. You should add checks to ensure the response objects and lists are not null or empty before accessing them.

Copy link
Author

@kencenerelli kencenerelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed malformed commenting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants