<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Consider that a trait is an interface
      applied to some class. In the context of the pair:<br>
      A "hard" field is a property (get/set) exposed by the interface
      AND the underlying class<br>
      A "soft" (or "virtual") field is a property exposed by the
      interface BUT NOT by the underlying class<br>
      A "hidden" field is a field of the underlying class NOT exposed by
      the interface<br>
      <br>
      Hard and Soft fields can be accessed using the interface, hidden
      fields are accessible using the map-like<br>
      construct fields[ "fieldName" ].<br>
      <br>
      This said,<br>
      the mapping is by default done using the property name and (then)
      the property type.<br>
      However, this mapping can be decoupled using the annotation
      @Alias() on either the class OR the trait.<br>
      E.g.<br>
      declare Core <br>
      &nbsp; name : String @Alias( "any-Id-or-even-an-IRI-here" )<br>
      end <br>
      <br>
      declare trait SomeTrait<br>
      &nbsp;&nbsp;&nbsp; label : String @Alias( "..." )&nbsp; // if two "aliases" match,
      this will be considered a hard field<br>
      end<br>
      <br>
      The "accessor", i.e. the ability to bind a trait property to a
      (possibly deeply) nested path is what I'm working<br>
      on these days, I have the same requirement from another urgent use
      case<br>
      <br>
      For the time being, you can probably create a "shortcut" accessor
      pair in your implementation class, <br>
      to execute the complex expression, and @Alias it to the trait
      field.<br>
      <br>
      Please let me know if you find any issue/bugs and any feature
      request you may have!<br>
      Best<br>
      Davide<br>
      <br>
      <br>
      On 05/27/2014 07:57 AM, Horv&aacute;th P&eacute;ter Gergely wrote:<br>
    </div>
    <blockquote
cite="mid:CA+UsspASfF9JVFv-4vigBn9j5+_=urbN3XZqzXsbA59kJ_axJg@mail.gmail.com"
      type="cite">
      <div dir="ltr">Hi&nbsp;Davide,
        <div><br>
        </div>
        <div>Drools trait functionality is one of the powerful concepts
          which makes Drools a good candidate for the project. So keep
          up the good work! :) However I'm not sure if its current level
          of flexibility would be sufficient for our use case. I've
          checked the documentation, but haven't really found the term
          virtual field -- could you please elaborate on this?</div>
        <div><br>
        </div>
        <div>Do you think we could somehow hook into the evaluation of
          the aliases or the "fields" Map? Sometimes you would need
          slightly more than merely aliasing fields to something else;
          e.g. calculating values for the purpose of rule processing or
          extracting a value from a more complex object tree etc. Citing
          the example -- GoldenCustomer( fields[ "age" ] &gt; 18 ) --
          being able to get a reference to the target object and the
          field map expression "age" would be quite close to what I
          imagined. Our custom code could then perform the appropriate
          translation and return the requested value, hiding the fact
          whether "age" is an actual field in the Customer object
          itself/retrieved from an encapsulated complex object e.g.
          replacing expression
          "customer.personalInformation.birthData.age"/calculated on the
          flight. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
        <div><br>
        </div>
        <div>What do you think?</div>
        <div><br>
        </div>
        <div>Cheers,</div>
        <div>Peter</div>
        <div><br>
        </div>
      </div>
      <div class="gmail_extra"><br>
        <br>
        <div class="gmail_quote">2014-05-26 17:58 GMT+02:00 Davide
          Sottara <span dir="ltr">&lt;<a moz-do-not-send="true"
              href="mailto:dsotty@gmail.com" target="_blank">dsotty@gmail.com</a>&gt;</span>:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">We are
            working on the trait framework for cases like this.
            Essentially,<br>
            it allows to use<br>
            interfaces when writing rules AND to inject the interfaces
            dynamically<br>
            at runtime,<br>
            at the instance level. It relies on transparent proxies
            which wrap the<br>
            data classes<br>
            and implement the required interfaces. A simple field
            aliasing mechanism<br>
            is provided<br>
            (work in progress). For more complex transformations,
            "virtual" fields<br>
            can be added.<br>
            See section 7.7.8 of the manual for more details and let me
            know if it<br>
            can help<br>
            with your use case.<br>
            Best,<br>
            Davide<br>
            <div class="HOEnZb">
              <div class="h5"><br>
                On 05/26/2014 09:55 AM, Wolfgang Laun wrote:<br>
                &gt; Even a relatively sophisticated transformation
                would be easier to implement<br>
                &gt; and most certainly safer from changes in the
                unstable Drools API than some<br>
                &gt; hook-and-intercept mechanism built into Drools.<br>
                &gt;<br>
                &gt; Notice that violent structural departure of the
                model the BUs see from what<br>
                &gt; you call "persistence model" might make it
                impossible for the BUs to come<br>
                &gt; up with rules that can be transformed to match the
                other model at all;<br>
                &gt; if it is possible, rules might still incur a heavy
                performance penalty.<br>
                &gt;<br>
                &gt; It is (IMHO) a myth that "Rules" is a foolproof way
                of establishing<br>
                &gt; business logic<br>
                &gt; independent from the data model and application
                environment with which<br>
                &gt; this logic should be able to cooperate. As long as
                everything is kept in the<br>
                &gt; abstract (i.e., formulated in terms of mathematics)
                it will look &nbsp;good, but<br>
                &gt; any implementation may throw a spanner in the
                works, or worse.<br>
                &gt;<br>
                &gt; -W<br>
                &gt;<br>
                &gt; On 26/05/2014, P&eacute;ter Gergely, Horv&aacute;th &lt;<a
                  moz-do-not-send="true"
                  href="mailto:h.peter@mailbox.hu">h.peter@mailbox.hu</a>&gt;
                wrote:<br>
                &gt;&gt; Hi Wolfgang,<br>
                &gt;&gt;<br>
                &gt;&gt; Thank you for your input. You are right that
                some of the cases could simply<br>
                &gt;&gt; be covered by regexp-replace, but I'm afraid,
                not all of them. Interfaces<br>
                &gt;&gt; could also help, but we have a requirement that
                the business rules should<br>
                &gt;&gt; not be tightly coupled to the underlying
                persistence model. (I understand<br>
                &gt;&gt; that some might say this is not ideal, but that
                is our current situation)<br>
                &gt;&gt;<br>
                &gt;&gt; I am wondering whether it is possible to hook
                into Drools engine and<br>
                &gt;&gt; intercept field value reference expression
                evaluations in run time (e.g if<br>
                &gt;&gt; "foo.bars" is used in an expression, we could
                return "foo.barList") ? By<br>
                &gt;&gt; injecting some custom code, we could make the
                necessary decisions and<br>
                &gt;&gt; extract the proper value from an object.
                Unfortunately these parts of<br>
                &gt;&gt; Drools are pretty much undocumented.<br>
                &gt;&gt;<br>
                &gt;&gt; Regards,<br>
                &gt;&gt; Peter<br>
                &gt;&gt;<br>
                &gt;&gt;<br>
                &gt;&gt;<br>
                &gt;&gt; 2014-05-26 13:57 GMT+02:00 Wolfgang Laun &lt;<a
                  moz-do-not-send="true"
                  href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>&gt;:<br>
                &gt;&gt;<br>
                &gt;&gt;&gt; What you describe can be done with
                /bin/sed.<br>
                &gt;&gt;&gt;<br>
                &gt;&gt;&gt; Notice that the DSL processor doesn't
                require you to translate entire<br>
                &gt;&gt;&gt; patterns; there is a mechanism for
                translating "keywords", which is<br>
                &gt;&gt;&gt; just arbitrary tokens to whatever
                replacement text.<br>
                &gt;&gt;&gt;<br>
                &gt;&gt;&gt; If a "bar" must be translated to a
                "barList" in the context of a class<br>
                &gt;&gt;&gt; "Foo" but not in any other context, a more
                sophisticated translation<br>
                &gt;&gt;&gt; is required in any case (with /bin/sed
                still being sufficient if<br>
                &gt;&gt;&gt; patterns aren't split across lines).<br>
                &gt;&gt;&gt;<br>
                &gt;&gt;&gt; Some say that good design makes use of
                Interfaces, which leaves room<br>
                &gt;&gt;&gt; for actual implementations being changed as
                long as the interfaces are<br>
                &gt;&gt;&gt; implemented. Here, note that rules can be
                written against interface<br>
                &gt;&gt;&gt; types.<br>
                &gt;&gt;&gt;<br>
                &gt;&gt;&gt; -W<br>
                &gt;&gt;&gt;<br>
                &gt;&gt;&gt;<br>
                &gt;&gt;&gt; On 26/05/2014, P&eacute;ter Gergely, Horv&aacute;th &lt;<a
                  moz-do-not-send="true"
                  href="mailto:h.peter@mailbox.hu">h.peter@mailbox.hu</a>&gt;
                wrote:<br>
                &gt;&gt;&gt;&gt; Hi All,<br>
                &gt;&gt;&gt;&gt;<br>
                &gt;&gt;&gt;&gt; We are evaluating Drools 6 for our use
                case, and face challenges where<br>
                &gt;&gt;&gt;&gt; we<br>
                &gt;&gt;&gt;&gt; would need some ideas from more
                experienced users of Drools.<br>
                &gt;&gt;&gt;&gt;<br>
                &gt;&gt;&gt;&gt; We have an application with a massive
                code base and a large number of<br>
                &gt;&gt;&gt; model<br>
                &gt;&gt;&gt;&gt; (entity) classes. We are in the process
                of moving away from inherited<br>
                &gt;&gt;&gt;&gt; legacy technologies and refactoring the
                old code base. As a part of<br>
                &gt;&gt;&gt;&gt; this<br>
                &gt;&gt;&gt;&gt; work we would like extract some of the
                hard-coded business logic to<br>
                &gt;&gt;&gt;&gt; external rules, that is why we are
                looking at Drools as a potential<br>
                &gt;&gt;&gt;&gt; solution.<br>
                &gt;&gt;&gt;&gt;<br>
                &gt;&gt;&gt;&gt; What we would like to have is some kind
                of abstraction or mapping<br>
                &gt;&gt;&gt;&gt; between<br>
                &gt;&gt;&gt;&gt; actual entities and rules the business
                users can define so that they do<br>
                &gt;&gt;&gt; not<br>
                &gt;&gt;&gt;&gt; have to know the _exact_ details of the
                data model (field names,<br>
                &gt;&gt;&gt;&gt; precise<br>
                &gt;&gt;&gt;&gt; relations etc). This would be important
                for us so that we can refactor<br>
                &gt;&gt;&gt; the<br>
                &gt;&gt;&gt;&gt; old model classes without affecting
                business rules; also it would make<br>
                &gt;&gt;&gt; life<br>
                &gt;&gt;&gt;&gt; easier for the business users. While
                IDE support might make refactoring<br>
                &gt;&gt;&gt;&gt; easier, we definitely want to have a
                separation between rules and<br>
                &gt;&gt;&gt; entities.<br>
                &gt;&gt;&gt;&gt; Given our situation, writing and
                maintaining "stable" wrapper/adapter<br>
                &gt;&gt;&gt;&gt; classes for the sole purpose of rule
                processing is out of question. I<br>
                &gt;&gt;&gt; have<br>
                &gt;&gt;&gt;&gt; checked the documentation of Drools DSL
                support and for me it seems to<br>
                &gt;&gt;&gt;&gt; be<br>
                &gt;&gt;&gt;&gt; overkill for our use case: we do not
                really need a custom language, but<br>
                &gt;&gt;&gt;&gt; simply an abstraction between rules and
                the data model classes.<br>
                &gt;&gt;&gt;&gt;<br>
                &gt;&gt;&gt;&gt; What I could imagine is a piece of
                code, (a custom property resolver? -<br>
                &gt;&gt;&gt; no<br>
                &gt;&gt;&gt;&gt; sure how it is called) which maps
                property expressions to actual<br>
                &gt;&gt;&gt; properties<br>
                &gt;&gt;&gt;&gt; based on a custom annotation on the
                entity class or something like<br>
                &gt;&gt;&gt;&gt; that,<br>
                &gt;&gt;&gt; so<br>
                &gt;&gt;&gt;&gt; that a rule containing "Foo.bars"
                expression does not have to change<br>
                &gt;&gt;&gt;&gt; even<br>
                &gt;&gt;&gt;&gt; if we decide to rename "Foo.bars" to
                "Foo.barList" in the model<br>
                &gt;&gt;&gt;&gt; classes.<br>
                &gt;&gt;&gt;&gt; (This was just a simple example of a
                potential use cases)<br>
                &gt;&gt;&gt;&gt;<br>
                &gt;&gt;&gt;&gt; Could you please share your thoughts on
                this topic and point me into<br>
                &gt;&gt;&gt;&gt; the<br>
                &gt;&gt;&gt;&gt; right direction?<br>
                &gt;&gt;&gt;&gt;<br>
                &gt;&gt;&gt;&gt; Thanks,<br>
                &gt;&gt;&gt;&gt; Peter<br>
                &gt;&gt;&gt;&gt;<br>
                &gt;&gt;&gt;
                _______________________________________________<br>
                &gt;&gt;&gt; rules-users mailing list<br>
                &gt;&gt;&gt; <a moz-do-not-send="true"
                  href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
                &gt;&gt;&gt; <a moz-do-not-send="true"
                  href="https://lists.jboss.org/mailman/listinfo/rules-users"
                  target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
                &gt;&gt;&gt;<br>
                &gt; _______________________________________________<br>
                &gt; rules-users mailing list<br>
                &gt; <a moz-do-not-send="true"
                  href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
                &gt; <a moz-do-not-send="true"
                  href="https://lists.jboss.org/mailman/listinfo/rules-users"
                  target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
                &gt;<br>
                <br>
                _______________________________________________<br>
                rules-users mailing list<br>
                <a moz-do-not-send="true"
                  href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
                <a moz-do-not-send="true"
                  href="https://lists.jboss.org/mailman/listinfo/rules-users"
                  target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
              </div>
            </div>
          </blockquote>
        </div>
        <br>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a></pre>
    </blockquote>
    <br>
  </body>
</html>