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 * Thierry Delprat 018 */ 019package org.nuxeo.ecm.platform.importer.executor.jaxrs; 020 021import javax.ws.rs.GET; 022import javax.ws.rs.Path; 023import javax.ws.rs.Produces; 024import javax.ws.rs.QueryParam; 025 026import org.apache.commons.logging.Log; 027import org.apache.commons.logging.LogFactory; 028import org.nuxeo.ecm.platform.importer.base.ImporterRunner; 029import org.nuxeo.ecm.platform.importer.service.DefaultImporterService; 030import org.nuxeo.runtime.api.Framework; 031 032@Path("fileImporter") 033public class HttpFileImporterExecutor extends AbstractJaxRSImporterExecutor { 034 035 private static final Log log = LogFactory.getLog(HttpFileImporterExecutor.class); 036 037 protected DefaultImporterService importerService; 038 039 @Override 040 protected Log getJavaLogger() { 041 return log; 042 } 043 044 @GET 045 @Path("run") 046 @Produces("text/plain; charset=UTF-8") 047 public String run(@QueryParam("leafType") String leafType, @QueryParam("folderishType") String folderishType, 048 @QueryParam("inputPath") String inputPath, @QueryParam("targetPath") String targetPath, 049 @QueryParam("skipRootContainerCreation") Boolean skipRootContainerCreation, 050 @QueryParam("batchSize") Integer batchSize, @QueryParam("nbThreads") Integer nbThreads, 051 @QueryParam("interactive") Boolean interactive, @QueryParam("transactionTimeout") Integer transactionTimeout) { 052 053 if (inputPath == null || targetPath == null) { 054 return "Can not import, missing " + (inputPath == null ? "inputPath" : "targetPath"); 055 } 056 if (skipRootContainerCreation == null) { 057 skipRootContainerCreation = false; 058 } 059 if (batchSize == null) { 060 batchSize = 5; 061 } 062 if (nbThreads == null) { 063 nbThreads = 5; 064 } 065 if (interactive == null) { 066 interactive = false; 067 } 068 if (transactionTimeout == null) { 069 transactionTimeout = 0; 070 } 071 072 getImporterService().setTransactionTimeout(transactionTimeout); 073 074 if (leafType != null || folderishType != null) { 075 log.info("Importing with the specified doc types"); 076 return getImporterService().importDocuments(this, leafType, folderishType, targetPath, inputPath, 077 skipRootContainerCreation, batchSize, nbThreads, interactive); 078 } else { 079 log.info("Importing with the deafult doc types"); 080 return getImporterService().importDocuments(this, targetPath, inputPath, skipRootContainerCreation, 081 batchSize, nbThreads, interactive); 082 } 083 084 } 085 086 @Override 087 public String run(ImporterRunner runner, Boolean interactive) { 088 return doRun(runner, interactive); 089 } 090 091 protected DefaultImporterService getImporterService() { 092 if (importerService == null) { 093 importerService = Framework.getService(DefaultImporterService.class); 094 } 095 return importerService; 096 } 097}