def test_addOrUpdateConnectorThenCreateANewOne(self):
     connectorName = 'Connection t1 t2'
     element = {
                 "type": "dbModel.shape.TableConnection",
                 "id": "f9735797-cf1d-8431-d891-c2d10f0a67be",
                 "name": connectorName,
                 "userData": {"isPrimary":True, "useDecorators": False},
                 "cssClass": "draw2d_Connection",
                 "stroke": 2,
                 "color": "#5BCAFF",
                 "policy": "draw2d.policy.line.LineSelectionFeedbackPolicy",
                 "router": "draw2d.layout.connection.InteractiveManhattanConnectionRouter",
                 "source": {
                   "node": "3253ff2a-a920-09d5-f033-ca759a778e19",
                   "port": "output1"
                 },
                 "target": {
                   "node": "2810494b-931f-da59-fd9d-6deba4385fe0",
                   "port": "input0"
                 }
               }
     elementUUID = 'f9735797cf1d8431d891c2d10f0a67be'
     addOrUpdateConnector(element, elementUUID, self.entity, self.entity)
     connector = Relationship.objects.get(smUUID=elementUUID)
     self.assertTrue(connector.code == connectorName)
Beispiel #2
0
 def test_addOrUpdateConnectorThenCreateANewOne(self):
     connectorName = 'Connection t1 t2'
     element = {
         "type": "dbModel.shape.TableConnection",
         "id": "f9735797-cf1d-8431-d891-c2d10f0a67be",
         "name": connectorName,
         "userData": {
             "isPrimary": True,
             "useDecorators": False
         },
         "cssClass": "draw2d_Connection",
         "stroke": 2,
         "color": "#5BCAFF",
         "policy": "draw2d.policy.line.LineSelectionFeedbackPolicy",
         "router":
         "draw2d.layout.connection.InteractiveManhattanConnectionRouter",
         "source": {
             "node": "3253ff2a-a920-09d5-f033-ca759a778e19",
             "port": "output1"
         },
         "target": {
             "node": "2810494b-931f-da59-fd9d-6deba4385fe0",
             "port": "input0"
         }
     }
     elementUUID = 'f9735797cf1d8431d891c2d10f0a67be'
     addOrUpdateConnector(element, elementUUID, self.entity, self.entity)
     connector = Relationship.objects.get(smUUID=elementUUID)
     self.assertTrue(connector.code == connectorName)
def synchDBFromDiagram(request):
    """ Create and synchronize elements in database
    """
    projectID = request.GET['projectID']
    try:
        project = Project.objects.get(id=projectID)
        user = request.user

        model = Model.objects.filter(project=project)
        if not model:
            model = Model.objects.create(project=project,code='default',smOwningTeam=project.smOwningTeam,smCreatedBy=user,smOwningUser=user)
        else:
            model = model[0]

        owningTeam = model.smOwningTeam
    except Exception as e:
        return JsonError(e)
    
    objects = json.loads(request.body)
    deletedConnectors = []
    UUIDList = []
    for element in objects:
        elementUUID = uuid.UUID(element['id']).hex
        if element['type'] == 'dbModel.shape.DBTable':
            UUIDList.append(elementUUID)
            addOrUpdateEntity(model, user, owningTeam, deletedConnectors, element, elementUUID)
        else:
            if elementUUID not in deletedConnectors:
                sourceUUID = uuid.UUID(element['source']['node']).hex
                targetUUID = uuid.UUID(element['target']['node']).hex
                try:
                    refEntity = Entity.objects.get(smUUID=sourceUUID)
                    connEntity = Entity.objects.get(smUUID=targetUUID)
                except Exception as e:
                    return JsonError(e)
                
                addOrUpdateConnector(element, elementUUID, refEntity, connEntity)
    
    # Return the updated JSON model
    selectedTables = []
    connectors = []
    try:
        entities = Entity.objects.filter(smUUID__in=UUIDList)
        assembler = JSONAssembler()
        assembler.getJSONElements(entities, selectedTables, connectors)
                
    except Exception as e:
        print(e)
        return JsonError("Entity non trouvé")
    
    jsondict = {
        'success':True,
        'message': '',
        'tables': selectedTables,
        'connectors': connectors,
    }
    context = json.dumps(jsondict)
    return HttpResponse(context, content_type="application/json")
def synchDBFromDiagram(request):
    """ Create and synchronize elements in database
    """
    projectID = request.GET['projectID']
    try:
        project = Project.objects.get(id=projectID)
        user = request.user

        model = Model.objects.filter(project=project)
        if not model:
            model = Model.objects.create(project=project,
                                         code='default',
                                         smOwningTeam=project.smOwningTeam,
                                         smCreatedBy=user,
                                         smOwningUser=user)
        else:
            model = model[0]

        owningTeam = model.smOwningTeam
    except Exception as e:
        return JsonError(e)

    objects = json.loads(request.body)
    deletedConnectors = []
    UUIDList = []
    for element in objects:
        elementUUID = uuid.UUID(element['id']).hex
        if element['type'] == 'dbModel.shape.DBTable':
            UUIDList.append(elementUUID)
            addOrUpdateEntity(model, user, owningTeam, deletedConnectors,
                              element, elementUUID)
        else:
            if elementUUID not in deletedConnectors:
                sourceUUID = uuid.UUID(element['source']['node']).hex
                targetUUID = uuid.UUID(element['target']['node']).hex
                try:
                    refEntity = Entity.objects.get(smUUID=sourceUUID)
                    connEntity = Entity.objects.get(smUUID=targetUUID)
                except Exception as e:
                    return JsonError(e)

                addOrUpdateConnector(element, elementUUID, refEntity,
                                     connEntity)

    # Return the updated JSON model
    selectedTables = []
    connectors = []
    try:
        entities = Entity.objects.filter(smUUID__in=UUIDList)
        assembler = JSONAssembler()
        assembler.getJSONElements(entities, selectedTables, connectors)

    except Exception as e:
        print(e)
        return JsonError("Entity non trouvé")

    jsondict = {
        'success': True,
        'message': '',
        'tables': selectedTables,
        'connectors': connectors,
    }
    context = json.dumps(jsondict)
    return HttpResponse(context, content_type="application/json")