001/* 002 * (C) Copyright 2012 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 * bjalon 018 */ 019package org.nuxeo.ecm.mobile.webengine.adapter; 020 021import java.util.HashMap; 022 023import javax.ws.rs.GET; 024import javax.ws.rs.POST; 025import javax.ws.rs.core.Response; 026 027import org.nuxeo.ecm.automation.AutomationService; 028import org.nuxeo.ecm.automation.OperationContext; 029import org.nuxeo.ecm.automation.OperationException; 030import org.nuxeo.ecm.core.api.Blob; 031import org.nuxeo.ecm.webengine.forms.FormData; 032import org.nuxeo.ecm.webengine.model.WebAdapter; 033import org.nuxeo.runtime.api.Framework; 034 035/** 036 * @author <a href="mailto:bjalon@nuxeo.com">Benjamin JALON</a> 037 * @since 5.5 038 */ 039@WebAdapter(name = "folderish", type = "Folderish", targetType = "MobileDocument") 040public class FolderishAdapter extends DefaultMobileAdapter { 041 042 @GET 043 public Object doGet() { 044 return getView("index"); 045 } 046 047 @POST 048 public Object doUpload() throws OperationException { 049 FormData form = ctx.getForm(); 050 Blob blob = form.getFirstBlob(); 051 if (blob == null) { 052 throw new IllegalArgumentException("Could not find any uploaded file"); 053 } 054 AutomationService as = Framework.getLocalService(AutomationService.class); 055 HashMap<String, Object> params = new HashMap<String, Object>(); 056 params.put("overwite", true); 057 058 OperationContext subctx = new OperationContext(ctx.getCoreSession(), null); 059 subctx.setInput(blob); 060 subctx.put("currentDocument", getDocumentModel().getPathAsString()); 061 062 as.run(subctx, "FileManager.Import", params); 063 return Response.ok().build(); 064 } 065}