Example #1
0
 public function getResponseObject($contentType = "application/xml")
 {
     switch ($contentType) {
         case 'application/xml':
             $content = $this->getXML();
             $this->response->setContent($content);
             return $this->response;
             break;
         default:
             $this->response->setStatus(406);
             $this->response->setContent(SmintErrorXML::error($this->response->getStatusCode(), "The client does not accept any of the accepted content types. Try using a client that supports application/xml or add the header manually."));
             return $this->response;
             break;
     }
 }
Example #2
0
 protected function getXML()
 {
     if ($this->response->getStatusCode() == 200) {
         $content = SmintXML::simpleXMLElement();
         $track_added = $content->addChild("track_to_be_deleted");
         $track_added->addAttribute("id", $this->guid);
         $track_added->addAttribute("collection", $this->collection);
         return $content->asXML();
     } else {
         if (!isset($this->errorMessage)) {
             $this->errorMessage = "No additional Information on error available.";
         }
         return SmintErrorXML::error($this->response->getStatusCode(), $this->errorMessage);
     }
 }
Example #3
0
File: Track.php Project: EQ4/smafe
 protected function getXML()
 {
     $result = $this->queryBySmintFileId();
     if (is_null($result)) {
         // if there was an error the result will be null
         // assume that the detailed error message was set where the query failed
         $this->response->setStatus(403);
         return SmintErrorXML::error($this->response->getStatusCode(), $this->errorMessage);
     } else {
         if (count($result) > 0) {
             $this->response->setStatus(200);
             $content = SmintXML::simpleXMLElement();
             $querytrack = $content->addChild("query");
             $querytrack->addAttribute("id", $this->queryFileGUID);
             if ($this->external_keys) {
                 if (!isset($this->queryFileExternal_Key)) {
                     $this->queryFileExternal_Key = $this->getExternalKeyfromGUID($this->queryFileGUID);
                 }
                 $querytrack->addAttribute("external_key", $this->queryFileExternal_Key);
             }
             if ($this->collection) {
                 $querytrack->addAttribute("collection", $this->collection);
             }
             foreach ($result as $trackKey => $trackValue) {
                 $resultnode = $querytrack->addChild("result");
                 $resultnode->addAttribute("id", $trackValue["guid"]);
                 if ($this->external_keys) {
                     $resultnode->addAttribute("external_key", $trackValue["external_key"]);
                 }
                 if ($this->distance_values) {
                     $resultnode->addAttribute("value", $trackValue["value"]);
                 }
             }
             return $content->asXML();
         } else {
             # check if jobs are already added
             $job_result = $this->queryJobsBySmintFileId();
             if (is_null($job_result)) {
                 // if there was an error the result will be null
                 // assume that the detailed error message was set where the query failed
                 $this->response->setStatus(403);
                 return SmintErrorXML::error($this->response->getStatusCode(), $this->errorMessage);
             }
             if (count($job_result) > 0) {
                 $this->response->setStatus(200);
                 $content = SmintXML::simpleXMLElement();
                 $querytrack = $content->addChild("query");
                 $querytrack->addAttribute("id", $this->queryFileGUID);
                 if ($this->external_keys) {
                     if (!isset($this->queryFileExternal_Key)) {
                         $this->queryFileExternal_Key = $this->getExternalKeyfromGUID($this->queryFileGUID);
                     }
                     $querytrack->addAttribute("external_key", $this->queryFileExternal_Key);
                 }
                 if ($this->collection) {
                     $querytrack->addAttribute("collection", $this->collection);
                 }
                 if ($job_result[0]["status"] == null) {
                     $status_message = "waiting for processing.";
                     $status_code = 1;
                 } else {
                     if ($job_result[0]["status"] == "FAILED") {
                         $status_message = "job could not be processed: " . $job_result[0]["log"];
                         $status_code = -1;
                     } else {
                         if ($job_result[0]["status"] == "OK") {
                             // check if distjobs are open:
                             $featurevectortype_id = $this->apiConfig["query"]["defaultFVTypeid"];
                             $distancetype_id = $this->apiConfig["query"]["defaultDSTypeid"];
                             if ($this->openDistanceJobs($job_result[0]["id"], $featurevectortype_id, $distancetype_id)) {
                                 $status_message = "processing done. indexing. this might take some time.";
                                 $status_code = 3;
                             } else {
                                 $status_message = "job processed. if there is no result, there might be no related track in the database. ";
                                 $status_code = 0;
                             }
                         } else {
                             if (strlen($job_result[0]["status"]) > 0) {
                                 // assume that the string is the ID of the daemon performing the current job
                                 $status_message = "job is processed by process: " . $job_result[0]["status"];
                                 $status_code = 2;
                             }
                         }
                     }
                 }
                 // currently not directly covered by add_job table -> use separate query to check if distance jobs are open
                 // else if ( $job_result[0]["status"] == "DIST" ) {
                 //   $status_message = "processing done. indexing might still take some time.";
                 //   $status_code = 3;
                 // }
                 $result = $querytrack->addChild("status", $status_message);
                 $result->addAttribute("status_code", $status_code);
                 return $content->asXML();
             } else {
                 $this->response->setStatus(404);
                 $this->errorMessage = "Track with the guid: \"{$this->queryFileGUID}\"";
                 if ($this->external_keys) {
                     $this->errorMessage = $this->errorMessage . " / external_key: \"{$this->queryFileExternal_Key}\"";
                 }
                 if ($this->collection) {
                     $this->errorMessage = $this->errorMessage . " / collection: \"{$this->collection}\"";
                 }
                 $this->errorMessage = $this->errorMessage . " could not be found in our database. {$this->debug}";
                 return SmintErrorXML::error($this->response->getStatusCode(), $this->errorMessage);
             }
         }
     }
 }
Example #4
0
 protected function getXML()
 {
     if ($this->response->getStatusCode() == 200) {
         $content = SmintXML::simpleXMLElement();
         $track_added = $content->addChild("track_added");
         $track_added->addAttribute("smint_track_id", $this->uniqueid);
         $track_added->addAttribute("url", $this->fileURL);
         $track_added->addAttribute("file", $this->localFile);
         if (!is_null($this->external_key)) {
             $track_added->addAttribute("external_key", $this->external_key);
         }
         return $content->asXML();
     } else {
         if (!isset($this->errorMessage)) {
             $this->errorMessage = "No additional Information on error available.";
         }
         return SmintErrorXML::error($this->response->getStatusCode(), $this->errorMessage);
     }
 }
Example #5
0
 protected function getXML()
 {
     if ($this->response->getStatusCode() == 200) {
         $content = SmintXML::simpleXMLElement();
         foreach ($this->nns as $nn) {
             $nn_node = $content->addChild("match", $nn[3]);
             //$nn_node->addAttribute("track_id", $nn[0]);
             //$nn_node->addAttribute("segment_id", $nn[1]);
             $nn_node->addAttribute("confidence", number_format($nn[2], 3));
             //$nn_node->addAttribute("", $nn[1]);
         }
         return $content->asXML();
     } else {
         if (!isset($this->errorMessage)) {
             $this->errorMessage = "No additional Information on error available.";
         }
         return SmintErrorXML::error($this->response->getStatusCode(), $this->errorMessage);
     }
 }