001/* 002 * (C) Copyright 2006-2011 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 * bstefanescu 018 */ 019package org.nuxeo.ecm.platform.routing.core.io; 020 021import static org.nuxeo.ecm.core.io.registry.reflect.Instantiations.SINGLETON; 022import static org.nuxeo.ecm.core.io.registry.reflect.Priorities.DERIVATIVE; 023 024import java.io.IOException; 025import java.io.Serializable; 026import java.util.ArrayList; 027import java.util.Iterator; 028import java.util.List; 029import java.util.Map; 030 031import org.apache.commons.logging.Log; 032import org.apache.commons.logging.LogFactory; 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; 038 039import com.fasterxml.jackson.databind.JsonNode; 040 041/** 042 * @since 8.2 043 * @deprecated use {@link WorkflowRequestJsonReader WorkflowRequestJsonReader} 044 */ 045@Setup(mode = SINGLETON, priority = DERIVATIVE) 046@Deprecated 047public class WorkflowRequestLegacyJsonReader extends EntityJsonReader<WorkflowRequest> { 048 049 protected static final Log log = LogFactory.getLog(WorkflowRequestLegacyJsonReader.class); 050 051 public static final String ENTITY_TYPE = "workflow"; 052 053 public WorkflowRequestLegacyJsonReader() { 054 super(WorkflowRequestLegacyJsonReader.ENTITY_TYPE); 055 } 056 057 @Override 058 protected WorkflowRequest readEntity(JsonNode jn) throws IOException { 059 String workflowModelName = getStringField(jn, "workflowModelName"); 060 List<String> attachedDocumentIds = new ArrayList<>(); 061 JsonNode attachedDocumentIdsNode = jn.get("attachedDocumentIds"); 062 if (attachedDocumentIdsNode != null) { 063 for (Iterator<JsonNode> it = attachedDocumentIdsNode.elements(); it.hasNext();) { 064 attachedDocumentIds.add(it.next().textValue()); 065 } 066 } 067 JsonNode variableNode = jn.get("variables"); 068 Map<String, Serializable> variables = null; 069 070 try (SessionWrapper closeable = ctx.getSession(null)) { 071 CoreSession session = closeable.getSession(); 072 if (variableNode != null) { 073 try { 074 variables = JsonEncodeDecodeUtils.decodeVariables(variableNode, 075 null, session); 076 } catch (ClassNotFoundException e) { 077 throw new MarshallingException(e); 078 } 079 } 080 } 081 082 return new WorkflowRequest(workflowModelName, attachedDocumentIds, variables); 083 } 084 085}