use of com.evolveum.midpoint.provisioning.api.ResourceOperationDescription in project midpoint by Evolveum.
the class ModifyHelper method notifyAfterModify.
void notifyAfterModify(ProvisioningContext ctx, PrismObject<ShadowType> repoShadow, Collection<? extends ItemDelta> modifications, ProvisioningOperationState<AsynchronousOperationReturnValue<Collection<PropertyDelta<PrismPropertyValue>>>> opState, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
ObjectDelta<ShadowType> delta = prismContext.deltaFactory().object().createModifyDelta(repoShadow.getOid(), modifications, repoShadow.getCompileTimeClass());
ResourceOperationDescription operationDescription = createSuccessOperationDescription(ctx, repoShadow, delta, parentResult);
if (opState.isExecuting()) {
eventDispatcher.notifyInProgress(operationDescription, task, parentResult);
} else {
eventDispatcher.notifySuccess(operationDescription, task, parentResult);
}
}
use of com.evolveum.midpoint.provisioning.api.ResourceOperationDescription in project midpoint by Evolveum.
the class ShadowManager method createResourceFailureDescription.
public ResourceOperationDescription createResourceFailureDescription(PrismObject<ShadowType> conflictedShadow, ResourceType resource, OperationResult parentResult) {
ResourceOperationDescription failureDesc = new ResourceOperationDescription();
failureDesc.setCurrentShadow(conflictedShadow);
ObjectDelta<ShadowType> objectDelta = null;
if (FailedOperationTypeType.ADD == conflictedShadow.asObjectable().getFailedOperationType()) {
objectDelta = ObjectDelta.createAddDelta(conflictedShadow);
}
failureDesc.setObjectDelta(objectDelta);
failureDesc.setResource(resource.asPrismObject());
failureDesc.setResult(parentResult);
failureDesc.setSourceChannel(SchemaConstants.CHANGE_CHANNEL_DISCOVERY.getLocalPart());
return failureDesc;
}
use of com.evolveum.midpoint.provisioning.api.ResourceOperationDescription in project midpoint by Evolveum.
the class SimpleResourceObjectNotifier method getBody.
@Override
protected String getBody(Event event, GeneralNotifierType generalNotifierType, String transport, Task task, OperationResult result) {
boolean techInfo = Boolean.TRUE.equals(generalNotifierType.isShowTechnicalInformation());
StringBuilder body = new StringBuilder();
ResourceObjectEvent resourceObjectEvent = (ResourceObjectEvent) event;
FocusType owner = (FocusType) resourceObjectEvent.getRequesteeObject();
ResourceOperationDescription rod = resourceObjectEvent.getAccountOperationDescription();
ObjectDelta<ShadowType> delta = (ObjectDelta<ShadowType>) rod.getObjectDelta();
boolean isAccount = resourceObjectEvent.isShadowKind(ShadowKindType.ACCOUNT);
String objectTypeDescription = isAccount ? "account" : "resource object";
String userOrOwner = owner instanceof UserType ? "User" : "Owner";
body.append("Notification about ").append(objectTypeDescription).append("-related operation\n\n");
if (isAccount) {
if (owner != null) {
body.append(userOrOwner).append(": ").append(resourceObjectEvent.getRequesteeDisplayName());
body.append(" (").append(owner.getName()).append(", oid ").append(owner.getOid()).append(")\n");
} else {
body.append(userOrOwner).append(": unknown\n");
}
}
body.append("Notification created on: " + new Date() + "\n\n");
body.append("Resource: " + resourceObjectEvent.getResourceName() + " (oid " + resourceObjectEvent.getResourceOid() + ")\n");
boolean named;
if (rod.getCurrentShadow() != null && rod.getCurrentShadow().asObjectable().getName() != null) {
if (isAccount) {
body.append("Account: " + rod.getCurrentShadow().asObjectable().getName() + "\n");
} else {
body.append("Resource object: " + rod.getCurrentShadow().asObjectable().getName() + " (kind: " + rod.getCurrentShadow().asObjectable().getKind() + ")\n");
}
named = true;
} else {
named = false;
}
body.append("\n");
if (isAccount) {
body.append((named ? "The" : "An") + " account ");
} else {
body.append((named ? "The" : "A") + " resource object ");
}
switch(resourceObjectEvent.getOperationStatus()) {
case SUCCESS:
body.append("has been successfully ");
break;
case IN_PROGRESS:
body.append("has been ATTEMPTED to be ");
break;
case FAILURE:
body.append("FAILED to be ");
break;
}
final boolean watchSynchronizationAttributes = isWatchSynchronizationAttributes((SimpleResourceObjectNotifierType) generalNotifierType);
final boolean watchAuxiliaryAttributes = isWatchAuxiliaryAttributes(generalNotifierType);
if (delta.isAdd()) {
body.append("created on the resource with attributes:\n");
body.append(resourceObjectEvent.getContentAsFormattedList(watchSynchronizationAttributes, watchAuxiliaryAttributes));
body.append("\n");
} else if (delta.isModify()) {
body.append("modified on the resource. Modified attributes are:\n");
body.append(resourceObjectEvent.getContentAsFormattedList(watchSynchronizationAttributes, watchAuxiliaryAttributes));
body.append("\n");
} else if (delta.isDelete()) {
body.append("removed from the resource.\n\n");
}
if (resourceObjectEvent.getOperationStatus() == OperationStatus.IN_PROGRESS) {
body.append("The operation will be retried.\n\n");
} else if (resourceObjectEvent.getOperationStatus() == OperationStatus.FAILURE) {
body.append("Error: " + resourceObjectEvent.getAccountOperationDescription().getResult().getMessage() + "\n\n");
}
body.append("\n\n");
functions.addRequesterAndChannelInformation(body, event, result);
if (techInfo) {
body.append("----------------------------------------\n");
body.append("Technical information:\n\n");
body.append(rod.debugDump(2));
}
return body.toString();
}
use of com.evolveum.midpoint.provisioning.api.ResourceOperationDescription in project midpoint by Evolveum.
the class SchemaExceptionHandler method handleError.
@Override
public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Exception ex, boolean doDiscovery, boolean compensate, Task task, OperationResult parentResult) throws SchemaException, GenericFrameworkException, CommunicationException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException, SecurityViolationException {
if (!doDiscovery) {
parentResult.recordFatalError(ex);
if (ex instanceof SchemaException) {
throw (SchemaException) ex;
} else {
throw new SchemaException(ex.getMessage(), ex);
}
}
ObjectDelta delta = null;
switch(op) {
case ADD:
delta = ObjectDelta.createAddDelta(shadow.asPrismObject());
break;
case DELETE:
delta = ObjectDelta.createDeleteDelta(shadow.getClass(), shadow.getOid(), prismContext);
break;
case MODIFY:
Collection<? extends ItemDelta> modifications = null;
if (shadow.getObjectChange() != null) {
ObjectDeltaType deltaType = shadow.getObjectChange();
modifications = DeltaConvertor.toModifications(deltaType.getItemDelta(), shadow.asPrismObject().getDefinition());
}
delta = ObjectDelta.createModifyDelta(shadow.getOid(), modifications, shadow.getClass(), prismContext);
break;
}
if (op != FailedOperation.GET) {
// Task task = taskManager.createTaskInstance();
ResourceOperationDescription operationDescription = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, parentResult);
changeNotificationDispatcher.notifyFailure(operationDescription, task, parentResult);
}
if (shadow.getOid() == null) {
parentResult.recordFatalError("Schema violation during processing shadow: " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
throw new SchemaException("Schema violation during processing shadow: " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
}
Collection<ItemDelta> modification = createAttemptModification(shadow, null);
try {
ConstraintsChecker.onShadowModifyOperation(modification);
cacheRepositoryService.modifyObject(shadow.asPrismObject().getCompileTimeClass(), shadow.getOid(), modification, parentResult);
} catch (Exception e) {
//this should not happen. But if it happens, we should return original exception
// throw new SchemaException("Schema violation during processing shadow: "
// + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
}
parentResult.recordFatalError("Schema violation during processing shadow: " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
throw new SchemaException("Schema violation during processing shadow: " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
}
use of com.evolveum.midpoint.provisioning.api.ResourceOperationDescription in project midpoint by Evolveum.
the class SecurityViolationHandler method handleError.
@Override
public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Exception ex, boolean doDiscovery, boolean compensate, Task task, OperationResult parentResult) throws SchemaException, GenericFrameworkException, CommunicationException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException, SecurityViolationException {
if (!doDiscovery) {
parentResult.recordFatalError(ex);
if (ex instanceof SecurityViolationException) {
throw (SecurityViolationException) ex;
} else {
throw new SecurityViolationException(ex.getMessage(), ex);
}
}
ObjectDelta delta = null;
switch(op) {
case ADD:
delta = ObjectDelta.createAddDelta(shadow.asPrismObject());
break;
case DELETE:
delta = ObjectDelta.createDeleteDelta(shadow.getClass(), shadow.getOid(), prismContext);
break;
case MODIFY:
Collection<? extends ItemDelta> modifications = null;
if (shadow.getObjectChange() != null) {
ObjectDeltaType deltaType = shadow.getObjectChange();
modifications = DeltaConvertor.toModifications(deltaType.getItemDelta(), shadow.asPrismObject().getDefinition());
}
delta = ObjectDelta.createModifyDelta(shadow.getOid(), modifications, shadow.getClass(), prismContext);
break;
}
if (op != FailedOperation.GET) {
// Task task = taskManager.createTaskInstance();
ResourceOperationDescription operationDescription = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, parentResult);
changeNotificationDispatcher.notifyFailure(operationDescription, task, parentResult);
}
if (shadow.getOid() == null) {
throw new SecurityViolationException("Security violation during processing shadow " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
}
Collection<ItemDelta> modification = createAttemptModification(shadow, null);
try {
ConstraintsChecker.onShadowModifyOperation(modification);
cacheRepositoryService.modifyObject(shadow.asPrismObject().getCompileTimeClass(), shadow.getOid(), modification, parentResult);
} catch (Exception e) {
//this should not happen. But if it happens, we should return original exception
}
throw new SecurityViolationException("Security violation during processing shadow " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
}
Aggregations