001 package org.hackystat.projectbrowser.page.sensordata; 002 003 import java.util.ArrayList; 004 import java.util.Iterator; 005 import java.util.List; 006 import java.util.Set; 007 import java.util.TreeSet; 008 009 import org.apache.wicket.model.IModel; 010 import org.apache.wicket.model.Model; 011 import org.hackystat.sensorbase.resource.projects.jaxb.MultiDayProjectSummary; 012 import org.hackystat.sensorbase.resource.projects.jaxb.Project; 013 import org.hackystat.sensorbase.resource.projects.jaxb.ProjectSummary; 014 import org.hackystat.sensorbase.resource.projects.jaxb.SensorDataSummary; 015 import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider; 016 017 /** 018 * Provides a model that summarizes for each day in a month, how many sensor data instances 019 * of a given type were associated with that day. 020 * @author Philip Johnson 021 */ 022 public class SensorDataTableModel extends SortableDataProvider { 023 024 /** Required for serialization. */ 025 private static final long serialVersionUID = 1L; 026 private List<SensorDataTableRowModel> rows = new ArrayList<SensorDataTableRowModel>(); 027 private MultiDayProjectSummary multiDaySummary; 028 029 /** 030 * Default constructor. 031 */ 032 public SensorDataTableModel() { 033 // do nothing. 034 } 035 036 /** 037 * Used to set up the model. 038 * @param multiDaySummary The multidayprojrectsummary instance. 039 * @param project The project. 040 */ 041 public void setModel(MultiDayProjectSummary multiDaySummary, Project project) { 042 this.multiDaySummary = multiDaySummary; 043 this.rows.clear(); 044 for (ProjectSummary summary : multiDaySummary.getProjectSummary()) { 045 rows.add(new SensorDataTableRowModel(summary)); 046 } 047 } 048 049 /** 050 * Gets a set of strings containing the name of all Sdts sent during this month. 051 * @return The set of all SDT names. 052 */ 053 public Set<String> getSdtSet() { 054 Set<String> sdts = new TreeSet<String>(); 055 if (this.multiDaySummary == null) { 056 return sdts; 057 } 058 for (ProjectSummary projectSummary : this.multiDaySummary.getProjectSummary()) { 059 for (SensorDataSummary summary : 060 projectSummary.getSensorDataSummaries().getSensorDataSummary()) { 061 String sdt = summary.getSensorDataType(); 062 if ((sdt == null) || ("".equals(sdt))) { 063 sdt = "Unspecified"; 064 } 065 sdts.add(sdt); 066 } 067 } 068 return sdts; 069 } 070 071 072 /** 073 * Returns an iterator over the rows in this model. 074 * @param first The first element in the iterator. (Ignored) 075 * @param count The total number of instances. (Ignored) 076 * @return The iterator. 077 */ 078 @SuppressWarnings("unchecked") 079 public Iterator iterator(int first, int count) { 080 return rows.iterator(); 081 } 082 083 /** 084 * The model associated with a row in this table. 085 * @param obj The SensorDataTableRowModel. 086 * @return The model. 087 */ 088 public IModel model(Object obj) { 089 return new Model((SensorDataTableRowModel) obj); 090 } 091 092 /** 093 * The total number of rows in this table. 094 * @return The total number of rows. 095 */ 096 public int size() { 097 return rows.size(); 098 } 099 100 /** 101 * Does nothing at the moment. 102 */ 103 @Override 104 public void detach() { 105 // does nothing. 106 } 107 108 /** 109 * True if this model contains no data. 110 * @return True if this model has no data. 111 */ 112 public boolean isEmpty() { 113 return this.rows.size() == 0; 114 } 115 116 }