Defining primary objects

In this lesson, you create a primary object definition file and define the primary object definitions for the Recipe and Recipe Collection primary objects.

About this task

A business object definition is a definition that extends the ObjectDefinition class. 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 by using a search service and can be referenced by other primary objects.

Procedure

  1. In the Enterprise Explorer view, expand LOBTools > WebContent > WEB-INF > src > xml > mycompany > recipe > objectDefinitions.
  2. Right-click the objectDefinitions folder and select Import. Expand General and select File system.
  3. Click Next, then click Browse to the following directory:

    TutorialSource\LOBTools\WebContent\WEB-INF\src\xml\mycompany\recipe\objectDefinitions, where TutorialSource is the location where you extracted the Tutorial sample source code

  4. Select the RecipePrimaryObjectDefinition.xml primary object definition files within this directory. Click Finish to import the file.
  5. Open the RecipePrimaryObjectDefinition.xml primary object definition file within your workspace to examine the contents:
    A primary object that is named Recipe is defined in this file.
    The following code sample show the Recipe primary object definition that is defined in this files:
    
    <?xml version="1.0" encoding="UTF-8"?>
    <Definitions>  
      <PrimaryObjectDefinition creatable="true" definitionName="cmc/recipe/Recipe" displayName="${ExtRecipeResources.recipe_DisplayName}" 
       displayNameProperty="name" headerIcon="productHeaderIcon" icon="productIcon" idProperty="recipeId" 
       newDisplayName="${ExtRecipeResources.recipe_NewDisplayName}" objectType="Recipe" propertiesDefinition="cmc/recipe/RecipeProperties" 
       searchType="FindRecipes">
        <dependency localName="ExtRecipeResources" moduleName="cmc/recipe/ExtRecipeResources"/>
        
        <GetChildrenService objectTypes="RecipeIngredients" url="/cmc/GetRecipeChildren-Ingredients">
          <ServiceParam name="storeId"/>
          <ServiceParam name="recipeId" propertyName="recipeId"/>
        </GetChildrenService>
        
        <GetChildrenService objectTypes="RecipeInstruction" url="/cmc/GetRecipeChildren-Instruction">
          <ServiceParam name="storeId"/>
          <ServiceParam name="recipeId" propertyName="recipeId"/>
        </GetChildrenService>
        
        <GetChildrenService objectTypes="RecipeAssociation" url="/cmc/GetRecipeChildren-Association">
          <ServiceParam name="storeId"/>
          <ServiceParam name="recipeId" propertyName="recipeId"/>
        </GetChildrenService>
        
        <CreateService sendDefaultLanguageProperties="true" url="/cmc/CreateRecipe">
          <ServiceParam name="storeId"/>
          <ServiceParam name="defaultLanguageId" parameterName="languageId"/>
        </CreateService>	 
        
        <UpdateService sendDefaultLanguageProperties="true" url="/cmc/UpdateRecipe">
          <ServiceParam name="storeId"/>
          <ServiceParam name="defaultLanguageId" parameterName="languageId"/>
          <ServiceParam name="recipeId" propertyName="recipeId"/>
        </UpdateService>
        
        <DeleteService url="/cmc/DeleteRecipe">
          <ServiceParam name="storeId"/>
          <ServiceParam name="recipeId" propertyName="recipeId"/>
        </DeleteService>	
                        
        <RefreshService url="/cmc/GetRecipeByRecipeId">
          <ServiceParam name="storeId"/>
          <ServiceParam name="recipeId" propertyName="recipeId"/>
        </RefreshService>
        
        <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>	
         	
        <ChildObjectDefinition baseDefinition="cmc/recipe/RecipeDescriptionDefinition"/>
        <ChildObjectDefinition baseDefinition="cmc/recipe/RecipeIngredientsDefinition"/>
        <ReferenceObjectDefinition baseDefinition="cmc/recipe/RecipeIngredientsReference"/>
        <ChildObjectDefinition baseDefinition="cmc/recipe/RecipeInstructionDefinition"/>
        <ReferenceObjectDefinition baseDefinition="cmc/recipe/RecipeAssociationDefinition"/>	
      
      </PrimaryObjectDefinition>
      ...
    </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 GetChildrenService 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 one of the following lessons.
    The following code sample show the Recipe Collection primary object definition that is defined in this files:
    
    <!--
    The primary objects for recipes collections
    -->	
    <PrimaryObjectDefinition creatable="true" definitionName="cmc/recipe/RecipeCollection" 
     displayName="${ExtRecipeResources.recipeCollection_DisplayName}" displayNameProperty="collectionName" 
     headerIcon="catalogHeaderIcon" icon="catalogIcon" idProperty="collectionId" 
     newDisplayName="${ExtRecipeResources.recipeCollection_NewDisplayName}" objectType="RecipeCollection" 
     propertiesDefinition="cmc/recipe/CollectionProperties" searchType="FindRecipeCollections">
      <dependency localName="ExtRecipeResources" moduleName="cmc/recipe/ExtRecipeResources"/>				
      
      <CreateService sendDefaultLanguageProperties="true" url="/cmc/CreateRecipeCollection">
        <ServiceParam name="storeId"/>
        <ServiceParam name="defaultLanguageId" parameterName="languageId"/> 
      </CreateService>
      
      <UpdateService sendDefaultLanguageProperties="true" url="/cmc/UpdateRecipeCollection">
        <ServiceParam name="storeId"/>
        <ServiceParam name="defaultLanguageId" parameterName="languageId"/>
        <ServiceParam name="collectionId" propertyName="collectionId"/>
      </UpdateService>
      
      <DeleteService url="/cmc/DeleteRecipeCollection">
        <ServiceParam name="storeId"/>
        <ServiceParam name="collectionId" propertyName="collectionId"/>
      </DeleteService>		
      
    1<GetChildrenService objectTypes="ChildRecipe" url="/cmc/GetRecipesByCollection">
        <ServiceParam name="storeId"/>
        <ServiceParam name="collectionId" propertyName="collectionId"/>
      </GetChildrenService>
      
      <RefreshService url="/cmc/GetRecipeCollectionById">
        <ServiceParam name="storeId"/>
        <ServiceParam name="collectionId" propertyName="collectionId"/>
      </RefreshService>
      
      <ChildObjectDefinition baseDefinition="cmc/recipe/RecipeCollectionDescription"/>
    2<NavigationListDefinition baseDefinition="cmc/recipe/RecipeNavigationList"/>
      
    3<ParentReferenceObjectDefinition baseDefinition="cmc/recipe/RecipeReferencesCollection"/>	 	
      
    </PrimaryObjectDefinition>		
      
    <ParentReferenceObjectDefinition definitionName="cmc/recipe/RecipeReferencesCollection" 
     idProperty="childRecipeId" objectType="ChildRecipe" referencedType="Recipe">
      <CreateService url="/cmc/CreateRecipeCollectionRelationship"> 
        <ServiceParam name="storeId"/>
        <ServiceParam name="recipeId" objectPath="Recipe" propertyName="recipeId"/>
        <ServiceParam name="collectionId" parentProperty="true" propertyName="collectionId"/>
      </CreateService>
      <DeleteService sendAll="false" url="/cmc/DeleteRecipeCollectionRelationship">
        <ServiceParam name="storeId"/>
        <ServiceParam name="recipeId" objectPath="Recipe" propertyName="recipeId"/>
        <ServiceParam name="collectionId" parentProperty="true" propertyName="collectionId"/>
      </DeleteService>	      
    </ParentReferenceObjectDefinition>
    1 GetChildrenService
    Gets all the recipes under the recipe collection as child objects of it. The service is defined in the prerequisite tutorial and is mapped to the URL in the lesson in a following lesson.
    2 RecipeNavigationList
    An instance of NavigationListDefinition used to list the recipes in the grid view after clicking a recipe collection in the navigation tree. It is defined in RecipeGrid.xml in a following lesson.
    3 RecipeReferencesCollection
    An instance of ParentReferenceObjectDefinition defined in RecipeCommonObjectDefinition.xml. It is used to build the parent-child relationship between the recipe collection and recipe.