package performa.search;

import oneit.objstore.*;
import oneit.objstore.rdbms.filters.*;
import oneit.security.SecUser;
import performa.orm.*;


public class SearchWorkFlowTemplate extends BaseSearchWorkFlowTemplate
{
    private static final long serialVersionUID = 0L;
    
    // This constructor should not be called
    public SearchWorkFlowTemplate ()
    {
        // Do not add any code to this, always put it in initialiseNewObject
    }
    
    @Override
    public BaseBusinessClass[] doSearch()
    {
        BaseWorkFlowTemplate.SearchAll  searchByAll     = WorkFlowTemplate.SearchByAll();
        SecUser                         secUser         = SecUser.getTXUser(getTransaction());
        CompanyUser                     companyUser     = secUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
        
        if (isTrue(getOnlyGlobalTemplates()))
        {
            return searchByAll.andIsGlobalTemplate(new EqualsFilter<>(Boolean.TRUE)).search(getTransaction());
        }
        
        return searchByAll.andIsGlobalTemplate(new IsNotNullFilter<>())
                            .andHiringTeam(new EqualsFilter<>(companyUser.getSelectedTeam()))
                            .search(getTransaction());
    }
}