private function buildMappings($context) { //Load mapToClass property $mapToClassName = $this->loadProperty(TemplateMapping::MAP_TO_CLASS); $this->mapToClass = $this->ontology->getClass($mapToClassName); if (!$this->mapToClass) { throw new \Exception('Class ' . $mapToClassName . ' defined by property ' . TemplateMapping::MAP_TO_CLASS . ' not found.'); } //Load correspondingProperty property $correspondingClassName = $this->loadProperty(TemplateMapping::CORRESPONDING_CLASS, true); if ($correspondingClassName) { $this->correspondingClass = $this->ontology->getClass($correspondingClassName); if (!$this->correspondingClass) { throw new \Exception('Class ' . $correspondingClassName . ' defined by property ' . TemplateMapping::CORRESPONDING_CLASS . ' not found.'); } } //Load correspondingClass property $correspondingPropertyName = $this->loadProperty(TemplateMapping::CORRESPONDING_PROPERTY, true); if ($correspondingPropertyName) { $this->correspondingProperty = $this->ontology->getProperty($correspondingPropertyName); if (!$this->correspondingProperty) { throw new \Exception('Property ' . $correspondingPropertyName . ' defined by property ' . TemplateMapping::CORRESPONDING_PROPERTY . ' not found.'); } } //Load mappings property $mappingsProperty = $this->node->getProperty(TemplateMapping::MAPPINGS); if ($mappingsProperty) { foreach ($mappingsProperty->getChildren('TemplateNode') as $mapping) { try { $propertyMapping = PropertyMapping::load($mapping, $this->ontology, $context); $this->propertiesMap[] = $propertyMapping; } catch (\Exception $e) { $this->logger->warn("[" . $this->node->getRoot()->getTitle() . "] Couldn't load property mapping: " . $e->getMessage()); } } } }
public static function load($node, $ontology, $context) { $mapping = new ConditionalMapping(); $mapping->destination = $context->getDestinations()->getDestination(self::DESTINATION_ID); //Load default mappings $defaultMappings = array(); $defaultMappingsNode = $node->getProperty(self::DEFAULT_MAPPINGS); foreach ($defaultMappingsNode->getChildren('TemplateNode') as $defaultMappingNode) { $defaultMappings[] = PropertyMapping::load($defaultMappingNode, $ontology, $context); } //Load cases $casesNode = $node->getProperty(self::CASES); if (!$casesNode) { throw new \Exception('No ' . self::CASES . ' property found in conditional mapping defined in ' . $node->getRoot()->getTitle()); } $mapping->cases = array(); $caseNodes = $casesNode->getChildren('TemplateNode'); foreach ($caseNodes as $caseNode) { $condition = Condition::load($caseNode); $mappingNodes = $caseNode->getProperty('mapping')->getChildren('TemplateNode'); if (!isset($mappingNodes[0])) { continue; } $templateMapping = TemplateMapping::load($mappingNodes[0], $ontology, $context); //If the template mapping does not define any property mapping -> add default mappings if (count($templateMapping->getPropertyMappings()) == 0) { foreach ($defaultMappings as $defaultMapping) { $templateMapping->addPropertyMapping($defaultMapping); } } if ($condition->getOperator() === 'otherwise') { if ($mapping->otherwise) { throw \Exception('Cannot define multiple default mappings in ' . $node->getRoot()->getTitle()); } $mapping->otherwise = $templateMapping; } else { $mapping->cases[] = array($condition, $templateMapping); } } return $mapping; }
private function loadMappings($context) { $mappingsProperty = $this->templateNode->getProperty(self::MAPPINGS); if ($mappingsProperty) { $mappings = $mappingsProperty->getChildren('TemplateNode'); foreach ($mappings as $mapping) { try { $propertyMapping = PropertyMapping::load($mapping, $this->ontology, $context); $this->propertiesMap[] = $propertyMapping; } catch (Exception $e) { $this->logger->warn("Couldn't load property mapping" . PHP_EOL . $e->getTraceAsString()); } } } else { throw new Exception('Table mapping does no define any mappings'); } }