ReportDefinition.java

/*
** Module   : ReportDefinition.java
** Abstract : stores the data for a report definition
**
** Copyright (c) 2013-2017, Golden Code Development Corporation.
**
** -#- -I- --Date-- --------------------------------Description---------------------------------
** 001 GES 20130201 Created first version.
** 002 GES 20160311 Added support level expression.
** 003 ECF 20170505 Modified for use in analytics web application.
*/
/*
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
** published by the Free Software Foundation, either version 3 of the
** License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU Affero General Public License for more details.
**
** You may find a copy of the GNU Affero GPL version 3 at the following
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
** 
** Additional terms under GNU Affero GPL version 3 section 7:
** 
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
**   terms apply to the works covered under the License.  These additional terms
**   are non-permissive additional terms allowed under Section 7 of the GNU
**   Affero GPL version 3 and may not be removed by you.
** 
**   0. Attribution Requirement.
** 
**     You must preserve all legal notices or author attributions in the covered
**     work or Appropriate Legal Notices displayed by works containing the covered
**     work.  You may not remove from the covered work any author or developer
**     credit already included within the covered work.
** 
**   1. No License To Use Trademarks.
** 
**     This license does not grant any license or rights to use the trademarks
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
**     of Golden Code Development Corporation. You are not authorized to use the
**     name Golden Code, FWD, or the names of any author or contributor, for
**     publicity purposes without written authorization.
** 
**   2. No Misrepresentation of Affiliation.
** 
**     You may not represent yourself as Golden Code Development Corporation or FWD.
** 
**     You may not represent yourself for publicity purposes as associated with
**     Golden Code Development Corporation, FWD, or any author or contributor to
**     the covered work, without written authorization.
** 
**   3. No Misrepresentation of Source or Origin.
** 
**     You may not represent the covered work as solely your work.  All modified
**     versions of the covered work must be marked in a reasonable way to make it
**     clear that the modified work is not originating from Golden Code Development
**     Corporation or FWD.  All modified versions must contain the notices of
**     attribution required in this license.
*/

package com.goldencode.p2j.report;

import java.util.*;
import com.fasterxml.jackson.annotation.*;

/**
 * A report definition which includes all report-specific details needed
 * by either the rule-set (for matching and storing match text) or for the
 * proper configuration of the worker that generates the report.
 */
public class ReportDefinition
{
   /** Report ID. */
   public long id = -1L;
   
   /** Summary report title. */
   public String title = null;
   
   /** All category names with which the currently running report is tagged. */
   public Set<String> tags = null;
   
   /** Expression which defines a match when it evaluates <code>true</code>. */
   public String condition = null;
   
   /** Description of the condition expression. */
   public String conditionDescr = null;
   
   /** Is this a user-defined report? */
   public boolean user = false;
   
   /** Type of text output for each match. */
   public String dumpType = null;
   
   /** Expression for generating custom text output for each match. */
   public String dumpExpr = null;
   
   /** 0 to dump the current matched node, otherwise the ancestor level. */
   public int dumpLevel = 0;
   
   /** Expression for generating custom text for the statistic name. */
   public String multiplexExpr = null;
   
   /** Expression for calculating the support level for the statistic name. */
   public String supportLvlExpr = null;
   
   /** Stores statistics based on a key of a short name. */
   @JsonIgnore
   public Map<String, Long> cats2Id = new HashMap<>();
   
   /**
    * Obtains the report ID. 
    *
    * @return   The report ID.
    */
   public long getId()
   {
      return id;
   }
   
   /**
    * Obtains the title for the summary report.
    *
    * @return   The title.
    */
   public String getTitle()
   {
      return title;
   }
   
   /**
    * Obtains the set of all category names with which this report is tagged.
    *
    * @return   The tag names.
    */
   public Set<String> getTags()
   {
      return tags;
   }
   
   /**
    * Obtains the condition (an expression) used for detecting a match.
    *
    * @return   The condition.
    */
   public String getCondition()
   {
      return condition;
   }
   
   /**
    * Obtains the condition description.
    *
    * @return   The condition description.
    */
   public String getConditionDescr()
   {
      return conditionDescr;
   }
   
   /**
    * Set the condition description.
    *
    * @param    conditionDescr
    *           The new condition description.
    */
   public void setConditionDescr(String conditionDescr)
   {
      this.conditionDescr = conditionDescr;
   }
   
   /**
    * Obtains the mechanism by which to dump the match text.
    *
    * @return   The dump type.
    */
   public String getDumpType()
   {
      return dumpType;
   }
   
   /**
    * Obtains any custom dump expression with which to dump the match text.
    *
    * @return   The dump expression.
    */
   public String getDumpExpr()
   {
      return dumpExpr;
   }
   
   /**
    * Obtains the ancestor level at which to dump the match text.
    *
    * @return   The ancestor level.
    */
   public int getDumpLevel()
   {
      return dumpLevel;
   }
   
   /**
    * Obtains the multiplex expression. 
    *
    * @return   The multiplex expression.
    */
   public String getMultiplexExpr()
   {
      return multiplexExpr;
   }
   
   /**
    * Obtains the support level expression. 
    *
    * @return   The support level expression.
    */
   public String getSupportLvlExpr()
   {
      return supportLvlExpr;
   }
   
   /**
    * Associate the given list of comma-separated category names with the current report. 
    *
    * @param    list
    *           The comma-separated list of categories with which to tag the current report.
    */
   public void setTagList(String list)
   {
      if (list == null)
      {
         return;
      }
      
      // split up the list
      String[] array = list.split(",", -1);
      
      for (int i = 0; i < array.length; i++)
      {
         String trimmed;
         if (array[i] != null && (trimmed = array[i].trim()).length() > 0)
         {
            if (tags == null)
            {
               tags = new LinkedHashSet<>();
            }
            
            tags.add(trimmed);
         }
      }
   }
}