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.DataModel; 034import org.nuxeo.ecm.core.api.DocumentModel; 035import org.nuxeo.ecm.core.api.DocumentModelList; 036import org.nuxeo.ecm.core.api.IdRef; 037import org.nuxeo.ecm.core.api.IterableQueryResult; 038import org.nuxeo.ecm.core.api.impl.LifeCycleFilter; 039import org.nuxeo.ecm.core.query.sql.NXQL; 040import org.nuxeo.ecm.platform.api.ws.DocumentBlob; 041import org.nuxeo.ecm.platform.api.ws.DocumentDescriptor; 042import org.nuxeo.ecm.platform.api.ws.session.WSRemotingSession; 043import org.nuxeo.ecm.platform.exalead.ws.api.WSExalead; 044import org.nuxeo.ecm.platform.indexing.gateway.ws.UUIDPage; 045import org.nuxeo.ecm.platform.indexing.gateway.ws.WSIndexingGatewayBean; 046 047@WebService(name = "WSExaleadInterface", serviceName = "WSExaleadService") 048@SOAPBinding(style = Style.DOCUMENT) 049public class WSExaleadBean extends WSIndexingGatewayBean implements WSExalead { 050 051 /** 052 * 053 */ 054 private static final long serialVersionUID = 87687687681L; 055 056 protected static boolean DEPRECATION_DONE; 057 058 protected static void logDeprecation() { 059 if (!DEPRECATION_DONE) { 060 DEPRECATION_DONE = true; 061 log.warn("The SOAP endpoint /webservices/indexinggateway" 062 + " is DEPRECATED since Nuxeo 9.3 and will be removed in a future version"); 063 } 064 } 065 066 @Override 067 @WebMethod 068 public DocumentDescriptor[] getChildren(@WebParam(name = "sessionId") String sessionId, 069 @WebParam(name = "uuid") String uuid) { 070 logDeprecation(); 071 WSRemotingSession rs = initSession(sessionId); 072 LifeCycleFilter filter = new LifeCycleFilter("deleted", false); 073 DocumentModelList docList = rs.getDocumentManager().getChildren(new IdRef(uuid), null, null, filter, null); 074 DocumentDescriptor[] docs = new DocumentDescriptor[docList.size()]; 075 int i = 0; 076 for (DocumentModel doc : docList) { 077 docs[i++] = new DocumentDescriptor(doc); 078 } 079 return docs; 080 } 081 082 @Override 083 @WebMethod 084 public UUIDPage getRecursiveChildrenUUIDsByPage(@WebParam(name = "sessionId") String sid, 085 @WebParam(name = "uuid") String uuid, @WebParam(name = "page") int page, 086 @WebParam(name = "pageSize") int pageSize) { 087 logDeprecation(); 088 089 CoreSession session = initSession(sid).getDocumentManager(); 090 091 List<String> uuids = new ArrayList<String>(); 092 IdRef parentRef = new IdRef(uuid); 093 DocumentModel parent = session.getDocument(parentRef); 094 String path = parent.getPathAsString(); 095 096 String query = "select ecm:uuid from Document where ecm:path startswith '" + path 097 + " AND ecm:currentLifeCycleState != 'deleted' order by ecm:uuid"; 098 099 IterableQueryResult result = session.queryAndFetch(query, "NXQL"); 100 boolean hasMore = false; 101 try { 102 if (page > 1) { 103 int skip = (page - 1) * pageSize; 104 result.skipTo(skip); 105 } 106 107 for (Map<String, Serializable> record : result) { 108 uuids.add((String) record.get(NXQL.ECM_UUID)); 109 if (uuids.size() == pageSize) { 110 hasMore = true; 111 break; 112 } 113 } 114 } finally { 115 result.close(); 116 } 117 return new UUIDPage(uuids.toArray(new String[uuids.size()]), page, hasMore); 118 } 119 120 @Override 121 @WebMethod 122 public String[] getRecursiveChildrenUUIDs(@WebParam(name = "sessionId") String sid, 123 @WebParam(name = "uuid") String uuid) { 124 logDeprecation(); 125 126 CoreSession session = initSession(sid).getDocumentManager(); 127 128 List<String> uuids = new ArrayList<String>(); 129 IdRef parentRef = new IdRef(uuid); 130 DocumentModel parent = session.getDocument(parentRef); 131 String path = parent.getPathAsString(); 132 133 String query = "select ecm:uuid from Document where ecm:path startswith '" + path 134 + "' AND ecm:currentLifeCycleState != 'deleted' order by ecm:uuid"; 135 136 IterableQueryResult result = session.queryAndFetch(query, "NXQL"); 137 138 try { 139 for (Map<String, Serializable> record : result) { 140 uuids.add((String) record.get(NXQL.ECM_UUID)); 141 } 142 } finally { 143 result.close(); 144 } 145 146 return uuids.toArray(new String[uuids.size()]); 147 } 148 149}