Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/8 #9

Merged
merged 2 commits into from
Mar 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Common's CollectionUtils, while perfectly functional, should be avoided.

You could instead use Guava's Iterables class see here to perform this operation. It provides a much cleaner API, and lazily evaluates the collection, in a much more efficient manner.

Note that I am not saying you should change what you have done here, just leaving it for future reference :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just saw it CollectionUtils was being used in some parts of the code, so I just followed it.

But I'll use Iterables next time, thanks for the tip ;)

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;
}

Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/mailtracking/editCorrespondenceEntry.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</div>


<fr:form id="add.new.entry.form" action="<%= "/mailtracking.do?method=editEntry&amp;mailTrackingId=" + mailTrackingId + "&amp;correspondenceType=" + correspondenceType %>">
<fr:form id="add.new.entry.form" action="<%= "/mailtracking.do?method=editEntry&amp;mailTrackingId=" + mailTrackingId + "&amp;entryId="+ entryId + "&amp;correspondenceType=" + correspondenceType %>">
<fr:edit id="correspondence.entry.bean" name="correspondenceEntryBean" visible="false" />

<fr:edit id="correspondence.entry.bean.data" name="correspondenceEntryBean" schema="<%= CorrespondenceType.RECEIVED.name().equals(correspondenceType) ? "module.mailtracking.correspondence.received.entry.edit" : "module.mailtracking.correspondence.sent.entry.edit" %>" >
Expand Down