FIWARE Orion CB subscription conditions - fiware-orion

Is there a way to use exceptAttrs in the attributes of the condition field in a subscription, like we can in the notification field?
For example, lets say I have an entity with attributes A,B,C,D,E and I don't want to get notified when D changes. (apart from putting only A B C E in the condition)

Related

GWT Requestfactory 3 nested object

I have a GWT application with Requestfactory. On the serverside I have a service returning a triple nested object. A contains a List<B> #B. Each B contains a C.
When I fire my request to findAll(A).with("B","C").fire(receiver) it only returns B values. C is null. In debugging I see that up to the DAO the A object is properly set with all values.
(Clientside all extend EntityProxy)
Right now I need to fire seperate requests to get C for every B selected in the list of A. Which means more back and forth...
Thanks
If A contains B, you need .with("B"). If A contains C, you would add "C" to that call, but since B contains C, you instead add "B.C":
findAll(A).with("B","B.C").fire(receiver)
Real world example: Person (A) has Address (C), and Person has Employer (B), and Employer also has Address (C). You were asking RequestFactory to send Person, their Employer and the Person's address, but not the Employer's Address.

What is the intended way to increment or decrement a counter value, using Spring 4 data jpa with repositories?

Given the following scenario:
A shop sells products A, B and C.
The stock amounts are A := 100, B := 100, C := 100
A shopping cart contains 50 A, and 80 B
We have a business service providing a checkout(ShoppingCart cart) method. This method shall do two things transactional:
Persists the shopping cart
Reduce the shop stock according to the amount of products
So in our example, after checkout, we want the shop stock to be A := 50, B := 20 and C := 100.
We currently use two repository methods to do so:
CartRepository.save(ShoppingCart cart)
and, for each contained product ShopStockRepository.incrementStock(productId, -1 * amount of product)
incrementStock is implemented as a custom update query using the #Modifying and #Query annotations. The Query uses an UPDATE SET statement that decreases the shop stocks for the related item.
Unfortunately it turns out, that the database is correctly updated but the shop item object is not refreshed.
Using integrations tests, we found out, that if we inject the EntityManager to the checkout service and advise it, to refresh each product manually, that everything seems to works. But is this the correct way to handle this kind of incremental update???
An alternative, that we could think of, is to read the product, update the value and save it back, But wouldn't this lead to race conditions? Would we have to implement some sort of locking?
Hope you can help, we're struggling with this for days :-/
Marius
What you are doing is correct, but if you want the value to be updated next time you fetch the entity you need to add #Modifying(clearAutomatically = true).
For example
public interface UsersRepository extends JpaRepository<Users, String> {
#Modifying(clearAutomatically = true)
#Query("update #{#entityName} u set u.sent = u.sent + :sentIncrement, u.receipts = u.receipts + :receiptsIncrement where u.id = :id")
int incrementSentAndReceipts(#Param("id") String id,
#Param("sentIncrement") int sentIncrement,
#Param("receiptsIncrement") int receiptsIncrement);
}
The downside is that every time you execute that query, the first level cache will be cleared and you'll force hibernate to go to the database to refresh the data.

Entity Framework - best practice to get count

I have a Customer table and another Orders table. Each Customer can have many orders (One to many relationship).
I want to get a Customer object and from it get how many orders he has (the actual order data is not relevant at this point). So as I see it I have 2 options:
create a view with another OrdersCount field - and that will be another object in my system.
in my app, when I need the count get the Customer.Orders.Count - but for my understanding that will cause an extra query to run and pull all the orders from the database to that collection.
Is there a correct way to do such thing?
Thanks
You do need a new type, but you don't need to recreate all relevant properties.
from c in context.Customers
// where ...
select new {
Customer = c,
OrderCount = c.Orders.Count()
}
Update code that looks for e.g. the Name property of an item in the result, to look for Customer.Name.

Make a record in one Entity Inactive when a value is changed in another Entity of the same record in crm 2011 on-premise

I have two entities, Bookings and Discharge.
When a record is created in Bookings, it automatically creates a record in Discharge. Discharge
has an additional field that is a drop down with four options.
I want a functionality where when any one of the values in drop down is chosen, the similar record in Bookings
should shift from "Active" view to a default view which I have created by the name of "Processed" in Bookings.
What I have in mind is to create a hidden field in Bookings that is populated when I choose one of the options from Discharge drop down and based on that field the record should shift the view in Bookings. But how do I populate the hidden field? Workflow is not giving me that option or maybe I am doing something wrong.
Help?
So I have created a 1:N relationship between Booking and Discharge. The field is updated in Booking based on the field in Discharge and I choose the particular record in Booking from the look up field in Discharge. But I want to get rid of this second step. I don't want to choose the record in Booking entity but directly update it from Discharge. There are some fields and their values common in both forms, can I create a relationship based on that?
Regarding the first part of your question
"What I have in mind is to create a hidden field in Bookings that is populated when I choose one of the options from Discharge drop down and based on that field the record should shift the view in Bookings. But how do I populate the hidden field?"
If the field is not on a form you can't set its value hence the following:
I don't believe you can set a hidden field using a workflow. However there is a 'visibility' option on the form designer.
I suggest you add your "hidden" field to the form. Then double click on it and toggle the "Visible by default" checkbox. This will hide the field from the user.
You can then set the value of this field using a workflow.
Regarding part two of your question
I don't want to choose the record in Booking entity but directly update it from Discharge. There are some fields and their values common in both forms, can I create a relationship based on that
You have a 1:N relationship however you want to set the related Booking Dynamically is this correct? You cannot select a Booking in the lookup field based on criteria from a workflow. You would need to use a plugin.
If the Discharge has a related Booking (the Booking lookup on Discharge is already set) then you can use a workflow to either:
1) Set a field value (Using 'Update Record' in the Workflow steps) in the parent Booking
2) set to Inactive (Using 'Change Status' in the Workflow steps) in the parent Booking

Handling Many to Many - Entity Framework

I have an MVC app I am building as a learning project. I have a table with Payees, and a table with Categories. Certain Payees can make transactions of certain categories. For example, Payee A can make payments to Categories A, B and C. Payee B can maybe payments to categories B, C and D.
So, I have a PayeeCategory linking table, with a PayeeId and a CategoryId.
So see the categories the payee can make transactions against, it's a simple Select from PayeeCategory where PayeeId = this.PayeeId. And I join to the Category table to get the category names.
In the view, when I edit a Payee, I need to display a list of all categories, and and allow the user to select or unselect the categories that the current Payee is associated to.
So, in my ViewModel, I'd have a list of categorySelectableItems, which has maybe the CategoryId, the DisplayName and a Selected boolean field. To get the data, I need to Select from Categories, LEFT JOIN PayeeCategory, and where PayeeCategoryId is null, set the Selected to false, else true.
How would I do that ina single Linq statement?
Then, when the data comes back... how would I save the data? Would I have to delete all the relationships, and then re-add them based on the List<> values I get back?
Hope someone can guide me.
This was answered in a different question.
Linq query assistance