/** * @param $fileId * @param $content * @param null $pharPath */ public function onUpdateOrCreate($fileId, $content, $pharPath = null) { $sml = SensorMLParser::parse($content); $uuid = $sml['uuid']; if ($uuid) { $startDate = $sml['startDate']; $endDate = $sml['endDate']; $this->systemAncestorsMapper->deleteChildren($uuid, $startDate, $endDate); $components = $sml['components']; if ($components) { //IF data is not unique, there is no link created between ancestors and children if ($this->ensureUnique($components)) { foreach ($components as $component) { $systemAncestor = new SystemAncestor(); $systemAncestor->setParentUuid($sml['uuid']); $systemAncestor->setParentName($sml['name']); $systemAncestor->setComponentName($component['name']); $systemAncestor->setStatus(true); $systemAncestor->setChildUuid($component['uuid']); $systemAncestor->setParentStartDate($startDate); $systemAncestor->setParentEndDate($endDate); $this->systemAncestorsMapper->insert($systemAncestor); } } } $system = $this->systemMapper->getByUuidAndDate($uuid, $startDate, $endDate, true); if ($system == null) { $system = $this->systemMapper->getByUuidAndFileId($uuid, $fileId); } $insert = false; if ($system == null) { $system = new System(); $insert = true; } $system->setUuid($uuid); $system->setName($sml['name']); $system->setDescription($sml['desc']); $system->setFileId($fileId); $system->setPharPath($pharPath); $system->setStatus(true); $system->setStartDate($startDate); $system->setEndDate($endDate); if ($insert === true) { $this->systemMapper->insert($system); } else { $this->systemMapper->update($system); } } }
/** * Return the type of the node * @param $node node to analyze */ function getType($node) { $xmlFile = FileUtil::endsWith($node->getName(), XML); if ($xmlFile === true) { $xml = new \SimpleXMLElement($node->getContent()); if (OMParser::accept($xml)) { return OM; } else { if (SensorMLParser::accept($xml)) { return SML; } } } return UNKNOW; }