Doctrine value object with one field only - doctrine-orm

Currently I use Doctrine2 with value object, it's working great. The problem when I use value object with only one field, for example:
$this->repository->findBy(array('email' => 'name#domain.com')); //This is not working
$this->repository->findBy(array('email.email' => 'name#domain.com')); //This is work great
The question is, how to make $this->repository->findBy(array('email' => 'name#domain.com')); working?
This is my doctrine mapping
User.orm.xml
<!-- User.orm.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping">
<entity name="Domain\User\Entity\User" table="users" repository-class="Infrastructure\User\Repository\UserRepository">
<id name="id" type="guid">
<generator strategy="UUID"/>
</id>
<embedded name="email" class="Shared\ValueObject\Email" use-column-prefix="false" />
</entity>
</doctrine-mapping>
Email.orm.xml
<!-- Email.orm.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<embeddable name="Shared\ValueObject\Email">
<field name="email" type="string" length="80" />
</embeddable>
</doctrine-mapping>
Thank you for your help, and sorry for my bad english.

Unfortunately according to code this is not possible. Field name always be
$property . "." . $fieldMapping['fieldName'];

Related

Validation String XSLT WSO2

I'm newbie about validation on programming. Like Checking string and checking field input empty or not. Maybe anyone in here can share me about simple sample validation rule about string and checking field to me with XSLT. Thanks
First of all, XSLT is for XML transformations and if you want to do schema validations you should be looking at XSD validations. Having said that below is how you can use XSLT to validate a message and generate a payload.
Let's say you have a Payload like the below.
<Request>
<messages>
<message>
<id>123</id>
<name>Not Empty</name>
</message>
<message>
<id>234</id>
<name></name>
</message>
</messages>
</Request>
In the above payload, you want to check each message and check whether the name is empty or not. Inorder to validate this you can use XSLT. First create a XSLT as a LocalEntry in the local-entries directory. You can use the following content. (You can create your XSLT in the registry as well)
<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="LOCAL_XSLT_NullCheck" xmlns="http://ws.apache.org/ns/synapse">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" indent="yes" method="xml" omit-xml-declaration="yes"/>
<xsl:template match="/">
<Response>
<!-- Iterating through message elements -->
<xsl:for-each select="//messages/message">
<message>
<messageID><xsl:value-of select="id/text()"/></messageID>
<xsl:choose>
<!-- Check if name is empty -->
<xsl:when test="boolean(name/text())">
<isEmpty>false</isEmpty>
</xsl:when>
<xsl:otherwise>
<isEmpty>true</isEmpty>
</xsl:otherwise>
</xsl:choose>
</message>
</xsl:for-each>
</Response>
</xsl:template>
</xsl:stylesheet>
</localEntry>
Next create a API to consume your request and to validate the payload and then to generate the response.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/xslt" name="TestAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<log level="full">
<property name="Message" value="Incoming Message"/>
</log>
<xslt key="LOCAL_XSLT_NullCheck"/>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
Now once you invoke the API with the aforementioned message. You should see the following response.
<Response xmlns="http://ws.apache.org/ns/synapse">
<message>
<messageID>123</messageID>
<isEmpty>false</isEmpty>
</message>
<message>
<messageID>234</messageID>
<isEmpty>true</isEmpty>
</message>
</Response>
You ca read more on XSLT mediator from here. You can also consider using FastXSLT Mediator as well based on your requirement. Read more on XSLT from here.

XPATH to get distinct set of nodes from XML

I have an XML file as shown below.
<?xml version="1.0" encoding="UTF-8"?>
<body xmlns:bons0="http://DistinctAppSample" xmlns:httpsca="http://www.ibm.com/xmlns/prod/websphere/http/sca/6.1.0" xmlns:mq="http://www.ibm.com/xmlns/prod/websphere/mq/sca/6.0.0" xmlns:smo="http://www.ibm.com/websphere/sibx/smo/v6.0.1" xmlns:tns="http://DistinctAppSample/TestInf" xmlns:tns1="http://www.w3.org/2005/08/addressing" xmlns:tns2="http://www.w3.org/2003/05/soap-envelope" xmlns:tns_1="wsdl.http://DistinctAppSample/TestInf" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="foo.xsd">
<tns:testOperation>
<input>
<request>
<salary>100</salary>
<newSalary>101</newSalary>
</request>
<request>
<salary>123</salary>
<newSalary>101</newSalary>
</request>
<request>
<salary>101</salary>
<newSalary>123</newSalary>
</request>
<request>
<salary>100</salary>
<newSalary>101</newSalary>
</request>
</input>
</tns:testOperation>
</body>
I am trying to remove the duplicate "request" node where we have same salary and newSalary value (node1 and node4 has same values. So I need to consider only one node). Sample output is follows.
<?xml version="1.0" encoding="UTF-8"?>
<body xmlns:bons0="http://DistinctAppSample" xmlns:httpsca="http://www.ibm.com/xmlns/prod/websphere/http/sca/6.1.0" xmlns:mq="http://www.ibm.com/xmlns/prod/websphere/mq/sca/6.0.0" xmlns:smo="http://www.ibm.com/websphere/sibx/smo/v6.0.1" xmlns:tns="http://DistinctAppSample/TestInf" xmlns:tns1="http://www.w3.org/2005/08/addressing" xmlns:tns2="http://www.w3.org/2003/05/soap-envelope" xmlns:tns_1="wsdl.http://DistinctAppSample/TestInf" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="foo.xsd">
<tns:testOperation>
<input>
<request>
<salary>100</salary>
<newSalary>101</newSalary>
</request>
<request>
<salary>123</salary>
<newSalary>101</newSalary>
</request>
<request>
<salary>101</salary>
<newSalary>123</newSalary>
</request>
</input>
</tns:testOperation>
</body>
I would need to write a XPATH to achieve this Scenario.
I have tried //request[not(salary = preceding::salary and newSalary = preceding::newSalary)] but it is not working as expected. Any suggesition would be much appriciated.
Thanks.

how to generate xml file using libxml2 in c++?

I want to have following xml file:
<?xml version="1.0" encoding="UTF8" ?>
<!DOCTYPE people SYSTEM "XMLSpyDTD.dtd">
<report>
<Start>
<date format="ddMMyy" val="Tue Jun 09 2015
" />
<time format="hhmm" val="11:43:06 " />
</Start>
<test name="Testadd" executed="Yes">
<discription>
<![CDATA[Add two numbers]]>
</discription>
<targets>
<target threaded="false">C++</target>
</targets>
</test>
</report>
So, kindly suggest me how may i generate it using libxml2 in c++?

Can not edit Doctrine ArrayCollection

I have a problem with editing an Doctrine2 ArrayCollection of a many-to-many assosciation.
Persisting an new entity is no problem and works fine. But if I would like to persist an entity with new added CollectionItems I got an
Doctrine\ORM\ORMInvalidArgumentException
I use the xml-mapping, the mapping files are the following:
receipt:
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Application\Entity\Receipt" table="receipt" repository-class="Application\Repositories\ReceiptRepository">
<indexes>
<index name="FK_receipt_profession" columns="professsion"/>
<index name="FK_receipt_items_needed" columns="items"/>
</indexes>
<id name="rId" type="integer" column="r_id">
<generator strategy="IDENTITY"/>
</id>
<field name="name" type="string" column="name" length="100" nullable="false"/>
<many-to-one field="profession" target-entity="Application\Entity\Profession">
<join-columns>
<join-column name="profession" referenced-column-name="p_id"/>
</join-columns>
</many-to-one>
<many-to-many field="items" target-entity="Application\Entity\ItemsNeeded" inversed-by="receipt">
<!--<cascade><cascade-all/></cascade>-->
<join-table name="receipt_x_items_needed">
<join-columns>
<join-column name="receipt" referenced-column-name="r_id"/>
</join-columns>
<inverse-join-columns>
<join-column name="itemNeeded" referenced-column-name="in_id"/>
</inverse-join-columns>
</join-table>
</many-to-many>
</entity>
</doctrine-mapping>
ItemsNeeded:
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Application\Entity\ItemsNeeded" table="items_needed" repository-class="Application\Repositories\ItemsneededRepository">
<indexes>
<index name="FK_items_needed_receipt" columns="receipt_id"/>
<index name="item_id" columns="item_id"/>
</indexes>
<id name="inId" type="integer" column="in_id">
<generator strategy="IDENTITY"/>
</id>
<field name="count" type="integer" column="count" nullable="false"/>
<many-to-one field="item" target-entity="Application\Entity\Items">
<join-columns>
<join-column name="item_id" referenced-column-name="i_id"/>
</join-columns>
</many-to-one>
<many-to-many field="receipt" target-entity="Application\Entity\Receipt" mapped-by="items"/>
</entity>
</doctrine-mapping>
and items:
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Application\Entity\Items" table="items" repository-class="Importer\Repository\ItemRepository">
<unique-constraints>
<unique-constraint name="buffed_id" columns="buffed_id"/>
</unique-constraints>
<id name="iId" type="integer" column="i_id">
<generator strategy="IDENTITY"/>
</id>
<field name="name" type="string" column="name" length="100" nullable="false"/>
<field name="buffedId" type="integer" column="buffed_id" nullable="false"/>
</entity>
</doctrine-mapping>
The receipt table has an many-to-many relation through the crosstable "receipt_x_items_needed".
If I call $receipt->addItem($item); and $item is an already existing item from the itemtable I got the following error:
A new entity was found through the relationship 'Application\Entity\ItemsNeeded#item' that was not configured to cascade persist operations for entity: Application\Entity\Items#0000000041f6e49000000000651183aa. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example #ManyToOne(..,cascade={"persist"}). If you cannot find out which entity causes the problem implement 'Application\Entity\Items#__toString()' to get a clue.
But this is no new entity. All data are correctly set and as I wrote, if I add e new receipt all works fine.

Creating custom magento webservices

I'm having some trouble creating some custom web services in Magento. I'm trying to get the module configured properly and I can't seem to make the web services I've defined in the api.xml file show up under the user role setup in the admin area.
I've defined a custom module in app/etc shown here
ctp_GiftCards.xml:
<?xml version="1.0"?>
<config>
<modules>
<ctp_GiftCards>
<active>true</active>
<codePool>local</codePool>
</ctp_GiftCards>
</modules>
</config>
The module code is located in app/local/ctp/GiftCards/
Here is an example of the etc/api.xml:
<?xml version="1.0"?>
<config>
<api>
<resources>
<GiftCards translate="title" module="ctp_GiftCards">
<title>GiftCard webservices</title>
<acl>GiftCards/GiftCard</acl>
<methods>
<update translate="title" module="ctp_GiftCards">
<title>updates a giftcard account</title>
</update>
</methods>
<faults module="ctp_GiftCards">
<invalid_data>
<code>100</code>
<message>giftcard data invalid</message>
</invalid_data>
<card_pool_error>
<code>101</code>
<message>card pool for entry not updated</message>
</card_pool_error>
<cache_error>
<code>102</code>
<message>cache not reset</message>
</cache_error>
</faults>
</GiftCards>
</resources>
<acl>
<resources>
<GiftCards translate="title" module="ctp_GiftCards">
<title>GiftCards</title>
<sort_order>6</sort_order>
<GiftCard translate="title" module="ctp_GiftCards">
<title>GiftCard</title>
<update translate="title" module="ctp_GiftCards">
<title>Update</title>
</update>
</GiftCard>
</GiftCards>
</resources>
</acl>
</api>
</config>
and the etc/config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<ctp_GiftCards>
<version>0.1.0</version>
</ctp_GiftCards>
</modules>
<global>
<models>
<GiftCard>
<class>CTP_GiftCards_Model</class>
</GiftCard>
</models>
</global>
</config>
Any help would be much appreciated.
--edit--
I'm using mangeto pro 1.10
Don't use capital letter (GiftCards) in the name of xml tag inside the node. Moreover, your module's name contains both underscope (_) and capital letter (ctp_GiftCards) which will lead Magento to misunderstand.