Bug #1443: Review other places where InvalidValue is used and mark to translate

Move some code to print errors from OrderCRUDController to SaveCommandBuilder
as it was not been used in OrderCRUDController anymore.

FEA: ItEr76S04BugFixing
This commit is contained in:
Manuel Rego Casasnovas 2012-06-28 08:22:42 +02:00
parent 30292b062a
commit f1c21413f6
17 changed files with 87 additions and 110 deletions

View file

@ -20,7 +20,6 @@
*/
package org.libreplan.business.orders.entities;
import org.hibernate.validator.NotEmpty;
/**
* @author Óscar González Fernández <ogonzalez@igalia.com>
@ -38,7 +37,6 @@ public class InfoComponent {
this.name = name;
}
@NotEmpty(message = "name not specified")
public String getName() {
return name;
}

View file

@ -18,7 +18,6 @@
*/
package org.libreplan.business.orders.entities;
import org.hibernate.validator.NotEmpty;
/**
* @author Jacobo Aragunde Pérez <jaragunde@igalia.com>
@ -31,7 +30,6 @@ public class InfoComponentWithCode extends InfoComponent {
this.code = code;
}
@NotEmpty(message = "code not specified")
public String getCode() {
return code;
}

View file

@ -37,6 +37,7 @@ import java.util.Set;
import org.apache.commons.lang.Validate;
import org.hibernate.validator.AssertTrue;
import org.hibernate.validator.InvalidValue;
import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.Valid;
import org.joda.time.LocalDate;
import org.libreplan.business.advance.bootstrap.PredefinedAdvancedTypes;
@ -515,6 +516,7 @@ public abstract class OrderElement extends IntegrationEntity implements
public abstract List<HoursGroup> getHoursGroups();
@NotEmpty(message = "name not specified")
public String getName() {
return getInfoComponent().getName();
}
@ -582,6 +584,7 @@ public abstract class OrderElement extends IntegrationEntity implements
this.getInfoComponent().setCode(code);
}
@NotEmpty(message = "code not specified")
public String getCode() {
return getInfoComponent().getCode();
}
@ -1290,7 +1293,6 @@ public abstract class OrderElement extends IntegrationEntity implements
return directAdvanceAssignment;
}
@Valid
public InfoComponentWithCode getInfoComponent() {
if (infoComponent == null) {
infoComponent = new InfoComponentWithCode();

View file

@ -35,6 +35,7 @@ import org.apache.commons.logging.LogFactory;
import org.hibernate.NonUniqueResultException;
import org.hibernate.validator.AssertTrue;
import org.hibernate.validator.Min;
import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.Valid;
import org.joda.time.DateTime;
import org.joda.time.Days;
@ -321,7 +322,6 @@ public abstract class OrderElementTemplate extends BaseEntity implements
this.parent = parent;
}
@Valid
private InfoComponent getInfoComponent() {
if (infoComponent == null) {
infoComponent = new InfoComponent();
@ -362,6 +362,7 @@ public abstract class OrderElementTemplate extends BaseEntity implements
getInfoComponent().setDescription(description);
}
@NotEmpty(message = "name not specified")
public String getName() {
return getInfoComponent().getName();
}

View file

@ -27,7 +27,6 @@ import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.List;
import org.hibernate.validator.InvalidValue;
import org.libreplan.business.common.exceptions.ValidationException;
import org.libreplan.business.labels.entities.Label;
import org.libreplan.business.labels.entities.LabelType;
@ -232,10 +231,7 @@ public class LabelTypeCRUDController extends BaseCRUDController<LabelType> {
forceSortGridLabels();
newLabelTextbox.setValue("");
} catch (ValidationException e) {
for (InvalidValue invalidValue : e.getInvalidValues()) {
messagesForUser.showMessage(Level.ERROR, invalidValue
.getMessage());
}
messagesForUser.showInvalidValues(e);
}
}

View file

@ -327,7 +327,8 @@ public class MaterialsController extends
MaterialCategory materialCategory = (MaterialCategory) value;
Component comp = findInMaterialCategoryTree(materialCategory);
if (comp != null) {
throw new WrongValueException(comp, invalidValue.getMessage());
throw new WrongValueException(comp,
_(invalidValue.getMessage()));
}
}
}
@ -418,10 +419,14 @@ public class MaterialsController extends
final Treeitem treeitem = findTreeItemByMaterialCategory(categoriesTree, materialCategory);
if (treeitem != null) {
if(each.getPropertyName().equals("name")) {
throw new WrongValueException(getCategoryTextbox(treeitem), each.getMessage());
throw new WrongValueException(
getCategoryTextbox(treeitem),
_(each.getMessage()));
}
if(each.getPropertyName().equals("code")) {
throw new WrongValueException(getCategoryCodeTextbox(treeitem), each.getMessage());
throw new WrongValueException(
getCategoryCodeTextbox(treeitem),
_(each.getMessage()));
}
}
}

View file

@ -609,14 +609,14 @@ public class AssignedTaskQualityFormsToOrderElementController extends
if (TaskQualityFormItem.propertyDate.equals(propertyName)) {
openDetails(rowItem);
Datebox datebox = getDatebox(rowItem);
throw new WrongValueException(datebox, invalidValue
.getMessage());
throw new WrongValueException(datebox,
_(invalidValue.getMessage()));
}
if (TaskQualityFormItem.propertyPassed.equals(propertyName)) {
openDetails(rowItem);
Checkbox checkbox = getCheckbox(rowItem);
throw new WrongValueException(checkbox, invalidValue
.getMessage());
throw new WrongValueException(checkbox,
_(invalidValue.getMessage()));
}
}
}

View file

@ -37,16 +37,13 @@ import javax.annotation.Resource;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.LogFactory;
import org.hibernate.validator.InvalidValue;
import org.libreplan.business.calendars.entities.BaseCalendar;
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
import org.libreplan.business.common.exceptions.ValidationException;
import org.libreplan.business.externalcompanies.entities.DeadlineCommunication;
import org.libreplan.business.externalcompanies.entities.DeliverDateComparator;
import org.libreplan.business.externalcompanies.entities.EndDateCommunication;
import org.libreplan.business.externalcompanies.entities.ExternalCompany;
import org.libreplan.business.orders.daos.IOrderDAO;
import org.libreplan.business.orders.entities.HoursGroup;
import org.libreplan.business.orders.entities.Order;
import org.libreplan.business.orders.entities.Order.SchedulingMode;
import org.libreplan.business.orders.entities.OrderElement;
@ -125,47 +122,6 @@ public class OrderCRUDController extends GenericForwardComposer {
private static final String DEFAULT_TAB = "tabOrderElements";
private static final class LabelCreatorForInvalidValues implements
IMessagesForUser.ICustomLabelCreator {
@Override
public Component createLabelFor(
InvalidValue invalidValue) {
if (invalidValue.getBean() instanceof OrderElement) {
Label result = new Label();
String orderElementName;
if (invalidValue.getBean() instanceof Order) {
orderElementName = _("Project");
} else {
orderElementName = ((OrderElement) invalidValue
.getBean()).getName();
}
result.setValue(orderElementName + " "
+ invalidValue.getPropertyName() + ": "
+ invalidValue.getMessage());
return result;
} else if (invalidValue.getBean() instanceof HoursGroup) {
Label result = new Label();
HoursGroup hoursGroup = (HoursGroup) invalidValue.getBean();
result.setValue(_("Hours Group at ")
+ getParentName(hoursGroup) + ". "
+ invalidValue.getPropertyName() + ": "
+ invalidValue.getMessage());
return result;
}else {
return MessagesForUser.createLabelFor(invalidValue);
}
}
private String getParentName(HoursGroup hoursGroup) {
return (hoursGroup.getParentOrderLine() != null) ? hoursGroup
.getParentOrderLine().getName() : hoursGroup
.getOrderLineTemplate().getName();
}
}
private static final org.apache.commons.logging.Log LOG = LogFactory
.getLog(OrderCRUDController.class);
@ -692,11 +648,6 @@ public class OrderCRUDController extends GenericForwardComposer {
Util.reloadBindings(orderElementAuthorizations);
}
private void saveOrderAuthorizations() {
setupOrderAuthorizationController();
orderAuthorizationController.save();
}
public List<Order> getOrders() {
return orderModel.getOrders();
}
@ -806,11 +757,6 @@ public class OrderCRUDController extends GenericForwardComposer {
}
orderModel.save(showSaveMessage);
try {
saveOrderAuthorizations();
} catch (ValidationException e) {
messagesForUser.showInvalidValues(e, new LabelCreatorForInvalidValues());
}
}
Tab tabGeneralData;

View file

@ -88,6 +88,8 @@ import org.libreplan.business.scenarios.entities.Scenario;
import org.libreplan.business.users.daos.IOrderAuthorizationDAO;
import org.libreplan.business.users.entities.OrderAuthorization;
import org.libreplan.business.workingday.IntraDayDate;
import org.libreplan.web.common.IMessagesForUser;
import org.libreplan.web.common.MessagesForUser;
import org.libreplan.web.common.concurrentdetection.ConcurrentModificationHandling;
import org.libreplan.web.planner.TaskElementAdapter;
import org.libreplan.web.planner.order.PlanningStateCreator.PlanningState;
@ -104,6 +106,7 @@ import org.zkoss.ganttz.data.GanttDate;
import org.zkoss.ganttz.data.constraint.Constraint;
import org.zkoss.ganttz.extensions.IContext;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zul.Label;
import org.zkoss.zul.Messagebox;
/**
@ -319,12 +322,22 @@ public class SaveCommandBuilder {
}
try {
String message = validationException.getMessage();
String message = "";
LabelCreatorForInvalidValues labelCreator = new LabelCreatorForInvalidValues();
for (InvalidValue invalidValue : validationException
.getInvalidValues()) {
message += "\n" + invalidValue.getPropertyName() + ": "
+ invalidValue.getMessage();
message += "* "
+ ((Label) labelCreator
.createLabelFor(invalidValue))
.getValue() + "\n";
}
if (validationException.getInvalidValues().length == 0) {
message += validationException.getMessage();
}
LOG.warn(validationException.getMessage());
Messagebox.show(
_("Error saving the project\n{0}", message),
_("Error"), Messagebox.OK, Messagebox.ERROR);
@ -1063,4 +1076,45 @@ public class SaveCommandBuilder {
}
}
private static final class LabelCreatorForInvalidValues implements
IMessagesForUser.ICustomLabelCreator {
@Override
public org.zkoss.zk.ui.Component createLabelFor(
InvalidValue invalidValue) {
if (invalidValue.getBean() instanceof OrderElement) {
Label result = new Label();
String orderElementName;
if (invalidValue.getBean() instanceof Order) {
orderElementName = _("Project");
} else {
orderElementName = _("Task {0}",
((OrderElement) invalidValue.getBean()).getName());
}
result.setValue(orderElementName + ": "
+ _(invalidValue.getMessage()));
return result;
} else if (invalidValue.getBean() instanceof HoursGroup) {
Label result = new Label();
HoursGroup hoursGroup = (HoursGroup) invalidValue.getBean();
result.setValue(_("Hours Group at {0}",
getParentName(hoursGroup))
+ ": "
+ _(invalidValue.getMessage()));
return result;
} else {
return MessagesForUser.createLabelFor(invalidValue);
}
}
private String getParentName(HoursGroup hoursGroup) {
return (hoursGroup.getParentOrderLine() != null) ? hoursGroup
.getParentOrderLine().getName() : hoursGroup
.getOrderLineTemplate().getName();
}
}
}

View file

@ -259,10 +259,8 @@ public class CriterionsController extends GenericForwardComposer {
reload();
} catch (ValidationException e) {
showInvalidValues(e);
for (InvalidValue invalidValue : e.getInvalidValues()) {
messages.showMessage(Level.ERROR, invalidValue.getPropertyName()+invalidValue.getMessage());
return false;
}
messages.showInvalidValues(e);
return false;
} catch (IllegalStateException e) {
messages.showMessage(Level.ERROR,e.getMessage());
return false;

View file

@ -265,12 +265,8 @@ public class CriterionsMachineController extends GenericForwardComposer {
reload();
} catch (ValidationException e) {
showInvalidValues(e);
for (InvalidValue invalidValue : e.getInvalidValues()) {
messages.showMessage(Level.ERROR, invalidValue
.getPropertyName()
+ invalidValue.getMessage());
return false;
}
messages.showInvalidValues(e);
return false;
} catch (IllegalStateException e) {
messages.showMessage(Level.ERROR, e.getMessage());
return false;

View file

@ -28,7 +28,6 @@ import java.util.List;
import javax.annotation.Resource;
import org.apache.commons.logging.LogFactory;
import org.hibernate.validator.InvalidValue;
import org.libreplan.business.calendars.entities.BaseCalendar;
import org.libreplan.business.common.exceptions.ValidationException;
import org.libreplan.business.orders.entities.OrderElement;
@ -225,10 +224,7 @@ public class OrderTemplatesController extends GenericForwardComposer implements
messagesForUser.showMessage(Level.INFO, _("Template saved"));
show(listWindow);
} catch (ValidationException e) {
for (InvalidValue invalidValue : e.getInvalidValues()) {
messagesForUser.showMessage(Level.ERROR,
invalidValue.getMessage());
}
messagesForUser.showInvalidValues(e);
}
}
}
@ -245,10 +241,7 @@ public class OrderTemplatesController extends GenericForwardComposer implements
bindTemplatesTreeWithModel();
messagesForUser.showMessage(Level.INFO, _("Template saved"));
} catch (ValidationException e) {
for (InvalidValue invalidValue : e.getInvalidValues()) {
messagesForUser.showMessage(Level.ERROR,
invalidValue.getMessage());
}
messagesForUser.showInvalidValues(e);
}
}

View file

@ -699,8 +699,8 @@ public abstract class TreeController<T extends ITreeNode<T>> extends
InvalidValue[] invalidValues = validator.getPotentialInvalidValues(
property, value);
if (invalidValues.length > 0) {
throw new WrongValueException(component, invalidValues[0]
.getMessage());
throw new WrongValueException(component,
_(invalidValues[0].getMessage()));
}
}

View file

@ -42,8 +42,6 @@ public interface IOrderAuthorizationModel {
void initEdit(PlanningState planningState);
void confirmSave();
List<ProfileOrderAuthorization> getProfileOrderAuthorizations();
List<UserOrderAuthorization> getUserOrderAuthorizations();

View file

@ -76,10 +76,6 @@ public class OrderAuthorizationController extends GenericForwardComposer{
Util.reloadBindings(window);
}
public void save() {
orderAuthorizationModel.confirmSave();
}
public List<ProfileOrderAuthorization> getProfileOrderAuthorizations() {
return orderAuthorizationModel.getProfileOrderAuthorizations();
}

View file

@ -107,12 +107,6 @@ public class OrderAuthorizationModel implements IOrderAuthorizationModel {
return duplicated.isEmpty()? null : duplicated;
}
@Override
@Transactional
public void confirmSave() {
// Do nothing
}
@Override
public List<ProfileOrderAuthorization> getProfileOrderAuthorizations() {
return profileOrderAuthorizationList;

View file

@ -19,6 +19,8 @@
package org.libreplan.web.util;
import static org.libreplan.web.I18nHelper._;
import org.hibernate.validator.InvalidValue;
import org.libreplan.business.common.exceptions.ValidationException;
import org.zkoss.ganttz.util.ComponentsFinder;
@ -47,13 +49,13 @@ public class ValidationExceptionPrinter {
}
private static void showAt(Component comp, InvalidValue invalidValue) {
throw new WrongValueException(comp, invalidValue.getMessage());
throw new WrongValueException(comp, _(invalidValue.getMessage()));
}
private static void showAt(Grid comp, InvalidValue invalidValue) {
Row row = ComponentsFinder.findRowByValue(comp, invalidValue.getValue());
if (row != null) {
throw new WrongValueException(row, invalidValue.getMessage());
throw new WrongValueException(row, _(invalidValue.getMessage()));
}
}