This is an automated email from the ASF dual-hosted git repository.
nmalin 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 2b684ba379 Improved: Add possibility to filter by date on
PartyContentWrapper class
2b684ba379 is described below
commit 2b684ba37941fbcfa0164b5555f39922e022ccf2
Author: Nicolas Malin <[email protected]>
AuthorDate: Tue Nov 19 11:44:29 2024 +0100
Improved: Add possibility to filter by date on PartyContentWrapper class
For method PartyContentWrapper::getFirstPartyContentByType add dateTime
parameter to add possibility to retrieve a dated content
This is useful for document generated at date (like invoice, purchase
order) on custom plugin
---
.../ofbiz/party/content/PartyContentWrapper.java | 27 +++++++++++-----------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git
a/applications/party/src/main/java/org/apache/ofbiz/party/content/PartyContentWrapper.java
b/applications/party/src/main/java/org/apache/ofbiz/party/content/PartyContentWrapper.java
index 8ee3e93548..978e3c29a2 100644
---
a/applications/party/src/main/java/org/apache/ofbiz/party/content/PartyContentWrapper.java
+++
b/applications/party/src/main/java/org/apache/ofbiz/party/content/PartyContentWrapper.java
@@ -22,6 +22,7 @@ package org.apache.ofbiz.party.content;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
+import java.sql.Timestamp;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@@ -34,6 +35,7 @@ import org.apache.ofbiz.base.util.Debug;
import org.apache.ofbiz.base.util.GeneralException;
import org.apache.ofbiz.base.util.GeneralRuntimeException;
import org.apache.ofbiz.base.util.StringUtil;
+import org.apache.ofbiz.base.util.UtilDateTime;
import org.apache.ofbiz.base.util.UtilHttp;
import org.apache.ofbiz.base.util.UtilValidate;
import org.apache.ofbiz.base.util.cache.UtilCache;
@@ -43,7 +45,6 @@ import org.apache.ofbiz.entity.Delegator;
import org.apache.ofbiz.entity.GenericValue;
import org.apache.ofbiz.entity.condition.EntityCondition;
import org.apache.ofbiz.entity.util.EntityQuery;
-import org.apache.ofbiz.entity.util.EntityUtil;
import org.apache.ofbiz.service.LocalDispatcher;
/**
@@ -287,6 +288,11 @@ public class PartyContentWrapper implements ContentWrapper
{
}
public static GenericValue getFirstPartyContentByType(String partyId,
GenericValue party, String partyContentTypeId, Delegator delegator) {
+ return getFirstPartyContentByType(partyId, party, partyContentTypeId,
delegator, UtilDateTime.nowTimestamp());
+ }
+
+ public static GenericValue getFirstPartyContentByType(String partyId,
GenericValue party, String partyContentTypeId,
+ Delegator delegator,
Timestamp date) {
if (partyId == null && party != null) {
partyId = party.getString("partyId");
}
@@ -298,24 +304,19 @@ public class PartyContentWrapper implements
ContentWrapper {
if (delegator == null) {
throw new IllegalArgumentException("Delegator missing");
}
-
- List<GenericValue> partyContentList = null;
try {
- partyContentList = EntityQuery.use(delegator).from("PartyContent")
+ return EntityQuery.use(delegator).from("PartyContent")
.where("partyId", partyId, "partyContentTypeId",
partyContentTypeId)
.orderBy("-fromDate")
- .cache(true)
- .queryList();
+ .filterByDate(date == null
+ ? UtilDateTime.nowTimestamp()
+ : date)
+ .cache()
+ .queryFirst();
} catch (GeneralException e) {
Debug.logError(e, MODULE);
}
-
- if (partyContentList != null) {
- partyContentList = EntityUtil.filterByDate(partyContentList);
- return EntityUtil.getFirst(partyContentList);
- } else {
- return null;
- }
+ return null;
}
public static PartyContentWrapper makePartyContentWrapper(GenericValue
party, HttpServletRequest request) {