PlaceOrder Transactions - hyperledger-composer

can you help me with this? I am trying to implement a transaction to place an order as the one you have on the vehicle- lifecycle-network however it is not working. I am able to submit the order; however when I try to update the status, I get an error saying that the order is not part of the collection ID; however, it works if I can create it with the add asset process. the same happen when testing the vehicle- lifecycle-network in the online playground. please advise.

I suspect you are trying to resolve to a Registry that does not exist - or is actually an abstract definition.
eg.
Both the Vehicle asset and the PrivateVehicleTransfer transaction accept relationships to the abstract participant composer.base.Person:
asset Vehicle identified by vin {
o String vin
o VehicleDetails vehicleDetails
o VehicleStatus vehicleStatus
--> Person owner optional
o String numberPlate optional
o String suspiciousMessage optional
o VehicleTransferLogEntry[] logEntries optional
}
transaction PrivateVehicleTransfer extends VehicleTransaction {
--> Person seller
--> Person buyer
o String specialNotes optional
}
The error message means that we're trying to look for (in this case) the composer.base.Person participant registry - but it does not exist:
Error: Object with ID 'Participant:composer.base.Person' in collection with ID '$sysregistries' does not exist
That participant registry does not exist because we do not create registries for abstract types.
We are looking for this registry because the vehicles supplied originally contain fully qualified relationships, but they do not include the right type:
{
"$class": "org.vda.Vehicle",
"vin": "1234",
"vehicleDetails": {
"$class": "org.vda.VehicleDetails",
"make": "Ford",
"modelType": "Ka",
"colour": "Red",
"vin": "1234",
"bodyType": "Hatchback",
"taxationClass": "PETROL_CAR",
"co2": 89,
"typeOfFuel": "Petrol",
"numberOfSeats": 5
},
"vehicleStatus": "ACTIVE",
"owner": "resource:composer.base.Person#bob#bob.com", <-- this is the problem
"numberPlate": "AA12 AAA"
},
etc
The relationships in the owner field need to contain the right type, eg, a Participant that extends from abstract 'Person' - for example PrivateOwner below would be the correct relationship:
"owner": "resource:org.acme.vehicle.lifecycle.PrivateOwner#bob#bob.com"

Related

Cannot update Organization field of a Person while doing a PUT request

So I created a person and also created an Organization and i want to send a PUT request to update a few fields of that Person (+ Organization they belong to).
So if my payload looks like:
{
"name": "Lorem Ipsum"
}
The persons name will be updated, all’s well.
But if I add the field ID for Organizations (org_id) as per the api docs on PUT requests, either nothing happens or i get an error.
If i add to the payload org_id as so, the name will be updated but not the organization.
{
"name": "Lorem Ipsum",
"org_id": 1, // <integer> of the Organizations ID
}
And if i format my payload just to include the org_id as so:
{
"org_id": 1
}
I get the following error:
“{"success":false,"error":"Bad request","error_info":"Please check developers.pipedrive.com for more information about Pipedrive API.","data":null,"additional_data":null}”
I’m stuck.
Can anyone help?

Microsoft 365 API : Issue at attaching Contact to Campaign Response

I am trying to attach a contact to campaign response.
I am using rest API for that.
https://learn.microsoft.com/en-us/dynamics365/customer-engagement/web-api/campaignresponse?view=dynamics-ce-odata-9
Post Data :
{
"firstname": "TestFirst",
"lastname": "TestLast",
"emailaddress": "test#test.com",
"telephone": "1234567890",
"prioritycode": 0,
"responsecode": 1,
"subject": "Test Subject",
"statuscode": 1,
"regardingobjectid_campaign#odata.bind": "/campaigns(xxxx90c-11ef-e811-a966-000d3ad24a0d)",
"regardingobjectid_contact#odata.bind": "/contacts(xxxxfa2e-c3b5-e811-a962-000d3ad24a0d)"
}
Here is my JSON.
I am getting Error : “Campaign as RegardingObject must be supplied”. Without contact, it works fine.
I had the same problem and the documentation is not very clear about it, I had to check all the relationships of the CampaignResponse in order to understand how to solve this.
If you want to create a CampaignResponse linked to both a Campaign and a Contact you need to do the following:
Create a CampaignResponse with the "regardingobjectid_campaign#odata.bind" in the params sent.
POST "https://some_subdomain.crm6.dynamics.com/api/data/v9.0/campaignresponses"
{
"regardingobjectid_campaign#odata.bind": "/campaigns(CAMPAIGN_ID_HERE)",
"description": "some desc",
"subject": "some subject "
}
Then find the CampaignResponse you just created to get its activityid (every CampaignResponse is an Activity)
Finally, you need to create a new ActivityParty, that will link the Contact to the CampaignResponse.
POST "https://some_subdomain.crm6.dynamics.com/api/data/v9.0/campaignresponses(CAMPAIGN_ID_HERE)/activitypointer_activity_parties"
{
"partyid_contact#odata.bind": "/contacts(CONTACT_ID_HERE)",
"participationtypemask": 11 //this is the code for customers
}
The "Regarding" lookup field can only be set to a single "regarding" record. Even though it appears that there are different Regarding fields, one for each entity type, those are "helper" fields that let you easily set the main Regarding field by setting one of those regardingobjectid_xxx fields.
You must choose to use either a campaign or a contact as your Regarding field. You can of course create other lookups, so you could use the Regarding field for your campaign and then add an additional Contact lookup field, for example.

How to execute logic on query?

With transactions, we can put our business logic in the transaction processors. Very simple access control logic can be put in the ACL file. But how can we use more complex logic to guard (or extend) queries?
I'm working on a case where I'd like to restrict read access to an asset by checking if another asset exists and has a certain property.
Example:
asset PersonalDetails identified by id {
o String id
o String dateOfBirth
o String firstName
o String lastName
--> Participant owner
}
asset AccessRequest identified by id {
o String id
o String property
o Boolean allowed
--> PersonalDetails personalDetails
}
When a participant requests PersonalDetails, an AccessRequest has to exist and to have allowed === true. The owner of the personal details is the one who can grant access. Ideally the AccessRequest has a field 'property' to allow more fine grained access control.
So my initial thought was:
transaction GetInfo identified by transactionId {
o String transactionId
--> AccessRequest accessRequest
}
/**
* Sample transaction
* #param {org.example.GetInfo} tx
* #transaction
*/
function getInfo(tx) {
if (!tx.accessRequest.allowed) {
throw 'Access denied.';
}
return Promise.resolve(tx.accessRequest.personalDetails[tx.accessRequest.property]);
}
But I don't think Composer supports returning values from a transaction (right?). So, in general how can we use logic in or before queries and more specifically, what would be the 'composer way' to solve my case?
I'm in the process of committing a new sample network that illustrates how to do this. You can follow the pull request here:
https://github.com/hyperledger/composer-sample-networks/pull/66/commits/6bb0d757a0248046da60b013cfddbd7d549686b6

How to update a #ManyToOne relationship with Spring Data REST?

I use Spring Data REST with JPA. I have a User entity that has a many to one relationship with another called AccountStatus modeled in a separate RDBMS table. The JSON representation looks like this:
{
"id": "123"
"username": "user1",
"accountStatus": {
"id": "1",
"status": "Active"
}
}
The relationship in the User entity is:
#ManyToOne(optional = false)
#JoinColumn(name = "account_state")
#Getter #Setter private AccountState accountState;
Now I try to change the account status using a PATCH request on /users/123 and the payload:
{"accountState":{"id":0}}
But I get an error:
"identifier of an instance of com.domain.account.AccountState was
altered from 1 to 0; nested exception is org.hibernate.HibernateException:
identifier of an instance of com.domain.account.AccountState was
altered from 1 to 0"
I also tried to use #HandleBeforeSave/#HandleBeforeLinkSave to fetch the new AccountState from the repository and replace user.accountStatus with no success.
What am I doing wrong?
It really depends if you have an exported repository for AccountState. If you do you can update your account state with a PATCH against /users/{id}:
{
"accountState": "http://localhost:8080/accountStates/2"
}
So you are using the URI of your account state to reference the resource to assign

Laravel 5 Eloquent model dynamically generated at runtime

I am looking to make some sort of "GenericModel" class extending Eloquent's Model class, that can load database configuration (like connection, table name, primary key column) as well as relationships at runtime based on a configuration JSON file.
My reasons for wanting this are as follows: I'm going to have a lot of database tables and thus a lot of models, but most don't really have any complicated logic behind them. I've developed a generic CRUD API and front-end interface to interact with them. Each model has a "blueprint" JSON file associated with it that describes things like its attributes and relationships. This lets me automatically generate, say, a view to create a new model and it knows what attributes I need to fill in, what input elements to use, what to label them, which are mandatory, how to validate, whether to check for uniqueness, etc. without ever needing code specific to that model. Here's an example, project.json:
{
"db_table": "projects",
"primary_key": "projectid",
"display_attr": "title", // Attribute to display when picking row from list, etc
"attributes": {
"projectid": { // Attribute name matches column name
"display": "ID", // Display this to user instead of db column name
"data_type": "integer" // Can be integer, string, numeric, bool...
},
"title": {
"data_type": "string",
"unique": true // Check for uniqueness when validating field
},
"customer": {
"data_type": "integer", // Data type of local key, matches customer PK
"relationship": { // Relationship to a different model
"type": "manytoone",
"foreign_model": "customer"
},
"user": "autocomplete" // User input element/widget to use, queries customer model for matches as user types
},
"description": {
"data_type": "string",
"user": "textarea" // Big string, use <textarea> for user input
"required": false // Can be NULL/empty, default true
}
},
"views": {
"table": [ // Show only these attributes when viewing table
"customer",
"title"
],
"edit_form": [ // Show these when editing
"customer",
"title",
"description"
],
...
}
}
This works extremely well on the front end, I don't need any more information than this to describe how my models behave. Problem is I feel like I just end up writing this all over again in most of my Model classes and it seems much more natural to have them just pull information from the blueprint file as well. This would result in the information being in one place rather than two, and would avoid extra effort and possible mistakes when I change a database table and only need to update one file to reflect it.
I'd really just like to be able to do something like GenericModel::blueprint('project.json')->find($id) and get a functioning "product" instance. Is this possible, or even advisable? Or is there a better way to do this?
Have you looked at Migrations (was Schema Builder)? It allows you to programatically build models (from JSON if necessary).
Then you could leverage Eloquent on your queries...

Resources