Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Developer Challenge - Full-Stack - Project Set-up and Database Modeling (Week 1)

dinah
Product and Topic Expert
Product and Topic Expert

If you have not checked out the initial blog post for this challenge, please do so and get your development environment set up as outlined in the post. 

Task Description 

We are working on creating test(s) for a particular course/subject. We need to have a pool of questions (related to the course/subject) that we can pick from to make up a test. A single test can be associated with several questions, but each question belongs to only one test. Through the relationship between tests and questions, one should be able to access all questions related to a specific test and easily access the specific test to which a question belongs (hint: backlink). 

Additionally, we need to have a right answer for every question and a question can only have one right answer. An answer cannot exist without a question. If a question is deleted, so should the linked answer be deleted. 

We will get started with database modeling using SAP CAP. We delve into the architecture, carefully defining two core entities and an aspect respectively: "Tests," "Questions," and "Answers".  

Tests Entity – serves as a container for organizing different test cycles. Each entry within the Tests entity represents a unique object with attributes such as test ID, title, description, createdAt, createdBy, modifiedAt, modifiedBy and any other vital information relating to tests. A single test can have many questions. This entity allows us to categorize and manage tests efficiently, facilitating easy retrieval and presentation of tests data. 

Questions Entity – serves as a repository for individual questions comprising the intellectual content of our tests. Each entry in the Questions entity comprises attributes such as ID, text, and any other vital information relating to questions. Many questions can be associated with a single test, but each question belongs to only one test (that is, two different tests cannot have the same question). Centralizing questions in this entity allows us to create a cohesive reservoir of knowledge that can be easily linked to a Test instance. 

Answers Aspect– records the correct answer to a particular question. Each record in this aspect corresponds to a correct answer linked to a specific question. Each entry in the Answers aspect comprises attributes such as ID, and text. The separation of answers from questions reinforces data integrity. 

Why an Aspect instead of Entity for the Answers? 

Aspects are well suited for representing data that does not have a distinct identity of their own. In our schema design, the answers cannot exist without a question. For example, if a question record is deleted, we would want an answer associated with it to be deleted as well. Using an aspect in this case allows us to associate answers data directly with questions without creating a separate entity.  

 

Task outline 

Our goal is to perform entity-relationship modeling based on the above entities' description and then populate initial data in csv files to be used in the next tasks. Below is a visual representation providing details (entity properties and data types) to help with the modeling. 

Schema.png

Steps 

  1. Model the entities in the db/data-model.cds file. 
  2. Declare the remaining entities in srv/cat-service.cds file (The Tests entity has already been declared). 
  3. Generate an empty set of initial csv files and then manually populate them with about two or more records of data each. Note: remember the relationships that exist between entities when populating the records. 

 

Resources 

Here are some resources to guide you through this task: 

CDS Command line Interface tools 

Domain modeling 

Compositions vs. Associations 

Modeling to many associations 

Modeling services in CDS 

Providing Initial Data 

 

Task checklist 

Run the application (cds watch). Note that the initial errors displayed in the terminal after our development environment setup should have disappeared.   

Click on the URL that the server is listening on to access the page displayed below: 

Launched page.png

Under Service Endpoints, click on $metadata and post a screenshot into this discussion thread. Collapse other sections and focus on the <EntityType Name=”...”> tags as shown below.  

week 1 res.png
141 REPLIES 141

AndyBoolean
Participant

afordham
Participant

dhegde
Participant

mrpz
Explorer

fran__nino
Discoverer

DangerZone931
Explorer

Buena tarde estimados.

Here's my screenshot.

DangerZone931_0-1694123908329.png

 

bztoy
Participant

swatantra
Explorer

dinah
Product and Topic Expert
Product and Topic Expert
0 Kudos

Some pieces are not accurately represented in your model:

  • Check your Tests entity, there is a tiny piece missing in your model (The attribute Partner in your <NavigationProperty Name="questions">). Hint: backlink
  • Answers is not an independent Entity but an Aspect that exists in the context of a Questions entity. An answer cannot exist on its own without a question.

mjhtalingdan
Discoverer

UweFetzer_se38
Active Contributor

Raghu_150
Explorer

SORABHN
Explorer

rakesh82
Participant

dinah
Product and Topic Expert
Product and Topic Expert
0 Kudos

One piece is not accurately represented in your model: Answers in not an independent Entity but an Aspect that exists in the context of a Questions entity. An answer cannot exist on its own without a question.

Thanks! @dinah I have corrected that now and updated image..

OrmEmbar
Discoverer

dinah
Product and Topic Expert
Product and Topic Expert

There's a tiny piece missing in your model in the Tests entity - (The attribute Partner in your <NavigationProperty Name="questions">). Hint: backlink

JohnPaulLiberal
Explorer

dinah
Product and Topic Expert
Product and Topic Expert
0 Kudos

There is a tiny piece missing in your model in the Tests entity - (The attribute Partner in your <NavigationProperty Name="questions">). Hint: backlink

satya-dev
Participant

agnissh
Product and Topic Expert
Product and Topic Expert

kjyothiraditya
Participant

nmkarthikeya
Active Participant

vietdht
Newcomer

VinayBhatt
Product and Topic Expert
Product and Topic Expert

MioYasuatke
Active Contributor

petrosy
Explorer

dinah
Product and Topic Expert
Product and Topic Expert

A tiny piece missing in your model in the Tests entity - (The attribute Partner in your <NavigationProperty Name="questions">). Hint: backlink

v-tryputsina
Product and Topic Expert
Product and Topic Expert

dinah
Product and Topic Expert
Product and Topic Expert
0 Kudos

There is a missing piece in your model: check on the relationship between the Tests and Questions entities and remember to include the backlink.

EmmanuelDaCosta
Product and Topic Expert
Product and Topic Expert

ashokkumarg
Explorer
0 Kudos
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
<edmx:Include Alias="Common" Namespace="com.sap.vocabularies.Common.v1"/>
</edmx:Reference>
<edmx:Include Alias="Core" Namespace="Org.OData.Core.V1"/>
</edmx:Reference>
<edmx:Include Alias="UI" Namespace="com.sap.vocabularies.UI.v1"/>
</edmx:Reference>
<edmx:DataServices>
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="tests">
<EntityContainer Name="EntityContainer">
<EntitySet Name="Tests" EntityType="tests.Tests">
<NavigationPropertyBinding Path="Questions" Target="Questions"/>
<NavigationPropertyBinding Path="SiblingEntity" Target="Tests"/>
</EntitySet>
<EntitySet Name="Questions" EntityType="tests.Questions">
<NavigationPropertyBinding Path="test" Target="Tests"/>
<NavigationPropertyBinding Path="Answers" Target="Questions_Answers"/>
</EntitySet>
<EntitySet Name="Questions_Answers" EntityType="tests.Questions_Answers">
<NavigationPropertyBinding Path="up_" Target="Questions"/>
</EntitySet>
</EntityContainer>
<EntityType Name="Tests">
<Key>
<PropertyRef Name="ID"/>
<PropertyRef Name="IsActiveEntity"/>
</Key>
<Property Name="ID" Type="Edm.Guid" Nullable="false"/>
<Property Name="createdAt" Type="Edm.DateTimeOffset" Precision="7"/>
<Property Name="createdBy" Type="Edm.String"/>
<Property Name="modifiedAt" Type="Edm.DateTimeOffset" Precision="7"/>
<Property Name="modifiedBy" Type="Edm.String"/>
<Property Name="title" Type="Edm.String"/>
<Property Name="description" Type="Edm.String"/>
<NavigationProperty Name="Questions" Type="tests.Questions">
<ReferentialConstraint Property="Questions_ID" ReferencedProperty="ID"/>
</NavigationProperty>
<Property Name="Questions_ID" Type="Edm.Guid"/>
<Property Name="IsActiveEntity" Type="Edm.Boolean" Nullable="false" DefaultValue="true"/>
<Property Name="HasActiveEntity" Type="Edm.Boolean" Nullable="false" DefaultValue="false"/>
<Property Name="HasDraftEntity" Type="Edm.Boolean" Nullable="false" DefaultValue="false"/>
<NavigationProperty Name="DraftAdministrativeData" Type="tests.DraftAdministrativeData" ContainsTarget="true"/>
<NavigationProperty Name="SiblingEntity" Type="tests.Tests"/>
</EntityType>
<EntityType Name="Questions">
<Key>
<PropertyRef Name="ID"/>
</Key>
<Property Name="ID" Type="Edm.Guid" Nullable="false"/>
<Property Name="text" Type="Edm.String"/>
<NavigationProperty Name="test" Type="tests.Tests">
<ReferentialConstraint Property="test_ID" ReferencedProperty="ID"/>
</NavigationProperty>
<Property Name="test_ID" Type="Edm.Guid"/>
<NavigationProperty Name="Answers" Type="Collection(tests.Questions_Answers)" Partner="up_">
<OnDelete Action="Cascade"/>
</NavigationProperty>
</EntityType>
<EntityType Name="DraftAdministrativeData">
<Key>
<PropertyRef Name="DraftUUID"/>
</Key>
<Property Name="DraftUUID" Type="Edm.Guid" Nullable="false"/>
<Property Name="CreationDateTime" Type="Edm.DateTimeOffset" Precision="7"/>
<Property Name="CreatedByUser" Type="Edm.String" MaxLength="256"/>
<Property Name="DraftIsCreatedByMe" Type="Edm.Boolean"/>
<Property Name="LastChangeDateTime" Type="Edm.DateTimeOffset" Precision="7"/>
<Property Name="LastChangedByUser" Type="Edm.String" MaxLength="256"/>
<Property Name="InProcessByUser" Type="Edm.String" MaxLength="256"/>
<Property Name="DraftIsProcessedByMe" Type="Edm.Boolean"/>
</EntityType>
<EntityType Name="Questions_Answers">
<Key>
<PropertyRef Name="up__ID"/>
<PropertyRef Name="ID"/>
</Key>
<NavigationProperty Name="up_" Type="tests.Questions" Nullable="false" Partner="Answers">
<ReferentialConstraint Property="up__ID" ReferencedProperty="ID"/>
</NavigationProperty>
<Property Name="up__ID" Type="Edm.Guid" Nullable="false"/>
<Property Name="ID" Type="Edm.Guid" Nullable="false"/>
<Property Name="text" Type="Edm.String"/>
</EntityType>
<Action Name="draftPrepare" IsBound="true" EntitySetPath="in">
<Parameter Name="in" Type="tests.Tests"/>
<Parameter Name="SideEffectsQualifier" Type="Edm.String"/>
<ReturnType Type="tests.Tests"/>
</Action>
<Action Name="draftActivate" IsBound="true" EntitySetPath="in">
<Parameter Name="in" Type="tests.Tests"/>
<ReturnType Type="tests.Tests"/>
</Action>
<Action Name="draftEdit" IsBound="true" EntitySetPath="in">
<Parameter Name="in" Type="tests.Tests"/>
<Parameter Name="PreserveChanges" Type="Edm.Boolean"/>
<ReturnType Type="tests.Tests"/>
</Action>
<Annotations Target="tests.EntityContainer/Tests">
<Annotation Term="Common.DraftRoot">
<Record Type="Common.DraftRootType">
<PropertyValue Property="ActivationAction" String="tests.draftActivate"/>
<PropertyValue Property="EditAction" String="tests.draftEdit"/>
<PropertyValue Property="PreparationAction" String="tests.draftPrepare"/>
</Record>
</Annotation>
</Annotations>
<Annotations Target="tests.Tests/IsActiveEntity">
<Annotation Term="UI.Hidden" Bool="true"/>
</Annotations>
<Annotations Target="tests.Tests/HasActiveEntity">
<Annotation Term="UI.Hidden" Bool="true"/>
</Annotations>
<Annotations Target="tests.Tests/HasDraftEntity">
<Annotation Term="UI.Hidden" Bool="true"/>
</Annotations>
<Annotations Target="tests.Tests/DraftAdministrativeData">
<Annotation Term="UI.Hidden" Bool="true"/>
</Annotations>
<Annotations Target="tests.DraftAdministrativeData">
<Annotation Term="Common.Label" String="Draft Administrative Data"/>
</Annotations>
<Annotations Target="tests.DraftAdministrativeData/DraftUUID">
<Annotation Term="UI.Hidden" Bool="true"/>
<Annotation Term="Common.Label" String="Draft (Technical ID)"/>
</Annotations>
<Annotations Target="tests.DraftAdministrativeData/CreationDateTime">
<Annotation Term="Common.Label" String="Draft Created On"/>
</Annotations>
<Annotations Target="tests.DraftAdministrativeData/CreatedByUser">
<Annotation Term="Common.Label" String="Draft Created By"/>
</Annotations>
<Annotations Target="tests.DraftAdministrativeData/DraftIsCreatedByMe">
<Annotation Term="UI.Hidden" Bool="true"/>
<Annotation Term="Common.Label" String="Draft Created By Me"/>
</Annotations>
<Annotations Target="tests.DraftAdministrativeData/LastChangeDateTime">
<Annotation Term="Common.Label" String="Draft Last Changed On"/>
</Annotations>
<Annotations Target="tests.DraftAdministrativeData/LastChangedByUser">
<Annotation Term="Common.Label" String="Draft Last Changed By"/>
</Annotations>
<Annotations Target="tests.DraftAdministrativeData/InProcessByUser">
<Annotation Term="Common.Label" String="Draft In Process By"/>
</Annotations>
<Annotations Target="tests.DraftAdministrativeData/DraftIsProcessedByMe">
<Annotation Term="UI.Hidden" Bool="true"/>
<Annotation Term="Common.Label" String="Draft In Process By Me"/>
</Annotations>
</Schema>
</edmx:DataServices>
</edmx:Edmx>