Skip to content

Commit

Permalink
improving result messages for save and preview + redirect behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Sep 29, 2021
1 parent ca8aed1 commit cc9fe7f
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,26 +224,27 @@ public Collection<ObjectDeltaOperation<? extends ObjectType>> saveOrPreviewPerfo
LOGGER.trace("returning from saveOrPreviewPerformed");
Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = executeChanges(deltas, previewOnly, options, task, result, target);

postProcessResult(result, executedDeltas);
postProcessResult(result, executedDeltas, target);

return executedDeltas;
}

protected void postProcessResult(OperationResult result, Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas) {
protected void postProcessResult(OperationResult result, Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas, AjaxRequestTarget target) {
result.computeStatusIfUnknown();

if (allowRedirectBack() && !result.isError()) { // && allowRedirectBack()) {
redirectBack();
} else {
target.add(getFeedbackPanel());
}
}

protected Collection<ObjectDeltaOperation<? extends ObjectType>> executeChanges(Collection<ObjectDelta<? extends ObjectType>> deltas, boolean previewOnly, ExecuteChangeOptionsDto options, Task task, OperationResult result, AjaxRequestTarget target) {
if (noChangesToExecute(deltas, options)) {
recordNoChangesWarning(result);

if (shouldBeStoppedProcessingOfChanges(deltas, options, previewOnly, target, result)) {
return null;
}

if (deltas.isEmpty()) {
result.recordWarning("PageAdminObjectDetails.noChangesSave");
showResult(result);
target.add(getFeedbackPanel());
redirectBack();
return null;
}
//TODO force
Expand All @@ -259,40 +260,23 @@ protected Collection<ObjectDeltaOperation<? extends ObjectType>> executeChanges(
ObjectChangeExecutor changeExecutor = getChangeExecutor();
Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = changeExecutor.executeChanges(deltas, previewOnly, task, result, target);

result.computeStatusIfUnknown();
if (changeExecutor instanceof ObjectChangesExecutorImpl) {
showResult(result);
if (!previewOnly && result.isSuccess() && allowRedirectBack()) {
redirectBack();
} else {
target.add(getFeedbackPanel());
}
}

return executedDeltas;
}

protected boolean allowRedirectBack() {
return true;
protected boolean noChangesToExecute(Collection<ObjectDelta<? extends ObjectType>> deltas, ExecuteChangeOptionsDto options) {
return deltas.isEmpty();
}

protected boolean shouldBeStoppedProcessingOfChanges(Collection<ObjectDelta<? extends ObjectType>> deltas, ExecuteChangeOptionsDto options, boolean previewOnly, AjaxRequestTarget target, OperationResult result){
if (ItemStatus.NOT_CHANGED == getObjectDetailsModels().getObjectStatus()) {
if (deltas.isEmpty() && !options.isReconcile()) {
if (!previewOnly) {
result.recordWarning(getString("PageAdminObjectDetails.noChangesSave"));
showResult(result);
if (allowRedirectBack()) {
redirectBack();
}
} else {
warn(getString("PageAdminObjectDetails.noChangesPreview"));
target.add(getFeedbackPanel());
}
return true;
}
}
return false;
protected void recordNoChangesWarning(OperationResult result) {
result.recordWarning(getString("PageAdminObjectDetails.noChangesSave"));
}

protected boolean allowRedirectBack() {
return true;
}

protected ExecuteChangeOptionsDto getExecuteChangesOptionsDto() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,19 @@ protected Collection<ObjectDeltaOperation<? extends ObjectType>> executeChanges(
return super.executeChanges(deltas, previewOnly, options, task, result, target);
}

// @Override
// protected final void saveOrPreviewPostProcess(AjaxRequestTarget target, Task task, ExecuteChangeOptionsDto options) {
// Fragment progressPanelFragment = new ProgressFragment(ID_DETAILS_VIEW, ID_PROGRESS_PANEL_FRAGMENT, PageFocusDetails.this, options);
// replace(progressPanelFragment);
// target.add(progressPanelFragment);
// }

// @Override
// protected void postProcessDeltas(AjaxRequestTarget target, Collection<ObjectDelta<? extends ObjectType>> deltas, ItemStatus status, ExecuteChangeOptionsDto executeChangeOptionsDto) throws SchemaException {
// super.postProcessDeltas(target, deltas, status, executeChangeOptionsDto);
//
// if (executeChangeOptionsDto.isReconcile() && deltas.isEmpty()) {
// ObjectDelta emptyDelta = getPrismContext().deltaFor(getType()).asObjectDelta(getModelPrismObject().getOid());
// deltas.add(emptyDelta);
// }
// }
@Override
protected void recordNoChangesWarning(OperationResult result) {
if (previewRequested) {
result.recordWarning(getString("PageAdminObjectDetails.noChangesPreview"));
} else {
super.recordNoChangesWarning(result);
}
}

@Override
protected boolean allowRedirectBack() {
return !previewRequested;
}

protected ProgressPanel getProgressPanel() {
return (ProgressPanel) get(createComponentPath(ID_DETAILS_VIEW, ID_PROGRESS_PANEL));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,43 +148,18 @@ public void saveAndRunPerformed(AjaxRequestTarget target) {
Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = saveOrPreviewPerformed(target, saveResult, false);

if (!saveResult.isError()) {
OperationResult saveAndRunResult = new OperationResult(OPERATION_SAVE_AND_RUN_REPORT);
PrismObject<ReportType> report;
if (getModelObjectType().getOid() != null) {
report = getModelPrismObject();
} else {
report = (PrismObject<ReportType>) executedDeltas.iterator().next().getObjectDelta().getObjectToAdd();
}
PrismObject<ReportType> report = getReport(executedDeltas);
if (!ReportOperationalButtonsPanel.hasParameters(report.asObjectable())) {
try {
Task task = createSimpleTask(OPERATION_RUN_REPORT);
getReportManager().runReport(report, null, task, saveAndRunResult);
} catch (Exception ex) {
saveAndRunResult.recordFatalError(ex);
} finally {
saveAndRunResult.computeStatusIfUnknown();
showResult(saveAndRunResult);
redirectBack();
}

runReport(report, null);
} else {

RunReportPopupPanel runReportPopupPanel = new RunReportPopupPanel(getMainPopupBodyId(), report.asObjectable()) {

private static final long serialVersionUID = 1L;

protected void runConfirmPerformed(AjaxRequestTarget target, ReportType reportType, PrismContainer<ReportParameterType> reportParam) {
try {
Task task = createSimpleTask(OPERATION_RUN_REPORT);
getReportManager().runReport(reportType.asPrismObject(), reportParam, task, saveAndRunResult);
} catch (Exception ex) {
saveAndRunResult.recordFatalError(ex);
} finally {
saveAndRunResult.computeStatusIfUnknown();
}
protected void runConfirmPerformed(AjaxRequestTarget target, PrismObject<ReportType> report, PrismContainer<ReportParameterType> reportParam) {
runReport(report, reportParam);
hideMainPopup(target);
showResult(saveAndRunResult);
redirectBack();
}
};
showMainPopup(runReportPopupPanel, target);
Expand All @@ -195,6 +170,28 @@ protected void runConfirmPerformed(AjaxRequestTarget target, ReportType reportTy
}
}

private PrismObject<ReportType> getReport(Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas) {
if (getModelObjectType().getOid() != null) {
return getModelPrismObject();
}
return (PrismObject<ReportType>) executedDeltas.iterator().next().getObjectDelta().getObjectToAdd();

}

private void runReport(PrismObject<ReportType> report, PrismContainer<ReportParameterType> reportParam) {
Task task = createSimpleTask(OPERATION_RUN_REPORT);
OperationResult saveAndRunResult = task.getResult();
try {
getReportManager().runReport(report, reportParam, task, saveAndRunResult);
} catch (Exception ex) {
saveAndRunResult.recordFatalError(ex);
} finally {
saveAndRunResult.computeStatusIfUnknown();
saveAndRunResult.setBackgroundTaskOid(task.getOid());
redirectBack();
}
}

@Override
protected boolean allowRedirectBack() {
return !processingOfSaveAndRun;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,16 @@ protected void savePerformed(AjaxRequestTarget target) {
}

@Override
protected void postProcessResult(OperationResult result, Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas) {
protected void postProcessResult(OperationResult result, Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas, AjaxRequestTarget target) {
if (executedDeltas == null) {
super.postProcessResult(result, executedDeltas, target);
return;
}
String taskOid = ObjectDeltaOperation.findFocusDeltaOidInCollection(executedDeltas);
if (taskOid != null) {
result.setBackgroundTaskOid(taskOid);
}
super.postProcessResult(result, executedDeltas, target);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,28 +100,18 @@ protected UserDetailsModel createObjectDetailsModels(PrismObject<UserType> objec
return new UserDetailsModel(createPrismObejctModel(object), this);
}

private boolean delegationChangesExist = false;
@Override
protected boolean shouldBeStoppedProcessingOfChanges(Collection<ObjectDelta<? extends ObjectType>> deltas, ExecuteChangeOptionsDto options, boolean previewOnly, AjaxRequestTarget target, OperationResult result) {
protected Collection<ObjectDeltaOperation<? extends ObjectType>> executeChanges(Collection<ObjectDelta<? extends ObjectType>> deltas, boolean previewOnly, ExecuteChangeOptionsDto options, Task task, OperationResult result, AjaxRequestTarget target) {
if (ItemStatus.NOT_CHANGED == getObjectDetailsModels().getObjectStatus()) {
boolean delegationChangesExist = processDeputyAssignments(previewOnly);

if (deltas.isEmpty() && !options.isReconcile()) {
if (!previewOnly) {
if (!delegationChangesExist) {
result.recordWarning(getString("PageAdminObjectDetails.noChangesSave"));
showResult(result);
}
redirectBack();
} else {
if (!delegationChangesExist) {
warn(getString("PageAdminObjectDetails.noChangesPreview"));
target.add(getFeedbackPanel());
}
}
return true;
}
delegationChangesExist = processDeputyAssignments(previewOnly);
}
return false;
return super.executeChanges(deltas, previewOnly, options, task, result, target);
}

@Override
protected boolean noChangesToExecute(Collection<ObjectDelta<? extends ObjectType>> deltas, ExecuteChangeOptionsDto options) {
return deltas.isEmpty() && !options.isReconcile() && !delegationChangesExist;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ private void runConfirmPerformed(AjaxRequestTarget target) {
}
}
}
runConfirmPerformed(target, getModelObject(), parameterContainer);
runConfirmPerformed(target, getModelObject().asPrismObject(), parameterContainer);
}

protected void runConfirmPerformed(AjaxRequestTarget target, ReportType reportType2,
protected void runConfirmPerformed(AjaxRequestTarget target, PrismObject<ReportType> reportType2,
PrismContainer<ReportParameterType> reportParam) {
}

Expand Down

0 comments on commit cc9fe7f

Please sign in to comment.