<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Apr 5, 2017 at 9:06 PM Moti Asayag &lt;<a href="mailto:masayag@redhat.com">masayag@redhat.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg">Hi All,<br class="gmail_msg"><br class="gmail_msg"></div>ATM, there are 78 occurrences of &quot;Injector.injectMembers(new AuditLogableBase())&quot; in ovirt-engine project, which their main purpose is to ease the resolve of the placeholders of the audit log message while logging an event.<br class="gmail_msg"><br class="gmail_msg"></div>For instance AuditLogType.MAC_ADDRESS_IS_EXTERNAL is being used from ImportVmCommandBase.java in the following way:<br class="gmail_msg"><br class="gmail_msg">private AuditLogableBase createExternalMacsAuditLog(VM vm, Set&lt;String&gt; externalMacs) {<br class="gmail_msg">        AuditLogableBase logable = <b class="gmail_msg">Injector.injectMembers</b>(new AuditLogableBase());<br class="gmail_msg">        logable.setVmId(vm.getId());<br class="gmail_msg">        logable.setCustomCommaSeparatedValues(&quot;MACAddr&quot;, externalMacs);<br class="gmail_msg">        return logable;<br class="gmail_msg">    }<br class="gmail_msg" clear="all"><div class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg">The entry in the properties file is:<br class="gmail_msg">MAC_ADDRESS_IS_EXTERNAL=VM ${<b class="gmail_msg">VmName</b>} has MAC address(es) ${MACAddr}, which is/are out of its MAC pool definitions.<br class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Therefore the only purpose of the injection is to allow the AuditLogDirector to resolve the ${<b class="gmail_msg">VmName</b>} which is already known at the time of creating the AuditLogableBase entry.<br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">The result is injecting the DAOs for the AuditLogableBase instance and using the VM dao to retrieve the VM entry from the DB.<br class="gmail_msg"></div><div class="gmail_msg">This is just a wastef of injection and DB access while both can be spared.<br class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">This could have been easily replaced by one of the following:<br class="gmail_msg"><ul class="gmail_msg"><li class="gmail_msg">auditLogableBase.setVmName(vm.getName());</li></ul></div></div></div></div></blockquote><div>- setVmName is protected so not usable as is  <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><ul class="gmail_msg"><li class="gmail_msg">auditLogableBase.addCustomValue(&quot;VmName&quot;, vm.getName());</li></ul></div></div></div></div></blockquote><div>I prefer this, it is readable. and BTW it is fluent, it returns &#39;this&#39; so use<br><br></div><div>  AuditLogDirector(new AuditLogableBase(type)<br>      .addCustomValue(&quot;VmName&quot;, vm.getName()));</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><p class="gmail_msg">Please pick up any occurrence from your domain and send a patch to replace it where possible.<br class="gmail_msg"></p></div><div class="gmail_msg">Thanks in advance,<br class="gmail_msg"><div class="m_5996702152823124421gmail_signature gmail_msg"><div dir="ltr" class="gmail_msg">Moti<br class="gmail_msg"></div></div></div></div></div></div></blockquote><div><br></div><div>+1<br><br></div><div>Frankly the fact that all the DAOs sets protected access in AuditLogableBase is a total abuse. Every command should declare its own deps. <br></div></div><div class="gmail_quote"><br></div><div class="gmail_quote">_______________________________________________<br class="gmail_msg"></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Devel mailing list<br class="gmail_msg">
<a href="mailto:Devel@ovirt.org" class="gmail_msg" target="_blank">Devel@ovirt.org</a><br class="gmail_msg">
<a href="http://lists.ovirt.org/mailman/listinfo/devel" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.ovirt.org/mailman/listinfo/devel</a></blockquote></div></div>