[Bug #1223] Catch ValidationException in SaveCommandBuilder
FEA: ItEr75S04BugFixing
This commit is contained in:
parent
38acc73985
commit
d378166772
4 changed files with 88 additions and 71 deletions
|
|
@ -25,7 +25,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.externalcompanies.entities.ExternalCompany;
|
||||
import org.navalplanner.business.labels.entities.Label;
|
||||
import org.navalplanner.business.orders.entities.Order;
|
||||
|
|
@ -89,7 +88,9 @@ public interface IOrderModel extends IIntegrationEntityModel {
|
|||
|
||||
void remove(Order order);
|
||||
|
||||
void save() throws ValidationException;
|
||||
void save();
|
||||
|
||||
void save(boolean showSaveMessage);
|
||||
|
||||
void setPlanningState(PlanningState planningState);
|
||||
|
||||
|
|
|
|||
|
|
@ -706,31 +706,30 @@ public class OrderCRUDController extends GenericForwardComposer {
|
|||
final boolean isNewObject = order.isNewObject();
|
||||
setCurrentTab();
|
||||
Tab previousTab = getCurrentTab();
|
||||
final boolean couldSave = save(showSaveMessage);
|
||||
save(showSaveMessage);
|
||||
|
||||
if (couldSave) {
|
||||
if (orderModel.userCanRead(order,
|
||||
SecurityUtils.getSessionUserLoginName())) {
|
||||
refreshOrderWindow();
|
||||
|
||||
if (orderModel.userCanRead(order, SecurityUtils.getSessionUserLoginName())) {
|
||||
refreshOrderWindow();
|
||||
// come back to the current tab after initialize all tabs.
|
||||
resetSelectedTab();
|
||||
selectTab(previousTab.getId());
|
||||
Events.sendEvent(new SelectEvent(Events.ON_SELECT, previousTab,
|
||||
null));
|
||||
|
||||
// come back to the current tab after initialize all tabs.
|
||||
resetSelectedTab();
|
||||
selectTab(previousTab.getId());
|
||||
Events.sendEvent(new SelectEvent(Events.ON_SELECT, previousTab,
|
||||
null));
|
||||
|
||||
if (isNewObject) {
|
||||
this.planningControllerEntryPoints.goToOrderDetails(order);
|
||||
}
|
||||
if (isNewObject) {
|
||||
this.planningControllerEntryPoints.goToOrderDetails(order);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
Messagebox.show(_("You don't have read access to this project"),
|
||||
_("Information"), Messagebox.OK, Messagebox.INFORMATION);
|
||||
goToList();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Messagebox
|
||||
.show(_("You don't have read access to this project"),
|
||||
_("Information"), Messagebox.OK,
|
||||
Messagebox.INFORMATION);
|
||||
goToList();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -758,38 +757,30 @@ public class OrderCRUDController extends GenericForwardComposer {
|
|||
}
|
||||
}
|
||||
|
||||
public void saveAndExit() {
|
||||
setCurrentTab();
|
||||
final boolean couldSave = save();
|
||||
if (couldSave) {
|
||||
goToList();
|
||||
}
|
||||
private void save() {
|
||||
save(true);
|
||||
}
|
||||
|
||||
private boolean save() {
|
||||
return save(true);
|
||||
}
|
||||
|
||||
private boolean save(boolean showSaveMessage) {
|
||||
private void save(boolean showSaveMessage) {
|
||||
if (manageOrderElementAdvancesController != null) {
|
||||
selectTab("tabAdvances");
|
||||
if (!manageOrderElementAdvancesController.save()) {
|
||||
setCurrentTab();
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (assignedCriterionRequirementController != null) {
|
||||
selectTab("tabRequirements");
|
||||
if (!assignedCriterionRequirementController.close()) {
|
||||
setCurrentTab();
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (assignedTaskQualityFormController != null) {
|
||||
selectTab("tabTaskQualityForm");
|
||||
if (!assignedTaskQualityFormController.confirm()) {
|
||||
setCurrentTab();
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -800,23 +791,12 @@ public class OrderCRUDController extends GenericForwardComposer {
|
|||
selectTab(getCurrentTab().getId());
|
||||
}
|
||||
|
||||
orderModel.save(showSaveMessage);
|
||||
try {
|
||||
orderModel.save();
|
||||
saveOrderAuthorizations();
|
||||
if (showSaveMessage) {
|
||||
try {
|
||||
Messagebox.show(_("Project saved"), _("Information"),
|
||||
Messagebox.OK, Messagebox.INFORMATION);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (ValidationException e) {
|
||||
messagesForUser.showInvalidValues(e, new LabelCreatorForInvalidValues());
|
||||
}
|
||||
setCurrentTab();
|
||||
return false;
|
||||
}
|
||||
|
||||
Tab tabGeneralData;
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ import org.navalplanner.business.common.daos.IConfigurationDAO;
|
|||
import org.navalplanner.business.common.entities.Configuration;
|
||||
import org.navalplanner.business.common.entities.EntityNameEnum;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.externalcompanies.daos.IExternalCompanyDAO;
|
||||
import org.navalplanner.business.externalcompanies.entities.ExternalCompany;
|
||||
import org.navalplanner.business.labels.daos.ILabelDAO;
|
||||
|
|
@ -436,15 +435,25 @@ public class OrderModel extends IntegrationEntityModel implements IOrderModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void save() throws ValidationException {
|
||||
this.planningState.getSaveCommand().save(new IBeforeSaveActions() {
|
||||
public void save() {
|
||||
save(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(boolean showSaveMessage) {
|
||||
IBeforeSaveActions beforeSaveActions = new IBeforeSaveActions() {
|
||||
|
||||
@Override
|
||||
public void doActions() {
|
||||
reattachCalendar();
|
||||
reattachCriterions();
|
||||
}
|
||||
});
|
||||
};
|
||||
if (showSaveMessage) {
|
||||
this.planningState.getSaveCommand().save(beforeSaveActions);
|
||||
} else {
|
||||
this.planningState.getSaveCommand().save(beforeSaveActions, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void reattachCalendar() {
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import java.util.SortedSet;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.hibernate.validator.InvalidValue;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.advance.entities.AdvanceMeasurement;
|
||||
import org.navalplanner.business.advance.entities.DirectAdvanceAssignment;
|
||||
|
|
@ -236,32 +237,58 @@ public class SaveCommandBuilder {
|
|||
|
||||
@Override
|
||||
public void save(IBeforeSaveActions beforeSaveActions) {
|
||||
save(beforeSaveActions, null);
|
||||
save(beforeSaveActions, new IAfterSaveActions() {
|
||||
|
||||
@Override
|
||||
public void doActions() {
|
||||
notifyUserThatSavingIsDone();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(final IBeforeSaveActions beforeSaveActions,
|
||||
IAfterSaveActions afterSaveActions)
|
||||
throws ValidationException {
|
||||
if (state.getScenarioInfo().isUsingTheOwnerScenario()
|
||||
|| userAcceptsCreateANewOrderVersion()) {
|
||||
transactionService.runOnTransaction(new IOnTransaction<Void>() {
|
||||
@Override
|
||||
public Void execute() {
|
||||
if (beforeSaveActions != null) {
|
||||
beforeSaveActions.doActions();
|
||||
IAfterSaveActions afterSaveActions) {
|
||||
try {
|
||||
if (state.getScenarioInfo().isUsingTheOwnerScenario()
|
||||
|| userAcceptsCreateANewOrderVersion()) {
|
||||
transactionService
|
||||
.runOnTransaction(new IOnTransaction<Void>() {
|
||||
@Override
|
||||
public Void execute() {
|
||||
if (beforeSaveActions != null) {
|
||||
beforeSaveActions.doActions();
|
||||
}
|
||||
doTheSaving();
|
||||
return null;
|
||||
}
|
||||
doTheSaving();
|
||||
return null;
|
||||
});
|
||||
dontPoseAsTransientObjectAnymore(state.getOrder());
|
||||
state.getScenarioInfo().afterCommit();
|
||||
fireAfterSave();
|
||||
if (afterSaveActions != null) {
|
||||
afterSaveActions.doActions();
|
||||
}
|
||||
});
|
||||
dontPoseAsTransientObjectAnymore(state.getOrder());
|
||||
state.getScenarioInfo().afterCommit();
|
||||
fireAfterSave();
|
||||
if (afterSaveActions != null) {
|
||||
afterSaveActions.doActions();
|
||||
}
|
||||
} catch (ValidationException validationException) {
|
||||
if (Executions.getCurrent() == null) {
|
||||
throw validationException;
|
||||
}
|
||||
|
||||
try {
|
||||
String message = validationException.getMessage();
|
||||
for (InvalidValue invalidValue : validationException.getInvalidValues()) {
|
||||
message += "\n" + invalidValue.getPropertyName() + ": "
|
||||
+ invalidValue.getMessage();
|
||||
}
|
||||
Messagebox.show(
|
||||
_("Error saving the project\n{0}", message),
|
||||
_("Error"), Messagebox.OK, Messagebox.ERROR);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void fireAfterSave() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue