<commit_before>package org.jboss.windup.rules.apps.java.ip;

import java.util.HashMap;
import java.util.Map;

import org.jboss.windup.config.GraphRewrite;
import org.jboss.windup.config.WindupRuleProvider;
import org.jboss.windup.config.operation.GraphOperation;
import org.jboss.windup.config.phase.ReportGeneration;
import org.jboss.windup.config.phase.RulePhase;
import org.jboss.windup.config.query.Query;
import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.graph.model.ProjectModel;
import org.jboss.windup.graph.model.WindupConfigurationModel;
import org.jboss.windup.graph.model.WindupVertexFrame;
import org.jboss.windup.graph.service.GraphService;
import org.jboss.windup.graph.service.WindupConfigurationService;
import org.jboss.windup.reporting.model.ApplicationReportModel;
import org.jboss.windup.reporting.model.TemplateType;
import org.jboss.windup.reporting.model.WindupVertexListModel;
import org.jboss.windup.reporting.service.ApplicationReportService;
import org.jboss.windup.reporting.service.ReportService;
import org.ocpsoft.rewrite.config.Configuration;
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
import org.ocpsoft.rewrite.context.EvaluationContext;

/**
 * Finds files that contain potential static IP addresses, determined by regular expression.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class CreateStaticIPAddressReportRuleProvider extends WindupRuleProvider
{
    private static final String TITLE = "Static IP Addresses";
    public static final String TEMPLATE_REPORT = "/reports/templates/static_ip_addresses.ftl";

    @Override
    public Class<? extends RulePhase> getPhase()
    {
        return ReportGeneration.class;
    }

    @Override
    public Configuration getConfiguration(final GraphContext graphContext)
    {

        return ConfigurationBuilder
                    .begin()
                    .addRule()
                    // when a IP Location Model exists...
                    .when(Query.fromType(StaticIPLocationModel.class))
                    // perform the write of this report once (GraphOperation)...
                    .perform(new GraphOperation()
                    {

                        @Override
                        public void perform(GraphRewrite event, EvaluationContext context)
                        {
                            // configuration of current execution
                            WindupConfigurationModel configurationModel = WindupConfigurationService.getConfigurationModel(event.getGraphContext());

                            // reference to input project model
                            ProjectModel projectModel = configurationModel.getInputPath().getProjectModel();
                            createIPReport(event.getGraphContext(), projectModel);
                        }
                    });
    }

    private ApplicationReportModel createIPReport(GraphContext context, ProjectModel rootProjectModel)
    {
        ApplicationReportService applicationReportService = new ApplicationReportService(context);

        // create a reference in the graph to the static ip location report.
        ApplicationReportModel applicationReport = applicationReportService.create();

        applicationReport.setReportPriority(600);
        applicationReport.setReportName(TITLE);
        applicationReport.setTemplatePath(TEMPLATE_REPORT);
        applicationReport.setDisplayInApplicationReportIndex(true);
        applicationReport.setTemplateType(TemplateType.FREEMARKER);
        applicationReport.setProjectModel(rootProjectModel);

        // find all IPLocationModels
        GraphService<StaticIPLocationModel> ipLocationModelService = new GraphService<StaticIPLocationModel>(context, StaticIPLocationModel.class);
        Iterable<StaticIPLocationModel> results = ipLocationModelService.findAll();

        Map<String, WindupVertexFrame> relatedData = new HashMap<>(1);
        WindupVertexListModel staticIPList = new GraphService<WindupVertexListModel>(context, WindupVertexListModel.class).create();
        for (StaticIPLocationModel location : results)<commit_msg>Added in icon for static IP addresses report.<commit_after>package org.jboss.windup.rules.apps.java.ip;

import java.util.HashMap;
import java.util.Map;

import org.jboss.windup.config.GraphRewrite;
import org.jboss.windup.config.WindupRuleProvider;
import org.jboss.windup.config.operation.GraphOperation;
import org.jboss.windup.config.phase.ReportGeneration;
import org.jboss.windup.config.phase.RulePhase;
import org.jboss.windup.config.query.Query;
import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.graph.model.ProjectModel;
import org.jboss.windup.graph.model.WindupConfigurationModel;
import org.jboss.windup.graph.model.WindupVertexFrame;
import org.jboss.windup.graph.service.GraphService;
import org.jboss.windup.graph.service.WindupConfigurationService;
import org.jboss.windup.reporting.model.ApplicationReportModel;
import org.jboss.windup.reporting.model.TemplateType;
import org.jboss.windup.reporting.model.WindupVertexListModel;
import org.jboss.windup.reporting.service.ApplicationReportService;
import org.jboss.windup.reporting.service.ReportService;
import org.ocpsoft.rewrite.config.Configuration;
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
import org.ocpsoft.rewrite.context.EvaluationContext;

/**
 * Finds files that contain potential static IP addresses, determined by regular expression.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class CreateStaticIPAddressReportRuleProvider extends WindupRuleProvider
{
    private static final String TITLE = "Static IP Addresses";
    public static final String TEMPLATE_REPORT = "/reports/templates/static_ip_addresses.ftl";

    @Override
    public Class<? extends RulePhase> getPhase()
    {
        return ReportGeneration.class;
    }

    @Override
    public Configuration getConfiguration(final GraphContext graphContext)
    {

        return ConfigurationBuilder
                    .begin()
                    .addRule()
                    // when a IP Location Model exists...
                    .when(Query.fromType(StaticIPLocationModel.class))
                    // perform the write of this report once (GraphOperation)...
                    .perform(new GraphOperation()
                    {

                        @Override
                        public void perform(GraphRewrite event, EvaluationContext context)
                        {
                            // configuration of current execution
                            WindupConfigurationModel configurationModel = WindupConfigurationService.getConfigurationModel(event.getGraphContext());

                            // reference to input project model
                            ProjectModel projectModel = configurationModel.getInputPath().getProjectModel();
                            createIPReport(event.getGraphContext(), projectModel);
                        }
                    });
    }

    private ApplicationReportModel createIPReport(GraphContext context, ProjectModel rootProjectModel)
    {
        ApplicationReportService applicationReportService = new ApplicationReportService(context);

        // create a reference in the graph to the static ip location report.
        ApplicationReportModel applicationReport = applicationReportService.create();

        applicationReport.setReportPriority(600);
        applicationReport.setReportName(TITLE);
        applicationReport.setTemplatePath(TEMPLATE_REPORT);
        applicationReport.setDisplayInApplicationReportIndex(true);
        applicationReport.setReportIconClass("glyphicon glyphicon-map-marker");
        applicationReport.setTemplateType(TemplateType.FREEMARKER);
        applicationReport.setProjectModel(rootProjectModel);

        // find all IPLocationModels
        GraphService<StaticIPLocationModel> ipLocationModelService = new GraphService<StaticIPLocationModel>(context, StaticIPLocationModel.class);
        Iterable<StaticIPLocationModel> results = ipLocationModelService.findAll();

        Map<String, WindupVertexFrame> relatedData = new HashMap<>(1);
        WindupVertexListModel staticIPList = new GraphService<WindupVertexListModel>(context, WindupVertexListModel.class).create();
        for (StaticIPLocationModel location : results)
{'fraction_non_alphanumeric': 0.08001430956355832, 'fraction_numerical': 0.0009539709038874314, 'mean_word_length': 3.235858585858586, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3639516', 'n_tokens_mistral': 2143, 'n_tokens_neox': 2017, 'n_words': 398}