Corda Node vs Party Clarification - blockchain

Newbie alert and just finished the Corda Bootcamp videos and a few exercises.
Something that's unclear to me is: From the minimalistic "standalone" examples, I see that that Node=Party=Single JVM Process.
Is this the way it has been designed? From going through examples, it appears to me that a Party is a person (who is identified by a certificate) and part of the network.
If we model a Party to be a Node, then how can this be dynamic (where persons could join the network at realtime)?
Also, is it crazy to model Party as a department in an organisation (like below)?
For an imaginary example:
PartyA = Human Resources Department
PartyB = IT Department
PartyC = Finance Department
PartyD = Executives
Each of these departments transact with each other (in terms of a Person's payroll record, Project financials etc).

You are correct that a single Party is a Node and thus is a Single JVM Process. Each party represents one node. Adding/Onboarding a node will require the process of requesting/signing with a doorman/CA.
You could represent departments by each party which in turn becomes a node on its own. Or you could let it be a single node and control the permissions of the departments at the app level.
There's something in the roadmap for a node to represent multiple parties but that's still far off in the future. https://groups.io/g/corda-dev/message/469

Related

I need help properly implementing a booking scheduler and availability in Django

This question has been asked many times before on StackOverflow and in the Django forums, but none of the answers I've found are appropriate or complete enough for my situation.
First, the brief:
I'm creating a web application for a car rental business. In addition to helping them organize and centralize their fleet, it will also help them collect orders directly from customers. As with most rentals, the logistics of it all can be somewhat confusing.
Someone may place an order for a car today (December 12th) but actually take the car over the Christmas to New Year's period.
A renter may borrow a car for just two days, and then extend the booking at the last minute. When this happens (often very frequently), the business usually has to scramble to find another one for a different customer who was scheduled to get that car the next day.
Adding to that, an individual car can only be rented to one client at a time, so it can't have multiple bookings for the same period.
Most answers advocate for a simple approach that looks like this:
models.py
class Booking(models.Model):
car = models.ForeignKey(Car, ...)
start_date = models.dateField(...)
end_date = models.dateField(...)
is_available = models.booleanField(default=True)
forms.py
import datetime
from django import forms
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
from . import models
class PlaceOrderForm(forms.Form):
"""Initial order forms for customers."""
start_date = forms.DateField(help_text='When do you want the car?')
end_date = forms.DateField(help_text='When will you return the car?')
def clean_data(self, date):
data = self.cleaned_data(date)
# Check that start date is not in the past
if data < datetime.date.today():
raise ValidationError(_('Invalid date: Start in past.'))
# Ensure that start date is not today (to avoid last_minute bookings.)
if data == datetime.date.today():
raise ValidationError(_('Invalid date: Please reserve your car at least 24 hours in advance.'))
return data
cleaned_start_date = clean_data(start_date)
cleaned_end_date = clean_data(end_date)
('_' is for )
The booking has a start_date and an end_date. When a current date is within the start_date and end_date, the car is marked as unavailable. If the boolean field is_available (not represented in forms.py above) is set to "False", the car is unavailable completely.
Again, because of the unique nature of car rentals, this may be a problem. Some people book a car for six months, and others book it for two days. If someone wants a long-term rental but there's another short interlude during their expected duration, this validation would prevent them from placing the order completely!
But this is a problem: Going back to the rental model, someone may be booking a car in the future. A car that's unavailable now should still be able to be reserved for a future date.
Adding to that, an individual car can only be rented to one person at a time, so it can't have multiple bookings for the same period. Again, because of the unique nature of car rentals, this may be a problem. Some people book a car for six months, and others book it for two days. If someone wants a long-term rental but there's another short interlude during their expected duration, this validation would prevent them from placing the order completely!
So if a conflict arises, rather than blocking the booking entirely (which, again, would be a bad UX decision), it should notify the business so they can assign another car and plan ahead.
Other clients should not be able to book it for the time in which it is borrowed, but they should be able to book it for other times when it is free.
So if someone places an order now for, let's say the 24-31st of December. Those days should be blocked off. However, another person should be able to book it from today to the 23rd, and from the 31st onwards. And if the person renting it should extend, it should notify the rental business so they can assign another car to the user well in advance.
Possible idea to move forward
The core assumption in all those answers is that the booking unavailability has to be handled in Django itself, in the backend. However, I'm building this project with REST framework, and will use a Js based front-end (currently learning Javascript for this purpose).
I think that this would be better handled in a more holistic way with the in-built form validation and save functions.
The workflow would go something like this:
The User selects a car and selects the start and end dates from a drop-down calendar on the website.
The form will then check to see if the absolute basic checks (can't book a car in the past) are fine. If those work, then the order is placed and saved in the database.
If there's a scheduling conflict, the order is not blocked, but passed to the business that can assign them a different car for the period. (Generally, people don't care much for receiving particular cars--mostly the price, space and the fuel economy. Everything else is interchangeable.
Once that happens, the deposit can be collected, and the order can be set in the system.
Anyhow, that's my preliminary idea that would bring together the best of all worlds
and create a great experience for both the business and customer.
So my question is: How could this actually be set up? What would need to be on the front-end and what would go in the back-end? I'm learning programming as I go, so this may be simple, but I've been struggling with this for a week, I would appreciate any help on this!
Thanks!
Sounds like you have two processes - the customer order and the car assignment. You need to plan out your data structure and then your process flow. This will help you get things straight before you start.
Models
Using (Brackets) for foreign keys, Customer_order collects things like:
Customer(User)
desired_start_date
desired_end_date
car_type - this could be many fields
A car model
car_type
rental (many to many Rental with through table Rental)
A rental model
car (Car)
customer_order(Customer_order)
start_date
end_date
We have kept the rental model with its own start and end dates as the user may change their desired period but it shouldn't change the rental dates without checking if others exist in that time period for that car.
So the flow should go:
user passes js validation and form submitted to backend
backend checks for car availability based on type and dates
if available, creates rental
if not available, alert user and passes to staff
if a user changes a rental period (via an edit screen for existing customer_orders)
backend checks for same car availability based on existing rentals
if not available, alert user and pass to staff
You'd also create a staff only view, that lists customer_orders that can't be matched (without rental models) along with cars of the requested type that don't have rentals for that period.
Seeing as you have that view, it strikes me your backend process could use something similar to also look for and assign a different car of the same type automatically if you wanted to extend the availability check process, notifying staff it has occurred, while only referring back to staff if that type of car is unavailable.
Actually programming all this is left as an exercise for the reader.

How can i run class from Prestashop WebService

So here is my problem.
I have a class created that extends AdminProductsControllerCore.
What it does is if you have one product that you want to split in 3 different products but have the same stock, it will have 1 master and 2 slaves.
For example:
You have reference - N101 that has stock 100, but you want to have 3 products with different reference N100FR and N100DE.
What the new class does is that if you link the 3 products, all will have the same stock. As soon as you change the stock for one, it will also change it for the other 2.
We also have a connection to a fulfillment system that manages the warehouse stock. This means that the Fulfillment software is connected through WebService to Prestashop and every change in the Fulfillment system to the stock is being sent to Prestashop. This also works very good.
Also to be noted that in the Fulfillment software we have multiple systems linked to import orders, not just prestashop so it means that some orders are never in prestashop, but the stock drops.
Now comes the problem:
If i manually (or by new order) change the stock in Prestashop, all products change qty to the new value.
But if the qty changes in the Fulfillment system, only the master sku changes stock in Prestashop.
So this actually means that the new class that changes the stock when it's manually done in Prestashop (or by creation of new order) does not work.
My question is how can i make it that when the stock is changed, that the class that i created will run?
If there is need for more details, please let me know.
Thanks in advance.
Stock update does not trigger a full product object update.
I guess your fulfillment system is calling the stock_available resource,
so one possible solution is to override the updateWs() method
to make sure your code is executed there too.

Conditional Expression on multiple models

Background:
My customer's shop has Internet wifi for customer and also his staff.
Shop owner would like to visualize the heatmap of his shop in order to arrange the desk and furniture for sake of convinient.
Schema:
https://gist.github.com/elcolie/7bb56c286afacadff63eccae94bda713
Goal:
1. I want to determine mac address to be a pin_value
Constraints:
1. One mac can has many imc(username). Public computer serves many customer
2. One imc can has many pin_value. Customer got promote his pin
3. imc does not need to has pin_value. Staff account has no pin_value
4. mac does not need to has imc. May be somebody their just passing by without turn off his wifi
Question:
How do you use conditional expression to do single query and get mac:pin_value?
My poor solution is brute-force search which is very slow.
Location model has record per day is about 100k rows.

How to decide dynamic work flow for a set of model?

Let consider we have 3 roles, Manager, Admin, Superadmin.
Sequence of transactions should happen like t1->t2->t3->t4.
If any employee belongs to Manager role , his transaction should happen t1->t3->t2
If any employee belongs to Admin role , his transaction should happen t1->t2->t4
If any employee belongs to Supreadmin role , his transaction should happen
t1->t2
In django how to define this dynamic workflow? So on request of employee this process should follow based on there Role.
Thank you in advance.
Generally, that sample is about non-dynamic workflow. All nodes instances counts are known at the moment of workflow definitions.
If you think about the flow from the process modeling side, visual representation and explanation to a non-technical user, the flow would be modeled as following BPMN diagram that not a far away from the textual specification:
So this directly could be translated into the viewflow class definition, where django views for the same tasks could be reused over different flow nodes, ex:
class MyFlow(Flow):
start = flow.Start(ViewT1).Next(check_role)
check_role = (
flow.Switch()
.Case(this.user_t2, cond=lambda act: act.process.created_by.role=='USER')
.Case(this.admin_t2, cond=lambda act: act.process.created_by.role=='ADMIN')
...
)
user_t2 = flow.View(ViewT2).Next(this.user_t3)
admin_t2 = flow.View(ViewT2).Next(this.admin_t4)
...
Ability to have the code that looks pretty same as the textual and visual specification the main value of the viewflow library. To do that for some cases you will need to create your own flow nodes. In the viewflow samples, you can find a dynamic split node that show how to be, if the nodes instance counts are unknown at the design time.

NoSQL Race Condition

I'm trying to figure out how companies that use nosql database solve this general nosql race condition issue:
Lucky example: User and Product. Product has quantity of 1 and there are 2 users. When the first user tries to buy this product, system first checks whether quantity is > 0 and it is indeed > 0, proceeds to create a Transaction object and decrement quantity of product. The second user tries to buy the product, system rejects as quantity isn't > 0.
Unlucky: Both users try to buy the product simultaneously. For both, system confirmed quantity is > 0 and so created a Transaction object for both users, hence destroying the company image next day...
How to generally deal with this common scenario?
From similar cases i found on the net, one suggested solution is to use request queue, and process the request one by one. However, if all transactions are queued, and you're running business like Amazon (millions of transactions every now and then), how do we expect users to know whether or not their purchase succeeded shortly after they clicked that purchase now button?
One of the ways to solve this problem is to allow both users to order products simultaneously.
Then there are two possible situations:
One of the users doesn't finish a transaction (refuses to pay, closes a browser window etc). Then another one will have the requested amount of a product.
Both users finished their transactions. Then you will get a random user your product and say sorry to another one giving away a coupon with $10 to him/her.
The second situation should happen extremely rare. So you won't blow out all your money on coupons and your users will be happy whatever the outcome. But you still need to monitor the 2nd situation in order to react and make changes to your system if it happens more often than you expected.