package com.trs.example;

import com.trs.TRSWCMBaseTest;
import com.trs.components.wcm.content.persistent.Document;
import com.trs.components.wcm.content.persistent.Documents;
import com.trs.infra.common.WCMException;
import com.trs.infra.persistent.WCMFilter;

public class ErrorCase extends TRSWCMBaseTest {
    public void errorOnWCMFilter() throws WCMException {
        // 错误代码1，带了关键字Where和Select
        WCMFilter filter1 = new WCMFilter("", "Where DocId>=1", "",
                "Select DocTitle,DocId,CrUser");

        // 错误代码2：Where和Order反了
        WCMFilter filter2 = new WCMFilter("", "DocId desc", "DocId>=1",
                " DocTitle,DocId,CrUser");

        // 错误代码3：需要提取的字段没有在Select中
        WCMFilter filter3 = new WCMFilter("", "DocId>=1 and DocId<=10",
                "DocId desc", "DocId,CrUser");
        Documents documents = Documents.openWCMObjs(null, filter3);
        for (int i = 0, nSize = documents.size(); i < nSize; i++) {
            Document document = (Document) documents.getAt(i);
            // 这时取出的Title肯定为Null，虽然文档有标题，Filter没有指定
            System.out.println("Doctitle：" + document.getTitle());
        }// END For

        // 错误代码4：指定的字段在元素对应的表中不存在，读取集合的时候老没有出现结果，但是后台有异常
        WCMFilter filter4 = new WCMFilter("", "DocId>=1 and DocId<=10",
                "DocId desc", "DocTitle2,DocId,CrUser");
        documents = Documents.openWCMObjs(null, filter4);
        for (int i = 0, nSize = documents.size(); i < nSize; i++) {
            Document document = (Document) documents.getAt(i);
            if(document == null){
                // 永远是走到这个逻辑上
                System.out.println("WCMFilter设置错误？？？");
                continue;
            }
            // 永远走不到这个逻辑
            System.out.println("Doctitle：" + document.getTitle());
        }// END For

    }

    public void queryById() throws WCMException {
        /*
         * 低效方法1：通过集合获取
         */
    }
}
