How to get timestamp for any attributes in Orion - fiware-orion

I've my context in Orion within multiple attributes;
how can I also get the attributes' timestamp ("modDate") via GET query?
Thank you so much

According with Builtin Attributes documentation (to which dateModified belongs):
Builtin attributes are not rendered by default. In order to render a specific attribute, add its name to the attrs parameter in URLs (or payload field in POST /v2/op/query operation) or subscription (attrs sub-field within notification).
So, in the case of GET, you have to use something like this:
GET /v2/entities?attrs=*,dateModified
The * is needed to include all the regular attributes. If you ommit it and use just ?attrs=dateModified you will get only dateModified and no other attribute.
EDIT: in the case you want to get not the entity dateModified attribute but the attribute dateModified metadata is similar. In this case, from Builtin Metadata documentation
Builtin metadata are not rendered by default. In order to render a specific metadata, add its name to the metadata URL parameter (or payload field in POST /v2/op/query operation) or subscription (metadata sub-field within notification).
So:
GET /v2/entities?metadata=*,dateModified

Related

Add attribute to multiple created entities with same id pattern

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).

How can I post the custom field to Workfront through workfront REST API

In workfront, we want to create a custom form(custom fields) for an Issue. How can I use Workfront REST API to do a POST request and create the custom fields in a custom form for that issue in workfront?
https://developers.workfront.com/api-docs/api-explorer/
You POST the same as you would to a system field. Simply prefix the field name with DE:.
attask/api-internal//user/xxxxxxxxx?DE:foo=bar
The above sets the field 'foo' to the string 'bar'.
If the custom field is not present on the object (not on a custom form already attached) then you will first need to attach one.
attask/api-internal/user/xxxxxxxxxx?updates={objectCategories:[{categoryID:`"customformUUID`",categoryOrder:0,objCode:`"CTGY`"}]}

Use MetdataId to find the Attribute Name of a deleted attribute

When I query the metadata using RetrieveMetadataChangesRequest, the RetrieveMetadataChangesResponse returns EntityMetadata and DeletedMetadata. The DeletedMetadata only returns the MetadataId.
Is there a way to get the metadata for the attribute without knowing the entity? Even just the attribute name would be fine.
RetrieveAttributeRequest I think only works if the attribute exists and if you have the entitylogicalname.
No, the only infomration available is the MetadataId.
Quoting from the SDK:
This collection is a dictionary of GUID values using a
DeletedMetadataFilters as a key. The GUID values represent MetadataId
values of the metadata items.
Looking at another part of the SDK specifically addresses this question:
You will also use DeletedMetadataFilters enumeration as a key to the
RetrieveMetadataChangesResponse.DeletedMetadata to filter the GUID
values found in the RetrieveMetadataChangesResponse.DeletedMetadata
property. When you design a metadata cache you will want to use the
MetadataId for each item so that you can identify deleted metadata
items and remove them.
So as a developer you are expected to populate a cache of metadata of interest to your application. You can query the CRM Metadata to find changes and deletes - but in the case of a delete you are responsible for having collected the metadata in your cache.

Reference an item by an identifier or a URL

We started to use the vocabulary from Schema.org and we are looking for a simple and effective way to reference an object by its identifier or a unique URL.
For example, in the Organization type there is a property employee which refers to Person. We would like to be able to refer to it using a unique identifier instead of the whole object.
What would be the best solution according to Schema.org?
If the Person (resp. the name-value pairs) is defined on the same page, you could use the itemref attribute, containing reference to the id(s):
Elements with an itemscope attribute may have an itemref attribute specified, to give a list of additional elements to crawl to find the name-value pairs of the item.
With Microdata’s itemid attribute you can specify a URL that identifies an item.
However, Microdata requires that vocabularies explicitly specify support of itemid, which Schema.org hasn’t done yet.

In Tastypie is there a way to change a resources excludes based on the authentication?

Consider the example of a user resource that has profile pic and email fields. Where any user may see any other users profile pic but a user may only see their own email address.
Is it possible to setup tastypie so that the set of excluded fields can be varied based on the authenticated user?
I realize that an alternative approach is to create separate full and restricted user resources. But for the moment I just want to know whether the approach of limiting the fields based on user authentication is even doable in tastypie.
Also it doesn't have to be the excludes, in the same vein is there a way instead to change the fields property based on the requesting user?
I dont think excluded fields can be brought back into the picture in an elegant fashion. You could probably manipulate the object list based on the request using some object manipulation by including the get_object_list in your resource
But it would be much better and more logical for you to use the apply_limits method in your custom authorization class.
Yes there is a way to do it.
If you define email to be a separate field, not the one of the User(might work and with that but never did it).
You can define dehydrate_email where the bundle.request contains the current request and you could get it. It won't be exactly excluded as a field but it will be None for others.
I created a ModelResource subclass that can be multiple inherited into the required ModelResource instances. Like:
class ResourceThatNeedsToExcludeSomeFields(ExcludeResource, ModelResource):
pass
It takes in the fields to be excluded via GET parameters (like "&exclude=username")
class ExcludeResource(ModelResource):
"""
Generic class to implement exclusion of fields in all the ModelResource classes
All ModelResource classes will be muliple inherited by this class, whose dehydrate method has been overriden
"""
# STACK: How to exclude some fields from a resource list created by tastypie?
def dehydrate(self, bundle):
# I was taking the exclude fields from get paramaters as a comma separated value
if bundle.request.GET.get('exclude'):
exclude_fields = bundle.request.GET.get('exclude').split(',')
for field in exclude_fields:
if str(field) in bundle.data.keys():
del bundle.data[str(field)]
return bundle
You can modify this to get the exclude fields based on user group (or whatever criteria you base the fields on) like this:
class ExcludeResource(ModelResource):
"""
Generic class to implement exclusion of fields in all the ModelResource classes
All ModelResource classes will be muliple inherited by this class, whose dehydrate method has been overriden
"""
# STACK: How to exclude some fields from a resource list created by tastypie?
def dehydrate(self, bundle):
exclude_fields = <get a comma separated list of fields to be excluded based in bundle.request.user>
for field in exclude_fields:
if str(field) in bundle.data.keys():
del bundle.data[str(field)]
return bundle
However, this snippet will not work for related resources specified with "full=True"