From 0176b30f8320950c76d7804b61ecc1e8d9d01c44 Mon Sep 17 00:00:00 2001 From: brkagithub Date: Fri, 20 Dec 2024 18:51:12 +0100 Subject: [PATCH] Fixes --- .../v1-0-0-handle-get-request-command.js | 41 ++++++++++++++----- .../sender/get-schedule-messages-command.js | 4 +- .../protocols/get/sender/local-get-command.js | 24 +++++++---- .../v1.0.0/v1-0-0-get-request-command.js | 11 +++++ .../implementation/ot-triple-store.js | 2 + 5 files changed, 63 insertions(+), 19 deletions(-) diff --git a/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-request-command.js b/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-request-command.js index 139c2adce..a5058454a 100644 --- a/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-request-command.js +++ b/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-request-command.js @@ -118,25 +118,46 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand { ual, ); - if (!assertionId) { - return { - messageType: NETWORK_MESSAGE_TYPES.RESPONSES.NACK, - messageData: { errorMessage: `Unable to find assertion ${ual}` }, - }; - } - this.logger.info( `Found assertion id: ${assertionId}, operation id ${operationId}, ual: ${ual}`, ); } + + // DO NOT RUN THIS IF !assertionId assertionPromise = this.tripleStoreService .getV6Assertion(TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, assertionId) - .then((result) => { + .then(async (result) => { + if (!result?.length) { + this.logger.info( + `No V6 assertion found for assertionId: ${assertionId}, falling back to V8 getAssertion`, + ); + + const fallbackResult = await this.tripleStoreService.getAssertion( + blockchain, + contract, + knowledgeCollectionId, + knowledgeAssetId, + TRIPLES_VISIBILITY.PUBLIC, + ); + + this.operationIdService.emitChangeEvent( + OPERATION_ID_STATUS.GET.GET_REMOTE_GET_ASSERTION_END, + operationId, + blockchain, + ); + + return [ + ...(fallbackResult.public ?? []), + ...(fallbackResult.private ?? []), + ]; + } + this.operationIdService.emitChangeEvent( OPERATION_ID_STATUS.GET.GET_REMOTE_GET_ASSERTION_END, operationId, blockchain, ); + return result.split('\n').filter((res) => res.length > 0); }); } else { @@ -185,7 +206,7 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand { ...(includeMetadata && metadata && { metadata }), }; - if (assertion?.public?.length) { + if (assertion?.public?.length || assertion?.length) { await this.operationIdService.updateOperationIdStatus( operationId, blockchain, @@ -193,7 +214,7 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand { ); } - return assertion?.public?.length + return assertion?.public?.length || assertion?.length ? { messageType: NETWORK_MESSAGE_TYPES.RESPONSES.ACK, messageData: responseData } : { messageType: NETWORK_MESSAGE_TYPES.RESPONSES.NACK, diff --git a/src/commands/protocols/get/sender/get-schedule-messages-command.js b/src/commands/protocols/get/sender/get-schedule-messages-command.js index 9ec9eb44b..7b34d8892 100644 --- a/src/commands/protocols/get/sender/get-schedule-messages-command.js +++ b/src/commands/protocols/get/sender/get-schedule-messages-command.js @@ -26,8 +26,8 @@ class GetScheduleMessagesCommand extends ProtocolScheduleMessagesCommand { paranetUAL: command.data.paranetUAL, paranetId: command.data.paranetId, paranetMetadata: command.data.paranetMetadata, - assertionId: command.data.isOperationV0, - isOperationV0: command.data.assertionId, + assertionId: command.data.assertionId, + isOperationV0: command.data.isOperationV0, }; } diff --git a/src/commands/protocols/get/sender/local-get-command.js b/src/commands/protocols/get/sender/local-get-command.js index 9bf440089..0054c3344 100644 --- a/src/commands/protocols/get/sender/local-get-command.js +++ b/src/commands/protocols/get/sender/local-get-command.js @@ -104,7 +104,8 @@ class LocalGetCommand extends Command { if (assertionId) { assertionPromise = (async () => { - let result = {}; + let result = null; + for (const repository of [ TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT, TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, @@ -116,15 +117,24 @@ class LocalGetCommand extends Command { } } - if (result?.length) { - this.operationIdService.emitChangeEvent( - OPERATION_ID_STATUS.GET.GET_LOCAL_GET_ASSERTION_END, - operationId, + if (!result?.length) { + result = await this.tripleStoreService.getAssertion( blockchain, + contract, + knowledgeCollectionId, + knowledgeAssetId, + contentType, ); } + this.operationIdService.emitChangeEvent( + OPERATION_ID_STATUS.GET.GET_LOCAL_GET_ASSERTION_END, + operationId, + blockchain, + ); - return result.split('\n').filter((res) => res.length > 0); + return typeof result === 'string' + ? result.split('\n').filter((res) => res.length > 0) + : result; })(); } else { assertionPromise = this.tripleStoreService @@ -172,7 +182,7 @@ class LocalGetCommand extends Command { assertion, ...(includeMetadata && metadata && { metadata }), }; - if (assertion?.public?.length || assertion?.private?.length) { + if (assertion?.public?.length || assertion?.private?.length || assertion?.length) { await this.operationService.markOperationAsCompleted( operationId, blockchain, diff --git a/src/commands/protocols/get/sender/v1.0.0/v1-0-0-get-request-command.js b/src/commands/protocols/get/sender/v1.0.0/v1-0-0-get-request-command.js index 84a727a52..35d4d7924 100644 --- a/src/commands/protocols/get/sender/v1.0.0/v1-0-0-get-request-command.js +++ b/src/commands/protocols/get/sender/v1.0.0/v1-0-0-get-request-command.js @@ -98,6 +98,17 @@ class GetRequestCommand extends ProtocolRequestCommand { return ProtocolRequestCommand.empty(); } + if (responseData?.assertion?.length) { + // V6 assertion + + await this.operationService.processResponse( + command, + OPERATION_REQUEST_STATUS.COMPLETED, + responseData, + ); + + return ProtocolRequestCommand.empty(); + } return this.handleNack(command, responseData); } diff --git a/src/modules/triple-store/implementation/ot-triple-store.js b/src/modules/triple-store/implementation/ot-triple-store.js index a69d337f9..b82d2ecc9 100644 --- a/src/modules/triple-store/implementation/ot-triple-store.js +++ b/src/modules/triple-store/implementation/ot-triple-store.js @@ -587,6 +587,8 @@ class OtTripleStore { } async getV6Assertion(repository, assertionId) { + if (!assertionId) return ''; + const escapedGraphName = this.cleanEscapeCharacter(assertionId); const query = `PREFIX schema: <${SCHEMA_CONTEXT}>