01: package com.technoetic.xplanner.importer;
02:
03: import com.technoetic.xplanner.domain.Iteration;
04: import com.technoetic.xplanner.domain.UserStory;
05: import com.technoetic.xplanner.importer.spreadsheet.*;
06:
07: import java.io.IOException;
08: import java.io.InputStream;
09: import java.util.ArrayList;
10: import java.util.Iterator;
11: import java.util.List;
12:
13: public class SpreadsheetStoryImporter {
14: private SpreadsheetStoryFactory spreadsheetStoryFactory;
15:
16: public SpreadsheetStoryImporter(
17: SpreadsheetStoryFactory spreadsheetStoryFactory) {
18: this .spreadsheetStoryFactory = spreadsheetStoryFactory;
19: }
20:
21: public List importStories(Iteration iteration,
22: SpreadsheetHeaderConfiguration headerConfiguration,
23: InputStream inputStream, boolean onlyUncompleted)
24: throws IOException {
25: List newStories = new ArrayList();
26: List stories = readStoriesFromSpreadsheet(headerConfiguration,
27: inputStream);
28: SpreadsheetStoryFilter storyFilter = new SpreadsheetStoryFilter(
29: iteration.getStartDate(), iteration.getEndDate());
30: for (Iterator iterator = stories.iterator(); iterator.hasNext();) {
31: SpreadsheetStory spreadsheetStory = (SpreadsheetStory) iterator
32: .next();
33: if (!storyFilter.matches(spreadsheetStory)
34: || (onlyUncompleted && spreadsheetStory.getStatus()
35: .equalsIgnoreCase("C")))
36: continue;
37: UserStory userStory = new UserStory();
38: if (spreadsheetStory.getTitle() == null
39: || "".equals(spreadsheetStory.getTitle().trim()))
40: throw new MissingFieldSpreadsheetImporterException(
41: "name", "missing field");
42: userStory.setName(spreadsheetStory.getTitle());
43: userStory.setEstimatedHours(spreadsheetStory.getEstimate());
44: userStory.setIterationId(iteration.getId());
45: userStory.setPriority(spreadsheetStory.getPriority());
46: iteration.getUserStories().add(userStory);
47: userStory.setIterationId(iteration.getId());
48: newStories.add(userStory);
49: }
50: return newStories;
51: }
52:
53: protected List readStoriesFromSpreadsheet(
54: SpreadsheetHeaderConfiguration headerConfiguration,
55: InputStream inputStream) throws IOException {
56: return new SpreadsheetStoryReader(spreadsheetStoryFactory)
57: .readStories(headerConfiguration, inputStream);
58: }
59: }
|