diff --git a/src/main/java/module/mailtracking/presentationTier/MailTrackingAction.java b/src/main/java/module/mailtracking/presentationTier/MailTrackingAction.java index a6c099d..c5a42e2 100644 --- a/src/main/java/module/mailtracking/presentationTier/MailTrackingAction.java +++ b/src/main/java/module/mailtracking/presentationTier/MailTrackingAction.java @@ -44,6 +44,8 @@ import module.mailtracking.domain.exception.PermissionDeniedException; import org.apache.commons.beanutils.BeanComparator; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.Predicate; import org.apache.commons.lang.StringUtils; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; @@ -258,7 +260,7 @@ public ActionForward addNewEntry(final ActionMapping mapping, final ActionForm f throw new PermissionDeniedException(); } - if (!preValidate(readCorrespondenceEntryBean(request), request)) { + if (!preValidate(readCorrespondenceEntryBean(request), request, readCorrespondenceTypeView(request))) { RenderUtils.invalidateViewState("associate.document.bean"); setAssociateDocumentBean(request, null); return prepareCreateNewEntry(mapping, form, request, response); @@ -301,7 +303,8 @@ public ActionForward addNewEntryInvalid(final ActionMapping mapping, final Actio private static final Integer MAX_SENDER_SIZE = 50; private static final Integer MAX_RECIPIENT_SIZE = 50; - protected boolean preValidate(CorrespondenceEntryBean correspondenceEntryBean, HttpServletRequest request) { + protected boolean preValidate(CorrespondenceEntryBean correspondenceEntryBean, HttpServletRequest request, + CorrespondenceType correspondenceType) { if (StringUtils.isEmpty(correspondenceEntryBean.getSender())) { addMessage(request, "error.mail.tracking.sender.is.required"); return false; @@ -323,6 +326,22 @@ protected boolean preValidate(CorrespondenceEntryBean correspondenceEntryBean, H return false; } + final String reference = correspondenceEntryBean.getReference(); + final CorrespondenceEntry entry = correspondenceEntryBean.getEntry(); + + if (CollectionUtils.select(correspondenceEntryBean.getMailTracking().getActiveEntries(correspondenceType), + new Predicate() { + + @Override + public boolean evaluate(Object arg0) { + return ((CorrespondenceEntry) arg0).getReference().equals(reference) + && ((CorrespondenceEntry) arg0) != entry; // if they are the same + } + }).size() >= 1) { + addMessage(request, "error.mail.tracking.reference.duplicated"); + return false; + } + return true; } @@ -343,7 +362,7 @@ public final ActionForward editEntry(final ActionMapping mapping, final ActionFo final HttpServletResponse response) throws Exception { MailTracking mailTracking = readMailTracking(request); - if (!preValidate(readCorrespondenceEntryBean(request), request)) { + if (!preValidate(readCorrespondenceEntryBean(request), request, readCorrespondenceTypeView(request))) { return prepareEditEntry(mapping, form, request, response); } diff --git a/src/main/java/module/mailtracking/presentationTier/ajax/MailTrackingAction.java b/src/main/java/module/mailtracking/presentationTier/ajax/MailTrackingAction.java index 6474425..f0a5e11 100644 --- a/src/main/java/module/mailtracking/presentationTier/ajax/MailTrackingAction.java +++ b/src/main/java/module/mailtracking/presentationTier/ajax/MailTrackingAction.java @@ -75,7 +75,7 @@ public final ActionForward addNewEntry(final ActionMapping mapping, final Action throw new PermissionDeniedException(); } - if (!preValidate(readCorrespondenceEntryBean(request), request)) { + if (!preValidate(readCorrespondenceEntryBean(request), request, readCorrespondenceTypeView(request))) { RenderUtils.invalidateViewState("associate.document.bean"); setAssociateDocumentBean(request, null); return prepareCreateNewEntry(mapping, form, request, response); diff --git a/src/main/resources/resources/MailTrackingResources.properties b/src/main/resources/resources/MailTrackingResources.properties index 9dfb51c..9a73d1b 100644 --- a/src/main/resources/resources/MailTrackingResources.properties +++ b/src/main/resources/resources/MailTrackingResources.properties @@ -128,6 +128,7 @@ label.reason=Motivo messsage.mail.tracking.deletion.reason.necessary=Indique o motivo remoção deste registo error.mail.tracking.sender.is.required=O remetente é obrigatório +error.mail.tracking.reference.duplicated=A referência já existe error.mail.tracking.sender.length.must.be.less.than=O tamanho máximo para o campo remetente é de {0} error.mail.tracking.recipient.is.required=O destinatário é obrigatório error.mail.tracking.recipient.length.must.be.less.than=O tamanho máximo para o campo de destinatário é de {0} diff --git a/src/main/webapp/mailtracking/editCorrespondenceEntry.jsp b/src/main/webapp/mailtracking/editCorrespondenceEntry.jsp index 8dcb4d4..33637b6 100644 --- a/src/main/webapp/mailtracking/editCorrespondenceEntry.jsp +++ b/src/main/webapp/mailtracking/editCorrespondenceEntry.jsp @@ -28,7 +28,7 @@ - + " >