/**
  * Produces RDF dump of the entity
  *
  * @param EntityId $entityId
  *
  * @throws EntityLookupException
  * @throws StorageException
  * @return string|null RDF
  */
 protected function generateDumpForEntityId(EntityId $entityId)
 {
     try {
         $entityRevision = $this->entityRevisionLookup->getEntityRevision($entityId);
         if (!$entityRevision) {
             throw new EntityLookupException($entityId, 'Entity not found: ' . $entityId->getSerialization());
         }
         $this->rdfBuilder->addEntityRevisionInfo($entityRevision->getEntity()->getId(), $entityRevision->getRevisionId(), $entityRevision->getTimestamp());
         $this->rdfBuilder->addEntity($entityRevision->getEntity());
     } catch (MWContentSerializationException $ex) {
         throw new StorageException('Deserialization error for ' . $entityId->getSerialization());
     } catch (RevisionedUnresolvedRedirectException $e) {
         if ($e->getRevisionId() > 0) {
             $this->rdfBuilder->addEntityRevisionInfo($entityId, $e->getRevisionId(), $e->getRevisionTimestamp());
         }
         $this->rdfBuilder->addEntityRedirect($entityId, $e->getRedirectTargetId());
     }
     $rdf = $this->rdfBuilder->getRDF();
     return $rdf;
 }
 /**
  * @param EntityRevision $entityRevision
  * @param RedirectRevision|null $followedRedirect a redirect leading to the entity for use in the output
  * @param EntityId[] $incomingRedirects Incoming redirects to include in the output
  * @param RdfBuilder $rdfBuilder
  * @param string|null $flavor The type of the output provided by serializer
  *
  * @return string RDF
  */
 private function rdfSerialize(EntityRevision $entityRevision, RedirectRevision $followedRedirect = null, array $incomingRedirects, RdfBuilder $rdfBuilder, $flavor = null)
 {
     $rdfBuilder->startDocument();
     $redir = null;
     if ($followedRedirect) {
         $redir = $followedRedirect->getRedirect();
         $rdfBuilder->addEntityRedirect($redir->getEntityId(), $redir->getTargetId());
         if ($followedRedirect->getRevisionId() > 0) {
             $rdfBuilder->addEntityRevisionInfo($redir->getEntityId(), $followedRedirect->getRevisionId(), $followedRedirect->getTimestamp());
         }
     }
     if ($followedRedirect && $flavor === 'dump') {
         // For redirects, don't output the target entity data if the "dump" flavor is requested.
         // @todo: In this case, avoid loading the Entity all together.
         // However we want to output the revisions for redirects
     } else {
         $rdfBuilder->addEntityRevisionInfo($entityRevision->getEntity()->getId(), $entityRevision->getRevisionId(), $entityRevision->getTimestamp());
         $rdfBuilder->addEntity($entityRevision->getEntity());
         $rdfBuilder->resolveMentionedEntities($this->entityLookup);
     }
     if ($flavor !== 'dump') {
         // For $flavor === 'dump' we don't need to output incoming redirects.
         $targetId = $entityRevision->getEntity()->getId();
         $this->addIncomingRedirects($targetId, $redir, $incomingRedirects, $rdfBuilder);
     }
     $rdfBuilder->finishDocument();
     return $rdfBuilder->getRDF();
 }