SlideShare una empresa de Scribd logo
1 de 23
Serious Sencha
Sencha Data-Layer
Learned lessons from the first
Sencha projects at ]project-open[
frank.bergmann@project-open.com
Contents  Architecture
– Model
– Store
– Proxy
 Practical Tricks
– Performance
• “Dereferenced” columns
• Compression
• Store reuse
– Dependent stores
– Error handling
 Enterprise Reuse
– Reusing models
– Reusing stores
– Sencha ExtJS vs. Touch reuse
Architecture
ServerServer
Architecture – The Role of Model, Store & Proxy
]po[ Server]po[ Server
REST
Interface
REST
Interface
Server:
REST API
ClientClient
NoteNavigationViewNoteNavigationView
NoteListNoteList
NoteDetailNoteDetail
GUI View:
Pages & Panels
NoteStoreNoteStore
• Id: 12345
• note: „asdf@asdf.com“
• note_type_id: 11508
• note_status_id: 11400
• object_id: 624
• Id: 12346
• note: „http://www.test.com/“
• note_type_id: 11510
• note_status_id: 11400
• object_id: 8868
. . .
NoteModelNoteModel
• Id: integer
• note: text
• note_type_id: integer
• note_status_id: integer
• object_id: integer
„Proxy“„Proxy“
Data:
Model & Store
Network:
Interface
Model  A “Model” defines an object type
together with it’s attributes
 Optionally attributes may have an
object type defined:
– String (default)
– int (-eger)
– boolean
 Corresponds to a UML object
definition or an SQL table definition.
 Watch out for the “config” section.
This is required for Sencha Touch not
allowed in ExtJS
 The model closely resembles the
SQL data-model in ]project-open[. In
fact, we can generate the model
automatically from the ]po[ SQL
metadata system.
Ext.define('PO.model.Note', {
extend: 'Ext.data.Model',
config: {
fields: [
'id',
'note',
'object_id',
'note_status_id',
'note_type_id'
]
}
});
NoteNote
• Id: integer
• note: text
• note_type_id: integer
• note_status_id: integer
• object_id: integer
Store  A “store” contains a list
of models
 A store corresponds to
an SQL table with a list
of models.
 Stores are directly used
by lists, widgets and
other GUI elements for
data.
 The store specifies the
“proxy” that defines how
data are read/written
from/to the server
Ext.define('PO.store.NoteStore', {
extend: 'Ext.data.Store',
storeId: 'noteStore',
config: {
model: 'PO.model.Note',
autoLoad: true,
proxy: {
type: 'rest',
url: '/intranet-rest/im_note',
appendId: true,
extraParams: {
format: 'json'
},
reader: {
type: 'json',
rootProperty: 'data'
}
}
}
});
Proxy  A “proxy” defines how data
are read/written from/to
the server.
 Reader: Specifications on
how to convert JSON data
from the server
 Writer: Specifications on
how to convert data into
JSON for the server
 Two options:
– Adapt the Reader/Writer to
the WS interface of the
server or
– Adapt the WS server
interface to Sencha
– The ]po[ REST interface has
been designed for Sencha
compatibility
Ext.define('PO.store.NoteStore', {
extend: 'Ext.data.Store',
storeId: 'noteStore',
config: {
model: 'PO.model.Note',
autoLoad: true,
proxy: {
type: 'rest',
url: '/intranet-rest/im_note',
appendId: true,
extraParams: {
format: 'json'
},
reader: {
type: 'json',
rootProperty: 'data'
}
}
}
});
Server Side Interface
 Options on how to build suitable data-
sources for the server side
ServerServer
Server Side Interfaces
]po[ Server]po[ Server
REST
Interface
REST
Interface
Server:
REST API
ClientClient
NoteNavigationViewNoteNavigationView
NoteListNoteList
NoteDetailNoteDetail
GUI View:
Pages & Panels
NoteStoreNoteStore
• Id: 12345
• note: „asdf@asdf.com“
• note_type_id: 11508
• note_status_id: 11400
• object_id: 624
• Id: 12346
• note: „http://www.test.com/“
• note_type_id: 11510
• note_status_id: 11400
• object_id: 8868
. . .
NoteModelNoteModel
• Id: integer
• note: text
• note_type_id: integer
• note_status_id: integer
• object_id: integer
„Proxy“„Proxy“
Data:
Model & Store
Network:
Interface
Server Side Interfaces: Protocols, Styles and Formatting
 Protocol Options
– HTTP 1.1
– Web Sockets
 Communication Styles
– Plain AJAX
– REST style
 Payload Formatting Options
– XML
– JSON
– CSV
 ]project-open[ has decided for REST style communication with JSON
formatting:
– REST provides at least some type of standard
– REST is “stateless”
– Sencha ExtJS/Touch come with a REST “Proxy” that can both read and write
– The ]po[ REST interface has been designed to meet the Sencha protocol.
Server Side Interfaces: Example
 Sencha request URL to
Server
 Answer from Server
– “success”: true/false for
error handling
– “message”: Error message
– “data”: The starting point for
the payload data
{
"success": true,
"message": "Data loaded",
"data": [
{'date': '2014-06-16', 'value': 0.0},
{'date': '2014-06-17', 'value': 43200.0},
{'date': '2014-06-19', 'value': 43200.0},
{'date': '2014-06-24', 'value': 187200.0},
{'date': '2014-06-25', 'value': 187200.0},
{'date': '2014-06-27', 'value': 187200.0}
]
}
http://po40dev.project-open.net/
intranet-reporting-dashboard/project-eva.json?
diagram_project_id=168725&
page=1&
start=0&
limit=25
Server Side Interfaces: Store Example
 The source code at the right is
a real-world example.
 “fields”: Defines the “columns”
of the store
 “proxy”: Defines how to load
the data
 “extraParams”: Allows to
specify URL parameters – in
this case we pass the
project_id.
 “reader”: Defines how to parse
the response from the server.
projectEvaStore = Ext.create('Ext.data.Store', {
fields: ['date', 'value'],
autoLoad: true,
proxy: {
type: 'rest',
url: '/intranet-dashboard/project-eva.json',
extraParams: {
project_id: project_id
},
reader: { type: 'json', root: 'data' }
}
});
{
"success": true,
"message": "Data loaded",
"data": [
{'date': '2014-06-16', 'value': 0.0},
{'date': '2014-06-17', 'value': 43200.0},
{'date': '2014-06-19', 'value': 43200.0},
{'date': '2014-06-24', 'value': 187200.0},
{'date': '2014-06-25', 'value': 187200.0},
{'date': '2014-06-27', 'value': 187200.0}
]
}
http://po40dev.project-open.net/
intranet-reporting-dashboard/project-eva.json?
project_id=168725&
page=1&
start=0&
limit=25
Server Side Interfaces: Data Sources Considerations
 A “data-source” is a server-side script that returns
JSON data to the client
 Security: Data-sources provide data to the “wild”
Internet and are vulnerable to SQL injection, DoS,
XSS and other attacks.
 Permissions: The system’s permission model
needs to honored
 Performance: SQL optimization and caching
You may very quickly run into a variety of badly
documented data-sources with security holes.
Plan for your future data-sources and keep order
Server Side Interfaces: Data Sources Examples
 In ]po[ we use three different types of data-
sources:
– SQL as data-source:
A library allows to generically deploy any SQL
command as a data-source including permissions
– ]po[ REST Interface:
A generic REST interface that provides generic read,
write, create and delete access to ]po[ business objects
via the ]po[ SQL metadata system.
– Custom written in TCL (could be PHP): Only in special
cases of complex logic or performance issues. Try to
avoid whenever possible.
Practical Tricks
 The Problem
– An app is supposed to show the list of projects
for the current user.
– Project information is stored in the “Project”
model that closely resembles the ]
po[ “im_projects” table.
– The table stores the project’s customer and
project manager as IDs, based on SQL design
best practices (1st normal form).
– => The app can not show the project list, unless
it has loaded the full Users and Customers
stores, which can take minutes (with 40.000
customers, for example).
 The Solution
– “Dereferencing”:
The server-side REST interface includes the
user-name and customer-name, together with
the IDs
– Compression:
Long lists of objects can be compressed on the
server side using GZip (HTTP standard). This
reduces the data size by a factor of 10.
– Client-side caching:
Lists of slow changing data (users, customer,
value ranges (categories), …) can be stored in
the browser. These data can then be “synced”
instead of being loaded.
Performance
issues with
large amounts
of data
ProjectProject
• project_id: integer
• […]
• customer_id: integer
• project_manager_id: integer
• […]
CustomerCustomer
• customer_id: integer
• customer_name: string
• […]
UserUser
• user_id: integer
• user_name: string
• […]
Dependent
Stores – Stores
with similar
contents
 The Problem
– The client has to load multiple times similar data
from the server.
– Reason: Every list, drop-down box, etc. GUI
element requires a store for it’s data.
– These stores frequently contain similar data, but
not exactly the same data:
• Different filters or subsets (Users of group
“Employees” vs. “Customers”)
• Different sort order
• Different groupings
– These stores sometimes are long.
 The Solution
– Load the maximum list in the background right
after the initial startup
– After loading the store, create the “dependent”
stores using a JavaScript procedure.
Error Handling  The Problem:
– Many things can go wrong on the server-side
• Connection unavailable
• Server unavailable
• Database issues
• Unique and check condition violation
• Software error
• …
– These issues are somehow “obscure” and difficult to debug:
• They are part of a long chain of processes
• They may occur rarely or randomly
• They may occur under high load or concurrency conditions
– The issues may be difficult to communicate
• They appear to technically unskilled users.
• They appear on a mobile device with limited GUI capabilities
– When operating the service, you will need to be able to debug these
issues efficiently
 The Solution
– All parts of the chain need to return reasonable error messages.
– Display important errors to the user
– Provide a server-side error reporting functionality where the user can
submit error reports.
– Keep an error log on the client side. You may send this error log to
the server together with a stack trace in order to provide a context for
debugging.
– ]project-open[ includes a package for submitting and tracking error
reports per user and software version
Enterprise Reuse
Enterprise
Reuse
Motivation
 Enterprise applications consist of hundreds
or thousands of pages
 The page structure is relatively simple and
standardized, as opposed to sophisticated
user experiences of apps mainly created
for marketing reasons.
Reuse becomes more important because
of the number of pages
Reuse is possible, because the various
pages are more standard.
Enterprise
Reuse –
REST Interface
 Generic REST interface for business
objects based on SQL metadata
– Generic R=read operation returns table columns
plus optionally dereferenced object_ids
– Generic W=write operation updates existing
objects
– Generic C=create operation is not possible in ]
project-open[, but may be possible in other
business applications because of object type
specific PL/SQL constructors
– Generic D=delete operation not possible in ]po[
 Permissions
– Permissions per operation and per attribute
need to be handled.
– Access to certain business objects may need to
be logged for security reasons
Enterprise
Reuse –
Automatic
Models
 Models can be generated automatically
based on SQL metadata (table columns,
column types and foreign key constraints).
Thank
You!
frank.bergmann@project-open.com
www.project-open.com
(Frank Bergmann and Klaus Hofeditz)

Más contenido relacionado

La actualidad más candente

Graviton Approval Framework Presentation
Graviton Approval Framework PresentationGraviton Approval Framework Presentation
Graviton Approval Framework Presentation
gravitonconsulting
 
Custom controls
Custom controlsCustom controls
Custom controls
aspnet123
 
Client Object Model - SharePoint Extreme 2012
Client Object Model - SharePoint Extreme 2012Client Object Model - SharePoint Extreme 2012
Client Object Model - SharePoint Extreme 2012
daniel plocker
 

La actualidad más candente (18)

Serious Sencha - Using Sencha ExtJS/Touch for Enterprise Applications
Serious Sencha - Using Sencha ExtJS/Touch for Enterprise ApplicationsSerious Sencha - Using Sencha ExtJS/Touch for Enterprise Applications
Serious Sencha - Using Sencha ExtJS/Touch for Enterprise Applications
 
]po[ Developers: Reporting, Indicators & Dashboards
]po[ Developers: Reporting, Indicators & Dashboards]po[ Developers: Reporting, Indicators & Dashboards
]po[ Developers: Reporting, Indicators & Dashboards
 
]project-open[ My First Package
]project-open[ My First Package]project-open[ My First Package
]project-open[ My First Package
 
Graviton Approval Framework Presentation
Graviton Approval Framework PresentationGraviton Approval Framework Presentation
Graviton Approval Framework Presentation
 
]project-open[ Reporting & Indicators Options
]project-open[ Reporting & Indicators Options]project-open[ Reporting & Indicators Options
]project-open[ Reporting & Indicators Options
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
MVC ppt presentation
MVC ppt presentationMVC ppt presentation
MVC ppt presentation
 
PeopleSoft Approval FrameWork AWE
PeopleSoft Approval FrameWork AWEPeopleSoft Approval FrameWork AWE
PeopleSoft Approval FrameWork AWE
 
Spsdc what's new in share point 2013 workflow
Spsdc   what's new in share point 2013 workflowSpsdc   what's new in share point 2013 workflow
Spsdc what's new in share point 2013 workflow
 
Spring Batch 2.0
Spring Batch 2.0Spring Batch 2.0
Spring Batch 2.0
 
MVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCMVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVC
 
Evolutionary db development
Evolutionary db development Evolutionary db development
Evolutionary db development
 
Custom controls
Custom controlsCustom controls
Custom controls
 
ASp.net Mvc 5
ASp.net Mvc 5ASp.net Mvc 5
ASp.net Mvc 5
 
Custom Controls in ASP.net
Custom Controls in ASP.netCustom Controls in ASP.net
Custom Controls in ASP.net
 
Client Object Model - SharePoint Extreme 2012
Client Object Model - SharePoint Extreme 2012Client Object Model - SharePoint Extreme 2012
Client Object Model - SharePoint Extreme 2012
 
Asp dot net final (2)
Asp dot net   final (2)Asp dot net   final (2)
Asp dot net final (2)
 
Rest web service_with_spring_hateoas
Rest web service_with_spring_hateoasRest web service_with_spring_hateoas
Rest web service_with_spring_hateoas
 

Similar a Serious Sencha - Data Layer and Server-Side REST Interface

REST - What's It All About? (SAP TechEd 2012, CD110)
REST - What's It All About? (SAP TechEd 2012, CD110)REST - What's It All About? (SAP TechEd 2012, CD110)
REST - What's It All About? (SAP TechEd 2012, CD110)
Sascha Wenninger
 

Similar a Serious Sencha - Data Layer and Server-Side REST Interface (20)

Adding Data into your SOA with WSO2 WSAS
Adding Data into your SOA with WSO2 WSASAdding Data into your SOA with WSO2 WSAS
Adding Data into your SOA with WSO2 WSAS
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDB
 
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
 
Scalable Architectures - Microsoft Finland DevDays 2014
Scalable Architectures - Microsoft Finland DevDays 2014Scalable Architectures - Microsoft Finland DevDays 2014
Scalable Architectures - Microsoft Finland DevDays 2014
 
Integrate MongoDB & SQL data with a single REST API
Integrate MongoDB & SQL data with a single REST APIIntegrate MongoDB & SQL data with a single REST API
Integrate MongoDB & SQL data with a single REST API
 
VMworld 2013: Performance Management of Business Critical Applications using ...
VMworld 2013: Performance Management of Business Critical Applications using ...VMworld 2013: Performance Management of Business Critical Applications using ...
VMworld 2013: Performance Management of Business Critical Applications using ...
 
Data Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite ApplicationsData Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite Applications
 
REST - What's It All About? (SAP TechEd 2012, CD110)
REST - What's It All About? (SAP TechEd 2012, CD110)REST - What's It All About? (SAP TechEd 2012, CD110)
REST - What's It All About? (SAP TechEd 2012, CD110)
 
Business-friendly library for inter-service communication
Business-friendly library for inter-service communicationBusiness-friendly library for inter-service communication
Business-friendly library for inter-service communication
 
REST APIs
REST APIsREST APIs
REST APIs
 
BITM3730Week12.pptx
BITM3730Week12.pptxBITM3730Week12.pptx
BITM3730Week12.pptx
 
Presented at useR! 2010
Presented at useR! 2010Presented at useR! 2010
Presented at useR! 2010
 
SenchaCon 2016: Upgrading an Ext JS 4.x Application to Ext JS 6.x - Mark Linc...
SenchaCon 2016: Upgrading an Ext JS 4.x Application to Ext JS 6.x - Mark Linc...SenchaCon 2016: Upgrading an Ext JS 4.x Application to Ext JS 6.x - Mark Linc...
SenchaCon 2016: Upgrading an Ext JS 4.x Application to Ext JS 6.x - Mark Linc...
 
Introducing MongoDB Stitch, Backend-as-a-Service from MongoDB
Introducing MongoDB Stitch, Backend-as-a-Service from MongoDBIntroducing MongoDB Stitch, Backend-as-a-Service from MongoDB
Introducing MongoDB Stitch, Backend-as-a-Service from MongoDB
 
01 - Web Programming Intro.pptx
01 - Web Programming Intro.pptx01 - Web Programming Intro.pptx
01 - Web Programming Intro.pptx
 
Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)
 
How sitecore depends on mongo db for scalability and performance, and what it...
How sitecore depends on mongo db for scalability and performance, and what it...How sitecore depends on mongo db for scalability and performance, and what it...
How sitecore depends on mongo db for scalability and performance, and what it...
 
L11 Application Architecture
L11 Application ArchitectureL11 Application Architecture
L11 Application Architecture
 
EEDC 2010. Scaling Web Applications
EEDC 2010. Scaling Web ApplicationsEEDC 2010. Scaling Web Applications
EEDC 2010. Scaling Web Applications
 
L19 Application Architecture
L19 Application ArchitectureL19 Application Architecture
L19 Application Architecture
 

Más de Klaus Hofeditz

The ]project-open[ Community
The ]project-open[ CommunityThe ]project-open[ Community
The ]project-open[ Community
Klaus Hofeditz
 
]project-open[ Screenshots
]project-open[ Screenshots ]project-open[ Screenshots
]project-open[ Screenshots
Klaus Hofeditz
 
]project-open[ CVS+ACL Permission Configuration
]project-open[ CVS+ACL Permission Configuration]project-open[ CVS+ACL Permission Configuration
]project-open[ CVS+ACL Permission Configuration
Klaus Hofeditz
 

Más de Klaus Hofeditz (13)

]project-open[ Budget Planning and Tracking
]project-open[ Budget Planning and Tracking]project-open[ Budget Planning and Tracking
]project-open[ Budget Planning and Tracking
 
]po[ Sencha File-Storage Specs
]po[ Sencha File-Storage Specs]po[ Sencha File-Storage Specs
]po[ Sencha File-Storage Specs
 
The ]project-open[ Community
The ]project-open[ CommunityThe ]project-open[ Community
The ]project-open[ Community
 
]project-open[ Data-Model 100511b
]project-open[ Data-Model 100511b]project-open[ Data-Model 100511b
]project-open[ Data-Model 100511b
 
]project-open[ Screenshots
]project-open[ Screenshots ]project-open[ Screenshots
]project-open[ Screenshots
 
]project-open[ CVS+ACL Permission Configuration
]project-open[ CVS+ACL Permission Configuration]project-open[ CVS+ACL Permission Configuration
]project-open[ CVS+ACL Permission Configuration
 
Po workflow-tutorial-1-overview.100603
Po workflow-tutorial-1-overview.100603Po workflow-tutorial-1-overview.100603
Po workflow-tutorial-1-overview.100603
 
]project-open[ Reporting & Indicators Options
]project-open[ Reporting & Indicators Options]project-open[ Reporting & Indicators Options
]project-open[ Reporting & Indicators Options
 
]project-open[ Package Manager
]project-open[ Package Manager]project-open[ Package Manager
]project-open[ Package Manager
 
]project-open[ Data-Model “Categories”
]project-open[ Data-Model “Categories”]project-open[ Data-Model “Categories”
]project-open[ Data-Model “Categories”
 
]project-open[ Roll Out Plan
]project-open[ Roll Out Plan]project-open[ Roll Out Plan
]project-open[ Roll Out Plan
 
]project-open[ Timesheet Project Invoicing
]project-open[ Timesheet Project Invoicing]project-open[ Timesheet Project Invoicing
]project-open[ Timesheet Project Invoicing
 
]project-open[ OSS Project Mangement
]project-open[ OSS Project Mangement]project-open[ OSS Project Mangement
]project-open[ OSS Project Mangement
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

Serious Sencha - Data Layer and Server-Side REST Interface

  • 1. Serious Sencha Sencha Data-Layer Learned lessons from the first Sencha projects at ]project-open[ frank.bergmann@project-open.com
  • 2. Contents  Architecture – Model – Store – Proxy  Practical Tricks – Performance • “Dereferenced” columns • Compression • Store reuse – Dependent stores – Error handling  Enterprise Reuse – Reusing models – Reusing stores – Sencha ExtJS vs. Touch reuse
  • 4. ServerServer Architecture – The Role of Model, Store & Proxy ]po[ Server]po[ Server REST Interface REST Interface Server: REST API ClientClient NoteNavigationViewNoteNavigationView NoteListNoteList NoteDetailNoteDetail GUI View: Pages & Panels NoteStoreNoteStore • Id: 12345 • note: „asdf@asdf.com“ • note_type_id: 11508 • note_status_id: 11400 • object_id: 624 • Id: 12346 • note: „http://www.test.com/“ • note_type_id: 11510 • note_status_id: 11400 • object_id: 8868 . . . NoteModelNoteModel • Id: integer • note: text • note_type_id: integer • note_status_id: integer • object_id: integer „Proxy“„Proxy“ Data: Model & Store Network: Interface
  • 5. Model  A “Model” defines an object type together with it’s attributes  Optionally attributes may have an object type defined: – String (default) – int (-eger) – boolean  Corresponds to a UML object definition or an SQL table definition.  Watch out for the “config” section. This is required for Sencha Touch not allowed in ExtJS  The model closely resembles the SQL data-model in ]project-open[. In fact, we can generate the model automatically from the ]po[ SQL metadata system. Ext.define('PO.model.Note', { extend: 'Ext.data.Model', config: { fields: [ 'id', 'note', 'object_id', 'note_status_id', 'note_type_id' ] } }); NoteNote • Id: integer • note: text • note_type_id: integer • note_status_id: integer • object_id: integer
  • 6. Store  A “store” contains a list of models  A store corresponds to an SQL table with a list of models.  Stores are directly used by lists, widgets and other GUI elements for data.  The store specifies the “proxy” that defines how data are read/written from/to the server Ext.define('PO.store.NoteStore', { extend: 'Ext.data.Store', storeId: 'noteStore', config: { model: 'PO.model.Note', autoLoad: true, proxy: { type: 'rest', url: '/intranet-rest/im_note', appendId: true, extraParams: { format: 'json' }, reader: { type: 'json', rootProperty: 'data' } } } });
  • 7. Proxy  A “proxy” defines how data are read/written from/to the server.  Reader: Specifications on how to convert JSON data from the server  Writer: Specifications on how to convert data into JSON for the server  Two options: – Adapt the Reader/Writer to the WS interface of the server or – Adapt the WS server interface to Sencha – The ]po[ REST interface has been designed for Sencha compatibility Ext.define('PO.store.NoteStore', { extend: 'Ext.data.Store', storeId: 'noteStore', config: { model: 'PO.model.Note', autoLoad: true, proxy: { type: 'rest', url: '/intranet-rest/im_note', appendId: true, extraParams: { format: 'json' }, reader: { type: 'json', rootProperty: 'data' } } } });
  • 8. Server Side Interface  Options on how to build suitable data- sources for the server side
  • 9. ServerServer Server Side Interfaces ]po[ Server]po[ Server REST Interface REST Interface Server: REST API ClientClient NoteNavigationViewNoteNavigationView NoteListNoteList NoteDetailNoteDetail GUI View: Pages & Panels NoteStoreNoteStore • Id: 12345 • note: „asdf@asdf.com“ • note_type_id: 11508 • note_status_id: 11400 • object_id: 624 • Id: 12346 • note: „http://www.test.com/“ • note_type_id: 11510 • note_status_id: 11400 • object_id: 8868 . . . NoteModelNoteModel • Id: integer • note: text • note_type_id: integer • note_status_id: integer • object_id: integer „Proxy“„Proxy“ Data: Model & Store Network: Interface
  • 10. Server Side Interfaces: Protocols, Styles and Formatting  Protocol Options – HTTP 1.1 – Web Sockets  Communication Styles – Plain AJAX – REST style  Payload Formatting Options – XML – JSON – CSV  ]project-open[ has decided for REST style communication with JSON formatting: – REST provides at least some type of standard – REST is “stateless” – Sencha ExtJS/Touch come with a REST “Proxy” that can both read and write – The ]po[ REST interface has been designed to meet the Sencha protocol.
  • 11. Server Side Interfaces: Example  Sencha request URL to Server  Answer from Server – “success”: true/false for error handling – “message”: Error message – “data”: The starting point for the payload data { "success": true, "message": "Data loaded", "data": [ {'date': '2014-06-16', 'value': 0.0}, {'date': '2014-06-17', 'value': 43200.0}, {'date': '2014-06-19', 'value': 43200.0}, {'date': '2014-06-24', 'value': 187200.0}, {'date': '2014-06-25', 'value': 187200.0}, {'date': '2014-06-27', 'value': 187200.0} ] } http://po40dev.project-open.net/ intranet-reporting-dashboard/project-eva.json? diagram_project_id=168725& page=1& start=0& limit=25
  • 12. Server Side Interfaces: Store Example  The source code at the right is a real-world example.  “fields”: Defines the “columns” of the store  “proxy”: Defines how to load the data  “extraParams”: Allows to specify URL parameters – in this case we pass the project_id.  “reader”: Defines how to parse the response from the server. projectEvaStore = Ext.create('Ext.data.Store', { fields: ['date', 'value'], autoLoad: true, proxy: { type: 'rest', url: '/intranet-dashboard/project-eva.json', extraParams: { project_id: project_id }, reader: { type: 'json', root: 'data' } } }); { "success": true, "message": "Data loaded", "data": [ {'date': '2014-06-16', 'value': 0.0}, {'date': '2014-06-17', 'value': 43200.0}, {'date': '2014-06-19', 'value': 43200.0}, {'date': '2014-06-24', 'value': 187200.0}, {'date': '2014-06-25', 'value': 187200.0}, {'date': '2014-06-27', 'value': 187200.0} ] } http://po40dev.project-open.net/ intranet-reporting-dashboard/project-eva.json? project_id=168725& page=1& start=0& limit=25
  • 13. Server Side Interfaces: Data Sources Considerations  A “data-source” is a server-side script that returns JSON data to the client  Security: Data-sources provide data to the “wild” Internet and are vulnerable to SQL injection, DoS, XSS and other attacks.  Permissions: The system’s permission model needs to honored  Performance: SQL optimization and caching You may very quickly run into a variety of badly documented data-sources with security holes. Plan for your future data-sources and keep order
  • 14. Server Side Interfaces: Data Sources Examples  In ]po[ we use three different types of data- sources: – SQL as data-source: A library allows to generically deploy any SQL command as a data-source including permissions – ]po[ REST Interface: A generic REST interface that provides generic read, write, create and delete access to ]po[ business objects via the ]po[ SQL metadata system. – Custom written in TCL (could be PHP): Only in special cases of complex logic or performance issues. Try to avoid whenever possible.
  • 16.  The Problem – An app is supposed to show the list of projects for the current user. – Project information is stored in the “Project” model that closely resembles the ] po[ “im_projects” table. – The table stores the project’s customer and project manager as IDs, based on SQL design best practices (1st normal form). – => The app can not show the project list, unless it has loaded the full Users and Customers stores, which can take minutes (with 40.000 customers, for example).  The Solution – “Dereferencing”: The server-side REST interface includes the user-name and customer-name, together with the IDs – Compression: Long lists of objects can be compressed on the server side using GZip (HTTP standard). This reduces the data size by a factor of 10. – Client-side caching: Lists of slow changing data (users, customer, value ranges (categories), …) can be stored in the browser. These data can then be “synced” instead of being loaded. Performance issues with large amounts of data ProjectProject • project_id: integer • […] • customer_id: integer • project_manager_id: integer • […] CustomerCustomer • customer_id: integer • customer_name: string • […] UserUser • user_id: integer • user_name: string • […]
  • 17. Dependent Stores – Stores with similar contents  The Problem – The client has to load multiple times similar data from the server. – Reason: Every list, drop-down box, etc. GUI element requires a store for it’s data. – These stores frequently contain similar data, but not exactly the same data: • Different filters or subsets (Users of group “Employees” vs. “Customers”) • Different sort order • Different groupings – These stores sometimes are long.  The Solution – Load the maximum list in the background right after the initial startup – After loading the store, create the “dependent” stores using a JavaScript procedure.
  • 18. Error Handling  The Problem: – Many things can go wrong on the server-side • Connection unavailable • Server unavailable • Database issues • Unique and check condition violation • Software error • … – These issues are somehow “obscure” and difficult to debug: • They are part of a long chain of processes • They may occur rarely or randomly • They may occur under high load or concurrency conditions – The issues may be difficult to communicate • They appear to technically unskilled users. • They appear on a mobile device with limited GUI capabilities – When operating the service, you will need to be able to debug these issues efficiently  The Solution – All parts of the chain need to return reasonable error messages. – Display important errors to the user – Provide a server-side error reporting functionality where the user can submit error reports. – Keep an error log on the client side. You may send this error log to the server together with a stack trace in order to provide a context for debugging. – ]project-open[ includes a package for submitting and tracking error reports per user and software version
  • 20. Enterprise Reuse Motivation  Enterprise applications consist of hundreds or thousands of pages  The page structure is relatively simple and standardized, as opposed to sophisticated user experiences of apps mainly created for marketing reasons. Reuse becomes more important because of the number of pages Reuse is possible, because the various pages are more standard.
  • 21. Enterprise Reuse – REST Interface  Generic REST interface for business objects based on SQL metadata – Generic R=read operation returns table columns plus optionally dereferenced object_ids – Generic W=write operation updates existing objects – Generic C=create operation is not possible in ] project-open[, but may be possible in other business applications because of object type specific PL/SQL constructors – Generic D=delete operation not possible in ]po[  Permissions – Permissions per operation and per attribute need to be handled. – Access to certain business objects may need to be logged for security reasons
  • 22. Enterprise Reuse – Automatic Models  Models can be generated automatically based on SQL metadata (table columns, column types and foreign key constraints).