SlideShare a Scribd company logo
The Road to Damascus – A Conversion 
Experience: 
LS and @Formula to SSJS 
Matthew Fyleman, Product and Project Manager 
MWLUG 2014
Who am I? 
• Matthew Fyleman 
• 21 Years as a Notes/Domino Developer 
• Mostly Working on: 
– Xpages conversions 
– Product development
What is this Talk About? 
• Based on My Experiences 
• Converting LotusScript and @Formula 
to SSJS 
• Tools that can help – particularly 
regular expressions
What am I talking about? 
• When should you convert existing code? 
• Conversion Options 
– NotesAgent.run() with parameter doc 
– Search and Replace 
– Dedicated Tools 
• Search and Replace 
– Preparation 
– Introduction to Regular Expressions 
– Examples and Demonstration 
– Tips and Traps 
• Dedicated Tools 
• Questions
When should you convert code? 
Never!
When should you convert code? 
What is the problem? 
• It is always going to be slow 
• GIGO 
• You will introduce new bugs 
• Re-developing will be quicker, cheaper 
and you will end up with a better result 
• But if you really must ...
Conversion Options 
What are your options? 
• NotesAgent.run() 
– Quick and Dirty 
– Agent must run independently 
– Only use when agents are available and time is critical 
• Search and Replace 
– LotusScript -> JavaScript (and Java) 
– Less useful for @Formula 
• Dedicated Tools 
– @Formula
LotusScript to SSJS - Preparation 
• Search and Replace is most useful for LS conversion 
– Syntactically similar 
• Easiest if you do a little refactoring first 
– Option Declare 
– doc.field(0) -> doc.getItemValue(“Field“)(0) 
– Camel Case Notes Objects 
– Make Sure Method calls are consistently named 
• Best to Avoid All-In-One-Go 
– Function or Sub at a Time
Regular Expressions 
• Regular Expressions are your new BFF 
• Sophisticated Pattern Matching 
• Elements from search can be carried through to 
replace 
• The Search and Replace built in to DDE can use 
Regular Expressions 
• Useful outside LS conversion (e.g. Validation) 
– See Planet Lotus - http://planetlotus.org/profiles/ross-swick_97733
Starting Simple – Dim 
• Tidy up first – Option Declare, remove clustering e.g.: 
Dim x as Integer,y as Integer,z as Integer 
• We want to match any variable name in the pattern: 
Dim <var name> As <Any valid type> 
• Fairly simple: 
Dim[ ]+[A-Za-z0-9_]+[ ]+As[ ]+(Integer|String|Boolean|Double|Variant) 
• But how do we replace? 
– Modify the search: 
Dim[ ]+([w]*)[ ]+As[ ]+String 
– Use this for replace 
var 1 = “”;
Starting Simple – Dim (2) 
• For Notes Objects, Things are simpler 
Dim <var name> As Notes<rest of object name> 
- Ignore ... As New NotesSession for now 
• Also, initialising in SSJS, = null is ok: 
var <var name>:Notes<rest of object name> = null; 
• So our terms are: 
– Search: 
Dim[ ]+([w]*)[ ]+As[ ]+(Notes[w]*) 
– Replace: 
var 1:2 = null;
Less simple – If Statements 
• For the most part, simple S & R (but order is important): 
End If to } 
[ ]*Then to ) { 
Else[ ]+If[ ]* to } else if ( 
If[ ]* to if ( 
• But what about: 
If (x = 10) Then 
• Use Search: If[ ]+([w()[].<>" ]*)=([w()[].<> "]*)[ ]+Then 
• Use Replace: if (1==2) { 
• NB: Works but not optimal! 
• Other comparison operators not a problem
! – session objects 
• The problem: 
• Session object is global in ssjs: ‘session’ 
• In LS it is created: 
Dim sess As New NotesSession 
• Need to find all LS session objects, and replace with session 
• How do you get a list of session object names? 
You need a coffee!
Adding Java 
• Java String Object has regex search and replace 
String source = “Dim x As String”; 
String result = source.replaceAll(“Dim[ ]+([w]*)[ ]+As[ ]+String”, “var $1 = “”;”); 
• Pattern and Matcher objects make this even more powerful 
Pattern p = Pattern.compile(pattern); 
Matcher m = p.matcher(this.source); 
int startPos = 0; 
while (m.find(startPos)) { 
if (!itemList.contains(m.group(1))) { 
itemList.add(m.group(1)); 
} 
startPos = m.end() + 1; 
}
Field Handling 
• Similar Issue to Session 
• Need to find all document object names, and replace field 
handling methods 
• Will probably need to handle dot notation 
– Arrgghh! 
• How do you search for dot notation? 
<doc name>.([^GetItemValue])([0-9]+) 
• Still hard work!
Search and Replace: Tips & Traps 
• There are other types than string! 
– Always review and test converted code thoroughly 
• Date handling is a pain 
– Script libraries can help here – Java? 
• Watch out for User interaction and particularly dialogues 
Work out your strategies in advance!
Converting Formula 
• @Formula JavaScript Wrappers help a lot 
– Mostly just ‘;’ to ‘,’, and converting lists to arrays 
• Some constructions are obvious: 
@SetField(“Field”, Value); 
• Goes to: 
doc.replaceItemValue(“Field”, Value); 
• Or 
S: @SetField([ ]*([w”]*)[ ]*,[ ]*([w”]*)[ ]*); 
R: doc.replaceItemValue(1, 2); 
• But there are some issues ... 
@
Formula – List Processing 
• No direct equivalent in SSJS for *+, *= *>= etc. 
when applied to Lists 
• Need to plan for this 
• Java Class/Library to provide direct substitute 
• Unfortunately, Java does not permit operator 
overloading, so has to be a set of methods 
@!
Formula - @If, @Do and @While 
@If(@Contains(_WFData_neu;_Key);""; 
@Do( 
@Set("_Sachgebiet_Zuordnung";@DbLookup("NOTES":"NOCACHE";"":_ADM$StructureDB;"Workflows";"WFArbeitsanweisung";"Sachgebietzuordnung")); 
@If(_Sachgebiet_Zuordnung = "" | !@Contains(_Sachgebiet_Zuordnung;_Key2);@Do( 
@Prompt([Ok];"Hinweis";"In der System Struktur VBM wurde für das aktuelle Sachgebiet kein Workflow definiert. Das Dokument wird zum ehemaligen 
Kompetenzträger zurückgegeben, damit dieser ein neues Sachgebiet auswählen kann."); 
@Set("_Kompetenzträger";Bearbeiter1); 
@Set("_tmpintern";5) 
); 
@Do( 
@Prompt([Ok];"Hinweis";"In der System Struktur VBM wurde für das aktuelle Sachgebiet ein neues Sachgebiet konfiguriert. Das Dokument wird zum 
Kompetenzträger zurückgegeben, damit dieser das neue Sachgebiet auswählen kann."); 
@Set("_neues_Sachgebiet";@Left(@Right(_Sachgebiet_Zuordnung;_key2);"||")); 
@Set("_Elements";@Elements(@Explode(@Left(@Left(@Right(_WFData_neu;"||Sachgebiet#");"||"); _neues_Sachgebiet) + _neues_Sachgebiet; "$" ))); 
@Set("_KompetenzträgerData";@Explode(@Left(@Right(_WFData_neu;"||Kompetenzträger#");"||"); "$")); 
@Set("_Kompetenzträger";@Subset(@Subset(_KompetenzträgerData;_Elements);-1)); 
@Set("_tmpintern";6) 
) 
) 
) 
); @!!
Focusing on @If 
• @Formula is a FUNCTION language 
• @If is a function not a statement 
@!!! • In practice: 
@SetField(“Author”; @If(Status=“1”; Manager; Salesman)); 
• Needs to convert to: 
if (Status == “1”) { 
var author = doc.getItemValueString(“Manager”); 
} else { 
var author = doc.getItemValueString(“Salesman”); 
} 
doc.replaceItemValue(“Author”, author);
Tools 
• Search and Replace can be used for @Formula -> 
SSJS ... 
• ... but it can only take you so far 
• A dedicated tool can go further 
– Only real alternative to manual translation for complex 
statements 
– Time consuming to create 
– Still not a silver bullet
Third Party Tools 
• Espresso - http://www.ultrapico.com/Expresso.htm 
– Good for learning regex, and serious regex dev 
– Free! 
• GREP 
– Sophisticated regex file search 
– Where regex started (UNIX grep)!
Resources and Information 
• We4IT – www.we4it.com 
• OpenNTF – www.openntf.org 
• Regex Quick Reference 
http://www.night-ray.com/regex.pdf 
• Loads of websites for all aspects of regex development 
• Mastering Regular Expressions – Jeffrey E.F. Friedl – 
O’Reilly Publishing
Questions?
matthew.fyleman@we4it.com

More Related Content

What's hot

Search Engine-Building with Lucene and Solr
Search Engine-Building with Lucene and SolrSearch Engine-Building with Lucene and Solr
Search Engine-Building with Lucene and Solr
Kai Chan
 
Introduction To Groovy
Introduction To GroovyIntroduction To Groovy
Introduction To Groovy
manishkp84
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3
Jeremy Coates
 
Namespace in C++ Programming Language
Namespace in C++ Programming LanguageNamespace in C++ Programming Language
Namespace in C++ Programming Language
Himanshu Choudhary
 
Functional programming with Scala
Functional programming with ScalaFunctional programming with Scala
Functional programming with Scala
Neelkanth Sachdeva
 
groovy rules
groovy rulesgroovy rules
groovy rules
Paul King
 
Java XML Parsing
Java XML ParsingJava XML Parsing
Java XML Parsing
srinivasanjayakumar
 
Building Data Mapper PHP5
Building Data Mapper PHP5Building Data Mapper PHP5
Building Data Mapper PHP5
Vance Lucas
 
Linq Introduction
Linq IntroductionLinq Introduction
Linq Introduction
Neeraj Kaushik
 
Tutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component pluginTutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component plugin
searchbox-com
 
Designing and Building a Graph Database Application – Architectural Choices, ...
Designing and Building a Graph Database Application – Architectural Choices, ...Designing and Building a Graph Database Application – Architectural Choices, ...
Designing and Building a Graph Database Application – Architectural Choices, ...
Neo4j
 
SFDC Introduction to Apex
SFDC Introduction to ApexSFDC Introduction to Apex
SFDC Introduction to Apex
Sujit Kumar
 
Querydsl overview 2014
Querydsl overview 2014Querydsl overview 2014
Querydsl overview 2014
Timo Westkämper
 
Prototype Js
Prototype JsPrototype Js
Prototype Js
Kivanc Kanturk
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
Mohammed Irfan Shaikh
 
Querydsl fin jug - june 2012
Querydsl   fin jug - june 2012Querydsl   fin jug - june 2012
Querydsl fin jug - june 2012
Timo Westkämper
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
agorolabs
 
Advanced Relevancy Ranking
Advanced Relevancy RankingAdvanced Relevancy Ranking
Advanced Relevancy Ranking
Search Technologies
 
MongoDB crud
MongoDB crudMongoDB crud
MongoDB crud
Darshan Jayarama
 
Query Parsing - Tips and Tricks
Query Parsing - Tips and TricksQuery Parsing - Tips and Tricks
Query Parsing - Tips and Tricks
Erik Hatcher
 

What's hot (20)

Search Engine-Building with Lucene and Solr
Search Engine-Building with Lucene and SolrSearch Engine-Building with Lucene and Solr
Search Engine-Building with Lucene and Solr
 
Introduction To Groovy
Introduction To GroovyIntroduction To Groovy
Introduction To Groovy
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3
 
Namespace in C++ Programming Language
Namespace in C++ Programming LanguageNamespace in C++ Programming Language
Namespace in C++ Programming Language
 
Functional programming with Scala
Functional programming with ScalaFunctional programming with Scala
Functional programming with Scala
 
groovy rules
groovy rulesgroovy rules
groovy rules
 
Java XML Parsing
Java XML ParsingJava XML Parsing
Java XML Parsing
 
Building Data Mapper PHP5
Building Data Mapper PHP5Building Data Mapper PHP5
Building Data Mapper PHP5
 
Linq Introduction
Linq IntroductionLinq Introduction
Linq Introduction
 
Tutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component pluginTutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component plugin
 
Designing and Building a Graph Database Application – Architectural Choices, ...
Designing and Building a Graph Database Application – Architectural Choices, ...Designing and Building a Graph Database Application – Architectural Choices, ...
Designing and Building a Graph Database Application – Architectural Choices, ...
 
SFDC Introduction to Apex
SFDC Introduction to ApexSFDC Introduction to Apex
SFDC Introduction to Apex
 
Querydsl overview 2014
Querydsl overview 2014Querydsl overview 2014
Querydsl overview 2014
 
Prototype Js
Prototype JsPrototype Js
Prototype Js
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
Querydsl fin jug - june 2012
Querydsl   fin jug - june 2012Querydsl   fin jug - june 2012
Querydsl fin jug - june 2012
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
 
Advanced Relevancy Ranking
Advanced Relevancy RankingAdvanced Relevancy Ranking
Advanced Relevancy Ranking
 
MongoDB crud
MongoDB crudMongoDB crud
MongoDB crud
 
Query Parsing - Tips and Tricks
Query Parsing - Tips and TricksQuery Parsing - Tips and Tricks
Query Parsing - Tips and Tricks
 

Viewers also liked

Interruptores
InterruptoresInterruptores
Interruptores
Juancho Medallo
 
Iisrt settu ravichandran (civil)
Iisrt settu ravichandran (civil)Iisrt settu ravichandran (civil)
Iisrt settu ravichandran (civil)
IISRT
 
Iisrt zzz satyabrata khatua
Iisrt zzz satyabrata khatuaIisrt zzz satyabrata khatua
Iisrt zzz satyabrata khatua
IISRT
 
Iisrt aarthi ravindran (networks)
Iisrt aarthi ravindran (networks)Iisrt aarthi ravindran (networks)
Iisrt aarthi ravindran (networks)
IISRT
 
Iisrt zzz bhavyasri vanteddu
Iisrt zzz bhavyasri vantedduIisrt zzz bhavyasri vanteddu
Iisrt zzz bhavyasri vanteddu
IISRT
 
Woven Wire Partitions
Woven Wire PartitionsWoven Wire Partitions
Antena Kaleng (raihan s & syis f)
Antena Kaleng (raihan s & syis f)Antena Kaleng (raihan s & syis f)
Antena Kaleng (raihan s & syis f)
raihansayyid
 
Vembu SaaSBackup – Backup Solution for Office 365 and Google Apps !
Vembu SaaSBackup – Backup Solution for Office 365 and Google Apps !Vembu SaaSBackup – Backup Solution for Office 365 and Google Apps !
Vembu SaaSBackup – Backup Solution for Office 365 and Google Apps !
Saravanan Sri
 
Questões -rotinas_administrativas_alunos
Questões  -rotinas_administrativas_alunosQuestões  -rotinas_administrativas_alunos
Questões -rotinas_administrativas_alunos
Joice Souza
 
Sistema de gestion en seguridad y salud leere urgente
Sistema de gestion en seguridad y salud leere urgenteSistema de gestion en seguridad y salud leere urgente
Sistema de gestion en seguridad y salud leere urgente
Alina Cajaleon
 
Persentasi Jaringan WAN (Raihan & Badi)
Persentasi Jaringan WAN (Raihan & Badi)Persentasi Jaringan WAN (Raihan & Badi)
Persentasi Jaringan WAN (Raihan & Badi)
raihansayyid
 
foreveryoungasia
foreveryoungasiaforeveryoungasia
foreveryoungasia
Ratha Eagle
 
asdfghjkl
asdfghjklasdfghjkl
asdfghjkl
Andres Felipe
 
preciptation profiles on sprinkler irrigation
preciptation profiles on sprinkler irrigationpreciptation profiles on sprinkler irrigation
preciptation profiles on sprinkler irrigation
Keshav Achugatla
 
Iisrt sibi kumar (mech)
Iisrt sibi kumar (mech)Iisrt sibi kumar (mech)
Iisrt sibi kumar (mech)
IISRT
 
Kids Collection In Chennai
Kids Collection In ChennaiKids Collection In Chennai
Kids Collection In Chennai
saree123
 
Iisrt karthik subramanian
Iisrt karthik subramanianIisrt karthik subramanian
Iisrt karthik subramanian
IISRT
 
Termes de référence du forum national d’échanges et de validation du contrat ...
Termes de référence du forum national d’échanges et de validation du contrat ...Termes de référence du forum national d’échanges et de validation du contrat ...
Termes de référence du forum national d’échanges et de validation du contrat ...
Global Water Initiative - West Africa
 
Map Edit Records to Forms
Map Edit Records to FormsMap Edit Records to Forms
Map Edit Records to Forms
OutSystems Technical Knowledge
 
Communication sur l’étude « Analyse de la problématique de la mise en applica...
Communication sur l’étude « Analyse de la problématique de la mise en applica...Communication sur l’étude « Analyse de la problématique de la mise en applica...
Communication sur l’étude « Analyse de la problématique de la mise en applica...
Global Water Initiative - West Africa
 

Viewers also liked (20)

Interruptores
InterruptoresInterruptores
Interruptores
 
Iisrt settu ravichandran (civil)
Iisrt settu ravichandran (civil)Iisrt settu ravichandran (civil)
Iisrt settu ravichandran (civil)
 
Iisrt zzz satyabrata khatua
Iisrt zzz satyabrata khatuaIisrt zzz satyabrata khatua
Iisrt zzz satyabrata khatua
 
Iisrt aarthi ravindran (networks)
Iisrt aarthi ravindran (networks)Iisrt aarthi ravindran (networks)
Iisrt aarthi ravindran (networks)
 
Iisrt zzz bhavyasri vanteddu
Iisrt zzz bhavyasri vantedduIisrt zzz bhavyasri vanteddu
Iisrt zzz bhavyasri vanteddu
 
Woven Wire Partitions
Woven Wire PartitionsWoven Wire Partitions
Woven Wire Partitions
 
Antena Kaleng (raihan s & syis f)
Antena Kaleng (raihan s & syis f)Antena Kaleng (raihan s & syis f)
Antena Kaleng (raihan s & syis f)
 
Vembu SaaSBackup – Backup Solution for Office 365 and Google Apps !
Vembu SaaSBackup – Backup Solution for Office 365 and Google Apps !Vembu SaaSBackup – Backup Solution for Office 365 and Google Apps !
Vembu SaaSBackup – Backup Solution for Office 365 and Google Apps !
 
Questões -rotinas_administrativas_alunos
Questões  -rotinas_administrativas_alunosQuestões  -rotinas_administrativas_alunos
Questões -rotinas_administrativas_alunos
 
Sistema de gestion en seguridad y salud leere urgente
Sistema de gestion en seguridad y salud leere urgenteSistema de gestion en seguridad y salud leere urgente
Sistema de gestion en seguridad y salud leere urgente
 
Persentasi Jaringan WAN (Raihan & Badi)
Persentasi Jaringan WAN (Raihan & Badi)Persentasi Jaringan WAN (Raihan & Badi)
Persentasi Jaringan WAN (Raihan & Badi)
 
foreveryoungasia
foreveryoungasiaforeveryoungasia
foreveryoungasia
 
asdfghjkl
asdfghjklasdfghjkl
asdfghjkl
 
preciptation profiles on sprinkler irrigation
preciptation profiles on sprinkler irrigationpreciptation profiles on sprinkler irrigation
preciptation profiles on sprinkler irrigation
 
Iisrt sibi kumar (mech)
Iisrt sibi kumar (mech)Iisrt sibi kumar (mech)
Iisrt sibi kumar (mech)
 
Kids Collection In Chennai
Kids Collection In ChennaiKids Collection In Chennai
Kids Collection In Chennai
 
Iisrt karthik subramanian
Iisrt karthik subramanianIisrt karthik subramanian
Iisrt karthik subramanian
 
Termes de référence du forum national d’échanges et de validation du contrat ...
Termes de référence du forum national d’échanges et de validation du contrat ...Termes de référence du forum national d’échanges et de validation du contrat ...
Termes de référence du forum national d’échanges et de validation du contrat ...
 
Map Edit Records to Forms
Map Edit Records to FormsMap Edit Records to Forms
Map Edit Records to Forms
 
Communication sur l’étude « Analyse de la problématique de la mise en applica...
Communication sur l’étude « Analyse de la problématique de la mise en applica...Communication sur l’étude « Analyse de la problématique de la mise en applica...
Communication sur l’étude « Analyse de la problématique de la mise en applica...
 

Similar to The Road To Damascus - A Conversion Experience: LotusScript and @Formula to SSJS

Icsug conf 14_dev03_xpages-roadtodamascas-lotus-script-and-formula-to-ssjs
Icsug conf 14_dev03_xpages-roadtodamascas-lotus-script-and-formula-to-ssjsIcsug conf 14_dev03_xpages-roadtodamascas-lotus-script-and-formula-to-ssjs
Icsug conf 14_dev03_xpages-roadtodamascas-lotus-script-and-formula-to-ssjs
ICS User Group
 
Modern, Scalable, Ambitious apps with Ember.js
Modern, Scalable, Ambitious apps with Ember.jsModern, Scalable, Ambitious apps with Ember.js
Modern, Scalable, Ambitious apps with Ember.js
Mike North
 
Java Script
Java ScriptJava Script
Java Script
Sarvan15
 
Java Script
Java ScriptJava Script
Java Script
Sarvan15
 
javaScript.ppt
javaScript.pptjavaScript.ppt
javaScript.ppt
sentayehu
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
Lars Marius Garshol
 
Powershell Training
Powershell TrainingPowershell Training
Powershell Training
Fahad Noaman
 
DIG1108C Lesson3 Fall 2014
DIG1108C Lesson3 Fall 2014DIG1108C Lesson3 Fall 2014
DIG1108C Lesson3 Fall 2014
David Wolfpaw
 
Дмитрий Нестерук, Паттерны проектирования в XXI веке
Дмитрий Нестерук, Паттерны проектирования в XXI векеДмитрий Нестерук, Паттерны проектирования в XXI веке
Дмитрий Нестерук, Паттерны проектирования в XXI веке
Sergey Platonov
 
Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2
Henry S
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
Mike Harris
 
A brief tour of modern Java
A brief tour of modern JavaA brief tour of modern Java
A brief tour of modern Java
Sina Madani
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
Edureka!
 
Design Patterns in Modern C++
Design Patterns in Modern C++Design Patterns in Modern C++
Design Patterns in Modern C++
Dmitri Nesteruk
 
PostgreSQL - It's kind've a nifty database
PostgreSQL - It's kind've a nifty databasePostgreSQL - It's kind've a nifty database
PostgreSQL - It's kind've a nifty database
Barry Jones
 
Rich Internet Applications con JavaFX e NetBeans
Rich Internet Applications  con JavaFX e NetBeans Rich Internet Applications  con JavaFX e NetBeans
Rich Internet Applications con JavaFX e NetBeans
Fabrizio Giudici
 
PLSQL-OO [SOUG 2022].pptx
PLSQL-OO [SOUG 2022].pptxPLSQL-OO [SOUG 2022].pptx
PLSQL-OO [SOUG 2022].pptx
Richard Martens
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
jimbojsb
 
AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)
Paul Chao
 
FFW Gabrovo PMG - JavaScript 1
FFW Gabrovo PMG - JavaScript 1FFW Gabrovo PMG - JavaScript 1
FFW Gabrovo PMG - JavaScript 1
Toni Kolev
 

Similar to The Road To Damascus - A Conversion Experience: LotusScript and @Formula to SSJS (20)

Icsug conf 14_dev03_xpages-roadtodamascas-lotus-script-and-formula-to-ssjs
Icsug conf 14_dev03_xpages-roadtodamascas-lotus-script-and-formula-to-ssjsIcsug conf 14_dev03_xpages-roadtodamascas-lotus-script-and-formula-to-ssjs
Icsug conf 14_dev03_xpages-roadtodamascas-lotus-script-and-formula-to-ssjs
 
Modern, Scalable, Ambitious apps with Ember.js
Modern, Scalable, Ambitious apps with Ember.jsModern, Scalable, Ambitious apps with Ember.js
Modern, Scalable, Ambitious apps with Ember.js
 
Java Script
Java ScriptJava Script
Java Script
 
Java Script
Java ScriptJava Script
Java Script
 
javaScript.ppt
javaScript.pptjavaScript.ppt
javaScript.ppt
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
 
Powershell Training
Powershell TrainingPowershell Training
Powershell Training
 
DIG1108C Lesson3 Fall 2014
DIG1108C Lesson3 Fall 2014DIG1108C Lesson3 Fall 2014
DIG1108C Lesson3 Fall 2014
 
Дмитрий Нестерук, Паттерны проектирования в XXI веке
Дмитрий Нестерук, Паттерны проектирования в XXI векеДмитрий Нестерук, Паттерны проектирования в XXI веке
Дмитрий Нестерук, Паттерны проектирования в XXI веке
 
Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
 
A brief tour of modern Java
A brief tour of modern JavaA brief tour of modern Java
A brief tour of modern Java
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
 
Design Patterns in Modern C++
Design Patterns in Modern C++Design Patterns in Modern C++
Design Patterns in Modern C++
 
PostgreSQL - It's kind've a nifty database
PostgreSQL - It's kind've a nifty databasePostgreSQL - It's kind've a nifty database
PostgreSQL - It's kind've a nifty database
 
Rich Internet Applications con JavaFX e NetBeans
Rich Internet Applications  con JavaFX e NetBeans Rich Internet Applications  con JavaFX e NetBeans
Rich Internet Applications con JavaFX e NetBeans
 
PLSQL-OO [SOUG 2022].pptx
PLSQL-OO [SOUG 2022].pptxPLSQL-OO [SOUG 2022].pptx
PLSQL-OO [SOUG 2022].pptx
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
 
AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)
 
FFW Gabrovo PMG - JavaScript 1
FFW Gabrovo PMG - JavaScript 1FFW Gabrovo PMG - JavaScript 1
FFW Gabrovo PMG - JavaScript 1
 

Recently uploaded

Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
GohKiangHock
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Envertis Software Solutions
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 

Recently uploaded (20)

Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 

The Road To Damascus - A Conversion Experience: LotusScript and @Formula to SSJS

  • 1. The Road to Damascus – A Conversion Experience: LS and @Formula to SSJS Matthew Fyleman, Product and Project Manager MWLUG 2014
  • 2. Who am I? • Matthew Fyleman • 21 Years as a Notes/Domino Developer • Mostly Working on: – Xpages conversions – Product development
  • 3. What is this Talk About? • Based on My Experiences • Converting LotusScript and @Formula to SSJS • Tools that can help – particularly regular expressions
  • 4. What am I talking about? • When should you convert existing code? • Conversion Options – NotesAgent.run() with parameter doc – Search and Replace – Dedicated Tools • Search and Replace – Preparation – Introduction to Regular Expressions – Examples and Demonstration – Tips and Traps • Dedicated Tools • Questions
  • 5. When should you convert code? Never!
  • 6. When should you convert code? What is the problem? • It is always going to be slow • GIGO • You will introduce new bugs • Re-developing will be quicker, cheaper and you will end up with a better result • But if you really must ...
  • 7. Conversion Options What are your options? • NotesAgent.run() – Quick and Dirty – Agent must run independently – Only use when agents are available and time is critical • Search and Replace – LotusScript -> JavaScript (and Java) – Less useful for @Formula • Dedicated Tools – @Formula
  • 8. LotusScript to SSJS - Preparation • Search and Replace is most useful for LS conversion – Syntactically similar • Easiest if you do a little refactoring first – Option Declare – doc.field(0) -> doc.getItemValue(“Field“)(0) – Camel Case Notes Objects – Make Sure Method calls are consistently named • Best to Avoid All-In-One-Go – Function or Sub at a Time
  • 9. Regular Expressions • Regular Expressions are your new BFF • Sophisticated Pattern Matching • Elements from search can be carried through to replace • The Search and Replace built in to DDE can use Regular Expressions • Useful outside LS conversion (e.g. Validation) – See Planet Lotus - http://planetlotus.org/profiles/ross-swick_97733
  • 10. Starting Simple – Dim • Tidy up first – Option Declare, remove clustering e.g.: Dim x as Integer,y as Integer,z as Integer • We want to match any variable name in the pattern: Dim <var name> As <Any valid type> • Fairly simple: Dim[ ]+[A-Za-z0-9_]+[ ]+As[ ]+(Integer|String|Boolean|Double|Variant) • But how do we replace? – Modify the search: Dim[ ]+([w]*)[ ]+As[ ]+String – Use this for replace var 1 = “”;
  • 11. Starting Simple – Dim (2) • For Notes Objects, Things are simpler Dim <var name> As Notes<rest of object name> - Ignore ... As New NotesSession for now • Also, initialising in SSJS, = null is ok: var <var name>:Notes<rest of object name> = null; • So our terms are: – Search: Dim[ ]+([w]*)[ ]+As[ ]+(Notes[w]*) – Replace: var 1:2 = null;
  • 12. Less simple – If Statements • For the most part, simple S & R (but order is important): End If to } [ ]*Then to ) { Else[ ]+If[ ]* to } else if ( If[ ]* to if ( • But what about: If (x = 10) Then • Use Search: If[ ]+([w()[].<>" ]*)=([w()[].<> "]*)[ ]+Then • Use Replace: if (1==2) { • NB: Works but not optimal! • Other comparison operators not a problem
  • 13. ! – session objects • The problem: • Session object is global in ssjs: ‘session’ • In LS it is created: Dim sess As New NotesSession • Need to find all LS session objects, and replace with session • How do you get a list of session object names? You need a coffee!
  • 14. Adding Java • Java String Object has regex search and replace String source = “Dim x As String”; String result = source.replaceAll(“Dim[ ]+([w]*)[ ]+As[ ]+String”, “var $1 = “”;”); • Pattern and Matcher objects make this even more powerful Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(this.source); int startPos = 0; while (m.find(startPos)) { if (!itemList.contains(m.group(1))) { itemList.add(m.group(1)); } startPos = m.end() + 1; }
  • 15. Field Handling • Similar Issue to Session • Need to find all document object names, and replace field handling methods • Will probably need to handle dot notation – Arrgghh! • How do you search for dot notation? <doc name>.([^GetItemValue])([0-9]+) • Still hard work!
  • 16. Search and Replace: Tips & Traps • There are other types than string! – Always review and test converted code thoroughly • Date handling is a pain – Script libraries can help here – Java? • Watch out for User interaction and particularly dialogues Work out your strategies in advance!
  • 17. Converting Formula • @Formula JavaScript Wrappers help a lot – Mostly just ‘;’ to ‘,’, and converting lists to arrays • Some constructions are obvious: @SetField(“Field”, Value); • Goes to: doc.replaceItemValue(“Field”, Value); • Or S: @SetField([ ]*([w”]*)[ ]*,[ ]*([w”]*)[ ]*); R: doc.replaceItemValue(1, 2); • But there are some issues ... @
  • 18. Formula – List Processing • No direct equivalent in SSJS for *+, *= *>= etc. when applied to Lists • Need to plan for this • Java Class/Library to provide direct substitute • Unfortunately, Java does not permit operator overloading, so has to be a set of methods @!
  • 19. Formula - @If, @Do and @While @If(@Contains(_WFData_neu;_Key);""; @Do( @Set("_Sachgebiet_Zuordnung";@DbLookup("NOTES":"NOCACHE";"":_ADM$StructureDB;"Workflows";"WFArbeitsanweisung";"Sachgebietzuordnung")); @If(_Sachgebiet_Zuordnung = "" | !@Contains(_Sachgebiet_Zuordnung;_Key2);@Do( @Prompt([Ok];"Hinweis";"In der System Struktur VBM wurde für das aktuelle Sachgebiet kein Workflow definiert. Das Dokument wird zum ehemaligen Kompetenzträger zurückgegeben, damit dieser ein neues Sachgebiet auswählen kann."); @Set("_Kompetenzträger";Bearbeiter1); @Set("_tmpintern";5) ); @Do( @Prompt([Ok];"Hinweis";"In der System Struktur VBM wurde für das aktuelle Sachgebiet ein neues Sachgebiet konfiguriert. Das Dokument wird zum Kompetenzträger zurückgegeben, damit dieser das neue Sachgebiet auswählen kann."); @Set("_neues_Sachgebiet";@Left(@Right(_Sachgebiet_Zuordnung;_key2);"||")); @Set("_Elements";@Elements(@Explode(@Left(@Left(@Right(_WFData_neu;"||Sachgebiet#");"||"); _neues_Sachgebiet) + _neues_Sachgebiet; "$" ))); @Set("_KompetenzträgerData";@Explode(@Left(@Right(_WFData_neu;"||Kompetenzträger#");"||"); "$")); @Set("_Kompetenzträger";@Subset(@Subset(_KompetenzträgerData;_Elements);-1)); @Set("_tmpintern";6) ) ) ) ); @!!
  • 20. Focusing on @If • @Formula is a FUNCTION language • @If is a function not a statement @!!! • In practice: @SetField(“Author”; @If(Status=“1”; Manager; Salesman)); • Needs to convert to: if (Status == “1”) { var author = doc.getItemValueString(“Manager”); } else { var author = doc.getItemValueString(“Salesman”); } doc.replaceItemValue(“Author”, author);
  • 21. Tools • Search and Replace can be used for @Formula -> SSJS ... • ... but it can only take you so far • A dedicated tool can go further – Only real alternative to manual translation for complex statements – Time consuming to create – Still not a silver bullet
  • 22. Third Party Tools • Espresso - http://www.ultrapico.com/Expresso.htm – Good for learning regex, and serious regex dev – Free! • GREP – Sophisticated regex file search – Where regex started (UNIX grep)!
  • 23. Resources and Information • We4IT – www.we4it.com • OpenNTF – www.openntf.org • Regex Quick Reference http://www.night-ray.com/regex.pdf • Loads of websites for all aspects of regex development • Mastering Regular Expressions – Jeffrey E.F. Friedl – O’Reilly Publishing