<commit_before><?php


/**
 * @propoerty Arpgen $arpgen
 */

/**
 * Class Attributepolicy2
 */
class Attributepolicy2 extends MY_Controller
{

    public function __construct()
    {
        parent::__construct();
    }


    private function checkaccess()
    {

    }

    public function show($idpid = null)
    {
        if (!ctype_digit($idpid)) {
            show_404();
        }
        if (!$this->j_auth->logged_in()) {
            redirect('auth/login', 'location');
        }

        /**
         * @var $ent models\Provider
         */
        $ent = $this->em->getRepository('models\Provider')->findOneBy(array('id' => $idpid));
        if ($ent === null) {
            show_404();
        }
        $this->load->library('zacl');
        $hasWriteAccess = $this->zacl->check_acl($idpid, 'write', 'entity', '');
        if (!$hasWriteAccess) {
            show_error('Denied', 401);
        }
        $this->load->library('arpgen');
        $data['attrdefs'] = $this->arpgen->getAttrDefs();
        $data['arpglobal'] = $this->arpgen->genGlobal($ent);
        $data['arpsupport'] = $this->arpgen->getSupportAttributes($ent);
        $data['idpid'] = $ent->getId();
        $data['content_view'] = 'manage/attributepolicy2_view';
        $this->load->view('page', $data);
    }

    public function getsupported($idpid = null)
    {
        if (!ctype_digit($idpid) || !$this->input->is_ajax_request() || !$this->j_auth->logged_in()) {
            return $this->output->set_status_header(403)->set_output('Access Denied');
        }


        /**
         * @var $ent models\Provider
         */
        $ent = $this->em->getRepository('models\Provider')->findOneBy(array('id' => $idpid));
        if ($ent === null) {
            return $this->output->set_status_header(404)->set_output('Not found');
        }
        $this->load->library('zacl');
        $hasWriteAccess = $this->zacl->check_acl($idpid, 'write', 'entity', '');
        if (!$hasWriteAccess) {
            return $this->output->set_status_header(403)->set_output('Access Denied');
        }

        $this->load->library('arpgen');


        $result['type'] = 'supported';
        $result['definitions']['columns'] = array(lang('attrname'), lang('dfltarpcolname'), lang('rr_action'));
        $result['data']['support'] = $this->arpgen->getSupportAttributes($ent);
        $result['data']['global'] = $this->arpgen->genGlobal($ent);
        $result['definitions']['attrs'] = $this->arpgen->getAttrDefs();
        $result['definitions']['policy'] = array('0' => 'never permit', '1' => 'only when required', '2' => 'when required or desired', '100' => 'unset', '1000' => 'unsupported');

        return $this->output->set_content_type('application/json')->set_output(json_encode($result));

    }
    public function getfedattrs($idpid = null)
    {
        if (!ctype_digit($idpid) || !$this->input->is_ajax_request() || !$this->j_auth->logged_in()) {
            return $this->output->set_status_header(403)->set_output('Access Denied');
        }


        /**
         * @var $ent models\Provider
         */
        $ent = $this->em->getRepository('models\Provider')->findOneBy(array('id' => $idpid));
        if ($ent === null) {
            return $this->output->set_status_header(404)->set_output('Not found');
        }
        $this->load->library('zacl');
        $hasWriteAccess = $this->zacl->check_acl($idpid, 'write', 'entity', '');
        if (!$hasWriteAccess) {
            return $this->output->set_status_header(403)->set_output('Access Denied');
        }
        $this->load->library('arpgen');
        $result['type'] = 'federation';

       // $result['policydefs'] = $this->arpgen->genPolicyDefs($ent);

        $result['definitions']['columns'] = array(lang('attrname'),'policy','reqstatus', lang('rr_action'));
        $result['data']['support'] = $this->arpgen->getSupportAttributes($ent);
        $result['data']['global'] = $this->arpgen->genGlobal($ent);

        /**
         * @var $allFeds models\Federation[]
         */
        $allFeds = $this->em->getRepository('models\Federation')->findAll();
        $allFederations = array();
        foreach ( $allFeds as $fed) {
            $allFederations[$fed->getId()] = $fed->getName();

        }
        /**
         * @var $fedpolicies models\AttributeReleasePolicy[]
         */
        $fedpolicies = $this->em->getRepository('models\AttributeReleasePolicy')->findBy(
            array(
                'idp' => $ent,
                'type' => array('fed')
            )
        );
        $fedpoliciesByRequester = array();
        foreach($fedpolicies as $fedpolicy)
        {
            $requester = $fedpolicy->getRequester();
            if(!array_key_exists($requester,$allFederations))
            {
                log_message('warning',__METHOD__ .' found policy for federation which doesn not exist anymore - policy will be removed automaticaly');
                $this->em->remove($fedpolicy);
                continue;
            }
            $fedpoliciesByRequester[$fedpolicy->getRequester()][$fedpolicy->getAttribute()->getId()] = $fedpolicy->getPolicy();
        }



        $result['definitions']['feds'] = $allFederations;

        $result['data']['fedpols'] = $fedpoliciesByRequester;

        $activeFederation = $this->arpgen->getActiveFederations($ent);

        $result['data']['activefeds'] = $activeFederation;


        $this->em->flush();
        return $this->output->set_content_type('application/json')->set_output(json_encode($result));
    }

<commit_msg>arpgen ui<commit_after><?php


/**
 * @propoerty Arpgen $arpgen
 */

/**
 * Class Attributepolicy2
 */
class Attributepolicy2 extends MY_Controller
{

    public function __construct()
    {
        parent::__construct();
    }


    private function checkaccess()
    {

    }

    public function show($idpid = null)
    {
        if (!ctype_digit($idpid)) {
            show_404();
        }
        if (!$this->j_auth->logged_in()) {
            redirect('auth/login', 'location');
        }

        /**
         * @var $ent models\Provider
         */
        $ent = $this->em->getRepository('models\Provider')->findOneBy(array('id' => $idpid));
        if ($ent === null) {
            show_404();
        }
        $this->load->library('zacl');
        $hasWriteAccess = $this->zacl->check_acl($idpid, 'write', 'entity', '');
        if (!$hasWriteAccess) {
            show_error('Denied', 401);
        }
        $this->load->library('arpgen');
        $data['attrdefs'] = $this->arpgen->getAttrDefs();
        $data['arpglobal'] = $this->arpgen->genGlobal($ent);
        $data['arpsupport'] = $this->arpgen->getSupportAttributes($ent);
        $data['idpid'] = $ent->getId();
        $data['content_view'] = 'manage/attributepolicy2_view';
        $this->load->view('page', $data);
    }

    public function getsupported($idpid = null)
    {
        if (!ctype_digit($idpid) || !$this->input->is_ajax_request() || !$this->j_auth->logged_in()) {
            return $this->output->set_status_header(403)->set_output('Access Denied');
        }


        /**
         * @var $ent models\Provider
         */
        $ent = $this->em->getRepository('models\Provider')->findOneBy(array('id' => $idpid));
        if ($ent === null) {
            return $this->output->set_status_header(404)->set_output('Not found');
        }
        $this->load->library('zacl');
        $hasWriteAccess = $this->zacl->check_acl($idpid, 'write', 'entity', '');
        if (!$hasWriteAccess) {
            return $this->output->set_status_header(403)->set_output('Access Denied');
        }

        $this->load->library('arpgen');


        $result['type'] = 'supported';
        $result['definitions']['columns'] = array(lang('attrname'), lang('dfltarpcolname'), lang('rr_action'));
        $result['data']['support'] = $this->arpgen->getSupportAttributes($ent);
        $result['data']['global'] = $this->arpgen->genGlobal($ent);
        $result['definitions']['attrs'] = $this->arpgen->getAttrDefs();
        $result['definitions']['policy'] = array('0' => 'never permit', '1' => 'only when required', '2' => 'when required or desired', '100' => 'unset', '1000' => 'unsupported');

        return $this->output->set_content_type('application/json')->set_output(json_encode($result));

    }
    public function getfedattrs($idpid = null)
    {
        if (!ctype_digit($idpid) || !$this->input->is_ajax_request() || !$this->j_auth->logged_in()) {
            return $this->output->set_status_header(403)->set_output('Access Denied');
        }


        /**
         * @var $ent models\Provider
         */
        $ent = $this->em->getRepository('models\Provider')->findOneBy(array('id' => $idpid));
        if ($ent === null) {
            return $this->output->set_status_header(404)->set_output('Not found');
        }
        $this->load->library('zacl');
        $hasWriteAccess = $this->zacl->check_acl($idpid, 'write', 'entity', '');
        if (!$hasWriteAccess) {
            return $this->output->set_status_header(403)->set_output('Access Denied');
        }
        $this->load->library('arpgen');
        $result['type'] = 'federation';

       // $result['policydefs'] = $this->arpgen->genPolicyDefs($ent);

        $result['definitions']['columns'] = array(lang('attrname'),'policy','reqstatus', lang('rr_action'));
        $result['data']['support'] = $this->arpgen->getSupportAttributes($ent);
        $result['data']['global'] = $this->arpgen->genGlobal($ent);

        /**
         * @var $allFeds models\Federation[]
         */
        $allFeds = $this->em->getRepository('models\Federation')->findAll();
        $allFederations = array();
        foreach ( $allFeds as $fed) {
            $allFederations[$fed->getId()] = $fed->getName();

        }
        /**
         * @var $fedpolicies models\AttributeReleasePolicy[]
         */
        $fedpolicies = $this->em->getRepository('models\AttributeReleasePolicy')->findBy(
            array(
                'idp' => $ent,
                'type' => array('fed')
            )
        );
        $fedpoliciesByRequester = array();
        foreach($fedpolicies as $fedpolicy)
        {
            $requester = $fedpolicy->getRequester();
            if(!array_key_exists($requester,$allFederations))
            {
                log_message('warning',__METHOD__ .' found policy for federation which doesn not exist anymore - policy will be removed automaticaly');
                $this->em->remove($fedpolicy);
                continue;
            }
            $fedpoliciesByRequester[$fedpolicy->getRequester()][$fedpolicy->getAttribute()->getId()] = $fedpolicy->getPolicy();
        }



        $result['definitions']['feds'] = $allFederations;
 $result['definitions']['attrs'] = $this->arpgen->getAttrDefs();
        $result['data']['fedpols'] = $fedpoliciesByRequester;

        $activeFederation = $this->arpgen->getActiveFederations($ent);

        $result['data']['activefeds'] = $activeFederation;

        $result['definitions']['statusstr']['inactive'] = 'inactive';

        $this->em->flush();
        return $this->output->set_content_type('application/json')->set_output(json_encode($result));
    }


{'fraction_non_alphanumeric': 0.19272500889363217, 'fraction_numerical': 0.007114905727499111, 'mean_word_length': 2.6274193548387097, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 227, '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': '4817893', 'n_tokens_mistral': 3472, 'n_tokens_neox': 3371, 'n_words': 467}