Delimiter //
/**
 * Accounts ref data normalization
 * 
 */

Drop Procedure If Exists LOADER_EDMINDEX_NORMALIZE //
Create Procedure LOADER_EDMINDEX_NORMALIZE (
    In batchnum Int
)
Begin
    MAIN_EDMINDEX_NORMALIZE: Begin


		call LOADER_CREATE_TABLE_EDMINDEX_ENTRIES_HAS_DOCUMENTS(); -- purge de la table des ecritures
		call LOADER_CREATE_TABLE_EDMINDEX_DOCUMENTS_HAS_KEYWORDS(); -- purge des mot clés
		call LOADER_CREATE_TABLE_EDMINDEX_DOCUMENTS_METADATA(); -- purge des méta data

		call LOADER_EDMINDEX_NORMALIZE_CHECK_ACCOUNTS_PROVIDED(batchnum); 
        Call LOADER_EDMINDEX_NORMALIZE_TYPE_PROVIDED(batchnum);
        Call LOADER_EDMINDEX_NORMALIZE_MAP_MIME_TYPE_PROVIDED(batchnum);
        Call LOADER_EDMINDEX_NORMALIZE_MAP_ACCOUNT_REF_PROVIDED(batchnum);

        Call LOADER_EDMINDEX_NORMALIZE_MAP_KEYWORDS_PROVIDED(batchnum);

        Call LOADER_EDMINDEX_NORMALIZE_MAP_ENTRIES_ACC_EXT_REF_PROVIDED(batchnum); -- doit être appelée apres LOADER_EDMINDEX_NORMALIZE_MAP_ACCOUNT_REF_PROVIDED
        Call LOADER_EDMINDEX_NORMALIZE_MAP_ENTRIES_REF_PROVIDED(batchnum); -- doit être appelée apres LOADER_EDMINDEX_NORMALIZE_MAP_ACCOUNT_REF_PROVIDED

		call LOADER_EDMINDEX_NORMALIZE_CHECK_ENTRY_EXISTS(batchnum); --  doit être appelé apres LOADER_EDMINDEX_NORMALIZE_MAP_ENTRIES_ACC_EXT_REF_PROVIDED 
																	-- et LOADER_EDMINDEX_NORMALIZE_MAP_ENTRIES_REF_PROVIDED

        Call LOADER_EDMINDEX_NORMALIZE_MAP_ENTRIES_DOCUMENT_PROVIDED(batchnum); -- doit être appelée apres LOADER_EDMINDEX_NORMALIZE_MAP_ENTRIES_REF_PROVIDED

        Call LOADER_EDMINDEX_NORMALIZE_MAP_METADATA_PROVIDED(batchnum); -- doit être appelé apres  LOADER_EDMINDEX_NORMALIZE_MAP_ENTRIES_DOCUMENT_PROVIDED 
        call LOADER_EDMINDEX_NORMALIZE_CHECK_METADATA_EMPTY(batchnum); 
        Call LOADER_EDMINDEX_NORMALIZE_CHECK_METADATA_UNIQUE(batchnum); -- doit être appelé apres  LOADER_EDMINDEX_NORMALIZE_MAP_ENTRIES_DOCUMENT_PROVIDED et LOADER_EDMINDEX_NORMALIZE_MAP_METADATA_PROVIDED
    End;

End//
Delimiter ;