示例#1
0
 /**
  * Generate items informations
  * 
  * Get an array containing two lists :
  *  -> items : Downloadable items with url
  *  -> errors : Not downloadable items with explanations
  * 
  * @return array
  */
 private function generateItemsInformations()
 {
     /*
      * Features with errors
      */
     $errors = array();
     /*
      * Features without errors
      */
     $items = array();
     /*
      * Loop over items
      */
     foreach ($this->order['items'] as $item) {
         /*
          * Check if item get an id
          */
         if (!isset($item['id'])) {
             array_push($errors, array('type' => 'Feature', 'ErrorMessage' => 'Wrong item', 'ErrorCode' => 404, 'properties' => isset($item['properties']) ? $item['properties'] : null));
             continue;
         }
         /*
          * Create RestoFeature
          */
         $feature = new RestoFeature($this->context, $this->user, array('featureIdentifier' => $item['id']));
         /*
          * Check if User is fullfilling license requirements
          */
         if (!$feature->getLicense()->isApplicableToUser($this->user)) {
             array_push($errors, array('type' => 'Feature', 'id' => $feature->identifier, 'ErrorMessage' => 'User does not fulfill license requirements', 'ErrorCode' => 403, 'properties' => isset($item['properties']) ? $item['properties'] : null));
             continue;
         }
         /*
          * Check if user has to sign license
          */
         if ($feature->getLicense()->hasToBeSignedByUser($this->user)) {
             array_push($errors, array('type' => 'Feature', 'id' => $feature->identifier, 'ErrorMessage' => 'User has to sign license', 'ErrorCode' => 3002, 'license' => $feature->getLicense()->toArray(), 'properties' => isset($item['properties']) ? $item['properties'] : null));
             continue;
         }
         /*
          * Check if item is valid
          */
         if (!isset($item['properties']) || !isset($item['properties']['services']) || !isset($item['properties']['services']['download'])) {
             array_push($errors, array('type' => 'Feature', 'id' => $feature->identifier, 'ErrorMessage' => 'Invalid item', 'ErrorCode' => 404, 'properties' => isset($item['properties']) ? $item['properties'] : null));
             continue;
         }
         /*
          * Check is item is downloadable
          */
         if (!isset($item['properties']['services']['download']['url']) || !RestoUtil::isUrl($item['properties']['services']['download']['url'])) {
             array_push($errors, array('type' => 'Feature', 'id' => $feature->identifier, 'ErrorMessage' => 'Item not downloadable', 'ErrorCode' => 404, 'properties' => isset($item['properties']) ? $item['properties'] : null));
             continue;
         }
         /*
          * Check user rights
          */
         if (!$this->user->hasRightsTo(RestoUser::DOWNLOAD, array('collectionName' => $item['properties']['collection'], 'featureIdentifier' => $feature->identifier))) {
             array_push($errors, array('type' => 'Feature', 'id' => $feature->identifier, 'ErrorMessage' => "User hasn't enough rights. Please contact an administrator", 'ErrorCode' => 403, 'properties' => isset($item['properties']) ? $item['properties'] : null));
             continue;
         }
         /*
          * Update local download url with a shared link
          */
         $exploded = explode('?', $item['properties']['services']['download']['url']);
         if ($exploded[0] === $this->context->baseUrl . join('/', array('/collections', $item['properties']['collection'], $feature->identifier, 'download'))) {
             $item['properties']['services']['download']['url'] = $this->getSharedLink($item['properties']['services']['download']['url']);
         }
         /*
          * Add item to downloadable items list
          */
         array_push($items, array('type' => 'Feature', 'id' => $feature->identifier, 'properties' => isset($item['properties']) ? $item['properties'] : null));
     }
     /*
      * Return array containing errors and downloadable items
      */
     return array('errors' => $errors, 'items' => $items);
 }
示例#2
0
 /**
  * @depends testInsertResource
  */
 public function testResource()
 {
     $this->initContext();
     $data = file_get_contents(dirname(__FILE__) . "/../data/Landsat.json");
     $data = json_decode($data, true);
     $collection = new RestoCollection($data['name'], $this->context, $this->admin, array('autoload' => true));
     $feature = new RestoFeature($this->context, $this->admin, array('featureIdentifier' => 'c5dc1f32-002d-5ee9-bd4a-c690461eb734', 'collection' => $collection));
     $this->assertEquals(true, $feature->isValid());
     $license = $feature->getLicense();
     $this->assertEquals('Example', $license->licenseId);
     $json = json_decode($feature->toJSON(false));
     $this->assertEquals('c5dc1f32-002d-5ee9-bd4a-c690461eb734', $json->id);
     $arr_feature = $feature->toArray();
     $this->assertEquals('c5dc1f32-002d-5ee9-bd4a-c690461eb734', $arr_feature['id']);
     try {
         $feature->download();
         $this->fail('An expected exception has not been raised.');
     } catch (Exception $ex) {
     }
 }