public function testUniqueKeys()
 {
     $client_json = '[
                         {"key":"0000123MNO","name":"My MNO","r":1,"w":0},
                         {"key":"0000123ABC","name":"My ABC","r":0,"w":1},
                         {"key":"*****23ABC","name":"My ABC","r":0,"w":1}
                     ]';
     $server_json = '[
                         {"tm":true,"glos":false,"owner":true,"key":"0000123MNO","name":"My MNO","r":"1","w":"1","uid_transl":123,"uid_rev":null,"r_transl":0,"w_transl":1,"r_rev":null,"w_rev":null,"source":null,"target":null},
                         {"tm":true,"glos":false,"owner":false,"key":"0000123ABC","name":"","r":null,"w":null,"uid_transl":123,"uid_rev":456,"r_transl":1,"w_transl":0,"r_rev":1,"w_rev":1,"source":null,"target":null}
                     ]';
     /*
      * Expected Exception because the same key can not be sent twice
      *
      */
     $this->setExpectedException('Exception', "A key is already present in this project.", 5);
     TmKeyManagement_TmKeyManagement::mergeJsonKeys($client_json, $server_json, TmKeyManagement_Filter::ROLE_TRANSLATOR, 123);
 }
 /**
  * When Called it perform the controller action to retrieve/manipulate data
  *
  * @return mixed
  */
 function doAction()
 {
     //if some error occured, stop execution.
     if (count(@$this->result['errors'])) {
         return false;
     }
     /*
      * The client send data as structured json, for now take it as a plain structure
      *
      *   $clientDecodedJson = Array
      *       (
      *           [owner] => Array
      *               (
      *                   [0] => Array
      *                       (
      *                           [tm] => 1
      *                           [glos] => 1
      *                           [owner] => 1
      *                           [key] => ***************da9a9
      *                           [name] =>
      *                           [r] => 1
      *                           [w] => 1
      *                       )
      *
      *               )
      *
      *           [mine] => Array
      *               (
      *                   [0] => Array
      *                       (
      *                           [tm] => 1
      *                           [glos] => 1
      *                           [owner] => 0
      *                           [key] => 952681baffb9c147b346
      *                           [name] => cgjhkmfgdcjkfh
      *                           [r] => 1
      *                           [w] => 1
      *                       )
      *
      *               )
      *
      *           [anonymous] => Array
      *               (
      *                   [0] => Array
      *                       (
      *                           [tm] => 1
      *                           [glos] => 1
      *                           [owner] => 0
      *                           [key] => ***************882eb
      *                           [name] => Chiave di anonimo
      *                           [r] => 0
      *                           [w] => 0
      *                       )
      *
      *               )
      *
      *       )
      *
      */
     $tm_keys = json_decode($this->tm_keys, true);
     /*
      * sanitize owner role key type
      */
     foreach ($tm_keys['mine'] as $k => $val) {
         $tm_keys['mine'][$k]['owner'] = $this->userRole == TmKeyManagement_Filter::OWNER;
     }
     $tm_keys = array_merge($tm_keys['ownergroup'], $tm_keys['mine'], $tm_keys['anonymous']);
     $this->tm_keys = json_encode($tm_keys);
     try {
         $totalTmKeys = TmKeyManagement_TmKeyManagement::mergeJsonKeys($this->tm_keys, $this->jobData['tm_keys'], $this->userRole, $this->uid);
         Log::doLog('Before:');
         Log::doLog($this->jobData['tm_keys']);
         Log::doLog('After:');
         Log::doLog(json_encode($totalTmKeys));
         TmKeyManagement_TmKeyManagement::setJobTmKeys($this->job_id, $this->job_pass, $totalTmKeys);
         $this->result['data'] = 'OK';
     } catch (Exception $e) {
         $this->result['data'] = 'KO';
         $this->result['errors'][] = array("code" => $e->getCode(), "message" => $e->getMessage());
     }
 }