# Data Module

# What is a data module?

Data module holds composites of the project.

  1. Different types of data that can be defined in this module:

    • Data
    • Enum
    • ADT
    • type-alias
    • data-tag
  2. What are the primitives data-types in Smile.

  3. When do we use data in a real project?

While moving between various access layers ex: when you want to read data from several dbs and display as a single unit of data on web.

# Creating a data module

  1. Open Mould project in eclipse
  2. Create a new data module by adding the following section:
section learning {
	data-module TutorialData at com.metastay.tutorialdata
	data-module LearningData at com.metastay.learningdata
}
  1. Run smile command in sbt & refresh the project in eclipse.
  2. Open file LearningData.kdata & add the following definition of Employee & Company data:
data Employee (
	name:String,
	gender:String,
	yearOfJoining:Int,
	designation:String,
	experienceInMonths:Int
)

data Company object-extend (
	employeeList:Employee*
)
  1. Copy the methods from tutorialdata.Company.scala to CompanyObjectExtn.scala class.

  2. Also copy the test cases & fix the imports to point to CompanyObjectExtn methods.

  3. Re-run the test cases.

Note

IntelliJ Troubleshooting Note: When a new module added is not being recognised as a source folder in intelliJ - Open ApplicationBuild.scala and if you see a banner above as shown below, click on "Enable auto-import" else make a small change and save the file - this triggers a reload of the project.

# Defining an enum

  1. Open file LearningData.kdata in eclipse
  2. Define DesignationType as an enum:
enum DesignationType => SE | SSE | TL | TA | PM | DIR | VP | CEO
  1. Change Employee's designation type from string to the enum defined above.
  2. Fix compiler errors & test:compile error (if any)
  3. Re-run the test cases.

# Defining an option

  1. Open file LearningData.kdata in eclipse
  2. Define emailId as an optional field in Employee data
  3. There should be no compiler errors due to this change
  4. Re-run the test cases.

# Assignment

# Implement the following methods in Company extension

  1. List all employees who have an emailId. Output must be a map of name & emailId

  2. Add address field in Employee data with the following attributes in address:

    • addressLine1
    • addressLine2 - optional
    • City
    • State
    • Pincode
  3. List all employees who belong to a specific city.

# Define Employee's dateOfBirth skillList and language as optional value

  1. implement the following methods
    • Get the number of employees per skill
    • Get the highest paid employee per skill
    • Given a language - list the employee names.
    • Get the oldest employee details
    • Get the youngest employee details

# Further references