Commit 1731c04e authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Context component:

- Added logic to keep order of link endpoints
parent efed73e3
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -64,13 +64,14 @@ def link_set(db_engine : Engine, request : Link) -> Tuple[Dict, bool]:
    topology_uuids : Set[str] = set()
    related_topologies : List[Dict] = list()
    link_endpoints_data : List[Dict] = list()
    for endpoint_id in request.link_endpoint_ids:
    for i,endpoint_id in enumerate(request.link_endpoint_ids):
        endpoint_topology_uuid, _, endpoint_uuid = endpoint_get_uuid(
            endpoint_id, allow_random=False)

        link_endpoints_data.append({
            'link_uuid'    : link_uuid,
            'endpoint_uuid': endpoint_uuid,
            'position'     : i,
        })

        if endpoint_topology_uuid not in topology_uuids:
+8 −2
Original line number Diff line number Diff line
@@ -12,7 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from sqlalchemy import Column, DateTime, ForeignKey, String
import operator
from sqlalchemy import CheckConstraint, Column, DateTime, ForeignKey, Integer, String
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
from typing import Dict
@@ -38,7 +39,7 @@ class LinkModel(_Base):
            'name'             : self.link_name,
            'link_endpoint_ids': [
                link_endpoint.endpoint.dump_id()
                for link_endpoint in self.link_endpoints
                for link_endpoint in sorted(self.link_endpoints, key=operator.attrgetter('position'))
            ],
        }

@@ -47,6 +48,11 @@ class LinkEndPointModel(_Base):

    link_uuid     = Column(ForeignKey('link.link_uuid',         ondelete='CASCADE' ), primary_key=True)
    endpoint_uuid = Column(ForeignKey('endpoint.endpoint_uuid', ondelete='RESTRICT'), primary_key=True, index=True)
    position      = Column(Integer, nullable=False)

    link     = relationship('LinkModel',     back_populates='link_endpoints', lazy='joined')
    endpoint = relationship('EndPointModel', lazy='joined') # back_populates='link_endpoints'

    __table_args__ = (
        CheckConstraint(position >= 0, name='check_position_value'),
    )