Esempio n. 1
0
def createTestModel():
    testProject = createTestProject()

    modeldata = {
        'project': testProject,
        'code': 'testCode',
        'category': 'testCategory',
        'modelPrefix': 'testPrefix',
        'description': 'Model used for tests'
    }

    testModel = Model(**modeldata)
    testModel.save()

    return testModel
def createTestModel():
    testProject = createTestProject()
    testProject.save()

    modeldata = {
        'project': testProject,
        'code': 'testCode',
        'category': 'testCategory',
        'modelPrefix': 'testPrefix',
        'description': 'Model used for tests'
    }

    testModel = Model(**modeldata)
    testModel.save()

    return testModel
Esempio n. 3
0
    def __write(self):

        # Logging info
        self.__logger.info("Ecriture dans la base de donnee...")

        # Los elementos superXXX son referencias de tipo caracter,
        fdsModel = ('code', 'category', 'modelPrefix',)
        
        fdsEntity = ('code',)
        
        # fdsProperty = ( 'code', 'alias', 'physicalName', 'foreignEntity' )
        fdsProperty = ('code',)
        booProperty = ('isPrimary', 'isNullable', 'isRequired', 'isSensitive', 'isEssential',)
        
        fdsRelationship = ('code', 'baseMin', 'baseMax', 'refMin', 'refMax',)

        # need for setSecurityInfo 
        data = {}

        # We populate the database
        if (self.__tree != None):  # A file has been loaded
        
            xProjects = self.__tree.getiterator("domain")
            
            # ------------------------------------------------------------------------------
            xModels = xProjects[0].getiterator("model")
            for xModel in xModels:
                dModel = Model()
                dModel.project = self.project 
                modelUdps = []

                for child in xModel:
                    if child.tag in fdsModel:
                        setattr(dModel, child.tag, child.text)
                    elif child.tag == 'udps':
                        for xUdp in child:
                            modelUdps.append((xUdp.tag, xUdp.get('text')))

                try:
                    setSecurityInfo(dModel, data, self.userProfile, True )
                    dModel.save()
                except:  
                    self.__logger.info("Error dModel.save")
                    return
                    
                self.__logger.info("Model..." + dModel.code)

                # ------------------------------------------------------------------------------
                xEntitys = xModel.getiterator("concept")
                for xEntity in xEntitys:
                    dEntity = Entity()
                    dEntity.model = dModel
                    
                    for child in xEntity:
                        if (child.tag in fdsEntity):
                            if (child.text is not None):
                                setattr(dEntity, child.tag, child.text)
                        elif  (child.tag == 'physicalName'):
                            setattr(dEntity, 'dbName' , child.text)
                        
                    try:              
                        setSecurityInfo(dEntity, data, self.userProfile, True )
                        dEntity.save()
                    except: 
                        self.__logger.info("Error dEntity.save")
                        return

                    self.__logger.info("Entity..." + dEntity.code)


                    # ------------------------------------------------------------------------------
                    xProperties = xEntity.getiterator("property")
                    for xProperty in xProperties:
                        
                        dProperty = Property()
                        dProperty.entity = dEntity

                        for child in xProperty:

                            if child.tag in fdsProperty:
                                if (child.text is not None):
                                    setattr(dProperty, child.tag, child.text)
                                
                            elif child.tag in booProperty:
                                bValue = toBoolean(child.text)
                                setattr(dProperty, child.tag, bValue)


                        try: 
                            setSecurityInfo(dProperty, data, self.userProfile, True )
                            dProperty.save()
                        except: 
                            self.__logger.info("Error prpDom.save")
                            return


                    # Relationship -------------------------------------------------------------------
                    xForeigns = xEntity.getiterator("foreign")
                    for xForeign in xForeigns:
                        dForeign = Relationship()

                        dForeign.entity = dEntity 
                        dForeign.refEntity = dEntity

                        for child in xForeign:
                            if child.tag in fdsRelationship:
                                setattr(dForeign, child.tag, child.text)

                            elif  (child.tag == 'baseConcept'):
                                setattr(dForeign, 'dbName' , child.text)

                            elif  (child.tag == 'alias'):
                                setattr(dForeign, 'relatedName' , child.text)
                                
                            elif child.tag in booProperty:
                                bValue = toBoolean(child.text)
                                setattr(dForeign, child.tag, bValue)

                        try:
                            setSecurityInfo(dForeign, data, self.userProfile, True )
                            dForeign.save()
                        except Exception, e: 
                            self.__logger.info("Error dForeign.save" + str(e))
                            return