001package org.nuxeo.sample;
002
003import org.apache.commons.lang3.StringUtils;
004import org.nuxeo.ecm.automation.core.Constants;
005import org.nuxeo.ecm.automation.core.annotations.Context;
006import org.nuxeo.ecm.automation.core.annotations.Operation;
007import org.nuxeo.ecm.automation.core.annotations.OperationMethod;
008import org.nuxeo.ecm.automation.core.annotations.Param;
009import org.nuxeo.ecm.core.api.CoreSession;
010import org.nuxeo.ecm.core.api.DocumentModel;
011import org.nuxeo.ecm.core.api.PathRef;
012
013/**
014 *
015 */
016@Operation(id=SampleOperation.ID, category=Constants.CAT_DOCUMENT, label="Sample Operation", description="Describe here what your operation does.")
017public class SampleOperation {
018
019    public static final String ID = "Document.SampleOperation";
020
021    @Context
022    protected CoreSession session;
023
024    @Param(name = "path", required = false)
025    protected String path;
026
027    @OperationMethod
028    public DocumentModel run() {
029        if (StringUtils.isBlank(path)) {
030            return session.getRootDocument();
031        } else {
032            return session.getDocument(new PathRef(path));
033        }
034    }
035}