Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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 getFactory emit */
- /**
- * Sample transaction processor function.
- * @param {org.doptrace.setupDemo} setupDemo The sample transaction instance.
- * @transaction
- */
- function setupDemo(setupDemo) {
- var factory = getFactory();
- var NS = 'org.doptrace';
- /**
- * VALUE CHAIN OPERATORS
- */
- // criar Producer
- var producer = factory.newResource(NS, 'Producer', 'PROD_001');
- producer.phoneNumber = "9444444444";
- producer.email = "producer@email.com";
- producer.street = "Rua do prod";
- producer.zip = "4900-200";
- producer.city = "Viana do Castelo";
- producer.country = "Portugal";
- producer.name = "Quinta Vianense";
- producer.description = 'Produtores de leite';
- // criar Industry_Retailer
- var industry_retailer = factory.newResource(NS, 'Industry_Retailer', 'IR_001');
- industry_retailer.phoneNumber = "955555555";
- industry_retailer.email = "industry_retailer@email.com";
- industry_retailer.street = "Rua da industra";
- industry_retailer.zip = "4900-210";
- industry_retailer.city = "Viana do Castelo";
- industry_retailer.country = "Portugal";
- industry_retailer.name = "Milky Way";
- industry_retailer.description = 'Industria e retalhe de produtos lacticinios';
- // criar CertificationEntity
- var certificationEntity = factory.newResource(NS, 'CertificationEntity', 'CE_001');
- certificationEntity.phoneNumber = "966666666";
- certificationEntity.email = "certificationEntity@email.com";
- certificationEntity.street = "Rua da entidade";
- certificationEntity.zip = "4900-212";
- certificationEntity.city = "Viana do Castelo";
- certificationEntity.country = "Portugal";
- certificationEntity.name = "CE";
- certificationEntity.description = 'Entidade de certificação de produtos DOP';
- // criar Logistics
- var logistics = factory.newResource(NS, 'Logistics', 'L_001');
- logistics.phoneNumber = "955555555";
- logistics.email = "logistics@email.com";
- logistics.street = "Rua do transporte";
- logistics.zip = "4900-100";
- logistics.city = "Viana do Castelo";
- logistics.country = "Portugal";
- logistics.name = "Logistica AltoMinho";
- logistics.description = 'Companhia de distribuição';
- /**
- * PARTICIPANTS
- */
- // criar SysAdmin (luisalves é username [sysadmin id])
- var sysAdmin = factory.newResource(NS, 'SysAdmin', 'luisalves');
- sysAdmin.phoneNumber = "911111111";
- sysAdmin.email = "admin@email.com";
- sysAdmin.firstname = "Luis";
- sysAdmin.lastname = "Alves";
- sysAdmin.password = "123";
- // criar WorkerAdmin
- var workerAdmin = factory.newResource(NS, 'WorkerAdmin', 'tiagocarvalhido');
- workerAdmin.phoneNumber = "922222222";
- workerAdmin.email = "workeradmin@email.com";
- workerAdmin.firstname = "Tiago";
- workerAdmin.lastname = "Carvalhido";
- workerAdmin.password = "123"
- workerAdmin.operator = factory.newRelationship(NS, 'Producer', 'PROD_001');
- // criar Worker
- var worker = factory.newResource(NS, 'Worker', 'joselima');
- worker.phoneNumber = "933333333";
- worker.email = "worker@email.com";
- worker.firstname = "Jose";
- worker.lastname = "Lima";
- worker.password = "123"
- worker.operator = factory.newRelationship(NS, 'Producer', 'PROD_001');
- /**
- * EVENTS
- */
- /**
- * BATCH
- */
- // assets
- return getAssetRegistry(NS + '.Producer')
- .then(function(producerRegistry) {
- return producerRegistry.addAll([producer]);
- })
- .then(function() {
- return getAssetRegistry(NS + '.Industry_Retailer');
- })
- .then(function(industry_retailerRegistry) {
- return industry_retailerRegistry.addAll([industry_retailer]);
- })
- .then(function() {
- return getAssetRegistry(NS + '.CertificationEntity');
- })
- .then(function(certificationEntityRegistry) {
- return certificationEntityRegistry.addAll([certificationEntity]);
- })
- .then(function() {
- return getAssetRegistry(NS + '.Logistics');
- })
- .then(function(logisticsRegistry) {
- return logisticsRegistry.addAll([logistics]);
- })
- // participants
- .then(function() {
- return getParticipantRegistry(NS + '.SysAdmin');
- })
- .then(function(sysAdminRegistry) {
- return sysAdminRegistry.addAll([sysAdmin]);
- })
- .then(function() {
- return getParticipantRegistry(NS + '.WorkerAdmin');
- })
- .then(function(workerAdminRegistry) {
- return workerAdminRegistry.addAll([workerAdmin]);
- })
- .then(function() {
- return getParticipantRegistry(NS + '.Worker');
- })
- .then(function(workerRegistry) {
- return workerRegistry.addAll([worker]);
- });
- }
- /**
- * Sample transaction processor function.
- * @param {org.doptrace.A_producerToLogistics} prodToLog The sample transaction instance.
- * @transaction
- */
- async function prodToLog(prodToLog) {
- return getAssetRegistry('org.doptrace.Logistics').then(function(playerRegistry) {
- return playerRegistry.exists(prodToLog.newOwner.getIdentifier())
- }).then(function(exists) {
- return getAssetRegistry('org.doptrace.Producer')
- .then(function(playerRegistryHarvest) {
- return playerRegistryHarvest.exists(prodToLog.issuer.getIdentifier())
- }).then(function(existsHarvest) {
- if (!exists && existsHarvest) {
- throw Error('Companhia Logistica não registada !')
- } else if (!existsHarvest && exists) {
- throw Error('Produtor não Registado !')
- } else if (!existsHarvest && !exists) {
- throw Error('Erro na trasação!')
- } else if (exists && existsHarvest) {
- getAssetRegistry('org.doptrace.Batch')
- .then(function(assetRegistry) {
- prodToLog.batch.previousOperator = prodToLog.issuer
- prodToLog.batch.state = 'IN_TRANSIT'
- prodToLog.batch.currentOperator = prodToLog.newOwner
- // prodToLog.batch.previousEvents.push(prodToLog.)
- assetRegistry.update(prodToLog.batch)
- ;
- });;
- }
- })
- })
- }
- /**
- * Sample transaction processor function.
- * @param {org.doptrace.B_producerToIndustry} prodToIndustry The sample transaction instance.
- * @transaction
- */
- async function prodToIndustry(prodToIndustry) {
- return getAssetRegistry('org.doptrace.Industry_Retailer').then(function(playerRegistry) {
- return playerRegistry.exists(prodToIndustry.newOwner.getIdentifier())
- }).then(function(exists) {
- return getAssetRegistry('org.doptrace.Producer')
- .then(function(playerRegistryHarvest) {
- return playerRegistryHarvest.exists(prodToIndustry.issuer.getIdentifier())
- }).then(function(existsHarvest) {
- return getAssetRegistry('org.doptrace.Batch')
- .then(function(playerRegistryBatch) {
- return playerRegistryBatch.exists(prodToIndustry.batch.getIdentifier())
- }).then(function(existsBatch) {
- if (!exists) {
- throw Error('Companhia Logistica não registada !')
- } else if (!existsHarvest) {
- throw Error('Produtor não Registado !')
- } else if (!existsBatch) {
- throw Error('Lote não registado!')
- } else if (exists && existsHarvest && existsBatch) {
- getAssetRegistry('org.doptrace.Batch')
- .then(function(assetRegistry) {
- prodToIndustry.batch.issuer = prodToIndustry.issuer
- prodToIndustry.batch.state = 'IN_TRANSIT'
- prodToLog.batch.owner = prodToLog.newOwner
- prodToLog.batch.previousOwners.push(prodToLog.issuer)
- assetRegistry.update(prodToLog.batch)
- ;
- });;
- }
- })
- })
- })
- }
- /**
- * Sample transaction processor function.
- * @param {org.doptrace.C_logisticsToIndustry} logisticsToIndustry The sample transaction instance.
- * @transaction
- */
- async function logisticsToIndustry(logisticsToIndustry) {
- return getAssetRegistry('org.doptrace.Industry_Retailer').then(function(playerRegistry) {
- return playerRegistry.exists(logisticsToIndustry.newOwner.getIdentifier())
- }).then(function(exists) {
- return getAssetRegistry('org.doptrace.Logistics')
- .then(function(playerRegistryHarvest) {
- return playerRegistryHarvest.exists(logisticsToIndustry.issuer.getIdentifier())
- }).then(function(existsHarvest) {
- return getAssetRegistry('org.doptrace.Batch')
- .then(function(playerRegistryBatch) {
- return playerRegistryBatch.exists(logisticsToIndustry.batch.getIdentifier())
- }).then(function(existsBatch) {
- if (!exists) {
- throw Error('Industria não registada !')
- } else if (!existsHarvest) {
- throw Error('Companhia Logistica não Registada !')
- } else if (!existsBatch) {
- throw Error('Lote não registado!')
- } else if (exists && existsHarvest && existsBatch) {
- getAssetRegistry('org.doptrace.Batch')
- .then(function(assetRegistry) {
- logisticsToIndustry.batch.issuer = logisticsToIndustry.issuer
- logisticsToIndustry.batch.state = 'IN_TRANSIT'
- logisticsToIndustry.batch.owner = logisticsToIndustry.newOwner
- logisticsToIndustry.batch.previousOwners.push(logisticsToIndustry.issuer)
- assetRegistry.update(logisticsToIndustry.batch)
- ;
- });;
- }
- })
- })
- })
- }
- /**
- * Sample transaction processor function.
- * @param {org.doptrace.batchRegistration} batchRegistration The sample transaction instance.
- * @transaction
- async function batchRegistration(batchRegistration) {
- return getAssetRegistry('org.doptrace.Industry_Retailer')
- .then(function(playerRegistry) {
- return playerRegistry.exists(batchRegistration.retailer.getIdentifier())
- }).then(async function(exists) {
- return getAssetRegistry('org.doptrace.Batch')
- .then(function(playerRegistryBatch) {
- return playerRegistryBatch.exists(batchRegistration.batch.getIdentifier())
- }).then(async function(existsHarvest) {
- if (!exists && existsHarvest) {
- throw Error('Industria não registada !')
- } else if (exists && !existsHarvest) {
- throw Error('Lote não registado !')
- } else if (!exists && !existsHarvest) {
- throw Error('ERRO NA TRANSAÇÃO!')
- } else if (exists && existsHarvest) {
- let result = await getAssetRegistry('org.doptrace.Batch')
- let batchAsset = batchRegistration.batch
- let batchId = batchAsset.id
- let numberOfBatch = batchRegistration.numberOfBatchs;
- let i;
- for (i = 1; i <= numberOfBatch; i++) {
- var factory = getFactory();
- var random = Math.floor(Math.random() * (1000 - 100) + 100) / 100;
- let batch = factory.newResource('org.doptrace', 'Batch', batchRegistration.batch.id + 'SubBatch' + random);
- batch.unit = batchRegistration.newUnit
- batch.state = 'REGISTERED'
- batch.amount = batchRegistration.newAmount
- batch.previousOwners = batchRegistration.batch.previousOwners
- batch.issuer = batchRegistration.retailer
- batch.owner = batchRegistration.retailer
- batchRegistration.batch.previousOwners.push(batchRegistration.batch.issuer)
- await result.addAll([batch]);
- }
- await result.update(batchRegistration.batch)
- };
- });
- })
- }
- */
- /**
- * Sample transaction processor function.
- * @param {org.doptrace.D_industryToEntity} industryToEntity The sample transaction instance.
- * @transaction
- */
- async function industryToEntity(industryToEntity) {
- return getAssetRegistry('org.doptrace.CertificationEntity').then(function(playerRegistry) {
- return playerRegistry.exists(industryToEntity.newOwner.getIdentifier())
- }).then(function(exists) {
- return getAssetRegistry('org.doptrace.Industry_Retailer')
- .then(function(playerRegistryHarvest) {
- return playerRegistryHarvest.exists(industryToEntity.issuer.getIdentifier())
- }).then(function(existsHarvest) {
- return getAssetRegistry('org.doptrace.Batch')
- .then(function(playerRegistryBatch) {
- return playerRegistryBatch.exists(industryToEntity.batch.getIdentifier())
- }).then(function(existsBatch) {
- if (!exists) {
- throw Error('Entidade de certificação não registada !')
- } else if (!existsHarvest) {
- throw Error('Companhia Logistica não Registada !')
- } else if (!existsBatch) {
- throw Error('Lote não registado!')
- } else if (exists && existsHarvest && existsBatch) {
- getAssetRegistry('org.doptrace.Batch')
- .then(function(assetRegistry) {
- industryToEntity.batch.issuer = industryToEntity.issuer
- industryToEntity.batch.state = 'IN_TRANSIT'
- industryToEntity.batch.owner = industryToEntity.newOwner
- industryToEntity.batch.previousOwners.push(industryToEntity.issuer)
- assetRegistry.update(industryToEntity.batch)
- ;
- });;
- }
- })
- })
- })
- }
- /**
- * Sample transaction processor function.
- * @param {org.doptrace.F_EntityToIndustry} entityToIndustry The sample transaction instance.
- * @transaction
- */
- async function entityToIndustry(entityToIndustry) {
- return getAssetRegistry('org.doptrace.Industry_Retailer').then(function(playerRegistry) {
- return playerRegistry.exists(entityToIndustry.newOwner.getIdentifier())
- }).then(function(exists) {
- return getAssetRegistry('org.doptrace.CertificationEntity')
- .then(function(playerRegistryHarvest) {
- return playerRegistryHarvest.exists(entityToIndustry.issuer.getIdentifier())
- }).then(function(existsHarvest) {
- return getAssetRegistry('org.doptrace.Batch')
- .then(function(playerRegistryBatch) {
- return playerRegistryBatch.exists(entityToIndustry.batch.getIdentifier())
- }).then(function(existsBatch) {
- if (!exists) {
- throw Error('Industria não registada !')
- } else if (!existsHarvest) {
- throw Error('Companhia Logistica não Registada !')
- } else if (!existsBatch) {
- throw Error('Lote não registado!')
- } else if (exists && existsHarvest && existsBatch) {
- getAssetRegistry('org.doptrace.Batch')
- .then(function(assetRegistry) {
- entityToIndustry.batch.issuer = entityToIndustry.issuer
- entityToIndustry.batch.state = 'IN_TRANSIT'
- entityToIndustry.batch.owner = entityToIndustry.newOwner
- entityToIndustry.batch.previousOwners.push(entityToIndustry.issuer)
- assetRegistry.update(entityToIndustry.batch)
- ;
- });;
- }
- })
- })
- })
- }
- /**
- * Sample transaction processor function.
- * @param {org.doptrace.G_EntityToLogistics} entityToLogistics The sample transaction instance.
- * @transaction
- */
- async function entityToLogistics(entityToLogistics) {
- return getAssetRegistry('org.doptrace.Logistics').then(function(playerRegistry) {
- return playerRegistry.exists(entityToLogistics.newOwner.getIdentifier())
- }).then(function(exists) {
- return getAssetRegistry('org.doptrace.CertificationEntity')
- .then(function(playerRegistryHarvest) {
- return playerRegistryHarvest.exists(entityToLogistics.issuer.getIdentifier())
- }).then(function(existsHarvest) {
- return getAssetRegistry('org.doptrace.Batch')
- .then(function(playerRegistryBatch) {
- return playerRegistryBatch.exists(entityToLogistics.batch.getIdentifier())
- }).then(function(existsBatch) {
- if (!exists) {
- throw Error('Companhia Logistica não registada !')
- } else if (!existsHarvest) {
- throw Error('Entidade de Certificação não Registada !')
- } else if (!existsBatch) {
- throw Error('Lote não registado!')
- } else if (exists && existsHarvest && existsBatch) {
- getAssetRegistry('org.doptrace.Batch')
- .then(function(assetRegistry) {
- entityToLogistics.batch.issuer = entityToLogistics.issuer
- entityToLogistics.batch.state = 'IN_TRANSIT'
- entityToLogistics.batch.owner = entityToLogistics.newOwner
- entityToLogistics.batch.previousOwners.push(entityToLogistics.issuer)
- assetRegistry.update(entityToLogistics.batch)
- ;
- });;
- }
- })
- })
- })
- }
- /**
- * Sample transaction processor function.
- * @param {org.doptrace.transactionProductRegistration} productRegistration The sample transaction instance
- * @transaction
- */
- function productRegistation(productRegistation) {
- var array = new Array();
- return getAssetRegistry('org.doptrace.Producer').then(function(playerRegistry) {
- return playerRegistry.exists(productRegistation.productRegistration.producer.getIdentifier())
- }).then(function(exists) {
- return getParticipantRegistry('org.doptrace.Worker').then(function(playerRegistry) {
- return playerRegistry.exists(productRegistation.productRegistration.worker.getIdentifier())
- }).then(function(existsWorker) {
- return getAssetRegistry('org.doptrace.Product').then(function(playerRegistry) {
- return playerRegistry.exists(productRegistation.productRegistration.newBatch.product.getIdentifier())
- }).then(function(existsProduct) {
- if (!exists) {
- throw Error('Produtor não registado !');
- }else if(!existsWorker){
- throw Error('Worker não registado !');
- }else if(!existsProduct){
- throw Error('Product não registado !');
- } else if(exists &&existsWorker && existsProduct && productRegistation.productRegistration.newBatch != null) {
- getAssetRegistry('org.doptrace.ProductRegistration')
- .then(function(assetRegistry) {
- var factory = getFactory();
- var newAsset = factory.newResource(
- 'org.doptrace',
- 'ProductRegistration',
- productRegistation.productRegistration.id);
- newAsset.description = productRegistation.productRegistration.description;
- newAsset.latitude = productRegistation.productRegistration.latitude;
- newAsset.longitude = productRegistation.productRegistration.longitude;
- newAsset.dateTime = productRegistation.productRegistration.dateTime;
- newAsset.worker = productRegistation.productRegistration.worker;
- newAsset.producer = productRegistation.productRegistration.producer;
- array.push(newAsset);
- return assetRegistry.add(newAsset);
- ;
- }).then(function(batchRegistry){
- getAssetRegistry('org.doptrace.Batch')
- .then(function(batchRegistry2) {
- var factory = getFactory();
- var newBatch = factory.newResource(
- 'org.doptrace',
- 'Batch',
- productRegistation.productRegistration.newBatch.id);
- newBatch.amount = productRegistation.productRegistration.newBatch.amount;
- newBatch.unit = productRegistation.productRegistration.newBatch.unit;
- newBatch.creationDate = productRegistation.productRegistration.newBatch.creationDate;
- newBatch.expirationDate = productRegistation.productRegistration.newBatch.expirationDate;
- newBatch.state = productRegistation.productRegistration.newBatch.state;
- newBatch.certificated = productRegistation.productRegistration.newBatch.certificated;
- newBatch.previousEvents = array
- newBatch.currentOperator = productRegistation.productRegistration.producer;
- newBatch.product = productRegistation.productRegistration.newBatch.product;
- return batchRegistry2.add(newBatch);
- });;
- }
- )}else{
- throw Error('Novo Lote null');
- }})}
- )})}
- /**
- * Sample transaction processor function.
- * @param {org.doptrace.transactionQualityAssessement} quality The sample transaction instance
- * @transaction
- */
- function quality(quality) {
- var array = new Array();
- return getAssetRegistry('org.doptrace.Industry_Retailer').then(function(playerRegistry) {
- return playerRegistry.exists(quality.quality.industry_retailer.getIdentifier())
- }).then(function(existsIndustry) {
- return getAssetRegistry('org.doptrace.Batch').then(function(playerRegistry) {
- return playerRegistry.exists(quality.quality.assessedBatch.getIdentifier())
- }).then(function(existsBatch) {
- if (!existsIndustry) {
- throw Error('Industria não registado !');
- }else if(!existsBatch){
- throw Error('Lote não registado !');
- }else if( existsIndustry && existsBatch && quality.quality.amountDowned == 0.00){
- getAssetRegistry('org.doptrace.QualityAssessment')
- .then(function(assetRegistry) {
- var factory = getFactory();
- var newAsset = factory.newResource(
- 'org.doptrace',
- 'QualityAssessment',
- quality.quality.id);
- newAsset.description = quality.quality.description;
- newAsset.latitude = quality.quality.latitude;
- newAsset.longitude = quality.quality.longitude;
- newAsset.dateTime = quality.quality.dateTime;
- newAsset.worker = quality.quality.worker;
- newAsset.industry_retailer = quality.quality.industry_retailer;
- newAsset.assessedBatch = quality.quality.assessedBatch
- newAsset.amountDowned = quality.quality.amountDowned
- array.push(newAsset)
- return assetRegistry.add(newAsset);
- }).then(function(batchRegistry){
- getAssetRegistry('org.doptrace.Batch')
- .then(function(assetRegistry) {
- quality.quality.assessedBatch.currentOperator = quality.quality.industry_retailer
- assetRegistry.update(quality.quality.assessedBatch);
- })})}else if(existsBatch && existsIndustry && quality.quality.amountDowned != 0.00 /*quality.quality.industry_retailer.getIdentifier() != quality.quality.assessedBatch.currentOperator.getIdentifier()*/) {
- getAssetRegistry('org.doptrace.QualityAssessment')
- .then(function(assetRegistry) {
- var factory = getFactory();
- var newAsset = factory.newResource(
- 'org.doptrace',
- 'QualityAssessment',
- quality.quality.id);
- newAsset.description = quality.quality.description;
- newAsset.latitude = quality.quality.latitude;
- newAsset.longitude = quality.quality.longitude;
- newAsset.dateTime = quality.quality.dateTime;
- newAsset.worker = quality.quality.worker;
- newAsset.industry_retailer = quality.quality.industry_retailer;
- newAsset.assessedBatch = quality.quality.assessedBatch
- newAsset.amountDowned = quality.quality.amountDowned
- array.push(newAsset)
- return assetRegistry.add(newAsset);
- ;
- }).then(function(batchRegistry){
- getAssetRegistry('org.doptrace.Batch')
- .then(function(batchRegistry2) {
- var factory = getFactory();
- var newBatch = factory.newResource(
- 'org.doptrace',
- 'Batch',
- quality.quality.newBatch.id);
- newBatch.amount = quality.quality.assessedBatch.amount - quality.quality.amountDowned;
- newBatch.unit = quality.quality.assessedBatch.unit;
- newBatch.creationDate = quality.quality.assessedBatch.creationDate;
- newBatch.expirationDate = quality.quality.assessedBatch.expirationDate;
- newBatch.state = quality.quality.assessedBatch.state;
- newBatch.certificated = quality.quality.assessedBatch.certificated;
- newBatch.previousEvents = quality.quality.assessedBatch.previousEvents.concat(array)
- newBatch.currentOperator = quality.quality.assessedBatch.currentOperator;
- newBatch.product = quality.quality.assessedBatch.product;
- return batchRegistry2.add(newBatch);
- });;
- }
- )}else{
- throw Error('Erro na transação');
- }}
- )})}
- /**
- * Sample transaction processor function.
- * @param {org.doptrace.transactionTransformation} transformation The sample transaction instance
- * @transaction
- */
- async function transformation(transformation){
- //Tamanho dos arrays de Lotes e do array de quantidades
- var batchLength = transformation.transformation.usedBatches.length;
- var amountLength = transformation.transformation.amountPerBatch.length;
- //Array de Erros para verificação do batch
- var errors = new Array();
- //Array para concatenação de Eventos
- var array = new Array();
- //Verificação do Industry Retailer
- let registryIndustry = await getAssetRegistry('org.doptrace.Industry_Retailer');
- let resultIndustry = await registryIndustry.exists(transformation.transformation.industry_retailer.getIdentifier());
- if(!resultIndustry){
- throw Error('Industria nao registada !')
- }else if(transformation.transformation.usedBatches.length == 0){
- throw Error('Preencha os lotes usados para transformação !')
- }
- //Verificação dos lotes usados
- for(var i=0;i<batchLength;i++) {
- let registryBatch = await getAssetRegistry('org.doptrace.Batch');
- let resultBatch = await registryBatch.exists(transformation.transformation.usedBatches[i].getIdentifier());
- if(resultIndustry&& resultBatch && transformation.transformation.usedBatches != null){
- let transformRegistry = await getAssetRegistry('org.doptrace.Transformation');
- var factory = getFactory();
- var newAsset = factory.newResource(
- 'org.doptrace',
- 'Transformation',
- transformation.transformation.id);
- newAsset.description = transformation.transformation.description;
- newAsset.latitude = transformation.transformation.latitude;
- newAsset.longitude = transformation.transformation.longitude;
- newAsset.dateTime = transformation.transformation.dateTime;
- newAsset.worker = transformation.transformation.worker;
- newAsset.processes = transformation.transformation.processes;
- newAsset.industry_retailer = transformation.transformation.industry_retailer
- newAsset.usedBatches = transformation.transformation.usedBatches;
- newAsset.amountPerBatch = transformation.transformation.amountPerBatch;
- array.push(newAsset)
- if(batchLength != amountLength){
- throw Error('Erro na transação');
- }else{
- return transformRegistry.add(newAsset);
- let registryBatch = await getAssetRegistry('org.doptrace.Batch');
- var factory = getFactory();
- var newBatch = factory.newResource(
- 'org.doptrace',
- 'Batch',
- transformation.transformation.newBatch.id);
- newBatch.amount = // transformation.transformation.usedBatch[i].amount - transformation.transformation.;
- newBatch.unit = quality.quality.assessedBatch.unit;
- newBatch.creationDate = quality.quality.assessedBatch.creationDate;
- newBatch.expirationDate = quality.quality.assessedBatch.expirationDate;
- newBatch.state = quality.quality.assessedBatch.state;
- newBatch.certificated = quality.quality.assessedBatch.certificated;
- newBatch.previousEvents = quality.quality.assessedBatch.previousEvents.concat(array)
- newBatch.currentOperator = quality.quality.assessedBatch.currentOperator;
- newBatch.product = quality.quality.assessedBatch.product;
- }
- }else{
- errors.push(new Error('Lote ' + transformation.transformation.usedBatches[i].getIdentifier() + ' não se encontra registado ! '));
- }
- throw errors
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement