View Javadoc

1   package org.codehaus.mojo.dashboard.report.plugin.beans;
2   
3   /*
4    * Copyright 2007 David Vicente
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  
20  import java.util.HashSet;
21  import java.util.Hashtable;
22  import java.util.Iterator;
23  import java.util.Map;
24  import java.util.Set;
25  
26  /**
27   * 
28   * @author <a href="dvicente72@gmail.com">David Vicente</a>
29   * 
30   */
31  
32  public class DashBoardMavenProject
33  {
34      /**
35       * 
36       */
37      private String projectName;
38      /**
39       * 
40       */
41      private String artifactId;
42      
43      private String groupId;
44      
45      private String version;
46      
47      private long id;
48      
49      private Set modules = new HashSet();
50      
51      private Set reports = new HashSet();
52      
53      
54      private transient Map reportsByType = new Hashtable();
55      /**
56       * 
57       *
58       */
59      public DashBoardMavenProject()
60      {
61      }
62      /**
63       * 
64       * @param artifactId
65       */
66      public DashBoardMavenProject( String artifactId )
67      {
68          this.artifactId = artifactId;
69      }
70      /**
71       * 
72       * @param artifactId
73       */
74      public DashBoardMavenProject( String artifactId, String groupId )
75      {
76          this.artifactId = artifactId;
77          this.groupId = groupId;
78      }
79      /**
80       * 
81       * @param artifactId
82       * @param projectName
83       */
84      public DashBoardMavenProject( String artifactId, String groupId, String projectName )
85      {
86          this.artifactId = artifactId;
87          this.groupId = groupId;
88          this.projectName = projectName;
89      }
90      /**
91       * 
92       * @param artifactId
93       * @param projectName
94       * @param dateGeneration
95       */
96      public DashBoardMavenProject( String artifactId, String groupId, String projectName, String version )
97      {
98          this.artifactId = artifactId;
99          this.groupId = groupId;
100         this.projectName = projectName;
101         this.version = version;
102     }
103     /**
104      * 
105      */
106     public String getProjectName()
107     {
108         return projectName;
109     }
110     /**
111      * 
112      */
113     public void setProjectName( String projectName )
114     {
115         this.projectName = projectName;
116     }
117     /* (non-Javadoc)
118      * @see org.codehaus.mojo.dashboard.report.plugin.beans.IDashBoardReportBean#getartifactId()
119      */
120     public String getArtifactId()
121     {
122         return artifactId;
123     }
124     /* (non-Javadoc)
125      * @see org.codehaus.mojo.dashboard.report.plugin.beans.IDashBoardReportBean#setartifactId(java.lang.String)
126      */
127     public void setArtifactId( String artifactId )
128     {
129         this.artifactId = artifactId;
130     }
131     
132     public String getGroupId()
133     {
134         return groupId;
135     }
136     public void setGroupId( String groupId )
137     {
138         this.groupId = groupId;
139     }
140     public String getVersion()
141     {
142         return version;
143     }
144     public void setVersion( String version )
145     {
146         this.version = version;
147     }
148     public long getId()
149     {
150         return id;
151     }
152     public void setId( long id )
153     {
154         this.id = id;
155     }
156     public Set getModules()
157     {
158         return modules;
159     }
160     public void setModules( Set modules )
161     {
162         this.modules = modules;
163     }
164     /**
165      * 
166      * @param report
167      */
168     public void addModule( DashBoardMavenProject module )
169     {
170         this.modules.add( module );
171         fillReports( module );
172     }
173     
174     /**
175      * 
176      * @param dashboardReport
177      */
178     private void fillReports( DashBoardMavenProject module )
179     {
180 
181         if ( reports.isEmpty() )
182         {
183             Set reportsModule = module.getReports();
184             Iterator iter = reportsModule.iterator();
185             while ( iter.hasNext() )
186             {
187                 AbstractReportBean report = (AbstractReportBean) iter.next();
188                 if ( report != null )
189                 {
190                     this.reports.add( report.clone() );
191                 }
192             }
193 
194         }
195         else
196         {
197             Set reportsModule = module.getReports();
198             Iterator iter = reportsModule.iterator();
199             while ( iter.hasNext() )
200             {
201                 AbstractReportBean report = (AbstractReportBean) iter.next();
202                 boolean isMerge = false;
203                 if ( report != null )
204                 {
205                     Iterator iterInternal = this.reports.iterator();
206                     while ( iterInternal.hasNext() )
207                     {
208                         IDashBoardReportBean reportInternal = (IDashBoardReportBean) iterInternal.next();
209                         if ( reportInternal != null && reportInternal.getClass().equals( report.getClass() ) )
210                         {
211                             reportInternal.merge( report );
212                             isMerge = true;
213                         }
214                     }
215                     if ( !isMerge )
216                     {
217                         this.reports.add( report.clone() );
218                     }
219                 }
220 
221             }
222         }
223     }
224     public Set getReports()
225     {
226         return reports;
227     }
228     public void setReports( Set reports )
229     {
230         this.reports = reports;
231     }
232     
233     /**
234      * 
235      * @param report
236      */
237     public void addReport( AbstractReportBean report )
238     {
239         this.reports.add( report );
240     }
241     /**
242      * 
243      * @param classname
244      * @return
245      */
246     public AbstractReportBean getReportsByType( Class classname )
247     {
248         if ( reportsByType == null || reportsByType.isEmpty() )
249         {
250             reportsByType = new Hashtable();
251 
252             Iterator iter = this.reports.iterator();
253 
254             while ( iter.hasNext() )
255             {
256                 IDashBoardReportBean report = (IDashBoardReportBean) iter.next();
257                 if ( report != null )
258                 {
259                     reportsByType.put( report.getClass(), report );
260                 }
261             }
262         }
263         return (AbstractReportBean) reportsByType.get( classname );
264     }
265 
266 }