Ports and link in a diagram

i have 2 questions how check if all the ports of a certain entity are filled ?
the second is how to limit one link per port?
consider the following diagram

Try this:
aNode.ports.all(function(p) { return aNode.findLinksConnected(p.portId).count === 1; })

If your ports only support either inputs or outputs but not both, you could set GraphObject.fromMaxLinks or GraphObject.toMaxLinks. Otherwise you’ll need to set linkValidation to a predicate: GoJS Validation -- Northwoods Software

      $(go.Node, . . .,
        {
          linkValidation: function(fromnode, fromport, tonode, toport) {
            // total number of links connecting with a node is limited to 1:
            return fromnode.linksConnected.count + tonode.linksConnected.count < 1;
          }
        }, . . .

one more thing how can i make the link not hop to the closest possible port and stay on the port that i drop it on

Do i need to assign each port an id and save it in link data?

Yes, each link needs to know which port to connect with on each end. Read GoJS Ports in Nodes-- Northwoods Software for more information.

How can i catch the port ids in link drawn event ?

In a “LinkDrawn” DiagramEvent listener, the e.subject will be the newly drawn Link. From there you can look at its Link.fromPort and Link.toPort.

If you have set GraphLinksModel.linkFromPortIdProperty and GraphLinksModel.linkToPortIdProperty, then the port identifier properties will be set automatically for you, both when the link is first drawn as well as whenever the user reconnects a link.

GraphLinksModel.linkFromPortIdProperty and GraphLinksModel.linkToPortIdProperty, where exactally do i set them? in the example it is set in the model data

$(go.GraphLinksModel,
{ linkFromPortIdProperty: “fromPort”, // required information:
linkToPortIdProperty: “toPort”, // identifies data property names
nodeDataArray: [
{ key: “Add1” },
{ key: “Add2” },
{ key: “Subtract1” }
],
linkDataArray: [
// no predeclared links
] });

can i set them in link template or any where else?

i m sorry if i m asking immature questions but i m fairly new to this api so bear with me i will be greatful

That’s correct, you should set those properties during the model initialization.