2
votes

Regards,

Our problem is ‘a priori’ related to the GE implementation Orion Context Broker. Our version Orion Context Broker: 0.14.0.

We have a Web Service which we have implemented, sending data collected by a number of dispositives, to a machine that we have deployed in our account Fi-ware Platform. The problem that has been presented to us is that one of the attributes we are setting is a type attribute “coords” and when we are trying to make an update of the entity, does not allow us to update that attribute, and gives the following error (see below, a part of the response). We also want to update this field.

      </contextAttribute>
      <contextAttribute>
        <name>android_version</name>
        <type />
        <contextValue />
      </contextAttribute>
      <contextAttribute>
        <name>date</name>
        <type />
        <contextValue />
      </contextAttribute>
      <contextAttribute>
        <name>position</name>
        <type>coords</type>
        <contextValue />
          <metada>
            <contextMetadata>
            <name>location</name>
            <type>string</type>
            <value>WSG84</value>
          </contextMetadata>
        </metada>
      </contextAttribute>
    </contextAttributeList>
  </contextElement>
  <statusCode>
    <code>472</code>
    <reasonPhrase>request parameter is invalid/not allowed</reasonPhrase>
    <details>action:UPDATE - entity: (300000000000008, dispositivo) - offending attribute: position - location attribute has to be defined at creation time, with APPEND</details>
  </statusCode>
</contextElementResponse>

The REST request that we are setting to the ContextBroker and which is giving us problems is:

public static String payloadUpdateTemplate = 
                    @"<updateContextRequest>
                     <contextElementList>
                       <contextElement>
                         <entityId type='dispositivo' isPattern='false'>
                           <id>{0}</id>
                         </entityId>
                         <contextAttributeList>
                           <contextAttribute>
                             <name>temperature</name>
                             <type></type>
                             <contextValue>{1}</contextValue>
                           </contextAttribute>
                           <contextAttribute>
                             <name>latitude</name>
                             <type>φ</type>
                             <contextValue>{2}</contextValue>
                           </contextAttribute>
                           <contextAttribute>
                             <name>longitude</name>
                             <type>λ</type>
                             <contextValue>{3}</contextValue>
                           </contextAttribute>
                           <contextAttribute>
                             <name>altitude</name>
                             <type>m</type>
                             <contextValue>{4}</contextValue>
                           </contextAttribute>
                           <contextAttribute>
                             <name>acceleration</name>
                             <type>m/s²</type>
                             <contextValue>{5}</contextValue>
                           </contextAttribute>
                           <contextAttribute>
                             <name>android_version</name>
                             <type></type>
                             <contextValue>{6}</contextValue>
                           </contextAttribute>
                           <contextAttribute>
                             <name>date</name>
                             <type></type>
                             <contextValue>{7}</contextValue>
                           </contextAttribute>
                           <contextAttribute>
                             <name>position</name>
                             <type>coords</type>
                             <contextValue>{2}, {3}</contextValue>
                             <metadata>
                               <contextMetadata>
                                 <name>location</name>
                                 <type>string</type>
                                 <value>WSG84</value>
                               </contextMetadata>
                             </metadata>
                           </contextAttribute>
                         </contextAttributeList>
                       </contextElement>
                     </contextElementList>
                     <updateAction>UPDATE</updateAction>
                   </updateContextRequest>";

Yes, we have previously created the entity that we are trying to update, using updateContext operation with APPEND action type. The payload that we are using to do entity creation is:

public static String payloadInsertTemplate = 
                    @"<updateContextRequest>
                        <contextElementList>
                          <contextElement>
                            <entityId type='dispositivo' isPattern='false'>
                              <id>{0}</id>
                            </entityId>
                            <contextAttributeList>
                              <contextAttribute>
                                <name>temperature</name>
                                <type></type>
                                <contextValue>{1}</contextValue>
                              </contextAttribute>
                              <contextAttribute>
                                <name>latitude</name>
                                <type>φ</type>
                                <contextValue>{2}</contextValue>
                              </contextAttribute>
                              <contextAttribute>
                                <name>longitude</name>
                                <type>λ</type>
                                <contextValue>{3}</contextValue>
                              </contextAttribute>
                              <contextAttribute>
                                <name>altitude</name>
                                <type>m</type>
                                <contextValue>{4}</contextValue>
                              </contextAttribute>
                              <contextAttribute>
                                <name>acceleration</name>
                                <type>m/s²</type>
                                <contextValue>{5}</contextValue>
                              </contextAttribute>
                              <contextAttribute>
                                <name>android_version</name>
                                <type></type>
                                <contextValue>{6}</contextValue>
                              </contextAttribute>
                              <contextAttribute>
                                <name>date</name>
                                <type></type>
                                <contextValue>{7}</contextValue>
                              </contextAttribute>
                              <contextAttribute>
                                <name>position</name>
                                <type>coords</type>
                                <contextValue>{2}, {3}</contextValue>
                                <metadata>
                                  <contextMetadata>
                                    <name>location</name>
                                    <type>string</type>
                                    <value>WSG84</value>
                                  </contextMetadata>
                                </metadata>
                              </contextAttribute>
                            </contextAttributeList>
                          </contextElement>
                        </contextElementList>
                        <updateAction>APPEND</updateAction>
                      </updateContextRequest>";

We are using a REST Web Service. The literal {0} in the payload identifies each entity of the context. For example, if the ID of a dispositivo is 1111, the literal {0} will be 1111. In the other side, if the code of a sensor is 2222, the literal {0} will be 2222. The literal {0} is an identification key (unique and not null).

More information,

1) First of all, we insert a new entity with the following payload. The literal {0} is the ID of the entity, for example, id(entity) = 30000000000002. The literal {1} is the current value of the temperature of the entity Id, for example, temperature(entity) = 30,0.

  public static String payloadInsertTemplate = 
       @"<updateContextRequest>
           <contextElementList>
             <contextElement>
               <entityId type='dispositivo' isPattern='false'>
                 <id>{0}</id>
               </entityId>
               <contextAttributeList>
                 <contextAttribute>
                   <name>temperature</name>
                   <type></type>
                   <contextValue>{1}</contextValue>
                 </contextAttribute>
                      .
                      .
                      .
                      .
                 <contextAttribute>
                   <name>position</name>
                   <type>coords</type>
                   <contextValue>{2}, {3}</contextValue>
                   <metadata>
                     <contextMetadata>
                       <name>location</name>
                       <type>string</type>
                       <value>WSG84</value>
                     </contextMetadata>
                   </metadata>
                 </contextAttribute>
               </contextAttributeList>
             </contextElement>
           </contextElementList>
           <updateAction>APPEND</updateAction>
         </updateContextRequest>";

2) The result of the insertion operation is as follows.

  <updateContextResponse>
    <contextResponseList>
      <contextElementResponse>
        <contextElement>
          <entityId type="dispositivo" isPattern="false">
            <id>30000000000002</id>
          </entityId>
          <contextAttributeList>
            <contextAttribute>
              <name>temperature</name>
              <type></type>
              <contextValue />
            </contextAttribute>
                .
                .
                .
                .
            <contextAttribute>
              <name>position</name>
              <type>coords</type>
              <contextValue />
              <metadata>
                <contextMetadata>
                  <name>location</name>
                  <type>string</type>
                  <value>WSG84</value>
                </contextMetadata>
              </metadata>
            </contextAttribute>
          </contexAttributeList>
        </contextElement>
        <statusCode>
          <code>200</code>
          <reasonPhrase>OK</reasonPhrase>
        </statusCode>
      </contextElementResponse>
    </contextResponseList>
  </updateContextResponse>

3) We make the query and we can check the new values created with the payload.

  <queryContextRequest>
    <entityIdList>
      <entityId type='dispositivo' isPattern='false'>
        <id>{0}</id>
      </entityId>
    </entityIdList>
    <attributeList/>
  </queryContextRequest>

4) Then we are getting the value that we have introduced.

 <queryContextResponse>
   <contextResponseList>
     <contextElementResponse>
       <contextElement>
         <entityId type="dispositivo" isPattern="false">
           <id>30000000000002</id>
         </entityId>
         <contextAttributeList>
           <contextAttribute>
             <name>temperature</name>
             <type></type>
             <contextValue>30,0</contextValue>
         </contextAttribute>
             .
             .
             .
             .
         <contextAttribute>
           <name>position</name>
           <type>coords</type>
           <contextValue>36.723804, -4.417518</contextValue>
           <metadata>
             <contextMetadata>
               <name>location</name>
               <type>string</type>
               <value>WSG84</value>
             </contextMetadata>
           </metadata>
         </contextAttribute>
       </contextAttributeList>
     </contextElement>
     <statusCode>
       <code>200</code>
       <reasonPhrase>OK</reasonPhrase>
     </statusCode>
   </contextElementResponse>
 </contextResponseList>

5) Now we try to do the update of this data which we have introduced correctly (how you can check) and it gives the error.

2
Doubt: have you previously created the entity that you are trying to update (typically using updateContext operation with APPEND action type)? Which payload are you using to do such entity creation? Please, edit you post to include that information.fgalan
Doubt: I'm not familiar with the web service technology that you are using, but I guess that the {0} literal in the template is not the actual entity ID, isn't it?fgalan
Thanks for contributing your questions. We have already updated the initial question.TOPdigital

2 Answers

1
votes

This block means that you can't update a value of an attribute that not defined at creation time.

action:UPDATE - entity: (300000000000008, dispositivo) - offending attribute: position - location attribute has to be defined at creation time, with APPEND

If the location attribute was not defined at creation time you should use APPEND action to create that new attribute in your entity, also if this entity already created before.

Using APPEND instead of UPDATE you will be able to append new attributes to a previously created Entity.

After that be sure that you're replacing all curly braces to properly values.

1
votes

This seems to be an issue in 0.14.0 (and before). Fortunatelly, there are two easy workarounds to this problem:

  1. Use APPEND instead of UPDATE (note that APPEND on existing context elements has the same semantic than UPDATE).
  2. Remove the <metadata>...</metadata> for location given that once you have defined an attribute as location it is stored as such and you don't need to "repeat" the metadata in further updateCoxtext requests (you can check that with queryContext).

We will implement a fix in the next release (0.14.1). Thanks for the feedback!