Добавление нескольких активов в качестве владельцев в одной транзакции - PullRequest
0 голосов
/ 19 марта 2019

Я пытаюсь написать код, в котором я сначала делаю некоторые материалы, а затем эти материалы объединяются в модуль.Когда я выполняю транзакцию модуля, материалы должны быть частью транзакции.

Когда я пишу новый код, транзакция "internProducerModule" работает, но если я копирую его в новый файл, возникает ошибка:"TypeError: Невозможно установить свойство 'owner' из undefined"

Как я уже упоминал, если я копирую код, он не работает, но когда я удаляю в асинхронной функции InternProducerModule весь код (строки) с помощью "материал1, ..., материал4) в нем и напиши им новый, он работает.

Вот код: Файл модели:

namespace org.master

// BASE DEFINTIONS

abstract participant Business identified by businessId {
  o String businessId
}

participant MaterialSupplier extends Business {
  o String materialSupplierName
  o Double accountBalance
  // Alle vorhandenen Materialien anzeigen
}

concept MaterialDetails {
  --> MaterialSupplier make
  o String materialName
  o String materialColour optional
  o String batch
  o Double amount
}

concept MaterialTransferLogEntry {
  --> Business seller
  --> Business buyer
  --> Material material
  o DateTime arrivalDateTime
}

asset Material identified by materialId {
  --> Business owner
  o String materialId
  o MaterialDetails materialDetails
  o QualityControlMaterial [] qualityControlsMaterial optional
  o MaterialTransferLogEntry[] logEntries
}

transaction InternMaterialSupplier {
  --> MaterialSupplier seller
  --> MaterialSupplier buyer
  --> Material material
  o Double unitCount
  o DateTime arrivalDateTime
}

transaction MaterialSupplierToProducer {
  --> MaterialSupplier seller
  --> Producer buyer
  --> Material material
  o Double unitCount
  o Double unitPrice
  o Double minQuality 
  o Double maxQuality 
  o Double Penalty 
  o DateTime arrivalDateTime
  --> MaterialSupplier materialSupplier
  --> Producer producer
}

participant Producer extends Business {
  o String producerName
  o Double accountBalance
  // Alle vorhandenen Materialien + Module anzeigen
}

concept ModuleDetails {
  --> Producer make
  o String moduleName
  o String batch
  o Double amount
}

concept ModuleTransferLogEntry {
  --> Business seller
  --> Business buyer
  --> Module module
  --> Material material1 optional
  --> Material material2 optional
  --> Material material3 optional
  --> Material material4 optional
  --> Material material5 optional
  o DateTime arrivalDateTime
}

asset Module identified by moduleId {
  --> Business owner
  o String moduleId
  o ModuleDetails moduleDetails
  o QualityControlModule [] qualityControlsModule optional
  o ModuleTransferLogEntry[] logEntries
}

transaction InternProducerMaterial {
  --> Producer seller
  --> Producer buyer
  --> Material material
  o Double unitCount
  o DateTime arrivalDateTime
}

transaction InternProducerModule {
  --> Producer seller
  --> Producer buyer
  --> Module module
  o Double unitCount
  --> Material material1 optional
  o Double unitCount1 optional
  --> Material material2 optional
  o Double unitCount2 optional
  --> Material material3 optional
  o Double unitCount3 optional
  --> Material material4 optional
  o Double unitCount4 optional
  --> Material material5 optional
  o Double unitCount5 optional
  o DateTime arrivalDateTime
}

transaction QualityControlMaterial {
  o Double qualityDegree
  --> Material material
}

transaction QualityControlModule {
  o Double qualityDegree
}

Файл сценария:

/**
 * @param {org.master.InternMaterialSupplier} internMaterialSupplier - the internMaterialSupplier to be processed
 * @transaction
 */
async function internMaterialSupplier(internMaterialSupplier) { // eslint-disable-line no-unused-vars
    console.log('internMaterialSupplier');

    const namespace = 'org.master';
    const factory = getFactory();

    const seller = internMaterialSupplier.seller;
    const buyer = internMaterialSupplier.buyer;
    const material = internMaterialSupplier.material;

    //change material owner
    material.owner = buyer;

    //MaterialTransaction for log
    const materialTransferLogEntry = factory.newConcept(namespace, 'MaterialTransferLogEntry');
    materialTransferLogEntry.material = factory.newRelationship(namespace, 'Material', material.getIdentifier());
    materialTransferLogEntry.seller = factory.newRelationship(namespace, 'Business', seller.getIdentifier());
    materialTransferLogEntry.buyer = factory.newRelationship(namespace, 'Business', buyer.getIdentifier());
    materialTransferLogEntry.arrivalDateTime = internMaterialSupplier.arrivalDateTime;
    if (!material.logEntries) {
        material.logEntries = [];
    }

    material.logEntries.push(materialTransferLogEntry);

    const assetRegistry = await getAssetRegistry(material.getFullyQualifiedType());
    await assetRegistry.update(material);
}

/**
 * @param {org.master.MaterialSupplierToProducer} materialSupplierToProducer - the materialSupplierToProducer to be processed
 * @transaction
 */
async function test2(materialSupplierToProducer) {
   console.log('materialSupplierToProducer');

    const namespace = 'org.master';
    const factory = getFactory();

    const seller = materialSupplierToProducer.seller;
    const buyer = materialSupplierToProducer.buyer;
    const material = materialSupplierToProducer.material;

    //change material owner
    material.owner = buyer;

    //MaterialTransaction for log
    const materialTransferLogEntry = factory.newConcept(namespace, 'MaterialTransferLogEntry');
    materialTransferLogEntry.material = factory.newRelationship(namespace, 'Material', material.getIdentifier());
    materialTransferLogEntry.seller = factory.newRelationship(namespace, 'Business', seller.getIdentifier());
    materialTransferLogEntry.buyer = factory.newRelationship(namespace, 'Business', buyer.getIdentifier());
    materialTransferLogEntry.arrivalDateTime = materialSupplierToProducer.arrivalDateTime;
    if (!material.logEntries) {
        material.logEntries = [];
    }

    material.logEntries.push(materialTransferLogEntry);

    const assetRegistry = await getAssetRegistry(material.getFullyQualifiedType());
    await assetRegistry.update(material);

    let payOut = materialSupplierToProducer.unitPrice * materialSupplierToProducer.unitCount;
    console.log('Payout: ' + payOut);

    materialSupplierToProducer.materialSupplier.accountBalance += payOut;
    materialSupplierToProducer.producer.accountBalance -= payOut;

    console.log('MaterialSupplier: ' + materialSupplierToProducer.$identifier + 'new balance: ' + materialSupplierToProducer.materialSupplier.accountBalance);
    console.log('Producer: ' + materialSupplierToProducer.$identifier + 'new balance: ' + materialSupplierToProducer.producer.accountBalance);

    const materialSupplierRegistry = await getParticipantRegistry('org.master.MaterialSupplier');
    await materialSupplierRegistry.update(materialSupplierToProducer.materialSupplier);

    const producerRegistry = await getParticipantRegistry('org.master.Producer');
    await producerRegistry.update(materialSupplierToProducer.producer);
}

/**
 * @param {org.master.InternProducerMaterial} internProducerMaterial - the internProducerMaterial to be processed
 * @transaction
 */
async function internProducerMaterial(internProducerMaterial) { // eslint-disable-line no-unused-vars
    console.log('internProducerMaterial');

    const namespace = 'org.master';
    const factory = getFactory();

    const seller = internProducerMaterial.seller;
    const buyer = internProducerMaterial.buyer;
    const material = internProducerMaterial.material;

    //change material owner
    material.owner = buyer;

    //MaterialTransaction for log
    const materialTransferLogEntry = factory.newConcept(namespace, 'MaterialTransferLogEntry');
    materialTransferLogEntry.material = factory.newRelationship(namespace, 'Material', material.getIdentifier());
    materialTransferLogEntry.seller = factory.newRelationship(namespace, 'Business', seller.getIdentifier());
    materialTransferLogEntry.buyer = factory.newRelationship(namespace, 'Business', buyer.getIdentifier());
    materialTransferLogEntry.arrivalDateTime = internProducerMaterial.arrivalDateTime;
    if (!material.logEntries) {
        material.logEntries = [];
    }

    material.logEntries.push(materialTransferLogEntry);

    const assetRegistry = await getAssetRegistry(material.getFullyQualifiedType());
    await assetRegistry.update(material);
}

// Fehlt: Update des aktuellen Besitzers der Materialien
/**
 * @param {org.master.InternProducerModule} internProducerModule - the internProducerModule to be processed
 * @transaction
 */
async function internProducerModule(internProducerModule) { // eslint-disable-line no-unused-vars
    console.log('internProducerModule');

    const namespace = 'org.master';
    const factory = getFactory();

    const seller = internProducerModule.seller;
    const buyer = internProducerModule.buyer;
    const module = internProducerModule.module;
    const material1 = internProducerModule.material1;


    //change module owner
    module.owner = buyer;
    material1.owner = buyer;

    //ModuleTransaction for log
    const moduleTransferLogEntry = factory.newConcept(namespace, 'ModuleTransferLogEntry');
    moduleTransferLogEntry.module = factory.newRelationship(namespace, 'Module', module.getIdentifier());
    moduleTransferLogEntry.material1 = factory.newRelationship(namespace, 'Material', material1.getIdentifier());
    moduleTransferLogEntry.seller = factory.newRelationship(namespace, 'Business', seller.getIdentifier());
    moduleTransferLogEntry.buyer = factory.newRelationship(namespace, 'Business', buyer.getIdentifier());
    moduleTransferLogEntry.arrivalDateTime = internProducerModule.arrivalDateTime;
    if (!module.logEntries) {
        module.logEntries = [];
    }

    module.logEntries.push(moduleTransferLogEntry);
    material1.logEntries.push(moduleTransferLogEntry);

    const assetRegistry = await getAssetRegistry(module.getFullyQualifiedType());
    await assetRegistry.update(module);
}

Надеюсь, вы, ребята, можете мне помочь !!

...