View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  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,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.changes.issues;
20  
21  import java.util.ArrayList;
22  import java.util.Iterator;
23  import java.util.List;
24  import java.util.Map;
25  
26  /**
27   * A helper class for generation of reports based on issues.
28   *
29   * @author Dennis Lundberg
30   * @version $Id$
31   * @since 2.4
32   */
33  public class IssuesReportHelper {
34      public static final int COLUMN_ASSIGNEE = 0;
35  
36      public static final int COLUMN_COMPONENT = 1;
37  
38      public static final int COLUMN_CREATED = 2;
39  
40      public static final int COLUMN_FIX_VERSION = 3;
41  
42      public static final int COLUMN_ID = 4;
43  
44      public static final int COLUMN_KEY = 5;
45  
46      public static final int COLUMN_PRIORITY = 6;
47  
48      public static final int COLUMN_REPORTER = 7;
49  
50      public static final int COLUMN_RESOLUTION = 8;
51  
52      public static final int COLUMN_STATUS = 9;
53  
54      public static final int COLUMN_SUMMARY = 10;
55  
56      public static final int COLUMN_TYPE = 11;
57  
58      public static final int COLUMN_UPDATED = 12;
59  
60      public static final int COLUMN_VERSION = 13;
61  
62      /**
63       * Get a list of id:s for the columns that are to be included in the report.
64       *
65       * @param columnNames The names of the columns
66       * @param allColumns A mapping from column name to column id
67       * @return A List of column id:s
68       */
69      public static List<Integer> getColumnIds(String columnNames, Map<String, Integer> allColumns) {
70          List<Integer> columnIds = new ArrayList<>();
71          String[] columnNamesArray = columnNames.split(",");
72  
73          // Loop through the names of the columns, to validate each of them and add their id to the list
74          for (String aColumnNamesArray : columnNamesArray) {
75              String columnName = aColumnNamesArray.trim();
76              if (allColumns.containsKey(columnName)) {
77                  columnIds.add(allColumns.get(columnName));
78              }
79          }
80          return columnIds;
81      }
82  
83      /**
84       * Print a list of values separated by commas.
85       *
86       * @param values The values to print
87       * @return A nicely formatted string of values.
88       */
89      public static String printValues(List<String> values) {
90          StringBuilder sb = new StringBuilder();
91          if (values != null) {
92              Iterator<String> iterator = values.iterator();
93              while (iterator.hasNext()) {
94                  String value = iterator.next();
95                  sb.append(value);
96                  if (iterator.hasNext()) {
97                      sb.append(", ");
98                  }
99              }
100         }
101         return sb.toString();
102     }
103 }