application/docValidate.js
/**
 * Process a request in the ledger to get a document, based in a document-key.
 * @param {ChaincodeClientTx} chaincodeTxRetrieve Transaction client to connect on ledger.
 * @param {string} documentKey The document key.
 * @param {BeanUser} validator User as validator role.
 */
Process a request in the ledger to get a document, based in a document-key.
@param {ChaincodeClientTx} chaincodeTxRetrieve Transaction client to connect on ledger.
@param {string} documentKey The document key.
@param {BeanUser} validator User as validator role.
Process a request in the ledger to get a document based in a document - key . @param { ChaincodeClientTx } chaincodeTxRetrieve Transaction client to connect on ledger . @param { string } documentKey The document key . @param { BeanUser } validator User as validator role .
async function retrieveDocument(chaincodeTxRetrieve, documentKey, validator){
    let persona = BeanUser.createBeanUser(validator);
    persona.clearSecurityData();
    var dataToSubmit = BeanDataBlock.newBeanDataBlock();
    dataToSubmit.setReader(persona);
    dataToSubmit.setKey(documentKey);
    logWrite('[retrieveDocument] Data to submit in transaction = ' + JSON.stringify(dataToSubmit));
    if (logActive) { fs.writeFileSync(JsonSubmitToRetrieve, dataToSubmit.serialize(), utf8); }
    var txResponse = await chaincodeTxRetrieve.processBlockchainTransaction(dataToSubmit);
    if (txResponse == null || txResponse == undefined) {
        let msgError = `The response from ledger is NULL or UNDEFINED`;
        logWrite(`[retrieveDocument, A] Message: ${msgError}`);
        throw msgError;
    }
    var response = ResponseModel.translateLedgerResponse(txResponse);
    logWrite(`[retrieveDocument] ResponseModel object =  ${response.serialize()}`);
    if (response.txStatus == ResponseModel.getTxStatusType().FAIL){
        logWrite(`[retrieveDocument, B] Error message = ${response.txMessage}`);
        logWrite(`[retrieveDocument] Error stack = ${response.txContent}`);
        throw response.txMessage;
    }
    logWrite(`[retrieveDocument] Transaction Message = ${response.txMessage}`);
    if (response.txStatus == ResponseModel.getTxStatusType().EMPTY) {
        logWrite(`[retrieveDocument, C] Message = ${response.txMessage}`);
        logWrite(`[retrieveDocument] Content = ${response.txContent}`);
        throw response.txMessage;
    }
    var blockDataJSon = JSON.parse(response.txContent);
    logWrite('[retrieveDocument] Bloco de dados = ' + JSON.stringify(blockDataJSon));
    var blockDataAfterRetrieve = BeanDataBlock.createBeanDataBlock(blockDataJSon);
    var status = blockDataAfterRetrieve.status;
    logWrite(`[retrieveDocument] Document status = ${status}`);
    return blockDataAfterRetrieve;
}
async function retrieveDocument ( chaincodeTxRetrieve , documentKey , validator ) { let persona = BeanUser . createBeanUser ( validator ) ; persona . clearSecurityData ( ) ; var dataToSubmit = BeanDataBlock . newBeanDataBlock ( ) ; dataToSubmit . setReader ( persona ) ; dataToSubmit . setKey ( documentKey ) ; logWrite ( '[retrieveDocument] Data to submit in transaction = ' + JSON . stringify ( dataToSubmit ) ) ; if ( logActive ) { fs . writeFileSync ( JsonSubmitToRetrieve , dataToSubmit . serialize ( ) , utf8 ) ; } var txResponse = await chaincodeTxRetrieve . processBlockchainTransaction ( dataToSubmit ) ; if ( txResponse == null || txResponse == undefined ) { let msgError = ` ` ; logWrite ( ` ${ msgError } ` ) ; throw msgError ; } var response = ResponseModel . translateLedgerResponse ( txResponse ) ; logWrite ( ` ${ response . serialize ( ) } ` ) ; if ( response . txStatus == ResponseModel . getTxStatusType ( ) . FAIL ) { logWrite ( ` ${ response . txMessage } ` ) ; logWrite ( ` ${ response . txContent } ` ) ; throw response . txMessage ; } logWrite ( ` ${ response . txMessage } ` ) ; if ( response . txStatus == ResponseModel . getTxStatusType ( ) . EMPTY ) { logWrite ( ` ${ response . txMessage } ` ) ; logWrite ( ` ${ response . txContent } ` ) ; throw response . txMessage ; } var blockDataJSon = JSON . parse ( response . txContent ) ; logWrite ( '[retrieveDocument] Bloco de dados = ' + JSON . stringify ( blockDataJSon ) ) ; var blockDataAfterRetrieve = BeanDataBlock . createBeanDataBlock ( blockDataJSon ) ; var status = blockDataAfterRetrieve . status ; logWrite ( ` ${ status } ` ) ; return blockDataAfterRetrieve ; }
Process a request in the ledger to get a document, based in a document-key.
Process a request in the ledger to get a document based in a document - key .
// Prevents the private dataset from being inside the user's data // Creates the empty data block //---------------------------------------------------------------------------------- // Retrieve the document from the ledger // Process transaction into ledger // Treatment about data received as response from Ledger // Validate the success of transaction // Validate the situation of transaction // Process the content of the transaction