001/* 002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Mariana Cedica 016 */ 017package org.nuxeo.ecm.platform.routing.core.impl; 018 019import java.util.Locale; 020 021import org.nuxeo.ecm.automation.OperationContext; 022import org.nuxeo.ecm.automation.core.annotations.Context; 023import org.nuxeo.ecm.automation.core.annotations.Operation; 024import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 025import org.nuxeo.ecm.automation.core.annotations.Param; 026import org.nuxeo.ecm.core.api.Blob; 027import org.nuxeo.ecm.core.api.Blobs; 028import org.nuxeo.ecm.core.api.CoreSession; 029import org.nuxeo.ecm.platform.routing.api.DocumentRoutingConstants; 030import org.nuxeo.ecm.platform.routing.core.impl.jsongraph.JsonGraphRoute; 031 032/** 033 * Returns a json representation of the graph route 034 * 035 * @since 5.6 036 */ 037@Operation(id = GetGraphOperation.ID, category = DocumentRoutingConstants.OPERATION_CATEGORY_ROUTING_NAME, label = "Get graph", description = "get graph nodes.", addToStudio = false) 038public class GetGraphOperation { 039 public final static String ID = "Document.Routing.GetGraph"; 040 041 @Context 042 protected OperationContext context; 043 044 @Param(name = "routeDocId", required = true) 045 protected String routeDocId; 046 047 /*** 048 * @since 5.7 049 */ 050 @Param(name = "language", required = false) 051 protected String language; 052 053 @Context 054 protected CoreSession session; 055 056 @OperationMethod 057 public Blob run() { 058 Locale locale = language != null && !language.isEmpty() ? new Locale(language) : Locale.ENGLISH; 059 JsonGraphRoute unrestrictedRunner = new JsonGraphRoute(session, routeDocId, locale); 060 String json = unrestrictedRunner.getJSON(); 061 return Blobs.createBlob(json.toString(), "application/json"); 062 } 063 064}