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.
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.
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:
Verify that the following files are generated in the appropriate directories:
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:
------------------------------------------------------- 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.
------------------------------------------------------------------------------- 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!
The next step is to implement the findTimecards() method. Click here to start this implementation.