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