# Path: OGRgeoConverter/models.py
# class ConversionJob(models.Model):
#     job_identifier = models.ForeignKey(JobIdentifier)
# 
#     export_format_name = models.CharField(max_length=50)
#     source_srs = models.IntegerField()
#     target_srs = models.IntegerField()
#     simplify_parameter = models.DecimalField(max_digits=16, decimal_places=10)
# 
#     upload_folder_path = models.CharField(max_length=128)
#     extract_folder_path = models.CharField(max_length=128)
#     output_folder_path = models.CharField(max_length=128)
#     download_folder_path = models.CharField(max_length=128)
# 
#     class Meta:
#         db_table = 'ogrgeoconverter_conversion_jobs'
# 
#     @staticmethod
#     def get_conversion_job(job_identifier):
#         return ConversionJob.objects.filter(job_identifier=job_identifier)
# 
# Path: OGRgeoConverter/models.py
# class ConversionJobFolder(models.Model):
#     conversion_job = models.ForeignKey(ConversionJob)
# 
#     folder_path = models.CharField(max_length=1024)
# 
#     class Meta:
#         db_table = 'ogrgeoconverter_conversion_job_folders'
#         unique_together = (('conversion_job', 'folder_path'),)
# 
#     @staticmethod
#     def get_conversion_job_folders(conversion_job):
#         return ConversionJobFolder.objects.filter(
#             conversion_job=conversion_job)
# 
#     @staticmethod
#     def get_conversion_job_folder_by_path(conversion_job, folder_path):
#         return ConversionJobFolder.objects.filter(
#             conversion_job=conversion_job,
#             folder_path=folder_path)
# 
# class ConversionJobFileMatch(models.Model):
#     conversion_job_folder = models.ForeignKey(ConversionJobFolder)
# 
#     identified_format_name = models.CharField(max_length=50)
#     is_archive = models.BooleanField()
#     is_valid = models.BooleanField()
#     in_process_id = models.CharField(max_length=50)
# 
#     class Meta:
#         db_table = 'ogrgeoconverter_conversion_job_file_matches'
# 
# class ConversionJobFile(models.Model):
#     conversion_job = models.ForeignKey(ConversionJob)
#     file_match = models.ForeignKey(ConversionJobFileMatch)
# 
#     file_id = models.CharField(max_length=50)
#     file_name = models.CharField(max_length=1024)
#     matched_file_name = models.CharField(max_length=1024)
#     is_uploaded = models.BooleanField()
#     is_processed = models.BooleanField()
#     is_removed = models.BooleanField()
# 
#     class Meta:
#         db_table = 'ogrgeoconverter_conversion_job_files'
#         unique_together = (('conversion_job', 'file_id'),)
# 
#     @staticmethod
#     def get_conversion_job_files_by_conversion_job(conversion_job):
#         return ConversionJobFile.objects.filter(conversion_job=conversion_job)
# 
#     @staticmethod
#     def get_conversion_job_files_by_file_match(file_match):
#         return ConversionJobFile.objects.filter(file_match=file_match)
# 
# class ConversionJobFileIdTracker(models.Model):
#     conversion_job = models.ForeignKey(ConversionJob)
#     file_id = models.AutoField(primary_key=True)
# 
#     class Meta:
#         db_table = 'ogrgeoconverter_conversion_job_file_id_tracking'
# 
# Path: OGRgeoConverter/models.py
# class ConversionJobUrl(models.Model):
#     conversion_job = models.ForeignKey(ConversionJob)
# 
#     url_id = models.CharField(max_length=50)
#     url = models.CharField(max_length=2048)
#     is_processed = models.BooleanField()
#     is_removed = models.BooleanField()
# 
#     class Meta:
#         db_table = 'ogrgeoconverter_conversion_job_urls'
# 
#     @staticmethod
#     def get_conversion_job_urls(conversion_job):
#         return ConversionJobUrl.objects.filter(conversion_job=conversion_job)
# 
# Path: OGRgeoConverter/models.py
# class ConversionJobShellParameter(ShellParameter):
#     conversion_job = models.ForeignKey(ConversionJob)
# 
#     class Meta(ShellParameter.Meta):
#         db_table = 'ogrgeoconverter_conversion_job_shell_parameters'
#         unique_together = (
#             ('conversion_job',
#              'parameter_name',
#              'parameter_value'),
#         )
# 
#     @staticmethod
#     def get_conversion_job_shell_parameters(conversion_job):
#         return ConversionJobShellParameter.objects.filter(
#             conversion_job=conversion_job)


from OGRgeoConverter.models import ConversionJob
from OGRgeoConverter.models import ConversionJobFolder, ConversionJobFileMatch, ConversionJobFile, ConversionJobFileIdTracker
from OGRgeoConverter.models import ConversionJobUrl
from OGRgeoConverter.models import ConversionJobShellParameter

    def __get_conversion_job_query_set(self):
        conversion_jobs = ConversionJob.get_conversion_job(
            self.__job_identifier)

        if len(conversion_jobs) == 0:
            conversion_job = ConversionJob()
            conversion_job.job_identifier = self.__job_identifier
            conversion_job.source_srs = 0
            conversion_job.target_srs = 0
            conversion_job.simplify_parameter = 0
            conversion_job.save()
            conversion_jobs = ConversionJob.get_conversion_job(
                self.__job_identifier)

        if len(conversion_jobs) == 1:
            return conversion_jobs
        else:
            raise Exception("Number of found conversion_jobs must be 1")

    def __get_conversion_job_folder_query_set(self, folder_path):
        conversion_job = self.__get_conversion_job_query_set()[0]
        conversion_job_folders = ConversionJobFolder.get_conversion_job_folder_by_path(
            conversion_job, folder_path)

        if len(conversion_job_folders) == 0:
            conversion_job_folder = ConversionJobFolder()
            conversion_job_folder.conversion_job = conversion_job
            conversion_job_folder.folder_path = folder_path
            conversion_job_folder.save()

# Path: OGRgeoConverter/models.py
# class ConversionJob(models.Model):
#     job_identifier = models.ForeignKey(JobIdentifier)
# 
#     export_format_name = models.CharField(max_length=50)
#     source_srs = models.IntegerField()
#     target_srs = models.IntegerField()
#     simplify_parameter = models.DecimalField(max_digits=16, decimal_places=10)
# 
#     upload_folder_path = models.CharField(max_length=128)
#     extract_folder_path = models.CharField(max_length=128)
#     output_folder_path = models.CharField(max_length=128)
#     download_folder_path = models.CharField(max_length=128)
# 
#     class Meta:
#         db_table = 'ogrgeoconverter_conversion_jobs'
# 
#     @staticmethod
#     def get_conversion_job(job_identifier):
#         return ConversionJob.objects.filter(job_identifier=job_identifier)
# 
# Path: OGRgeoConverter/models.py
# class ConversionJobFolder(models.Model):
#     conversion_job = models.ForeignKey(ConversionJob)
# 
#     folder_path = models.CharField(max_length=1024)
# 
#     class Meta:
#         db_table = 'ogrgeoconverter_conversion_job_folders'
#         unique_together = (('conversion_job', 'folder_path'),)
# 
#     @staticmethod
#     def get_conversion_job_folders(conversion_job):
#         return ConversionJobFolder.objects.filter(
#             conversion_job=conversion_job)
# 
#     @staticmethod
#     def get_conversion_job_folder_by_path(conversion_job, folder_path):
#         return ConversionJobFolder.objects.filter(
#             conversion_job=conversion_job,
#             folder_path=folder_path)
# 
# class ConversionJobFileMatch(models.Model):
#     conversion_job_folder = models.ForeignKey(ConversionJobFolder)
# 
#     identified_format_name = models.CharField(max_length=50)
#     is_archive = models.BooleanField()
#     is_valid = models.BooleanField()
#     in_process_id = models.CharField(max_length=50)
# 
#     class Meta:
#         db_table = 'ogrgeoconverter_conversion_job_file_matches'
# 
# class ConversionJobFile(models.Model):
#     conversion_job = models.ForeignKey(ConversionJob)
#     file_match = models.ForeignKey(ConversionJobFileMatch)
# 
#     file_id = models.CharField(max_length=50)
#     file_name = models.CharField(max_length=1024)
#     matched_file_name = models.CharField(max_length=1024)
#     is_uploaded = models.BooleanField()
#     is_processed = models.BooleanField()
#     is_removed = models.BooleanField()
# 
#     class Meta:
#         db_table = 'ogrgeoconverter_conversion_job_files'
#         unique_together = (('conversion_job', 'file_id'),)
# 
#     @staticmethod
#     def get_conversion_job_files_by_conversion_job(conversion_job):
#         return ConversionJobFile.objects.filter(conversion_job=conversion_job)
# 
#     @staticmethod
#     def get_conversion_job_files_by_file_match(file_match):
#         return ConversionJobFile.objects.filter(file_match=file_match)
# 
# class ConversionJobFileIdTracker(models.Model):
#     conversion_job = models.ForeignKey(ConversionJob)
#     file_id = models.AutoField(primary_key=True)
# 
#     class Meta:
#         db_table = 'ogrgeoconverter_conversion_job_file_id_tracking'
# 
# Path: OGRgeoConverter/models.py
# class ConversionJobUrl(models.Model):
#     conversion_job = models.ForeignKey(ConversionJob)
# 
#     url_id = models.CharField(max_length=50)
#     url = models.CharField(max_length=2048)
#     is_processed = models.BooleanField()
#     is_removed = models.BooleanField()
# 
#     class Meta:
#         db_table = 'ogrgeoconverter_conversion_job_urls'
# 
#     @staticmethod
#     def get_conversion_job_urls(conversion_job):
#         return ConversionJobUrl.objects.filter(conversion_job=conversion_job)
# 
# Path: OGRgeoConverter/models.py
# class ConversionJobShellParameter(ShellParameter):
#     conversion_job = models.ForeignKey(ConversionJob)
# 
#     class Meta(ShellParameter.Meta):
#         db_table = 'ogrgeoconverter_conversion_job_shell_parameters'
#         unique_together = (
#             ('conversion_job',
#              'parameter_name',
#              'parameter_value'),
#         )
# 
#     @staticmethod
#     def get_conversion_job_shell_parameters(conversion_job):
#         return ConversionJobShellParameter.objects.filter(
#             conversion_job=conversion_job)


# Path: OGRgeoConverter/modelhandlers/jobhandler.py
from OGRgeoConverter.models import ConversionJob
from OGRgeoConverter.models import ConversionJobFolder, ConversionJobFileMatch, ConversionJobFile, ConversionJobFileIdTracker
from OGRgeoConverter.models import ConversionJobUrl
from OGRgeoConverter.models import ConversionJobShellParameter


    def __get_conversion_job_query_set(self):
        conversion_jobs = ConversionJob.get_conversion_job(
            self.__job_identifier)

        if len(conversion_jobs) == 0:
            conversion_job = ConversionJob()
            conversion_job.job_identifier = self.__job_identifier
            conversion_job.source_srs = 0
            conversion_job.target_srs = 0
            conversion_job.simplify_parameter = 0
            conversion_job.save()
            conversion_jobs = ConversionJob.get_conversion_job(
                self.__job_identifier)

        if len(conversion_jobs) == 1:
            return conversion_jobs
        else:
            raise Exception("Number of found conversion_jobs must be 1")

    def __get_conversion_job_folder_query_set(self, folder_path):
        conversion_job = self.__get_conversion_job_query_set()[0]
        conversion_job_folders = ConversionJobFolder.get_conversion_job_folder_by_path(
            conversion_job, folder_path)

        if len(conversion_job_folders) == 0:
            conversion_job_folder = ConversionJobFolder()
            conversion_job_folder.conversion_job = conversion_job
            conversion_job_folder.folder_path = folder_path
            conversion_job_folder.save()

            conversion_job_folders = ConversionJobFolder.get_conversion_job_folder_by_path(