<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang  
    $Date: 2013-9-27 下午02:33:35  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    t.contract_lease_item_id,
                    t.lease_item_id,
                    i.full_name,
                    'LEASE_ITEM' item_type,
                    t.lease_item_id item_id,
                    ${@content_id} content_id,
                    ca.content_asset_id,
                    (
                        CASE
                            WHEN ca.CONTENT_ID=${@content_id}
                            THEN 'Y'
                            ELSE 'N'
                        END) selected_flag
                FROM
                    con_contract_lease_item t,
                    hls_lease_item i,
                    con_contract_content_asset ca #WHERE_CLAUSE#
                ORDER BY
                    i.lease_item_code
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="contract_lease_item_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTRACT_LEASE_ITEM_ID" required="true"/>
        <bm:field name="lease_item_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="LEASE_ITEM_ID" required="true"/>
        <bm:field name="full_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FULL_NAME"/>
        <bm:field name="item_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="ITEM_TYPE"/>
        <bm:field name="item_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="ITEM_ID"/>
        <bm:field name="content_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTENT_ID"/>
        <bm:field name="content_asset_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTENT_ASSET_ID"/>
        <bm:field name="selected_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="SELECTED_FLAG"/>
    </bm:fields>
    <bm:query-fields>
        <bm:query-field field="full_name" queryOperator="like"/>
    </bm:query-fields>
    <bm:data-filters>
        <bm:data-filter enforceOperations="query" expression="t.contract_id=${@contract_id} and t.lease_item_id = i.lease_item_id and exists (select 1 from con_contract_bp d where d.record_id = ${@con_contract_bp_id} and d.bp_category != &apos;PLEDGER&apos;) and t.lease_item_id = ca.item_id(+)    and ca.item_type(+) = &apos;LEASE_ITEM&apos; and ca.content_id(+)=${@content_id}"/>
    </bm:data-filters>
</bm:model>
