# Path: OGRgeoConverter/models.py
# class JobIdentifier(models.Model):
#     session_key = models.CharField(max_length=50, blank=False)
#     client_job_token = models.CharField(max_length=50, blank=False)
#     job_id = models.CharField(max_length=50, unique=True, blank=False)
#     creation_time = models.DateTimeField()
# 
#     def __unicode__(self):
#         return self.job_id
# 
#     class Meta:
#         db_table = 'ogrgeoconverter_conversion_job_identification'
#         unique_together = (('session_key', 'client_job_token'),)
# 
#     @staticmethod
#     def get_job_identifier_by_client_job_token(session_key, client_job_token):
#         return JobIdentifier.objects.filter(
#             session_key=session_key,
#             client_job_token=client_job_token)
# 
#     @staticmethod
#     def get_job_identifier_by_job_id(session_key, job_id):
#         return JobIdentifier.objects.filter(
#             session_key=session_key,
#             job_id=job_id)
# 
#     @staticmethod
#     def cleanup_by_date(date_limit):
#         JobIdentifier.objects.filter(creation_time__lt=date_limit).delete()
# 
# Path: OGRgeoConverter/geoconverter/datetimehandler.py
# def get_default_datetime():
# def get_now():


import datetime
import string
import random
import re
from OGRgeoConverter.models import JobIdentifier
from OGRgeoConverter.geoconverter import datetimehandler

def get_new_job_identifier_by_client_job_token(session_key, client_job_token):
    client_job_token = _check_client_job_token(client_job_token)
    job_identifier = JobIdentifier.get_job_identifier_by_client_job_token(
        session_key,
        client_job_token)
    if len(job_identifier) == 0:
        new_job_identifier = JobIdentifier()
        new_job_identifier.session_key = session_key
        new_job_identifier.client_job_token = client_job_token
        new_job_identifier.job_id = _get_random_job_id()
        new_job_identifier.creation_time = datetimehandler.get_now()
        new_job_identifier.save()
        return new_job_identifier
    else:
        return None


def get_job_identifier_by_client_job_token(session_key, client_job_token):
    client_job_token = _check_client_job_token(client_job_token)
    job_identifier = JobIdentifier.get_job_identifier_by_client_job_token(
        session_key,
        client_job_token)
    if len(job_identifier) == 1:
        return job_identifier[0]
    else:
        return None


def get_job_identifier_by_job_id(session_key, job_id):

# Path: OGRgeoConverter/models.py
# class JobIdentifier(models.Model):
#     session_key = models.CharField(max_length=50, blank=False)
#     client_job_token = models.CharField(max_length=50, blank=False)
#     job_id = models.CharField(max_length=50, unique=True, blank=False)
#     creation_time = models.DateTimeField()
# 
#     def __unicode__(self):
#         return self.job_id
# 
#     class Meta:
#         db_table = 'ogrgeoconverter_conversion_job_identification'
#         unique_together = (('session_key', 'client_job_token'),)
# 
#     @staticmethod
#     def get_job_identifier_by_client_job_token(session_key, client_job_token):
#         return JobIdentifier.objects.filter(
#             session_key=session_key,
#             client_job_token=client_job_token)
# 
#     @staticmethod
#     def get_job_identifier_by_job_id(session_key, job_id):
#         return JobIdentifier.objects.filter(
#             session_key=session_key,
#             job_id=job_id)
# 
#     @staticmethod
#     def cleanup_by_date(date_limit):
#         JobIdentifier.objects.filter(creation_time__lt=date_limit).delete()
# 
# Path: OGRgeoConverter/geoconverter/datetimehandler.py
# def get_default_datetime():
# def get_now():


# Path: OGRgeoConverter/jobs/jobidentification.py
import datetime
import string
import random
import re
from OGRgeoConverter.models import JobIdentifier
from OGRgeoConverter.geoconverter import datetimehandler


def get_new_job_identifier_by_client_job_token(session_key, client_job_token):
    client_job_token = _check_client_job_token(client_job_token)
    job_identifier = JobIdentifier.get_job_identifier_by_client_job_token(
        session_key,
        client_job_token)
    if len(job_identifier) == 0:
        new_job_identifier = JobIdentifier()
        new_job_identifier.session_key = session_key
        new_job_identifier.client_job_token = client_job_token
        new_job_identifier.job_id = _get_random_job_id()
        new_job_identifier.creation_time = datetimehandler.get_now()
        new_job_identifier.save()
        return new_job_identifier
    else:
        return None


def get_job_identifier_by_client_job_token(session_key, client_job_token):
    client_job_token = _check_client_job_token(client_job_token)
    job_identifier = JobIdentifier.get_job_identifier_by_client_job_token(
        session_key,
        client_job_token)
    if len(job_identifier) == 1:
        return job_identifier[0]
    else:
        return None


def get_job_identifier_by_job_id(session_key, job_id):

    job_identifier = JobIdentifier.get_job_identifier_by_job_id(