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.codehaus.jackson.JsonNode; 034import org.nuxeo.ecm.core.api.CoreSession; 035import org.nuxeo.ecm.core.io.marshallers.json.EntityJsonReader; 036import org.nuxeo.ecm.core.io.registry.MarshallingException; 037import org.nuxeo.ecm.core.io.registry.context.RenderingContext.SessionWrapper; 038import org.nuxeo.ecm.core.io.registry.reflect.Setup; 039 040/** 041 * @since 8.2 042 * @deprecated use {@link WorkflowRequestJsonReader WorkflowRequestJsonReader} 043 */ 044@Setup(mode = SINGLETON, priority = DERIVATIVE) 045@Deprecated 046public class WorkflowRequestLegacyJsonReader extends EntityJsonReader<WorkflowRequest> { 047 048 protected static final Log log = LogFactory.getLog(WorkflowRequestLegacyJsonReader.class); 049 050 public static final String ENTITY_TYPE = "workflow"; 051 052 public WorkflowRequestLegacyJsonReader() { 053 super(WorkflowRequestLegacyJsonReader.ENTITY_TYPE); 054 } 055 056 @Override 057 protected WorkflowRequest readEntity(JsonNode jn) throws IOException { 058 String workflowModelName = getStringField(jn, "workflowModelName"); 059 List<String> attachedDocumentIds = new ArrayList<String>(); 060 JsonNode attachedDocumentIdsNode = jn.get("attachedDocumentIds"); 061 if (attachedDocumentIdsNode != null) { 062 for (Iterator<JsonNode> it = attachedDocumentIdsNode.getElements(); it.hasNext();) { 063 attachedDocumentIds.add(it.next().getTextValue()); 064 } 065 } 066 JsonNode variableNode = jn.get("variables"); 067 Map<String, Serializable> variables = null; 068 069 try (SessionWrapper closeable = ctx.getSession(null)) { 070 CoreSession session = closeable.getSession(); 071 if (variableNode != null) { 072 try { 073 variables = JsonEncodeDecodeUtils.decodeVariables(variableNode, 074 null, session); 075 } catch (ClassNotFoundException e) { 076 throw new MarshallingException(e); 077 } 078 } 079 } 080 081 return new WorkflowRequest(workflowModelName, attachedDocumentIds, variables); 082 } 083 084}