/**
  * Generate association type name for a given association set, 
  * this name is used as value of Name attribute of Association type node in the
  * metadata corrosponding to the given association set.
  * 
  * Refer ./AssociationSetAndTypeNamingRules.txt for naming rules.
  * 
  * @param ResourceAssociationSet $resourceAssociationSet The association set
  * 
  * @return string The association type name
  */
 private function _getAssociationTypeName(ResourceAssociationSet $resourceAssociationSet)
 {
     $end1 = !is_null($resourceAssociationSet->getEnd1()->getResourceProperty()) ? $resourceAssociationSet->getEnd1() : $resourceAssociationSet->getEnd2();
     $end2 = $resourceAssociationSet->getRelatedResourceAssociationSetEnd($end1->getResourceSet(), $end1->getResourceType(), $end1->getResourceProperty());
     //e.g. Customer_Orders (w.r.t Northwind DB)
     $associationTypeName = $end1->getResourceType()->getName() . '_' . $end1->getResourceProperty()->getName();
     if (!is_null($end2->getResourceProperty())) {
         //Customer_Orders_Order_Customer
         $associationTypeName .= '_' . $end2->getResourceType()->getName() . '_' . $end2->getResourceProperty()->getName();
     }
     return $associationTypeName;
 }
Ejemplo n.º 2
0
 /**
  * Write both ends of the given association set.
  * 
  * @param ResourceAssociationSet $associationSet resource association set
  * 
  * @return nothing
  */
 private function _writeAssocationSetEnds(ResourceAssociationSet $associationSet)
 {
     $associationTypeEnd1 = $associationSet->resourceAssociationType->getResourceAssociationTypeEnd($associationSet->getEnd1()->getResourceType(), $associationSet->getEnd1()->getResourceProperty());
     $associationTypeEnd2 = $associationSet->resourceAssociationType->getResourceAssociationTypeEnd($associationSet->getEnd2()->getResourceType(), $associationSet->getEnd2()->getResourceProperty());
     $this->_iOdataWriter->startElement(ODataConstants::END);
     $this->_iOdataWriter->writeAttribute(ODataConstants::ROLE, $associationTypeEnd1->getName());
     $this->_iOdataWriter->writeAttribute(ODataConstants::ENTITY_SET, $associationSet->getEnd1()->getResourceSet()->getName());
     $this->_iOdataWriter->endElement();
     $this->_iOdataWriter->startElement(ODataConstants::END);
     $this->_iOdataWriter->writeAttribute(ODataConstants::ROLE, $associationTypeEnd2->getName());
     $this->_iOdataWriter->writeAttribute(ODataConstants::ENTITY_SET, $associationSet->getEnd2()->getResourceSet()->getName());
     $this->_iOdataWriter->endElement();
 }
Ejemplo n.º 3
0
 /**
  * Test ResourceAssociationSet class
  * Note: ResourceAssociationSet is an internal class used for metadata generation, not suppose to used by the developers 
  */
 public function testResourceAssociationSet()
 {
     try {
         $customerResType = $this->_getCustomerResourceType();
         $customerResourceSet = new ResourceSet('Customers', $customerResType);
         $orderResType = $this->_getOrderResourceType();
         $orderResourceSet = new ResourceSet('Orders', $orderResType);
         $customerReferenceProperty = new ResourceProperty('Customer', null, ResourcePropertyKind::RESOURCE_REFERENCE, $customerResType);
         $ordersReferenceSetProperty = new ResourceProperty('Orders', null, ResourcePropertyKind::RESOURCESET_REFERENCE, $orderResType);
         $customerResType->addProperty($ordersReferenceSetProperty);
         $orderResType->addProperty($customerReferenceProperty);
         $assoSetEnd1 = new ResourceAssociationSetEnd($customerResourceSet, $customerResType, $ordersReferenceSetProperty);
         $assoSetEnd2 = new ResourceAssociationSetEnd($orderResourceSet, $orderResType, $customerReferenceProperty);
         $assoSet = new ResourceAssociationSet('Orders_Customers', $assoSetEnd1, $assoSetEnd2);
         $this->AssertEquals($assoSet->getName(), 'Orders_Customers');
         $this->AssertTrue($assoSet->getEnd1() === $assoSetEnd1);
         $this->AssertTrue($assoSet->getEnd2() === $assoSetEnd2);
         $this->AssertTrue($assoSet->getResourceAssociationSetEnd($customerResourceSet, $customerResType, $ordersReferenceSetProperty) === $assoSetEnd1);
         $this->AssertTrue($assoSet->getRelatedResourceAssociationSetEnd($customerResourceSet, $customerResType, $ordersReferenceSetProperty) === $assoSetEnd2);
         $exceptionThrown = false;
     } catch (\Exception $exception) {
         $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
     }
 }