You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by nm...@apache.org on 2016/01/13 13:43:13 UTC
svn commit: r1724413 -
/ofbiz/branches/release13.07/applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java
Author: nmalin
Date: Wed Jan 13 12:43:12 2016
New Revision: 1724413
URL: http://svn.apache.org/viewvc?rev=1724413&view=rev
Log:
Correct the service CommunicationServices.createAttachmentContent that duplicates attachments for existing CommunicationEvents. Issue reported and solved by Gareth Carter on issue OFBIZ-6697.Backport from trunk
Modified:
ofbiz/branches/release13.07/applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java
Modified: ofbiz/branches/release13.07/applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java?rev=1724413&r1=1724412&r2=1724413&view=diff
==============================================================================
--- ofbiz/branches/release13.07/applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java (original)
+++ ofbiz/branches/release13.07/applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java Wed Jan 13 12:43:12 2016
@@ -26,6 +26,7 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.nio.ByteBuffer;
import java.sql.Timestamp;
+import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;
@@ -645,8 +646,8 @@ public class CommunicationEventServices
// attachments
try {
- createAttachmentContent(dispatcher, wrapper, communicationEventId, userLogin);
- } catch (GenericServiceException e) {
+ createAttachmentContent(dispatcher, dctx.getDelegator(), wrapper, communicationEventId, userLogin);
+ } catch (GenericServiceException | GenericEntityException e) {
return ServiceUtil.returnError(e.getMessage());
}
@@ -903,7 +904,7 @@ public class CommunicationEventServices
Debug.logInfo("Persisting New Email: " + aboutThisEmail + " into CommunicationEventId: " + communicationEventId, module);
// handle the attachments
- createAttachmentContent(dispatcher, wrapper, communicationEventId, userLogin);
+ createAttachmentContent(dispatcher, delegator, wrapper, communicationEventId, userLogin);
// For all addresses create a CommunicationEventRoles
createCommEventRoles(userLogin, delegator, dispatcher, communicationEventId, toParties, "ADDRESSEE");
@@ -974,14 +975,34 @@ public class CommunicationEventServices
if (UtilValidate.isNotEmpty(bccString)) commEventMap.put("bccString", bccString);
}
- private static void createAttachmentContent(LocalDispatcher dispatcher, MimeMessageWrapper wrapper, String communicationEventId, GenericValue userLogin) throws GenericServiceException {
+ private static List<String> getCommEventAttachmentNames(Delegator delegator, String communicationEventId) throws GenericEntityException {
+ List<GenericValue> commEventContentAssocList = delegator.findList("CommEventContentDataResource", EntityCondition.makeCondition("communicationEventId", communicationEventId), null, null, null, false);
+ commEventContentAssocList = EntityUtil.filterByDate(commEventContentAssocList);
+
+ List<String> attachmentNames = new ArrayList<String>();
+ for (GenericValue commEventContentAssoc : commEventContentAssocList) {
+ String dataResourceName = commEventContentAssoc.getString("drDataResourceName");
+ attachmentNames.add(dataResourceName);
+ }
+
+ return attachmentNames;
+ }
+
+ private static void createAttachmentContent(LocalDispatcher dispatcher, Delegator delegator, MimeMessageWrapper wrapper, String communicationEventId, GenericValue userLogin) throws GenericServiceException, GenericEntityException {
// handle the attachments
String subject = wrapper.getSubject();
List<String> attachmentIndexes = wrapper.getAttachmentIndexes();
+ List<String> currentAttachmentNames = getCommEventAttachmentNames(delegator, communicationEventId);
if (attachmentIndexes.size() > 0) {
Debug.logInfo("=== message has attachments [" + attachmentIndexes.size() + "] =====", module);
for (String attachmentIdx : attachmentIndexes) {
+ String attFileName = wrapper.getPartFilename(attachmentIdx);
+ if (currentAttachmentNames.contains(attFileName)) {
+ Debug.logWarning(String.format("CommunicationEvent [%s] already has attachment named '%s'", communicationEventId, attFileName), module);
+ continue;
+ }
+
Map<String, Object> attachmentMap = FastMap.newInstance();
attachmentMap.put("communicationEventId", communicationEventId);
attachmentMap.put("contentTypeId", "DOCUMENT");
@@ -991,7 +1012,6 @@ public class CommunicationEventServices
subject = subject.substring(0,80); // make sure not too big for database field. (20 characters for filename)
}
- String attFileName = wrapper.getPartFilename(attachmentIdx);
String attContentType = wrapper.getPartContentType(attachmentIdx);
if (attContentType != null && attContentType.indexOf(";") > -1) {
attContentType = attContentType.toLowerCase().substring(0, attContentType.indexOf(";"));