001/*
002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     bdelbosc
016 */
017package org.nuxeo.elasticsearch.fetcher;
018
019import java.util.Map;
020
021import org.elasticsearch.action.search.SearchResponse;
022import org.nuxeo.ecm.core.api.CoreSession;
023import org.nuxeo.ecm.core.api.impl.DocumentModelListImpl;
024
025/**
026 * @since 6.0
027 */
028public abstract class Fetcher {
029
030    private final CoreSession session;
031
032    private final SearchResponse response;
033
034    private final Map<String, String> repoNames;
035
036    public Fetcher(CoreSession session, SearchResponse response, Map<String, String> repoNames) {
037        this.session = session;
038        this.response = response;
039        this.repoNames = repoNames;
040    }
041
042    protected CoreSession getSession() {
043        return session;
044    }
045
046    protected SearchResponse getResponse() {
047        return response;
048    }
049
050    protected String getRepoForIndex(String indexName) {
051        if (repoNames == null) {
052            return null;
053        }
054        return repoNames.get(indexName);
055    }
056
057    abstract public DocumentModelListImpl fetchDocuments();
058
059}