Skip to content

Commit

Permalink
Fixed MID-2058 (Notifications don't display association info when add…
Browse files Browse the repository at this point in the history
…ing account+association). Fixed displaying errors in resource objects failure notifications. Also, now showing errors that occur during "reconcile user" operation.
  • Loading branch information
mederly committed Oct 15, 2014
1 parent 864be46 commit 6606d89
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 16 deletions.
Expand Up @@ -581,7 +581,7 @@ private void reconcilePerformed(AjaxRequestTarget target, UserListItemDto select
ObjectDelta delta = ObjectDelta.createEmptyModifyDelta(UserType.class, user.getOid(), getPrismContext());
Collection<ObjectDelta<? extends ObjectType>> deltas = WebMiscUtil.createDeltaCollection(delta);
getModelService().executeChanges(deltas, ModelExecuteOptions.createReconcile(), task, opResult);
opResult.recordSuccess();
opResult.computeStatusIfUnknown();
} catch (Exception ex) {
opResult.recomputeStatus();
opResult.recordFatalError("Couldn't reconcile user " + userShortString + ".", ex);
Expand Down
Expand Up @@ -21,6 +21,7 @@

import javax.xml.bind.JAXBElement;

import com.evolveum.midpoint.prism.util.CloneUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.w3c.dom.Document;
Expand Down Expand Up @@ -62,7 +63,7 @@
* @author Radovan Semancik
*
*/
public class OperationResult implements Serializable, DebugDumpable {
public class OperationResult implements Serializable, DebugDumpable, Cloneable {

private static final long serialVersionUID = -2467406395542291044L;
private static final String INDENT_STRING = " ";
Expand Down Expand Up @@ -1447,4 +1448,36 @@ public int hashCode() {
}
}

public OperationResult clone() {
OperationResult clone = new OperationResult(operation);

clone.status = status;
clone.params = CloneUtil.clone(params);
clone.context = CloneUtil.clone(context);
clone.returns = CloneUtil.clone(returns);
clone.token = token;
clone.messageCode = messageCode;
clone.message = message;
clone.localizationMessage = localizationMessage;
clone.localizationArguments = CloneUtil.clone(localizationArguments);
clone.cause = CloneUtil.clone(cause);
clone.count = count;
if (subresults != null) {
clone.subresults = new ArrayList<>(subresults.size());
for (OperationResult subresult : subresults) {
if (subresult != null) {
clone.subresults.add(subresult.clone());
}
}
}
clone.details = CloneUtil.clone(details);
clone.summarizeErrors = summarizeErrors;
clone.summarizePartialErrors = summarizePartialErrors;
clone.summarizeSuccesses = summarizeSuccesses;
clone.minor = minor;

return clone;
}


}
Expand Up @@ -176,17 +176,22 @@ public String formatAccountAttributes(ShadowType shadowType, List<ItemPath> hidd
if (shadowType.getAttributes() != null) {
formatContainerValue(retval, "", shadowType.getAttributes().asPrismContainerValue(), false, hiddenAttributes, showOperationalAttributes);
}
if (shadowType.getAssociation() != null) {
for (ShadowAssociationType shadowAssociationType : shadowType.getAssociation()) {
formatContainerValue(retval, "", shadowAssociationType.asPrismContainerValue(), false, hiddenAttributes, showOperationalAttributes);
}
}
if (shadowType.getCredentials() != null) {
formatContainerValue(retval, "", shadowType.getCredentials().asPrismContainerValue(), false, hiddenAttributes, showOperationalAttributes);
}
if (shadowType.getActivation() != null) {
formatContainerValue(retval, "", shadowType.getActivation().asPrismContainerValue(), false, hiddenAttributes, showOperationalAttributes);
}
if (shadowType.getAssociation() != null) {
boolean first = true;
for (ShadowAssociationType shadowAssociationType : shadowType.getAssociation()) {
if (first) retval.append("\n"); else first = false;
retval.append("Association:\n");
formatContainerValue(retval, " ", shadowAssociationType.asPrismContainerValue(), false, hiddenAttributes, showOperationalAttributes);
retval.append("\n");
}
}

return retval.toString();
}

Expand Down
Expand Up @@ -103,7 +103,7 @@ protected Integer getAttemptNumber(ShadowType shadow) {
return attemptNumber;
}

protected ResourceOperationDescription createOperationDescription(ShadowType shadowType, ResourceType resource, ObjectDelta delta, Task task, OperationResult result) {
protected ResourceOperationDescription createOperationDescription(ShadowType shadowType, Exception ex, ResourceType resource, ObjectDelta delta, Task task, OperationResult result) {
ResourceOperationDescription operationDescription = new ResourceOperationDescription();
operationDescription.setCurrentShadow(shadowType.asPrismObject());
if (resource != null){
Expand All @@ -113,7 +113,15 @@ protected ResourceOperationDescription createOperationDescription(ShadowType sha
operationDescription.setSourceChannel(task.getChannel());
}
operationDescription.setObjectDelta(delta);
operationDescription.setResult(result);

// fill-in the message if necessary
OperationResult storedResult = result != null ? result.clone() : new OperationResult("dummy"); // actually, the result shouldn't be null anyway
storedResult.computeStatusIfUnknown();
if (storedResult.getMessage() == null && ex != null) {
storedResult.recordStatus(storedResult.getStatus(), ex.getMessage(), ex);
}
operationDescription.setResult(storedResult);

return operationDescription;
}

Expand Down
Expand Up @@ -158,7 +158,7 @@ public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Except

// task = taskManager.createTaskInstance();
delta = ObjectDelta.createAddDelta(shadow.asPrismObject());
operationDescription = createOperationDescription(shadow, resource, delta, task, operationResult);
operationDescription = createOperationDescription(shadow, ex, resource, delta, task, operationResult);
changeNotificationDispatcher.notifyInProgress(operationDescription, task, parentResult);
return shadow;
case MODIFY:
Expand Down Expand Up @@ -196,7 +196,7 @@ public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Except
+ ", because resource is unreachable. Modifications will be applied when the resource goes online");
// task = taskManager.createTaskInstance();
//
operationDescription = createOperationDescription(shadow, shadow.getResource(), delta, task, operationResult);
operationDescription = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, operationResult);
changeNotificationDispatcher.notifyInProgress(operationDescription, task, parentResult);
return shadow;
case DELETE:
Expand All @@ -217,7 +217,7 @@ public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Except
// task = taskManager.createTaskInstance();
// task.setChannel(QNameUtil.qNameToUri(SchemaConstants.CHANGE_CHANNEL_DISCOVERY));
delta = ObjectDelta.createDeleteDelta(shadow.asPrismObject().getCompileTimeClass(), shadow.getOid(), prismContext);
operationDescription = createOperationDescription(shadow, shadow.getResource(), delta, task, operationResult);
operationDescription = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, operationResult);
changeNotificationDispatcher.notifyInProgress(operationDescription, task, parentResult);
return shadow;
case GET:
Expand Down
Expand Up @@ -74,7 +74,7 @@ public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Except

if (op != FailedOperation.GET){
// Task task = taskManager.createTaskInstance();
ResourceOperationDescription operationDescription = createOperationDescription(shadow, shadow.getResource(),
ResourceOperationDescription operationDescription = createOperationDescription(shadow, ex, shadow.getResource(),
delta, task, parentResult);
changeNotificationDispatcher.notifyFailure(operationDescription, task, parentResult);
}
Expand Down
Expand Up @@ -135,7 +135,7 @@ public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Except
LOGGER.trace("Shadow deleted from the repository. Inconsistencies are now removed.");
result.computeStatus();
delta = ObjectDelta.createDeleteDelta(shadow.getClass(), shadow.getOid(), prismContext);
ResourceOperationDescription operationDescritpion = createOperationDescription(shadow, shadow.getResource(), delta, task, result);
ResourceOperationDescription operationDescritpion = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, result);
changeNotificationDispatcher.notifySuccess(operationDescritpion, task, result);
return shadow;
case MODIFY:
Expand Down
Expand Up @@ -76,7 +76,7 @@ public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Except

if (op != FailedOperation.GET) {
// Task task = taskManager.createTaskInstance();
ResourceOperationDescription operationDescription = createOperationDescription(shadow,
ResourceOperationDescription operationDescription = createOperationDescription(shadow, ex,
shadow.getResource(), delta, task, parentResult);
changeNotificationDispatcher.notifyFailure(operationDescription, task, parentResult);
}
Expand Down
Expand Up @@ -76,7 +76,7 @@ public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Except

if (op != FailedOperation.GET){
// Task task = taskManager.createTaskInstance();
ResourceOperationDescription operationDescription = createOperationDescription(shadow, shadow.getResource(),
ResourceOperationDescription operationDescription = createOperationDescription(shadow, ex, shadow.getResource(),
delta, task, parentResult);
changeNotificationDispatcher.notifyFailure(operationDescription, task, parentResult);
}
Expand Down

0 comments on commit 6606d89

Please sign in to comment.