public function putStatement(StatementId $id, Statement $statement) { if (null !== $statement->getId() && !$id->equals($statement->getId())) { throw new ConflictException(sprintf('Id parameter ("%s") and statement id ("%s") do not match.', $id->getValue(), $statement->getId()->getValue())); } try { $existingStatement = $this->repository->findStatementById($id->getValue()); } catch (NotFoundException $e) { $this->repository->storeStatement($statement, true); } return new Response('', 204); }
public static function fromModel(StatementModel $model) { $statement = new self(); $statement->id = $model->getId()->getValue(); $statement->actor = Object::fromModel($model->getActor()); $statement->verb = Verb::fromModel($model->getVerb()); $statement->object = Object::fromModel($model->getObject()); if (null !== $model->getTimestamp()) { $statement->created = $model->getTimestamp()->getTimestamp(); } if (null !== ($result = $model->getResult())) { $statement->result = Result::fromModel($result); } if (null !== ($authority = $model->getAuthority())) { $statement->authority = Object::fromModel($authority); } if (null !== ($context = $model->getContext())) { $statement->context = Context::fromModel($context); } if (null !== ($attachments = $model->getAttachments())) { $statement->hasAttachments = true; $statement->attachments = array(); foreach ($attachments as $attachment) { $mappedAttachment = Attachment::fromModel($attachment); $mappedAttachment->statement = $statement; $statement->attachments[] = $mappedAttachment; } } else { $statement->hasAttachments = false; } return $statement; }
/** * {@inheritDoc} */ public function storeStatement(Statement $statement) { if (null !== $statement->getId()) { return $this->doStoreStatements($statement, 'put', array('statementId' => $statement->getId()), 204); } else { return $this->doStoreStatements($statement); } }
public static function createFromModel(Statement $statement) { $mappedStatement = new MappedStatement(); $mappedStatement->id = $statement->getId(); $mappedStatement->actor = $statement->getActor(); $mappedStatement->verb = MappedVerb::createFromModel($statement->getVerb()); $mappedStatement->object = $statement->getObject(); $mappedStatement->result = $statement->getResult(); $mappedStatement->authority = $statement->getAuthority(); $mappedStatement->created = $statement->getCreated(); $mappedStatement->stored = $statement->getStored(); return $mappedStatement; }
/** * {@inheritdoc} */ public final function storeStatement(Statement $statement, $flush = true) { if (null === $statement->getId()) { $statement = $statement->withId(StatementId::fromUuid(Uuid::uuid4())); } $mappedStatement = MappedStatement::fromModel($statement); $mappedStatement->stored = time(); $this->repository->storeStatement($mappedStatement, $flush); return $statement->getId(); }
/** * Writes a {@link Statement} to the underlying data storage. * * @param Statement $statement The statement to store * @param bool $flush Whether or not to flush the managed objects * immediately (i.e. write them to the data * storage) * * @return string The UUID of the created Statement */ public final function storeStatement(Statement $statement, $flush = true) { $uuid = $statement->getId(); $mappedStatement = MappedStatement::createFromModel($statement); $mappedStatement->stored = new \DateTime(); if (null === $uuid) { $uuid = Uuid::uuid4()->toString(); $mappedStatement->id = $uuid; } $this->storeMappedStatement($mappedStatement, $flush); return $uuid; }
private function assertStatementEquals(Statement $expected, Statement $actual, $validateId = true) { if ($validateId) { $this->assertSame($expected->getId(), $actual->getId()); } $this->assertTrue($actual->getActor()->equals($expected->getActor())); $this->assertTrue($actual->getVerb()->equals($expected->getVerb())); $this->assertTrue($actual->getObject()->equals($expected->getObject())); if (null === $expected->getResult()) { $this->assertNull($actual->getResult()); } else { $this->assertTrue($actual->getResult()->equals($expected->getResult())); } if (null === $expected->getAuthority()) { $this->assertNull($actual->getAuthority()); } else { $this->assertTrue($actual->getAuthority()->equals($expected->getAuthority())); } }