Skip to content

Commit

Permalink
REST: Add Property read model
Browse files Browse the repository at this point in the history
This creates a new read model to hold all data of a Property. The class
previously called "Property" is renamed to "PredicateProperty" to
indicate the statement context.

Change-Id: If602fc45b24826bbb61a0c593c57f3fd72c90c11
  • Loading branch information
jakobw committed Aug 9, 2023
1 parent a0479c4 commit ec4e077
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 38 deletions.
31 changes: 31 additions & 0 deletions repo/rest-api/src/Domain/ReadModel/PredicateProperty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php declare( strict_types=1 );

namespace Wikibase\Repo\RestApi\Domain\ReadModel;

use Wikibase\DataModel\Entity\PropertyId;

/**
* @license GPL-2.0-or-later
*/
class PredicateProperty {

private PropertyId $id;
private ?string $dataType;

public function __construct( PropertyId $id, ?string $dataType ) {
$this->id = $id;
$this->dataType = $dataType;
}

public function getId(): PropertyId {
return $this->id;
}

/**
* @return string|null null only if the property was deleted/cannot be found
*/
public function getDataType(): ?string {
return $this->dataType;
}

}
21 changes: 5 additions & 16 deletions repo/rest-api/src/Domain/ReadModel/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,19 @@

namespace Wikibase\Repo\RestApi\Domain\ReadModel;

use Wikibase\DataModel\Entity\PropertyId;

/**
* @license GPL-2.0-or-later
*/
class Property {

private PropertyId $id;
private ?string $dataType;

public function __construct( PropertyId $id, ?string $dataType ) {
$this->id = $id;
$this->dataType = $dataType;
}
private StatementList $statements;

public function getId(): PropertyId {
return $this->id;
public function __construct( StatementList $statements ) {
$this->statements = $statements;
}

/**
* @return string|null null only if the property was deleted/cannot be found
*/
public function getDataType(): ?string {
return $this->dataType;
public function getStatements(): StatementList {
return $this->statements;
}

}
6 changes: 3 additions & 3 deletions repo/rest-api/src/Domain/ReadModel/PropertyValuePair.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
*/
class PropertyValuePair {

private Property $property;
private PredicateProperty $property;
private Value $value;

public function __construct( Property $property, Value $value ) {
public function __construct( PredicateProperty $property, Value $value ) {
$this->property = $property;
$this->value = $value;
}

public function getProperty(): Property {
public function getProperty(): PredicateProperty {
return $this->property;
}

Expand Down
6 changes: 3 additions & 3 deletions repo/rest-api/src/Domain/ReadModel/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
class Statement {

private StatementGuid $guid;
private Property $property;
private PredicateProperty $property;
private Value $value;
private Rank $rank;
private Qualifiers $qualifiers;
private References $references;

public function __construct(
StatementGuid $guid,
Property $property,
PredicateProperty $property,
Value $value,
Rank $rank,
Qualifiers $qualifiers,
Expand All @@ -36,7 +36,7 @@ public function getGuid(): StatementGuid {
return $this->guid;
}

public function getProperty(): Property {
public function getProperty(): PredicateProperty {
return $this->property;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Wikibase\DataModel\Snak\Snak;
use Wikibase\DataModel\Snak\SnakList;
use Wikibase\DataModel\Statement\Statement as DataModelStatement;
use Wikibase\Repo\RestApi\Domain\ReadModel\Property;
use Wikibase\Repo\RestApi\Domain\ReadModel\PredicateProperty;
use Wikibase\Repo\RestApi\Domain\ReadModel\PropertyValuePair;
use Wikibase\Repo\RestApi\Domain\ReadModel\Qualifiers;
use Wikibase\Repo\RestApi\Domain\ReadModel\Rank;
Expand Down Expand Up @@ -83,7 +83,7 @@ private function convertSnakToPropertyValuePair( Snak $snak ): PropertyValuePair
}

return new PropertyValuePair(
new Property( $snak->getPropertyId(), $dataType ),
new PredicateProperty( $snak->getPropertyId(), $dataType ),
new Value(
$snak->getType(),
$snak instanceof PropertyValueSnak ? $snak->getDataValue() : null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\NumericPropertyId;
use Wikibase\Repo\RestApi\Application\Serialization\PropertyValuePairSerializer;
use Wikibase\Repo\RestApi\Domain\ReadModel\Property;
use Wikibase\Repo\RestApi\Domain\ReadModel\PredicateProperty;
use Wikibase\Repo\RestApi\Domain\ReadModel\PropertyValuePair;
use Wikibase\Repo\RestApi\Domain\ReadModel\Value;

Expand Down Expand Up @@ -43,7 +43,7 @@ public function testSerialize( PropertyValuePair $propertyValuePair, array $expe
public static function serializationProvider(): Generator {
yield 'no value for string prop' => [
new PropertyValuePair(
new Property(
new PredicateProperty(
new NumericPropertyId( self::STRING_PROPERTY_ID ),
'string'
),
Expand All @@ -60,7 +60,7 @@ public static function serializationProvider(): Generator {

yield 'some value for item id prop' => [
new PropertyValuePair(
new Property(
new PredicateProperty(
new NumericPropertyId( self::ITEM_ID_PROPERTY_ID ),
'wikibase-item'
),
Expand All @@ -77,7 +77,7 @@ public static function serializationProvider(): Generator {

yield 'string value' => [
new PropertyValuePair(
new Property(
new PredicateProperty(
new NumericPropertyId( self::STRING_PROPERTY_ID ),
'string'
),
Expand All @@ -100,7 +100,7 @@ public static function serializationProvider(): Generator {

yield 'item id value' => [
new PropertyValuePair(
new Property(
new PredicateProperty(
new NumericPropertyId( self::ITEM_ID_PROPERTY_ID ),
'wikibase-item'
),
Expand All @@ -125,7 +125,7 @@ public static function serializationProvider(): Generator {
$calendar = 'Q12345';
yield 'time value' => [
new PropertyValuePair(
new Property(
new PredicateProperty(
new NumericPropertyId( self::TIME_PROPERTY_ID ),
'time'
),
Expand All @@ -152,7 +152,7 @@ public static function serializationProvider(): Generator {

yield 'globecoordinate value' => [
new PropertyValuePair(
new Property(
new PredicateProperty(
new NumericPropertyId( self::GLOBECOORDINATE_PROPERTY_ID ),
'globe-coordinate'
),
Expand Down Expand Up @@ -180,7 +180,7 @@ public static function serializationProvider(): Generator {

yield 'null data type for some property value' => [
new PropertyValuePair(
new Property(
new PredicateProperty(
new NumericPropertyId( self::DELETED_PROPERTY_ID ),
null
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Wikibase\DataModel\Entity\NumericPropertyId;
use Wikibase\Repo\RestApi\Application\Serialization\PropertyValuePairSerializer;
use Wikibase\Repo\RestApi\Application\Serialization\ReferenceSerializer;
use Wikibase\Repo\RestApi\Domain\ReadModel\Property;
use Wikibase\Repo\RestApi\Domain\ReadModel\PredicateProperty;
use Wikibase\Repo\RestApi\Domain\ReadModel\PropertyValuePair;
use Wikibase\Repo\RestApi\Domain\ReadModel\Reference;
use Wikibase\Repo\RestApi\Domain\ReadModel\Value;
Expand All @@ -34,7 +34,7 @@ public function testSerialize( Reference $reference, array $expectedSerializatio
public static function serializationProvider(): Generator {
$ref1 = new Reference( 'some-hash-1', [
new PropertyValuePair(
new Property( new NumericPropertyId( 'P123' ), 'string' ),
new PredicateProperty( new NumericPropertyId( 'P123' ), 'string' ),
new Value( Value::TYPE_SOME_VALUE )
),
] );
Expand All @@ -50,11 +50,11 @@ public static function serializationProvider(): Generator {

$ref2 = new Reference( 'some-hash-2', [
new PropertyValuePair(
new Property( new NumericPropertyId( 'P234' ), 'string' ),
new PredicateProperty( new NumericPropertyId( 'P234' ), 'string' ),
new Value( Value::TYPE_SOME_VALUE )
),
new PropertyValuePair(
new Property( new NumericPropertyId( 'P345' ), 'string' ),
new PredicateProperty( new NumericPropertyId( 'P345' ), 'string' ),
new Value( Value::TYPE_SOME_VALUE )
),
] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\NumericPropertyId;
use Wikibase\DataModel\Statement\StatementGuid;
use Wikibase\Repo\RestApi\Domain\ReadModel\Property;
use Wikibase\Repo\RestApi\Domain\ReadModel\PredicateProperty;
use Wikibase\Repo\RestApi\Domain\ReadModel\Qualifiers;
use Wikibase\Repo\RestApi\Domain\ReadModel\Rank;
use Wikibase\Repo\RestApi\Domain\ReadModel\References;
Expand Down Expand Up @@ -46,7 +46,7 @@ public function testGivenStatementWithIdDoesNotExist_getStatementByIdReturnsNull
private function newStatementWithId( StatementGuid $id ): Statement {
return new Statement(
$id,
new Property( new NumericPropertyId( 'P123' ), 'string' ),
new PredicateProperty( new NumericPropertyId( 'P123' ), 'string' ),
new Value( Value::TYPE_SOME_VALUE ),
Rank::normal(),
new Qualifiers(),
Expand Down

0 comments on commit ec4e077

Please sign in to comment.