1 /* 2 * Copyright 2008-2010 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 17 package de.smartics.maven.issues.bugzilla; 18 19 import java.util.List; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 23 import org.eclipse.mylyn.tasks.core.data.TaskAttribute; 24 import org.eclipse.mylyn.tasks.core.data.TaskData; 25 26 import de.smartics.maven.issues.RendererConfig; 27 28 /** 29 * Selects the issues to their categories. 30 * 31 * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a> 32 * @version $Revision:591 $ 33 */ 34 public class SimpleSectioner implements Sectioner<Sections> 35 { 36 // ********************************* Fields ********************************* 37 38 // --- constants ------------------------------------------------------------ 39 40 /** 41 * Reference to the logger for this class. 42 */ 43 private static final Log LOG = LogFactory.getLog(SimpleSectioner.class); 44 45 // --- members -------------------------------------------------------------- 46 47 /** 48 * The configuration to control the processing of the sections. 49 */ 50 private final RendererConfig config; 51 52 /** 53 * The issues to be appointed to the different sections. 54 */ 55 private final List<TaskData> issues; 56 57 /** 58 * The map stores the bugs in the order read from the issue management system 59 * in different sections. 60 */ 61 private final Sections sections; 62 63 // ****************************** Initializer ******************************* 64 65 // ****************************** Constructors ****************************** 66 67 /** 68 * Default constructor. 69 * 70 * @param config the configuration to control the processing of the sections. 71 * @param issues the issues to be appointed to the different sections. 72 */ 73 public SimpleSectioner(final RendererConfig config, 74 final List<TaskData> issues) 75 { 76 this.config = config; 77 this.issues = issues; 78 this.sections = new Sections(config.getSections()); 79 } 80 81 // ****************************** Inner Classes ***************************** 82 83 // ********************************* Methods ******************************** 84 85 // --- init ----------------------------------------------------------------- 86 87 // --- get&set -------------------------------------------------------------- 88 89 // --- business ------------------------------------------------------------- 90 91 /** 92 * Distributes the issues to the configured sections. Issues not defining the 93 * property referenced by {@link RendererConfig#getSectionType()} are skipped 94 * as well as issues that provide a value for that property that is not part 95 * of {@link RendererConfig#getSections()}. 96 * 97 * @return the map of sections. 98 */ 99 public Sections run() 100 { 101 final String sectionAttributeKey = config.getSectionType(); 102 103 for (TaskData issue : issues) 104 { 105 final TaskAttribute attribute = 106 issue.getRoot().getAttribute(sectionAttributeKey); 107 if (attribute != null) 108 { 109 final String section = attribute.getValue(); 110 final boolean added = sections.addToSection(section, issue); 111 if (!added && LOG.isDebugEnabled()) 112 { 113 LOG.debug("Issue #" + issue.getTaskId() + " defines attribute '" 114 + sectionAttributeKey + "' as '" + section 115 + "' which is not mapped to a column. Skipped."); 116 } 117 } 118 else 119 { 120 if (LOG.isDebugEnabled()) 121 { 122 LOG.debug("Issue #" + issue.getTaskId() 123 + " does not define attribute '" + sectionAttributeKey 124 + "'. Skipped."); 125 } 126 } 127 } 128 129 return sections; 130 } 131 132 // --- object basics -------------------------------------------------------- 133 134 }