Defining primary objects

As part of creating a custom tool for the Management Center, define an OpenLaszlo library class for the primary objects.

Feature Pack 2Feature Pack 3You must define a definition file for the primary objects instead of an OpenLaszlo library class.

About this task

A primary object definition describes a top-level business object that exists as its own entity independent of other objects. The primary object definition differs from other object definition types since the primary objects can be found using a search service and can be referenced by other primary objects.

Two primary objects are defined in this lesson: Recipe and Recipe Collection.

Procedure

  1. Complete one of the following steps:
    • WebSphere Commerce Version 7.0.0.0Feature Pack 1In the Enterprise Explorer view, expand LOBTools > WebContent > WEB-INF > src > lzx > mycompany > recipe > objectDefinitions.
    • Feature Pack 2Feature Pack 3In the Enterprise Explorer view, expand LOBTools > WebContent > config > mycompany > recipe > objectDefinitions.
  2. Right-click the objectDefinitions folder and select Import. Expand General and select File system.
  3. Click Next, then click Browse and navigate to the following directory:
    OptionDescription
    WebSphere Commerce Version 7.0.0.0Feature Pack 1TutorialSource\LOBTools\WebContent\WEB-INF\src\lzx\mycompany\recipe\objectDefinitions, where TutorialSource is the location where you extracted the Tutorial sample source code WebSphere Commerce Version 7.0.0.0Feature Pack 1
    1. Select the RecipePrimaryObjectDefinition.lzx file.
    2. Click Finish to import the file.
    Feature Pack 2Feature Pack 3TutorialSource\LOBTools\WebContent\config\mycompany\recipe\objectDefinitions, where TutorialSource is the location where you extracted the Tutorial sample source code Feature Pack 2Feature Pack 3
    1. Select the RecipePrimaryObjectDefinition.def file.
    2. Click Finish to import the file.
  4. Open one of the following files and examine the contents:
    • WebSphere Commerce Version 7.0.0.0Feature Pack 1RecipePrimaryObjectDefinition.lzx (primary object class file)
    • Feature Pack 2Feature Pack 3RecipePrimaryObjectDefinition.def (primary object definition file)
    A primary object named Recipe is defined in these files.

    The following code samples show the primary object that is defined in each of these files:

    OptionDescription
    WebSphere Commerce Version 7.0.0.0Feature Pack 1RecipePrimaryObjectDefinition.lzx WebSphere Commerce Version 7.0.0.0Feature Pack 1
    
    <class name="recRecipePrimaryObjectDefinition" extends="wcfPrimaryObjectDefinition"
                    objectType="Recipe"
                    creatable="true"
                    displayName="${extRecipeResources.recipe_DisplayName.string}"
                    displayNameProperty="name"
                    idProperty="recipeId"
                    newDisplayName="${extRecipeResources.recipe_NewDisplayName.string}"
                    propertiesClass="recRecipeProperties"
                    icon="recipeIcon"
                    headerIcon="recipeHeaderIcon"  
                    >                    
                    
            <!-- Multiple GetChildrenService -->
            <wcfGetChildrenService url="/cmc/GetRecipeChildren-Ingredients" objectTypes="RecipeIngredients">
                    <wcfServiceParam name="storeId" />
                    <wcfServiceParam name="recipeId" propertyName="recipeId"/>
            </wcfGetChildrenService>       
            <wcfGetChildrenService url="/cmc/GetRecipeChildren-Instruction" objectTypes="RecipeInstruction">
                    <wcfServiceParam name="storeId" />
                    <wcfServiceParam name="recipeId" propertyName="recipeId"/>
            </wcfGetChildrenService>      
            <wcfGetChildrenService url="/cmc/GetRecipeChildren-Association" objectTypes="RecipeAssociation">
                    <wcfServiceParam name="storeId" />
                    <wcfServiceParam name="recipeId" propertyName="recipeId"/>
            </wcfGetChildrenService>
                            
            <!-- Create Service -->
            <wcfCreateService sendDefaultLanguageProperties="true" url="/cmc/CreateRecipe">
                    <wcfServiceParam name="storeId"/>
                    <wcfServiceParam name="defaultLanguageId" parameterName="languageId" />
            </wcfCreateService>        
            
            <!-- Update Service -->
            <wcfUpdateService sendDefaultLanguageProperties="true" url="/cmc/UpdateRecipe">
                    <wcfServiceParam name="storeId" />
                    <wcfServiceParam name="defaultLanguageId" parameterName="languageId" />
                    <wcfServiceParam name="recipeId" propertyName="recipeId" />
            </wcfUpdateService>
            
            <!-- Delete Service -->
            <wcfDeleteService url="/cmc/DeleteRecipe">
                    <wcfServiceParam name="storeId" />
                    <wcfServiceParam name="recipeId" propertyName="recipeId" />
            </wcfDeleteService>       
                                                                          
            <!-- Refresh Service -->
            <wcfRefreshService url="/cmc/GetRecipeByRecipeId">
            <wcfServiceParam name="storeId" />
            <wcfServiceParam name="recipeId" propertyName="recipeId" />
            </wcfRefreshService>
    
            <!-- Property Definition -->
            <wcfPropertyDefinition displayName="${extRecipeResources.recipeTime_DisplayName.string}"  
                    propertyName="time" type="number" />
            <wcfPropertyDefinition displayName="${extRecipeResources.difficultyLevel_DisplayName.string}" 
                    propertyName="difficulty">
                            <wcfPropertyValue displayName="easy" value="easy"/>
                            <wcfPropertyValue displayName="medium" value="normal"/>
                            <wcfPropertyValue displayName="difficult" value="difficult"/>                                 
            </wcfPropertyDefinition>  
                                                    
            <!-- All child and reference objects need to be initialized so that the parent-child and reference relationship can be built.   -->
            <recRecipeDescriptionDefinition/>
            <recRecipeCollectionReference/>
            <recRecipeIngredientsDefinition/>
            <recRecipeInstructionDefinition/>
            <recRecipeAssociationDefinition/>
                    
    </class>
    
    Feature Pack 2Feature Pack 3RecipePrimaryObjectDefinition.def Feature Pack 2Feature Pack 3
    <PrimaryObjectDefinition definitionName="Recipe"
    		objectType="Recipe"
    		creatable="true"
    		displayName="${extRecipeResources.recipe_DisplayName}"
    		displayNameProperty="name"
    		idProperty="recipeId"
    		newDisplayName="${extRecipeResources.recipe_NewDisplayName}"
    		propertiesDefinitionName="recRecipeProperties"
    		icon="recipeIcon"
    		headerIcon="recipeHeaderIcon">
    
    	<!-- Multiple GetChildrenService -->
    	<GetChildrenService url="/cmc/GetRecipeChildren-Ingredients"
    		objectTypes="RecipeIngredients">
    		<ServiceParam name="storeId"/>
    		<ServiceParam name="recipeId" propertyName="recipeId"/>
            </GetChildrenService>
    	<GetChildrenService url="/cmc/GetRecipeChildren-Instruction"
    		objectTypes="RecipeInstruction">
    		<ServiceParam name="storeId"/>
    		<ServiceParam name="recipeId" propertyName="recipeId"/>
    	</GetChildrenService>      
    	<GetChildrenService url="/cmc/GetRecipeChildren-Association"
    		objectTypes="RecipeAssociation">
    		<ServiceParam name="storeId"/>
    		<ServiceParam name="recipeId" propertyName="recipeId"/>
    	</GetChildrenService>
    
    	<!-- Create Service -->
    	<CreateService sendDefaultLanguageProperties="true" url="/cmc/CreateRecipe">
    		<ServiceParam name="storeId"/>
    		<ServiceParam name="defaultLanguageId" parameterName="languageId"/>
    	</CreateService>
    
    	<!-- Update Service -->
    	<UpdateService sendDefaultLanguageProperties="true" url="/cmc/UpdateRecipe">
    		<ServiceParam name="storeId"/>
    		<ServiceParam name="defaultLanguageId" parameterName="languageId"/>
    		<ServiceParam name="recipeId" propertyName="recipeId"/>
    	</UpdateService>
    
    	<!-- Delete Service -->
    	<DeleteService url="/cmc/DeleteRecipe">
    		<ServiceParam name="storeId"/>
    		<ServiceParam name="recipeId" propertyName="recipeId"/>
            </DeleteService>
                                                                
    	<!-- Refresh Service -->
    	<RefreshService url="/cmc/GetRecipeByRecipeId">
    		<ServiceParam name="storeId"/>
    		<ServiceParam name="recipeId" propertyName="recipeId"/>
    	</RefreshService>
    
            <!-- Property Definition -->
            <PropertyDefinition displayName="${extRecipeResources.recipeTime_DisplayName}"
                    propertyName="time" type="number"/>
            <PropertyDefinition
    		displayName=
    			"${extRecipeResources.difficultyLevel_DisplayName}"
    		propertyName="difficulty">
    		<PropertyValue displayName="easy" value="easy"/>
    		<PropertyValue displayName="medium" value="normal"/>
    		<PropertyValue displayName="difficult" value="difficult"/>
            </PropertyDefinition>
    
    	<!--
    		All child and reference objects need to be initialized so that the
    		parent-child and reference relationship can be built.
    	-->
            <ChildObjectDefinition baseDefinitionName="recRecipeDescriptionDefinition"/>
            <ChildObjectDefinition baseDefinitionName="recRecipeIngredientsDefinition"/>
            <ReferenceObjectDefinition baseDefinitionName="recRecipeIngredientsReference"/>
            <ChildObjectDefinition baseDefinitionName="recRecipeInstructionDefinition"/>
            <ReferenceObjectDefinition baseDefinitionName="recRecipeAssociationDefinition"/>
    </PrimaryObjectDefinition>
    As described in the lesson Modeling the Recipe noun to Management Center object definitions, the primary object Recipe has four child objects:
    • description
    • ingredients
    • instructions
    • tools association
    Recipe also has one parent reference object: ChildRecipe. All child and reference objects must be retrieved by separate wcfGetChildrenService services, except for description. The description is retrieved in the Recipe get service. All of the services have been defined in Tutorial: Creating a BOD service module, and are mapped to the URL in the lesson: Retrieving objects by transforming Nouns.
  5. Define the primary object, RecipeCollection, within one of the following files:
    OptionDescription
    WebSphere Commerce Version 7.0.0.0Feature Pack 1RecipePrimaryObjectDefinition.lzx (primary object class file) WebSphere Commerce Version 7.0.0.0Feature Pack 1The following sample code shows the primary object definition for RecipeCollection:
    
    <class name="recRecipeCollectionPrimaryObjectDefinition" extends="wcfPrimaryObjectDefinition"
                    creatable="true"
                    idProperty="collectionId"
                    objectType="RecipeCollection"
                    displayName="${extRecipeResources.recipeCollection_DisplayName.string}"
                    displayNameProperty="collectionName"  
                    newDisplayName="${extRecipeResources.recipeCollection_NewDisplayName.string}"
                    propertiesClass="recCollectionProperties" 
                    >                            
                    
            <!-- Create Service -->
            <wcfCreateService sendDefaultLanguageProperties="true" url="/cmc/CreateRecipeCollection">
                    <wcfServiceParam name="storeId"/>
                    <wcfServiceParam name="defaultLanguageId" parameterName="languageId"/> 
            </wcfCreateService>
            
            <!-- Update Service -->
            <wcfUpdateService sendDefaultLanguageProperties="true" url="/cmc/UpdateRecipeCollection">
                    <wcfServiceParam name="storeId" />
                    <wcfServiceParam name="defaultLanguageId" parameterName="languageId" />
                    <wcfServiceParam name="collectionId" propertyName="collectionId" />
            </wcfUpdateService>
            
            <!-- Delete Service -->
            <wcfDeleteService url="/cmc/DeleteRecipeCollection">
                    <wcfServiceParam name="storeId" />
                    <wcfServiceParam name="collectionId" propertyName="collectionId"/>
            </wcfDeleteService>               
            
            <!-- GetChildren Service -->      
            1 <wcfGetChildrenService url="/cmc/GetRecipesByCollection" objectTypes="ChildRecipe">
                    <wcfServiceParam name="collectionId" propertyName="collectionId"/>
                    <wcfServiceParam name="storeId" />
            </wcfGetChildrenService>          
            <!-- Refresh Service -->
            <wcfRefreshService url="/cmc/GetRecipeCollectionById">
              <wcfServiceParam name="storeId" />
              <wcfServiceParam name="collectionId" propertyName="collectionId" />
            </wcfRefreshService>
    
            2 <recRecipeNavigationList/>                                                
            
            <!-- Include all children object definition-->
            <recRecipeCollectionDescription/>                 
            
            <!-- Define the reference relationship with Recipe -->
            3 <recRecipeReferencesCollection/>	
    </class>
    
    1 wcfGetChildrenService
    Gets all the recipes under the recipe collection as child objects of it. The service is defined in Tutorial: Creating a BOD service module and is mapped to the URL in the lesson: Retrieving objects by transforming Nouns.
    2 recRecipeNavigationList
    An instance of wcfNavigationListDefinition used to list the recipes in the grid view after clicking a recipe collection in the navigation tree. It is defined in RecipeGrid.lzx in the lesson: Defining views for a Management Center object.
    3 recRecipeReferencesCollection
    An instance of wcfParentReferenceObjectDefinition defined in RecipeCommonObjectDefinition.lzx. It is used to build the parent-child relationship between the recipe collection and recipe.
    Feature Pack 2Feature Pack 3RecipePrimaryObjectDefinition.def (primary object definition file) Feature Pack 2Feature Pack 3The following sample code shows the primary object definition for RecipeCollection:
    <PrimaryObjectDefinition definitionName="RecipeCollection"
    		creatable="true"
    		idProperty="collectionId"
    		objectType="RecipeCollection"
    		displayName="${extRecipeResources.recipeCollection_DisplayName}"
    		displayNameProperty="collectionName"
    		newDisplayName="${extRecipeResources.recipeCollection_NewDisplayName}"
    		propertiesDefinitionName="recCollectionProperties">
    
    	<!-- Create Service -->
    	<CreateService sendDefaultLanguageProperties="true"
    		url="/cmc/CreateRecipeCollection">
    		<ServiceParam name="storeId"/>
    		<ServiceParam name="defaultLanguageId" parameterName="languageId"/> 
            </CreateService>
    
            <!-- Update Service -->
    	<UpdateService sendDefaultLanguageProperties="true"
    		url="/cmc/UpdateRecipeCollection">
    		<ServiceParam name="storeId"/>
    		<ServiceParam name="defaultLanguageId" parameterName="languageId"/>
    		<ServiceParam name="collectionId" propertyName="collectionId"/>
    	</UpdateService>
    
    	<!-- Delete Service -->
    	<DeleteService url="/cmc/DeleteRecipeCollection">
    		<ServiceParam name="storeId"/>
    		<ServiceParam name="collectionId" propertyName="collectionId"/>
    	</DeleteService>
    
    	<!-- GetChildren Service -->
    	1 <GetChildrenService url="/cmc/GetRecipesByCollection"
    		objectTypes="ChildRecipe">
    		<ServiceParam name="collectionId" propertyName="collectionId"/>
    		<wServiceParam name="storeId"/>
    	</GetChildrenService>
    	<!-- Refresh Service -->
    	<RefreshService url="/cmc/GetRecipeCollectionById">
    		<wcfServiceParam name="storeId"/>
    		<wcfServiceParam name="collectionId" propertyName="collectionId"/>
    	</RefreshService>
    
    2 <NavigationListDefinition baseDefinitionName="recRecipeNavigationList"/>
    
    	<!-- Include all children object definition-->
    	<ChildObjectDefinition baseDefinitionName="recRecipeCollectionDescription"/>
    
    	<!-- Define the reference relationship with Recipe -->
    	<ParentReferenceObjectDefinition
    	3 baseDefinitionName="recRecipeReferencesCollection"/>
    </PrimaryObjectDefinition>
    1 GetChildrenService
    Gets all the recipes under the recipe collection as child objects of it. The service is defined in Tutorial: Creating a BOD service module and is mapped to the URL in the lesson: Retrieving objects by transforming Nouns.
    2 recRecipeNavigationList
    An instance of wcfNavigationListDefinition used to list the recipes in the grid view after clicking a recipe collection in the navigation tree. It is defined in RecipeGrid.def in the lesson: Defining views for a Management Center object.
    3 recRecipeReferencesCollection
    An instance of wcfParentReferenceObjectDefinition defined in RecipeCommonObjectDefinition.def. It is used to build the parent-child relationship between the recipe collection and recipe.
  6. WebSphere Commerce Version 7.0.0.0Feature Pack 1Right-click the LOBTools project and select Build OpenLaszlo Project.