001/* 002 * (C) Copyright 2014 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 * <a href="mailto:glefevre@nuxeo.com">Gildas</a> 018 */ 019package org.nuxeo.ecm.automation.core.operations.collections; 020 021import java.util.HashMap; 022import java.util.Map; 023 024import org.nuxeo.ecm.automation.AutomationService; 025import org.nuxeo.ecm.automation.OperationChain; 026import org.nuxeo.ecm.automation.OperationContext; 027import org.nuxeo.ecm.automation.OperationException; 028import org.nuxeo.ecm.automation.OperationParameters; 029import org.nuxeo.ecm.automation.core.Constants; 030import org.nuxeo.ecm.automation.core.annotations.Context; 031import org.nuxeo.ecm.automation.core.annotations.Operation; 032import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 033import org.nuxeo.ecm.automation.core.annotations.Param; 034import org.nuxeo.ecm.automation.core.operations.services.DocumentPageProviderOperation; 035import org.nuxeo.ecm.automation.core.util.PageProviderHelper; 036import org.nuxeo.ecm.automation.core.util.StringList; 037import org.nuxeo.ecm.automation.jaxrs.io.documents.PaginableDocumentModelListImpl; 038import org.nuxeo.ecm.collections.api.CollectionConstants; 039 040/** 041 * Class for the operation to get the collections matching the searching terms. 042 * 043 * @since 5.9.4 044 */ 045@Operation(id = GetCollectionsOperation.ID, category = Constants.CAT_DOCUMENT, label = "Get collections", description = "Get the list of all the collections visible by the currentUser. " 046 + "This is returning a list of collections.", aliases = { "Collection.GetCollections" }) 047public class GetCollectionsOperation { 048 049 public static final String ID = "User.GetCollections"; 050 051 @Param(name = "searchTerm") 052 protected String searchTerm; 053 054 @Context 055 protected OperationContext ctx; 056 057 @Context 058 protected AutomationService service; 059 060 @OperationMethod 061 public PaginableDocumentModelListImpl run() throws OperationException { 062 StringList sl = new StringList(); 063 sl.add(searchTerm + (searchTerm.endsWith("%") ? "" : "%")); 064 sl.add(PageProviderHelper.CURRENT_USERID_PATTERN); 065 OperationChain chain = new OperationChain("operation"); 066 Map<String, Object> vars = new HashMap<>(); 067 vars.put("queryParams", sl); 068 vars.put("providerName", CollectionConstants.COLLECTION_PAGE_PROVIDER); 069 OperationParameters oparams = new OperationParameters(DocumentPageProviderOperation.ID, vars); 070 chain.add(oparams); 071 return (PaginableDocumentModelListImpl) service.run(ctx, chain); 072 } 073}