/**
  * Transform an elastica document to a resource.
  *
  * @param Document $document
  *
  * @return Resource|null
  */
 public function reverseTransform(Document $document)
 {
     if ($document) {
         $uri = $document->getParam('_id');
         $type = $document->getParam('_type');
         $graph = $this->serializerHelper->getGraph($document->getParam('_index'), $uri, $type);
         $phpClass = $this->typeMapperRegistry->get($type);
         if ($phpClass) {
             return new $phpClass($uri, $graph);
         }
         return new Resource($uri, $graph);
     }
     return;
 }
Пример #2
0
 /**
  * Search correspondant frames and return only ones corresponding to the searched mapping
  * @param string $resourceType
  * @param array  $propertiesUpdated
  * @return array
  */
 protected function getAllResourceTypesIndexingThisResourceType($resourceType, $propertiesUpdated)
 {
     $frames = $this->serializerHelper->getAllFrames();
     $resourceTypesIndexingThisResourceType = array();
     foreach ($frames as $index => $types) {
         foreach ($types as $typeName => $frame) {
             if ($typeName !== $resourceType) {
                 $pathToResourceType = $this->getResourceTypesIndexingPropertiesOfRootResourceType($frame, $resourceType, $propertiesUpdated);
                 if (!empty($pathToResourceType)) {
                     $resourceTypesIndexingThisResourceType[$index][$typeName] = $pathToResourceType;
                 }
             }
         }
     }
     return $resourceTypesIndexingThisResourceType;
 }
Пример #3
0
 protected function getMostAccurateType($types, $resource, $output, $class)
 {
     $mostAccurateType = null;
     $mostAccurateTypes = $this->filiationBuilder->getMostAccurateType($types, $this->serializerHelper->getAllTypes());
     // not specified in project ontology description
     if (count($mostAccurateTypes) == 1) {
         $mostAccurateType = $mostAccurateTypes[0];
     } else {
         if ($mostAccurateTypes === null) {
             $output->writeln("No accurate type found for " . $resource->getUri() . ". The type {$class} will be used.");
             $mostAccurateType = $class;
         } else {
             $output->writeln("The most accurate type for " . $resource->getUri() . " has not be found. The resource will not be indexed.");
         }
     }
     return $mostAccurateType;
 }
Пример #4
0
 /**
  * If a types resource has changed and the new type is mapped to another document type, then the old document is removed
  * @param $uri
  * @param $types
  * @param $oldType
  * @return bool
  */
 protected function deleteOldDocument($uri, $types, $oldType)
 {
     $newTypes = array();
     foreach ($types as $type) {
         $type = (string) $type;
         if ($type && !empty($type)) {
             $newTypes[] = RdfNamespace::shorten($type);
         }
     }
     // Get most accurtype of oldtype
     $mostAccurateTypes = $this->filiationBuilder->getMostAccurateType(array(RdfNamespace::expand($oldType)), $this->serializerHelper->getAllTypes());
     $mostAccurateType = null;
     // not specified in project ontology description
     if (count($mostAccurateTypes) == 1) {
         $mostAccurateType = $mostAccurateTypes[0];
     } else {
         //            echo "Seems to not have to be indexed";
     }
     if (!in_array($mostAccurateType, $newTypes)) {
         $typesConfig = $this->configManager->getTypesConfigurationByClass($mostAccurateType);
         foreach ($typesConfig as $typeConfig) {
             $indexConfig = $typeConfig->getIndex();
             $index = $indexConfig->getName();
             $this->container->get('nemrod.elastica.jsonld.frame.loader')->setEsIndex($index);
             if ($index !== null) {
                 $esType = $this->indexRegistry->getIndex($index)->getType($typeConfig->getType());
                 // Trow an exeption if document does not exist
                 try {
                     $esType->deleteDocument(new Document($uri, array(), $mostAccurateType, $indexConfig->getElasticSearchName()));
                     return true;
                 } catch (\Exception $e) {
                 }
             }
         }
     }
     return false;
 }