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:grenard@nuxeo.com">Guillaume Renard</a> 018 * 019 */ 020 021package org.nuxeo.ecm.platform.routing.core.io; 022 023import static org.nuxeo.ecm.core.io.registry.reflect.Instantiations.SINGLETON; 024import static org.nuxeo.ecm.core.io.registry.reflect.Priorities.DERIVATIVE; 025 026import java.io.IOException; 027import java.io.Serializable; 028import java.util.Map; 029 030import javax.ws.rs.core.Response; 031 032import org.codehaus.jackson.JsonNode; 033import org.nuxeo.ecm.core.api.CoreSession; 034import org.nuxeo.ecm.core.io.marshallers.json.EntityJsonReader; 035import org.nuxeo.ecm.core.io.registry.MarshallingException; 036import org.nuxeo.ecm.core.io.registry.context.RenderingContext.SessionWrapper; 037import org.nuxeo.ecm.core.io.registry.reflect.Setup; 038import org.nuxeo.ecm.webengine.WebException; 039 040/** 041 * 042 * @since 8.2 043 * @deprecated use @{link TaskCompletionRequestJsonReader TaskCompletionRequestJsonReader} 044 */ 045@Setup(mode = SINGLETON, priority = DERIVATIVE) 046@Deprecated 047public class TaskCompletionRequestLegacyJsonReader extends EntityJsonReader<TaskCompletionRequest> { 048 049 public TaskCompletionRequestLegacyJsonReader() { 050 super(TaskCompletionRequestJsonReader.ENTITY_TYPE); 051 } 052 053 @Override 054 protected TaskCompletionRequest readEntity(JsonNode jn) throws IOException { 055 String id = jn.get("id").getValueAsText(); 056 String comment = jn.get("comment").getValueAsText(); 057 JsonNode variableNode = jn.get("variables"); 058 Map<String, Serializable> variables = null; 059 060 if (id == null) { 061 throw new WebException("No id found in request body", Response.Status.BAD_REQUEST.getStatusCode()); 062 } 063 064 try (SessionWrapper closeable = ctx.getSession(null)) { 065 CoreSession session = closeable.getSession(); 066 if (variableNode != null) { 067 try { 068 variables = JsonEncodeDecodeUtils.decodeVariables(variableNode, 069 null, session); 070 } catch (ClassNotFoundException e) { 071 throw new MarshallingException(e); 072 } 073 } 074 } 075 076 return new TaskCompletionRequest(comment, variables, true); 077 } 078 079}