• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

telefonicaid / fiware-orion / 44567853743

19 Nov 2026 04:35PM UTC coverage: 80.454% (+0.07%) from 80.389%
44567853743

Pull #4833

github

web-flow
Merge cbe77c68c into b19aa55ec
Pull Request #4833: Add `contextReferences` to custom notifications to include referred entities in the JEXL context

21484 of 28268 branches covered (76.0%)

Branch coverage included in aggregate %.

197 of 210 new or added lines in 9 files covered. (93.81%)

21 existing lines in 1 file now uncovered.

17517 of 20208 relevant lines covered (86.68%)

56764.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

67.69
/src/lib/apiTypesV2/ContextReference.cpp
1
/*
2
*
3
* Copyright 2026 Telefonica Investigacion y Desarrollo, S.A.U
4
*
5
* This file is part of Orion Context Broker.
6
*
7
* Orion Context Broker is free software: you can redistribute it and/or
8
* modify it under the terms of the GNU Affero General Public License as
9
* published by the Free Software Foundation, either version 3 of the
10
* License, or (at your option) any later version.
11
*
12
* Orion Context Broker is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
15
* General Public License for more details.
16
*
17
* You should have received a copy of the GNU Affero General Public License
18
* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/.
19
*
20
* For those usages not covered by this license please contact with
21
* iot_support at tid dot es
22
*
23
* Author: Orion dev team
24
*/
25
#include <string>
26
#include <vector>
27

28
#include "logMsg/logMsg.h"
29
#include "common/JsonHelper.h"
30

31
#include "apiTypesV2/ContextReference.h"
32

33
#include "mongoBackend/dbConstants.h"
34

35
#include "mongoDriver/BSONObj.h"
36
#include "mongoDriver/BSONElement.h"
37
#include "mongoDriver/BSONObjBuilder.h"
38
#include "mongoDriver/BSONArrayBuilder.h"
39
#include "mongoDriver/safeMongo.h"
40

41

42

43
namespace ngsiv2
44
{
45
/* ****************************************************************************
46
*
47
* ContextReference::toJson -
48
*/
49
std::string ContextReference::toJson()
14 ✔
50
{
51
  JsonObjectHelper jh;
14 ✔
52

53
  jh.addString("id",   this->id);
28 ✔
54
  jh.addString("type", this->type);
28 ✔
55

56
  return jh.str();
28 ✔
57
}
14 ✔
58

59

60

61
/* ****************************************************************************
62
*
63
* contextReferencesFill -
64
*/
65
void contextReferencesFill(const orion::BSONObj& bo, std::vector<ContextReference>* crV)
898 ✔
66
{
67
  crV->clear();
898 ✔
68

69
  if (!bo.hasField(CSUB_CONTEXT_REFERENCES))
1,796 ✔
70
  {
71
    return;
879 ✔
72
  }
73

74
  orion::BSONElement be = getFieldF(bo, CSUB_CONTEXT_REFERENCES);
57 ✔
75
  if (be.type() != orion::Array)
19 !
76
  {
NEW
77
    LM_E(("Runtime Error (csub contextReferences field must be Array but is %s)", orion::bsonType2String(be.type())));
×
NEW
78
    return;
×
79
  }
80

81
  std::vector<orion::BSONElement> crElements = be.Array();
19 ✔
82
  for (unsigned int ix = 0; ix < crElements.size(); ++ix)
51 ✔
83
  {
84
    if (crElements[ix].type() != orion::Object)
32 !
85
    {
NEW
86
      LM_E(("Runtime Error (csub contextReferences item must be Object but is %s)",
×
87
            orion::bsonType2String(crElements[ix].type())));
NEW
88
      continue;
×
NEW
89
    }
×
90

91
    orion::BSONObj   crObj = crElements[ix].embeddedObject();
32 ✔
92
    ContextReference cr;
32 ✔
93

94
    cr.id   = crObj.hasField(CSUB_ENTITY_ID)?   getStringFieldF(crObj, CSUB_ENTITY_ID)   : "";
192 !
95
    cr.type = crObj.hasField(CSUB_ENTITY_TYPE)? getStringFieldF(crObj, CSUB_ENTITY_TYPE) : "";
160 !
96

97
    crV->push_back(cr);
32 ✔
98
  }
32 ✔
99
}
19 !
100

101

102

103
/* ****************************************************************************
104
*
105
* contextReferencesToBson -
106
*/
107
orion::BSONArray contextReferencesToBson(const std::vector<ContextReference>& crV)
18 ✔
108
{
109
  orion::BSONArrayBuilder ba;
18 ✔
110

111
  for (unsigned int ix = 0; ix < crV.size(); ++ix)
48 ✔
112
  {
113
    orion::BSONObjBuilder bob;
30 ✔
114

115
    bob.append(CSUB_ENTITY_ID,   crV[ix].id);
60 ✔
116
    bob.append(CSUB_ENTITY_TYPE, crV[ix].type);
60 ✔
117

118
    ba.append(bob.obj());
30 ✔
119
  }
30 ✔
120

121
  return ba.arr();
36 ✔
122
}
18 ✔
123
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc