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  
20  package org.apache.rat.report.claim.impl;
21  
22  import org.apache.rat.api.Document;
23  import org.apache.rat.api.MetaData;
24  import org.apache.rat.api.RatException;
25  import org.apache.rat.license.ILicense;
26  import org.apache.rat.license.ILicenseFamily;
27  import org.apache.rat.report.claim.ClaimStatistic;
28  import org.apache.rat.report.claim.ClaimStatistic.Counter;
29  
30  /**
31   * The aggregator is used to create a numerical statistic of claims.
32   */
33  public class ClaimAggregator extends AbstractClaimReporter {
34      private final ClaimStatistic statistic;
35  
36      /**
37       * Constructor.
38       * @param statistic The statistic to store the statistics in.
39       */
40      public ClaimAggregator(ClaimStatistic statistic) {
41          this.statistic = statistic;
42      }
43  
44      @Override
45      protected void handleDocumentCategoryClaim(Document.Type documentType) {
46          statistic.incCounter(documentType, 1);
47      }
48  
49      @Override
50      protected void handleApprovedLicenseClaim(MetaData metadata) {
51          statistic.incCounter(ClaimStatistic.Counter.APPROVED, (int) metadata.approvedLicenses().count());
52          statistic.incCounter(ClaimStatistic.Counter.UNAPPROVED,  (int) metadata.unapprovedLicenses().count());
53      }
54  
55      @Override
56      protected void handleLicenseClaim(ILicense license) {
57          String category = license.getLicenseFamily().getFamilyCategory();
58          if (category.equals(ILicenseFamily.GENTERATED_CATEGORY)) {
59              statistic.incCounter(Counter.GENERATED, 1);
60          } else if (category.equals(ILicenseFamily.UNKNOWN_CATEGORY)) {
61              statistic.incCounter(Counter.UNKNOWN, 1);
62          }
63          statistic.incLicenseCategoryCount(category, 1);
64          statistic.incLicenseFamilyNameCount(license.getFamilyName(), 1);
65      }
66  
67      @Override
68      public void endReport() throws RatException {
69          super.endReport();
70      }
71  }