SlideShare a Scribd company logo
1 of 33
Download to read offline
Javascript Konsole für Entwicklung und Administration
Meet the Experts in Hamburg – Florian Maul – 5.06.2012




fme AG - #212261
Über mich

    •   Florian Maul, Senior Consultant bei der fme AG
    •   Langjährige Erfahrung mit Alfresco
    •   Gewinner des Alfresco Dashlet Challenge 2011:
        Gallery Plus Dashlet
    •   Alfresco Certified Engineer & Alfresco Certified Administrator
    •   Opensource
            Contributor zu Share Extras und anderer Alfresco Extensions
            Android CMIS Browser (2010)




    •            @fmaul




3                                                                          (c) fme AG - #205626
Agenda

•    Kurzvorstellung fme AG
•    fme Alfresco Extensions
•    Was ist die Javascript Konsole?
•    Viele Demos mit Beispielskripten




4                                       © fme AG - #212261
Das Unternehmen
    Q1/2012




                                                                                    Techno-
                                                                                                 Lösungen
                                                                                    logien
              Wir unterstützen unsere Kunden dabei, Informationen effektiver
              und effizienter zu strukturieren und verwalten. Dies erreichen wir
    Unser     durch den Einsatz von Enterprise Content Management, Business                 Branchen
    Fokus     Intelligence und Product Lifecycle Management Technologien. Der
              Schwerpunkt liegt auf Lösungen für Life Sciences, industrielle
              Fertigung und Energie.




              • Gründung: 1995, Hauptsitz: Braunschweig, ca. 105 Mitarbeiter (fme-Gruppe)
              • Weitere Geschäftsstellen in München, Düsseldorf, Frankfurt
              • Töchter in Rumänien (100 %) und in den USA (60 %)
    Fakten    • Mehr als 10 Jahre EMC-Partner (höchster Partnerstatus), mehr als 80 ECM-Berater
              • International tätig
              • „We use what we sell“
              • Mehr als 130 ECM-Kunden weltweit



5                                                                                               #6120 - © fme AG
Kunden fme AG
    Auswahl




              Industrielle Fertigung        Life Science




              Energie                  Weitere




6                                                          © fme AG - #212261
fme Migration Center




    Analyse   Organise   Transform          Validate   Correct   Import




                                     Time

7                                                                 (c) fme AG - #205626
fme Alfresco Extensions Gallery

•     http://alfresco.fme.de/Overview.925.0.html
•     14 gelistete Alfresco Erweiterungen
•     8 unter Open Source (Sponsors wanted!)
•     6 unter Kommerzieller Lizenz
•     Fokus:
          Bedienkomfort von Alfresco maximieren
          Oft benötigte/angefragte Erweiterungen
           in Form von wiederverwendbaren
           Modulen
          Verwendung dieser Erweiterungen bei der
           Umsetzung branchen-/kundenspezifischer
           Alfresco Lösungen




8                                                    © fme AG - #212261
Alfresco APIs

•    What kinds of API are there?

         Java Foundation API

         Javascript API & Javascript Services

         CMIS



•    Where can I use Javascript in Alfresco:

         Webscripts developed in Javascript

         Javascript run by Actions (Run Script Action)

         Javascript attached to Tasks & Events in Workflows



9                                                              (c) fme AG - #205626
Webscripts developed in Javascript

•    Most of the Alfresco Webscript are developed in Javascript
•    Example: GET /alfresco/service/sample/blog/category/{category}


// check category exists?
var category = search.luceneSearch(
"PATH:"/cm:generalclassifiable//cm:" + url.extension + """);
if (category == undefined) {
      status.code = 404;
      status.message = "Category " + url.extension + " not found.";
      status.redirect = true;
 } else {
      // perform category search
      var nodes = search.luceneSearch(
      "PATH:"/cm:generalclassifiable//cm:" + url.extension +
      "//member"");
      model.resultset = nodes;
 }

10                                                                    (c) fme AG - #205626
Javascript for Tasks & Events in Workflows

•    Javascript can be executed from within Workflow definitions
•    Example of Activti Workflow: parallelreview_group_processdefinition.xml


<decision name="isapproved">
      <event type="node-enter">
          <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
          <script>
              <variable name="wf_actualPercent" access="write"/>
              <expression>
                  wf_actualPercent = ((wf_approveCount * 100) /
                  people.getMembers(bpm_groupAssignee).length);
              </expression>
          </script>
          </action>
      </event>
</decision>




11                                                                      (c) fme AG - #205626
Javascript run by Actions (Run Script Action)

•    Alfresco Explorer has a Run Script Action




•    For Share there is an Execute Script extension in Share-Extras:




12                                                                     (c) fme AG - #205626
But how to develop Javascript code?

•    Webscripts
         Develop in Eclipse
         ANT build script to copy changes & reload the webscripts
         Run the webscript manually in the browser


•    Data Dictionary Scripts
         upload script to Data Dictionary
         run Script Action
         watch errors in the Alfresco Log file (ScriptLogger=DEBUG)
         fix bugs and iterate


•     It takes to long to test out Javascript code and fix bugs.




13                                                                     (c) fme AG - #205626
Meet the Javascript Console




14                             (c) fme AG - #205626
JavaScript Console

•    Komponente für die Share Admin Console
      zum Schreiben & Ausführen von
     JavaScript-Code im Repository

         Vollzugriff auf die Alfresco JavaScript API
         Auswahl des Ausführungskontext (Ordner)
         Einfache Code-Completion
         Laden & Speichern von Skripten
         Formatierung von Ergebnislisten in Form
          einer Tabelle (v0.4.x)
         Import von JavaScript-Dateien aus dem
          Alfresco Classpath
         Verwendung von Freemarker-Templates
          zur Formatierung der Ergebnismenge (v0.5)




15                                                      © fme AG - #212261
Meet the Javascript Console

•




•    Mike Farman (Director Product Management Alfresco):
     „I really like the stuff you’ve been doing, my favourite is the JavaScript console, it’s the
     first add-on I always install!“


•    X




16                                                                                    (c) fme AG - #205626
Javascript Console milestones

•    End of 2010
         Need to develop and execute Javascript code for a project sparked development
          of the first prototype
         First internal versions were a single standalone page in Share
•    April 2011:
         Contact with Will Abson
         refactoring and integration into the admin console of Alfresco 3.4
•    May 2011:
         First checkin into the Share-Extras project and first public release
•    Nov 2011:
         Version 0.4 with basic code completion
•    June 2012:
         Version 0.5 with freemarker editor




17                                                                               (c) fme AG - #205626
Download & Installation

•    Visit: http://code.google.com/p/share-extras/

•    Download at http://code.google.com/p/share-extras/downloads/list




Installation

•    For version 0.4.x copy the jar file to tomcat/shared/lib/

•    With 0.5 there will be two jar files –repo.jar and –share.jar. The repo.jar must be
     copied to tomcat/webapps/alfresco/WEB-INF/lib and the share.jar to
     tomcat/webapps/share/WEB-INF/lib.



18                                                                                  (c) fme AG - #205626
Poor man‘s Nodebrowser

print(document);


print("--- PROPERTIES -----------------------------------------");
print(document.properties);


print("--- ASPECTS --------------------------------------------");
print(document.aspects);


print("--- ASSOCS ---------------------------------------------");
print(document.assocs);


print("--- PERMISSIONS ----------------------------------------");
print(document.fullPermissions);


19                                                         (c) fme AG - #205626
How does it work?

     Alfresco Repository / Webscripts                           •   print(), recurse(), logger
                                                                •   eval() / Java-Webscript
                                                                •   <imports>
                                  Execute Webscript
                                                                •   Error handling




     Browser / Javascript / YUI / Codemirror


                    Input                                 Output

       •   Javascript                          •   Print / log output
       •   Freemarker template                 •   Freemarker output
       •   space / document                    •   Error messages



20                                                                                    (c) fme AG - #205626
Selecting the file or folder to work with

• Select the space variable from   • Open any document in the
     a directory chooser:            Javascript Console from the
                                     document library:




21                                                         (c) fme AG - #205626
Recurse() function

•    The Javascript console has a special recurse function to iterate over a tree of nodes:


     recurse(space, function(node) {
        if (node.name.toLowerCase().indexOf("alfresco") >= 0) {
            print("adding tag alfresco to " +
                  node.displayPath + "/" + node.name);
            node.addTag("alfresco");
        }
     });


•    If no function is given it returns the nodes as an array:


     var allNodes =      recurse(space);




22                                                                                 (c) fme AG - #205626
Creating users and attaching avatars

function createUser(username,firstname, lastname, email, location, jobtitle)
{
     var password = username; // use for testing only!


     var p = people.createPerson(username, firstname, lastname,
                 email, password, true);


     p.properties["cm:location"] = location;
     p.properties["cm:jobtitle"] = jobtitle;
     p.save();
}


createUser("homer", "Homer", "Simpson", "h.simpson@springfield.fox",
           "Springfield", "Nuclear Safety Inspector");




23                                                                     (c) fme AG - #205626
Creating users and attaching avatars

// pseudo-code not working


for each (imageNode in space.children) {
     var user = people.getPerson(name);
     user.createAssociation(
        imageNode, "cm:avatar");
}




Full source code here:
http://www.techbits.de/2011/12/02/using-the-javascript-console-creating-users-with-avatar-images/


24                                                                                         (c) fme AG - #205626
Assign users to sites


                   var nodes = search.luceneSearch(
                     "TYPE:cm:person +@cm:lastName:Simpson");


                   for each(var simpson in nodes) {
                       var site = siteService.getSite(
                         "javascript-console-talk");


                       site.setMembership(
                         simpson.properties["cm:userName"],
                         "SiteCollaborator");
                   }




25                                                        (c) fme AG - #205626
Creating Webscripts

•    The new version 0.5 makes
     it easy to create webscripts:

         Write a controller javascript
          using logger.log output

         Create a freemarker
          template

         Test different URL
          arguments and different
          users




26                                        (c) fme AG - #205626
Creating Webscripts

var result = [];


for each(node in companyhome.childByNamePath(args.path).children) {
     result.push({
       name : node.name,
       creator : node.properties["cm:creator"],
       creationDate : node.properties["cm:created"]
     });
}
model.folder = result;


[
<#list folder as f>
 {
     "name" : "${f.name}",
     "creator" : "${f.creator}",
     "creationDate" : "${f.creationDate?date}"
 }
</#list>
]

27                                                                    (c) fme AG - #205626
Access spring beans / unlock documents

•    Example unlock a document:


     var ctx = Packages.org.springframework.
     web.context.ContextLoader.getCurrentWebApplicationContext();


     var lockService = ctx.getBean("lockService");


     lockService.unlock(document.nodeRef);


•    This looks like a hack but is perfectly valid Alfresco Javascript
•    It only works in Javascript stored in the Classpath (not in the Data Dictionary)
•    Also very useful to test your own Beans written in Java




28                                                                                  (c) fme AG - #205626
Access spring beans / reindex nodes

•    We faced the issue with nodes getting lost from the index. ALF-12588
•    You can force the reindexing of single nodes:
     var ctx =
     Packages.org.springframework.web.context.ContextLoader.getCurrentWebAppl
     icationContext();
     var nodeIndexer = ctx.getBean("nodeIndexer");
     var nodeService = ctx.getBean("nodeService");


     function indexNode(node) {
         var childAssoc = nodeService.getPrimaryParent(node.nodeRef);
         nodeIndexer.indexCreateNode(childAssoc);
     }
     indexNode(search.findNode("workspace://SpacesStore/d4923a10-96dc-4565-
     a471-d6b6c8f7b170"));




• Warning: With great power comes great responsibility!

29                                                                          (c) fme AG - #205626
Special access to logger configuration

•    The Javascript Console allows you to change to log4j log level at runtime.
•    For your own Java classes you can use:


     logger.setLevel("de.fme.alfresco", "DEBUG");




•    The Alfresco Javascript runtime uses the ScriptLogger class:


     logger.setLevel("org.alfresco.repo.jscript.ScriptLogger",
     "DEBUG");




30                                                                                (c) fme AG - #205626
Javascript Puzzlers – Alfresco Edition


What do these two do?
•    node.properties["cm:name"] = "textfile.txt";
•    node.name = "textfile.txt";




Comparing ScriptNode nodeRefs:
•    node1.nodeRef.equals(node2.nodeRef)
•    node1.nodeRef == node2.nodeRef
•    " " +node1.nodeRef == " " + node2.nodeRef




31                                                  (c) fme AG - #205626
Batch processing

•    Examples:
         Set all documents to inherit permissions
         Disable automatic versioning for all documents


•    Small batches can run in the Javascript Console in one Transaction (10000 nodes)
         I install the Javascript Console on every production system


•    Large batches currently only possible using Java with multiple Transactions.
•    Batch processing (updates for >100000 nodes)
         How to find the nodes? Search or recursion?
         Can not run in one transaction: Transaction Management in Javascript?
         Processing in smaller batches
         How to make use of multithreading?




32                                                                                  (c) fme AG - #205626
Fragen, Feedback …?




•    f.maul@fme.de
•    http://twitter.com/#!/fmaul




33                                 © fme AG - #212261
Meet the Experts in Hamburg – Florian Maul – Javascript Console

More Related Content

Similar to Meet the Experts in Hamburg – Florian Maul – Javascript Console

Build Your First SharePoint Framework Webpart
Build Your First SharePoint Framework WebpartBuild Your First SharePoint Framework Webpart
Build Your First SharePoint Framework WebpartEric Overfield
 
How to setup a development environment for ONAP
How to setup a development environment for ONAPHow to setup a development environment for ONAP
How to setup a development environment for ONAPVictor Morales
 
Alfresco Coding mit dem Alfresco SDK (auf Englisch) - Julien Bruinaud, Techni...
Alfresco Coding mit dem Alfresco SDK (auf Englisch) - Julien Bruinaud, Techni...Alfresco Coding mit dem Alfresco SDK (auf Englisch) - Julien Bruinaud, Techni...
Alfresco Coding mit dem Alfresco SDK (auf Englisch) - Julien Bruinaud, Techni...Nicole Szigeti
 
Fusion Applications Administration Overview
Fusion Applications Administration OverviewFusion Applications Administration Overview
Fusion Applications Administration OverviewVihangAstik
 
Hands-on Workshop: Intermediate Development with Heroku and Force.com
Hands-on Workshop: Intermediate Development with Heroku and Force.comHands-on Workshop: Intermediate Development with Heroku and Force.com
Hands-on Workshop: Intermediate Development with Heroku and Force.comSalesforce Developers
 
Convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Convert your Full Trust Solutions to the SharePoint Framework (SPFx)Convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Convert your Full Trust Solutions to the SharePoint Framework (SPFx)Brian Culver
 
CCI 2017 - Introduzione a SharePoint Framework (SPFx) - Fabio Franzini
CCI 2017 - Introduzione a SharePoint Framework (SPFx) - Fabio FranziniCCI 2017 - Introduzione a SharePoint Framework (SPFx) - Fabio Franzini
CCI 2017 - Introduzione a SharePoint Framework (SPFx) - Fabio Franziniwalk2talk srl
 
Alfresco Summit 2013 - The Art of the Upgrade
Alfresco Summit 2013 - The Art of the UpgradeAlfresco Summit 2013 - The Art of the Upgrade
Alfresco Summit 2013 - The Art of the UpgradeKyle Adams
 
Convert your Full Trust Solutions to the SharePoint Framework (SPFx) in 1 hour
Convert your Full Trust Solutions to the SharePoint Framework (SPFx) in 1 hourConvert your Full Trust Solutions to the SharePoint Framework (SPFx) in 1 hour
Convert your Full Trust Solutions to the SharePoint Framework (SPFx) in 1 hourBrian Culver
 
Golang 101 for IT-Pros - Cisco Live Orlando 2018 - DEVNET-1808
Golang 101 for IT-Pros - Cisco Live Orlando 2018 - DEVNET-1808Golang 101 for IT-Pros - Cisco Live Orlando 2018 - DEVNET-1808
Golang 101 for IT-Pros - Cisco Live Orlando 2018 - DEVNET-1808Cisco DevNet
 
The Rich Standard: Getting Familiar with HTML5
The Rich Standard: Getting Familiar with HTML5The Rich Standard: Getting Familiar with HTML5
The Rich Standard: Getting Familiar with HTML5Todd Anglin
 
Alfresco Development Framework Basic
Alfresco Development Framework BasicAlfresco Development Framework Basic
Alfresco Development Framework BasicMario Romano
 
SOA Knowledge Kit, Developer Productivity and Performance Comparison Analysis
SOA Knowledge Kit, Developer Productivity  and Performance Comparison AnalysisSOA Knowledge Kit, Developer Productivity  and Performance Comparison Analysis
SOA Knowledge Kit, Developer Productivity and Performance Comparison AnalysisClever Moe
 
Rock Solid Deployment of Web Applications
Rock Solid Deployment of Web ApplicationsRock Solid Deployment of Web Applications
Rock Solid Deployment of Web ApplicationsPablo Godel
 
Weave GitOps 2023.04 Release: Optimizing Developer Productivity & Experience ...
Weave GitOps 2023.04 Release: Optimizing Developer Productivity & Experience ...Weave GitOps 2023.04 Release: Optimizing Developer Productivity & Experience ...
Weave GitOps 2023.04 Release: Optimizing Developer Productivity & Experience ...CezzaineZaher1
 
Extending Microsoft Teams with SPFx webparts
Extending Microsoft Teams with SPFx webpartsExtending Microsoft Teams with SPFx webparts
Extending Microsoft Teams with SPFx webpartsAntti Koskela
 
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)Brian Culver
 
Getting started with PhoneGap
Getting started with PhoneGapGetting started with PhoneGap
Getting started with PhoneGapMihai Corlan
 

Similar to Meet the Experts in Hamburg – Florian Maul – Javascript Console (20)

Build Your First SharePoint Framework Webpart
Build Your First SharePoint Framework WebpartBuild Your First SharePoint Framework Webpart
Build Your First SharePoint Framework Webpart
 
How to setup a development environment for ONAP
How to setup a development environment for ONAPHow to setup a development environment for ONAP
How to setup a development environment for ONAP
 
Alfresco Coding mit dem Alfresco SDK (auf Englisch) - Julien Bruinaud, Techni...
Alfresco Coding mit dem Alfresco SDK (auf Englisch) - Julien Bruinaud, Techni...Alfresco Coding mit dem Alfresco SDK (auf Englisch) - Julien Bruinaud, Techni...
Alfresco Coding mit dem Alfresco SDK (auf Englisch) - Julien Bruinaud, Techni...
 
Fusion Applications Administration Overview
Fusion Applications Administration OverviewFusion Applications Administration Overview
Fusion Applications Administration Overview
 
Apache Cordova
Apache CordovaApache Cordova
Apache Cordova
 
Hands-on Workshop: Intermediate Development with Heroku and Force.com
Hands-on Workshop: Intermediate Development with Heroku and Force.comHands-on Workshop: Intermediate Development with Heroku and Force.com
Hands-on Workshop: Intermediate Development with Heroku and Force.com
 
Convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Convert your Full Trust Solutions to the SharePoint Framework (SPFx)Convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Convert your Full Trust Solutions to the SharePoint Framework (SPFx)
 
CCI 2017 - Introduzione a SharePoint Framework (SPFx) - Fabio Franzini
CCI 2017 - Introduzione a SharePoint Framework (SPFx) - Fabio FranziniCCI 2017 - Introduzione a SharePoint Framework (SPFx) - Fabio Franzini
CCI 2017 - Introduzione a SharePoint Framework (SPFx) - Fabio Franzini
 
Alfresco Summit 2013 - The Art of the Upgrade
Alfresco Summit 2013 - The Art of the UpgradeAlfresco Summit 2013 - The Art of the Upgrade
Alfresco Summit 2013 - The Art of the Upgrade
 
Convert your Full Trust Solutions to the SharePoint Framework (SPFx) in 1 hour
Convert your Full Trust Solutions to the SharePoint Framework (SPFx) in 1 hourConvert your Full Trust Solutions to the SharePoint Framework (SPFx) in 1 hour
Convert your Full Trust Solutions to the SharePoint Framework (SPFx) in 1 hour
 
Golang 101 for IT-Pros - Cisco Live Orlando 2018 - DEVNET-1808
Golang 101 for IT-Pros - Cisco Live Orlando 2018 - DEVNET-1808Golang 101 for IT-Pros - Cisco Live Orlando 2018 - DEVNET-1808
Golang 101 for IT-Pros - Cisco Live Orlando 2018 - DEVNET-1808
 
The Rich Standard: Getting Familiar with HTML5
The Rich Standard: Getting Familiar with HTML5The Rich Standard: Getting Familiar with HTML5
The Rich Standard: Getting Familiar with HTML5
 
Alfresco Development Framework Basic
Alfresco Development Framework BasicAlfresco Development Framework Basic
Alfresco Development Framework Basic
 
SOA Knowledge Kit, Developer Productivity and Performance Comparison Analysis
SOA Knowledge Kit, Developer Productivity  and Performance Comparison AnalysisSOA Knowledge Kit, Developer Productivity  and Performance Comparison Analysis
SOA Knowledge Kit, Developer Productivity and Performance Comparison Analysis
 
Rock Solid Deployment of Web Applications
Rock Solid Deployment of Web ApplicationsRock Solid Deployment of Web Applications
Rock Solid Deployment of Web Applications
 
Weave GitOps 2023.04 Release: Optimizing Developer Productivity & Experience ...
Weave GitOps 2023.04 Release: Optimizing Developer Productivity & Experience ...Weave GitOps 2023.04 Release: Optimizing Developer Productivity & Experience ...
Weave GitOps 2023.04 Release: Optimizing Developer Productivity & Experience ...
 
Extending Microsoft Teams with SPFx webparts
Extending Microsoft Teams with SPFx webpartsExtending Microsoft Teams with SPFx webparts
Extending Microsoft Teams with SPFx webparts
 
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
 
Intro to PhoneGap
Intro to PhoneGapIntro to PhoneGap
Intro to PhoneGap
 
Getting started with PhoneGap
Getting started with PhoneGapGetting started with PhoneGap
Getting started with PhoneGap
 

Recently uploaded

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 

Recently uploaded (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 

Meet the Experts in Hamburg – Florian Maul – Javascript Console

  • 1. Javascript Konsole für Entwicklung und Administration Meet the Experts in Hamburg – Florian Maul – 5.06.2012 fme AG - #212261
  • 2. Über mich • Florian Maul, Senior Consultant bei der fme AG • Langjährige Erfahrung mit Alfresco • Gewinner des Alfresco Dashlet Challenge 2011: Gallery Plus Dashlet • Alfresco Certified Engineer & Alfresco Certified Administrator • Opensource  Contributor zu Share Extras und anderer Alfresco Extensions  Android CMIS Browser (2010) • @fmaul 3 (c) fme AG - #205626
  • 3. Agenda • Kurzvorstellung fme AG • fme Alfresco Extensions • Was ist die Javascript Konsole? • Viele Demos mit Beispielskripten 4 © fme AG - #212261
  • 4. Das Unternehmen Q1/2012 Techno- Lösungen logien Wir unterstützen unsere Kunden dabei, Informationen effektiver und effizienter zu strukturieren und verwalten. Dies erreichen wir Unser durch den Einsatz von Enterprise Content Management, Business Branchen Fokus Intelligence und Product Lifecycle Management Technologien. Der Schwerpunkt liegt auf Lösungen für Life Sciences, industrielle Fertigung und Energie. • Gründung: 1995, Hauptsitz: Braunschweig, ca. 105 Mitarbeiter (fme-Gruppe) • Weitere Geschäftsstellen in München, Düsseldorf, Frankfurt • Töchter in Rumänien (100 %) und in den USA (60 %) Fakten • Mehr als 10 Jahre EMC-Partner (höchster Partnerstatus), mehr als 80 ECM-Berater • International tätig • „We use what we sell“ • Mehr als 130 ECM-Kunden weltweit 5 #6120 - © fme AG
  • 5. Kunden fme AG Auswahl Industrielle Fertigung Life Science Energie Weitere 6 © fme AG - #212261
  • 6. fme Migration Center Analyse Organise Transform Validate Correct Import Time 7 (c) fme AG - #205626
  • 7. fme Alfresco Extensions Gallery • http://alfresco.fme.de/Overview.925.0.html • 14 gelistete Alfresco Erweiterungen • 8 unter Open Source (Sponsors wanted!) • 6 unter Kommerzieller Lizenz • Fokus:  Bedienkomfort von Alfresco maximieren  Oft benötigte/angefragte Erweiterungen in Form von wiederverwendbaren Modulen  Verwendung dieser Erweiterungen bei der Umsetzung branchen-/kundenspezifischer Alfresco Lösungen 8 © fme AG - #212261
  • 8. Alfresco APIs • What kinds of API are there?  Java Foundation API  Javascript API & Javascript Services  CMIS • Where can I use Javascript in Alfresco:  Webscripts developed in Javascript  Javascript run by Actions (Run Script Action)  Javascript attached to Tasks & Events in Workflows 9 (c) fme AG - #205626
  • 9. Webscripts developed in Javascript • Most of the Alfresco Webscript are developed in Javascript • Example: GET /alfresco/service/sample/blog/category/{category} // check category exists? var category = search.luceneSearch( "PATH:"/cm:generalclassifiable//cm:" + url.extension + """); if (category == undefined) { status.code = 404; status.message = "Category " + url.extension + " not found."; status.redirect = true; } else { // perform category search var nodes = search.luceneSearch( "PATH:"/cm:generalclassifiable//cm:" + url.extension + "//member""); model.resultset = nodes; } 10 (c) fme AG - #205626
  • 10. Javascript for Tasks & Events in Workflows • Javascript can be executed from within Workflow definitions • Example of Activti Workflow: parallelreview_group_processdefinition.xml <decision name="isapproved"> <event type="node-enter"> <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript"> <script> <variable name="wf_actualPercent" access="write"/> <expression> wf_actualPercent = ((wf_approveCount * 100) / people.getMembers(bpm_groupAssignee).length); </expression> </script> </action> </event> </decision> 11 (c) fme AG - #205626
  • 11. Javascript run by Actions (Run Script Action) • Alfresco Explorer has a Run Script Action • For Share there is an Execute Script extension in Share-Extras: 12 (c) fme AG - #205626
  • 12. But how to develop Javascript code? • Webscripts  Develop in Eclipse  ANT build script to copy changes & reload the webscripts  Run the webscript manually in the browser • Data Dictionary Scripts  upload script to Data Dictionary  run Script Action  watch errors in the Alfresco Log file (ScriptLogger=DEBUG)  fix bugs and iterate •  It takes to long to test out Javascript code and fix bugs. 13 (c) fme AG - #205626
  • 13. Meet the Javascript Console 14 (c) fme AG - #205626
  • 14. JavaScript Console • Komponente für die Share Admin Console zum Schreiben & Ausführen von JavaScript-Code im Repository  Vollzugriff auf die Alfresco JavaScript API  Auswahl des Ausführungskontext (Ordner)  Einfache Code-Completion  Laden & Speichern von Skripten  Formatierung von Ergebnislisten in Form einer Tabelle (v0.4.x)  Import von JavaScript-Dateien aus dem Alfresco Classpath  Verwendung von Freemarker-Templates zur Formatierung der Ergebnismenge (v0.5) 15 © fme AG - #212261
  • 15. Meet the Javascript Console • • Mike Farman (Director Product Management Alfresco): „I really like the stuff you’ve been doing, my favourite is the JavaScript console, it’s the first add-on I always install!“ • X 16 (c) fme AG - #205626
  • 16. Javascript Console milestones • End of 2010  Need to develop and execute Javascript code for a project sparked development of the first prototype  First internal versions were a single standalone page in Share • April 2011:  Contact with Will Abson  refactoring and integration into the admin console of Alfresco 3.4 • May 2011:  First checkin into the Share-Extras project and first public release • Nov 2011:  Version 0.4 with basic code completion • June 2012:  Version 0.5 with freemarker editor 17 (c) fme AG - #205626
  • 17. Download & Installation • Visit: http://code.google.com/p/share-extras/ • Download at http://code.google.com/p/share-extras/downloads/list Installation • For version 0.4.x copy the jar file to tomcat/shared/lib/ • With 0.5 there will be two jar files –repo.jar and –share.jar. The repo.jar must be copied to tomcat/webapps/alfresco/WEB-INF/lib and the share.jar to tomcat/webapps/share/WEB-INF/lib. 18 (c) fme AG - #205626
  • 18. Poor man‘s Nodebrowser print(document); print("--- PROPERTIES -----------------------------------------"); print(document.properties); print("--- ASPECTS --------------------------------------------"); print(document.aspects); print("--- ASSOCS ---------------------------------------------"); print(document.assocs); print("--- PERMISSIONS ----------------------------------------"); print(document.fullPermissions); 19 (c) fme AG - #205626
  • 19. How does it work? Alfresco Repository / Webscripts • print(), recurse(), logger • eval() / Java-Webscript • <imports> Execute Webscript • Error handling Browser / Javascript / YUI / Codemirror Input Output • Javascript • Print / log output • Freemarker template • Freemarker output • space / document • Error messages 20 (c) fme AG - #205626
  • 20. Selecting the file or folder to work with • Select the space variable from • Open any document in the a directory chooser: Javascript Console from the document library: 21 (c) fme AG - #205626
  • 21. Recurse() function • The Javascript console has a special recurse function to iterate over a tree of nodes: recurse(space, function(node) { if (node.name.toLowerCase().indexOf("alfresco") >= 0) { print("adding tag alfresco to " + node.displayPath + "/" + node.name); node.addTag("alfresco"); } }); • If no function is given it returns the nodes as an array: var allNodes = recurse(space); 22 (c) fme AG - #205626
  • 22. Creating users and attaching avatars function createUser(username,firstname, lastname, email, location, jobtitle) { var password = username; // use for testing only! var p = people.createPerson(username, firstname, lastname, email, password, true); p.properties["cm:location"] = location; p.properties["cm:jobtitle"] = jobtitle; p.save(); } createUser("homer", "Homer", "Simpson", "h.simpson@springfield.fox", "Springfield", "Nuclear Safety Inspector"); 23 (c) fme AG - #205626
  • 23. Creating users and attaching avatars // pseudo-code not working for each (imageNode in space.children) { var user = people.getPerson(name); user.createAssociation( imageNode, "cm:avatar"); } Full source code here: http://www.techbits.de/2011/12/02/using-the-javascript-console-creating-users-with-avatar-images/ 24 (c) fme AG - #205626
  • 24. Assign users to sites var nodes = search.luceneSearch( "TYPE:cm:person +@cm:lastName:Simpson"); for each(var simpson in nodes) { var site = siteService.getSite( "javascript-console-talk"); site.setMembership( simpson.properties["cm:userName"], "SiteCollaborator"); } 25 (c) fme AG - #205626
  • 25. Creating Webscripts • The new version 0.5 makes it easy to create webscripts:  Write a controller javascript using logger.log output  Create a freemarker template  Test different URL arguments and different users 26 (c) fme AG - #205626
  • 26. Creating Webscripts var result = []; for each(node in companyhome.childByNamePath(args.path).children) { result.push({ name : node.name, creator : node.properties["cm:creator"], creationDate : node.properties["cm:created"] }); } model.folder = result; [ <#list folder as f> { "name" : "${f.name}", "creator" : "${f.creator}", "creationDate" : "${f.creationDate?date}" } </#list> ] 27 (c) fme AG - #205626
  • 27. Access spring beans / unlock documents • Example unlock a document: var ctx = Packages.org.springframework. web.context.ContextLoader.getCurrentWebApplicationContext(); var lockService = ctx.getBean("lockService"); lockService.unlock(document.nodeRef); • This looks like a hack but is perfectly valid Alfresco Javascript • It only works in Javascript stored in the Classpath (not in the Data Dictionary) • Also very useful to test your own Beans written in Java 28 (c) fme AG - #205626
  • 28. Access spring beans / reindex nodes • We faced the issue with nodes getting lost from the index. ALF-12588 • You can force the reindexing of single nodes: var ctx = Packages.org.springframework.web.context.ContextLoader.getCurrentWebAppl icationContext(); var nodeIndexer = ctx.getBean("nodeIndexer"); var nodeService = ctx.getBean("nodeService"); function indexNode(node) { var childAssoc = nodeService.getPrimaryParent(node.nodeRef); nodeIndexer.indexCreateNode(childAssoc); } indexNode(search.findNode("workspace://SpacesStore/d4923a10-96dc-4565- a471-d6b6c8f7b170")); • Warning: With great power comes great responsibility! 29 (c) fme AG - #205626
  • 29. Special access to logger configuration • The Javascript Console allows you to change to log4j log level at runtime. • For your own Java classes you can use: logger.setLevel("de.fme.alfresco", "DEBUG"); • The Alfresco Javascript runtime uses the ScriptLogger class: logger.setLevel("org.alfresco.repo.jscript.ScriptLogger", "DEBUG"); 30 (c) fme AG - #205626
  • 30. Javascript Puzzlers – Alfresco Edition What do these two do? • node.properties["cm:name"] = "textfile.txt"; • node.name = "textfile.txt"; Comparing ScriptNode nodeRefs: • node1.nodeRef.equals(node2.nodeRef) • node1.nodeRef == node2.nodeRef • " " +node1.nodeRef == " " + node2.nodeRef 31 (c) fme AG - #205626
  • 31. Batch processing • Examples:  Set all documents to inherit permissions  Disable automatic versioning for all documents • Small batches can run in the Javascript Console in one Transaction (10000 nodes)  I install the Javascript Console on every production system • Large batches currently only possible using Java with multiple Transactions. • Batch processing (updates for >100000 nodes)  How to find the nodes? Search or recursion?  Can not run in one transaction: Transaction Management in Javascript?  Processing in smaller batches  How to make use of multithreading? 32 (c) fme AG - #205626
  • 32. Fragen, Feedback …? • f.maul@fme.de • http://twitter.com/#!/fmaul 33 © fme AG - #212261