001/*
002 * (C) Copyright 2009 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 *     Thomas Roger
018 */
019
020package org.nuxeo.ecm.platform.importer.base;
021
022import org.nuxeo.ecm.core.api.repository.RepositoryManager;
023import org.nuxeo.ecm.platform.importer.log.ImporterLogger;
024import org.nuxeo.ecm.platform.importer.source.SourceNode;
025import org.nuxeo.runtime.api.Framework;
026
027/**
028 * Hold the configuration of an ImporterRunner.
029 *
030 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
031 */
032public class ImporterRunnerConfiguration {
033
034    public static class Builder {
035        private SourceNode sourceNode;
036
037        private String importWritePath;
038
039        private ImporterLogger log;
040
041        private boolean skipRootContainerCreation = false;
042
043        private int batchSize = 50;
044
045        private int nbThreads = 5;
046
047        private String jobName;
048        
049        private String repository=null;
050
051        public Builder(SourceNode sourceNode, String importWritePath, ImporterLogger log) {
052            this.sourceNode = sourceNode;
053            this.importWritePath = importWritePath;
054            this.log = log;
055        }
056
057        public Builder skipRootContainerCreation(Boolean skipRootContainerCreation) {
058            if (skipRootContainerCreation != null) {
059                this.skipRootContainerCreation = skipRootContainerCreation;
060            }
061            return this;
062        }
063
064        public Builder repository(String repo) {
065            this.repository = repo;
066            return this;
067        }
068        
069        public Builder batchSize(Integer batchSize) {
070            if (batchSize != null) {
071                this.batchSize = batchSize;
072            }
073            return this;
074        }
075
076        public Builder nbThreads(Integer nbThreads) {
077            if (nbThreads != null) {
078                this.nbThreads = nbThreads;
079            }
080            return this;
081        }
082
083        public Builder jobName(String jobName) {
084            if (jobName != null) {
085                this.jobName = jobName;
086            }
087            return this;
088        }
089
090        public ImporterRunnerConfiguration build() {
091            return new ImporterRunnerConfiguration(repository, sourceNode, importWritePath, log, skipRootContainerCreation,
092                    batchSize, nbThreads, jobName);
093        }
094
095    }
096
097    public final SourceNode sourceNode;
098
099    public final String importWritePath;
100
101    public final boolean skipRootContainerCreation;
102
103    public final int batchSize;
104
105    public final int nbThreads;
106
107    public final String jobName;
108
109    public final ImporterLogger log;
110    
111    public final String repositoryName;
112
113    protected ImporterRunnerConfiguration(String repositoryName, SourceNode sourceNode, String importWritePath, ImporterLogger log,
114            boolean skipRootContainerCreation, int batchSize, int nbThreads, String jobName) {
115        this.sourceNode = sourceNode;
116        this.importWritePath = importWritePath;
117        this.log = log;
118        this.skipRootContainerCreation = skipRootContainerCreation;
119        this.batchSize = batchSize;
120        this.nbThreads = nbThreads;
121        this.jobName = jobName;
122        if  (repositoryName!=null) {
123            this.repositoryName = repositoryName;
124        } else {
125            this.repositoryName = Framework.getService(RepositoryManager.class).getDefaultRepositoryName();
126        }
127    }
128
129}