Motivation
After creating a data model, we will populate it with some sample data we can use for testing.
Populating a data model can be done either manually using the hMC, an appropriate cockpit,
or automatically using hybris' Import-Export Data Framework called ImpEx.
Enter data via the hMC
First, we will create data manually in the hMC:
- Start hybris and navigate to the hmc http://localhost:9001/hmc/hybris
- Browse to Stadium, click New and enter the data below. Click Create to save the new Stadium
Add some matches to the Stadium created above.
- Make sure you have entered the Cuppy, CuppyTrail and CuppyTrailhmc extensions in your localextensions.xml file. You can check that they've been included in the build by looking at the platform - extensions page in the hAC.
- Assign some matches to the newly created stadiums
-
- Right-click on the matches field to get a context menu - select + Add Match
- In the new search window, click on the search button
- In the results area, select some matches by clicking anywhere in the match row except the little blue button
- Then click the use button
- This will return the selected matches to the stadium
In this use case we have added Matches to the Stadium which illustrates how the hMC handles relationships defined in the items.xml file.
ImpEx by Convention
As an alternative to populate the data model, we will use the ImpEx approach - "ImpEx By Convention" to define and import several stadiums rather than doing this manually in the hMC. The ImpEx Convention states that:
- by default any files named essentialdata*.impex and projectdata*.impex that reside in <extension>/resources/impex will be imported during essential and project data creation
- Alternatively, we could choose to use the "ImpEx by Configuration" approach; this would require us to provide hybris with a filename pattern for ImpEx files (in config/local.properties). If you would like to do so, please read ImpEx Import for Essential and Project Data.
Create an ImpEx File
Create the file cuppytrail/resources/impex/projectdataStadium.impex:
cuppytrail/resources/impex/projectdataStadium.impex
INSERT_UPDATE Stadium;code[unique=true];capacity
;Emirates;60361
;VillaPark;42788
UPDATE Match;id[unique=true];group(competition(code),code)[unique=true];stadium(code)
;1;wc2010:A;Emirates
;2;wc2010:A;Emirates
;3;wc2010:B;Emirates
;4;wc2010:B;VillaPark
$START_USERRIGHTS
Type;UID;MemberOfGroups;Password;Target;read;change;create;remove;change_perm
UserGroup;cuppyadmins;;;;;;;;
;;;;Stadium;+;+;+;+;-
$END_USERRIGHTS
The projectdata part of the file name is case-sensitive
Using Convention-based ImpEx will only work if the filenameadheres to the pattern. For example: naming the file projectDataStadium.impex (with a uppercase D) will result in the file being ignored.
- This ImpEx contains a header row with a SQL Table Command and columns, stating that we want to update the table Stadium, in particular the columns code (whose values must be unique), capacity and matches whose ids will be specified below. This is followed by several rows containing the data to import.
- We are specifying two stadiums and several matches to import
- The code attribute needs to be unique: unique=true.
- The USERRIGHTS section sets access rights for cuppyadmins-usergroup on Stadium type.
Invoke the ImpEx from within hybris
- Navigate to Platform/Update
- Check only cuppytrail in Project data settings, then click on Update
- Output both in the console and browser will display Creating project data for cuppytrail ... notifying you that the ImpEx has executed for CuppyTrail
- Now, if you've completed the sidetrail: Trail ~ Integration in the hMC, then:
- Open the hMC and select the imported Stadium (i.e., after performing an unrestricted Search of all stadiums, double-click on Emirates in the search results) to see if ImpEx completed successfully
===
===
Alternatively you can: Invoke the ImpEx using the hMC import wizard
- Log into the hMC
- Open the node System -> Tools -> Import
- Set the import file name
- Start the import: Click on the Start icon