__author__ = 'sulantha'

import Config.ManagerPageTableConfig as mPTConfig
from DBUtil.PageTableUpdater import PageTableUpdater

for entity in mPTConfig.entityList:
    PageTableUpdater.updateEntity(entity,
                                  mPTConfig.entityTableDictionary[entity],
                                  mPTConfig.entityColumnDictionary[entity])

from FileUtil.SourceBuilders import MunicipalityTableTemplateBuilder
from FileUtil.SourceBuilders import CountySourceBuilder
from FileUtil.SourceBuilders import CountyTableTemplateBuilder
from FileUtil.SourceBuilders import OperatorSourceBuilder
from FileUtil.SourceBuilders import OperatorTableTemplateBuilder

newIds = PageTableAccessor.getNewIds()

for entity in newIds:
    if entity == 'wells':
        for wellID in newIds[entity]:
            tableTemplateBuilder = WellTableTemplateBuilder.WellTableTemplateBuilder(wellID)
            tableTemplateBuilder.buildTableTemplates()
            sourceBuilder = WellSourceBuilder.WellSourceBuilder(wellID)
            sourceBuilder.buildMainSource()
            PageTableUpdater.setUpdateSuccess(wellID)
    elif entity == 'county':
        for conID in newIds[entity]:
            tableTemplateBuilder = CountyTableTemplateBuilder.CountyTableTemplateBuilder(conID)
            tableTemplateBuilder.buildTableTemplates()
            sourceBuilder = CountySourceBuilder.CountySourceBuilder(conID)
            sourceBuilder.buildMainSource()
            PageTableUpdater.setUpdateSuccess(conID)
    elif entity == 'municipality':
        for munID in newIds[entity]:
            tableTemplateBuilder = MunicipalityTableTemplateBuilder.MunicipalityTableTemplateBuilder(munID)
            tableTemplateBuilder.buildTableTemplates()
            sourceBuilder = MunicipalitySourceBuilder.MunicipalitySourceBuilder(munID)
            sourceBuilder.buildMainSource()
            PageTableUpdater.setUpdateSuccess(munID)
    elif entity == 'operator':