Skip to content

Commit

Permalink
Remove IBM confidential licenses (hyperledger-archives#1227)
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Stone authored Jun 9, 2017
1 parent 4a48959 commit 6ce5a0b
Show file tree
Hide file tree
Showing 16 changed files with 866 additions and 12 deletions.
Binary file modified packages/composer-admin/test/data/businessnetwork.zip
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* 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.
*/

'use strict';

/*eslint-disable no-unused-vars*/
/*eslint-disable no-undef*/

/**
* A transaction processor for AnimalMovementDeparture
* @param {com.ibm.concerto.mozart.AnimalMovementDeparture} movementDeparture - the transaction to be processed
*/
function onAnimalMovementDeparture(movementDeparture) {
console.log('onAnimalMovementDeparture');
if(movementDeparture.animal.movementStatus !== 'IN_FIELD'){
throw new Error('Animal is already IN_TRANSIT');
}

// set the movement status of the animal
movementDeparture.animal.movementStatus = 'IN_TRANSIT';

// save the animal
let ar = getAssetRegistry('com.ibm.concerto.mozart.Animal');
ar.update(movementDeparture.animal);

// add the animal to the incoming animals of the
// destination business
if(movementDeparture.to.incomingAnimals) {
movementDeparture.to.incomingAnimals.push(movementDeparture.animal);
}
else {
movementDeparture.to.incomingAnimals = [movementDeparture.animal];
}

// save the business
let br = getAssetRegistry('com.ibm.concerto.mozart.Business');
br.update(movementDeparture.to);
}

/**
* A transaction processor for AnimalMovementArrival
* @param {com.ibm.concerto.mozart.AnimalMovementArrival} movementArrival - the transaction to be processed
*/
function onAnimalMovementArrival(movementArrival) {
console.log('onAnimalMovementArrival');

if(movementArrival.animal.movementStatus !== 'IN_TRANSIT'){
throw new Error('Animal is not IN_TRANSIT');
}

// set the movement status of the animal
movementArrival.animal.movementStatus = 'IN_FIELD';

// set the new owner of the animal
// to the owner of the 'to' business
movementArrival.animal.owner = movementArrival.to.owner;

// set the new location of the animal
movementArrival.animal.location = movementArrival.arrivalField;

// save the animal
let ar = getAssetRegistry('com.ibm.concerto.mozart.Animal');
ar.update(movementArrival.animal);

// remove the animal from the incoming animals
// of the 'to' business
if(!movementArrival.to.incomingAnimals) {
throw new Error('Incoming business should have incomingAnimals on AnimalMovementArrival.');
}

movementArrival.to.incomingAnimals = movementArrival.to.incomingAnimals
.filter(function(animal) {
return animal.animalId !== movementArrival.animal.animalId;
});

// save the business
let br = getAssetRegistry('com.ibm.concerto.mozart.Business');
br.update(movementArrival.to);
}

/*eslint-enable no-unused-vars*/
/*eslint-enable no-undef*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.
*/

'use strict';

/*eslint-disable no-unused-vars*/
/*eslint-disable no-undef*/


/**
* Get the Animals, but do not resolve contained relationships
* @query
* @param {String} farmerId - the email of the farmer
* @returns {Animal[]} - the animals that belong to the farmer
*/
function findAnimalsByOwnerId(farmerId) {
return query('select a from Animal a where a.owner == :farmerId');
}

/**
* Get the Animals, but and selectively resolve relationships
* @query
* @param {String} farmerId - the email of the farmer
* @returns {Animal[]} - the animals that belong to the farmer
*/
function findAnimalsByOwnerIdWithDetails(farmerId) {
return query('select resolve(a, a.location, a.owner) from Animal a where a.owner == :farmerId');
}

/**
* Get the incoming animals for a farmer and do not resolve relationships
* @query
* @param {String} farmerId - the email of the farmer
* @returns {Animal[]} - the animals that belong to the farmer
*/
function findIncomingAnimalsByFarmerId(farmerId) {
return query('select b.incomingAnimals from Business b where b.owner == :farmerId');
}

/*eslint-enable no-unused-vars*/
/*eslint-enable no-undef*/
140 changes: 140 additions & 0 deletions packages/composer-admin/test/data/businessnetwork/models/carlease.cto
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/**
* Car Lease Scenario
* Concerto Language File
*
* Author: Billy Blockchain
* Version: 1.0
* Last Updates: 2016-09-22
*/

// define the namespace for this model
namespace org.acme

// import a type from the system namespace
import concerto.Participant

enum State {
o CREATED
o REGISTERED
o SOLD
}

/**
* Define an asset base class
*/
abstract asset Base identified by vin {
o String vin validator = "regex:/^(?:([A-HJ-NPR-Z]){3}|\d{3})(?1){2}\d{2}(?:(?1)|\d)(?:\d|X)(?:(?1)+\d+|\d+(?1)+)\d{6}$/i"
}

/**
* Vehicle is the definition of an asset that we will be tracking
* Vehicle extends (augments) the Base asset.
*/
asset Vehicle extends Base { // an asset is the core data type

// An asset contains Fields, each of which can have an optional default value
// and a validator expression
// A Field can be declared 'optional' meaning that it may be missing
o String model default="F150"
o String make default="FORD"
o String reg default="ABC123"
o Integer year default="2016" validator="numeric:[2000, 3000]" optional
// comment
o Integer[] integerArray
o State state
o Double value
o String colour
o String V5cID validator="regex:^[A-z][A-z][0-9]{7}"
o String LeaseContractID
o Boolean scrapped default="false"
o DateTime lastUpdate optional
--> Participant owner //relationship to a Participant, with the field named 'owner'.
--> Participant[] previousOwners optional // Nary relationship
}

participant Regulator extends Participant {

}

// defines a Vehicle transaction type
transaction VehicleTransaction {
--> Vehicle vehicle // a VehicleTransaction is related to a Vehicle
}

transaction VehicleCreated extends VehicleTransaction {
}

transaction VehicleTransferredToManufacturer extends VehicleTransaction{
--> Participant manufacturer // Participant is a built in type
}

transaction VehicleTransferredToDealer extends VehicleTransaction{
--> Participant dealer // Participant is a built in type
}

transaction VehicleTransferredToLeaseCompany extends VehicleTransaction{
--> Participant leaseCompany // Participant is a built in type
}

transaction VehicleTransferredToLeasee extends VehicleTransaction{
--> Participant leasee // Participant is a built in type
}

transaction VehicleTransferredToScrapMerchant extends VehicleTransaction{
--> Participant scrapMerchant // Participant is a built in type
}

transaction VehicleScrapped extends VehicleTransaction{
}

/*
*/


/*
permission {
Participant Permissions
Regulator Create, Read (All vehicles), Transfer
Manufacturer Read (Own vehicles), Update (VIN, Make, Model, Colour, Reg), Transfer
Dealership Read (Own vehicles), Update (Colour, Reg), Transfer
Lease Company Read (Own vehicles), Update (Colour, Reg), Transfer
Leasee Read (Own vehicles), Update (Colour, Reg), Transfer
Scrap Merchant Read (Own vehicles), Scrap
}
*/

/*
on event VehicleCreated(vehicleCreated) {
if(vehicleCreated.vehicle.state == 'Template')
then {
vehicleCreated.vehicle.state = 'Manufacture';
}
}

state Template {
=> Manufacture {
when (vehicle.owner == caller &&
vehicle.state == 'Template' &&
caller.affilation == 'AUTHORITY' &&
vehicle.scrapped == false)
}

state Manufacture {
vehicle.save();
=> PrivateOwnership
=> LeasedOut
}

state PrivateOwnership {
=> BeingScrapped
}

state LeasedOut {
=> PrivateOwnership
=> BeingScrapped
}

state BeingScrapped {
}
}
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Concerto Language File
*
* The concerto namespace defines built-in types for building Blockchain
* based business networks. This file should not be modified.
*/
namespace concerto

/**
* Participant defines an actor in a blockchain based business network
*/
participant Participant identified by id {
o String id
}
Loading

0 comments on commit 6ce5a0b

Please sign in to comment.