<commit_before>## OpenXPKI::Server::API::Profile.pm 
##
## Written 2013 by <NAME> for the OpenXPKI project
## Copyright (C) 2005-2013 by The OpenXPKI Project
package OpenXPKI::Server::API::Profile;

use strict;
use warnings;
use utf8;
use English;

use Class::Std;

use Data::Dumper;

#use Regexp::Common;

use OpenXPKI::Debug;
use OpenXPKI::Exception;
use OpenXPKI::DateTime;
use OpenXPKI::Server::Context qw( CTX );
use OpenXPKI::i18n qw( set_language );
use Digest::SHA1 qw( sha1_base64 );
use DateTime;

use Template;

use Workflow;

sub START {
    # somebody tried to instantiate us, but we are just an
    # utility class with static methods
    OpenXPKI::Exception->throw(
        message => 'I18N_OPENXPKI_SERVER_API_SUBCLASSES_CAN_NOT_BE_INSTANTIATED',
    );
}
# API: simple retrieval functions
 

sub __fetch_input_element_definitions {
    
    my $self = shift;   
    my $profile = shift;
    my $input_names = shift;  
    my $csr_info = shift;
    
    my $config = CTX('config');
    
    my @definitions;
            
    foreach my $input_name (@{$input_names}) {
        my ($input, $input_path); 
        ##! 32: "Input $input_name"
        # each input name can have a local or/and a global definiton, 
        # we need to probe where to find it 
        foreach my $path ("profile.$profile.template.$input_name", "profile.template.$input_name") {                            
            $input = $config->get_hash($path);            
            if ($input) {
                ##! 64: "Element found at $path"
                $input_path = $path;
                last;                        
            }
        }
        
        if (!$input) {
            OpenXPKI::Exception->throw (
                message => "I18N_OPENXPKI_SERVER_API_DEFAULT_NO_SUCH_INPUT_ELEMENT_DEFINED",
                params => {
                    'input' => $input_name,
                    'profile' => $profile,
                }
            );
        }

        # Uppercase the keys and push it to the array
        my %ucinput = map { uc $_ => $input->{$_} } keys %{$input};
        if (defined $csr_info) {

            my $source = $input->{'source'};
            ##! 16: 'source: ' . $source
            # if source is defined, use it with $csr_info ...
            if (defined $source) {
                my ($part, $regex) = ($source =~ m{([^:]+) : (.+)}xms);
                ##! 16: 'part: ' . $part<commit_msg>Allow autogeneration of profile input fields based on a default template<commit_after>## OpenXPKI::Server::API::Profile.pm 
##
## Written 2013 by <NAME> for the OpenXPKI project
## Copyright (C) 2005-2013 by The OpenXPKI Project
package OpenXPKI::Server::API::Profile;

use strict;
use warnings;
use utf8;
use English;

use Class::Std;

use Data::Dumper;

#use Regexp::Common;

use OpenXPKI::Debug;
use OpenXPKI::Exception;
use OpenXPKI::DateTime;
use OpenXPKI::Server::Context qw( CTX );
use OpenXPKI::i18n qw( set_language );
use Digest::SHA1 qw( sha1_base64 );
use DateTime;

use Template;

use Workflow;

sub START {
    # somebody tried to instantiate us, but we are just an
    # utility class with static methods
    OpenXPKI::Exception->throw(
        message => 'I18N_OPENXPKI_SERVER_API_SUBCLASSES_CAN_NOT_BE_INSTANTIATED',
    );
}
# API: simple retrieval functions
 

sub __fetch_input_element_definitions {
    
    my $self = shift;   
    my $profile = shift;
    my $input_names = shift;  
    my $csr_info = shift;
    
    my $config = CTX('config');
    
    my @definitions;
            
    foreach my $input_name (@{$input_names}) {
        my ($input, $input_path); 
        ##! 32: "Input $input_name"
        # each input name can have a local or/and a global definiton, 
        # we need to probe where to find it 
        foreach my $path ("profile.$profile.template.$input_name", "profile.template.$input_name") {                            
            $input = $config->get_hash($path);            
            if ($input) {
                ##! 64: "Element found at $path"
                $input_path = $path;
                last;                        
            }
        }
        
        if (!$input) {
            # check if there is a default section (only look in the profile!)
            $input = $config->get_hash(['profile', $profile, 'template' , '_default' ]);                
            OpenXPKI::Exception->throw (
                message => "I18N_OPENXPKI_SERVER_API_DEFAULT_NO_SUCH_INPUT_ELEMENT_DEFINED",
                params => {
                    'input' => $input_name,
                    'profile' => $profile,
                }
            ) unless($input);
                        
            # got a default item, create field using default 
            # set id and label to name
            $input->{id} = $input_name;
            $input->{label} = $input_name;
             
        }

        # Uppercase the keys and push it to the array
        my %ucinput = map { uc $_ => $input->{$_} } keys %{$input};
        if (defined $csr_info) {

            my $source = $input->{'source'};
            ##! 16: 'source: ' . $source
            # if source is defined, use it with $csr_info ...
            if (defined $source) {
                my ($part, $regex) = ($source =~ m{([^:]+) : (.+)}xms);
                ##! 16: 'part: ' . $part
{'fraction_non_alphanumeric': 0.12251779692768827, 'fraction_numerical': 0.011614837017609592, 'mean_word_length': 1.9302963776070252, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 30, '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': '965351', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1607, 'n_words': 447}