<?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="Job"  package="performa.orm">
        <IMPORT value="performa.orm.types.*"/>    
        <IMPORT value="oneit.security.*"/>

        <MULTIPLEREFERENCE  name="JobApplications"      type="JobApplication"       backreferenceName="Job" />
        <MULTIPLEREFERENCE  name="AssessmentCriterias"  type="AssessmentCriteria"   backreferenceName="Job" />
        <MULTIPLEREFERENCE  name="CultureCriterias"     type="CultureCriteria"      backreferenceName="Job" />
        <MULTIPLEREFERENCE  name="WorkFlows"            type="WorkFlow"             backreferenceName="Job" />
        
        <TRANSIENT  name="Email"                    type="String"           validators="Email"  />
        <TRANSIENT  name="Password"                 type="String"/>
        <TRANSIENT  name="ConfirmPassword"          type="String"/>
        <TRANSIENT  name="CompletedDetails"         type="Boolean"          defaultValue="Boolean.FALSE"/>
        <TRANSIENT  name="CompletedRequirements"    type="Boolean"          defaultValue="Boolean.FALSE"/>
        <TRANSIENT  name="CompletedCulture"         type="Boolean"          defaultValue="Boolean.FALSE"/>
        <TRANSIENT  name="CompletedAssessmentType"  type="Boolean"          defaultValue="Boolean.FALSE"/>
        <TRANSIENT  name="SaveAssessmentTemplate"   type="Boolean"          defaultValue="Boolean.FALSE"/>
        <TRANSIENT  name="SaveCultureTemplate"      type="Boolean"          defaultValue="Boolean.FALSE"/>
        <TRANSIENT  name="FromTemplate"             type="Boolean"          defaultValue="Boolean.FALSE"/>
        <TRANSIENT  name="AssessmentTemplateName"   type="String"/>
        <TRANSIENT  name="CultureTemplateName"      type="String"/>
        <TRANSIENT  name="AppProcessOption"         type="AppProcessOption"     attribHelper="EnumeratedAttributeHelper"/>
        <TRANSIENT  name="RankingCompleted"         type="Boolean"  />
        <TRANSIENT  name="OccupationId"             type="String"  />

        <TRANSIENTSINGLE name="AssessmentTemplate"  type="AssessmentCriteriaTemplate" />
        <TRANSIENTSINGLE name="CultureTemplate"     type="CultureCriteriaTemplate" />
        <TRANSIENTSINGLE name="JobTemplate"         type="Job" />
        <TRANSIENTSINGLE name="AppStatusWorkFlow"   type="WorkFlow" />
        
        <TABLE  name="tl_job"   tablePrefix="object"    polymorphic="FALSE">
            
            <ATTRIB name="JobTitle"                     type="String"           dbcol="job_title"           length="500"    mandatory="true"/>
            <ATTRIB name="JobDescription"               type="String"           dbcol="job_description"     mandatory="true"/>
            <ATTRIB name="JobStatus"                    type="JobStatus"        dbcol="job_status"          attribHelper="EnumeratedAttributeHelper"    mandatory="true"/>
            <ATTRIB name="OpenDate"                     type="Date"             dbcol="open_date"/>
            <ATTRIB name="ApplyBy"                      type="Date"             dbcol="apply_by"/>
            <ATTRIB name="IncludeAssessmentCriteria"    type="Boolean"          dbcol="include_assessment_criteria" mandatory="true"    defaultValue="Boolean.TRUE"/>
            <ATTRIB name="AssessmentType"               type="AssessmentType"   dbcol="assessment_type"     attribHelper="EnumeratedAttributeHelper"    mandatory="true"    defaultValue="AssessmentType.COMPREHENSIVE"/>
            <ATTRIB name="RandomKey"                    type="String"           dbcol="random_key"          length="10"/>
            <ATTRIB name="JobType"                      type="JobType"          dbcol="job_type"            attribHelper="EnumeratedAttributeHelper"    mandatory="true"    defaultValue="JobType.FULL_TIME"/>
            <ATTRIB name="ReferenceNumber"              type="String"           dbcol="ref_number"          length="100"/>
            <ATTRIB name="LastStatusChangeDate"         type="Date"             dbcol="last_status_change_date"/>
            <ATTRIB name="Remote"                       type="Boolean"          dbcol="remote"              defaultValue="Boolean.FALSE"/>
            <ATTRIB name="City"                         type="String"           dbcol="city"                length="100"/>
            <ATTRIB name="PostCode"                     type="String"           dbcol="postcode"            length="100"/>
            <ATTRIB name="ExpectedCandidateRadius"      type="LocationRadius"   dbcol="location_radius"     defaultValue="LocationRadius.KM100" attribHelper="EnumeratedAttributeHelper"    mandatory="true"/>
            <ATTRIB name="State"                        type="State"            dbcol="state"               defaultValue="State.WA"             attribHelper="EnumeratedAttributeHelper"/>
            <ATTRIB name="Country"                      type="Countries"        dbcol="country"             defaultValue="Countries.AU"         attribHelper="EnumeratedAttributeHelper"/>
            <ATTRIB name="RequireCV"                    type="Boolean"          dbcol="require_cv"          defaultValue="Boolean.FALSE"/>
            <ATTRIB name="IsManuallyClosed"             type="Boolean"          dbcol="manually_closed"     defaultValue="Boolean.FALSE"/>
            <ATTRIB name="LastEdited"                   type="Date"             dbcol="last_edited"     />
            <ATTRIB name="IsPPJ"                        type="Boolean"          dbcol="is_ppj"              defaultValue="Boolean.FALSE"/>
            <ATTRIB name="Industry"                     type="Industry"         dbcol="industry"            attribHelper="EnumeratedAttributeHelper"/>
            <ATTRIB name="CultureStatement"             type="String"           dbcol="culture_statement"   length="2000"/>
            <ATTRIB name="DraftLocation"                type="DraftLocation"    dbcol="draft_location"      attribHelper="EnumeratedAttributeHelper"/>
            <ATTRIB name="GoogleAddressText"            type="String"           dbcol="google_address_text" length="300"  />

            <SINGLEREFERENCE    name="Level"        type="Level"        dbcol="level_id"            mandatory="false"/>
            <SINGLEREFERENCE    name="Client"       type="Client"       dbcol="client_id"           backreferenceName="Jobs"/>
            <SINGLEREFERENCE    name="JobOwner"     type="CompanyUser"  dbcol="job_owner_id"        />
            <SINGLEREFERENCE    name="CreatedBy"    type="CompanyUser"  dbcol="company_user_id"     />
            <SINGLEREFERENCE    name="HiringTeam"   type="HiringTeam"   dbcol="hiring_team_id"      />
            <SINGLEREFERENCE    name="Occupation"   type="Occupation"   dbcol="occupation_id"       mandatory="true"/>
            <SINGLEREFERENCE    name="ShortenedURL" type="ShortenedURL" dbcol="shortened_url_id"    />
            
        </TABLE>
        
        <SEARCH type="All"  paramFilter="tl_job.object_id is not null"   orderBy="tl_job.object_id"   />
        
        <SEARCH type="JobKey" paramFilter="tl_job.object_id is not null"   singleton="TRUE">
            <PARAM name="ID"    type="Long"     paramFilter="object_id = ${ID} " />
            <PARAM name="Key"   type="String"   paramFilter="random_key = ${Key}" />
        </SEARCH>
            
        <SEARCH type="Company"    paramFilter="tl_job.object_id is not null"  orderBy="tl_job.object_id">
            <TABLE  name="oneit_sec_user_extension" join="oneit_sec_user_extension.object_id = tl_job.company_user_id"/>
            <TABLE  name="tl_company"               join="tl_company.object_id = oneit_sec_user_extension.company_id"/>
            <PARAM name="Company"   type="Company"  transform="Company.getObjectID ()"  paramFilter="tl_company.object_id = ${Company}"/>
        </SEARCH>
        
        <SEARCH type="Details"  paramFilter="tl_job.object_id is not null"   orderBy="tl_job.object_id">
            <PARAM  name="Name"         type="String"   transform=' "%" + Name + "%" '  
                    paramFilter="tl_job.object_id IN (
                                SELECT      tl_job.object_id           
                                FROM        tl_job
                                LEFT JOIN   tl_job_application          ON  tl_job_application.job_id = tl_job.object_id
                                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 
                                tl_job.job_title               ILIKE ${Name} OR 
                                tl_job.ref_number               ILIKE ${Name} OR
                                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>