Creating Your Data Models

To process data through Data Hub, create a data model for each of the three stages.

Data Hub data models are XML files that describe and sometimes transform data. As shown in the following image, a data model is required for each of the three stages of the Data Hub workflow. Data Hub uses the raw and canonical models to structure and transform data internally during the load and composition phases. It then uses the target model to transform data for specific target systems. Such data models are required to extend Data Hub.

Complete each of the procedures that follow to create and load the raw, canonical, and target data models required for the Hello World tutorial. For more information about each of these data models, see Advanced Metadata Structure.

Creating the Raw Data Model

Complete the following steps to map raw data to canonical data.

  1. Copy the following XML into a text editor.
    <extension xmlns="http://www.hybris.com/schema/" name="hello-raw-datahub-extension">
     
    	<dependencies>
    		<dependency>
    			<extension>hello-canonical-datahub-extension</extension>
    		</dependency>
    	</dependencies>
    
       <rawItems>
            <item>
                <type>RawProduct</type>
                <description>Raw representation of a product</description>
                <attributes>
                    <attribute>
                        <name>id</name>
                    </attribute>
                    <attribute>
                        <name>productName</name>
                    </attribute>
                    <attribute>
                        <name>productDescription</name>
                    </attribute>
                </attributes>
            </item>  
        </rawItems>
        <canonicalItems>
            <item>
                <type>CanonicalProduct</type>
                <attributes>
                    <attribute>
                        <name>identifier</name>
                        <transformations>
                            <transformation>
                                <rawSource>RawProduct</rawSource>
                                <expression>id</expression>
                            </transformation>
                        </transformations>
                    </attribute>
                    <attribute>
                        <name>name</name>
                        <transformations>
                            <transformation>
                                <rawSource>RawProduct</rawSource>
                                <expression>productName</expression>
                            </transformation>
                        </transformations>
                    </attribute>
                    <attribute>
                        <name>description</name>
                        <transformations>
                            <transformation>
                                <rawSource>RawProduct</rawSource>
                                <expression>productDescription</expression>
                            </transformation>
                        </transformations>
                    </attribute>
                </attributes>
            </item>
        </canonicalItems>
    </extension>
  2. In a command line interface, create a META-INF folder.
  3. Save the XML file you created in the META-INF folder with the file name hello-raw-datahub-extension.xml.
  4. From the command line, navigate to the folder in which the META-INF folder is located. Run the following command to compress the folder into a JAR file.
    jar cf hello-raw-datahub-extension.jar META-INF
  5. List the directory to ensure the hello-raw-datahub-extension.jar file and the META-INF directory appear.
  6. Copy the JAR file to /opt/datahub/extensions. When Data Hub starts, it loads the extensions in the directory.
  7. Complete the remaining procedures in this topic.

Creating the Canonical Data Model

The robust canonical data model is required for the tutorials in the next series, Building upon Hello World. Be sure to keep the canonical model isolated from those external sources.

  1. Copy the following XML into a text editor.
    <extension xmlns="http://www.hybris.com/schema/" name="hello-canonical-datahub-extension">
        <canonicalItems>
            <item>
                <type>CanonicalProduct</type>
                <attributes>
                    <attribute>
                        <name>identifier</name>
                        <model>
                            <localizable>false</localizable>
                            <collection>false</collection>
                            <type>String</type>
                            <primaryKey>true</primaryKey>
                        </model>
                    </attribute>
                    <attribute>
                        <name>name</name>
                        <model>
                            <localizable>false</localizable>
                            <collection>false</collection>
                            <type>String</type>
                            <primaryKey>false</primaryKey>
                        </model>
                    </attribute>
                    <attribute>
                        <name>description</name>
                        <model>
                            <localizable>false</localizable>
                            <collection>false</collection>
                            <type>String</type>
                            <primaryKey>false</primaryKey>
                        </model>
                    </attribute>
                </attributes>
            </item>
        </canonicalItems>
    </extension>
  2. In a command line interface, delete any files in the META-INF folder.
  3. Save the XML file you created to the META-INF folder with the file name hello-canonical-datahub-extension.xml.
  4. From the command line, navigate to the folder in which the META-INF folder is located. Run the following command to compress the folder into a JAR file.
    jar cf hello-canonical-datahub-extension.jar META-INF
  5. List the directory. You should only see hello-canonical-datahub-extension.jar and META-INF.
  6. Copy the JAR file to /opt/datahub/extensions. When Data Hub starts, it loads the extensions in the directory.
  7. Complete the remaining procedures in this topic.

Creating the Target Data Model

The target data model prepares the data for its new home on the target system.

  1. Copy the following XML into a text editor.
    <extension xmlns="http://www.hybris.com/schema/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://www.hybris.com/schema/ datahub-metadata-schema-1.0.0.xsd" name="hello-target-datahub-extension">
    
     	<dependencies>
    		<dependency>
    			<extension>hello-canonical-datahub-extension</extension>
    		</dependency>
    	</dependencies>
    
    	<targetSystems>
            <targetSystem>
                <name>FileAdapterTargetSystem</name>
                <type>HybrisCore</type>
                <exportURL/>
                <userName/>
                <password/>
                <exportCodes/>
    
    <!-- Target items and attributes -->
                <targetItems>
                    <item>
                        <type>targetProduct</type>
                        <updatable>true</updatable>
                        <canonicalItemSource>CanonicalProduct</canonicalItemSource>
                        <status>ACTIVE</status>
                        <attributes>
                            <attribute>
                                <name>identifier</name>
                                <localizable>false</localizable>
                                <collection>false</collection>
                                <transformationExpression>identifier</transformationExpression>
                            </attribute>
                            <attribute>
                                <name>name</name>
                                <localizable>false</localizable>
                                <collection>false</collection>
                                <transformationExpression>name</transformationExpression>
                            </attribute>
                            <attribute>
                                <name>description</name>
                                <localizable>false</localizable>
                                <collection>false</collection>
                                <transformationExpression>description</transformationExpression>
                            </attribute>
                        </attributes>
                    </item>
                </targetItems>
            </targetSystem>
        </targetSystems>
    </extension>
  2. In a command line interface, delete any files in the META-INF folder.
  3. Save the XML file you created into the META-INF folder with the file name hello-target-datahub-extension.xml.
  4. From the command line, navigate to the folder in which the META-INF folder is located. Run the following command to compress the folder into a JAR file.
    jar cf hello-target-datahub-extension.jar META-INF
  5. List the directory. You should only see hello-target-datahub-extension.jar and META-INF.
  6. Copy the JAR file to /opt/datahub/extensions. When Data Hub starts, it loads the extensions in the directory.
  7. Complete the remaining procedure in this topic.

Preparing and Loading the Data Models

Complete the following steps to load the three JAR files you created in the preceding procedures into the /opt/datahub/extensions directory.

  1. Start Tomcat.
  2. Review the Tomcat log to ensure that there are no errors.
  3. Search the log for the extension name to verify that each of your new data models loaded as expected.

Summary

This tutorial described how to create and load the data models required to extend Data Hub in the tutorials that follow.