<?xml version="1.0" encoding="UTF-8"?>

<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='http://www.oneit.com.au/schemas/5.2/BusinessObject.xsd'>

    <BUSINESSCLASS  name="JobApplication"   package="performa.orm">
        <IMPORT value="performa.orm.types.*"/>
                
        <MULTIPLEREFERENCE  name="AssessmentCriteriaAnswers"    type="AssessmentCriteriaAnswer" backreferenceName="JobApplication"  />
        
        <TRANSIENT  name="AppProcessOption"     type="AppProcessOption" attribHelper="EnumeratedAttributeHelper"/>
        <TRANSIENT  name="OverallRank"          type="Integer"  />
        <TRANSIENT  name="RoleFit"              type="Map"      attribHelper="BLOBAttributeHelper"  attribHelperInstance="BLOBAttributeHelper.INSTANCE"/>
        <TRANSIENT  name="RequirementFit"       type="Map"      attribHelper="BLOBAttributeHelper"  attribHelperInstance="BLOBAttributeHelper.INSTANCE"/>
        <TRANSIENT  name="CultureFit"           type="Map"      attribHelper="BLOBAttributeHelper"  attribHelperInstance="BLOBAttributeHelper.INSTANCE"/>
        <TRANSIENT  name="FactorScoreDetails"   type="Map"      attribHelper="BLOBAttributeHelper"  attribHelperInstance="BLOBAttributeHelper.INSTANCE"/>
       
        <TRANSIENTSINGLE name="WorkFlow"        type="WorkFlow"  />

        <TABLE  name="tl_job_application"   tablePrefix="object"    polymorphic="FALSE">
            
            <ATTRIB name="CV"                   type="BinaryContent"        dbcol="cv"                  binaryHandler="loggedin"    attribHelper="BLOBAttributeHelper"  attribHelperInstance="BLOBAttributeHelper.INSTANCE" mandatory="false"/>
            <ATTRIB name="CoverLetter"          type="BinaryContent"        dbcol="cover_letter"        binaryHandler="loggedin"    attribHelper="BLOBAttributeHelper"  attribHelperInstance="BLOBAttributeHelper.INSTANCE" mandatory="false"/>
            <ATTRIB name="ApplicationStatus"    type="ApplicationStatus"    dbcol="application_status"  attribHelper="EnumeratedAttributeHelper"    defaultValue="ApplicationStatus.DRAFT"  mandatory="true"/>
            <ATTRIB name="SubmittedDate"        type="Date"                 dbcol="submitted_date"/>
            <ATTRIB name="GoogleAddressText"    type="String"               dbcol="google_address_text" length="300"/>
            <ATTRIB name="PreferRemote"         type="Boolean"              dbcol="prefer_remote"       defaultValue="Boolean.FALSE"/>
            <ATTRIB name="HappyToRelocate"      type="Boolean"              dbcol="happy_to_relocate"/>
     
            <SINGLEREFERENCE    name="Candidate"    type="Candidate"    dbcol="candidate_id"    backreferenceName="JobApplications" mandatory="true"/>
            <SINGLEREFERENCE    name="Job"          type="Job"          dbcol="job_id"          backreferenceName="JobApplications" mandatory="true"/>

        </TABLE>
        
        <SEARCH type="All"  paramFilter="tl_job_application.object_id is not null"  orderBy="tl_job_application.object_id"   />
        
        <SEARCH type="CandidateJob" paramFilter="tl_job_application.object_id is not null"  singleton="TRUE"    checkTXObjects="TRUE">
            <PARAM name="Candidate" type="Candidate"    transform="Candidate.getObjectID()" paramFilter="candidate_id = ${Candidate} " />
            <PARAM name="Job"       type="Job"          transform="Job.getObjectID()"       paramFilter="job_id = ${Job}" />
        </SEARCH>
            
        <SEARCH type="Details"  paramFilter="tl_job_application.object_id is not null"   orderBy="tl_job_application.object_id">
            <PARAM  name="Name"         type="String"   transform=' "%" + Name + "%" '  
                    paramFilter="tl_job_application.object_id IN (
                                SELECT      tl_job_application.object_id           
                                FROM        tl_job_application
                                LEFT JOIN   oneit_sec_user_extension    ON  oneit_sec_user_extension.object_id = tl_job_application.candidate_id
                                LEFT JOIN   oneit_sec_user              ON  oneit_sec_user.object_id = oneit_sec_user_extension.user_id
                                WHERE 
                                oneit_sec_user_extension.phone  ILIKE ${Name} OR
                                oneit_sec_user.user_name        ILIKE ${Name} OR
                                oneit_sec_user.first_name       ILIKE ${Name} OR
                                oneit_sec_user.last_name        ILIKE ${Name} OR
                                oneit_sec_user.email            ILIKE ${Name})">                
            </PARAM>
        </SEARCH>
    </BUSINESSCLASS>
    
</ROOT>