This repository has been archived by the owner on Sep 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
06d828c
commit fc6a167
Showing
33 changed files
with
2,189 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
samples/snippets/src/main/java/com/example/datacatalog/CreateEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
samples/snippets/src/main/java/com/example/datacatalog/CreateTagTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
50 changes: 50 additions & 0 deletions
50
samples/snippets/src/main/java/com/example/datacatalog/DeleteEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
49 changes: 49 additions & 0 deletions
49
samples/snippets/src/main/java/com/example/datacatalog/DeleteEntryGroup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
49 changes: 49 additions & 0 deletions
49
samples/snippets/src/main/java/com/example/datacatalog/DeleteTagTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
Oops, something went wrong.