From 23b798b2e01ac036c5cbfbe8f3741fd0a0344cf9 Mon Sep 17 00:00:00 2001 From: helderbetiol <37706737+helderbetiol@users.noreply.github.com> Date: Fri, 14 Jun 2024 15:57:38 +0200 Subject: [PATCH] feat(cli,api) nodes on both namespaces --- API/controllers/entity.go | 9 +++++---- CLI/controllers/commandController.go | 23 +++++++++-------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/API/controllers/entity.go b/API/controllers/entity.go index 8278aebc9..e016f8b3a 100644 --- a/API/controllers/entity.go +++ b/API/controllers/entity.go @@ -476,10 +476,6 @@ func HandleGenericObjects(w http.ResponseWriter, r *http.Request) { // Save entity to help delete and respond for _, obj := range entData { obj["entity"] = entStr - if entStr == "device" && req["attributes.virtual_config.clusterId"] != nil { - // add namespace prefix to nodes - obj["id"] = "Physical." + obj["id"].(string) - } } if nLimit, e := strconv.Atoi(filters.Limit); e == nil && nLimit > 0 && req["id"] != nil { @@ -668,6 +664,7 @@ func HandleComplexFilters(w http.ResponseWriter, r *http.Request) { u.ErrLog(ErrDecodingBodyMsg, "HANDLE COMPLEX FILTERS", "", r) return } + println(complexFilterExp) // Get objects filters := getFiltersFromQueryParams(r) @@ -686,6 +683,10 @@ func HandleComplexFilters(w http.ResponseWriter, r *http.Request) { // Save entity to help delete and respond for _, obj := range entData { obj["entity"] = entStr + if entStr == "device" && strings.Contains(complexFilterExp, "virtual_config.type=node") { + // add namespace prefix to device nodes + obj["id"] = "Physical." + obj["id"].(string) + } } matchingObjects = append(matchingObjects, entData...) diff --git a/CLI/controllers/commandController.go b/CLI/controllers/commandController.go index 7f9765f6a..ba7b07314 100755 --- a/CLI/controllers/commandController.go +++ b/CLI/controllers/commandController.go @@ -115,10 +115,11 @@ func (controller Controller) ObjectUrlGeneric(pathStr string, depth int, filters isNodeLayerInVirtualPath := false if path.Layer != nil { + path.Layer.ApplyFilters(filters) if path.Prefix == models.VirtualObjsPath && path.Layer.Name() == "#nodes" { isNodeLayerInVirtualPath = true - } else { - path.Layer.ApplyFilters(filters) + filters["filter"] = strings.Replace(filters["filter"], "category=virtual_obj", + "virtual_config.clusterId="+path.ObjectID[:len(path.ObjectID)-2], 1) } } @@ -152,10 +153,7 @@ func (controller Controller) ObjectUrlGeneric(pathStr string, depth int, filters params.Add("namespace", "organisational") params.Add("id", path.ObjectID) case models.VirtualObjsPath: - if isNodeLayerInVirtualPath { - params.Add("category", "device") - params.Set("virtual_config.clusterId", path.ObjectID[:len(path.ObjectID)-2]) - } else { + if !isNodeLayerInVirtualPath { params.Add("category", "virtual_obj") if path.ObjectID != "Logical."+models.VirtualObjsNode+".*" { params.Add("id", path.ObjectID) @@ -169,14 +167,11 @@ func (controller Controller) ObjectUrlGeneric(pathStr string, depth int, filters } endpoint := "/api/objects" - - if !isNodeLayerInVirtualPath { - for key, value := range filters { - if key != "filter" { - params.Set(key, value) - } else { - endpoint = "/api/objects/search" - } + for key, value := range filters { + if key != "filter" { + params.Set(key, value) + } else { + endpoint = "/api/objects/search" } }