/** * Check wrapped resource set's resource type or any of the resource type derived * from the this resource type has bag property associated with it. * * @param MetadataQueryProviderWrapper $provider Metadata query provider wrapper * * @return boolean */ public function hasBagProperty(MetadataQueryProviderWrapper $provider) { $arrayToDetectLoop = array(); $hasBagProperty = $this->_resourceSet->getResourceType()->hasBagProperty($arrayToDetectLoop); unset($arrayToDetectLoop); // This will check only the resource type associated with // the resource set, we need to check presence of bag property // in resource type which is derived form this resource type also. if (!$hasBagProperty) { $derivedTypes = $provider->getDerivedTypes($this->_resourceSet->getResourceType()); if (!is_null($derivedTypes)) { foreach ($derivedTypes as $derivedType) { $arrayToDetectLoop = array(); if ($derivedType->hasBagProperty($arrayToDetectLoop)) { $hasBagProperty = true; break; } } } } return $hasBagProperty; }
/** * Validate the given entity instance. * * @param object $entityInstance Entity instance to validate * @param ResourceSet &$resourceSet Resource set to which the entity * instance belongs to. * @param KeyDescriptor &$keyDescriptor The key descriptor. * @param string $methodName Method from which this function * invoked. * * @return void * * @throws ODataException */ private function _validateEntityInstance($entityInstance, ResourceSet &$resourceSet, KeyDescriptor &$keyDescriptor, $methodName) { if (is_null($entityInstance)) { ODataException::createResourceNotFoundError($resourceSet->getName()); } $entityName = $resourceSet->getResourceType()->getInstanceType()->getName(); if (!is_object($entityInstance) || !$entityInstance instanceof $entityName) { ODataException::createInternalServerError(Messages::metadataQueryProviderWrapperIDSQPMethodReturnsUnExpectedType($entityName, $methodName)); } foreach ($keyDescriptor->getValidatedNamedValues() as $keyName => $valueDescription) { try { $keyProperty = new \ReflectionProperty($entityInstance, $keyName); $keyValue = $keyProperty->getValue($entityInstance); if (is_null($keyValue)) { ODataException::createInternalServerError(Messages::metadataQueryProviderWrapperIDSQPMethodReturnsInstanceWithNullKeyProperties($methodName)); } $convertedValue = $valueDescription[1]->convert($valueDescription[0]); if ($keyValue != $convertedValue) { ODataException::createInternalServerError(Messages::metadataQueryProviderWrapperIDSQPMethodReturnsInstanceWithNonMatchingKeys($methodName)); } } catch (\ReflectionException $reflectionException) { //throw ODataException::createInternalServerError( // Messages::orderByParserFailedToAccessOrInitializeProperty( // $resourceProperty->getName(), $resourceType->getName() // ) //); } } }
/** * To add a navigation property (resource set or resource reference) * to a resource type * * @param ResourceType $resourceType The resource type to add * the resource reference * or resource * reference set property to * @param string $name The name of the * property to add * @param ResourceSet $targetResourceSet The resource set the * resource reference * or reference * set property * ponits to * @param ResourcePropertyKind $resourcePropertyKind The property kind * * @return void */ private function _addReferencePropertyInternal(ResourceType $resourceType, $name, ResourceSet $targetResourceSet, $resourcePropertyKind) { try { $resourceType->getInstanceType()->getProperty($name); } catch (ReflectionException $exception) { throw new InvalidOperationException('Can\'t add a property which does not exist on the instance type.'); } if (!($resourcePropertyKind == ResourcePropertyKind::RESOURCESET_REFERENCE || $resourcePropertyKind == ResourcePropertyKind::RESOURCE_REFERENCE)) { throw new InvalidOperationException('Property kind should be ResourceSetReference or ResourceReference'); } $targetResourceType = $targetResourceSet->getResourceType(); $resourceProperty = new ResourceProperty($name, null, $resourcePropertyKind, $targetResourceType); $resourceType->addProperty($resourceProperty); //Create instance of AssociationSet for this relationship $sourceResourceSet = $resourceType->getCustomState(); if (is_null($sourceResourceSet)) { throw new InvalidOperationException('Failed to retrieve the custom state from ' . $resourceType->getName()); } //Customer_Orders_Orders, Order_Customer_Customers //(source type::name _ source property::name _ target set::name) $assoicationSetKey = $resourceType->getName() . '_' . $name . '_' . $targetResourceSet->getName(); $associationSet = new ResourceAssociationSet($assoicationSetKey, new ResourceAssociationSetEnd($sourceResourceSet, $resourceType, $resourceProperty), new ResourceAssociationSetEnd($targetResourceSet, $targetResourceSet->getResourceType(), null)); $this->associationSets[$assoicationSetKey] = $associationSet; }
/** * test ResourceSet class */ public function testResourceSet() { try { $exceptionThrown = false; try { $int64 = ResourceType::getPrimitiveResourceType(EdmPrimitiveType::INT64); $customerResourceSet = new ResourceSet('Customers', $int64); } catch (\InvalidArgumentException $exception) { $exceptionThrown = true; $this->AssertStringStartsWith('The ResourceTypeKind property of a ResourceType instance associated with a ResourceSet', $exception->getMessage()); } $customerResType = $this->_getCustomerResourceType(); $customerResourceSet = new ResourceSet('Customers', $customerResType); $this->AssertEquals($customerResourceSet->getName(), 'Customers'); $this->AssertEquals($customerResourceSet->getResourceType()->getName(), 'Customer'); if (!$exceptionThrown) { $this->fail('An expected InvalidArgumentException for \'non-entity type resource type\' has not been raised'); } } catch (\Exception $exception) { $this->fail('An unexpected Exception has been raised' . $exception->getMessage()); } }
/** * Construct new instance of ResourceAssociationSetEnd * Note: The $resourceSet represents collection of an entity, The * $resourceType can be this entity's type or type of any of the * base resource of this entity, on which the navigation property * represented by $resourceProperty is defined. * * @param ResourceSet $resourceSet Resource set for the association end * @param ResourceType $resourceType Resource type for the association end * @param ResourceProperty $resourceProperty Resource property for the association end * * @throws \InvalidArgumentException */ public function __construct(ResourceSet $resourceSet, ResourceType $resourceType, $resourceProperty) { if (!is_null($resourceProperty) && !$resourceProperty instanceof ResourceProperty) { throw new \InvalidArgumentException(Messages::resourceAssociationSetPropertyMustBeNullOrInsatnceofResourceProperty('$resourceProperty')); } if (!is_null($resourceProperty) && (is_null($resourceType->tryResolvePropertyTypeByName($resourceProperty->getName())) || $resourceProperty->getKind() != ResourcePropertyKind::RESOURCE_REFERENCE && $resourceProperty->getKind() != ResourcePropertyKind::RESOURCESET_REFERENCE)) { throw new \InvalidArgumentException(Messages::resourceAssociationSetEndPropertyMustBeNavigationProperty($resourceProperty->getName(), $resourceType->getFullName())); } if (!$resourceSet->getResourceType()->isAssignableFrom($resourceType) && !$resourceType->isAssignableFrom($resourceSet->getResourceType())) { throw new \InvalidArgumentException(Messages::resourceAssociationSetEndResourceTypeMustBeAssignableToResourceSet($resourceType->getFullName(), $resourceSet->getName())); } $this->_resourceSet = $resourceSet; $this->_resourceType = $resourceType; $this->_resourceProperty = $resourceProperty; }