Skip to content

Commit

Permalink
REMOVE unneded ContextRegistration classes (now Registration class is…
Browse files Browse the repository at this point in the history
… used instead) and solve several FIXME PR
  • Loading branch information
fgalan committed Aug 29, 2024
1 parent 03da017 commit 2545a5f
Show file tree
Hide file tree
Showing 17 changed files with 6 additions and 789 deletions.
12 changes: 0 additions & 12 deletions scripts/style_check_in_makefile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,6 @@ style_check test/unittests/serviceRoutines
# o ngsi/ContextElementResponseVector.h (haderding/remove_ngsiv1_indent: 7 lines)
# o ngsi/ContextElementVector.cpp (haderding/remove_ngsiv1_indent: 13 lines)
# o ngsi/ContextElementVector.h (haderding/remove_ngsiv1_indent: 8 lines)
# o ngsi/ContextRegistration.cpp (haderding/remove_ngsiv1_indent: 10 lines)
# o ngsi/ContextRegistration.h (haderding/remove_ngsiv1_indent: 2 lines)
# o ngsi/ContextRegistrationAttribute.cpp (haderding/remove_ngsiv1_indent: 7 lines)
# o ngsi/ContextRegistrationAttribute.h (haderding/remove_ngsiv1_indent: 1 line)
# o ngsi/ContextRegistrationAttributeVector.cpp (haderding/remove_ngsiv1_indent: 4 lines)
# o ngsi/ContextRegistrationAttributeVector.h (haderding/remove_ngsiv1_indent: 1 line)
# o ngsi/ContextRegistrationResponse.cpp (haderding/remove_ngsiv1_indent: 7 lines)
# o ngsi/ContextRegistrationResponse.h (haderding/remove_ngsiv1_indent: 2 lines)
# o ngsi/ContextRegistrationResponseVector.cpp (haderding/remove_ngsiv1_indent: 6 lines)
# o ngsi/ContextRegistrationResponseVector.h (haderding/remove_ngsiv1_indent: 2 lines)
# o ngsi/ContextRegistrationVector.cpp (haderding/remove_ngsiv1_indent: 6 lines)
# o ngsi/ContextRegistrationVector.h (haderding/remove_ngsiv1_indent: 2 lines)
# o ngsi/Duration.cpp (haderding/remove_ngsiv1_indent: 9 lines)
Expand Down Expand Up @@ -302,8 +292,6 @@ style_check test/unittests/serviceRoutines
# o unittests/ngsi/ContextElement_test.cpp (haderding/remove_ngsiv1_indent: 8 check())
# o unittests/ngsi/ContextRegistrationAttributeVector_test.cpp (haderding/remove_ngsiv1_indent: 4 render()
# o unittests/ngsi/ContextRegistrationAttribute_test.cpp (haderding/remove_ngsiv1_indent: 1 render()
# o unittests/ngsi/ContextRegistrationResponseVector_test.cpp (haderding/remove_ngsiv1_indent: 1 render(), 3 check())
# o unittests/ngsi/ContextRegistrationResponse_test.cpp (haderding/remove_ngsiv1_indent: 2 render(), 1 check())
# o unittests/ngsi/ContextRegistrationVector_test.cpp (haderding/remove_ngsiv1_indent: 1 render()
# o unittests/ngsi/Duration_test.cpp (haderding/remove_ngsiv1_indent: 3 check())
# o unittests/ngsi/EntityId_test.cpp (haderding/remove_ngsiv1_indent: 1 render()
Expand Down
173 changes: 6 additions & 167 deletions src/lib/mongoBackend/MongoGlobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,36 +433,6 @@ bool matchEntity(const EntityId* en1, const ngsiv2::EntID& en2)



#if 0
// FIXME PR
/* ****************************************************************************
*
* includedEntity -
*/
bool includedEntity(EntityId en, const EntityIdVector& entityIdV)
{
for (unsigned int ix = 0; ix < entityIdV.size(); ++ix)
{
if (en.isPatternIsTrue() && en.id == ".*")
{
// By the moment the only supported pattern is .*. In this case matching is
// based exclusively in type
if (en.type == entityIdV[ix]->type)
{
return true;
}
}
else if (matchEntity(&en, entityIdV[ix]))
{
return true;
}
}
return false;
}
#endif



/* ****************************************************************************
*
* includedAttribute -
Expand Down Expand Up @@ -1697,119 +1667,6 @@ void pruneContextElements



#if 0
// FIXME PR
/* ***************************************************************************
*
* processEntity -
*/
static void processEntity(ContextRegistrationResponse* crr, const EntityIdVector& enV, orion::BSONObj entity)
{
EntityId en;

en.id = getStringFieldF(entity, REG_ENTITY_ID);
en.type = entity.hasField(REG_ENTITY_TYPE)? getStringFieldF(entity, REG_ENTITY_TYPE) : "";
en.isPattern = entity.hasField(REG_ENTITY_ISPATTERN)? getStringFieldF(entity, REG_ENTITY_ISPATTERN) : "false";

if (includedEntity(en, enV))
{
EntityId* enP = new EntityId(en.id, en.type, en.isPattern);

crr->contextRegistration.entityIdVector.push_back(enP);
}
}



/* ***************************************************************************
*
* processAttribute -
*/
static void processAttribute(ContextRegistrationResponse* crr, const StringList& attrL, const orion::BSONObj& attribute)
{
ContextRegistrationAttribute attr(
getStringFieldF(attribute, REG_ATTRS_NAME),
getStringFieldF(attribute, REG_ATTRS_TYPE));

if (includedAttribute(attr.name, attrL))
{
ContextRegistrationAttribute* attrP = new ContextRegistrationAttribute(attr.name, attr.type);
crr->contextRegistration.contextRegistrationAttributeVector.push_back(attrP);
}
}



/* ***************************************************************************
*
* processContextRegistrationElement -
*/
static void processContextRegistrationElement
(
orion::BSONObj cr,
const EntityIdVector& enV,
const StringList& attrL,
ContextRegistrationResponseVector* crrV,
MimeType mimeType,
ProviderFormat providerFormat,
const std::string& regId
)
{
ContextRegistrationResponse crr;

crr.contextRegistration.providingApplication.set(getStringFieldF(cr, REG_PROVIDING_APPLICATION));
crr.contextRegistration.providingApplication.setProviderFormat(providerFormat);

std::vector<orion::BSONElement> queryEntityV = getFieldF(cr, REG_ENTITIES).Array();

for (unsigned int ix = 0; ix < queryEntityV.size(); ++ix)
{
processEntity(&crr, enV, queryEntityV[ix].embeddedObject());
}

/* Note that attributes can be included only if at least one entity has been found */
if (crr.contextRegistration.entityIdVector.size() > 0)
{
if (cr.hasField(REG_ATTRS)) /* To prevent registration in the E-<null> style */
{
std::vector<orion::BSONElement> queryAttrV = getFieldF(cr, REG_ATTRS).Array();

for (unsigned int ix = 0; ix < queryAttrV.size(); ++ix)
{
processAttribute(&crr, attrL, queryAttrV[ix].embeddedObject());
}
}
}

// FIXME: we don't take metadata into account at the moment
// crr.contextRegistration.registrationMetadataV = ..

/* Note that the context registration element is only included in one of the following cases:
* - The number of entities and attributes included are both greater than 0
* - The number of entities is greater than 0, the number of attributes is 0 but the discover
* doesn't use attributes in the request
*/
if (crr.contextRegistration.entityIdVector.size() == 0)
{
return;
}

if (crr.contextRegistration.contextRegistrationAttributeVector.size() > 0 ||
(crr.contextRegistration.contextRegistrationAttributeVector.size() == 0 && attrL.size() == 0))
{
ContextRegistrationResponse* crrP = new ContextRegistrationResponse();

crrP->contextRegistration = crr.contextRegistration;
crrP->providerFormat = providerFormat;
crrP->regId = regId;

crrV->push_back(crrP);
}
}
#endif



/* ****************************************************************************
*
* registrationsQuery -
Expand Down Expand Up @@ -1850,8 +1707,6 @@ bool registrationsQuery
// Note that by construction the $or array always has at least two elements (the two ones corresponding to the
// universal pattern) so we cannot avoid to use this operator.
//
// FIXME P5: the 'contextRegistration' token (19 chars) repeats in the query BSON. It would be better use 'cr' (2 chars)
// but this would need a data model migration in DB

/* Build query based on arguments */
std::string crEntitiesId = REG_CONTEXT_REGISTRATION "." REG_ENTITIES "." REG_ENTITY_ID;
Expand Down Expand Up @@ -1995,22 +1850,12 @@ bool registrationsQuery

LM_T(LmtMongo, ("retrieved document [%d]: '%s'", docs, r.toString().c_str()));

//std::vector<orion::BSONElement> queryContextRegistrationV = getFieldF(r, REG_CONTEXT_REGISTRATION).Array();
std::string format = getStringFieldF(r, REG_FORMAT);
//ProviderFormat providerFormat = (format.empty())? PfJson : (format == "JSON")? PfJson : PfV2; FIXME PR
std::string regId = getFieldF(r, "_id").OID();

//for (unsigned int ix = 0 ; ix < queryContextRegistrationV.size(); ++ix)
//{
//processContextRegistrationElement(queryContextRegistrationV[ix].embeddedObject(), enV, attrL, crrV, mimeType, providerFormat, regId);
ngsiv2::Registration reg;
//if (reg.fromBson(queryContextRegistrationV[ix].embeddedObject()))
if (reg.fromBson(r))
{
// FIXME PR: controll error if Registration comes from NGSIv1
regV->push_back(reg);
}
//}
ngsiv2::Registration reg;
if (reg.fromBson(r))
{
// FIXME PR: control error if Registration comes from NGSIv1
regV->push_back(reg);
}

/* FIXME: note that given the response doesn't distinguish from which registration ID the
* response comes, it could have that we have same context registration elements, belong to different
Expand Down Expand Up @@ -2310,18 +2155,14 @@ void fillContextProviders(ContextElementResponse* cer, const std::vector<ngsiv2:
/* Search for some CPr in crrV */
std::string perEntPa;
std::string perAttrPa;
MimeType perEntPaMimeType = NOMIMETYPE;
MimeType perAttrPaMimeType = NOMIMETYPE;
ProviderFormat providerFormat;
std::string regId;

cprLookupByAttribute(cer->entity,
ca->name,
regV,
&perEntPa,
&perEntPaMimeType,
&perAttrPa,
&perAttrPaMimeType,
&providerFormat,
&regId);

Expand Down Expand Up @@ -2373,9 +2214,7 @@ void cprLookupByAttribute
const std::string& attrName,
const std::vector<ngsiv2::Registration>& regV,
std::string* perEntPa,
MimeType* perEntPaMimeType, // FIXME PR: really needed?
std::string* perAttrPa,
MimeType* perAttrPaMimeType, // FIXME PR: really needed?
ProviderFormat* providerFormatP, // FIXME PR: ProviderFormat is really needed as type?
std::string* regId
)
Expand Down
4 changes: 0 additions & 4 deletions src/lib/mongoBackend/MongoGlobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@

#include "common/RenderFormat.h"
#include "ngsi/EntityId.h"
#include "ngsi/ContextRegistrationAttribute.h"
#include "ngsi/ContextAttribute.h"
#include "ngsi/EntityIdVector.h"
#include "ngsi/StringList.h"
#include "ngsi/ContextElementResponseVector.h"
#include "ngsi/ContextRegistrationResponseVector.h"
#include "ngsi10/UpdateContextResponse.h"
#include "ngsiNotify/Notifier.h"
#include "rest/uriParamNames.h"
Expand Down Expand Up @@ -368,9 +366,7 @@ extern void cprLookupByAttribute
const std::string& attrName,
const std::vector<ngsiv2::Registration>& regV,
std::string* perEntPa,
MimeType* perEntPaMimeType,
std::string* perAttrPa,
MimeType* perAttrPaMimeType,
ProviderFormat* providerFormatP,
std::string* regId
);
Expand Down
2 changes: 0 additions & 2 deletions src/lib/mongoBackend/mongoQueryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "common/string.h"
#include "common/sem.h"
#include "alarmMgr/alarmMgr.h"
#include "ngsi/ContextRegistrationResponse.h"
#include "ngsi10/QueryContextRequest.h"
#include "ngsi10/QueryContextResponse.h"

Expand Down Expand Up @@ -258,7 +257,6 @@ static void addContextProviders
for (unsigned int ix = 0; ix < regV.size(); ++ix)
{
ngsiv2::Registration reg = regV[ix];
//cr.providingApplication.setRegId(crrV[ix]->regId); FIXME PR: this is needed??

/* In case a "filtering" entity was provided, check that the current CRR matches or skip to next CRR */
if (enP != NULL && !matchEntityInRegistration(reg, enP))
Expand Down
10 changes: 0 additions & 10 deletions src/lib/ngsi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ SET (SOURCES
ContextAttributeVector.cpp
ContextElementResponse.cpp
ContextElementResponseVector.cpp
ContextRegistration.cpp
ContextRegistrationAttribute.cpp
ContextRegistrationAttributeVector.cpp
ContextRegistrationResponse.cpp
ContextRegistrationResponseVector.cpp
EntityId.cpp
EntityIdVector.cpp
Metadata.cpp
Expand All @@ -47,11 +42,6 @@ SET (HEADERS
ContextAttributeVector.h
ContextElementResponse.h
ContextElementResponseVector.h
ContextRegistrationAttribute.h
ContextRegistrationAttributeVector.h
ContextRegistration.h
ContextRegistrationResponse.h
ContextRegistrationResponseVector.h
EntityId.h
EntityIdVector.h
Metadata.h
Expand Down
59 changes: 0 additions & 59 deletions src/lib/ngsi/ContextRegistration.cpp

This file was deleted.

Loading

0 comments on commit 2545a5f

Please sign in to comment.