external data provider an headless way to share content - developers meetup - january 2017

32
1 DX External Data Provider in an headless world January 25th, 2017

Upload: jahia-solutions-group

Post on 11-Apr-2017

472 views

Category:

Software


0 download

TRANSCRIPT

Page 1: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

1

DX External Data Provider in an headless worldJanuary 25th, 2017

Page 2: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

2

Introduction

What will you see?

External data providerRendering capabilities of DXLearn how to bake a cake

There are 28 slides and 3 bonus

Page 3: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

3

The basics: get content, display it.

1

Page 4: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

4

1 Simple use case

Goal to achieve: - Give the world access to my catalog

Requirements:- A Catalog- A web server application (the world)

Page 5: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

5

1 Things to do

- Expose the catalog to the world - Create a connector in the web server application to

read the Catalog

2 connectors :- ExposeCatalog- DisplayCatalog

Page 6: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

6

Now, complicate things a bit

2

Page 7: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

7

2 Add a new source of content

Goal to achieve:- Provide content from a completely different Catalog

Things to do:- Create a connector to this catalog - Edit the display connector to fit the new structure

Page 8: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

8

2 Add a new output

Goal to achieve:- Expose the content to an Android / iOS / raspberry

application

Things to do:- Edit the 2 connectors to support this new output- Create a new output connector to support all the

external sources with their input connectors

Page 9: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

9

2

Page 10: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

10

2 And life goes on ...

New outputs to addNew sources to add

Time needed increase dramatically

Complex to maintain

Page 11: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

11

2 DX

Use DX as a solution between your content sources and the outside world

Using the External Data Provider to get the DataUsing the rendering mechanism and structure to deliver it

- Quick development- Easy to maintain- Easy to evolve

Page 12: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

12

2

Page 13: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

13

3Your content in DX:External Data Providers

Page 14: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

14

What is an External Data Provider ?

Functionally: A way to virtualize content in DX JCR tree

Technically: A simple DX module

3

Page 15: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

15

How to create an External Data Provider

Set an external provider declaration based onorg.jahia.modules.external.ExternalContentStoreProvider

Define an External Data Source implementing org.jahia.modules.external.ExternalDataSource

Create an External Data object

3

Page 16: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

16

ExternalContentStoreProvider

Use spring to instantiate the provider.<bean id="ExternalGenericDatabaseProvider" class="org.jahia.modules.external.ExternalContentStoreProvider" parent="AbstractJCRStoreProvider"> <property name="key" value="ExternalGenericDatabaseProvider"/> <property name="mountPoint" value="/external-database-generic"/> <property name="externalProviderInitializerService" ref="ExternalProviderInitializerService"/> <property name="dataSource"> <bean class="org.jahia.modules.external.test.db.GenericDatabaseDataSource"/> </property></bean>

The provider declaration can define provider capabilities such as:

- Extension support- Lock support

3

Page 17: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

17

External Data Source

Implement ExternalDataSource to build ExternalDataList<String> getChildren(String path)ExternalData getItemByIdentifier(String identifier)ExternalData getItemByPath(String path)

getSupportedNodeTypes()isSupportsHierarchicalIdentifiers()isSupportsUuid()itemExists(String path)

3

Page 18: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

18

3 External Data Object

To build it, use the default ConstructorExternalData(String id, String path, String type, Map<String, String[]> properties, boolean isNew)

Page 19: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

19

3 Extend an External Data Source

The External Data source can be extended implementing the following interfaces:

AccessControllable SupportPrivilegesSearchableWritableCanCheckAvailabilityCanLoadChildrenInBatchInitializableLazyPropertyReferenceable

Page 20: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

20

3 Extension

With extensions, it is possible to enhance the external content with custom properties.

This can be useful to add ratings, comments

The content is stored in a dedicated place in the JCR.

Page 21: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

21

3 Server settings

An External Data Provider is used to mount external content into DX.

We provide a UI in the server settings to manage mount points

No documentation yet :'(

Page 22: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

22

3 Usages

In DX:- VFS to mount file system- Sources in the Studio- User and Group Provider

From modules (available on the store or in Github):- CMIS- Tmdb- Database connector- LDAP

Page 23: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

23

4Headless rendering

Page 24: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

24

Headless

The rendering is detached from its content.Consume JSON

Examples :Single page appMobile rendering

Create a new edit UI

4

Page 25: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

25

4 DX and Headless

DX natively offers to render content in an unitary way

DX can generate JSON

Page 26: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

26

4 How to query and get JSON

Querying content can let you read the content, but also modifying it

- With the render chain:Default json views that can be found in /default/src/main/resources/nt_base/json

- Create an Action

- Use Jax-RS API (like in our JC Rest API module)

- Use GraphQL (this is the future)

Page 27: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

27

5Conclusion

Page 28: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

28

Mix the things

Get your content in DX using the External Data Provider

Generate JSON using DX capabilities

Enjoy !!

5

Page 29: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

29

5 One more thing ..

Now that your content is in DX you can use :

- Edit engines- DX flows- DX modules- Play with it as any other DX content- Etc ..

Page 30: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

30

Alternatively you can bake a cake

Here the recipe:● nonstick vegetable oil spray● 1 1/2 cups all-purpose flour● 2 teaspoons baking powder● 3/4 teaspoon kosher salt● 1 cup sugar● 1 tablespoon finely grated lemon zest● 3/4 cup whole-milk Greek yogurt● 1/2 cup vegetable oil● 2 large eggs● 1/2 teaspoon vanilla extract

5

Page 31: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

31

Preparation

Preheat oven to 350°F. Coat a standard (8 1/2x4 1/4") loaf pan with nonstick vegetable oil spray. Dust with flour; tap out excess. Whisk 1 1/2 cups all-purpose flour, 2 teaspoons baking powder, and 3/4 teaspoon kosher salt in a medium bowl. Using your fingers, rub 1 cup sugar with 1 tablespoon finely grated lemon zest in a large bowl until sugar is moist. Add 3/4 cup whole-milk Greek yogurt, 1/2 cup vegetable oil, 2 large eggs, and 1/2 teaspoon vanilla extract; whisk to blend. Fold in dry ingredients just to blend. Pour batter into prepared pan; smooth top. Bake until top of cake is golden brown and a tester inserted into center comes out clean, 50-55 minutes.

Let cake cool in pan on a wire rack for 15 minutes. Invert onto rack; let cool completely. DO AHEAD: Can be made 3 days ahead. Store airtight at room temperature.

5

Page 32: External Data Provider an Headless Way to Share Content - Developers Meetup - January 2017

32

THE END!THANKS FOR LISTENING