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.model;
20  
21  import java.util.ArrayList;
22  import java.util.Arrays;
23  import java.util.Collections;
24  import java.util.List;
25  import java.util.stream.Collectors;
26  
27  /**
28   * Abstract class with helper methods for {@link Action}.
29   */
30  public abstract class AbstractAction {
31  
32      private List<DueTo> dueTosList;
33  
34      private List<String> fixedIssueList;
35  
36      public abstract String getDueTo();
37  
38      public abstract String getDueToEmail();
39  
40      public abstract String getFixedIssuesString();
41  
42      /**
43       * Parse due-to and due-to-email attributes.
44       *
45       * @return a List of due-to person
46       */
47      public List<DueTo> getDueTos() {
48          if (dueTosList != null) {
49              return dueTosList;
50          }
51          List<DueTo> result = new ArrayList<>();
52          List<String> dueTos = new ArrayList<>();
53          List<String> dueToEmails = new ArrayList<>();
54  
55          if (getDueTo() != null) {
56              Arrays.stream(getDueTo().split(","))
57                      .map(String::trim)
58                      .filter(s -> !s.isEmpty())
59                      .forEach(dueTos::add);
60          }
61  
62          if (getDueToEmail() != null) {
63              Arrays.stream(getDueToEmail().split(",")).map(String::trim).forEach(dueToEmails::add);
64          }
65  
66          while (dueToEmails.size() < dueTos.size()) {
67              dueToEmails.add("");
68          }
69  
70          for (int i = 0; i < dueTos.size(); i++) {
71              DueTo dueTo = new DueTo();
72              dueTo.setName(dueTos.get(i));
73              dueTo.setEmail(dueToEmails.get(i));
74              result.add(dueTo);
75          }
76          dueTosList = Collections.unmodifiableList(result);
77          return dueTosList;
78      }
79  
80      /**
81       * Parse getFixedIssues attribute.
82       *
83       * @return a list of fixed issues
84       */
85      public List<String> getFixedIssues() {
86          if (fixedIssueList != null) {
87              return fixedIssueList;
88          }
89          List<String> result;
90          if (getFixedIssuesString() != null) {
91              result = Arrays.stream(getFixedIssuesString().split(","))
92                      .map(String::trim)
93                      .filter(s -> !s.isEmpty())
94                      .collect(Collectors.toList());
95          } else {
96              result = Collections.emptyList();
97          }
98  
99          fixedIssueList = Collections.unmodifiableList(result);
100         return fixedIssueList;
101     }
102 }