BeanValidation for runtime derived constraint values - bean-validation

I would like to use jsr303 in place of current custom validation framework because of some features that the custom framework doesn't support yet, and I'm investigating if the jsr supports a certain usecase.
Say I have a loan offer field presented to customer on some front-end, and the field is pre-populated with a loan amount generated by the system based on the user's credit score, and the customer is able to take the whole amount or lower than the offered value (so not more than what was offered).
field:
#DecimalMin("1000.00")
#DecimalMax(onlyKnowAtRuntime)
private BigDecimal loanOffer;
offer = $20 000.00
customer inputs = $50 000.00
Because the credit score is runtime generated, we don't know what the max (#DecimalMax which in this case is $20 000.00) value will be at compile time, but we need to make sure we validate that the customer doesn't take over $20 000.00
What ideas do you have around such a problem?

Your suggested use case is not possible with the provided Bean Validation constraints. Really Bean Validation is more about describing static constraints.
Once could imagine, however, to write a custom constraints #MaxCreditExceeded. Writing a custom constraint is easy, the question is how to get hold of the current credit limit for the user. One approach could be to use a ThreadLocal. But that requires that the credit limit gets properly set and cleared into this variable.

Related

Can I pass in a dynamic price into my typeform?

I'm trying to pass in a price into my typeform, and trying to implement a short of a payment flow with Stripe integration. The samples I have seen for this all involve static, hard-coded pricing coming from the Typeform itself; I would like to pass in the price as a hiddenfield parameter and have that be the item that is charged.
However, I am having a lot of trouble seeing examples of how to implement this. Does anyone have any guidance?
I know how to pass in parameters into the form - but how to implement the dynamic pricing based on those parameters seems to be... not possible?
Would love any input. TIA.
Typeform supports natively Stripe payments in their form. It lets you accept payments via credit card easily.
Unfortunately, if you want your price to be dynamic, you can't pass directly it as a parameter of the typeform (called Hidden field).
If your price depends on a calculation, like the number of items, you can use the calculator feature (help center article).
And ask those questions to determine the price to pay.
Here is a simple form to order pizzas at different prices depending on the type.
Here is how it was made on Typeform:
first: Setup a different price per pizza type
second: Update the total price depending on the number entered
Hope it makes sense :)

How does HKWorkoutActivityType contribute to a HKWorkout?

When creating a HKWorkoutSession we need to provide a HKWorkoutConfiguration with a HKWorkoutActivityType.
There are many HKWorkoutActivityType available to use, but I don't find what is the application of it.
Does different type of activityType contribute different amount of totalEnergyBurned during the workout? or is it only used in querying the HealthKit for particular type of workout?
I am creating a general workout watchApp by which a user can just start and stop a workout to complete its rings. But I am confused by HKWorkoutActivityType. Will there be any difference in TotalEnergyBurned if I use different HKWorkoutActivityType, because it is contributing to close the red ring.
As far as I can tell, HealthKit needs to know the HKWorkoutActivityType so that the workout is listed properly in Apple Health. It does not automatically calculate the totalEnergyBurned or any other quantities used to characterize the workout:
Your app should always provide data for the workout’s duration,
totalDistance, and totalEnergyBurned properties when the data is both
available and relevant to the workout. In addition, you should provide
a set of associated samples that sum up to these totals.
From: https://developer.apple.com/documentation/healthkit/hkworkout
I do not know whether HealthKit validates whether a quantity is appropriate for a given type of workout, e.g. wheelchair "pushes" when swimming.

Writing the correct formula for SugarCRM

I am trying to automatically populate a field through a calculated field.
Just a quick background we distribute equipment with serials numbers. This equipment is sometimes returned. So some customers have multiple products each with different status of returned, shipped and installed.
I would like to transfer this serial number to a field on the contact through a calculated field only if the status is installed or shipped.
I have tried:
related($products,"serial"),",",(related($products,"status"))
and
related(contains(status,"installed)"products,"serial")
I need this for reporting reasons and would be greatly appreciated if you could help.
Thanks
You need a combination of ifElse and equal and related and or
As an example, the following Sugar Logic formula can be placed on a Contact record and will populate the field with the related account's name if the related account is of the type "Reseller." If the Account is of some other account_type then the field takes the value of "nope!"
ifElse(equal(related($accounts,"account_type"),"Reseller"),related($accounts,"name"),"nope!")
If you wanted to add another condition, or allow for another acceptable Account Type, build in an or
When you're writing lengthy Sugar Logic like this, I find it helpful to start writing it out with indentation using a text editor:
ifElse(
or(
equal(related($accounts,"account_type"),"Reseller"),
equal(related($accounts,"account_type"),"Investor"),
),
related($accounts,"name"),
"nope!"
)
In some versions of Sugar I've had to remove the extra spacing but it seems like in 7.2.2.0 at least the editor actually allows and preservers the formatting, which is a pleasant surprise.

Logic to Sell Memberships for Children Using Ubercart and Drupal

I'm sorry if this is not within the acceptable question guidelines for Stack Overflow, but I am feeling stumped, and I feel that what I'm trying to do might just be incredibly simple for some of the veterans here.
I've set up an Ubercart on a Drupal installation for a small gym website. What they are wanting is to allow a customer to register and pay for various memberships for their children (youth flag football, teeball, etc.). One person may come back and sign up multiple times throughout the year, and each customer may have multiple children who can each participate in multiple programs.
What I'm thinking is to disable anonymous checkout on Ubercart. The customer billing address will be the saved information for the "parent." I'm thinking that the parents could create Members (their children) which could be stored in a content type called Members and the Members could be linked to the programs of which they are a member via entity reference. The children could maintain their relationship to their parents by authorship.
I've been trying to work through this for the last few hours. Does anyone know of a way the I can accomplish this--maybe with rules? I'm thinking some kind of credit system in which for each quantity of a membership (per program) that they pay for, they get one "credit" to create one entity reference between a member and a program.
Any brainstorming and help on this topic would be majorly appreciated. Thanks.
Your use case sounds more like event registration than selling memberships. Each class would be an event that parents would register their children for. It may seem like overkill here, but I would use something like CiviCRM or RedHen CRM for this. Both support the concept of relationships between members and provide event management tools. You could make each class an event that people would sign up for, pay (they could even register multiple children at the same time) and get a receipt. The event history information would be stored so parents could sign in and see what each child has done. You could even make the list of kids in the class public so parents could see who else is in the class.
Afterward, it would be easy to put together a survey to send to the "attendees" to get feedback on the event/class and notify them about future events. I can think of a dozen different things that these systems cover that you may need in the future (early bird event registration, special pricing for returning parents/children, activity reports to email to parents every year so they can see what their children did...).
You may be able to pull together modules and custom content types (Ubercart Event Registration module as a starting point), but a CRM would provide the things you are looking for now, and the features your customer will be asking for in the future.

Database relations query

I have two database tables
this is a sample database of a Ticketing system.
Figure 1: Sample table of air ticket.
Figure 2: Sample table of tax.
Requirement:
When ticket is made from the interface, it has multiple taxes of different names every time.
How can I store this information i.e. 'n' number of taxes for each ticket with different names every time.
I have tried to make many to many relationship but the problem is:
For each ticket if the tax is not setup, then need to add the tax first.
Any optimal solution for this?
"the problem is: For each ticket if the tax is not setup, then need to
add the tax first."
This is not a real-life problem. In real life governments declare taxes well in advance of collecting them, This gives organizations sufficient time to amend their systems which need to handle taxes. Tax is never a surprise.
"But this is very tiring solution for the end user.... to make bunch
of tax setup for each ticket"
This sort of thing is reference data, and is the duty of the system developer (hint: that's you) to populate the reference data tables. Or at least provide a screen where the user can create or amend various taxes. This is a different function from defining a ticket type.
The Ticket Creation screen should have a drop-down list (or similar widget) displaying all the existing taxes, which allows the user to pick the relevant one(s). If you reall think it's necessary you can include a link to the Create Tax screen, but that really is a very confusing workflow.
If the commentators are correct, and this is a ticket purchasing function, then your design is seriously wrong. Sales taxes must be included automatically to the cost of the purcahse as part of the transaction. Otherwise nobody would pay any tax.

Resources