From 5e3584d1e30d8ae3f13ffda9697204c8d955e601 Mon Sep 17 00:00:00 2001 From: Gil Portenseigne Date: Fri, 26 Jan 2018 15:48:02 +0000 Subject: [PATCH] Improved: When completing communicationEvent through setCommEventComplete, if datetimeEnded is null, set it to nowTimestamp (OFBIZ-10181) git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1822316 13f79535-47bb-0310-9956-ffa450edef68 --- applications/party/servicedef/services.xml | 3 ++- .../communication/CommunicationEventServices.java | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/applications/party/servicedef/services.xml b/applications/party/servicedef/services.xml index 1967e03e12..42ec441cce 100644 --- a/applications/party/servicedef/services.xml +++ b/applications/party/servicedef/services.xml @@ -939,7 +939,8 @@ under the License. - Sets the status of a communication event to COM_COMPLETE using the updateCommunicationEvent service + Sets the status of a communication event to COM_COMPLETE using the updateCommunicationEvent service, + set datetimeEnded to now if not defined diff --git a/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java b/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java index 41721bafa0..e5ab27b26d 100644 --- a/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java +++ b/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java @@ -508,17 +508,27 @@ public class CommunicationEventServices { public static Map setCommEventComplete(DispatchContext dctx, Map context) { LocalDispatcher dispatcher = dctx.getDispatcher(); + Delegator delegator = dctx.getDelegator(); GenericValue userLogin = (GenericValue) context.get("userLogin"); String communicationEventId = (String) context.get("communicationEventId"); String partyIdFrom = (String) context.get("partyIdFrom"); try { + GenericValue communicationEvent = delegator.findOne("CommunicationEvent", true, "communicationEventId", communicationEventId); + if (communicationEvent == null) { + return ServiceUtil.returnError(UtilProperties.getMessage("PartyUiLabels", "PartyCommunicationEventNotFound", + UtilMisc.toMap("communicationEventId", communicationEventId), (Locale) context.get("locale"))); + } + Timestamp endDate = communicationEvent.getTimestamp("datetimeEnded"); + if (endDate == null) { + endDate = UtilDateTime.nowTimestamp(); + } Map result = dispatcher.runSync("updateCommunicationEvent", UtilMisc.toMap("communicationEventId", communicationEventId, - "partyIdFrom", partyIdFrom, "statusId", "COM_COMPLETE", "userLogin", userLogin)); + "partyIdFrom", partyIdFrom, "statusId", "COM_COMPLETE", "datetimeEnded", endDate, "userLogin", userLogin)); if (ServiceUtil.isError(result)) { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result)); } - } catch (GenericServiceException esx) { + } catch (GeneralException esx) { return ServiceUtil.returnError(esx.getMessage()); }