001package org.nuxeo.template.xdocreport.jaxrs; 002 003import java.util.ArrayList; 004import java.util.List; 005 006import org.apache.commons.logging.Log; 007import org.apache.commons.logging.LogFactory; 008import org.nuxeo.ecm.core.api.CoreSession; 009import org.nuxeo.ecm.core.api.DocumentModel; 010import org.nuxeo.ecm.core.api.DocumentModelList; 011import org.nuxeo.ecm.webengine.model.impl.DefaultObject; 012import org.nuxeo.template.api.adapters.TemplateSourceDocument; 013 014/** 015 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a> 016 */ 017public abstract class AbstractResourceService extends DefaultObject { 018 019 protected static Log log = LogFactory.getLog(AbstractResourceService.class); 020 021 protected CoreSession session; 022 023 public AbstractResourceService(CoreSession session) { 024 this.session = session; 025 } 026 027 protected CoreSession getCoreSession() { 028 return session; 029 } 030 031 protected List<TemplateSourceDocument> getTemplates() { 032 List<TemplateSourceDocument> result = new ArrayList<TemplateSourceDocument>(); 033 CoreSession session = getCoreSession(); 034 StringBuffer sb = new StringBuffer( 035 "select * from Document where ecm:mixinType = 'Template' AND ecm:currentLifeCycleState != 'deleted'"); 036 sb.append(" AND tmpl:templateType = 'XDocReportProcessor'"); 037 DocumentModelList docs = session.query(sb.toString()); 038 for (DocumentModel doc : docs) { 039 TemplateSourceDocument tmpl = doc.getAdapter(TemplateSourceDocument.class); 040 if (tmpl != null) { 041 result.add(tmpl); 042 } 043 } 044 return result; 045 } 046 047}