View Javadoc

1   /*
2    * Copyright 2008-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.maven.issues.bugzilla;
17  
18  import java.util.List;
19  
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
23  import org.eclipse.mylyn.tasks.core.data.TaskData;
24  
25  import de.smartics.maven.issues.RendererConfig;
26  
27  /**
28   * Selects the issues to their categories.
29   *
30   * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a>
31   * @version $Revision:591 $
32   */
33  public class SimpleSectioner implements Sectioner<Sections>
34  {
35    // ********************************* Fields *********************************
36  
37    // --- constants ------------------------------------------------------------
38  
39    /**
40     * Reference to the logger for this class.
41     */
42    private static final Log LOG = LogFactory.getLog(SimpleSectioner.class);
43  
44    // --- members --------------------------------------------------------------
45  
46    /**
47     * The configuration to control the processing of the sections.
48     */
49    private final RendererConfig config;
50  
51    /**
52     * The issues to be appointed to the different sections.
53     */
54    private final List<TaskData> issues;
55  
56    /**
57     * The map stores the bugs in the order read from the issue management system
58     * in different sections.
59     */
60    private final Sections sections;
61  
62    // ****************************** Initializer *******************************
63  
64    // ****************************** Constructors ******************************
65  
66    /**
67     * Default constructor.
68     *
69     * @param config the configuration to control the processing of the sections.
70     * @param issues the issues to be appointed to the different sections.
71     */
72    public SimpleSectioner(final RendererConfig config,
73        final List<TaskData> issues)
74    {
75      this.config = config;
76      this.issues = issues;
77      this.sections = new Sections(config.getSections());
78    }
79  
80    // ****************************** Inner Classes *****************************
81  
82    // ********************************* Methods ********************************
83  
84    // --- init -----------------------------------------------------------------
85  
86    // --- get&set --------------------------------------------------------------
87  
88    // --- business -------------------------------------------------------------
89  
90    /**
91     * Distributes the issues to the configured sections. Issues not defining the
92     * property referenced by {@link RendererConfig#getSectionType()} are skipped
93     * as well as issues that provide a value for that property that is not part
94     * of {@link RendererConfig#getSections()}.
95     *
96     * @return the map of sections.
97     */
98    public Sections run()
99    {
100     final String sectionAttributeKey = config.getSectionType();
101 
102     for (TaskData issue : issues)
103     {
104       final TaskAttribute attribute =
105           issue.getRoot().getAttribute(sectionAttributeKey);
106       if (attribute != null)
107       {
108         final String section = attribute.getValue();
109         final boolean added = sections.addToSection(section, issue);
110         if (!added && LOG.isDebugEnabled())
111         {
112           LOG.debug("Issue #" + issue.getTaskId() + " defines attribute '"
113                     + sectionAttributeKey + "' as '" + section
114                     + "' which is not mapped to a column. Skipped.");
115         }
116       }
117       else
118       {
119         if (LOG.isDebugEnabled())
120         {
121           LOG.debug("Issue #" + issue.getTaskId()
122                     + " does not define attribute '" + sectionAttributeKey
123                     + "'. Skipped.");
124         }
125       }
126     }
127 
128     return sections;
129   }
130 
131   // --- object basics --------------------------------------------------------
132 
133 }