001 package org.hackystat.projectbrowser.page.dailyprojectdata.issue; 002 003 import java.io.Serializable; 004 import java.util.ArrayList; 005 import java.util.Arrays; 006 import java.util.HashMap; 007 import java.util.List; 008 import java.util.Map; 009 import java.util.Set; 010 import java.util.TreeSet; 011 import java.util.logging.Logger; 012 013 import org.hackystat.dailyprojectdata.client.DailyProjectDataClient; 014 import org.hackystat.dailyprojectdata.client.DailyProjectDataClientException; 015 import org.hackystat.dailyprojectdata.resource.issue.jaxb.IssueDailyProjectData; 016 import org.hackystat.projectbrowser.ProjectBrowserApplication; 017 import org.hackystat.projectbrowser.ProjectBrowserSession; 018 import org.hackystat.projectbrowser.page.dailyprojectdata.DailyProjectDataSession; 019 import org.hackystat.sensorbase.resource.projects.jaxb.Project; 020 import org.hackystat.utilities.tstamp.Tstamp; 021 022 /** 023 * The data model for Issue DPD display. This data model accommodates multiple Projects. 024 * For each project, the data model indicates the members in the Project along with 025 * the issue information for the given day. 026 * @author Philip Johnson 027 * 028 */ 029 public class IssueDataModel implements Serializable { 030 031 /** Support serialization. */ 032 private static final long serialVersionUID = 1L; 033 034 /** Holds the commit data, organized by Project.*/ 035 private Map<Project, IssueDpdData> issueDataMap = new HashMap<Project, IssueDpdData>(); 036 037 private final Set<String> openIssueStatus = new TreeSet<String>(); 038 private final Set<String> closedIssueStatus = new TreeSet<String>(); 039 040 private List<String> openIssueStatusValue = 041 Arrays.asList(new String[]{"New", "Accepted", "Started"}); 042 /** 043 * The default CommitDataModel, which contains no commit information. 044 */ 045 public IssueDataModel() { 046 // Do nothing 047 } 048 049 /** 050 * Updates this data model to reflect the build information associated with the selected 051 * projects. 052 */ 053 public void update() { 054 this.clear(); 055 DailyProjectDataClient dpdClient = ProjectBrowserSession.get().getDailyProjectDataClient(); 056 DailyProjectDataSession session = ProjectBrowserSession.get().getDailyProjectDataSession(); 057 List<Project> projects = session.getSelectedProjects(); 058 059 for (Project project : projects) { 060 Logger logger = ((ProjectBrowserApplication)ProjectBrowserApplication.get()).getLogger(); 061 logger.fine("Getting Issue DPD for project: " + project.getName()); 062 try { 063 IssueDailyProjectData issueDpd = dpdClient.getIssue(project.getOwner(), 064 project.getName(), Tstamp.makeTimestamp(session.getDate().getTime())); 065 logger.fine("Finished getting Issue DPD for project: " + project.getName()); 066 IssueDpdData data = new IssueDpdData(project, issueDpd); 067 this.issueDataMap.put(project, data); 068 for (String status : data.getIssueStatusCount().keySet()) { 069 if (openIssueStatusValue.contains(status)) { 070 openIssueStatus.add(status); 071 } 072 else { 073 closedIssueStatus.add(status); 074 } 075 } 076 } 077 078 catch (DailyProjectDataClientException e) { 079 session.setFeedback("Exception getting Issue DPD for project " + project + ": " + 080 e.getMessage()); 081 } 082 } 083 } 084 085 086 /** 087 * Sets this model to its empty state. 088 */ 089 public void clear() { 090 this.issueDataMap.clear(); 091 } 092 093 094 /** 095 * Returns true if this data model contains no information. 096 * Used to figure out if the associated panel should be visible. 097 * @return True if the data model is empty. 098 */ 099 public boolean isEmpty() { 100 return this.issueDataMap.isEmpty(); 101 } 102 103 /** 104 * Return the IssueData instance associated with the specified project. 105 * Creates and returns a new IssueData instance if one is not yet present. 106 * @param project The project. 107 * @return The IssueData instance for this project. 108 */ 109 public IssueDpdData getIssueData(Project project) { 110 if (!issueDataMap.containsKey(project)) { 111 issueDataMap.put(project, new IssueDpdData(project)); 112 } 113 return issueDataMap.get(project); 114 } 115 116 /** 117 * Returns the list of IssueData instances, needed for markup. 118 * @return The list of IssueData instances. 119 */ 120 public List<IssueDpdData> getIssueDataList() { 121 return new ArrayList<IssueDpdData>(this.issueDataMap.values()); 122 } 123 124 /** 125 * @return the openIssueStatus 126 */ 127 public Set<String> getOpenIssueStatus() { 128 return openIssueStatus; 129 } 130 131 /** 132 * @return the closedIssueStatus 133 */ 134 public Set<String> getClosedIssueStatus() { 135 return closedIssueStatus; 136 } 137 138 }