diff --git "a/01-Utilisation de Qualig\303\251o/02-SpecifierSchemaContraintes/06.DefinitionContraintesSpecifiquesJDD.md" "b/01-Utilisation de Qualig\303\251o/02-SpecifierSchemaContraintes/06.DefinitionContraintesSpecifiquesJDD.md" index f97c1eb532f78adf1605481bae793c087c51037c..7d90ae219d8f849f654421a3790676a988981d7c 100644 --- "a/01-Utilisation de Qualig\303\251o/02-SpecifierSchemaContraintes/06.DefinitionContraintesSpecifiquesJDD.md" +++ "b/01-Utilisation de Qualig\303\251o/02-SpecifierSchemaContraintes/06.DefinitionContraintesSpecifiquesJDD.md" @@ -16,25 +16,42 @@ Trois arguments sont implémentés : le nom du type d’entité, le nombre minim  - - - -### Ecriture du code - - Le début de chaque script doit commencer par 8 lignes d’appel des librairies suivantes : - - # IMPORT LIBRAIRIES - + # coding: utf-8 import fmeobjects - - import subprocess - - import time - - import sys - - import os - - import tempfile - - import re \ No newline at end of file + + # CheckFeatureNumber([feature_type, min, max]). + # Utiliser "None" pour l'absence de paramètre min ou max. + # Exemple d'appel : CheckFeatureNumber(['DPT',None ,50]), le nombre de DPT ne doit pas dépasser 50. + # Le nombre d'enregistrements du type d'entité doit être compris entre les valeurs min et max, sinon une erreur est générée. + class CheckFeatureNumber: + def __init__(self, arg): + #arg[0] = nom du type d'entité + #arg[1] = nombre minimal d'enregistrements + #arg[2] = nombre maximal d'enregistrements + self.logger = fmeobjects.FMELogFile() + self.logger.logMessageString('arguments = ' + arg[0] +':'+str(arg[1])+':'+str(arg[2]),1) + self.ft = arg[0] + self.min = arg[1] + self.max = arg[2] + self.count = 0 + + def input(self,feature): + if feature.getAttribute('fme_feature_type') == self.ft: + self.count +=1 + if self.count == 1: + self.feature=feature + + + def process(self): + self.errorFeatureList = [] + self.logger.logMessageString('self.count = ' + str(self.count),1) + if hasattr(self, "feature"): + if self.min != None: + if self.count < self.min : + self.feature.setAttribute('_message','Le nombre d\'enregistrements du type d\'entité ' + self.ft + ' est inférieur à ' + str(self.min)+' : '+str(self.count)) + self.errorFeatureList.append(self.feature) + if self.max != None and self.errorFeatureList == []: + if self.count > self.max : + self.feature.setAttribute('_message','Le nombre d\'enregistrements du type d\'entité ' + self.ft + ' est supérieur à ' + str(self.max)+' : '+str(self.count)) + self.errorFeatureList.append(self.feature) + return self.errorFeatureList \ No newline at end of file