Is the mapping in sequential order in Dozer? - mapping

I have Dozer mapping as follows
<mapping>
<class-a>Class1</class-a>
<class-b>Class2</class-b>
<field> <a>C1.field1</a> <b>C2.field1</b> </field>
<field custom-converter="converterField2"> <a>C1.field2</a> <b>C2.field2</b> </field>
<field> <a custom-converter="converterField3"> C1.field3</a> <b>C2.field3</b> </field>
<field> <a>C1.field4</a> <b>C2.field4</b> </field>
</mapping>
I have four mappings mapping file. Does the Dozer maps in order like field1 is mapped first, followed by field2 and then by field3?
Or will do map in any order?

Yes, the mapping happens in order. The field names are fetched from the files by Reflection and added to Lists. These lists are then iterated over and the values mapped one by one.
Specifically, the names are fetched here and the mapping starts here.

Related

How Can I use Name as res-id instead of index in a MIB table with two key indexes

[issue description]
I have defined a MIB table with two indexes, the table is like this:
TerminationEntry OBJECT-TYPE
SYNTAX TerminationEntry
ACCESS not-accessible
STATUS mandatory
DESCRIPTION
"An entry in the terminationTable ."
INDEX {ifIndex, TkId}
::= {terminationTable 1}
And the Tkname and TkId mapping table is:
TkMappingEntry::=
SEQUENCE
{
tkMappingName OCTET STRING,
tkMappingId INTEGER
}
In CLI, I defined two res-id mapping to this two indexes. And for the TkId, the user should input the TkName, and the TkName can be mapped to the TkId. the CLI XML is like this:
<parameters>
<res-id uname="if-index" parameter-type="Itf::Line">
<help>The unique internal identifier of the termination port</help>
<fields>
<field name="">
<mib-index name="ifIndex"/>
</field>
</fields>
</res-id>
<res-id name="tkgname" parameter-type="Sip::TkName">
<help>The name of Tk.</help>
<fields>
<field name="" access="CommandFieldDefinition::mayBeReadDuringDisplay_c |
CommandFieldDefinition::mayBeWrittenDuringCreate_c">
<mib-var tree-node="NODEterminationTkName" table-name="terminationTable "/>
<mib-index name="tkMappingName"/>
</field>
</fields>
</res-id>
<parameters>
...
<fields>
<field name="index" basic-type="Sip::TkId"
access="CommandFieldDefinition::mayBeReadDuringPrepare_c |
CommandFieldDefinition::mayBeReadDuringModify_c |
CommandFieldDefinition::mayBeReadDuringCommit_c |
CommandFieldDefinition::mayBeReadDuringDelete_c |
CommandFieldDefinition::mayBeReadDuringIn_c |
CommandFieldDefinition::mayBeReadDuringDisplay_c |
CommandFieldDefinition::mayBeReadDuringCreate_c">
<mib-var tree-node="NODEtkMappingId" table-name="tkMappingTable"/>
<mib-index name="terminationTkId"/>
</field>
<field name="next-free" basic-type="Sip::TrunkGroupId" access="CommandFieldDefinition::mayBeReadDuringCreate_c">
<mib-var tree-node="NODE_tkIdNext" table-name="SnmpAgent::localScalarTable_m"/>
<mib-index name="terminationTkId"/>
</field>
</fields>
But during testing, I find that when I input a unexisted TkName, the next-free field is called and the free index is stored in node tkIdNext. But it is not transferred to the terminationTkId. So my CLI command is failed and I get a error on CLI:referred instance does not exist.
[note]
Please help to check the code and help me find why the name/id mapping is failed. By the way, I have tried the name/id mapping in the signle index MIB table, there's no problem. I don't know why the same code can be failed in a two indexes MIB table.
in field name="index", the access "CommandFieldDefinition::mayBeReadDuringCreate_c" should be removed.
During creating node, CLi should only call "next-free" field.

How to bypass class level map-null="false" for a specific field in dozer?

In the mapping below, ObjectB has been set to map-null="false", and I think that means that any null property from ObjectA will not be set to ObjectB.
However, for a certain property only (say propB), I need ObjectA to successfully pass and set ObjectB's property even if it is null.
How do I bypass map-null="false" for this property? or is there any workaround I can do?
Thanks.
<mapping wildcard="false">
<class-a>ObjectA</class-a>
<class-b map-null="false">ObjectB</class-b>
<field>
<a>propA</a>
<b>childB.propA</b>
</field>
<field>
<a>propB</a>
<b>childB.propB</b>
</field>
</mapping>
I did a workaround by creating a separate dozer mapping between ObjectA and childB. Check the dozer mapping below:
<mapping wildcard="false">
<class-a>ObjectA</class-a>
<class-b map-null="false">ObjectB</class-b>
<field>
<a>propA</a>
<b>childB.propA</b>
</field>
<field>
<a>this</a>
<b>childB</b>
</field>
</mapping>
<mapping wildcard="false">
<class-a>ObjectA</class-a>
<class-b>childB</class-b>
<field>
<a>propB</a>
<b>propB</b>
</field>
</mapping>
This way, propB can be null and will be valid because it is in a different mapping.

Solr scoring based on subdocument (parent blockjoin)

I have the following structure of ... lets say products in a store. The Products have a rating. Then users can, additionally, rate the product (on their own). Lets say 300k Products plus 50k user-ratings (to each product)
Question 1: Are Subdocuments the right choice? I am adding everything with SolrJ, I did not find any other suitable method of doing that.
For sake of an example, you could copy and paste the following code to your collection:
<add>
<doc>
<field name="id">1</field>
<field name="title" >Product Title LOLO</field>
<field name="content_type" >parent</field>
<field name="rating_f" >7</field>
<doc>
<field name="id">1</field>
<field name="user_id_s" >123</field>
<field name="userrating_f" >1.2</field>
</doc>
</doc>
<doc>
<field name="id">2</field>
<field name="title" >Product Title LULU</field>
<field name="content_type" >parent</field>
<field name="rating_f" >2</field>
</doc>
<doc>
<field name="id">3</field>
<field name="title" >Product Title LALA</field>
<field name="content_type" >parent</field>
<field name="rating_f" >1.4</field>
<doc>
<field name="id">1</field>
<field name="user_id_s" >123</field>
<field name="userrating_f" >5</field>
</doc>
</doc>
</add>
Question 2 (The Important one): How can I query this index now, so that the documents are scored with a boost on the user-rating first (if one exists) and then by the product rating (and then by other fields, like the creation date, views, buys, ...)? Is that even possible?
I was looking into something like that:
{!parent which="content_type:parent"}(user_id_s:123 AND _val_:userrating_f)^2.0 _val_:rating_f^2.0 *:*
That should return the documents in this order (ids): 3, 1, 2
But instead it returns:
{
"responseHeader": {
"status": 500,
"QTime": 1,
"params": {
"indent": "true",
"q": "{!parent which=\"content_type:parent\"}(user_id_s:123 AND _val_:userrating_f)^2.0 _val_:rating_f^2.0 *:*",
"_": "1421996862814",
"wt": "json"
}
},
"error": {
"msg": "child query must only match non-parent docs, but parent docID=3 matched childScorer=class org.apache.lucene.search.DisjunctionSumScorer",
"trace": "java.lang.IllegalStateException: child query must only match non-parent docs, but parent docID=3 matched childScorer=class org.apache.lucene.search.DisjunctionSumScorer\n\tat org.apache.lucene.search.join.ToParentBlockJoinQuery$BlockJoinScorer.nextDoc(ToParentBlockJoinQuery.java:344)\n\tat org.apache.lucene.search.Weight$DefaultBulkScorer.scoreAll(Weight.java:192)\n\tat org.apache.lucene.search.Weight$DefaultBulkScorer.score(Weight.java:163)\n\tat org.apache.lucene.search.BulkScorer.score(BulkScorer.java:35)\n\tat org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:621)\n\tat org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:297)\n\tat org.apache.solr.search.SolrIndexSearcher.buildAndRunCollectorChain(SolrIndexSearcher.java:209)\n\tat org.apache.solr.search.SolrIndexSearcher.getDocListNC(SolrIndexSearcher.java:1619)\n\tat org.apache.solr.search.SolrIndexSearcher.getDocListC(SolrIndexSearcher.java:1433)\n\tat org.apache.solr.search.SolrIndexSearcher.search(SolrIndexSearcher.java:514)\n\tat org.apache.solr.handler.component.QueryComponent.process(QueryComponent.java:485)\n\tat org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:218)\n\tat org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:135)\n\tat org.apache.solr.core.SolrCore.execute(SolrCore.java:1967)\n\tat org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:777)\n\tat org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:418)\n\tat org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:207)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419)\n\tat org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:455)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)\n\tat org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)\n\tat org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1075)\n\tat org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384)\n\tat org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)\n\tat org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)\n\tat org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)\n\tat org.eclipse.jetty.server.Server.handle(Server.java:368)\n\tat org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)\n\tat org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:53)\n\tat org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:942)\n\tat org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1004)\n\tat org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:640)\n\tat org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)\n\tat org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:72)\n\tat org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:264)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)\n\tat java.lang.Thread.run(Thread.java:745)\n",
"code": 500
}
}
there is SolrInputDocument.getChildrenDocs() collection or so. use it.
to propagate score from children query to parent ones you need https://issues.apache.org/jira/browse/SOLR-5882
the problem is that functional queries matches every docs, thus it violates orthogonality and causes the exception. intersect children query with +content_type:child

Assigning Default value in DateTime field in TFS

Is it possible to assign DEFAULT rule for DateTime Field while adding a Work Item in TFS? But not using CLOCK value. Giving some Default Date.
Yes, you can do this by hardcoding the value in the Work Item Type Definition. In the appropriate TRANSITION element under the FIELDS\FIELD element for that field, instead of using ServerDefault and clock which you have probably seen like this:
<FIELD refname="Microsoft.VSTS.Common.ActivatedDate">
<SERVERDEFAULT from="clock" />
</FIELD>
try doing this:
<FIELD refname="Microsoft.VSTS.Common.ActivatedDate">
<COPY from"value" value="01-Feb-2014" />
</FIELD>
It is possible, try this:
<FIELD name="Custom Date" refname="Custom.Date" type="DateTime">
<DEFAULT from="value" value="2100-01-01" />
</FIELD>
The date that will be displayed is a day before of whatever date you're setting.

Struts 2 Xml validation: One set of validation on multiple fields

I have lots of number field let say num1, num2 ...
Now I am looking for way I can apply a set of validation on all field rather than writing same validations multiple times.
Here is set of two validation for requiredString and Number check
<validators>
<field name="num1">
<field-validator type="requiredstring">
<message>Field cannot be left blank</message>
</field-validator>
<field-validator type="regex" short-circuit="true">
<param name="expression"><![CDATA[^[0-9]+$]]></param>
<message>Not a valid Number</message>
</field-validator>
</field>
</validators>
Tia

Resources