Skip to content
Permalink
Browse files

Improved: Change current view-link requirement to allow use of

entity-condition only in view-entities
(OFBIZ-11179)



To explain the subject, i will give an example encountered recently:

We used, for a customer project, a view with Agreement, Virtual and Variant 
product entities and where the agreement can be attached to a virtual OR a 
variant product.
So to make a view returning Variant Product, Virtual Product AND Agreement 
informations, i could not create a view, as the key-map link is mandatory and 
made it impossible.

I can not have an alternative relation to the same entity so we have to 
duplicate member-entity and an alternative relation path. 
The result is a complicated and ugly entity-view

I think this can have been much simpler if i could have done it directly 
through the entity-condition (see the AGPA/PDTA view link in attached file 
ExampleWithoutKeyMap.xml)

So the purpose is to add the possibility to create a view-link without key map,  
if there is an entity-condition.

You can test by applying the given patch and add the entity view from attached 
file ExampleWithoutKeyMap.xml

Thanks: Leila Mekika

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1866439 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
JacquesLeRoux committed Sep 5, 2019
1 parent 5fb61ec commit 180ca716ccd4f49e6233518b9369d7387c18feb0
@@ -384,7 +384,7 @@ under the License.
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" ref="description"/>
<xs:element maxOccurs="unbounded" ref="key-map"/>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="key-map"/>
<xs:element minOccurs="0" ref="entity-condition"/>
</xs:sequence>
<xs:attributeGroup ref="attlist.view-link"/>
@@ -193,6 +193,7 @@ public static String makeFromClause(ModelEntity modelEntity, ModelFieldTypeReade

StringBuilder condBuffer = new StringBuilder();

ModelViewEntity.ViewEntityCondition viewEntityCondition = viewLink.getViewEntityCondition();
for (int j = 0; j < viewLink.getKeyMapsSize(); j++) {
ModelKeyMap keyMap = viewLink.getKeyMap(j);
ModelField linkField = linkEntity.getField(keyMap.getFieldName());
@@ -218,14 +219,13 @@ public static String makeFromClause(ModelEntity modelEntity, ModelFieldTypeReade
condBuffer.append(".");
condBuffer.append(relLinkField.getColName());
}
if (condBuffer.length() == 0) {
if (condBuffer.length() == 0 && viewEntityCondition == null) {
throw new GenericModelException("No view-link/join key-maps found for the " + viewLink.getEntityAlias() + " and the " + viewLink.getRelEntityAlias() + " member-entities of the " + modelViewEntity.getEntityName() + " view-entity.");
}

ModelViewEntity.ViewEntityCondition viewEntityCondition = viewLink.getViewEntityCondition();
if (viewEntityCondition != null) {
EntityCondition whereCondition = viewEntityCondition.getWhereCondition(modelFieldTypeReader, null);
condBuffer.append(" AND ");
if (condBuffer.length() > 0) condBuffer.append(" AND ");
condBuffer.append(whereCondition.makeWhereString(modelEntity, null, datasourceInfo));
}

0 comments on commit 180ca71

Please sign in to comment.
You can’t perform that action at this time.