From 384162d200caac7cc277b5e85de2ec17f82b223b Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Fri, 23 Jun 2023 21:45:04 -0700 Subject: [PATCH 01/29] add sample code for set acl --- document-warehouse/package.json | 3 +- document-warehouse/set-acl.js | 81 +++++++++++++++++++++++++ document-warehouse/test/set-acl.test.js | 50 +++++++++++++++ 3 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 document-warehouse/set-acl.js create mode 100644 document-warehouse/test/set-acl.test.js diff --git a/document-warehouse/package.json b/document-warehouse/package.json index 3f22485e62..ecccbf59c3 100644 --- a/document-warehouse/package.json +++ b/document-warehouse/package.json @@ -8,6 +8,7 @@ }, "dependencies": { "@google-cloud/contentwarehouse": "^0.5.1", - "assert": "^2.0.0" + "assert": "^2.0.0", + "json": "^11.0.0" } } diff --git a/document-warehouse/set-acl.js b/document-warehouse/set-acl.js new file mode 100644 index 0000000000..3060ddb719 --- /dev/null +++ b/document-warehouse/set-acl.js @@ -0,0 +1,81 @@ +/** Copyright 2023 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. + */ + +'use strict'; + +async function main( + projectId = 'YOUR_PROJECT_ID', + location = 'YOUR_PROJECT_LOCATION', + policyRole = 'YOUR_REQUESTED_ROLE', + policyMember = 'YOUR_REQUESTED_MEMBER', + userId = 'user:xxxx@example.com', + documentId = 'YOUR_DOCUMENT_ID' +) { + // [START contentwarehouse_set_acl] + /** + * TODO(developer): Uncomment these variables before running the sample. + * project_id = 'YOUR_PROJECT_ID' + * location = 'YOUR_PROJECT_LOCATION' // Format is 'us' or 'eu' + * policyRole = 'YOUR_REQUESTED_ROLE', + * policyMember = 'YOUR_REQUESTED_MEMBER', + * user_id = 'user:YOUR_SERVICE_ACCOUNT_ID' # Format is "user:xxxx@example.com" + * document_id = 'YOUR_DOCUMENT_ID' + */ + + //Import service client from google cloud + const {DocumentServiceClient} = require('@google-cloud/contentwarehouse').v1; + + // Create client + const serviceClient = new DocumentServiceClient(); + + // Set access control policies on project or document level. + async function setACL() { + //Initialize request argument(s) + const request = {}; + request.policy = { + bindings:[{ + role: policyRole, + members: [policyMember] + }] + }; + if (documentId !== 'YOUR_DOCUMENT_ID') { + // Full document resource name, e.g.: + // projects/{project_id}/locations/{location}/documents/{document_id} + request.resource = `projects/${projectId}/locations/${location}/documents/${documentId}`; + request.requestMetadata = {userInfo: {id: userId}}; + } else { + // Full document resource name, e.g.: projects/{project_id} + request.resource = `projects/${projectId}`; + request.projectOwner = true; + } + + // Make Request + const response = serviceClient.setAcl(request); + + // Print Response + response.then( + result => console.log(`Success! Response: \n${JSON.stringify(result)}`), + error => console.log(`Failed! Response: \n${error}`) + ); + } + + // [END contentwarehouse_set_acl] + await setACL(); +} + +main(...process.argv.slice(2)).catch(err => { + console.error(err); + process.exitCode = 1; +}); \ No newline at end of file diff --git a/document-warehouse/test/set-acl.test.js b/document-warehouse/test/set-acl.test.js new file mode 100644 index 0000000000..b1ef48f559 --- /dev/null +++ b/document-warehouse/test/set-acl.test.js @@ -0,0 +1,50 @@ +/** Copyright 2023 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. + */ + +'use strict'; + +const cp = require('child_process'); +const path = require('path'); +const assert = require('assert'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); +const cwd = path.join(__dirname, '..'); +const PROJECT_ID_PASS = 'YOUR_PROJECT_ID'; +const PROJECT_ID_FAILED = 'PROJECT_ID_WITHOUT_ACL'; +const LOCATION = 'us'; +const POLICY_ROLE = 'roles/contentwarehouse.documentAdmin'; +const POLICY_MEMBER = 'user:xxxx@example.com'; +const USER_ID = 'user:xxxx@example.com'; +const DOCUMENT_ID = 'YOUR_DOCUMENT_ID'; + +describe('Set document acl', () => { + it('should set acl given no userId', async () => { + const stdout = execSync(`node ./set-acl.js ${PROJECT_ID_PASS} ${LOCATION} ${POLICY_ROLE} ${POLICY_MEMBER} ${USER_ID}`, {cwd}); + assert(stdout.startsWith('Success!')); + }); + + it('should set acl given a documentId', async () => { + const stdout = execSync( + `node ./set-acl.js ${PROJECT_ID_PASS} ${LOCATION} ${POLICY_ROLE} ${POLICY_MEMBER} ${USER_ID} ${DOCUMENT_ID}`, + {cwd} + ); + assert(stdout.startsWith('Success!')); + }); + + it('should fail given an incorrect projectId', async () => { + const stdout = execSync(`node ./set-acl.js ${PROJECT_ID_FAILED}`, {cwd}); + assert(stdout.startsWith('Failed!')); + }); +}); From 3948b7953c0af51fbdd17a64a73630c65a86d0a6 Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Fri, 23 Jun 2023 22:03:35 -0700 Subject: [PATCH 02/29] lint fix --- document-warehouse/set-acl.js | 14 ++++++++------ document-warehouse/test/set-acl.test.js | 5 ++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/document-warehouse/set-acl.js b/document-warehouse/set-acl.js index 3060ddb719..cd992c0373 100644 --- a/document-warehouse/set-acl.js +++ b/document-warehouse/set-acl.js @@ -45,10 +45,12 @@ async function main( //Initialize request argument(s) const request = {}; request.policy = { - bindings:[{ - role: policyRole, - members: [policyMember] - }] + bindings: [ + { + role: policyRole, + members: [policyMember], + }, + ], }; if (documentId !== 'YOUR_DOCUMENT_ID') { // Full document resource name, e.g.: @@ -63,7 +65,7 @@ async function main( // Make Request const response = serviceClient.setAcl(request); - + // Print Response response.then( result => console.log(`Success! Response: \n${JSON.stringify(result)}`), @@ -78,4 +80,4 @@ async function main( main(...process.argv.slice(2)).catch(err => { console.error(err); process.exitCode = 1; -}); \ No newline at end of file +}); diff --git a/document-warehouse/test/set-acl.test.js b/document-warehouse/test/set-acl.test.js index b1ef48f559..3947ef6671 100644 --- a/document-warehouse/test/set-acl.test.js +++ b/document-warehouse/test/set-acl.test.js @@ -31,7 +31,10 @@ const DOCUMENT_ID = 'YOUR_DOCUMENT_ID'; describe('Set document acl', () => { it('should set acl given no userId', async () => { - const stdout = execSync(`node ./set-acl.js ${PROJECT_ID_PASS} ${LOCATION} ${POLICY_ROLE} ${POLICY_MEMBER} ${USER_ID}`, {cwd}); + const stdout = execSync( + `node ./set-acl.js ${PROJECT_ID_PASS} ${LOCATION} ${POLICY_ROLE} ${POLICY_MEMBER} ${USER_ID}`, + {cwd} + ); assert(stdout.startsWith('Success!')); }); From 777d0a5e3dbf873ee37ab15988de7c28f56e1d3d Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Sat, 24 Jun 2023 05:06:16 -0700 Subject: [PATCH 03/29] add main function --- document-warehouse/search-document.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 document-warehouse/search-document.js diff --git a/document-warehouse/search-document.js b/document-warehouse/search-document.js new file mode 100644 index 0000000000..edafa97d41 --- /dev/null +++ b/document-warehouse/search-document.js @@ -0,0 +1,25 @@ +/** Copyright 2023 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. + */ + +'use strict'; + +async function main() { + +} + +main(...process.argv.slice(2)).catch(err => { + console.error(err); + process.exitCode = 1; +}); \ No newline at end of file From 8ead25ea3e2188509fcabaab4e23ff748d991184 Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Sat, 24 Jun 2023 05:22:32 -0700 Subject: [PATCH 04/29] add search function --- document-warehouse/search-document.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/document-warehouse/search-document.js b/document-warehouse/search-document.js index edafa97d41..3eb4e13363 100644 --- a/document-warehouse/search-document.js +++ b/document-warehouse/search-document.js @@ -15,8 +15,31 @@ 'use strict'; -async function main() { +async function main( + projectId = 'YOUR_PROJECT_ID', + location = 'YOUR_PROJECT_LOCATION', + query = 'YOUR_DOCUMENT_QUERY', +) { + // [START contentwarehouse_search_documents] + /** + * TODO(developer): Uncomment these variables before running the sample. + * projectId = 'YOUR_PROJECT_ID' + * location = 'YOUR_PROJECT_LOCATION' // Format is 'us' or 'eu' + * query = 'YOUR_DOCUMENT_QUERY' + */ + // Import service client from google cloud + const {DocumentServiceClient} = require('@google-cloud/contentwarehouse').v1; + + // Create client + const serviceClient = new DocumentServiceClient(); + + // Search document + async function searchDocument() { + + } + + // [END contentwarehouse_search_documents] } main(...process.argv.slice(2)).catch(err => { From 50df4ec7e801d2389b4f75195d45648d9af9dac4 Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Sat, 24 Jun 2023 05:23:44 -0700 Subject: [PATCH 05/29] add search function --- document-warehouse/search-document.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/document-warehouse/search-document.js b/document-warehouse/search-document.js index 3eb4e13363..1e220046a7 100644 --- a/document-warehouse/search-document.js +++ b/document-warehouse/search-document.js @@ -36,10 +36,11 @@ async function main( // Search document async function searchDocument() { - + // TODO: Fill in } // [END contentwarehouse_search_documents] + await searchDocument(); } main(...process.argv.slice(2)).catch(err => { From 96a30037b2982c37e4356c92e3dbb81733009782 Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Sat, 24 Jun 2023 10:00:06 -0700 Subject: [PATCH 06/29] start creating request --- document-warehouse/search-document.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/document-warehouse/search-document.js b/document-warehouse/search-document.js index 1e220046a7..c79df0168a 100644 --- a/document-warehouse/search-document.js +++ b/document-warehouse/search-document.js @@ -36,7 +36,9 @@ async function main( // Search document async function searchDocument() { - // TODO: Fill in + // Initialize request arguments + const request = {}; + } // [END contentwarehouse_search_documents] From 7cbe4c2ada7c7abc52822df96ffb6d8fb2ff63d9 Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Sat, 24 Jun 2023 10:02:18 -0700 Subject: [PATCH 07/29] fix package.json --- document-warehouse/package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/document-warehouse/package.json b/document-warehouse/package.json index ecccbf59c3..79fd5217c8 100644 --- a/document-warehouse/package.json +++ b/document-warehouse/package.json @@ -7,8 +7,9 @@ "test": "c8 mocha test/*.js --timeout 600000" }, "dependencies": { - "@google-cloud/contentwarehouse": "^0.5.1", - "assert": "^2.0.0", - "json": "^11.0.0" + "@google-cloud/contentwarehouse": "^0.5.1" + }, + "devDependencies": { + "assert": "^2.0.0" } } From 2b8a0289ef34f3ebe2cfab95e4167c1d4006e0ee Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Mon, 26 Jun 2023 17:19:13 -0700 Subject: [PATCH 08/29] working on printing result --- document-warehouse/search-document.js | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/document-warehouse/search-document.js b/document-warehouse/search-document.js index c79df0168a..453c588d5f 100644 --- a/document-warehouse/search-document.js +++ b/document-warehouse/search-document.js @@ -38,7 +38,44 @@ async function main( async function searchDocument() { // Initialize request arguments const request = {}; + // Full document resource name, e.g.: projects/{project_id}/locations/{location} + request.parent = `projects/${projectId}/locations/${location}`; + // File Type Filter + // Options: DOCUMENT, FOLDER + const fileTypeFilter = { + fileType: DOCUMENT + }; + // Search Prompt + const documentQuery = { + query: query, + fileTypeFilter : fileTypeFilter + }; + request.documentQuery = documentQuery; + request.histogramQueries = [{histogramQuery:'count("DocumentSchemaId")'}]; + + // Make Request + const response = serviceClient.searchDocuments(request); + + // Print Search Results + for (matchingDocument in response.matchingDocuments) { + const document = matchingDocument.document; + console.log(` + ${document.displayName} - ${document.documentSchemaName}\n + ${document.name}\n + ${document.createTime}\n + ${matchingDocument.searchTextSnippet}\n + `); + } + // Print Histogram + for (result in response.histogramQueryResults){ + console.log(` + History Query: ${result.historyQuery}\n + + //TODO + `) + } + } // [END contentwarehouse_search_documents] From 073034b78a61ec58dd75888e3503741e5d13d9a3 Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Fri, 23 Jun 2023 21:45:04 -0700 Subject: [PATCH 09/29] add sample code for set acl --- document-warehouse/package.json | 3 +- document-warehouse/set-acl.js | 81 +++++++++++++++++++++++++ document-warehouse/test/set-acl.test.js | 50 +++++++++++++++ 3 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 document-warehouse/set-acl.js create mode 100644 document-warehouse/test/set-acl.test.js diff --git a/document-warehouse/package.json b/document-warehouse/package.json index 3f22485e62..ecccbf59c3 100644 --- a/document-warehouse/package.json +++ b/document-warehouse/package.json @@ -8,6 +8,7 @@ }, "dependencies": { "@google-cloud/contentwarehouse": "^0.5.1", - "assert": "^2.0.0" + "assert": "^2.0.0", + "json": "^11.0.0" } } diff --git a/document-warehouse/set-acl.js b/document-warehouse/set-acl.js new file mode 100644 index 0000000000..3060ddb719 --- /dev/null +++ b/document-warehouse/set-acl.js @@ -0,0 +1,81 @@ +/** Copyright 2023 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. + */ + +'use strict'; + +async function main( + projectId = 'YOUR_PROJECT_ID', + location = 'YOUR_PROJECT_LOCATION', + policyRole = 'YOUR_REQUESTED_ROLE', + policyMember = 'YOUR_REQUESTED_MEMBER', + userId = 'user:xxxx@example.com', + documentId = 'YOUR_DOCUMENT_ID' +) { + // [START contentwarehouse_set_acl] + /** + * TODO(developer): Uncomment these variables before running the sample. + * project_id = 'YOUR_PROJECT_ID' + * location = 'YOUR_PROJECT_LOCATION' // Format is 'us' or 'eu' + * policyRole = 'YOUR_REQUESTED_ROLE', + * policyMember = 'YOUR_REQUESTED_MEMBER', + * user_id = 'user:YOUR_SERVICE_ACCOUNT_ID' # Format is "user:xxxx@example.com" + * document_id = 'YOUR_DOCUMENT_ID' + */ + + //Import service client from google cloud + const {DocumentServiceClient} = require('@google-cloud/contentwarehouse').v1; + + // Create client + const serviceClient = new DocumentServiceClient(); + + // Set access control policies on project or document level. + async function setACL() { + //Initialize request argument(s) + const request = {}; + request.policy = { + bindings:[{ + role: policyRole, + members: [policyMember] + }] + }; + if (documentId !== 'YOUR_DOCUMENT_ID') { + // Full document resource name, e.g.: + // projects/{project_id}/locations/{location}/documents/{document_id} + request.resource = `projects/${projectId}/locations/${location}/documents/${documentId}`; + request.requestMetadata = {userInfo: {id: userId}}; + } else { + // Full document resource name, e.g.: projects/{project_id} + request.resource = `projects/${projectId}`; + request.projectOwner = true; + } + + // Make Request + const response = serviceClient.setAcl(request); + + // Print Response + response.then( + result => console.log(`Success! Response: \n${JSON.stringify(result)}`), + error => console.log(`Failed! Response: \n${error}`) + ); + } + + // [END contentwarehouse_set_acl] + await setACL(); +} + +main(...process.argv.slice(2)).catch(err => { + console.error(err); + process.exitCode = 1; +}); \ No newline at end of file diff --git a/document-warehouse/test/set-acl.test.js b/document-warehouse/test/set-acl.test.js new file mode 100644 index 0000000000..b1ef48f559 --- /dev/null +++ b/document-warehouse/test/set-acl.test.js @@ -0,0 +1,50 @@ +/** Copyright 2023 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. + */ + +'use strict'; + +const cp = require('child_process'); +const path = require('path'); +const assert = require('assert'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); +const cwd = path.join(__dirname, '..'); +const PROJECT_ID_PASS = 'YOUR_PROJECT_ID'; +const PROJECT_ID_FAILED = 'PROJECT_ID_WITHOUT_ACL'; +const LOCATION = 'us'; +const POLICY_ROLE = 'roles/contentwarehouse.documentAdmin'; +const POLICY_MEMBER = 'user:xxxx@example.com'; +const USER_ID = 'user:xxxx@example.com'; +const DOCUMENT_ID = 'YOUR_DOCUMENT_ID'; + +describe('Set document acl', () => { + it('should set acl given no userId', async () => { + const stdout = execSync(`node ./set-acl.js ${PROJECT_ID_PASS} ${LOCATION} ${POLICY_ROLE} ${POLICY_MEMBER} ${USER_ID}`, {cwd}); + assert(stdout.startsWith('Success!')); + }); + + it('should set acl given a documentId', async () => { + const stdout = execSync( + `node ./set-acl.js ${PROJECT_ID_PASS} ${LOCATION} ${POLICY_ROLE} ${POLICY_MEMBER} ${USER_ID} ${DOCUMENT_ID}`, + {cwd} + ); + assert(stdout.startsWith('Success!')); + }); + + it('should fail given an incorrect projectId', async () => { + const stdout = execSync(`node ./set-acl.js ${PROJECT_ID_FAILED}`, {cwd}); + assert(stdout.startsWith('Failed!')); + }); +}); From 8441f73266d6065126f3fe935888fed0d304a2ca Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Fri, 23 Jun 2023 22:03:35 -0700 Subject: [PATCH 10/29] lint fix --- document-warehouse/set-acl.js | 14 ++++++++------ document-warehouse/test/set-acl.test.js | 5 ++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/document-warehouse/set-acl.js b/document-warehouse/set-acl.js index 3060ddb719..cd992c0373 100644 --- a/document-warehouse/set-acl.js +++ b/document-warehouse/set-acl.js @@ -45,10 +45,12 @@ async function main( //Initialize request argument(s) const request = {}; request.policy = { - bindings:[{ - role: policyRole, - members: [policyMember] - }] + bindings: [ + { + role: policyRole, + members: [policyMember], + }, + ], }; if (documentId !== 'YOUR_DOCUMENT_ID') { // Full document resource name, e.g.: @@ -63,7 +65,7 @@ async function main( // Make Request const response = serviceClient.setAcl(request); - + // Print Response response.then( result => console.log(`Success! Response: \n${JSON.stringify(result)}`), @@ -78,4 +80,4 @@ async function main( main(...process.argv.slice(2)).catch(err => { console.error(err); process.exitCode = 1; -}); \ No newline at end of file +}); diff --git a/document-warehouse/test/set-acl.test.js b/document-warehouse/test/set-acl.test.js index b1ef48f559..3947ef6671 100644 --- a/document-warehouse/test/set-acl.test.js +++ b/document-warehouse/test/set-acl.test.js @@ -31,7 +31,10 @@ const DOCUMENT_ID = 'YOUR_DOCUMENT_ID'; describe('Set document acl', () => { it('should set acl given no userId', async () => { - const stdout = execSync(`node ./set-acl.js ${PROJECT_ID_PASS} ${LOCATION} ${POLICY_ROLE} ${POLICY_MEMBER} ${USER_ID}`, {cwd}); + const stdout = execSync( + `node ./set-acl.js ${PROJECT_ID_PASS} ${LOCATION} ${POLICY_ROLE} ${POLICY_MEMBER} ${USER_ID}`, + {cwd} + ); assert(stdout.startsWith('Success!')); }); From 039cf264c6ab247281db3069d989dd4bf8d6ad93 Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Sat, 24 Jun 2023 05:06:16 -0700 Subject: [PATCH 11/29] add main function --- document-warehouse/search-document.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 document-warehouse/search-document.js diff --git a/document-warehouse/search-document.js b/document-warehouse/search-document.js new file mode 100644 index 0000000000..edafa97d41 --- /dev/null +++ b/document-warehouse/search-document.js @@ -0,0 +1,25 @@ +/** Copyright 2023 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. + */ + +'use strict'; + +async function main() { + +} + +main(...process.argv.slice(2)).catch(err => { + console.error(err); + process.exitCode = 1; +}); \ No newline at end of file From 08abf0872c63a433e349d71860b9ee60970f218d Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Sat, 24 Jun 2023 05:22:32 -0700 Subject: [PATCH 12/29] add search function --- document-warehouse/search-document.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/document-warehouse/search-document.js b/document-warehouse/search-document.js index edafa97d41..3eb4e13363 100644 --- a/document-warehouse/search-document.js +++ b/document-warehouse/search-document.js @@ -15,8 +15,31 @@ 'use strict'; -async function main() { +async function main( + projectId = 'YOUR_PROJECT_ID', + location = 'YOUR_PROJECT_LOCATION', + query = 'YOUR_DOCUMENT_QUERY', +) { + // [START contentwarehouse_search_documents] + /** + * TODO(developer): Uncomment these variables before running the sample. + * projectId = 'YOUR_PROJECT_ID' + * location = 'YOUR_PROJECT_LOCATION' // Format is 'us' or 'eu' + * query = 'YOUR_DOCUMENT_QUERY' + */ + // Import service client from google cloud + const {DocumentServiceClient} = require('@google-cloud/contentwarehouse').v1; + + // Create client + const serviceClient = new DocumentServiceClient(); + + // Search document + async function searchDocument() { + + } + + // [END contentwarehouse_search_documents] } main(...process.argv.slice(2)).catch(err => { From be57cca03cdf6d2ad2b3c943816b5286a88d2e66 Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Sat, 24 Jun 2023 05:23:44 -0700 Subject: [PATCH 13/29] add search function --- document-warehouse/search-document.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/document-warehouse/search-document.js b/document-warehouse/search-document.js index 3eb4e13363..1e220046a7 100644 --- a/document-warehouse/search-document.js +++ b/document-warehouse/search-document.js @@ -36,10 +36,11 @@ async function main( // Search document async function searchDocument() { - + // TODO: Fill in } // [END contentwarehouse_search_documents] + await searchDocument(); } main(...process.argv.slice(2)).catch(err => { From bc721f62113fd88dc73b9cff96e3b4e2a419874a Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Sat, 24 Jun 2023 10:00:06 -0700 Subject: [PATCH 14/29] start creating request --- document-warehouse/search-document.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/document-warehouse/search-document.js b/document-warehouse/search-document.js index 1e220046a7..c79df0168a 100644 --- a/document-warehouse/search-document.js +++ b/document-warehouse/search-document.js @@ -36,7 +36,9 @@ async function main( // Search document async function searchDocument() { - // TODO: Fill in + // Initialize request arguments + const request = {}; + } // [END contentwarehouse_search_documents] From 041d783b5cf5ea7566841751b24ecd6e44e23342 Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Sat, 24 Jun 2023 10:02:18 -0700 Subject: [PATCH 15/29] fix package.json --- document-warehouse/package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/document-warehouse/package.json b/document-warehouse/package.json index ecccbf59c3..79fd5217c8 100644 --- a/document-warehouse/package.json +++ b/document-warehouse/package.json @@ -7,8 +7,9 @@ "test": "c8 mocha test/*.js --timeout 600000" }, "dependencies": { - "@google-cloud/contentwarehouse": "^0.5.1", - "assert": "^2.0.0", - "json": "^11.0.0" + "@google-cloud/contentwarehouse": "^0.5.1" + }, + "devDependencies": { + "assert": "^2.0.0" } } From d0e8729c603f8b6c1188138f5d2fac7ae12a2a7c Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Mon, 26 Jun 2023 17:19:13 -0700 Subject: [PATCH 16/29] working on printing result --- document-warehouse/search-document.js | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/document-warehouse/search-document.js b/document-warehouse/search-document.js index c79df0168a..453c588d5f 100644 --- a/document-warehouse/search-document.js +++ b/document-warehouse/search-document.js @@ -38,7 +38,44 @@ async function main( async function searchDocument() { // Initialize request arguments const request = {}; + // Full document resource name, e.g.: projects/{project_id}/locations/{location} + request.parent = `projects/${projectId}/locations/${location}`; + // File Type Filter + // Options: DOCUMENT, FOLDER + const fileTypeFilter = { + fileType: DOCUMENT + }; + // Search Prompt + const documentQuery = { + query: query, + fileTypeFilter : fileTypeFilter + }; + request.documentQuery = documentQuery; + request.histogramQueries = [{histogramQuery:'count("DocumentSchemaId")'}]; + + // Make Request + const response = serviceClient.searchDocuments(request); + + // Print Search Results + for (matchingDocument in response.matchingDocuments) { + const document = matchingDocument.document; + console.log(` + ${document.displayName} - ${document.documentSchemaName}\n + ${document.name}\n + ${document.createTime}\n + ${matchingDocument.searchTextSnippet}\n + `); + } + // Print Histogram + for (result in response.histogramQueryResults){ + console.log(` + History Query: ${result.historyQuery}\n + + //TODO + `) + } + } // [END contentwarehouse_search_documents] From 2459014c50cbf9dd73ba8aa78b764f736cebd904 Mon Sep 17 00:00:00 2001 From: Paulina <31912446+paulinawins@users.noreply.github.com> Date: Tue, 27 Jun 2023 10:02:02 -0700 Subject: [PATCH 17/29] Delete search-document.js Placed in wrong branch --- document-warehouse/search-document.js | 88 --------------------------- 1 file changed, 88 deletions(-) delete mode 100644 document-warehouse/search-document.js diff --git a/document-warehouse/search-document.js b/document-warehouse/search-document.js deleted file mode 100644 index 453c588d5f..0000000000 --- a/document-warehouse/search-document.js +++ /dev/null @@ -1,88 +0,0 @@ -/** Copyright 2023 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. - */ - -'use strict'; - -async function main( - projectId = 'YOUR_PROJECT_ID', - location = 'YOUR_PROJECT_LOCATION', - query = 'YOUR_DOCUMENT_QUERY', -) { - // [START contentwarehouse_search_documents] - /** - * TODO(developer): Uncomment these variables before running the sample. - * projectId = 'YOUR_PROJECT_ID' - * location = 'YOUR_PROJECT_LOCATION' // Format is 'us' or 'eu' - * query = 'YOUR_DOCUMENT_QUERY' - */ - - // Import service client from google cloud - const {DocumentServiceClient} = require('@google-cloud/contentwarehouse').v1; - - // Create client - const serviceClient = new DocumentServiceClient(); - - // Search document - async function searchDocument() { - // Initialize request arguments - const request = {}; - // Full document resource name, e.g.: projects/{project_id}/locations/{location} - request.parent = `projects/${projectId}/locations/${location}`; - // File Type Filter - // Options: DOCUMENT, FOLDER - const fileTypeFilter = { - fileType: DOCUMENT - }; - // Search Prompt - const documentQuery = { - query: query, - fileTypeFilter : fileTypeFilter - }; - request.documentQuery = documentQuery; - request.histogramQueries = [{histogramQuery:'count("DocumentSchemaId")'}]; - - // Make Request - const response = serviceClient.searchDocuments(request); - - // Print Search Results - for (matchingDocument in response.matchingDocuments) { - const document = matchingDocument.document; - console.log(` - ${document.displayName} - ${document.documentSchemaName}\n - ${document.name}\n - ${document.createTime}\n - ${matchingDocument.searchTextSnippet}\n - `); - } - - // Print Histogram - for (result in response.histogramQueryResults){ - console.log(` - History Query: ${result.historyQuery}\n - - //TODO - `) - } - - } - - // [END contentwarehouse_search_documents] - await searchDocument(); -} - -main(...process.argv.slice(2)).catch(err => { - console.error(err); - process.exitCode = 1; -}); \ No newline at end of file From fa3f49f8b9c5bbc94db4e299df3c8225ad2605c9 Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Tue, 27 Jun 2023 10:04:21 -0700 Subject: [PATCH 18/29] remove search document sample. accidental add to this branch --- .kokoro/appengine/test-deployment/common.cfg | 4 +- document-warehouse/search-document.js | 88 -------------------- 2 files changed, 2 insertions(+), 90 deletions(-) delete mode 100644 document-warehouse/search-document.js diff --git a/.kokoro/appengine/test-deployment/common.cfg b/.kokoro/appengine/test-deployment/common.cfg index b2b0b5f32b..7dd2269ce3 100644 --- a/.kokoro/appengine/test-deployment/common.cfg +++ b/.kokoro/appengine/test-deployment/common.cfg @@ -12,11 +12,11 @@ build_file: "nodejs-docs-samples/.kokoro/trampoline.sh" # Configure the docker image for kokoro-trampoline. env_vars: { key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-docs-samples/nodejs" + value: "gcr.io/cloud-devrel-kokoro-resources/node" } # Tell the trampoline which build file to use. env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/nodejs-docs-samples/.kokoro/build-with-appengine.sh" -} \ No newline at end of file +} diff --git a/document-warehouse/search-document.js b/document-warehouse/search-document.js deleted file mode 100644 index 453c588d5f..0000000000 --- a/document-warehouse/search-document.js +++ /dev/null @@ -1,88 +0,0 @@ -/** Copyright 2023 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. - */ - -'use strict'; - -async function main( - projectId = 'YOUR_PROJECT_ID', - location = 'YOUR_PROJECT_LOCATION', - query = 'YOUR_DOCUMENT_QUERY', -) { - // [START contentwarehouse_search_documents] - /** - * TODO(developer): Uncomment these variables before running the sample. - * projectId = 'YOUR_PROJECT_ID' - * location = 'YOUR_PROJECT_LOCATION' // Format is 'us' or 'eu' - * query = 'YOUR_DOCUMENT_QUERY' - */ - - // Import service client from google cloud - const {DocumentServiceClient} = require('@google-cloud/contentwarehouse').v1; - - // Create client - const serviceClient = new DocumentServiceClient(); - - // Search document - async function searchDocument() { - // Initialize request arguments - const request = {}; - // Full document resource name, e.g.: projects/{project_id}/locations/{location} - request.parent = `projects/${projectId}/locations/${location}`; - // File Type Filter - // Options: DOCUMENT, FOLDER - const fileTypeFilter = { - fileType: DOCUMENT - }; - // Search Prompt - const documentQuery = { - query: query, - fileTypeFilter : fileTypeFilter - }; - request.documentQuery = documentQuery; - request.histogramQueries = [{histogramQuery:'count("DocumentSchemaId")'}]; - - // Make Request - const response = serviceClient.searchDocuments(request); - - // Print Search Results - for (matchingDocument in response.matchingDocuments) { - const document = matchingDocument.document; - console.log(` - ${document.displayName} - ${document.documentSchemaName}\n - ${document.name}\n - ${document.createTime}\n - ${matchingDocument.searchTextSnippet}\n - `); - } - - // Print Histogram - for (result in response.histogramQueryResults){ - console.log(` - History Query: ${result.historyQuery}\n - - //TODO - `) - } - - } - - // [END contentwarehouse_search_documents] - await searchDocument(); -} - -main(...process.argv.slice(2)).catch(err => { - console.error(err); - process.exitCode = 1; -}); \ No newline at end of file From 1ba8ba6f6a2f8e0ed750c69e59096b7fe7156c3b Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Wed, 26 Jul 2023 11:32:27 -0700 Subject: [PATCH 19/29] add sample file --- document-warehouse/create-document-schema.js | 76 ++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 document-warehouse/create-document-schema.js diff --git a/document-warehouse/create-document-schema.js b/document-warehouse/create-document-schema.js new file mode 100644 index 0000000000..775a26d759 --- /dev/null +++ b/document-warehouse/create-document-schema.js @@ -0,0 +1,76 @@ +/** Copyright 2023 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. + */ + +'use strict'; + +async function main( + projectId = 'YOUR_PROJECT_ID', + location = 'YOUR_PROJECT_LOCATION' +) { + // [START contentwarehouse_create_document_schema] + + /** + * TODO(developer): Uncomment these variables before running the sample. + * const projectId = 'YOUR_PROJECT_ID'; + * const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' + */ + + // Import from google cloud + const {DocumentSchemaServiceClient} = require('@google-cloud/contentwarehouse').v1; + + // Create service client + const serviceClient = new DocumentSchemaServiceClient(); + + // Create Document Schema + async function createDocumentSchema() { + // Initialize request argument(s) + const request = {}; + + // Property Definition + const propertyDefinition = {}; + // Must be unique within a document schema (case insensitive) + propertyDefinition.name = "stock symbol"; + propertyDefinition.displayName = "Searchable text"; + propertyDefinition.isSearchable= true; + //propertyDefinition.textTypeOptions = {}; + + // Document Schema + const documentSchema = {}; + documentSchema.displayName = "My Test Schema"; + documentSchema.propertyDefinitions = [propertyDefinition]; + + // The full resource name of the location, e.g.: + // projects/{project_number}/locations/{location}/ + request.parent = `projects/${projectId}/locations/${location}`; + request.documentSchema = documentSchema; + + // Make Request + const response = serviceClient.createDocumentSchema(request); + + // Print out response + response.then( + result => console.log(`Success!\nDocument Schema Created: \n${result}`), + error => console.log(`Failed!\n${error}`) + ); + } + + // [END contentwarehouse_create_document_schema] + await createDocumentSchema(); +} + +main(...process.argv.slice(2)).catch(err => { + console.error(err); + process.exitCode = 1; +}); \ No newline at end of file From c44505ed95b871f2b39a250b0717f82229b8d98b Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Wed, 26 Jul 2023 12:13:56 -0700 Subject: [PATCH 20/29] working on property definition --- document-warehouse/create-document-schema.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/document-warehouse/create-document-schema.js b/document-warehouse/create-document-schema.js index 775a26d759..d6e56d5c0d 100644 --- a/document-warehouse/create-document-schema.js +++ b/document-warehouse/create-document-schema.js @@ -40,28 +40,29 @@ async function main( // Property Definition const propertyDefinition = {}; - // Must be unique within a document schema (case insensitive) - propertyDefinition.name = "stock symbol"; - propertyDefinition.displayName = "Searchable text"; - propertyDefinition.isSearchable= true; - //propertyDefinition.textTypeOptions = {}; + propertyDefinition.name = "schema property 1"; // Must be unique within a document schema (case insensitive) + propertyDefinition.displayName = "searchable text"; + propertyDefinition.isSearchable = true; + propertyDefinition.textTypeOptions = {}; // Document Schema const documentSchema = {}; documentSchema.displayName = "My Test Schema"; documentSchema.propertyDefinitions = [propertyDefinition]; + request.documentSchema = documentSchema; + // The full resource name of the location, e.g.: // projects/{project_number}/locations/{location}/ - request.parent = `projects/${projectId}/locations/${location}`; - request.documentSchema = documentSchema; + request.parent = `projects/${projectId}/locations/${location}/documentSchemas`; + request.requestMetadata = {userInfo: {id: userId}}; // Make Request const response = serviceClient.createDocumentSchema(request); // Print out response response.then( - result => console.log(`Success!\nDocument Schema Created: \n${result}`), + result => console.log(`Success!\nDocument Schema Created: \n${JSON.stringify(result)}`), error => console.log(`Failed!\n${error}`) ); } From 9f3cd437b3bf4ff4ffe8c87503d773193163c8ca Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Tue, 1 Aug 2023 10:45:24 -0700 Subject: [PATCH 21/29] debugging --- document-warehouse/create-document-schema.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/document-warehouse/create-document-schema.js b/document-warehouse/create-document-schema.js index d6e56d5c0d..22b94f47f6 100644 --- a/document-warehouse/create-document-schema.js +++ b/document-warehouse/create-document-schema.js @@ -48,14 +48,15 @@ async function main( // Document Schema const documentSchema = {}; documentSchema.displayName = "My Test Schema"; - documentSchema.propertyDefinitions = [propertyDefinition]; + documentSchema.propertyDefinitions = []; request.documentSchema = documentSchema; // The full resource name of the location, e.g.: // projects/{project_number}/locations/{location}/ - request.parent = `projects/${projectId}/locations/${location}/documentSchemas`; - request.requestMetadata = {userInfo: {id: userId}}; + request.parent = `projects/${projectId}/locations/${location}/`; + + //console.log(request); // Make Request const response = serviceClient.createDocumentSchema(request); From 4d0317ebd20ae5a50d44b6bc0e0f472d75b389e6 Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Tue, 1 Aug 2023 10:54:40 -0700 Subject: [PATCH 22/29] delete schema sample --- document-warehouse/delete-document-schema.js | 66 ++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 document-warehouse/delete-document-schema.js diff --git a/document-warehouse/delete-document-schema.js b/document-warehouse/delete-document-schema.js new file mode 100644 index 0000000000..d3f1fdb6f2 --- /dev/null +++ b/document-warehouse/delete-document-schema.js @@ -0,0 +1,66 @@ +/** Copyright 2023 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. + */ + +'use strict'; + +async function main( + projectId = 'YOUR_PROJECT_ID', + location = 'YOUR_PROJECT_LOCATION', + documentSchemaId = 'YOUR_DOCUMENT_SCHEMA_ID' +) { + // [START contentwarehouse_delete_document_schema] + + /** + * TODO(developer): Uncomment these variables before running the sample. + * const projectId = 'YOUR_PROJECT_ID'; + * const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' + * const documentSchemaId = 'YOUR_DOCUMENT_SCHEMA_ID'; + */ + + // Import from google cloud + const {DocumentSchemaServiceClient} = require('@google-cloud/contentwarehouse').v1; + + // Create service client + const serviceClient = new DocumentSchemaServiceClient(); + + // Delete Document Schema + async function deleteDocumentSchema() { + // Initialize request argument(s) + const request = {}; + + // The full resource name of the location, e.g.: + // projects/{project_number}/locations/{location}/documentSchemas/{document_schema_id} + request.name = `projects/${projectId}/locations/${location}/documentSchemas/${documentSchemaId}`; + + console.log(request); + + // Make Request + const response = serviceClient.deleteDocumentSchema(request); + + // Print out response + response.then( + result => console.log(`Success!\nDocument Schema Deleted: \n${JSON.stringify(result)}`), + error => console.log(`Failed!\n${error}`) + ); + } + + // [END contentwarehouse_delete_document_schema] + await deleteDocumentSchema(); +} + +main(...process.argv.slice(2)).catch(err => { + console.error(err); + process.exitCode = 1; +}); \ No newline at end of file From ef3ebd822d2233dd805d76e9e010d52d966e1758 Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Tue, 1 Aug 2023 11:16:03 -0700 Subject: [PATCH 23/29] remove create schema from this branch --- document-warehouse/create-document-schema.js | 78 -------------------- 1 file changed, 78 deletions(-) delete mode 100644 document-warehouse/create-document-schema.js diff --git a/document-warehouse/create-document-schema.js b/document-warehouse/create-document-schema.js deleted file mode 100644 index 22b94f47f6..0000000000 --- a/document-warehouse/create-document-schema.js +++ /dev/null @@ -1,78 +0,0 @@ -/** Copyright 2023 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. - */ - -'use strict'; - -async function main( - projectId = 'YOUR_PROJECT_ID', - location = 'YOUR_PROJECT_LOCATION' -) { - // [START contentwarehouse_create_document_schema] - - /** - * TODO(developer): Uncomment these variables before running the sample. - * const projectId = 'YOUR_PROJECT_ID'; - * const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' - */ - - // Import from google cloud - const {DocumentSchemaServiceClient} = require('@google-cloud/contentwarehouse').v1; - - // Create service client - const serviceClient = new DocumentSchemaServiceClient(); - - // Create Document Schema - async function createDocumentSchema() { - // Initialize request argument(s) - const request = {}; - - // Property Definition - const propertyDefinition = {}; - propertyDefinition.name = "schema property 1"; // Must be unique within a document schema (case insensitive) - propertyDefinition.displayName = "searchable text"; - propertyDefinition.isSearchable = true; - propertyDefinition.textTypeOptions = {}; - - // Document Schema - const documentSchema = {}; - documentSchema.displayName = "My Test Schema"; - documentSchema.propertyDefinitions = []; - - request.documentSchema = documentSchema; - - // The full resource name of the location, e.g.: - // projects/{project_number}/locations/{location}/ - request.parent = `projects/${projectId}/locations/${location}/`; - - //console.log(request); - - // Make Request - const response = serviceClient.createDocumentSchema(request); - - // Print out response - response.then( - result => console.log(`Success!\nDocument Schema Created: \n${JSON.stringify(result)}`), - error => console.log(`Failed!\n${error}`) - ); - } - - // [END contentwarehouse_create_document_schema] - await createDocumentSchema(); -} - -main(...process.argv.slice(2)).catch(err => { - console.error(err); - process.exitCode = 1; -}); \ No newline at end of file From 28e3f18c6614a3b952aba6be9a35289523e033ee Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Tue, 8 Aug 2023 19:42:09 -0700 Subject: [PATCH 24/29] add test and fix code based on comments --- document-warehouse/delete-document-schema.js | 27 ++++-------- .../test/delete-document-schema.test.js | 43 +++++++++++++++++++ 2 files changed, 51 insertions(+), 19 deletions(-) create mode 100644 document-warehouse/test/delete-document-schema.test.js diff --git a/document-warehouse/delete-document-schema.js b/document-warehouse/delete-document-schema.js index b5a544eb9b..1cbaaf7bf7 100644 --- a/document-warehouse/delete-document-schema.js +++ b/document-warehouse/delete-document-schema.js @@ -39,32 +39,21 @@ async function main( // Delete Document Schema async function deleteDocumentSchema() { // Initialize request argument(s) - const request = {}; - - // The full resource name of the location, e.g.: - // projects/{project_number}/locations/{location}/documentSchemas/{document_schema_id} - request.name = `projects/${projectId}/locations/${location}/documentSchemas/${documentSchemaId}`; - - console.log(request); + const request = { + // The full resource name of the location, e.g.: + // projects/{project_number}/locations/{location}/documentSchemas/{document_schema_id} + name: `projects/${projectId}/locations/${location}/documentSchemas/${documentSchemaId}`, + }; // Make Request - const response = serviceClient.deleteDocumentSchema(request); + const response = await serviceClient.deleteDocumentSchema(request); // Print out response - response.then( - result => - console.log( - `Success!\nDocument Schema Deleted: \n${JSON.stringify(result)}` - ), - error => console.log(`Failed!\n${error}`) - ); + console.log(`Document Schema Deleted: ${response}`); } // [END contentwarehouse_delete_document_schema] await deleteDocumentSchema(); } -main(...process.argv.slice(2)).catch(err => { - console.error(err); - process.exitCode = 1; -}); +exports.deleteDocumentSchema = main; diff --git a/document-warehouse/test/delete-document-schema.test.js b/document-warehouse/test/delete-document-schema.test.js new file mode 100644 index 0000000000..a2e49e847c --- /dev/null +++ b/document-warehouse/test/delete-document-schema.test.js @@ -0,0 +1,43 @@ +// Copyright 2023 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 +// +// https://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. + +'use strict'; + +const {describe, it} = require('mocha'); +const {assert} = require('chai'); +const sinon = require('sinon'); + +const text = 'Document Schema Deleted'; + +const {deleteDocumentSchema} = require('../delete-document-schema'); + // TODO(developer): Uncomment these variables before running the sample. + /** + * const projectId = 'YOUR_PROJECT_ID'; + * const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' + * const documentSchemaId = 'YOUR_DOCUMENT_SCHEMA_ID'; + */ + +describe('Delete document schema', () => { + const stubConsole = function () { + sinon.stub(console, 'error'); + sinon.stub(console, 'log'); + }; + + beforeEach(stubConsole); + + it('should delete a document schema', async () => { + await deleteDocumentSchema(projectId, location, documentSchemaId); + assert.include(console.log.firstCall.args[0], text); + }); +}); \ No newline at end of file From 36d08a9de0f702ca97eec89d25deb2f2afa568bf Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Wed, 9 Aug 2023 09:23:15 -0700 Subject: [PATCH 25/29] fix styles for test file --- .../test/delete-document-schema.test.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/document-warehouse/test/delete-document-schema.test.js b/document-warehouse/test/delete-document-schema.test.js index a2e49e847c..6be525082c 100644 --- a/document-warehouse/test/delete-document-schema.test.js +++ b/document-warehouse/test/delete-document-schema.test.js @@ -21,12 +21,11 @@ const sinon = require('sinon'); const text = 'Document Schema Deleted'; const {deleteDocumentSchema} = require('../delete-document-schema'); - // TODO(developer): Uncomment these variables before running the sample. - /** - * const projectId = 'YOUR_PROJECT_ID'; - * const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' - * const documentSchemaId = 'YOUR_DOCUMENT_SCHEMA_ID'; - */ + +// TODO(developer): Fill in the variables below before running this test. +const projectId = 'YOUR_PROJECT_ID'; +const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' +const documentSchemaId = 'YOUR_DOCUMENT_SCHEMA_ID'; describe('Delete document schema', () => { const stubConsole = function () { @@ -40,4 +39,4 @@ describe('Delete document schema', () => { await deleteDocumentSchema(projectId, location, documentSchemaId); assert.include(console.log.firstCall.args[0], text); }); -}); \ No newline at end of file +}); From fbd26c9561180e1070bfa9c9c4d2d1ebdd4959e9 Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Wed, 9 Aug 2023 09:46:59 -0700 Subject: [PATCH 26/29] remove trailing spaces: --- document-warehouse/test/delete-document-schema.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/document-warehouse/test/delete-document-schema.test.js b/document-warehouse/test/delete-document-schema.test.js index 6be525082c..41d8989015 100644 --- a/document-warehouse/test/delete-document-schema.test.js +++ b/document-warehouse/test/delete-document-schema.test.js @@ -21,7 +21,7 @@ const sinon = require('sinon'); const text = 'Document Schema Deleted'; const {deleteDocumentSchema} = require('../delete-document-schema'); - + // TODO(developer): Fill in the variables below before running this test. const projectId = 'YOUR_PROJECT_ID'; const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' From 5b84f6e0543bd67c35bd1f11b74a817685abd4cd Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Wed, 9 Aug 2023 09:51:48 -0700 Subject: [PATCH 27/29] github action workflow created --- .../workflows/document-warehouse-test.yaml | 62 +++++++++++++++++++ .github/workflows/utils/workflows.json | 1 + 2 files changed, 63 insertions(+) create mode 100644 .github/workflows/document-warehouse-test.yaml diff --git a/.github/workflows/document-warehouse-test.yaml b/.github/workflows/document-warehouse-test.yaml new file mode 100644 index 0000000000..70414c8c5e --- /dev/null +++ b/.github/workflows/document-warehouse-test.yaml @@ -0,0 +1,62 @@ +# Copyright 2023 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. + +name: document-warehouse-test +on: + push: + branches: + - main + paths: + - 'document-warehouse/test/**' + - '.github/workflows/document-warehouse-test.yaml' + pull_request: + paths: + - 'document-warehouse/test/**' + - '.github/workflows/document-warehouse-test.yaml' + pull_request_target: + types: [labeled] + paths: + - 'document-warehouse/test/**' + - '.github/workflows/document-warehouse-test.yaml' + schedule: + - cron: '0 0 * * 0' +jobs: + test: + # Ref: https://github.com/google-github-actions/auth#usage + permissions: + contents: 'read' + id-token: 'write' + if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' + uses: ./.github/workflows/test.yaml + with: + name: 'document-warehouse-test' + path: 'document-warehouse/test' + remove_label: + # Ref: https://github.com/google-github-actions/auth#usage + permissions: + contents: 'read' + id-token: 'write' + if: | + github.event.action == 'labeled' && + github.event.label.name == 'actions:force-run' && + always() + uses: ./.github/workflows/remove-label.yaml + flakybot: + # Ref: https://github.com/google-github-actions/auth#usage + permissions: + contents: 'read' + id-token: 'write' + if: github.event_name == 'schedule' && always() # always() submits logs even if tests fail + uses: ./.github/workflows/flakybot.yaml + needs: [test] diff --git a/.github/workflows/utils/workflows.json b/.github/workflows/utils/workflows.json index c1ffd9e387..e61081c2d0 100644 --- a/.github/workflows/utils/workflows.json +++ b/.github/workflows/utils/workflows.json @@ -40,6 +40,7 @@ "dlp", "document-ai", "document-warehouse", + "document-warehouse/test", "endpoints/getting-started", "endpoints/getting-started-grpc", "error-reporting", From b0297f65981e1a9580802b3397a18a58c0bbb871 Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Wed, 9 Aug 2023 10:13:55 -0700 Subject: [PATCH 28/29] remove test directory --- .../workflows/document-warehouse-test.yaml | 62 ------------------- document-warehouse/package.json | 10 ++- 2 files changed, 7 insertions(+), 65 deletions(-) delete mode 100644 .github/workflows/document-warehouse-test.yaml diff --git a/.github/workflows/document-warehouse-test.yaml b/.github/workflows/document-warehouse-test.yaml deleted file mode 100644 index 70414c8c5e..0000000000 --- a/.github/workflows/document-warehouse-test.yaml +++ /dev/null @@ -1,62 +0,0 @@ -# Copyright 2023 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. - -name: document-warehouse-test -on: - push: - branches: - - main - paths: - - 'document-warehouse/test/**' - - '.github/workflows/document-warehouse-test.yaml' - pull_request: - paths: - - 'document-warehouse/test/**' - - '.github/workflows/document-warehouse-test.yaml' - pull_request_target: - types: [labeled] - paths: - - 'document-warehouse/test/**' - - '.github/workflows/document-warehouse-test.yaml' - schedule: - - cron: '0 0 * * 0' -jobs: - test: - # Ref: https://github.com/google-github-actions/auth#usage - permissions: - contents: 'read' - id-token: 'write' - if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' - uses: ./.github/workflows/test.yaml - with: - name: 'document-warehouse-test' - path: 'document-warehouse/test' - remove_label: - # Ref: https://github.com/google-github-actions/auth#usage - permissions: - contents: 'read' - id-token: 'write' - if: | - github.event.action == 'labeled' && - github.event.label.name == 'actions:force-run' && - always() - uses: ./.github/workflows/remove-label.yaml - flakybot: - # Ref: https://github.com/google-github-actions/auth#usage - permissions: - contents: 'read' - id-token: 'write' - if: github.event_name == 'schedule' && always() # always() submits logs even if tests fail - uses: ./.github/workflows/flakybot.yaml - needs: [test] diff --git a/document-warehouse/package.json b/document-warehouse/package.json index 79fd5217c8..dd04235ca8 100644 --- a/document-warehouse/package.json +++ b/document-warehouse/package.json @@ -4,12 +4,16 @@ "license": "Apache-2.0", "author": "Google LLC", "scripts": { - "test": "c8 mocha test/*.js --timeout 600000" + "test": "c8 mocha test/*.test.js --timeout 600000" }, "dependencies": { - "@google-cloud/contentwarehouse": "^0.5.1" + "@google-cloud/contentwarehouse": "^0.5.1", + "c8": "^8.0.1", + "chai": "^4.3.7", + "mocha": "^10.2.0", + "sinon": "^15.2.0" }, "devDependencies": { - "assert": "^2.0.0" + "assert": "^2.0.0" } } From 17693d41f8ee956b2fab77be4e7f0d930920a919 Mon Sep 17 00:00:00 2001 From: Paulina Nguyen Date: Wed, 9 Aug 2023 10:16:06 -0700 Subject: [PATCH 29/29] add workflow changes --- .github/workflows/utils/workflows.json | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/utils/workflows.json b/.github/workflows/utils/workflows.json index e61081c2d0..c1ffd9e387 100644 --- a/.github/workflows/utils/workflows.json +++ b/.github/workflows/utils/workflows.json @@ -40,7 +40,6 @@ "dlp", "document-ai", "document-warehouse", - "document-warehouse/test", "endpoints/getting-started", "endpoints/getting-started-grpc", "error-reporting",