Auto generated map link color is linked to interface status by default. Fixes #NX...
authorEriks Jenkevics <eriks@netxms.org>
Mon, 13 Nov 2017 11:20:29 +0000 (13:20 +0200)
committerEriks Jenkevics <eriks@netxms.org>
Mon, 13 Nov 2017 13:50:16 +0000 (15:50 +0200)
src/client/java/netxms-client/src/main/java/org/netxms/client/maps/NetworkMapLink.java
src/client/java/netxms-client/src/main/java/org/netxms/client/maps/configs/LinkConfig.java
src/server/core/netmap.cpp
src/server/core/netmap_objlist.cpp
src/server/include/netxms_maps.h

index db993ed..f7d597a 100644 (file)
@@ -145,7 +145,7 @@ public class NetworkMapLink
       {
          Logger.warning("NetworkMapLink", "Cannot create data from XML (" + xml + ")", e);
          config = new LinkConfig();
-      }                
+      }
        }
        
        /**
@@ -155,7 +155,7 @@ public class NetworkMapLink
         * @param baseId base variable ID
         */
        public void fillMessage(NXCPMessage msg, long baseId)
-       {     
+       {
           String xml = "";
       try
       {
@@ -165,7 +165,6 @@ public class NetworkMapLink
       {
          Logger.warning("NetworkMapLink", "Cannot create XML from config (" + config.toString() + ")", e);
       }
-          
                msg.setFieldInt16(baseId, type);
                msg.setField(baseId + 1, name);
                msg.setField(baseId + 2, connectorName1);
@@ -319,13 +318,7 @@ public class NetworkMapLink
         */
        public List<Long> getStatusObject()
        {
-          Long [] statusObject = config.getObjectStatusList();
-          List<Long> result = new ArrayList<Long>();
-          if(statusObject == null)
-             return result;
-          for(int i = 0; i < statusObject.length; i++)
-             result.add(statusObject[i]);
-               return result;
+               return config.getObjectStatusList();
        }
 
        /**
@@ -334,7 +327,7 @@ public class NetworkMapLink
        public void setStatusObject(List<Long> statusObject)
        {
           if(statusObject != null)
-             config.setObjectStatusList(statusObject.toArray(new Long[statusObject.size()]));
+             config.setObjectStatusList(statusObject);
        }
 
        /**
index 14d7f8f..a148668 100644 (file)
@@ -20,10 +20,13 @@ package org.netxms.client.maps.configs;
 
 import java.io.StringWriter;
 import java.io.Writer;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 import org.netxms.client.maps.NetworkMapLink;
 import org.simpleframework.xml.Element;
 import org.simpleframework.xml.ElementArray;
+import org.simpleframework.xml.ElementList;
 import org.simpleframework.xml.Root;
 import org.simpleframework.xml.Serializer;
 import org.simpleframework.xml.core.Persister;
@@ -33,9 +36,9 @@ public class LinkConfig
 {
    @ElementArray(required=false)
    private SingleDciConfig[] dciList;
-   
-   @ElementArray(required=false)
-   private Long[] objectStatusList = new Long[0];
+
+   @ElementList(required=false)
+   private List<Long> objectStatusList = new ArrayList<Long>();
    
    @Element(required=false)
    private int color;
@@ -61,7 +64,7 @@ public class LinkConfig
    /**
     * Constructor for creating XML
     */
-   public LinkConfig(SingleDciConfig[] dciList, Long[] objectStatusList, int color, int routing,
+   public LinkConfig(SingleDciConfig[] dciList, List<Long> objectStatusList, int color, int routing,
          long[] bendPoints)
    {
       super();
@@ -102,7 +105,7 @@ public class LinkConfig
    /**
     * @return the objectStatusList
     */
-   public Long[] getObjectStatusList()
+   public List<Long> getObjectStatusList()
    {
       return objectStatusList;
    }
@@ -110,7 +113,7 @@ public class LinkConfig
    /**
     * @param objectStatusList the objectStatusList to set
     */
-   public void setObjectStatusList(Long[] objectStatusList)
+   public void setObjectStatusList(List<Long> objectStatusList)
    {
       this.objectStatusList = objectStatusList;
    }
@@ -185,7 +188,7 @@ public class LinkConfig
    @Override
    public String toString()
    {
-      return "LinkConfig [dciList=" + Arrays.toString(dciList) + ", objectStatusList=" + Arrays.toString(objectStatusList)
+      return "LinkConfig [dciList=" + Arrays.toString(dciList) + ", objectStatusList=" + objectStatusList.toString()
             + ", color=" + color + ", routing=" + routing + ", bendPoints=" + Arrays.toString(bendPoints) + "]";
    }
 }
index f03972d..5f2d1ee 100644 (file)
@@ -733,7 +733,7 @@ void NetworkMap::updateObjects(NetworkMapObjectList *objects)
 {
    bool modified = false;
 
-   DbgPrintf(5, _T("NetworkMap(%s): updateObjects called"), m_name);
+   nxlog_debug(5, _T("NetworkMap(%s): updateObjects called"), m_name);
 
    // Filter out disallowed objects
    if ((m_flags & MF_FILTER_OBJECTS) && (m_filter != NULL))
@@ -778,7 +778,7 @@ void NetworkMap::updateObjects(NetworkMapObjectList *objects)
 
       if (!linkExists)
       {
-         DbgPrintf(5, _T("NetworkMap(%s)/updateObjects: link %d - %d removed"), m_name, link->getElement1(), link->getElement2());
+         nxlog_debug(5, _T("NetworkMap(%s)/updateObjects: link %d - %d removed"), m_name, link->getElement1(), link->getElement2());
          m_links->remove(i);
          i--;
          modified = true;
@@ -794,7 +794,7 @@ void NetworkMap::updateObjects(NetworkMapObjectList *objects)
 
       if (!objects->isObjectExist(((NetworkMapObject *)e)->getObjectId()))
       {
-         DbgPrintf(5, _T("NetworkMap(%s)/updateObjects: object element %d removed"), m_name, e->getId());
+         nxlog_debug(5, _T("NetworkMap(%s)/updateObjects: object element %d removed"), m_name, e->getId());
          m_elements->remove(i);
          i--;
          modified = true;
@@ -850,11 +850,50 @@ void NetworkMap::updateObjects(NetworkMapObjectList *objects)
             NetworkMapLink *l = new NetworkMapLink(e1, e2, objects->getLinks()->get(i)->type);
             l->setConnector1Name(objects->getLinks()->get(i)->port1);
             l->setConnector2Name(objects->getLinks()->get(i)->port2);
-            l->setConfig(objects->getLinks()->get(i)->config);
+            String config;
+            config.append(_T("<config>\n"));
+            config.append(_T("\t<dciList length=\"0\"/>\n"));
+            config.append(_T("\t<objectStatusList class=\"java.util.ArrayList\">\n"));
+
+            Interface *interf = NULL;
+            Node *obj = static_cast<Node*>(FindObjectById(objects->getLinks()->get(i)->id1, OBJECT_NODE));
+            if (obj != NULL)
+            {
+               for(int n = 0; n < objects->getLinks()->get(i)->portIdCount; n++)
+               {
+                  interf = obj->findInterfaceByIndex(objects->getLinks()->get(i)->portIdArray1[n]);
+                  if (interf != NULL)
+                  {
+                     config.append(_T("\t\t<long>"));
+                     config.append(interf->getId());
+                     config.append(_T("</long>\n"));
+                  }
+               }
+            }
+            obj = static_cast<Node*>(FindObjectById(objects->getLinks()->get(i)->id2, OBJECT_NODE));
+            if (obj != NULL)
+            {
+               for(int n = 0; n < objects->getLinks()->get(i)->portIdCount; n++)
+               {
+                  interf = obj->findInterfaceByIndex(objects->getLinks()->get(i)->portIdArray2[n]);
+                  if (interf != NULL)
+                  {
+                     config.append(_T("\t\t<long>"));
+                     config.append(interf->getId());
+                     config.append(_T("</long>\n"));
+                  }
+               }
+            }
+
+            config.append(_T("\t</objectStatusList>\n"));
+            config.append(_T("\t<color>-1</color>\n"));
+            config.append(_T("\t<routing>0</routing>\n"));
+            config.append(_T("</config>"));
+            l->setConfig(config);
             l->setFlags(AUTO_GENERATED);
             m_links->add(l);
             modified = true;
-            DbgPrintf(5, _T("NetworkMap(%s)/updateObjects: link %d - %d added"), m_name, l->getElement1(), l->getElement2());
+            nxlog_debug(5, _T("NetworkMap(%s)/updateObjects: link %d - %d added"), m_name, l->getElement1(), l->getElement2());
          }
       }
    }
index 2a4177c..8886684 100644 (file)
@@ -33,36 +33,10 @@ ObjLink::ObjLink()
    port1[0] = 0;
    port2[0] = 0;
        portIdCount = 0;
-       config = NULL;
        flags = 0;
 }
 
 /**
- * Create new object link
- */
-ObjLink::ObjLink(UINT32 id1, UINT32 id2, LONG type, TCHAR* port1, TCHAR* port2, int portIdCount, UINT32* portIdArray1, UINT32* portIdArray2, TCHAR* config, UINT32 flags)
-{
-   this->id1 = id1;
-   this->id2 = id2;
-   this->type = type;
-       _tcscpy(this->port1, port1);
-       _tcscpy(this->port2, port2);
-       this->portIdCount = portIdCount;
-
-       for(int i = 0; i < portIdCount; i++)
-       {
-      this->portIdArray1[i] = portIdArray1[i];
-      this->portIdArray2[i] = portIdArray2[i];
-       }
-
-   if(config != NULL)
-      this->config = _tcsdup(config);
-   else
-      config = NULL;
-       this->flags = flags;
-}
-
-/**
  * Object link copy constructor
  */
 ObjLink::ObjLink(const ObjLink *src)
@@ -80,22 +54,10 @@ ObjLink::ObjLink(const ObjLink *src)
       this->portIdArray2[i] = src->portIdArray2[i];
        }
 
-   if(src->config != NULL)
-      config = _tcsdup(src->config);
-   else
-      config = NULL;
        flags = src->flags;
 }
 
 /**
- * Object link destructor
- */
-ObjLink::~ObjLink()
-{
-   free(config);
-}
-
-/**
  * Create empty object list
  */
 NetworkMapObjectList::NetworkMapObjectList()
@@ -105,32 +67,6 @@ NetworkMapObjectList::NetworkMapObjectList()
 }
 
 /**
- * Create object list from NXCP message
- */
-NetworkMapObjectList::NetworkMapObjectList(NXCPMessage *msg)
-{
-   m_objectList = new IntegerArray<UINT32>(16, 16);
-   m_linkList = new ObjectArray<ObjLink>(16, 16, true);
-
-       msg->getFieldAsInt32Array(VID_OBJECT_LIST, m_objectList);
-
-   int linksCount = msg->getFieldAsInt32(VID_NUM_LINKS);
-       UINT32 dwId = VID_OBJECT_LINKS_BASE;
-       for(int i = 0; i < linksCount; i++, dwId += 3)
-       {
-      ObjLink *obj = new ObjLink();
-               obj->id1 = msg->getFieldAsUInt32(dwId++);
-               obj->id2 = msg->getFieldAsUInt32(dwId++);
-               obj->type = (int)msg->getFieldAsUInt16(dwId++);
-               msg->getFieldAsString(dwId++, obj->port1, MAX_CONNECTOR_NAME);
-               msg->getFieldAsString(dwId++, obj->port2, MAX_CONNECTOR_NAME);
-               obj->config = msg->getFieldAsString(dwId++);
-               obj->flags = msg->getFieldAsUInt32(dwId++);
-               m_linkList->add(obj);
-       }
-}
-
-/**
  * Copy constructor
  */
 NetworkMapObjectList::NetworkMapObjectList(NetworkMapObjectList *src)
@@ -332,7 +268,6 @@ void NetworkMapObjectList::linkObjectsEx(UINT32 id1, UINT32 id2, const TCHAR *po
                        obj->portIdArray2[0] = portId2;
                        nx_strncpy(obj->port1, port1, MAX_CONNECTOR_NAME);
                        nx_strncpy(obj->port2, port2, MAX_CONNECTOR_NAME);
-                       obj->config = NULL;
                        m_linkList->add(obj);
       }
    }
@@ -359,7 +294,7 @@ void NetworkMapObjectList::createMessage(NXCPMessage *msg)
                msg->setField(dwId++, (WORD)l->type);
                msg->setField(dwId++, l->port1);
                msg->setField(dwId++, l->port2);
-               msg->setField(dwId++, CHECK_NULL_EX(m_linkList->get(i)->config));
+               msg->setField(dwId++, _T(""));
                msg->setField(dwId++, m_linkList->get(i)->flags);
        }
 }
index 847a643..4659d3e 100644 (file)
@@ -61,13 +61,10 @@ public:
        int portIdCount;
        UINT32 portIdArray1[MAX_PORT_COUNT];
        UINT32 portIdArray2[MAX_PORT_COUNT];
-       TCHAR *config;
        UINT32 flags;
 
    ObjLink();
-   ObjLink(UINT32 id1, UINT32 id2, LONG type, TCHAR* port1, TCHAR* port2, int portIdCount, UINT32* portIdArray1, UINT32* portIdArray2, TCHAR* config, UINT32 flags);
    ObjLink(const ObjLink *src);
-   ~ObjLink();
  };
 
 /**
@@ -82,7 +79,6 @@ protected:
 public:
    NetworkMapObjectList();
    NetworkMapObjectList(NetworkMapObjectList *src);
-   NetworkMapObjectList(NXCPMessage *msg);
    ~NetworkMapObjectList();
 
    void merge(const NetworkMapObjectList *src);