You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ml...@apache.org on 2024/08/30 07:53:10 UTC
(ofbiz-framework) branch trunk updated: Improved: Allow to define a view link condition when creating a dve (OFBIZ-13125)
This is an automated email from the ASF dual-hosted git repository.
mleila pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push:
new 31eb051326 Improved: Allow to define a view link condition when creating a dve (OFBIZ-13125)
31eb051326 is described below
commit 31eb051326bcec29f4c932a6d829e0d7c9979a16
Author: MLeila <ml...@apache.org>
AuthorDate: Fri Aug 30 09:53:05 2024 +0200
Improved: Allow to define a view link condition when creating a dve (OFBIZ-13125)
this PR adds the possibility to use the ViewEntityCondition definition
when creating a DynamicView
---
.../ofbiz/entity/model/DynamicViewEntity.java | 71 +++++++++++++++++++++-
.../apache/ofbiz/entity/model/ModelViewEntity.java | 66 ++++++++++++++++++++
2 files changed, 136 insertions(+), 1 deletion(-)
diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/model/DynamicViewEntity.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/model/DynamicViewEntity.java
index 9729491d56..d0753b5038 100644
--- a/framework/entity/src/main/java/org/apache/ofbiz/entity/model/DynamicViewEntity.java
+++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/model/DynamicViewEntity.java
@@ -34,6 +34,7 @@ import org.apache.ofbiz.entity.model.ModelViewEntity.ModelAlias;
import org.apache.ofbiz.entity.model.ModelViewEntity.ModelAliasAll;
import org.apache.ofbiz.entity.model.ModelViewEntity.ModelMemberEntity;
import org.apache.ofbiz.entity.model.ModelViewEntity.ModelViewLink;
+import org.apache.ofbiz.entity.model.ModelViewEntity.ViewEntityCondition;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
@@ -351,10 +352,78 @@ public class DynamicViewEntity {
* @param modelKeyMaps the model key maps
*/
public void addViewLink(String entityAlias, String relEntityAlias, Boolean relOptional, List<ModelKeyMap> modelKeyMaps) {
- ModelViewLink modelViewLink = new ModelViewLink(entityAlias, relEntityAlias, relOptional, null, modelKeyMaps);
+ addViewLink(entityAlias, relEntityAlias, relOptional, modelKeyMaps, null);
+ }
+
+ /**
+ * Add view link.
+ * @param entityAlias the entity alias
+ * @param relEntityAlias the rel entity alias
+ * @param relOptional the rel optional
+ * @param viewCond the condition of the view link
+ */
+ public void addViewLink(String entityAlias, String relEntityAlias, Boolean relOptional, ViewEntityCondition viewCond) {
+ addViewLink(entityAlias, relEntityAlias, relOptional, new ArrayList<ModelKeyMap>(), viewCond);
+ }
+
+ /**
+ * Add view link.
+ * @param entityAlias the entity alias
+ * @param relEntityAlias the rel entity alias
+ * @param relOptional the rel optional
+ * @param modelKeyMaps the model key maps
+ * @param viewCond the condition of the view link
+ */
+ public void addViewLink(String entityAlias, String relEntityAlias, Boolean relOptional,
+ List<ModelKeyMap> modelKeyMaps, ViewEntityCondition viewCond) {
+ ModelViewLink modelViewLink = new ModelViewLink(entityAlias, relEntityAlias, relOptional, viewCond, modelKeyMaps);
this.viewLinks.add(modelViewLink);
}
+ /**
+ * Prepare a ViewEntityCondition to use in view link
+ * @param delegator
+ * @param entityAlias
+ * @param fieldName
+ * @param operator
+ * @param value
+ * @return
+ */
+ public ViewEntityCondition makeViewEntityCondition(Delegator delegator, String entityAlias, String fieldName, String operator, String value) {
+ Element entityConditionExpr = ViewEntityCondition.makeViewEntityConditionExpr(entityAlias, fieldName, operator, value, "", "");
+ return makeViewEntityCondition(delegator, entityConditionExpr);
+ }
+
+ /**
+ * Prepare a ViewEntityCondition to use in view link
+ * @param delegator
+ * @param entityAlias
+ * @param fieldName
+ * @param operator
+ * @param relEntityAlias
+ * @param relFieldName
+ * @return
+ */
+ public ViewEntityCondition makeViewEntityCondition(Delegator delegator, String entityAlias, String fieldName, String operator,
+ String relEntityAlias, String relFieldName) {
+ Element entityConditionExpr = ViewEntityCondition
+ .makeViewEntityConditionExpr(entityAlias, fieldName, operator, "", relEntityAlias, relFieldName);
+ return makeViewEntityCondition(delegator, entityConditionExpr);
+ }
+
+ /**
+ * Prepare a ViewEntityCondition to use in view link
+ * @param delegator
+ * @param entityConditionElement
+ * @return
+ */
+ public ViewEntityCondition makeViewEntityCondition(Delegator delegator, Element entityConditionElement) {
+ if (!"entity-condition".equals(entityConditionElement.getNodeName())) {
+ entityConditionElement = ViewEntityCondition.makeViewEntityCondition(entityConditionElement);
+ }
+ return new ViewEntityCondition(this.makeModelViewEntity(delegator), null, entityConditionElement);
+ }
+
/**
* Add all view links to list.
* @param addList the add list
diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/model/ModelViewEntity.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/model/ModelViewEntity.java
index e35a547d15..82011fc077 100644
--- a/framework/entity/src/main/java/org/apache/ofbiz/entity/model/ModelViewEntity.java
+++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/model/ModelViewEntity.java
@@ -46,6 +46,7 @@ import org.apache.ofbiz.entity.condition.EntityJoinOperator;
import org.apache.ofbiz.entity.condition.EntityOperator;
import org.apache.ofbiz.entity.jdbc.SqlJdbcUtil;
import org.apache.ofbiz.entity.util.EntityUtil;
+import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
@@ -1470,6 +1471,71 @@ public class ModelViewEntity extends ModelEntity {
return null;
}
}
+
+ public static Element makeViewEntityCondition(Element child) {
+ return makeViewEntityCondition(List.of(child));
+ }
+
+ public static Element makeViewEntityCondition(List<Element> children) {
+ Document doc = children.get(0).getOwnerDocument();
+ Element entityConditionElement = doc.createElement("entity-condition");
+ for (Element child : children) {
+ if (child.getOwnerDocument() != doc) {
+ child = (Element) doc.importNode(child, true);
+ }
+ entityConditionElement.appendChild(child);
+ }
+ return entityConditionElement;
+ }
+
+ public static Element makeViewEntityConditionList(String combine, List<Element> children) {
+ Document doc = children.get(0).getOwnerDocument();
+ Element conditionListElement = doc.createElement("condition-list");
+ if (UtilValidate.isNotEmpty(combine)) {
+ conditionListElement.setAttribute("combine", combine);
+ }
+ for (Element child : children) {
+ if (child.getOwnerDocument() != doc) {
+ child = (Element) doc.importNode(child, true);
+ }
+ conditionListElement.appendChild(child);
+ }
+ return conditionListElement;
+ }
+
+ public static Element makeViewEntityConditionExpr(String entityAlias, String fieldName, String operator, String value) {
+ return makeViewEntityConditionExpr(entityAlias, fieldName, operator, value, null, null);
+ }
+
+ public static Element makeViewEntityConditionExpr(String entityAlias, String fieldName, String operator,
+ String relEntityAlias, String relFieldName) {
+ return makeViewEntityConditionExpr(entityAlias, fieldName, operator, null, relEntityAlias, relFieldName);
+ }
+
+ public static Element makeViewEntityConditionExpr(String entityAlias, String fieldName, String operator,
+ String value, String relEntityAlias, String relFieldName) {
+ Document doc = UtilXml.makeEmptyXmlDocument();
+ Element conditionExprElement = doc.createElement("condition-expr");
+ if (UtilValidate.isNotEmpty(entityAlias)) {
+ conditionExprElement.setAttribute("entity-alias", entityAlias);
+ }
+ if (UtilValidate.isNotEmpty(fieldName)) {
+ conditionExprElement.setAttribute("field-name", fieldName);
+ }
+ if (UtilValidate.isNotEmpty(operator)) {
+ conditionExprElement.setAttribute("operator", operator);
+ }
+ if (UtilValidate.isNotEmpty(value)) {
+ conditionExprElement.setAttribute("value", value);
+ }
+ if (UtilValidate.isNotEmpty(relEntityAlias)) {
+ conditionExprElement.setAttribute("rel-entity-alias", relEntityAlias);
+ }
+ if (UtilValidate.isNotEmpty(relFieldName)) {
+ conditionExprElement.setAttribute("rel-field-name", relFieldName);
+ }
+ return conditionExprElement;
+ }
}
public interface ViewCondition extends Serializable {