Skip to content
Permalink
Browse files
docs(samples): add Entry, EntryGroup and TagTemplate (#394)
* docs(samples): add Entry, EntryGroup and TagTemplate

* fix IT

* update sample

* Update CreateEntryGroupIT.java

* Update CreateEntryTests.java

Co-authored-by: Stephanie Wang <stephaniewang526@users.noreply.github.com>
  • Loading branch information
Praful Makani and stephaniewang526 committed Jun 30, 2021
1 parent 06d828c commit fc6a167d9b7be8b18edb5cb6515779beaa86c6ee
Showing with 2,189 additions and 30 deletions.
  1. +5 −0 samples/install-without-bom/pom.xml
  2. +5 −0 samples/snapshot/pom.xml
  3. +5 −0 samples/snippets/pom.xml
  4. +57 −0 samples/snippets/src/main/java/com/example/datacatalog/CreateEntry.java
  5. +14 −24 samples/snippets/src/main/java/com/example/datacatalog/CreateEntryGroup.java
  6. +1 −1 samples/snippets/src/main/java/com/example/datacatalog/CreateFilesetEntry.java
  7. +68 −0 samples/snippets/src/main/java/com/example/datacatalog/CreateTagTemplate.java
  8. +50 −0 samples/snippets/src/main/java/com/example/datacatalog/DeleteEntry.java
  9. +49 −0 samples/snippets/src/main/java/com/example/datacatalog/DeleteEntryGroup.java
  10. +49 −0 samples/snippets/src/main/java/com/example/datacatalog/DeleteTagTemplate.java
  11. +48 −0 samples/snippets/src/main/java/com/example/datacatalog/GetEntry.java
  12. +47 −0 samples/snippets/src/main/java/com/example/datacatalog/GetEntryGroup.java
  13. +50 −0 samples/snippets/src/main/java/com/example/datacatalog/GetTagTemplate.java
  14. +51 −0 samples/snippets/src/main/java/com/example/datacatalog/ListEntries.java
  15. +55 −0 samples/snippets/src/main/java/com/example/datacatalog/ListEntryGroups.java
  16. +57 −0 samples/snippets/src/main/java/com/example/datacatalog/UpdateEntry.java
  17. +62 −0 samples/snippets/src/main/java/com/example/datacatalog/UpdateEntryGroup.java
  18. +63 −0 samples/snippets/src/main/java/com/example/datacatalog/UpdateTagTemplate.java
  19. +84 −0 samples/snippets/src/test/java/com/example/datacatalog/CreateEntryGroupIT.java
  20. +119 −0 samples/snippets/src/test/java/com/example/datacatalog/CreateEntryIT.java
  21. +6 −5 samples/snippets/src/test/java/com/example/datacatalog/CreateEntryTests.java
  22. +100 −0 samples/snippets/src/test/java/com/example/datacatalog/CreateTagTemplateIT.java
  23. +84 −0 samples/snippets/src/test/java/com/example/datacatalog/DeleteEntryGroupIT.java
  24. +120 −0 samples/snippets/src/test/java/com/example/datacatalog/DeleteEntryIT.java
  25. +100 −0 samples/snippets/src/test/java/com/example/datacatalog/DeleteTagTemplateIT.java
  26. +87 −0 samples/snippets/src/test/java/com/example/datacatalog/GetEntryGroupIT.java
  27. +121 −0 samples/snippets/src/test/java/com/example/datacatalog/GetEntryIT.java
  28. +103 −0 samples/snippets/src/test/java/com/example/datacatalog/GetTagTemplateIT.java
  29. +121 −0 samples/snippets/src/test/java/com/example/datacatalog/ListEntriesIT.java
  30. +87 −0 samples/snippets/src/test/java/com/example/datacatalog/ListEntryGroupsIT.java
  31. +90 −0 samples/snippets/src/test/java/com/example/datacatalog/UpdateEntryGroupIT.java
  32. +123 −0 samples/snippets/src/test/java/com/example/datacatalog/UpdateEntryIT.java
  33. +108 −0 samples/snippets/src/test/java/com/example/datacatalog/UpdateTagTemplateIT.java
@@ -33,6 +33,11 @@
</dependency>
<!-- [END datacatalog_install_without_bom] -->

<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>3.14.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -31,6 +31,11 @@
<version>1.4.1</version>
</dependency>

<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>3.14.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -44,6 +44,11 @@
</dependency>
<!-- [END datacatalog_install_with_bom] -->

<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>3.14.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -0,0 +1,57 @@
/*
* Copyright 2020 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.example.datacatalog;

// [START data_catalog_create_entry]
import com.google.cloud.datacatalog.v1.CreateEntryRequest;
import com.google.cloud.datacatalog.v1.DataCatalogClient;
import com.google.cloud.datacatalog.v1.Entry;
import com.google.cloud.datacatalog.v1.EntryGroupName;
import java.io.IOException;

// Sample to create an entry
public class CreateEntry {

public static void main(String[] args) throws IOException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "MY_PROJECT_ID";
String location = "MY_LOCATION";
String entryGroupId = "MY_ENTRY_GROUP_ID";
String entryId = "MY_ENTRY_ID";
EntryGroupName entryGroupName = EntryGroupName.of(projectId, location, entryGroupId);
Entry entry = Entry.newBuilder().build();
createEntry(entryGroupName, entryId, entry);
}

public static void createEntry(EntryGroupName entryGroupName, String entryId, Entry entry)
throws IOException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
try (DataCatalogClient client = DataCatalogClient.create()) {
CreateEntryRequest request =
CreateEntryRequest.newBuilder()
.setParent(entryGroupName.toString())
.setEntryId(entryId)
.setEntry(entry)
.build();
client.createEntry(request);
System.out.println("Entry created successfully");
}
}
}
// [END data_catalog_create_entry]
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Google Inc.
* Copyright 2020 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,57 +16,47 @@

package com.example.datacatalog;

// [START datacatalog_create_entry_group_tag]

import com.google.api.gax.rpc.AlreadyExistsException;
// [START data_catalog_create_entry_group]
import com.google.cloud.datacatalog.v1.CreateEntryGroupRequest;
import com.google.cloud.datacatalog.v1.DataCatalogClient;
import com.google.cloud.datacatalog.v1.EntryGroup;
import com.google.cloud.datacatalog.v1.LocationName;
import java.io.IOException;

// Sample to create an entry group
public class CreateEntryGroup {

public static void createEntryGroup() {
public static void main(String[] args) throws IOException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "my-project-id";
String entryGroupId = "fileset_entry_group";
createEntryGroup(projectId, entryGroupId);
String projectId = "MY_PROJECT_ID";
String location = "us-central1";
String entryGroupId = "MY_ENTRY_GROUP_ID";
createEntryGroup(projectId, location, entryGroupId);
}

// Create Entry Group.
public static void createEntryGroup(String projectId, String entryGroupId) {
// Currently, Data Catalog stores metadata in the us-central1 region.
String location = "us-central1";

public static void createEntryGroup(String projectId, String location, String entryGroupId)
throws IOException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
try (DataCatalogClient dataCatalogClient = DataCatalogClient.create()) {
// Construct the EntryGroup for the EntryGroup request.
EntryGroup entryGroup =
EntryGroup.newBuilder()
.setDisplayName("My Fileset Entry Group")
.setDisplayName("MY Entry Group")
.setDescription("This Entry Group consists of ....")
.build();

// Construct the EntryGroup request to be sent by the client.
CreateEntryGroupRequest entryGroupRequest =
CreateEntryGroupRequest.newBuilder()
.setParent(LocationName.of(projectId, location).toString())
.setEntryGroupId(entryGroupId)
.setEntryGroup(entryGroup)
.build();

// Use the client to send the API request.
EntryGroup entryGroupResponse = dataCatalogClient.createEntryGroup(entryGroupRequest);
System.out.printf("\nEntry Group created with name: %s\n", entryGroupResponse.getName());
} catch (AlreadyExistsException | IOException e) {
// AlreadyExistsException's are thrown if EntryGroup or Entry already exists.
// IOException's are thrown when unable to create the DataCatalogClient,
// for example an invalid Service Account path.
System.out.println("Error in create entry process:\n" + e.toString());
dataCatalogClient.createEntryGroup(entryGroupRequest);
System.out.println("Entry Group created successfully");
}
}
}
// [END datacatalog_create_entry_group_tag]
// [END data_catalog_create_entry_group]
@@ -115,4 +115,4 @@ public static void createEntry(String projectId, String entryGroupId, String ent
}
}
}
// [END datacatalog_create_fileset_tag]
// [END datacatalog_create_fileset_tag]
@@ -0,0 +1,68 @@
/*
* Copyright 2020 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.example.datacatalog;

// [START data_catalog_create_tag_template]
import com.google.cloud.datacatalog.v1.CreateTagTemplateRequest;
import com.google.cloud.datacatalog.v1.DataCatalogClient;
import com.google.cloud.datacatalog.v1.FieldType;
import com.google.cloud.datacatalog.v1.LocationName;
import com.google.cloud.datacatalog.v1.TagTemplate;
import com.google.cloud.datacatalog.v1.TagTemplateField;
import java.io.IOException;

// Sample to create tag template
public class CreateTagTemplate {

public static void main(String[] args) throws IOException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "MY_PROJECT_ID";
String location = "MY_LOCATION";
LocationName locationName = LocationName.of(projectId, location);
String tagTemplateId = "MY_TAG_TEMPLATE_ID";
TagTemplateField sourceField =
TagTemplateField.newBuilder()
.setDisplayName("Your display name")
.setType(
FieldType.newBuilder().setPrimitiveType(FieldType.PrimitiveType.STRING).build())
.build();
TagTemplate tagTemplate =
TagTemplate.newBuilder()
.setDisplayName("Your display name")
.putFields("sourceField", sourceField)
.build();
createTagTemplate(locationName, tagTemplateId, tagTemplate);
}

public static void createTagTemplate(
LocationName name, String tagTemplateId, TagTemplate template) throws IOException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
try (DataCatalogClient client = DataCatalogClient.create()) {
CreateTagTemplateRequest request =
CreateTagTemplateRequest.newBuilder()
.setParent(name.toString())
.setTagTemplateId(tagTemplateId)
.setTagTemplate(template)
.build();
client.createTagTemplate(request);
System.out.println("Tag template created successfully");
}
}
}
// [END data_catalog_create_tag_template]
@@ -0,0 +1,50 @@
/*
* Copyright 2020 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.example.datacatalog;

// [START data_catalog_delete_entry]
import com.google.cloud.datacatalog.v1.DataCatalogClient;
import com.google.cloud.datacatalog.v1.DeleteEntryRequest;
import com.google.cloud.datacatalog.v1.EntryName;
import java.io.IOException;

// Sample to delete a entry
public class DeleteEntry {

public static void main(String[] args) throws IOException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "MY_PROJECT_ID";
String location = "MY_LOCATION";
String entryGroupId = "MY_ENTRY_GROUP_ID";
String entryId = "MY_ENTRY_ID";
EntryName entryName = EntryName.of(projectId, location, entryGroupId, entryId);
deleteEntry(entryName);
}

public static void deleteEntry(EntryName entryName) throws IOException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
try (DataCatalogClient client = DataCatalogClient.create()) {
DeleteEntryRequest request =
DeleteEntryRequest.newBuilder().setName(entryName.toString()).build();
client.deleteEntry(request);
System.out.println("Entry deleted successfully");
}
}
}
// [END data_catalog_delete_entry]
@@ -0,0 +1,49 @@
/*
* Copyright 2020 Google Inc.
*
* 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.example.datacatalog;

// [START data_catalog_delete_entry_group]
import com.google.cloud.datacatalog.v1.DataCatalogClient;
import com.google.cloud.datacatalog.v1.DeleteEntryGroupRequest;
import com.google.cloud.datacatalog.v1.EntryGroupName;
import java.io.IOException;

// Sample to delete a entry group
public class DeleteEntryGroup {

public static void main(String[] args) throws IOException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "MY_PROJECT_ID";
String location = "MY_LOCATION";
String entryGroupId = "MY_ENTRY_GROUP_ID";
EntryGroupName entryGroupName = EntryGroupName.of(projectId, location, entryGroupId);
deleteEntryGroup(entryGroupName);
}

public static void deleteEntryGroup(EntryGroupName entryGroupName) throws IOException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
try (DataCatalogClient client = DataCatalogClient.create()) {
DeleteEntryGroupRequest request =
DeleteEntryGroupRequest.newBuilder().setName(entryGroupName.toString()).build();
client.deleteEntryGroup(request);
System.out.println("Entry group deleted successfully");
}
}
}
// [END data_catalog_delete_entry_group]
@@ -0,0 +1,49 @@
/*
* Copyright 2020 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.example.datacatalog;

// [START data_catalog_delete_tag_template]
import com.google.cloud.datacatalog.v1.DataCatalogClient;
import com.google.cloud.datacatalog.v1.DeleteTagTemplateRequest;
import com.google.cloud.datacatalog.v1.TagTemplateName;
import java.io.IOException;

// Sample to delete tag template
public class DeleteTagTemplate {

public static void main(String[] args) throws IOException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "MY_PROJECT_ID";
String location = "MY_LOCATION";
String tagTemplateId = "MY_TAG_TEMPLATE_ID";
TagTemplateName tagTemplate = TagTemplateName.of(projectId, location, tagTemplateId);
deleteTagTemplate(tagTemplate);
}

public static void deleteTagTemplate(TagTemplateName template) throws IOException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
try (DataCatalogClient client = DataCatalogClient.create()) {
DeleteTagTemplateRequest request =
DeleteTagTemplateRequest.newBuilder().setName(template.toString()).setForce(true).build();
client.deleteTagTemplate(request);
System.out.println("Tag template deleted successfully");
}
}
}
// [END data_catalog_delete_tag_template]

0 comments on commit fc6a167

Please sign in to comment.