001/*
002 * (C) Copyright 2012 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 *     Mariana Cedica
018 */
019package org.nuxeo.ecm.platform.routing.core.impl;
020
021import java.util.Locale;
022
023import org.nuxeo.ecm.automation.OperationContext;
024import org.nuxeo.ecm.automation.core.annotations.Context;
025import org.nuxeo.ecm.automation.core.annotations.Operation;
026import org.nuxeo.ecm.automation.core.annotations.OperationMethod;
027import org.nuxeo.ecm.automation.core.annotations.Param;
028import org.nuxeo.ecm.core.api.Blob;
029import org.nuxeo.ecm.core.api.Blobs;
030import org.nuxeo.ecm.core.api.CoreSession;
031import org.nuxeo.ecm.platform.routing.api.DocumentRoutingConstants;
032import org.nuxeo.ecm.platform.routing.core.impl.jsongraph.JsonGraphRoute;
033
034/**
035 * Returns a json representation of the graph route
036 *
037 * @since 5.6
038 */
039@Operation(id = GetGraphOperation.ID, category = DocumentRoutingConstants.OPERATION_CATEGORY_ROUTING_NAME, label = "Get graph", description = "get graph nodes.", addToStudio = false)
040public class GetGraphOperation {
041    public final static String ID = "Document.Routing.GetGraph";
042
043    @Context
044    protected OperationContext context;
045
046    @Param(name = "routeDocId", required = true)
047    protected String routeDocId;
048
049    /***
050     * @since 5.7
051     */
052    @Param(name = "language", required = false)
053    protected String language;
054
055    @Context
056    protected CoreSession session;
057
058    @OperationMethod
059    public Blob run() {
060        Locale locale = language != null && !language.isEmpty() ? new Locale(language) : Locale.ENGLISH;
061        JsonGraphRoute unrestrictedRunner = new JsonGraphRoute(session, routeDocId, locale);
062        String json = unrestrictedRunner.getJSON();
063        return Blobs.createJSONBlob(json);
064    }
065
066}