001package org.nuxeo.ecm.platform.importer.executor.jaxrs; 002 003import javax.ws.rs.GET; 004import javax.ws.rs.Path; 005import javax.ws.rs.Produces; 006import javax.ws.rs.QueryParam; 007 008import org.apache.commons.logging.Log; 009import org.apache.commons.logging.LogFactory; 010import org.nuxeo.ecm.platform.importer.base.ImporterRunner; 011import org.nuxeo.ecm.platform.importer.service.DefaultImporterService; 012import org.nuxeo.runtime.api.Framework; 013 014@Path("fileImporter") 015public class HttpFileImporterExecutor extends AbstractJaxRSImporterExecutor { 016 017 private static final Log log = LogFactory.getLog(HttpFileImporterExecutor.class); 018 019 protected DefaultImporterService importerService; 020 021 @Override 022 protected Log getJavaLogger() { 023 return log; 024 } 025 026 @GET 027 @Path("run") 028 @Produces("text/plain; charset=UTF-8") 029 public String run(@QueryParam("leafType") String leafType, @QueryParam("folderishType") String folderishType, 030 @QueryParam("inputPath") String inputPath, @QueryParam("targetPath") String targetPath, 031 @QueryParam("skipRootContainerCreation") Boolean skipRootContainerCreation, 032 @QueryParam("batchSize") Integer batchSize, @QueryParam("nbThreads") Integer nbThreads, 033 @QueryParam("interactive") Boolean interactive, @QueryParam("transactionTimeout") Integer transactionTimeout) { 034 035 if (inputPath == null || targetPath == null) { 036 return "Can not import, missing " + (inputPath == null ? "inputPath" : "targetPath"); 037 } 038 if (skipRootContainerCreation == null) { 039 skipRootContainerCreation = false; 040 } 041 if (batchSize == null) { 042 batchSize = 5; 043 } 044 if (nbThreads == null) { 045 nbThreads = 5; 046 } 047 if (interactive == null) { 048 interactive = false; 049 } 050 if (transactionTimeout == null) { 051 transactionTimeout = 0; 052 } 053 054 getImporterService().setTransactionTimeout(transactionTimeout); 055 056 if (leafType != null || folderishType != null) { 057 log.info("Importing with the specified doc types"); 058 return getImporterService().importDocuments(this, leafType, folderishType, targetPath, inputPath, 059 skipRootContainerCreation, batchSize, nbThreads, interactive); 060 } else { 061 log.info("Importing with the deafult doc types"); 062 return getImporterService().importDocuments(this, targetPath, inputPath, skipRootContainerCreation, 063 batchSize, nbThreads, interactive); 064 } 065 066 } 067 068 @Override 069 public String run(ImporterRunner runner, Boolean interactive) { 070 return doRun(runner, interactive); 071 } 072 073 protected DefaultImporterService getImporterService() { 074 if (importerService == null) { 075 importerService = Framework.getService(DefaultImporterService.class); 076 } 077 return importerService; 078 } 079}