001/*
002 * (C) Copyright 2006-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 *     Nuxeo - initial API and implementation
018 *
019 * $Id$
020 */
021
022package org.nuxeo.ecm.platform.importer.executor;
023
024import org.apache.commons.logging.Log;
025import org.apache.commons.logging.LogFactory;
026import org.nuxeo.ecm.platform.importer.base.GenericMultiThreadedImporter;
027import org.nuxeo.ecm.platform.importer.base.ImporterRunner;
028import org.nuxeo.ecm.platform.importer.source.FileSourceNode;
029import org.nuxeo.ecm.platform.importer.source.SourceNode;
030
031/**
032 * Default importer
033 *
034 * @author Thierry Delprat
035 */
036public class DefaultImporterExecutor extends AbstractImporterExecutor {
037
038    private static final Log log = LogFactory.getLog(DefaultImporterExecutor.class);
039
040    protected GenericMultiThreadedImporter importer = null;
041
042    protected String repositoryName;
043    
044    public DefaultImporterExecutor() {
045    }
046 
047    public DefaultImporterExecutor(String repositoryName) {
048        this.repositoryName=repositoryName;
049    }
050    
051    @Override
052    protected Log getJavaLogger() {
053        return log;
054    }
055
056    public long getCreatedDocsCounter() {
057        return GenericMultiThreadedImporter.getCreatedDocsCounter();
058    }
059
060    public String run(String inputPath, String targetPath, Boolean skipRootContainerCreation, Integer batchSize,
061            Integer nbTheards, Boolean interactive) {
062        SourceNode source = new FileSourceNode(inputPath);
063        return run(source, targetPath, skipRootContainerCreation, batchSize, nbTheards, interactive);
064    }
065
066    public String run(SourceNode source, String targetPath, Boolean skipRootContainerCreation, Integer batchSize,
067            Integer nbTheards, Boolean interactive) {
068        importer = new GenericMultiThreadedImporter(source, targetPath, skipRootContainerCreation, batchSize,
069                nbTheards, getLogger());
070        importer.setFactory(getFactory());
071        importer.setThreadPolicy(getThreadPolicy());
072        importer.setTransactionTimeout(getTransactionTimeout());
073        return doRun(importer, interactive);
074    }
075
076    @Override
077    public String run(ImporterRunner runner, Boolean interactive) {
078        return doRun(runner, interactive);
079    }
080
081}