Add attribute to multiple created entities with same id pattern - fiware-orion

I didn't found in documentation or source code the specifications to add attribute to multiple created entities with same id pattern. Only found the method for add attr to entity one by one (with array), but this method doesn't work (lazy method) when need add attribute to 100+ entities with id pattern (idIot:1, ... , idIot:N).
Any help?

The NGSIv2 method that allows to update several entities at once is POST /v2/op/update. It uses as parameter an array of entities:
entities, an array of entities, each entity specified using the JSON entity representation format (described in the section "JSON Entity Representation").
and in the cited "JSON Entity Respresentation" section we have:
An entity is represented by a JSON object with the following syntax:
The entity id is specified by the object's id property, whose value is a string containing the entity id.
The entity type is specified by the object's type property, whose value is a string containing the entity's type name.
Entity attributes are specified by additional properties, whose names are the name of the attribute and whose representation is described in the "JSON Attribute Representation" section below. Obviously, id and type are not allowed to be used as attribute names.
Thus, in conclusion, you cannot use a pattern of entities to update.
However, this has an easy workaround: you can create a script (or logical function in a wider program) to do that work, basically:
To query Orion with a given pattern, getting a set of entity (taking into account pagination, if the number of entities is large).
To update all these entities with POST /v2/op/update (taking into account doing it in batches, as there is a limit of 1MB in Orion request, if the number of entities to update is large).
You can have a look to this script, which works in this way (although in this case is to delete a set of entities instead of updating an attribute).

Related

Persisting value objects in Typo3

I've got a Money class that extends AbstractValueObject with the properties $amount (int) and $currency (string). And I've got an AbstractEntity with a $price property holding an instance of Money. How do I get Typo3 to persist that value object? How do I define the mapping?
Coming from Doctrine, I'd expect it to be persisted in two columns price_amount and price_currency.
Extbase does things a bit differently - so value objects needs to be stored in their own tables and relations between objects are stored by using identifiers just like entities.
The only real difference between Entities and VOs is that the persistence manager will use property values (except the identifier field) when looking for VOs for persistence whereas the identifier will be used on Entities.
So you need to add the database schema for the value object to ext_tables.sql and as the table should contain an auto incrementing uid field as well as the fields you need for your VO. Ensure that you create a combined unique index on the amount and currency columns.
Define the TCA mapping and then you can persist value objects either directly if you create a repository or by attaching them to aggregate root objects and persisting these.
The price property on your entity should be an integer in the database schema, as extbase will either store a reference to the uid of the VO (if you only refer to one Money object on your entity) and if you wish to store a collection of Money objects, Extbase will store the number of relations between your entity object and the Money VOs.

How to find entity with any value of argument

I'm using Spring JPA with hibernate and have an entity with a lot of properties, let's say it has five; as illustrated below:
#Entity
#Table
public class MyEntity{
Object properties1;
Object properties2;
Object properties3;
Object properties4;
Object properties5;
}
Spring provides a very nice feature; it generates JPQL query based on method name in the repository. For example:
List<MyEntity> findByProperties3(Object properties3);
In my situation, users have an html form to search for a MyEntity. This html form has five fields respectively which correspond to the five properties on the MyEntity class. User also can leave any field empty so that the search will include all values of this property in the query.
I have idea of how to implement that but it would break away from the Spring convenience methods and need a lot of coding. My idea is to create a method on the repository interface for all possibilities: user leaving all field empty, filling one field, two fields, etc; up to five fields. Unfortunately, that means that there would be:
possibilities. How can I avoid this path? Ideally, I would create just one method:
List<MyEntity> findByProperties1andProperties2andProperties3andProperties4andProperties5(Object p1,Object p2,Object p3,Object p4,Object p5)
But, if some of the pXs are null, then Spring JPA will explicitly find MyEntitys with propertiesX equal to null, as opposed to all possible values of, say, 1, 2, 3, 4, 5 and null.
===========EDIT===============
I am still hoping to get an answer from someone about a Spring JPA solution, but I've used javax.persistence.criteria.CriteriaBuilder in the mean time for my solution.

EntityFramework inheritance - Ignore not nullable column

I have an one entity in my edmx model having an one property that can contains huge XML data.
Basically I want to load this entity without this property (column) /* huge data loading */ . And load this column only when it is strictly needed.
I have tried to create an inherited entity containing this property and remove this property from base entity (original entity). I have done mapping.
At this time I have problem, that during compilation a I get error, that base entity is not capable to insert and update itself, because property is not nullable
I am looking for best approach (solution) how this situation should be solved.
I am attaching the cut-out from my emdx designer (containing my current and desired situation)
UPDATE:
I will try to write a procedure that I have tried:
I mapped functions to my custom functions. For entity TRP_TechReport_T without the XML column (property). Then I just mapped for entity TRP_TechReport_T functions to my custom function (containing XML column).
Then I set Mapping condition on the entity TRP_TechReport_T: When TRP_XML = Empty.String
TechReport_T mappings:
TechReport_T functions:
TechReportFull_T mappings:
TechReportFull_T functions:
At this moment I get error:
Error 2 Error 3032: Problem in mapping fragments starting at line 3754:Condition member 'TRP_TechReport_T.TRP_XML' with a condition other than 'IsNull=False' is mapped. Either remove the condition on TRP_TechReport_T.TRP_XML or remove it from the mapping.
The column is not nullable in the database and mustn't be.
I can hard-set XML property to nullable, but in the case of the model updating from the database information will be lost.
At the moment it's the only thing I could think of.

Entity framework 4 model first using money value object

I want to use a Money value object in my application. I have found several examples of a Money datatype. But I can't figure out how to use them with EF4. I would like to store each amount as a Decimal/CurrencyCode pair (where currencycode is a string - "USD", "SEK", etc) in the database. I tried creating a complexType but I couldn't get that to work. Is this possible?
It should be definitely possible. Your complex type is just pair of decimal and string property. It is exactly what complex type are used for. Depending on your approach you must do:
Database first:
You will define your database first. Your table will contain money and varchar columns representing your new type. When you update your EDMX model from database it will include it as scalar properties to your entity. You must remove those properties. Then go to model browser and create new complex type. Return back to entity and add complex property of your new complex type. And at the end you must go to entity mapping and map your complex type to those database columns.
Here is basic tutorial from MSDN but from unknown reason they didn't include such elementary details like screenshots. Here is some video from channel9.
Model first:
This is similar to database first but you don't have to deal with database creation and mapping. It will be generated for you.
Code first (EF 4.1):
You must create separate class for your complex type and use it as property in your entity. You should not need to map it by default - mapping should be infered. If it doesn't work you can map complext type either by using ComplextTypeAttribute annotation or by defining mapping in DbModelBuilder.
I can further extend approach you need to use if you provide more details.

Access the property used in mapping entity to a table in EFv4

When we have two entities in EFv4 EDM diagram and only one table for both in the database (for instance, having table Documents and entities Invoice and Qoute), table Documents having documentTypeId column as a discriminator and set this column as a discriminator in the EDM (in Table mappings), how do we read the value of this property in our code?
We cannot assign values to it because EF does it for us under the hood (based on what we entered in Table mappings for condition) but somehow I don't get it why we are also not allowed to read it.
Imo this property is already mapped so you can't map it again. It is used to determine type of materialized entity. Why do you need such column. Usually it is enough to use is operator like:
var document = context.Documents.GetById(id);
if (document is Invoice)
{
...
}
If you only need to select subtypes you can use OfType extension method like:
var invoices = context.Documents.OfType<Invoice>().ToList();
You also don't need to set this value when adding new entity because you are adding subtype - Invoice or Quote.
Edit:
As I understand from your comment you don't need this information in query. In such case you don't need to map it. Simply use partial class of your entity and add custom property which will return your string. Sound like stupid solution but actually it would be the easiest one.
Discriminator column should be part of mapping metadata so in case of T4 template generating your entities, it could be possible to update the template so it generate such property for you.
You may want to use a single-table inheritance hierarchy, as described here.
That way, you could have an abstract Document class that includes a DocumentTypeId column. Invoices and Quotes would extend this class, but specify certain DocumentTypeId filters. However, because the original class has a DocumentTypeId column, they would each have that column as well.
Another advantage to this approach is that you could create utility methods that can act on any Document, and you could pass any Invoice or Quote to these methods.