Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dataplex): add code samples for search Entries #9609

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jacspa96
Copy link
Contributor

Description

Fixes b/368505575

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

  • I have followed Sample Format Guide
  • pom.xml parent set to latest shared-configuration
  • Appropriate changes to README are included in PR
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • Tests pass: mvn clean verify required
  • Lint passes: mvn -P lint checkstyle:check required
  • Static Analysis: mvn -P lint clean compile pmd:cpd-check spotbugs:check advisory only
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

@product-auto-label product-auto-label bot added api: dataplex Issues related to the Dataplex API. samples Issues that are directly related to samples. labels Oct 29, 2024
@jacspa96 jacspa96 marked this pull request as ready for review October 29, 2024 11:53
@jacspa96 jacspa96 requested review from yoshi-approver and a team as code owners October 29, 2024 11:53
Copy link

snippet-bot bot commented Oct 29, 2024

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

Copy link
Contributor

@minherz minherz left a comment

Choose a reason for hiding this comment

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

good coding styles.
please refactor the code to address the comments.

Copy link
Contributor

Choose a reason for hiding this comment

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

IF you want to demonstrate pagination, please refactor the code to either

  1. return all results from all pages for the given number of pages
  2. implement a smart iterator that "knows" to pull additional results when reaches the end of the page

either of them should be placed in the method that shows the implementation.

IF you want to demonstrate how to pull query results ONLY, remove paging from the picture and increase the size of the page to, say, 100 entries.

Comment on lines +43 to +47
List<Entry> entries =
searchEntriesResponse.getResultsList().stream()
// Extract Entries nested inside search results
.map(SearchEntriesResult::getDataplexEntry)
.collect(Collectors.toList());
Copy link
Contributor

Choose a reason for hiding this comment

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

please place this code into the code sample. if this code is not intended to demonstrate anything then remove this code. the main() method should be a simple setup and a call to the code samples. additional transformations in main() are confusing because it is unclear whether it is part of the code sample or not.

Comment on lines +67 to +73
// There are 2 ways to limit the scope of the search:
// 1) Set the "scope" field, with either "projects/<>" or "organizations/<>",
// which will limit the search to resources residing in given project / organization.
// 2) Leave "scope" field blank. In that case scope will be limited to organization in
// which project from "name" field is located.
// Please note that field "name" must always be filled, as the request itself will be
// attributed to that.
Copy link
Contributor

Choose a reason for hiding this comment

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

such large comments in code samples point to a problem. either create two code samples to demonstrate different principles or remove this comment.
if you decide to use two code samples, please follow a code sample per class principle.

Comment on lines +57 to +58
expectedEntry =
String.format("locations/%s/entryGroups/%s/entries/%s", LOCATION, entryGroupId, entryId);
Copy link
Contributor

Choose a reason for hiding this comment

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

need refactoring: move this to be a constant in the class declaration like LOCATION or ID

Comment on lines +49 to +52
@BeforeClass
public static void checkRequirements() {
requireProjectIdEnvVar();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

need refactoring: please combine all initial setup into a single method

CreateEntryGroup.createEntryGroup(PROJECT_ID, LOCATION, entryGroupId);
// Create Entry that will be used in tests
CreateEntry.createEntry(PROJECT_ID, LOCATION, entryGroupId, entryId);
// Wait 30 seconds to allow Entry to propagate to Search
Copy link
Contributor

Choose a reason for hiding this comment

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

delete this comment. the code is self-explanatory

}

@AfterClass
// Clean-up code that will be executed after all tests
Copy link
Contributor

Choose a reason for hiding this comment

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

delete this comment. the code is self-explanatory

}

@BeforeClass
// Set-up code that will be executed before all tests
Copy link
Contributor

Choose a reason for hiding this comment

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

delete this comment. the code is self-explanatory

@AfterClass
// Clean-up code that will be executed after all tests
public static void tearDown() throws Exception {
// Clean-up Entry Group resource created in setUp()
Copy link
Contributor

Choose a reason for hiding this comment

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

delete this comment. the code is self-explanatory

// Clean-up code that will be executed after all tests
public static void tearDown() throws Exception {
// Clean-up Entry Group resource created in setUp()
// Entry inside this Entry Group will be deleted automatically
Copy link
Contributor

Choose a reason for hiding this comment

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

this comment is required to clarify 1 "delete" vs. 2 "create"'s

@minherz minherz assigned jacspa96 and unassigned przemkow Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: dataplex Issues related to the Dataplex API. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants