Platform Explorer / Nuxeo Platform LTS 2019 10.10

Extension point operation

    <scriptedOperation id="Scripting.HelloWorld">
        <inputType>string</inputType>
        <outputType>string</outputType>
        <param name="lang" type="string"/>
        <script>
          function run(input, params) {
          if (params.lang === "fr") {
          return "Bonjour " + input;
          } else {
          return "Hello " + input;
          }
          }
        </script>
    </scriptedOperation>

Contribution Descriptor

Existing Contributions

  • nuxeo-template-rendering-web-ui-10.10.jar /OSGI-INF/operations-contrib.xml
    <extension point="operation" target="org.nuxeo.automation.scripting.internals.AutomationScriptingComponent">
    
        <scriptedOperation id="javascript.FilterTemplatesByType">
          <inputType>document</inputType>
          <outputType>documents</outputType>
          <category>javascript</category>
          <description>Filter templates according to the type of a given input document.</description>
          <script><![CDATA[
            function run(input, params) {
              return Repository.Query(null, {
                'query': 'select * from Document where ecm:mixinType = "Template" AND ecm:isTrashed = 0 AND tmpl:applicableTypes IN ( "all", "' + input['type'] + '")'
              });
            }
          ]]></script>
        </scriptedOperation>
    
        <scriptedOperation id="javascript.RenderPdf">
          <inputType>document</inputType>
          <outputType>blob</outputType>
          <category>javascript</category>
          <param name="templateName" type="string"/>
          <param name="attach" type="boolean"/>
          <param name="templateData" type="string"/>
          <description>Render a document with a given template and converts it to PDF.</description>
          <script><![CDATA[
            function run(input, params) {
              var blob = TemplateProcessor.Render(input, {
                'templateName': params.templateName,
                'attach': params.attach || false,
                'templateData': params.templateData || null
              });
              return Blob.RunConverter(blob, {'converter': 'any2pdf'});
            }
          ]]></script>
        </scriptedOperation>
    
      </extension>
  • nuxeo-vision-core-1.3.4.jar /OSGI-INF/default-chain-contrib.xml
    <extension point="operation" target="org.nuxeo.automation.scripting.internals.AutomationScriptingComponent">
        <scriptedOperation id="javascript.PictureVisionDefaultMapper">
          <inputType>Document</inputType>
          <outputType>Document</outputType>
          <category>javascript</category>
          <description/>
          <script><![CDATA[function run(input, params) {
    
                  var blob = Picture.GetView(input, {'viewName': 'Medium'});
    
                  blob = VisionOp(blob, {
                    'features': ['LABEL_DETECTION'],
                    'maxResults': 5,
                    'outputVariable': 'annotations'
                  });
    
                  var annotations = ctx.annotations;
    
                  if (annotations===undefined || annotations.length===0) return;
    
                  var textAndLabels = annotations[0];
    
                  // build tag list
                  var labels = textAndLabels.getClassificationLabels();
    
                  if (labels !== undefined && labels !== null && labels.length>0) {
                      var tags = [];
                      for(var i=0;i<labels.length;i++) {
                        var label = labels[i];
                        var tag = label.getText();
                        if (tag ===undefined || tag ===null) continue;
                        tags.push(tag.replace(/[^A-Z0-9]+/ig,'+'));
                      }
    
                      input = Services.TagDocument(input, {'tags': tags });
                  }
    
                  return input;
    
            }]]></script>
        </scriptedOperation>
    
        <scriptedOperation id="javascript.VideoVisionDefaultMapper">
          <inputType>Document</inputType>
          <outputType>Document</outputType>
          <category>javascript</category>
          <description/>
          <script><![CDATA[function run(input, params) {
                  var storyboard = input['vid:storyboard'];
                  var blobs = [];
                  var index;
                  var tags = [];
    
                  for (index=0;index<storyboard.length;index++) {
    
                    var blob = storyboard[index].content;
    
                    VisionOp(blob, {
                      'features': ['LABEL_DETECTION'],
                      'maxResults': 5,
                      'outputVariable': 'annotations'
                    });
    
                    var annotations = ctx.annotations;
    
                    if (annotations===undefined || annotations.length===0) return;
    
                    // build tag list
                    var textAndLabels = annotations[0];
                    var labels = textAndLabels.getClassificationLabels();
    
                    if (labels === undefined || labels === null || labels===0) continue;
    
                    for(var j=0;j<labels.length;j++) {
                        var label = labels[j];
                        var tag = label.getText();
                        if (tag ===undefined || tag ===null) continue;
                        tags.push(tag.replace(/[^A-Z0-9]+/ig,'+'));
                        tags.push(label.getText().replace(/\s/g,'+'));
                    }
                  }
    
                  input = Services.TagDocument(input, {'tags': tags });
    
                  return input;
    
                }]]></script>
        </scriptedOperation>
    
      </extension>