示例#1
0
 /**
  * function will create a temporary batchmake config, copying over test data
  * to the the locations in that config needed for the tests, returning an
  * array of config property names to directory locations.
  *
  * @todo figure out a way to copy over Batchmake or else mock it
  * @return array
  * @throws Zend_Exception
  */
 public function setupAndGetConfig()
 {
     // create a test batchmake setup in the temp dir
     // and initialize test data
     $tmpDir = $this->getTempDirectory();
     $subDirs = array('batchmake', 'tests');
     KWUtils::createSubDirectories($tmpDir . '/', $subDirs);
     $configProps = array(MIDAS_BATCHMAKE_TMP_DIR_PROPERTY => $tmpDir . '/batchmake/tests/tmp', MIDAS_BATCHMAKE_BIN_DIR_PROPERTY => $tmpDir . '/batchmake/tests/bin', MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY => $tmpDir . '/batchmake/tests/script', MIDAS_BATCHMAKE_APP_DIR_PROPERTY => $tmpDir . '/batchmake/tests/bin', MIDAS_BATCHMAKE_DATA_DIR_PROPERTY => $tmpDir . '/batchmake/tests/data', MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY => $tmpDir . '/batchmake/tests/condorbin');
     // now make sure these dirs exist
     // later can actually add some stuff to these dirs
     foreach ($configProps as $dir) {
         if (!file_exists($dir) && !KWUtils::mkDir($dir)) {
             throw new Zend_Exception("couldn't create dir " . $dir);
         }
     }
     // now copy over the bms files
     $srcDir = BASE_PATH . 'modules/batchmake/tests/testfiles/script';
     $targetDir = $configProps[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY];
     $extension = '.bms';
     $this->symlinkFileset($srcDir, $targetDir, $extension);
     // and now the bmms
     $srcDir = BASE_PATH . 'modules/batchmake/tests/testfiles/bin';
     $targetDir = $configProps[MIDAS_BATCHMAKE_APP_DIR_PROPERTY];
     $extension = '.bmm';
     $this->symlinkFileset($srcDir, $targetDir, $extension);
     // the mock object strategy requires both an interface and for
     // executable files to exist on disk in a particular location,
     // so here we will create symlinks to a known executable
     // ls
     // which should be on most systems
     $params = array('ls');
     $cmd = KWUtils::prepareExeccommand('which', $params);
     // dir doesn't matter, just send in srcDir as it is convenient
     KWUtils::exec($cmd, $output, $srcDir, $returnVal);
     if ($returnVal !== 0 || !isset($output) || !isset($output[0])) {
         throw new Zend_Exception('Problem finding ls on your system, used for testing');
     }
     $pathToLs = $output[0];
     // get the applications and their path properties from the component that
     // expects them
     $applicationsPaths = Batchmake_KWBatchmakeComponent::getApplicationsPaths();
     foreach ($applicationsPaths as $application => $pathProperty) {
         // now in the place of each executable, symlink the ls exe
         $link = $configProps[$pathProperty] . '/' . $application;
         if (!file_exists($link) && !symlink($pathToLs, $link)) {
             throw new Zend_Exception($pathToLs . ' could not be sym-linked to ' . $link);
         }
     }
     return $configProps;
 }
 /**
  * Use thumbnailer to pre-process a bitstream to generate a jpeg file.
  * Echoes an error message if a problem occurs (for the scheduler log).
  *
  * @param string $name name of the image to be pre-processed
  * @param string $fullPath absolute path to the image to be pre-processed
  * @return string
  * @throws Zend_Exception
  */
 public function preprocessByThumbnailer($name, $fullPath)
 {
     $tmpPath = UtilityComponent::getTempDirectory('thumbnailcreator');
     if (!file_exists($tmpPath)) {
         throw new Zend_Exception('Temporary thumbnail dir does not exist: ' . $tmpPath);
     }
     $copyDestination = $tmpPath . '/' . $name;
     copy($fullPath, $copyDestination);
     $jpegDestination = $tmpPath . '/' . $name . '.jpg';
     /** @var RandomComponent $randomComponent */
     $randomComponent = MidasLoader::loadComponent('Random');
     while (file_exists($jpegDestination)) {
         $jpegDestination = $tmpPath . '/' . $name . $randomComponent->generateInt() . '.jpg';
     }
     /** @var SettingModel $settingModel */
     $settingModel = MidasLoader::loadModel('Setting');
     $thumbnailerPath = $settingModel->getValueByName(MIDAS_THUMBNAILCREATOR_THUMBNAILER_KEY, $this->moduleName);
     $thumbnailerParams = array($copyDestination, $jpegDestination);
     $thumbnailerCmd = KWUtils::prepareExeccommand($thumbnailerPath, $thumbnailerParams);
     if (KWUtils::isExecutable($thumbnailerPath)) {
         KWUtils::exec($thumbnailerCmd);
     } else {
         unlink($copyDestination);
         throw new Zend_Exception('Thumbnailer does not exist or you do not have execute permission. Please check the configuration of thumbnailcreator module.');
     }
     if (!file_exists($jpegDestination)) {
         unlink($copyDestination);
         throw new Zend_Exception('Problem executing thumbnailer on your system');
     } else {
         unlink($copyDestination);
         return $jpegDestination;
     }
 }
示例#3
0
 /**
  * Stop DICOM server.
  *
  * @path /dicomserver/server/stop
  * @http POST
  * @param storescp_cmd (Optional) The command to run storescp
  * @param dcmqrscp_cmd (Optional) The command to run dcmqrscp
  * @param incoming_dir (Optional) The incoming directory to receive and process DICOM files
  * @param get_command (Optional) If set, will not stop DICOM server, but only get command used to stop DICOM server in command line.
  * @return
  */
 public function stop($args)
 {
     // Only administrator can call this api
     $userDao = Zend_Registry::get('userSession')->Dao;
     if (!$userDao || !$userDao->isAdmin()) {
         throw new Exception('Only administrator can stop DICOM server', MIDAS_INVALID_POLICY);
     }
     $ret = array();
     $status_args = array();
     if (!empty($args['storescp_cmd'])) {
         $status_args['storescp_cmd'] = $args['storescp_cmd'];
     }
     if (!empty($args['dcmqrscp_cmd'])) {
         $status_args['dcmqrscp_cmd'] = $args['dcmqrscp_cmd'];
     }
     $running_status = $this->status($status_args);
     if ($running_status['status'] == MIDAS_DICOMSERVER_SERVER_NOT_RUNNING && !array_key_exists('get_command', $args)) {
         $ret['message'] = 'DICOM server is not running now!';
         return $ret;
     }
     $storescp_cmd = 'storescp';
     if (!empty($args['storescp_cmd'])) {
         $storescp_cmd = $args['storescp_cmd'];
     }
     $dcmqrscp_cmd = 'dcmqrscp';
     if (!empty($args['dcmqrscp_cmd'])) {
         $dcmqrscp_cmd = $args['dcmqrscp_cmd'];
     }
     if (!empty($args['incoming_dir'])) {
         $incoming_dir = $args['incoming_dir'];
     } else {
         /** @var Dicomserver_ServerComponent $serverComponent */
         $serverComponent = MidasLoader::loadComponent('Server', 'dicomserver');
         $incoming_dir = $serverComponent->getDefaultReceptionDir();
     }
     $log_dir = $incoming_dir . MIDAS_DICOMSERVER_LOGS_DIRECTORY;
     if (!file_exists($log_dir)) {
         KWUtils::mkDir($log_dir, 0777);
     }
     $python_cmd = 'python';
     $python_params = array();
     $python_params[] = BASE_PATH . '/modules/dicomserver/library/serverWrapper.py';
     $python_params[] = '--stop';
     $python_params[] = '-i ' . $incoming_dir;
     $python_params[] = '-s ' . $storescp_cmd;
     $python_params[] = '-q ' . $dcmqrscp_cmd;
     $stop_server_command = KWUtils::prepareExeccommand($python_cmd, $python_params);
     if (array_key_exists('get_command', $args)) {
         $stop_server_command_string = str_replace("'", '', $stop_server_command);
         return escapeshellarg($stop_server_command_string);
     }
     KWUtils::exec($stop_server_command, $output, '', $returnVal);
     $ret['message'] = 'Succeeded to stop DICOM C-STORE receiver and Query-Retrieve services!';
     if ($returnVal) {
         $exception_string = "Failed to stop DICOM server! \n Reason:" . implode("\n", $output);
         throw new Zend_Exception(htmlspecialchars($exception_string, ENT_QUOTES), MIDAS_INVALID_POLICY);
     }
     return $ret;
 }
示例#4
0
 /**
  * Register DICOM image files (bitstreams).
  */
 public function register($revision)
 {
     $bitstreams = $revision->getBitstreams();
     if (count($bitstreams) < 1) {
         return;
     }
     /** @var SettingModel $settingModel */
     $settingModel = MidasLoader::loadModel('Setting');
     $command = $settingModel->getValueByName(MIDAS_DICOMSERVER_DCMQRIDX_COMMAND_KEY, $this->moduleName);
     $command = str_replace("'", '', $command);
     $commandParams = array();
     $receptionDirectory = $settingModel->getValueByName(MIDAS_DICOMSERVER_RECEPTION_DIRECTORY_KEY, $this->moduleName);
     if (!is_writable($receptionDirectory)) {
         throw new Zend_Exception('Please configure Dicom Server module correctly. Its reception directory is NOT writable!', MIDAS_INVALID_POLICY);
     }
     $aeStorage = $receptionDirectory . MIDAS_DICOMSERVER_PACS_DIRECTORY;
     $aeStorage = str_replace("'", '', $aeStorage);
     $commandParams[] = $aeStorage;
     foreach ($bitstreams as $bitstream) {
         $commandParams[] = $bitstream->getFullPath();
         $registerCommand = KWUtils::prepareExeccommand($command, $commandParams);
         array_pop($command_params);
         // prepare for next iteration in the loop
         KWUtils::exec($registerCommand, $output, '', $returnVal);
         if ($returnVal) {
             $exceptionString = "Failed to register DICOM images! \n Reason:" . implode("\n", $output);
             throw new Zend_Exception(htmlspecialchars($exceptionString, ENT_QUOTES), MIDAS_INVALID_POLICY);
         }
     }
     /** @var Dicomserver_RegistrationModel $registrationModel */
     $registrationModel = MidasLoader::loadModel('Registration', 'dicomserver');
     $itemId = $revision->getItemId();
     if (!$registrationModel->checkByItemId($itemId)) {
         $registrationModel->createRegistration($itemId);
     }
 }