DEFINITION Vrai_660003154 1
DEFINITION Faux_660003154 0
DEFINITION CPT_660003154 1507
DEFINITION MODULE_TRAIT_660003154 0x5000
DEFINITION ERR_SEM_660003154 0x040
DEFINITION ERR_CROISE_660003154 0x0F0
DEFINITION EFFICACE_660003154 0x01
DEFINITION pt_FicNameGlob_LEN_660003154 255
REGISTRE ENTIER erreur_660003154
REGISTRE ENTIER date_660003154
REGISTRE ENTIER Nb_jourRedist_660003154
REGISTRE ENTIER CPT_X_660003154
REGISTRE ENTIER CPT_Z_660003154
REGISTRE ENTIER code_rejet_660003154
REGISTRE ENTIER dateOfRedisJ_660003154
REGISTRE ENTIER val_SSENetworkType_660003154
REGISTRE ENTIER val_NetworkType_660003154
REGISTRE POINTEUR pt_IMSI_660003154
REGISTRE POINTEUR pt_NameOfFile_660003154
REGISTRE POINTEUR pt_NbJourRedist_660003154
REGISTRE POINTEUR pt_IdCrae_660003154
REGISTRE POINTEUR pt_VarGlob_660003154
REGISTRE ENTIER taille_660003154
REGISTRE ENTIER b_IMSI_OrangeCo_660003154
REGISTRE ENTIER date_cra_660003154
REGISTRE ENTIER Resultat_recherche_660003154
REGISTRE POINTEUR pt_FicNameTemp_660003154
REGISTRE POINTEUR pt_FicNameGlob_660003154
REGISTRE POINTEUR pt_LibelleAlarme_660003154
REGISTRE POINTEUR pt_resultat_660003154
REGISTRE POINTEUR pt_terme_660003154
REGISTRE ENTIER IMSI_Transnational_M2M_660003154
REGISTRE POINTEUR pt_MCCMNCx_660003154
REGISTRE POINTEUR pt_IMSIy_660003154
REGISTRE POINTEUR str_conteneur_660003154
REGISTRE POINTEUR ptr_res_660003154

#                         - Pcode du module de traitement Tcrae_ssp_trt.src : SERVICE COMPLEMENTAIRE
#                         - creation le 27/09/2006
#                         - Auteur : NBOU
#   HISTORIQUE
# 12/10/2010: QC711
# 14/01/2011 - BEA  - G3R1 lot4 Verification/Correction des variables (constantes, entiers, pointeurs)
# 19/08/2011 - DECI - G3R4 lot3 QC852, CRAE enrichissement du libelle des alarmes par le nom du fichier collecte
# 04/05/2012 - DECI - G3R7 Gestion du code MNC pour les MVNO lights
# 06/11/14 - JLG  - G5R2 lot2 : Ajout variables fonctionnelles MCCMNCx, IMSIy, IMSI_Transnational_M2M, Ajout controle sur Imsi, Filtrage des IMSIs inconnus vers NVDDCH (au lieu de ECDDCH) si IMSI transnational
# 06/11/14 - JLG  - G5R2 : contournement core sur verbe pcode i_adequation_chaine_expreg (QC1441)
##########################################################################################################

# declaration des variables




# G5R2lot2
#/G5R2lot2

# Initialisation
pt_IMSI_660003154 ="1245678945612345"
i_strcpy(pt_IMSI_660003154,"")
pt_NameOfFile_660003154 ="012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234"
i_strcpy(pt_NameOfFile_660003154,"")
pt_NbJourRedist_660003154 ="038977"
i_strcpy(pt_NbJourRedist_660003154,"")
pt_IdCrae_660003154="pt_IdCrae0123456789"
i_strcpy(pt_IdCrae_660003154,"")
pt_VarGlob_660003154="pt_VarGlob0123456789987654321213456789"
i_strcpy(pt_VarGlob_660003154,"")

Resultat_recherche_660003154 = 0
pt_FicNameTemp_660003154="pt_NameOfTemp0123456789pt_NameOfTemp0123456789pt_NameOfTemp0123456789pt_NameOfTemp0123456789pt_NameOfTemp0123456789pt_NameOfTemp0123456789pt_NameOfTemp0123456789pt_NameOfTemp0123456789pt_NameOfTemp0123456789pt_NameOfTemp0123456789pt_NameOfTemp0123456789pt"
i_strcpy(pt_FicNameTemp_660003154,"")
pt_FicNameGlob_660003154="pt_NameOfGlob0123456789pt_NameOfGlob0123456789pt_NameOfGlob0123456789pt_NameOfGlob0123456789pt_NameOfGlob0123456789pt_NameOfGlob0123456789pt_NameOfGlob0123456789pt_NameOfGlob0123456789pt_NameOfGlob0123456789pt_NameOfGlob0123456789pt_NameOfGlob0123456789pt"
i_strcpy(pt_FicNameGlob_660003154,"")
pt_LibelleAlarme_660003154="pt_LibelleAlarme_111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
i_strcpy(pt_LibelleAlarme_660003154,"")
pt_resultat_660003154="pt_resultat1111"
i_strcpy(pt_resultat_660003154,"")
pt_terme_660003154 =  "pt_terme1111111"
i_strcpy(pt_terme_660003154,"")

# G5R2lot2
IMSI_Transnational_M2M_660003154 = 0
pt_MCCMNCx_660003154 = "pt_MCCMNCx12"
i_strcpy(pt_MCCMNCx_660003154,"")
pt_IMSIy_660003154   = "pt_IMSIy1234"
i_strcpy(pt_IMSIy_660003154,"")
str_conteneur_660003154 = "str_conteneur123456789"
i_strcpy(str_conteneur_660003154,"")
ptr_res_660003154    = "ptr_res12345"
i_strcpy(ptr_res_660003154,"")
#/G5R2lot2

########################################################

trace("**[ssp CRAE ] : debut du pcode de traitement**")

# TT0033 plus de modification du g_iartin a cause de pb decoupe gros fichier
erreur_660003154 = i_dup_art_id(g_iartin , g_iartout12)
# /TT0033


# G3R4 lot3 QC852
SI (i_valid_field_n(g_iartin, $Tcrae_ssp::NameOfFile)&& i_valid_field_n(g_iartin, $Tcrae_ssp::DateOfRedistri))
ALORS
	erreur_660003154 = i_get_art_str(g_iartin, $Tcrae_ssp::NameOfFile, pt_NameOfFile_660003154)
SINON
	SI( pt_FicNameGlob_LEN_660003154 < i_strlen(g_isource) )
	ALORS
		trace("variable g_isource plus grande que pointeur de copie de g_isource.")
		code_rejet_660003154 = MODULE_TRAIT_660003154 + 0x0D0 + EFFICACE_660003154
		erreur_660003154 = i_PlvMessEmettre(8849, 2, g_iartout12, "", 2, code_rejet_660003154, "lg NameOfFile > 255", 0)
		SAUT STOCKE_ERRONE
	FINSI
	i_strcpy(pt_FicNameGlob_660003154, g_isource)
	POINT DEBUT_BOUCLE_FIC_NAME
	Resultat_recherche_660003154 = i_recupererValeur(pt_FicNameGlob_660003154, pt_FicNameTemp_660003154, 255, '/')
	SI( Resultat_recherche_660003154 == 0 )
	ALORS
		# On ne fait rien...
		# Le nom de fichier doit etre dans pt_FicNameTemp
		i_strcpy(pt_NameOfFile_660003154, pt_FicNameTemp_660003154)
		SAUT DEBUT_BOUCLE_FIC_NAME
	SINON
		# Le resultat a ete sauvegarde au coup precedent.
		trace("Fin boucle NameOfFile")
	FINSI
	# suppression des 9 derniers caracteres du g_isource (checksum)
	i_get_sub_str(pt_NameOfFile_660003154, 0, -10, pt_NameOfFile_660003154)
	SI (i_strlen(pt_NameOfFile_660003154) > 19)
	ALORS
		trace("**Tcrae_ssp, erreur : NameOfFile trop long **")
		code_rejet_660003154 = MODULE_TRAIT_660003154 + 0x0D0 + EFFICACE_660003154
		erreur_660003154 = i_format_str2(pt_LibelleAlarme_660003154, "%s=%s", "NameOfFile", pt_NameOfFile_660003154)
		erreur_660003154 = i_PlvMessEmettre(8865, 2, g_iartout12, "", 2, code_rejet_660003154, pt_LibelleAlarme_660003154, 0)
		SAUT STOCKE_ERRONE
	FINSI
FINSI
# /G3R4 lot3 QC852

# Controles semantiques

#Controle semantique du champ T3/NeworkType
erreur_660003154 = i_valid_field_n(g_iartin, $Tcrae_ssp::NetworkType)
SI (erreur_660003154 == 0)
ALORS
	trace("**Tcrae_ssp NetworkType est absent**")
	code_rejet_660003154  = MODULE_TRAIT_660003154  + ERR_SEM_660003154  + EFFICACE_660003154
	erreur_660003154 = i_format_str2(pt_LibelleAlarme_660003154, "%s> <f=%s", "NetworkType", pt_NameOfFile_660003154)
	erreur_660003154 = i_PlvMessEmettre(8866, 2, g_iartout12, "", 2, code_rejet_660003154, pt_LibelleAlarme_660003154, 0)
	SAUT STOCKE_ERRONE
SINON
	val_NetworkType_660003154 = i_get_art_field(g_iartin, $Tcrae_ssp::NetworkType)
	SI((val_NetworkType_660003154 != 0) && (val_NetworkType_660003154 != 1) && (val_NetworkType_660003154 != 2))
	ALORS
		trace1("**Tcrae_ssp NetworkType : <%x> != 0 et 1 et 2 **", erreur_660003154)
		code_rejet_660003154  = MODULE_TRAIT_660003154  + ERR_SEM_660003154  + EFFICACE_660003154
		erreur_660003154 = i_format_str2(pt_LibelleAlarme_660003154, "%s> <f=%s", "NetworkType", pt_NameOfFile_660003154)
		erreur_660003154 = i_PlvMessEmettre(8860, 2, g_iartout12, "", 3, code_rejet_660003154, val_NetworkType_660003154, pt_LibelleAlarme_660003154)
		SAUT STOCKE_ERRONE
	FINSI
FINSI


# G3R7 MVNO Light
date_cra_660003154 = i_get_art_field(g_iartin, $Tcrae_ssp::ddebut)

b_IMSI_OrangeCo_660003154 = 1

SI (i_valid_field_n(g_iartin, $Tcrae_ssp::IMSI))
ALORS
	b_IMSI_OrangeCo_660003154 = 0
	erreur_660003154 = i_get_art_str(g_iartin,$Tcrae_ssp::IMSI, pt_IMSI_660003154)
	SI (i_strplcmp(pt_IMSI_660003154, "20801", 0, 5) == 0) 
	ALORS
		b_IMSI_OrangeCo_660003154 = 1
	SINON
		SI (i_strplcmp(pt_IMSI_660003154, "208", 0, 3) == 0) 
		ALORS
			i_get_sub_str(pt_IMSI_660003154, 0, 4, pt_resultat_660003154)
			erreur_660003154 = i_format_str2(pt_terme_660003154, "%s%s", "L_", pt_resultat_660003154)
			SI (i_get_tab_field("MVNO", date_cra_660003154, pt_terme_660003154) != g_inull)
			ALORS
				b_IMSI_OrangeCo_660003154 = 1
			FINSI
		FINSI
	FINSI
FINSI

# G5R2lot2
# calcul de pt_MCCMNCx, pt_IMSIy, IMSI_Transnational_M2M
i_get_sub_str(pt_IMSI_660003154, 0, 5, pt_MCCMNCx_660003154)
i_get_sub_str(pt_IMSI_660003154, 6, 6, pt_IMSIy_660003154)
erreur_660003154 = i_format_str2(str_conteneur_660003154, "%s%s", "M2M_", pt_MCCMNCx_660003154)
i_strcpy(ptr_res_660003154, i_get_tab_field("MVNO", date_cra_660003154, str_conteneur_660003154))
# equivallent a QC1441 : anomalie core de i_adequation_chaine_expreg
SI (i_strcmp(pt_IMSIy_660003154, "") != 0 && i_strcmp(ptr_res_660003154, "") != 0)
ALORS
  SI ( i_strcmp(ptr_res_660003154,"Tous") == 0 || i_adequation_chaine_expreg(ptr_res_660003154, pt_IMSIy_660003154) == 0)
  ALORS
    IMSI_Transnational_M2M_660003154 = Vrai_660003154
  SINON
    IMSI_Transnational_M2M_660003154 = Faux_660003154
  FINSI
SINON
  IMSI_Transnational_M2M_660003154 = Faux_660003154
FINSI
#/QC1441

# filtre des non transnationnaux et non orangeCo
SI (!b_IMSI_OrangeCo_660003154 && !IMSI_Transnational_M2M_660003154)
ALORS
		trace("Le champ IMSI ne commence pas par 208xx => ERRONE")
		code_rejet_660003154 = MODULE_TRAIT_660003154 + ERR_SEM_660003154 + EFFICACE_660003154
		erreur_660003154 = i_format_str2(pt_LibelleAlarme_660003154, "%s> <f=%s", "IMSI", pt_NameOfFile_660003154)
		erreur_660003154 = i_PlvMessEmettre(8822, 2, g_iartout12, "", 2, code_rejet_660003154, pt_LibelleAlarme_660003154, 0)
		SAUT STOCKE_ERRONE
FINSI
#/G5R2 lot2

#Controle croise du champ T3/SSENetwokType
SI (i_valid_field_n(g_iartin, $Tcrae_ssp::NetworkType) && i_get_art_field(g_iartin, $Tcrae_ssp::NetworkType) == 0 )
ALORS
	SI (i_valid_field_n(g_iartin, $Tcrae_ssp::SSENetworkType)== 0 )
	ALORS
		trace("**Tcrae_ssp  NetworkType vaut 0 et SSENetworkType est absent**")
		code_rejet_660003154  = MODULE_TRAIT_660003154  + ERR_CROISE_660003154  + EFFICACE_660003154
		erreur_660003154 = i_format_str2(pt_LibelleAlarme_660003154, "%s> <f=%s", "SSENetworkType", pt_NameOfFile_660003154)
		erreur_660003154 = i_PlvMessEmettre(8866, 2, g_iartout12, "", 2, code_rejet_660003154, pt_LibelleAlarme_660003154, 0)
		SAUT STOCKE_ERRONE
	SINON
		val_SSENetworkType_660003154 = i_get_art_field(g_iartin, $Tcrae_ssp::SSENetworkType)
		SI( (val_SSENetworkType_660003154 != 1) && (val_SSENetworkType_660003154 != 2) )
		ALORS
			trace1("**Tcrae_ssp NetworkType vaut 0, SSENetworkType: <%x> != 1 et 2",erreur_660003154)
			code_rejet_660003154  = MODULE_TRAIT_660003154  + ERR_CROISE_660003154  + EFFICACE_660003154
			erreur_660003154 = i_format_str2(pt_LibelleAlarme_660003154, "%s> <f=%s", "SSENetworkType", pt_NameOfFile_660003154)
			erreur_660003154 = i_PlvMessEmettre(8860, 2, g_iartout12, "", 3, code_rejet_660003154, val_SSENetworkType_660003154, pt_LibelleAlarme_660003154)
			SAUT STOCKE_ERRONE
		FINSI
	FINSI
FINSI


# controles croises de champs
#Controle croise pour les champs Imsi et Min

SI((i_valid_field_n(g_iartin, $Tcrae_ssp::IMSI))&&(i_valid_field_n(g_iartin, $Tcrae_ssp::Min)))
ALORS
	trace("**Tcrae_ssp , presence simultanee des champs <IMSI> et <Min>")
	code_rejet_660003154  = MODULE_TRAIT_660003154  + ERR_CROISE_660003154  + EFFICACE_660003154
	erreur_660003154 = i_format_str2(pt_LibelleAlarme_660003154, "%s> <f=%s", "Min", pt_NameOfFile_660003154)
	erreur_660003154 = i_PlvMessEmettre(8864, 2, g_iartout12, "", 3, code_rejet_660003154, "IMSI", pt_LibelleAlarme_660003154)
	SAUT STOCKE_ERRONE
FINSI

SI(!(i_valid_field_n(g_iartin, $Tcrae_ssp::IMSI))&& !(i_valid_field_n(g_iartin, $Tcrae_ssp::Min)))
ALORS
	trace("**Tcrae_ssp ,absence simultanee des champs <IMSI> et <Min>")
	code_rejet_660003154  = MODULE_TRAIT_660003154  + ERR_CROISE_660003154  + EFFICACE_660003154
	erreur_660003154 = i_format_str2(pt_LibelleAlarme_660003154, "%s> <f=%s", "Min", pt_NameOfFile_660003154)
	erreur_660003154 = i_PlvMessEmettre(8863, 2, g_iartout12, "", 3, code_rejet_660003154, "IMSI", pt_LibelleAlarme_660003154)
	SAUT STOCKE_ERRONE
FINSI


#Controle de la Variable globale

erreur_660003154 = i_get_field_str(g_iartin ,"NameOfFile",pt_NameOfFile_660003154 )
erreur_660003154 = i_get_field_str(g_iartin ,"IdCrae",pt_IdCrae_660003154)
erreur_660003154 = i_format_str2(pt_VarGlob_660003154, "%s%s" ,pt_NameOfFile_660003154  , pt_IdCrae_660003154 )
#comparaison de VarGlob avec la variable globale rensign? dans le crae pere Tcrae_ssp ou Tcrae_ssp
#nom de cette variable non encore connu


# Mise a jour du champ T3t1/NameOfFile pour les articles provenant de la redistribution
SI (i_valid_field_n(g_iartin, $Tcrae_ssp::NameOfFile)&& i_valid_field_n(g_iartin,$Tcrae_ssp::DateOfRedistri))
ALORS
	trace("**Tcrae_ssp , article issu de la redistribution**")
#	erreur  = i_get_field_str(g_iartin ,"NameOfFile",pt_NameOfFile ) fait plus haut
	dateOfRedisJ_660003154 = i_sdat_to_jdat(i_get_art_field(g_iartin, $Tcrae_ssp::DateOfRedistri))
	trace1("datej %x", dateOfRedisJ_660003154)
#      Nb_jourRedist  = i_cur_date() - i_get_art_field(g_iartin, $Tcrae_ssp::DateOfRedistri)
	Nb_jourRedist_660003154 = i_cur_date()- dateOfRedisJ_660003154
	trace1("cur_date %x ",i_cur_date())
	trace1("Nb_jourRedist est %x ",Nb_jourRedist_660003154)
	erreur_660003154  = i_EntierToString(Nb_jourRedist_660003154 , pt_NbJourRedist_660003154 , 4)
	erreur_660003154 =i_format_str2(pt_NameOfFile_660003154 , "%s.%s" ,pt_NameOfFile_660003154  , pt_NbJourRedist_660003154 )
	trace2("Tcrae_ssp , mis a jour <NameOfFile> par :<%s>", pt_NameOfFile_660003154 , 0)
	SI (i_strlen(pt_NameOfFile_660003154) > g_iartin.NameOfFile!TAILLE)
	ALORS
		taille_660003154 = g_iartin.NameOfFile!TAILLE
	SINON
		taille_660003154 = i_strlen(pt_NameOfFile_660003154)
	FINSI
# TT0033 plus de modification du g_iartin a cause de pb decoupe gros fichier
	erreur_660003154 = i_resize_tlv(g_iartout12, "T3t1_NameOfFile", "NameOfFile", taille_660003154)
	erreur_660003154  = i_memcpy_art_field(g_iartout12, "NameOfFile",pt_NameOfFile_660003154 , taille_660003154)
# /TT0033
	erreur_660003154  = i_get_field_str(g_iartin ,"NameOfFile",pt_NameOfFile_660003154 )
	trace2("Tcrae_ssp , <NameOfFile> :<%s>", pt_NameOfFile_660003154 , 0)
SINON
	# mise a jour de l'article avec le champ NameOfFile

# TT0033 plus de modification du g_iartin a cause de pb decoupe gros fichier
	erreur_660003154  = i_ajout_tlv(g_iartout12, "T3t1_NameOfFile" , "")
	erreur_660003154  = i_resize_tlv(g_iartout12, "T3t1_NameOfFile" , "NameOfFile" ,17)
# /TT0033
	SI(erreur_660003154 !=0)
	ALORS
		trace("Tcrae_ssp, erreur d ajout du champ <NameOfFile>**")
		code_rejet_660003154  = MODULE_TRAIT_660003154  + ERR_SEM_660003154  + EFFICACE_660003154
		erreur_660003154 = i_format_str2(pt_LibelleAlarme_660003154, "%s> <f=%s", "NameOfFile", pt_NameOfFile_660003154)
		erreur_660003154 = i_PlvMessEmettre(8889, 2, g_iartout12, "", 2, code_rejet_660003154, pt_LibelleAlarme_660003154, 0)
		SAUT STOCKE_ERRONE
	FINSI
# TT0033 plus de modification du g_iartin a cause de pb decoupe gros fichier
	erreur_660003154 = i_resize_tlv(g_iartout12, "T3t1_NameOfFile" , "NbRedist" ,2)
# /TT0033
	SI(erreur_660003154!=0)
	ALORS
		trace("Tcrae_ssp, erreur d ajout du champ <NbRedist>**")
		code_rejet_660003154 = MODULE_TRAIT_660003154 + ERR_SEM_660003154 + EFFICACE_660003154
		SAUT STOCKE_ERRONE
	FINSI

# OGA 488
# TT0033 plus de modification du g_iartin a cause de pb decoupe gros fichier
	erreur_660003154 = i_memcpy_art_field(g_iartout12, "NameOfFile",pt_NameOfFile_660003154, i_strlen(pt_NameOfFile_660003154))
# /TT0033
# /OGA 488
FINSI


##############################################################################
# Mise a jour du compteur applicatif <Type de CRAE/EEC/Jour> :1507
###############################################################################
CPT_X_660003154 = 40
CPT_Z_660003154  = 0
date_660003154  = i_DHgetLocalTime(4, 7, i_date_audit())
erreur_660003154=i_incr_cpt(CPT_660003154,CPT_X_660003154,g_ieec,CPT_Z_660003154,date_660003154,1)
SI(erreur_660003154 !=0)
ALORS
	trace("**Tcrae_ssp, erreur de mise a jour du compteur 1507 **")
	code_rejet_660003154  = MODULE_TRAIT_660003154  + ERR_SEM_660003154  + EFFICACE_660003154
	SAUT STOCKE_ERRONE
FINSI

#  Article valide , stockage en OK
trace("**Tcrae_ssp, stockage de l'article en OK**")
# TT0033 plus de modification du g_iartin a cause de pb decoupe gros fichier
erreur_660003154  = i_stocke_art(g_iartout12, 0, PT_OK, 0)
# /TT0033
RETOUR  TRAIT_OK


# stockage en errone

POINT STOCKE_ERRONE

# TT0033 plus de modification du g_iartin a cause de pb decoupe gros fichier
erreur_660003154  = i_make_art_rej(g_iartout12, g_iartout2, code_rejet_660003154 )
# /TT0033
erreur_660003154  = i_stocke_art(g_iartout2,0,PT_ERRONE,0)
trace("**Tcrae_ssp , Artcile stocke en errone**")
#      RETOUR TRAIT_OK
RETOUR BAD_BLOC
#---------------------------- Fin Tcrae_ssp_trt.src --------------------------------------
