在hypperledger作曲家中创建资产的资产

时间:2018-08-01 13:03:52

标签: api assets hyperledger-fabric hyperledger-composer

我想创建一个名为item的资产,该资产由其他项目组成。 这是我的模型文件的片段:

namespace org.dps.track

asset Item identified by itemId{
    o String itemId
    o String name
    o String serialNumber
    o String comment
    o Item [] items optional

abstract participant BU identified by buId{
    o String buId
    o String name
    o String country
    o String city
}


participant Manufacturer extends BU{

}

participant Assembler extends BU{

}

在rest-server-api中,我试图发布包含其他项目的项目,例如:

    {
  "$class": "org.dps.track.Item",
  "itemId": "I5",
  "name": "complex",
  "serialNumber": "222",
  "comment": "complex item - consists of many items",
  "items": [
    "org.dps.track.Item#I2", "org.dps.track.Item#I3"
  ],
  "owner": "org.dps.track.Assembler#BU3"
}

(当然Item#I2和Item#I3已经发布并属于BU3),当我尝试发布此消息时,我收到以下错误消息

    {
  "error": {
    "statusCode": 500,
    "name": "Error",
    "message": "Invalid or missing identifier for Type Item in namespace       org.dps.track",
    "stack": "Error: Invalid or missing identifier for Type Item in namespace org.dps.track\n    at Factory.newResource (/home/composer/.npm-global/lib/node_modules/composer-rest-server/node_modules/composer-common/lib/factory.js:86:19)\n    at JSONPopulator.convertItem (/home/composer/.npm-global/lib/node_modules/composer-rest-server/node_modules/composer-common/lib/serializer/jsonpopulator.js:142:50)\n    at JSONPopulator.visitField (/home/composer/.npm-global/lib/node_modules/composer-rest-server/node_modules/composer-common/lib/serializer/jsonpopulator.js:104:34)\n    at JSONPopulator.visit (/home/composer/.npm-global/lib/node_modules/composer-rest-server/node_modules/composer-common/lib/serializer/jsonpopulator.js:60:25)\n    at Field.accept (/home/composer/.npm-global/lib/node_modules/composer-rest-server/node_modules/composer-common/lib/introspect/decorated.js:54:24)\n    at JSONPopulator.visitClassDeclaration (/home/composer/.npm-global/lib/node_modules/composer-rest-server/node_modules/composer-common/lib/serializer/jsonpopulator.js:83:60)\n    at JSONPopulator.visit (/home/composer/.npm-global/lib/node_modules/composer-rest-server/node_modules/composer-common/lib/serializer/jsonpopulator.js:56:25)\n    at AssetDeclaration.accept (/home/composer/.npm-global/lib/node_modules/composer-rest-server/node_modules/composer-common/lib/introspect/decorated.js:54:24)\n    at Serializer.fromJSON (/home/composer/.npm-global/lib/node_modules/composer-rest-server/node_modules/composer-common/lib/serializer.js:180:26)\n    at ensureConnected.then (/home/composer/.npm-global/lib/node_modules/composer-rest-server/node_modules/loopback-connector-composer/lib/businessnetworkconnector.js:634:43)\n    at <anonymous>\n    at process._tickDomainCallback (internal/process/next_tick.js:228:7)"
  }
}

是否有人设法创建嵌套资产,该资产对他有用?真的很感谢您的帮助,建议。

1 个答案:

答案 0 :(得分:0)

要将模型中定义的项目包含在项目中,可以使用类似于以下内容的JSON:

{
 "$class": "org.dps.track.Item",
 "itemId": "2",
 "name": "2",
 "serialNumber": "2",
 "comment": "2",
 "items": [{"$class": "org.dps.track.Item",
 "itemId": "3",
 "name": "3",
 "serialNumber": "3",
 "comment": "3"}]

}

但是,我想知道您真正想要的是与其他现有项目的关系数组吗,在这种情况下,您将拥有此模型和JSON:

asset Item identified by itemId{
o String itemId
o String name
o String serialNumber
o String comment
--> Item [] items optional
} 

{
 "$class": "org.dps.track.Item",
 "itemId": "A",
 "name": "A",
 "serialNumber": "A",
 "comment": "A",
 "items2": ["org.dps.track.Item#C","org.dps.track.Item#B"]
}