Walkthrough: Creating components to read and write data
This walkthrough is part two of Synchronizing data from a text file to Sitecore walkthrough series and describes how to create the components you need in order to read data from a text file and write it to Sitecore.
The walkthrough describes how to:
-
Add an endpoint for the source file.
-
Add a set of value accessors for the source file.
-
Add an endpoint for target items.
-
Add a set of value accessors for the target items
-
Add value mappings.
Add an endpoint for the source file
You use an endpoint to identify the text file that will be read.
To add an endpoint for the source file:
-
In the Content Editor, navigate to /sitecore/System/Data Exchange/File System Provider Test Tenant/Endpoints/Providers.
-
To add a new template, in the right-hand pane, on the Folder tab, click File System Endpoints.
NoteThis template is a command template. It does not prompt for the item name. The command template automatically assigns the item the name File System.
-
Navigate to the new File System folder. In the right-hand pane, on the Folder tab, click Text File Endpoint, and add the following item:
Template
Text File Endpoint
Name
City Information File
-
Select the new City Information File endpoint.
-
In the right-hand pane, set the following field values:
Field
Value
Path
C:\Sitecore\cities.dat
Column Separator
,
-
Save the item.
Add a set of value accessors for the source file
To read values from the source file, you must create a value accessor for each value. Each value accessor represents a specific value from a row in the source file. You group related value accessors into value accessor sets, which can contain one or more value accessors.
Under a tenant, value accessor sets are organized by provider. You must create a folder to hold the value accessor sets for the new provider. You then create a value accessor set representing all the values you want to read from a row in the source file. In the value accessor set, you create value accessors that can read individual values from the source file data row.
To add a value accessor set with value accessors:
-
In the Content Editor, navigate to /sitecore/System/Data Exchange/File System Provider Test/Data Access/Value Accessor Sets/Providers.
-
To add a new set, in the right-hand pane, on the Folder tab, click File System Value Accessor Sets.
NoteThis template is a command template. It does not prompt for the item name. The command template automatically assigns the item the name File System.
-
To create a value accessor set, navigate to the new File System folder. In the right-hand pane, on the Folder tab, click Array Value Accessor Set. Name the new item City Information File Fields.
-
To create the value accessors, in the content tree, navigate to the new City Information File Fields item. In the right-hand pane, on the Folder tab, click Array Value Accessor. Name the new item Identifier from City Information File.
-
In the right-hand pane, set the following field value:
Field
Value
Position
0
-
Save the item.
-
Repeat steps 1 to 3 to add two more Array Value Accessor items:
Item name
Position value
Country from City Information Item
1
City from City Information Item
2
Add an endpoint for target items
You use an endpoint to identify the Sitecore database where the Sitecore items will be created.
To add an endpoint:
-
In the Content Editor, navigate to /sitecore/System/Data Exchange/File System Provider Test Tenant/Endpoints/Providers.
-
In the right-hand pane, click Sitecore Endpoints.
NoteThis template is a command template. It does not prompt for the item name. Command templates assign the item name automatically.
-
Select the new item.
-
In the right-hand pane, click Sitecore Item Model Repository Endpoint. Name the new item Sitecore Database Endpoint.
Add a set of value accessors for the target items
To write values to the Sitecore items (target items) that act as the target objects, you must create a value accessor in the tenant for each item. Each value accessor represents a specific field on the template used for the target items. You group related value accessors into a value accessor set that represents all items you want to read from the source. You organize the value accessor sets in folders under the data provider.
To add value accessors for the target items:
-
To create a folder for the value accessor set, in the Content Editor, navigate to /sitecore/System/Data Exchange/File System Provider Test Tenant/Data Access/Value Accessor Sets/Providers.
-
In the right-hand pane, click Sitecore Value Accessor Sets.
NoteThis template is a command template. It does not prompt for the item name. Command templates assign the item name automatically.
-
To create a value accessor set, in the Content Editor, navigate to the Sitecore provider.
-
On the Folder tab, click Sitecore Item Field Value Accessor Set to create a new item, and name it City Information Item Fields.
-
To create the value accessors, in the Content Editor, navigate to the City Information Item Fields item.
-
In the right-pane, on the Folder tab, click Sitecore Item Field Value Accessor to create a new item, and name it Identifier on City Information Item.
-
In the right-hand pane, set the following field value:
Field
Value
Field
Templates/User Defined/City Information/Data/Identifier
-
Save the item.
-
Repeat steps 6 to 8 to add two more Sitecore Item Field Value Accessor fields:
Field name
Field value
Country on City Information Item
Templates/User Defined/City Information/Data/Country
City on City Information Item
Templates/User Defined/City Information/Data/City
Add value mappings
You use value mappings to associate a value accessor for a source object with a value accessor for a target object. Related value mappings are grouped together under a value mapping set.
In this example, you create a value mapping set to represent all of the values you must map from a row in a text file to a Sitecore item. You then create value mappings for the Identifier, Country, and City Sitecore items. These mappings associate the value accessors you use to read values from the text file with the value accessors you use to write values to the corresponding Sitecore item
To create a value mapping set with value mappings:
-
To create a value mapping set, in the Content Editor, navigate to /sitecore/System/Data Exchange/File System Provder Test Tenant/Value Mapping Sets.
-
In the right-hand pane, on the Folder tab, click Value Mapping Set. Name it Row from City Information File to City Information Item
-
To create a value mapping, in the content tree, navigate to the new value mapping set.
-
In the right-hand pane, on the Folder tab, click Value Mapping. Name the new item Identifier. Select the new item in the content tree.
-
In the right-hand pane, in the Source section, specify the following field values:
Field
Value
Source Accessor
Data Access/Value Accessor Sets/Providers/File System/City Information File Fields/Identifier from City Information File
Target Accessor
Data Access/Value Accessor Sets/Providers/Sitecore/City Information Item Fields/Identifier on City Information Item
-
Save the item.
-
Repeat steps 4 to 7 to add the following value mappings:
Name
Source accessor
Target Accessor
Country
Data Access/Value Accessor Sets/Providers/File System/City Information File Fields/Country from City Information File
Data Access/Value Accessor Sets/Providers/Sitecore/City Information Item Fields/Country on City Information Item
City
Data Access/Value Accessor Sets/Providers/File System/City Information File Fields/City from City Information File
Data Access/Value Accessor Sets/Providers/Sitecore/City Information Item Fields/City on City Information Item