<commit_before><?php
/**
 * Created by PhpStorm.
 * User: garbi
 * Date: 21.04.17
 * Time: 18:46
 */
// src/DispatcherBundle/Services/iLabServiceBroker.php
namespace DispatcherBundle\Services;

use Doctrine\ORM\EntityManager;
use DispatcherBundle\Security\IsaRlmsAuthenticator;


class iLabServiceBroker
{
    private $em;
    private $labServer;//object of class LabServer
    private $rlmsGuid;
    private $brokerAuthenticator;
    private $serviceUrl;
    private $authorityGuid;
    private $lsServices;
    //private $labServerId;

    public function __construct(EntityManager $em, GenericLabServerServices $lsServices)
    {
        $this->em = $em;
        $this->lsServices = $lsServices;
    }

    public function  setServiceUrl($url)
    {
        $this->serviceUrl = $url;
    }

    public function getLabServerByGuid($guid)
    {
        $labServer = $this
            ->em
            ->getRepository('DispatcherBundle:LabServer')
            ->findOneBy(array('Guid' => $guid));

        if ($labServer == null){
            return array('exception' => true,
                'message' => 'Provided lab server GUID is incorrect or you do not have permissions to access this lab server');

        }
        return array('exception' => false,
            'labServer' => $labServer,
            'message' => 'Lab Server found');
    }

    public function sbAuthHeader($sbHeader)
    {
        $authResponse['authenticated'] = true;
        //$authResponse = $this->brokerAuthenticator->authenticateBatchedMethod($Header->identifier, $Header->passKey, $this->labServer->getId());
        if ($authResponse['authenticated'] == false)
        {
            return new \SoapFault("Server", 'non authorized' );
        }
        $this->authorityGuid = 'DA02D5E137DE4469B9CECADFCAD8145F';
        //$this->couponID = $sbHeader->couponID;
        //$this->couponPassKey = $sbHeader->couponPassKey;
    }


    public function GetLabInfo($params)
    {
        //get the lab server for GUID
        $labServerResp = $this->getLabServerByGuid($params->labServerID);
        if ($labServerResp['exception']){
            return new \SoapFault("Server", $labServerResp['message'] );
        }
        $response = array('GetLabInfoResult' => $labServerResp['labServer']->getLabInfo());
        return $response;
    }

    public function GetLabStatus($params){

        //get the lab server for GUID
        $labServerResp = $this->getLabServerByGuid($params->labServerID);
        if ($labServerResp['exception']){
            return new \SoapFault("Server", $labServerResp['message'] );
        }

        $response = array('GetLabStatusResult' => array(
            'online' => $labServerResp['labServer']->getActive(),
            'labStatusMessage' => "1:Powered up"));<commit_msg>implement Service Broker client API on Dispatcher<commit_after><?php
/**
 * Created by PhpStorm.
 * User: garbi
 * Date: 21.04.17
 * Time: 18:46
 */
// src/DispatcherBundle/Services/iLabServiceBroker.php
namespace DispatcherBundle\Services;

use Doctrine\ORM\EntityManager;
use DispatcherBundle\Security\IsaRlmsAuthenticator;


class iLabServiceBroker
{
    private $em;
    private $labServer;//object of class LabServer
    private $rlmsGuid;
    private $brokerAuthenticator;
    private $serviceUrl;
    private $authorityGuid;
    private $lsServices;
    //private $labServerId;

    public function __construct(EntityManager $em, GenericLabServerServices $lsServices)
    {
        $this->em = $em;
        $this->lsServices = $lsServices;
    }

    public function  setServiceUrl($url)
    {
        $this->serviceUrl = $url;
    }

    public function getLabServerByGuid($guid)
    {
        $labServer = $this
            ->em
            ->getRepository('DispatcherBundle:LabServer')
            ->findOneBy(array('Guid' => $guid));

        if ($labServer == null){
            return array('exception' => true,
                'message' => 'Provided lab server GUID is incorrect or you do not have permissions to access this lab server');

        }
        return array('exception' => false,
            'labServer' => $labServer,
            'message' => 'Lab Server found');
    }

    public function sbAuthHeader($sbHeader)
    {
        $authResponse['authenticated'] = true;
        //$authResponse = $this->brokerAuthenticator->authenticateBatchedMethod($Header->identifier, $Header->passKey, $this->labServer->getId());
        if ($authResponse['authenticated'] == false)
        {
            return new \SoapFault("Server", 'non authorized' );
        }
        $this->authorityGuid = 'DA02D5E137DE4469B9CECADFCAD8145F';
        
        //$this->couponID = $sbHeader->couponID;
        //$this->couponPassKey = $sbHeader->couponPassKey;
    }


    public function GetLabInfo($params)
    {
        //get the lab server for GUID
        $labServerResp = $this->getLabServerByGuid($params->labServerID);
        if ($labServerResp['exception']){
            return new \SoapFault("Server", $labServerResp['message'] );
        }
        $response = array('GetLabInfoResult' => $labServerResp['labServer']->getLabInfo());
        return $response;
    }

    public function GetLabStatus($params){

        //get the lab server for GUID
        $labServerResp = $this->getLabServerByGuid($params->labServerID);
        if ($labServerResp['exception']){
            return new \SoapFault("Server", $labServerResp['message'] );
        }

        $response = array('GetLabStatusResult' => array(
            'online' => $labServerResp['labServer']->getActive(),
            'labStatusMessage' => "1:Powered up"));
{'fraction_non_alphanumeric': 0.13186422605295894, 'fraction_numerical': 0.009241158699129198, 'mean_word_length': 2.747003994673768, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, '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': '1686621', 'n_tokens_mistral': 1720, 'n_tokens_neox': 1617, 'n_words': 335}