TimeTrackingService Definition

We are now on iteration 2. The goal of this iteration is to build the Search Results panel. To refresh our memories, here's the mockup of the Search screen. The Search Results panel is the panel on the right that shows a table of timecards.

Value Objects

To support the Search Results panel, the service layer must provide the ability to get a list of timecards that match a specific criteria. Let's decide that we will create a service called TimeTrackingService that will provide this functionality via the method specified below:

    public interface TimeTrackingService
    {
        public Collection<TimecardSummaryVO> findTimecards(TimecardSearchCriteriaVO criteria);
    }
                

Here TimecardSearchCriteriaVO is a value object that packages timecard search criteria - if a field in this class is specified, then that criterion applies; if the field is left as null, then that criterion does not apply. TimecardSummaryVO is another value object that packages summary information about each timecard. Based on the fields in the Search screen, let's design these two value objects. Note that we need a status field in both these value objects. So first create a UML enumeration called TimecardStatus under the org.andromda.timetracker.domain package as shown below. To do this, create an enumeration in the "Domain Objects" diagram. Then add the four enumeration literal names and values as shown below. Enumeration Literal Names are UPPERCASE by convention and are referred to in code by TimecardStatue.NAME. EnumerationLiteral values are the String Text value displayed for the literal. Make sure the enumeration is created in the org.andromda.timetracker.domain package by inspecting the containment tree.

Now that TimecardStatus is defined, we can define the two value objects needed by the findTimecards() service method. Create TimecardSearchCriteriaVO and TimecardSummaryVO under the org.andromda.timetracker.vo package as shown below. Create these value objects in the "Value Objects" diagram. Note that the multiplicity of each attribute in TimecardSearchCriteriaVO is set to 0..1 - indicating that their value could be left as null. To specify the multiplicity of an attribute, you must double-click on the attribute to open its specification and then choose the right multiplicity. Make sure these two classes are created in the org.andromda.timetracker.vo package by inspecting the containment tree.

TimeTrackingService

We now have everything to define our TimeTrackingService. Create this service under the org.andromda.timetracker.service package as shown below. Create it in the "Services" diagram and make sure the service is created in the org.andromda.timetracker.service package by inspecting the containment tree. Also make sure that the return type of findTimecards is TimecardSummaryVO[0..*], by setting its return type as TimecardSummaryVO and the multiplicity as 0..* (use the return parameter in the parameters list to set the multiplicity).

Now let's ask AndroMDA to generate code:

  1. Execute the command mvn install in the Command Prompt. Make sure you get a BUILD SUCCESSFUL message.

Verify that the following files are generated in the appropriate directories:

  1. common\target\src\org\andromda\timetracker\domain\TimecardStatus.java
  2. common\target\src\org\andromda\timetracker\vo\TimecardSummaryVO.java
  3. common\target\src\org\andromda\timetracker\vo\TimecardSearchCriteriaVO.java
  4. common\target\src\org\andromda\timetracker\service\TimeTrackingService.java
  5. core\target\src\org\andromda\timetracker\service\TimeTrackingServiceBase.java
  6. core\src\main\java\org\andromda\timetracker\service\TimeTrackingServiceImpl.java

TimeTrackingService Test

As with UserService, we will first write a test for TimeTrackingService and then write the implementation to make the test pass. Follow the steps below to create TimeTrackingServiceTest and run it:

  1. Copy TimeTrackingServiceTest.java from the directory C:\timetracker-completed\core\src\test\java\org\andromda\timetracker\service to the corresponding directory under your implementation. This file contains two tests for findTimecards(): testFindAllTimecards() and testFindTimecardsForSubmitter. Review both tests and make sure you understand them.
  2. Execute the following command in the C:\timetracker directory to run the test.
    mvn -f core/pom.xml test
    You will find that the test fails with the following message:
    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    Running TestSuite
    Running TestSuite
    Tests run: 3, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 5.263 sec <<< FAILURE!
    Results :
    Failed tests: 
      testFindAllTimecards(org.andromda.timetracker.service.TimeTrackingServiceTest)
      testFindTimecardsForSubmitter(org.andromda.timetracker.service.TimeTrackingServiceTest)
    Tests run: 3, Failures: 2, Errors: 0, Skipped: 0
    [INFO] ------------------------------------------------------------------------
    [ERROR] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] There are test failures.
                            
  3. Let's look at the test results to see what happened. Open C:\timetracker\core\target\surefire-reports\TestSuite.txt. You will see the following log:
    -------------------------------------------------------------------------------
    Test set: TestSuite
    -------------------------------------------------------------------------------
    Results :
    Failed tests: 
      testFindAllTimecards(org.andromda.timetracker.service.TimeTrackingServiceTest)
      testFindTimecardsForSubmitter(org.andromda.timetracker.service.TimeTrackingServiceTest)
    Tests run: 3, Failures: 2, Errors: 0, Skipped: 0
    ServiceException: Error performing 'TimeTrackingService.findTimecards(TimecardSearchCriteriaVO criteria)' --> java.lang.UnsupportedOperationException: org.andromda.timetracker.service.TimeTrackingService.handleFindTimecards(TimecardSearchCriteriaVO criteria) Not implemented!
                            
    Obviously the service is throwing an java.lang.UnsupportedOperationException. This problem will be fixed when we implement the service.

What's Next?

The next step is to implement the findTimecards() method. Click here to start this implementation.