Access and update the relationship field of a resource - hyperledger-fabric

I am grabbing the resource of particular asset from registry by something like this:-
var flight = factory.newResource(Namespace,'Aircraft',flightId);
To this resource, i am assigning a relationship by :-
flight.aircraft = factory.newRelationship('org.acme.airline.aircraft','Aircraft',aircraftId);
flight.aircraft.firstClassSeats = 10;
flight.aircraft.secondClassSeats = 10;
This relationship contains the following properties as defined in model file :
asset Aircraft identified by aircraftId {
o String aircraftId
// Number of seats per class
o Integer firstClassSeats default = 0
o Integer businessClassSeats default = 0
o Integer economyClassSeats default = 0
}
Flight Data :
asset Flight identified by flightId {
o String flightId regex=/[A-Z][A-Z][0-9][0-9][0-9]-[0-9][0-9]-[0-3][0-9]-[0-9][0-9]/
o String flightNumber
o Route route
o String[] aliasFlightNumber optional
--> Aircraft aircraft optional
}
Now, how to update these relationship values (for example firstClassSeats) of a particular flight resource and update it to the corresponding registry.

Related

Get IdentifyRef fileds data from TFS workitem

I have a code that gets a WI Type [Code Review Response]. When trying to get the Created By field of the WI
field = {[System.CreatedBy, Microsoft.VisualStudio.Services.WebApi.IdentityRef]}
or Reviewed By, or Closed By field of the WI, I am getting the string Microsoft.VisualStudio.Services.WebApi.IdentityRef and not the user name.
It seems there is another, lower level object in it that holds the user data...
How can i get into the user name and details?
For example, when I trying the following code:
WorkItem linked_WI = witClient.GetWorkItemAsync(linked_WI_ID).Result;
//set WI object to the linked WI
string linked_WI_Type = linked_WI.Fields["System.WorkItemType"].ToString();
if (linked_WI_Type == "Code Review Response")
{
string codereview_closed_status = linked_WI.Fields["Microsoft.VSTS.CodeReview.ClosedStatus"].ToString();
string codereview_reviewer = linked_WI.Fields["Microsoft.VSTS.Common.ReviewedBy"].ToString();
}
I am not getting the reviewer name but again the identity reference (Microsoft.VisualStudio.Services.WebApi.IdentityRef) as string.
How can I loop into the Idefntify Ref object and get the user name?
Try DisplayName property of IdentityRef object:
var person = (IdentityRef)linked_WI.Fields["Microsoft.VSTS.Common.ReviewedBy"];
string codereview_reviewer = person.DisplayName;

Linking updated assets in Hyperledger Composer

I am trying to create a chain which holds a document.
I have created the asset in the model file as
asset document identified by documentid {
o String documentid
o String formImageBase64 //will use IPFS Later
o String nameOfSignator
o String addressOfSignator
o Integer ageOfSignator
o Boolean isSigned
o DateTime dateTimeOfSigning
}
And there are multiple documents containing information of different people.
If the document is updated(new asset is created), How to show a link between the old document and the updated document.
Update
Changing Title from "Creating Application Form using Hyperledger Composer"
To "Chaining/Connecting updated assets in Hyperledger Composer"
I don't know what type of relation you want to show between the past documents and the new documents but if you want to show the historical information of the transactions then you can use HistorianRecord
On the New Updating document, I added a new string which contains the unique "document of the previous string. Making it kind of a singly linked list.
asset document identified by documentid {
o String documentID
o String previousDocumentID // optional(later) original document "0" for now
o String formImageBase64 //will use IPFS Later
o String nameOfSignator
o String addressOfSignator
o Integer ageOfSignator
o Boolean isSigned
o DateTime dateTimeOfSigning
}
This way I can chain documents together.

Required Field Validator for Model (.cto file) in Hyperledger Composer

I am developing a blockchain application using Hyperledger Composer.
This is a part of my model i.e. .cto file:
concept Address{
o String addressId
o String PersonInChargeFullName
o String title
o String address1
o String address2 optional
o String city
o String country
o String zipcode regex=/^\d{5}$/
o String phone regex=/^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$/
o String email regex=/^([a-zA-Z0-9_\-\.]+)#([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/
o Boolean isActive default=true
}
abstract participant Company identified by companyId{
o String companyId
o String companyName
o Address defaultAddress
}
participant OEM extends Company {
o Address[] plants
}
From this page, I understand that if we use optional as a field validator, which means that that field is optional, and others are not. Am I right?
Although, I have not made PersonInChargeFullName as optional, when I submit the data (for eg: "PersonInChargeFullName": "",) from composer-rest-server API, the transaction gets processed, without any error.
Please advise.
Here option is little bit of different concept try running your code without PersonInChargeFullName field not as PersonInChargeFullName = "" but don't include it in json input i am pretty sure you will get error.

IllegalModelException: Namespace is not defined for type org.acme.airline.aircraft.Aircraft

I am following a Udemy tutorial on Hyperledger fabric. I want to import a model file(or a namespace) to another model file. But I am receiving an error.
IllegalModelException: Namespace is not defined for type org.acme.airline.aircraft.Aircraft
I want to import org.acme.airline.aircraft to org.acme.airline.flight.
The two files are : -
> 1. org.acme.airline.flight.cto
>
> namespace org.acme.airline.flight
>
> import org.acme.airline.aircraft.Aircraft
>
> asset Flight identified by flightNumber {
> o String flightNumber
> o Route route
> o String[] aliasFlightNumber
> --> Aircraft aircraft optional
> }
>
> concept Route {
> o String origin
> o String destination
> o DateTime schedule
> }
org.acme.airline.aircraft
namespace org.acme.airline.aircraft
asset Aircraft identified by aircraftId {
o String aircraftId
o Ownership ownershiptType default="LEASED"
o Integer firstClassSeats
o Integer businessClassSeats
o Integer economyClassSeats
o String nickName optional
}
enum Ownership {
o LEASED
o OWNED
}
I tried to remove the permissions.acl file as suggested in one of the little-related questions on StackOverflow, but it the error still persists.
In the permission.acl i am receiving an error that,
IllegalModelException: Failed to find namespace test.*
click on here for one of the solution here.
It says that: Currently, to work with models that use imports and span multiple files, you must open all related files. To validate the ACL files and query files, the corresponding model files must also be opened as well. I plan to improve this by allowing a folder to be opened, but from what you say, it sounds like it is working as designed.

Limit PUT acces to a property within an asset

Instead of giving full update access to a participant I'd like to give him update access to a specific property within the asset.
From what I've read from the documentation it's possible to apply a rule to a property.
Rule:
rule PatientAddMentor {
description: "A patient is allowed to add mentors"
participant(p): "nl.epd.blockchain.Patient"
operation: UPDATE
resource(m): "nl.epd.blockchain.MedicalFile.mentors"
condition: (m.owner.getIdentifier() == p.getIdentifier())
action: ALLOW
}
The part where I am stuck at is how to target the asset in the condition. I'm assuming (m) equals the mentors in the condition because the error message says that the participant does not have UPDATE rights. (I'm not sure if it's even possible.)
Model:
namespace nl.epd.blockchain
asset MedicalFile identified by bsn {
o String bsn
--> Patient owner
--> Patient[] mentors optional
--> Organisation[] organisations optional
o Visit[] visits optional
o String[] allergies optional
o Treatment[] treatments optional
o Medicine[] medicine optional
}
participant Patient identified by bsn {
o String bsn
o String firstName
o String namePrefix optional
o String lastName
o String email
o String telephoneNumber
o String birthday
o String gender
o String city
o String zipCode
o String street
o String houseNumber
o String houseNumberExtra optional
}
The ACL engine does not yet enforce property level access control (only namespace and class level access control has been implemented).
You will have to use programmatic access control using the getCurrentParticipant() runtime API until declarative access control for properties is implemented.

Resources