Skip to content

Commit

Permalink
fix for MID-6178 - delete task result repeatedly, fixed by fixing del…
Browse files Browse the repository at this point in the history
…ta computation for deleted values, small improvements for refreshing after operation.
  • Loading branch information
katkav committed Apr 6, 2020
1 parent fcde18a commit 0864f37
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 167 deletions.
Expand Up @@ -78,7 +78,9 @@ public <D extends ItemDelta<V, ID>, ID extends ItemDefinition> void addToDelta(D
}
break;
case DELETED:
delta.addValueToDelete((V) oldValue.clone());
if (oldValue != null && !oldValue.isEmpty()) {
delta.addValueToDelete((V) oldValue.clone());
}
break;
default:
break;
Expand Down
Expand Up @@ -4,6 +4,9 @@
import java.util.Collection;
import java.util.Collections;

import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.web.component.prism.ValueStatus;

import org.apache.wicket.Page;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AttributeAppender;
Expand Down Expand Up @@ -370,20 +373,34 @@ private void createCleanupResultsButton(RepeatingView repeatingView) {
@Override
public void onClick(AjaxRequestTarget target) {
try {
getObjectWrapper().findProperty(TaskType.F_RESULT).getValue().setRealValue(null);
getObjectWrapper().findProperty(TaskType.F_RESULT_STATUS).getValue().setRealValue(null);
deleteProperty(TaskType.F_RESULT);
deleteProperty(TaskType.F_RESULT_STATUS);
} catch (SchemaException e){
LOGGER.error("Cannot clear task results: {}", e.getMessage());
}
saveTaskChanges(target);
refresh(target);
}
};
cleanupResults.add(new VisibleBehaviour(this::isNotRunning));
cleanupResults.add(AttributeAppender.append("class", "btn btn-default btn-margin-left btn-sm"));
repeatingView.add(cleanupResults);
}

private <T> void deleteProperty(ItemName propertyName) throws SchemaException {
PrismPropertyWrapper<T> property = getObjectWrapper().findProperty(propertyName);
if (property == null) {
return;
}

PrismPropertyValueWrapper<T> propertyValue = property.getValue();
if (propertyValue == null) {
return;
}

propertyValue.setStatus(ValueStatus.DELETED);

}

private void saveTaskChanges(AjaxRequestTarget target) {
try {
ObjectDelta<TaskType> taskDelta = getObjectWrapper().getObjectDelta();
Expand All @@ -398,6 +415,7 @@ private void saveTaskChanges(AjaxRequestTarget target) {
private void saveTaskChanges(AjaxRequestTarget target, ObjectDelta<TaskType> taskDelta){
if (taskDelta.isEmpty()) {
getSession().warn("Nothing to save, no changes were made.");
target.add(getFeedbackPanel());
return;
}

Expand All @@ -408,7 +426,6 @@ private void saveTaskChanges(AjaxRequestTarget target, ObjectDelta<TaskType> tas
taskDelta.revive(getPrismContext()); //do we need revive here?
getModelService().executeChanges(MiscUtil.createCollection(taskDelta), null, task, result);
result.computeStatus();
getObjectModel().reset();
} catch (Exception e) {
LoggingUtils.logUnexpectedException(LOGGER, "Cannot save tasks changes", e);
result.recordFatalError("Cannot save tasks changes, " + e.getMessage(), e);
Expand All @@ -425,6 +442,7 @@ private CompositedIcon getTaskCleanupCompositedIcon(String basicIconClass){
}

private void afterOperation(AjaxRequestTarget target, OperationResult result) {
taskTabsVisibility = new TaskTabsVisibility();
showResult(result);
getObjectModel().reset();
refresh(target);
Expand Down

0 comments on commit 0864f37

Please sign in to comment.