001package org.nuxeo.ecm.platform.exalead.ws; 002 003import java.io.Serializable; 004import java.util.ArrayList; 005import java.util.List; 006import java.util.Map; 007 008import javax.jws.WebMethod; 009import javax.jws.WebParam; 010import javax.jws.WebService; 011import javax.jws.soap.SOAPBinding; 012import javax.jws.soap.SOAPBinding.Style; 013 014import org.nuxeo.ecm.core.api.CoreSession; 015import org.nuxeo.ecm.core.api.DataModel; 016import org.nuxeo.ecm.core.api.DocumentModel; 017import org.nuxeo.ecm.core.api.DocumentModelList; 018import org.nuxeo.ecm.core.api.IdRef; 019import org.nuxeo.ecm.core.api.IterableQueryResult; 020import org.nuxeo.ecm.core.api.impl.LifeCycleFilter; 021import org.nuxeo.ecm.core.query.sql.NXQL; 022import org.nuxeo.ecm.platform.api.ws.DocumentBlob; 023import org.nuxeo.ecm.platform.api.ws.DocumentDescriptor; 024import org.nuxeo.ecm.platform.api.ws.session.WSRemotingSession; 025import org.nuxeo.ecm.platform.exalead.ws.api.WSExalead; 026import org.nuxeo.ecm.platform.indexing.gateway.ws.UUIDPage; 027import org.nuxeo.ecm.platform.indexing.gateway.ws.WSIndexingGatewayBean; 028 029@WebService(name = "WSExaleadInterface", serviceName = "WSExaleadService") 030@SOAPBinding(style = Style.DOCUMENT) 031public class WSExaleadBean extends WSIndexingGatewayBean implements WSExalead { 032 033 /** 034 * 035 */ 036 private static final long serialVersionUID = 87687687681L; 037 038 @Override 039 @WebMethod 040 public DocumentDescriptor[] getChildren(@WebParam(name = "sessionId") String sessionId, 041 @WebParam(name = "uuid") String uuid) { 042 WSRemotingSession rs = initSession(sessionId); 043 LifeCycleFilter filter = new LifeCycleFilter("deleted", false); 044 DocumentModelList docList = rs.getDocumentManager().getChildren(new IdRef(uuid), null, null, filter, null); 045 DocumentDescriptor[] docs = new DocumentDescriptor[docList.size()]; 046 int i = 0; 047 for (DocumentModel doc : docList) { 048 docs[i++] = new DocumentDescriptor(doc); 049 } 050 return docs; 051 } 052 053 @Override 054 @WebMethod 055 public UUIDPage getRecursiveChildrenUUIDsByPage(@WebParam(name = "sessionId") String sid, 056 @WebParam(name = "uuid") String uuid, @WebParam(name = "page") int page, 057 @WebParam(name = "pageSize") int pageSize) { 058 059 CoreSession session = initSession(sid).getDocumentManager(); 060 061 List<String> uuids = new ArrayList<String>(); 062 IdRef parentRef = new IdRef(uuid); 063 DocumentModel parent = session.getDocument(parentRef); 064 String path = parent.getPathAsString(); 065 066 String query = "select ecm:uuid from Document where ecm:path startswith '" + path 067 + " AND ecm:currentLifeCycleState != 'deleted' order by ecm:uuid"; 068 069 IterableQueryResult result = session.queryAndFetch(query, "NXQL"); 070 boolean hasMore = false; 071 try { 072 if (page > 1) { 073 int skip = (page - 1) * pageSize; 074 result.skipTo(skip); 075 } 076 077 for (Map<String, Serializable> record : result) { 078 uuids.add((String) record.get(NXQL.ECM_UUID)); 079 if (uuids.size() == pageSize) { 080 hasMore = true; 081 break; 082 } 083 } 084 } finally { 085 result.close(); 086 } 087 return new UUIDPage(uuids.toArray(new String[uuids.size()]), page, hasMore); 088 } 089 090 @Override 091 @WebMethod 092 public String[] getRecursiveChildrenUUIDs(@WebParam(name = "sessionId") String sid, 093 @WebParam(name = "uuid") String uuid) { 094 095 CoreSession session = initSession(sid).getDocumentManager(); 096 097 List<String> uuids = new ArrayList<String>(); 098 IdRef parentRef = new IdRef(uuid); 099 DocumentModel parent = session.getDocument(parentRef); 100 String path = parent.getPathAsString(); 101 102 String query = "select ecm:uuid from Document where ecm:path startswith '" + path 103 + "' AND ecm:currentLifeCycleState != 'deleted' order by ecm:uuid"; 104 105 IterableQueryResult result = session.queryAndFetch(query, "NXQL"); 106 107 try { 108 for (Map<String, Serializable> record : result) { 109 uuids.add((String) record.get(NXQL.ECM_UUID)); 110 } 111 } finally { 112 result.close(); 113 } 114 115 return uuids.toArray(new String[uuids.size()]); 116 } 117 118}