Re: svn commit: r942076 - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r942076 - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java

Ashish Vijaywargiya
This is very good addition to trunk. Thanks Jacopo!
Sorry, I have missed your commit ;)

--
Ashish

On Fri, May 7, 2010 at 7:38 PM,  <[hidden email]> wrote:

> Author: jacopoc
> Date: Fri May  7 14:08:39 2010
> New Revision: 942076
>
> URL: http://svn.apache.org/viewvc?rev=942076&view=rev
> Log:
> Added ability to override the type, colName and description of an existing entity field using the extend-entity definition.
>
>
> Modified:
>    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java
>
> Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java?rev=942076&r1=942075&r2=942076&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java (original)
> +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java Fri May  7 14:08:39 2010
> @@ -303,13 +303,28 @@ public class ModelEntity extends ModelIn
>
>     public void addExtendEntity(ModelReader reader, Element extendEntityElement) {
>         for (Element fieldElement: UtilXml.childElementList(extendEntityElement, "field")) {
> -            // TODO: should we look for existing fields of the same name here? for now just add to list...
>             ModelField field = reader.createModelField(fieldElement);
>             if (field != null) {
> -                field.setModelEntity(this);
> -                this.fields.add(field);
> -                // this will always be true for now as extend-entity fielsd are always nonpks
> -                if (!field.isPk) this.nopks.add(field);
> +                ModelField existingField = this.getField(field.getName());
> +                if (existingField != null) {
> +                    // override the existing field's attributes
> +                    // TODO: only overrides of type, colName and description are currently supported
> +                    if (UtilValidate.isNotEmpty(field.getType())) {
> +                        existingField.setType(field.getType());
> +                    }
> +                    if (UtilValidate.isNotEmpty(field.getColName())) {
> +                        existingField.setColName(field.getColName());
> +                    }
> +                    if (UtilValidate.isNotEmpty(field.getDescription())) {
> +                        existingField.setDescription(field.getDescription());
> +                    }
> +                } else {
> +                    // add to the entity as a new field
> +                    field.setModelEntity(this);
> +                    this.fields.add(field);
> +                    // this will always be true for now as extend-entity fielsd are always nonpks
> +                    if (!field.isPk) this.nopks.add(field);
> +                }
>             }
>         }
>
>
>
>