001/* 002 * (C) Copyright 2008 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thierry Delprat 018 */ 019package org.nuxeo.ecm.platform.exalead.ws; 020 021import java.io.Serializable; 022import java.util.ArrayList; 023import java.util.List; 024import java.util.Map; 025 026import javax.jws.WebMethod; 027import javax.jws.WebParam; 028import javax.jws.WebService; 029import javax.jws.soap.SOAPBinding; 030import javax.jws.soap.SOAPBinding.Style; 031 032import org.nuxeo.ecm.core.api.CoreSession; 033import org.nuxeo.ecm.core.api.DocumentModel; 034import org.nuxeo.ecm.core.api.DocumentModelList; 035import org.nuxeo.ecm.core.api.Filter; 036import org.nuxeo.ecm.core.api.IdRef; 037import org.nuxeo.ecm.core.api.IterableQueryResult; 038import org.nuxeo.ecm.core.query.sql.NXQL; 039import org.nuxeo.ecm.platform.api.ws.DocumentDescriptor; 040import org.nuxeo.ecm.platform.api.ws.session.WSRemotingSession; 041import org.nuxeo.ecm.platform.exalead.ws.api.WSExalead; 042import org.nuxeo.ecm.platform.indexing.gateway.ws.UUIDPage; 043import org.nuxeo.ecm.platform.indexing.gateway.ws.WSIndexingGatewayBean; 044 045@WebService(name = "WSExaleadInterface", serviceName = "WSExaleadService") 046@SOAPBinding(style = Style.DOCUMENT) 047public class WSExaleadBean extends WSIndexingGatewayBean implements WSExalead { 048 049 /** 050 * 051 */ 052 private static final long serialVersionUID = 87687687681L; 053 054 protected static boolean DEPRECATION_DONE; 055 056 protected static void logDeprecation() { 057 if (!DEPRECATION_DONE) { 058 DEPRECATION_DONE = true; 059 log.warn("The SOAP endpoint /webservices/indexinggateway" 060 + " is DEPRECATED since Nuxeo 9.3 and will be removed in a future version"); 061 } 062 } 063 064 @Override 065 @WebMethod 066 public DocumentDescriptor[] getChildren(@WebParam(name = "sessionId") String sessionId, 067 @WebParam(name = "uuid") String uuid) { 068 logDeprecation(); 069 WSRemotingSession rs = initSession(sessionId); 070 Filter filter = docModel -> !docModel.isTrashed(); 071 DocumentModelList docList = rs.getDocumentManager().getChildren(new IdRef(uuid), null, null, filter, null); 072 DocumentDescriptor[] docs = new DocumentDescriptor[docList.size()]; 073 int i = 0; 074 for (DocumentModel doc : docList) { 075 docs[i++] = new DocumentDescriptor(doc); 076 } 077 return docs; 078 } 079 080 @Override 081 @WebMethod 082 public UUIDPage getRecursiveChildrenUUIDsByPage(@WebParam(name = "sessionId") String sid, 083 @WebParam(name = "uuid") String uuid, @WebParam(name = "page") int page, 084 @WebParam(name = "pageSize") int pageSize) { 085 logDeprecation(); 086 087 CoreSession session = initSession(sid).getDocumentManager(); 088 089 List<String> uuids = new ArrayList<String>(); 090 IdRef parentRef = new IdRef(uuid); 091 DocumentModel parent = session.getDocument(parentRef); 092 String path = parent.getPathAsString(); 093 094 String query = "select ecm:uuid from Document where ecm:path startswith '" + path 095 + " AND ecm:isTrashed = 0 order by ecm:uuid"; 096 097 IterableQueryResult result = session.queryAndFetch(query, "NXQL"); 098 boolean hasMore = false; 099 try { 100 if (page > 1) { 101 int skip = (page - 1) * pageSize; 102 result.skipTo(skip); 103 } 104 105 for (Map<String, Serializable> record : result) { 106 uuids.add((String) record.get(NXQL.ECM_UUID)); 107 if (uuids.size() == pageSize) { 108 hasMore = true; 109 break; 110 } 111 } 112 } finally { 113 result.close(); 114 } 115 return new UUIDPage(uuids.toArray(new String[uuids.size()]), page, hasMore); 116 } 117 118 @Override 119 @WebMethod 120 public String[] getRecursiveChildrenUUIDs(@WebParam(name = "sessionId") String sid, 121 @WebParam(name = "uuid") String uuid) { 122 logDeprecation(); 123 124 CoreSession session = initSession(sid).getDocumentManager(); 125 126 List<String> uuids = new ArrayList<String>(); 127 IdRef parentRef = new IdRef(uuid); 128 DocumentModel parent = session.getDocument(parentRef); 129 String path = parent.getPathAsString(); 130 131 String query = "select ecm:uuid from Document where ecm:path startswith '" + path 132 + "' AND ecm:isTrashed = 0 order by ecm:uuid"; 133 134 IterableQueryResult result = session.queryAndFetch(query, "NXQL"); 135 136 try { 137 for (Map<String, Serializable> record : result) { 138 uuids.add((String) record.get(NXQL.ECM_UUID)); 139 } 140 } finally { 141 result.close(); 142 } 143 144 return uuids.toArray(new String[uuids.size()]); 145 } 146 147}