protected function generateData(EntityInterface $entity) {
    $data = parent::generateData($entity);

    // Find media belonging to node that has the source term, and set its file
    // url in the data array.
    $source_term = $this->utils->getTermForUri($this->configuration['source_term_uri']);
    if (!$source_term) {
      throw new \RuntimeException("Could not locate source term with uri" . $this->configuration['source_term_uri'], 500);
    }

    $source_media = $this->utils->getMediaWithTerm($entity, $source_term);
    if (!$source_media) {
      throw new \RuntimeException("Could not locate source media", 500);
    }

    $source_file = $this->mediaSource->getSourceFile($source_media);
    if (!$source_file) {
      throw new \RuntimeException("Could not locate source file for media {$source_media->id()}", 500);
    }

    $data['source_uri'] = $source_file->url('canonical', ['absolute' => TRUE]);

    // Find the term for the derivative and use it to set the destination url
    // in the data array.
    $derivative_term = $this->utils->getTermForUri($this->configuration['derivative_term_uri']);
    if (!$source_term) {
      throw new \RuntimeException("Could not locate derivative term with uri" . $this->configuration['derivative_term_uri'], 500);
    }

    $route_params = [
      'node' => $entity->id(),
      'media_type' => $this->configuration['destination_media_type'],
      'taxonomy_term' => $derivative_term->id(),
    ];
    $data['destination_uri'] = Url::fromRoute('islandora.media_source_put_to_node', $route_params)
      ->setAbsolute()
      ->toString();

    $token_data = [
      'node' => $entity,
      'media' => $source_media,
      'term' => $derivative_term,
    ];
    $path = $this->token->replace($data['path'], $token_data);
    $data['file_upload_uri'] = $data['scheme'] . '://' . $path;

    // Get rid of some config so we just pass along
    // what the camel route and microservice need.
    unset($data['source_term_uri']);
    unset($data['derivative_term_uri']);
    unset($data['path']);
    unset($data['scheme']);
    unset($data['destination_media_type']);

    return $data;
  }
protected function generateData(EntityInterface $entity) {
    $data = parent::generateData($entity);

    // Find media belonging to node that has the source term, and set its file
    // url in the data array.
    $source_term = $this->utils->getTermForUri($this->configuration['source_term_uri']);
    if (!$source_term) {
      throw new \RuntimeException("Could not locate source term with uri" . $this->configuration['source_term_uri'], 500);
    }

    $source_media = $this->utils->getMediaWithTerm($entity, $source_term);
    if (!$source_media) {
      throw new \RuntimeException("Could not locate source media", 500);
    }

    $source_file = $this->mediaSource->getSourceFile($source_media);
    if (!$source_file) {
      throw new \RuntimeException("Could not locate source file for media {$source_media->id()}", 500);
    }

    $data['source_uri'] = $source_file->url('canonical', ['absolute' => TRUE]);

    // Find the term for the derivative and use it to set the destination url
    // in the data array.
    $derivative_term = $this->utils->getTermForUri($this->configuration['derivative_term_uri']);
    if (!$source_term) {
      throw new \RuntimeException("Could not locate derivative term with uri" . $this->configuration['derivative_term_uri'], 500);
    }

    $route_params = [
      'node' => $entity->id(),
      'media_type' => $this->configuration['destination_media_type'],
      'taxonomy_term' => $derivative_term->id(),
    ];
    $data['destination_uri'] = Url::fromRoute('islandora.media_source_put_to_node', $route_params)
      ->setAbsolute()
      ->toString();

    $token_data = [
      'node' => $entity,
      'media' => $source_media,
      'term' => $derivative_term,
    ];
    $path = $this->token->replace($data['path'], $token_data);
    $data['file_upload_uri'] = $data['scheme'] . '://' . $path;

    // Get rid of some config so we just pass along
    // what the camel route and microservice need.
    unset($data['source_term_uri']);
    unset($data['derivative_term_uri']);
    unset($data['path']);
    unset($data['scheme']);
    unset($data['destination_media_type']);

    return $data;
  }
protected function generateData ( EntityInterface $ entity ) { $ data = parent :: generateData ( $ entity ) ; // Find media belonging to node that has the source term, and set its file // url in the data array. $ source_term = $ this -> utils -> getTermForUri ( $ this -> configuration [ 'source_term_uri' ] ) ; if ( ! $ source_term ) { throw new \ RuntimeException ( "Could not locate source term with uri" . $ this -> configuration [ 'source_term_uri' ] , 500 ) ; } $ source_media = $ this -> utils -> getMediaWithTerm ( $ entity , $ source_term ) ; if ( ! $ source_media ) { throw new \ RuntimeException ( "Could not locate source media" , 500 ) ; } $ source_file = $ this -> mediaSource -> getSourceFile ( $ source_media ) ; if ( ! $ source_file ) { throw new \ RuntimeException ( "Could not locate source file for media {$source_media->id()}" , 500 ) ; } $ data [ 'source_uri' ] = $ source_file -> url ( 'canonical' , [ 'absolute' => TRUE ] ) ; // Find the term for the derivative and use it to set the destination url // in the data array. $ derivative_term = $ this -> utils -> getTermForUri ( $ this -> configuration [ 'derivative_term_uri' ] ) ; if ( ! $ source_term ) { throw new \ RuntimeException ( "Could not locate derivative term with uri" . $ this -> configuration [ 'derivative_term_uri' ] , 500 ) ; } $ route_params = [ 'node' => $ entity -> id ( ) , 'media_type' => $ this -> configuration [ 'destination_media_type' ] , 'taxonomy_term' => $ derivative_term -> id ( ) , ] ; $ data [ 'destination_uri' ] = Url :: fromRoute ( 'islandora.media_source_put_to_node' , $ route_params ) -> setAbsolute ( ) -> toString ( ) ; $ token_data = [ 'node' => $ entity , 'media' => $ source_media , 'term' => $ derivative_term , ] ; $ path = $ this -> token -> replace ( $ data [ 'path' ] , $ token_data ) ; $ data [ 'file_upload_uri' ] = $ data [ 'scheme' ] . '://' . $ path ; // Get rid of some config so we just pass along // what the camel route and microservice need. unset ( $ data [ 'source_term_uri' ] ) ; unset ( $ data [ 'derivative_term_uri' ] ) ; unset ( $ data [ 'path' ] ) ; unset ( $ data [ 'scheme' ] ) ; unset ( $ data [ 'destination_media_type' ] ) ; return $ data ; }
Override this to return arbitrary data as an array to be json encoded.
Override this to return arbitrary data as an array to be json encoded .