mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-23 18:15:10 +00:00
74 lines
2.8 KiB
Go
Executable file
74 lines
2.8 KiB
Go
Executable file
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/xeipuuv/gojsonschema"
|
|
)
|
|
|
|
type Data struct {
|
|
DocType string `json:"docType"`
|
|
Id string `json:"id"`
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
Type string `json:"Type"`
|
|
DOI string `json:"DOI"`
|
|
Url string `json:"url"`
|
|
Manifest []string `json:"manifest"`
|
|
Footprint string `json:"footprint"`
|
|
Keywords []string `json:"keywords"`
|
|
OtherDataIdName string `json:"otherDataIdName"`
|
|
OtherDataIdValue string `json:"otherDataIdValue"`
|
|
FundingAgencies []string `json:"fundingAgencies"`
|
|
Acknowledgment string `json:"acknowledgment"`
|
|
NoteForChange string `json:"noteForChange"`
|
|
Contributor string `json:"contributor"`
|
|
Contributor_id string `json:"contributor_id"`
|
|
}
|
|
|
|
/*
|
|
func (s *SmartContract) InitLedger(ctx contractapi.TransactionContextInterface) error {
|
|
dataEntries := []Data{
|
|
{docType: "TestType", id: "00000", title: "TestSample", description: "description", Type: "TestType", DOI: "https://doi.org/10.57873/T34W2R", url: "sdsc.edu", manifest: "TestManifest", footprint: "", keywords: "SmartContrac, ChainCode, Peer", otherDataIdName: "None", otherDataIdValue: "None", fundingAgencies: "DOS", acknowledgment: "SDSC", noteForChange: "NONE", contributor: "AveryhardworkingUser@email.com", contributor_id: "ABC123"},
|
|
}
|
|
|
|
for _, data := range dataEntries {
|
|
assetJSON, err := json.Marshal(data)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = ctx.GetStub().PutState(data.id, assetJSON)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to put to world state. %v", err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
*/
|
|
|
|
func main() {
|
|
//data := Data{
|
|
//"DocType": "TestType", "Id": "00000", "Title": "TestSample", "Description": "description", "Type": "TestType", "DOI": "https://doi.org/10.57873/T34W2R", "Url": "sdsc.edu", "Manifest": "TestManifest", "Footprint": "", "Keywords": '["SmartContrac", "ChainCode", "Peer"]'ß, "OtherDataIdName": "None", "OtherDataIdValue": "None", "FundingAgencies": ["DOS", "NASA"], "Acknowledgment": "SDSC", "NoteForChange": "NONE", "Contributor": "AveryhardworkingUser@email.com", "Contributor_id": "ABC123"
|
|
//}
|
|
|
|
schemaLoader := gojsonschema.NewReferenceLoader("file:///home/ofgarzon2662/OSC-IS/fabric-samples/test-network/JsonSchemaValidationTests/Schema.json")
|
|
documentLoader := gojsonschema.NewReferenceLoader("file:////home/ofgarzon2662/OSC-IS/fabric-samples/test-network/JsonSchemaValidationTests/testFile.json")
|
|
|
|
result, err := gojsonschema.Validate(schemaLoader, documentLoader)
|
|
//fmt.Printf(result.Valid())
|
|
if err != nil {
|
|
panic(err.Error())
|
|
}
|
|
|
|
if result.Valid() {
|
|
fmt.Printf("The document is valid\n")
|
|
} else {
|
|
fmt.Printf("The document is not valid. see errors :\n")
|
|
for _, desc := range result.Errors() {
|
|
fmt.Printf("- %s\n", desc)
|
|
}
|
|
}
|
|
}
|