Search code examples
hyperledger-composer

Expected Resource or Concept in hyperledger-composer playground


I have an error said "Expected Resource or Concept" in playground hyperledger-composer Two participants 1. School 2. Company

Two assets 1. Transcript 2. Transcript_status

One transaction updateStatus: • Update student’s transcript status from unread to either not interested or interested

Participant school, student, company Assets Transcript, Transcript_status Transaction updateStatus

  1. School creates a participant school
  2. Company creates a participant company
  3. School creates an asset transcript
  4. Company creates an asset transcript_status

Workflow: After creating student’s asset (transcript), schools can upload the record to its website, and companies can view the first asset Transcript. After that, companies can submit transaction Transcript_status and marked as read. Then the asset Transcript_status will be updated from unread to read.

/*
 * 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.
 */

/**
 * Definition of a Bond, based on the FpML schema:
 * http://www.fpml.org/spec/fpml-5-3-2-wd-2/html/reporting/schemaDocumentation/schemas/fpml-asset-5-3_xsd/elements/bond.html
 *
 */
namespace org.school.education

participant School identified by Schoolid {
  o String Schoolid
  o String name
}

participant Company identified by Companytid {
  o String Companytid
  o String name
}

participant Student identified by Studentid {
  o String Studentid
  o String studentName
  o String ClassofYear
}

asset Transcript identified by tId{
  o String tId
  o String name
  o String ClassofYear
  o String gpa
  o String major
  o String jobexp optional
  o String nationality
  o Boolean readStatus default=false
  --> School school
}

asset TranscriptStatus identified by tsId{
  o String tsId
  o String name
  o String status
  o String ReviewedCompany
  --> Company company
}

transaction UpdateTranscript_status {
  o String studentName
  o Boolean readStatus default=false
  --> School school
}

/*
 * 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.
 */

/* global getAssetRegistry */

'use strict';
/**
 * Process a property that is held for sale
 * @param {org.school.education.UpdateTranscript_status} updateTranscript the transcript to be updated
 * @transaction
 */
async function transcriptForUpdated(TforUpdated) {   // eslint-disable-line no-unused-vars
    console.log('### transcriptForUpdated ' + TforUpdated.toString());
    TforUpdated.readStatus = true;

    const registry = await getAssetRegistry('org.school.education.Transcript');
    await registry.update(TforUpdated.readStatus);
}

/*
 * 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.
 */

/**
 * Sample access control list.
 */
rule EverybodyCanReadEverything {
    description: "Allow all participants read access to all resources"
    participant: "org.school.education.School"
    operation: READ
    resource: "org.school.education.*"
    action: ALLOW
}

rule EverybodyCanSubmitTransactions {
    description: "Allow all participants to submit transactions"
    participant: "org.school.education.School"
    operation: CREATE
    resource: "org.schoo;.education.UpdateTranscript_status"
    action: ALLOW
}

rule OwnerHasFullAccessToTheirAssets {
    description: "Allow all participants full access to their assets"
    participant(p): "org.school.education.School"
    operation: ALL
    resource(r): "org.school.education.Transcript"
    condition: (r.owner.getIdentifier() === p.getIdentifier())
    action: ALLOW
}



rule SystemACL {
    description: "System ACL to permit all access"
    participant: "org.hyperledger.composer.system.Participant"
    operation: ALL
    resource: "org.hyperledger.composer.system.**"
    action: ALLOW
}

rule NetworkAdminUser {
    description: "Grant business network administrators full access to user resources"
    participant: "org.hyperledger.composer.system.NetworkAdmin"
    operation: ALL
    resource: "**"
    action: ALLOW
}

rule NetworkAdminSystem {
    description: "Grant business network administrators full access to system resources"
    participant: "org.hyperledger.composer.system.NetworkAdmin"
    operation: ALL
    resource: "org.hyperledger.composer.system.**"
    action: ALLOW
}


Solution

  • As per my understanding, I run your code. I had fix some issues. In your code, you may update a readStatus under a transcript asset. If you update a single value under s asset so you need to put an object of that asset in the Update function.

    1. Model File Changes:

    transaction UpdateTranscript_status {
      o Boolean readStatus default=false
      --> Transcript transcript
    }
    

    2. logic.js Changes:

    async function transcriptForUpdated(TforUpdated) { 
      // eslint-disable-line no-unused-vars
        TforUpdated.readStatus = true;
    
      TforUpdated.transcript.readStatus = TforUpdated.readStatus;
    
    
        const registry = await getAssetRegistry('org.school.education.Transcript');
        await registry.update(TforUpdated.transcript);
    }
    

    After Running this transaction it will update a readStatus (false value update by true) under a Transcript asset.

    Hope it will fix your issue :)