001/* 002 * (C) Copyright 2014 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 * <a href="mailto:[email protected]">Guillaume Renard</a> 018 * 019 */ 020 021package org.nuxeo.ecm.restapi.server.jaxrs.routing.adapter; 022 023 024import java.util.List; 025import java.util.Map; 026 027import javax.ws.rs.GET; 028import javax.ws.rs.PUT; 029import javax.ws.rs.Path; 030import javax.ws.rs.PathParam; 031import javax.ws.rs.QueryParam; 032import javax.ws.rs.core.Response; 033import javax.ws.rs.core.Response.Status; 034 035import org.nuxeo.ecm.core.api.CoreSession; 036import org.nuxeo.ecm.core.api.DocumentModel; 037import org.nuxeo.ecm.core.api.IdRef; 038import org.nuxeo.ecm.platform.routing.api.DocumentRoutingService; 039import org.nuxeo.ecm.platform.routing.core.io.TaskCompletionRequest; 040import org.nuxeo.ecm.platform.task.Task; 041import org.nuxeo.ecm.webengine.model.WebAdapter; 042import org.nuxeo.ecm.webengine.model.impl.DefaultAdapter; 043import org.nuxeo.runtime.api.Framework; 044 045/** 046 * @since 7.2 047 */ 048@WebAdapter(name = TaskAdapter.NAME, type = "taskAdapter") 049public class TaskAdapter extends DefaultAdapter { 050 051 public static final String NAME = "task"; 052 053 @PUT 054 @Path("{taskId}/{action}") 055 public Response completeTask(@PathParam("taskId") String taskId, @PathParam("action") String action, 056 TaskCompletionRequest taskCompletionRequest) { 057 Map<String, Object> data = taskCompletionRequest.getDataMap(); 058 CoreSession session = getContext().getCoreSession(); 059 Framework.getService(DocumentRoutingService.class).endTask(session, 060 session.getDocument(new IdRef(taskId)).getAdapter(Task.class), data, action); 061 Task completedTask = session.getDocument(new IdRef(taskId)).getAdapter(Task.class); 062 return Response.ok(completedTask).status(Status.OK).build(); 063 } 064 065 @GET 066 public List<Task> doGet(@QueryParam("userId") String userId, 067 @QueryParam("workflowInstanceId") String workflowInstanceId, 068 @QueryParam("workflowModelName") String workflowModelName) { 069 DocumentModel doc = getTarget().getAdapter(DocumentModel.class); 070 return Framework.getService(DocumentRoutingService.class).getTasks(doc, userId, workflowInstanceId, 071 workflowModelName, getContext().getCoreSession()); 072 } 073 074}