use of com.evolveum.midpoint.schema.result.OperationResultStatus in project midpoint by Evolveum.
the class TestMultiResource method jackUnAssignRoleDummiesError.
public void jackUnAssignRoleDummiesError(final String TEST_NAME, String roleOid) throws Exception {
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
TestUtil.displayWhen(TEST_NAME);
unassignRole(USER_JACK_OID, roleOid, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
display(result);
// there is a failure while reading dummy account - it was not created
// because of unavailability of the resource..but it is OK..
OperationResultStatus status = result.getStatus();
if (status != OperationResultStatus.SUCCESS && status != OperationResultStatus.PARTIAL_ERROR) {
AssertJUnit.fail("Expected result success or partial error status, but was " + status);
}
PrismObject<UserType> user = getUser(USER_JACK_OID);
assertAssignedNoRole(user);
assertLinks(user, 0);
assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
assertNoDummyAccount(RESOURCE_DUMMY_LAVENDER_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
assertNoDummyAccount(RESOURCE_DUMMY_IVORY_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
assertNoDummyAccount(RESOURCE_DUMMY_BEIGE_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
assertUserProperty(USER_JACK_OID, UserType.F_ORGANIZATIONAL_UNIT, PrismTestUtil.createPolyString("The crew of The Lost Souls"));
}
use of com.evolveum.midpoint.schema.result.OperationResultStatus in project midpoint by Evolveum.
the class ShadowCache method refreshShadow.
public PrismObject<ShadowType> refreshShadow(PrismObject<ShadowType> repoShadow, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
ShadowType shadowType = repoShadow.asObjectable();
List<PendingOperationType> pendingOperations = shadowType.getPendingOperation();
if (pendingOperations.isEmpty()) {
LOGGER.trace("Skipping refresh of {} because there are no pending operations", repoShadow);
return repoShadow;
}
LOGGER.trace("Refreshing {}", repoShadow);
ProvisioningContext ctx = ctxFactory.create(repoShadow, task, parentResult);
ctx.assertDefinition();
Duration gracePeriod = null;
ResourceConsistencyType consistency = ctx.getResource().getConsistency();
if (consistency != null) {
gracePeriod = consistency.getPendingOperationGracePeriod();
}
List<ObjectDelta<ShadowType>> notificationDeltas = new ArrayList<>();
List<PendingOperationType> sortedOperations = sortOperations(pendingOperations);
boolean isDead = ShadowUtil.isDead(shadowType);
ObjectDelta<ShadowType> shadowDelta = repoShadow.createModifyDelta();
for (PendingOperationType pendingOperation : sortedOperations) {
ItemPath containerPath = pendingOperation.asPrismContainerValue().getPath();
OperationResultStatusType statusType = pendingOperation.getResultStatus();
XMLGregorianCalendar completionTimestamp = pendingOperation.getCompletionTimestamp();
XMLGregorianCalendar now = null;
String asyncRef = pendingOperation.getAsynchronousOperationReference();
if (asyncRef != null) {
OperationResultStatus newStaus = resouceObjectConverter.refreshOperationStatus(ctx, repoShadow, asyncRef, parentResult);
now = clock.currentTimeXMLGregorianCalendar();
if (newStaus != null) {
OperationResultStatusType newStatusType = newStaus.createStatusType();
if (!newStatusType.equals(pendingOperation.getResultStatus())) {
boolean operationCompleted = isCompleted(newStatusType) && pendingOperation.getCompletionTimestamp() == null;
if (operationCompleted && gracePeriod == null) {
LOGGER.trace("Deleting pending operation because it is completed (no grace): {}", pendingOperation);
shadowDelta.addModificationDeleteContainer(new ItemPath(ShadowType.F_PENDING_OPERATION), pendingOperation.clone());
continue;
} else {
PropertyDelta<OperationResultStatusType> statusDelta = shadowDelta.createPropertyModification(containerPath.subPath(PendingOperationType.F_RESULT_STATUS));
statusDelta.setValuesToReplace(new PrismPropertyValue<>(newStatusType));
shadowDelta.addModification(statusDelta);
}
statusType = newStatusType;
if (operationCompleted) {
// Operation completed
PropertyDelta<XMLGregorianCalendar> timestampDelta = shadowDelta.createPropertyModification(containerPath.subPath(PendingOperationType.F_COMPLETION_TIMESTAMP));
timestampDelta.setValuesToReplace(new PrismPropertyValue<>(now));
shadowDelta.addModification(timestampDelta);
completionTimestamp = now;
ObjectDeltaType pendingDeltaType = pendingOperation.getDelta();
ObjectDelta<ShadowType> pendingDelta = DeltaConvertor.createObjectDelta(pendingDeltaType, prismContext);
if (pendingDelta.isAdd()) {
// We do not need to care about attributes in add deltas here. The add operation is already applied to
// attributes. We need this to "allocate" the identifiers, so iteration mechanism in the
// model can find unique values while taking pending create operations into consideration.
PropertyDelta<Boolean> existsDelta = shadowDelta.createPropertyModification(new ItemPath(ShadowType.F_EXISTS));
existsDelta.setValuesToReplace(new PrismPropertyValue<>(true));
shadowDelta.addModification(existsDelta);
}
if (pendingDelta.isModify()) {
for (ItemDelta<?, ?> pendingModification : pendingDelta.getModifications()) {
shadowDelta.addModification(pendingModification.clone());
}
}
if (pendingDelta.isDelete()) {
isDead = true;
if (gracePeriod == null) {
shadowDelta = repoShadow.createDeleteDelta();
notificationDeltas.add(pendingDelta);
break;
} else {
PropertyDelta<Boolean> deadDelta = shadowDelta.createPropertyModification(new ItemPath(ShadowType.F_DEAD));
deadDelta.setValuesToReplace(new PrismPropertyValue<>(true));
shadowDelta.addModification(deadDelta);
PropertyDelta<Boolean> existsDelta = shadowDelta.createPropertyModification(new ItemPath(ShadowType.F_EXISTS));
existsDelta.setValuesToReplace(new PrismPropertyValue<>(false));
shadowDelta.addModification(existsDelta);
}
}
notificationDeltas.add(pendingDelta);
}
}
}
}
if (now == null) {
now = clock.currentTimeXMLGregorianCalendar();
}
}
if (shadowDelta.isDelete()) {
LOGGER.trace("Deleting dead shadow because pending delete delta was completed (no grace period): {}", repoShadow);
shadowManager.deleteShadow(ctx, repoShadow, null, parentResult);
return null;
}
XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
boolean atLeastOnePendingOperationRemains = expirePendingOperations(ctx, repoShadow, shadowDelta, now, parentResult);
if (shadowType.getFailedOperationType() != null) {
atLeastOnePendingOperationRemains = true;
}
if (isDead && !atLeastOnePendingOperationRemains) {
LOGGER.trace("Deleting dead shadow because all pending operations expired: {}", repoShadow);
shadowManager.deleteShadow(ctx, repoShadow, null, parentResult);
return null;
}
if (!shadowDelta.isEmpty()) {
shadowManager.modifyShadowAttributes(ctx, repoShadow, shadowDelta.getModifications(), parentResult);
}
for (ObjectDelta<ShadowType> notificationDelta : notificationDeltas) {
ResourceOperationDescription operationDescription = createSuccessOperationDescription(ctx, repoShadow, notificationDelta, parentResult);
operationListener.notifySuccess(operationDescription, task, parentResult);
}
if (shadowDelta.isEmpty()) {
return repoShadow;
}
shadowDelta.applyTo(repoShadow);
return repoShadow;
}
use of com.evolveum.midpoint.schema.result.OperationResultStatus in project midpoint by Evolveum.
the class ResourceObjectConverter method computeResultStatus.
private void computeResultStatus(OperationResult parentResult) {
if (parentResult.isInProgress()) {
return;
}
OperationResultStatus status = OperationResultStatus.SUCCESS;
String asyncRef = null;
for (OperationResult subresult : parentResult.getSubresults()) {
if (OPERATION_MODIFY_ENTITLEMENT.equals(subresult.getOperation()) && subresult.isError()) {
status = OperationResultStatus.PARTIAL_ERROR;
} else if (subresult.isError()) {
status = OperationResultStatus.FATAL_ERROR;
} else if (subresult.isInProgress()) {
status = OperationResultStatus.IN_PROGRESS;
asyncRef = subresult.getAsynchronousOperationReference();
}
}
parentResult.setStatus(status);
parentResult.setAsynchronousOperationReference(asyncRef);
}
use of com.evolveum.midpoint.schema.result.OperationResultStatus in project midpoint by Evolveum.
the class Projector method computeResultStatus.
private void computeResultStatus(XMLGregorianCalendar projectoStartTimestampCal, OperationResult result) {
boolean hasProjectionErrror = false;
OperationResultStatus finalStatus = OperationResultStatus.SUCCESS;
String message = null;
for (OperationResult subresult : result.getSubresults()) {
if (subresult.isNotApplicable() || subresult.isSuccess()) {
continue;
}
if (subresult.isHandledError()) {
if (finalStatus == OperationResultStatus.SUCCESS) {
finalStatus = OperationResultStatus.HANDLED_ERROR;
}
continue;
}
if (subresult.isError()) {
message = subresult.getMessage();
if (OPERATION_PROJECT_PROJECTION.equals(subresult.getOperation())) {
hasProjectionErrror = true;
} else {
if (finalStatus != OperationResultStatus.FATAL_ERROR) {
finalStatus = subresult.getStatus();
}
}
}
}
if (finalStatus != OperationResultStatus.FATAL_ERROR && hasProjectionErrror) {
finalStatus = OperationResultStatus.PARTIAL_ERROR;
}
result.setStatus(finalStatus);
result.setMessage(message);
result.cleanupResult();
if (LOGGER.isDebugEnabled()) {
long projectoStartTimestamp = XmlTypeConverter.toMillis(projectoStartTimestampCal);
long projectorEndTimestamp = clock.currentTimeMillis();
LOGGER.trace("Projector finished ({}). Etime: {} ms", result.getStatus(), (projectorEndTimestamp - projectoStartTimestamp));
}
}
Aggregations