/**
  * 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 EntityId $targetId
  * @param EntityRedirect|null $followedRedirect The followed redirect, will be omitted from the
  * output.
  * @param EntityId[] $incomingRedirects
  * @param RdfBuilder $rdfBuilder
  */
 private function addIncomingRedirects(EntityId $targetId, EntityRedirect $followedRedirect = null, array $incomingRedirects, RdfBuilder $rdfBuilder)
 {
     foreach ($incomingRedirects as $rId) {
         // don't add the followed redirect again
         if (!$followedRedirect || !$followedRedirect->getEntityId()->equals($rId)) {
             $rdfBuilder->addEntityRedirect($rId, $targetId);
         }
     }
 }