Search in sources :

Example 1 with ObjectDelta

use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.

the class DefaultGuiProgressListener method updateStatusItemState.

private void updateStatusItemState(ProgressReportActivityDto si, ProgressInformation progressInformation, ModelContext modelContext) {
    si.setActivityType(progressInformation.getActivityType());
    si.setResourceShadowDiscriminator(progressInformation.getResourceShadowDiscriminator());
    if (progressInformation.getResourceShadowDiscriminator() != null) {
        String resourceOid = progressInformation.getResourceShadowDiscriminator().getResourceOid();
        String resourceName = resourceOid != null ? getResourceName(resourceOid) : "";
        si.setResourceName(resourceName);
    }
    if (progressInformation.getStateType() == null) {
        si.setStatus(null);
    } else if (progressInformation.getStateType() == ENTERING) {
        si.setStatus(OperationResultStatusType.IN_PROGRESS);
    } else {
        OperationResult result = progressInformation.getOperationResult();
        if (result != null) {
            OperationResultStatus status = result.getStatus();
            if (status == OperationResultStatus.UNKNOWN) {
                status = result.getComputeStatus();
            }
            si.setStatus(status.createStatusType());
        } else {
            si.setStatus(OperationResultStatusType.UNKNOWN);
        }
    }
    // information about modifications on a resource
    if (progressInformation.getActivityType() == RESOURCE_OBJECT_OPERATION && progressInformation.getStateType() == EXITING && progressInformation.getResourceShadowDiscriminator() != null && progressInformation.getResourceShadowDiscriminator().getResourceOid() != null) {
        ModelProjectionContext mpc = modelContext.findProjectionContext(progressInformation.getResourceShadowDiscriminator());
        if (mpc != null) {
            // it shouldn't be null!
            // operations performed (TODO aggregate them somehow?)
            List<ResourceOperationResult> resourceOperationResultList = new ArrayList<>();
            List<? extends ObjectDeltaOperation> executedDeltas = mpc.getExecutedDeltas();
            for (ObjectDeltaOperation executedDelta : executedDeltas) {
                ObjectDelta delta = executedDelta.getObjectDelta();
                if (delta != null) {
                    OperationResult r = executedDelta.getExecutionResult();
                    OperationResultStatus status = r.getStatus();
                    if (status == OperationResultStatus.UNKNOWN) {
                        status = r.getComputeStatus();
                    }
                    resourceOperationResultList.add(new ResourceOperationResult(delta.getChangeType(), status));
                }
            }
            si.setResourceOperationResultList(resourceOperationResultList);
            // object name
            PrismObject<ShadowType> object = mpc.getObjectNew();
            if (object == null) {
                object = mpc.getObjectOld();
            }
            String name = null;
            if (object != null) {
                if (object.asObjectable().getName() != null) {
                    name = PolyString.getOrig(object.asObjectable().getName());
                } else {
                    // determine from attributes
                    ResourceAttribute nameAttribute = ShadowUtil.getNamingAttribute(object);
                    if (nameAttribute != null) {
                        name = String.valueOf(nameAttribute.getAnyRealValue());
                    }
                }
            }
            if (name != null) {
                si.setResourceObjectName(name);
            }
        }
    }
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceOperationResult(com.evolveum.midpoint.web.component.progress.ProgressReportActivityDto.ResourceOperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) ResourceOperationResult(com.evolveum.midpoint.web.component.progress.ProgressReportActivityDto.ResourceOperationResult)

Example 2 with ObjectDelta

use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.

the class PageUser method saveDelegationToUser.

private void saveDelegationToUser(UserType user, List<AssignmentEditorDto> assignmentEditorDtos) {
    OperationResult result = new OperationResult(OPERATION_SAVE);
    ObjectDelta<UserType> delta;
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
    try {
        delta = user.asPrismObject().createModifyDelta();
        deltas.add(delta);
        PrismContainerDefinition def = user.asPrismObject().getDefinition().findContainerDefinition(UserType.F_ASSIGNMENT);
        handleAssignmentDeltas(delta, assignmentEditorDtos, def, true);
        getModelService().executeChanges(deltas, null, createSimpleTask(OPERATION_SAVE), result);
        result.recordSuccess();
    } catch (Exception e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Could not save assignments ", e);
        error("Could not save assignments. Reason: " + e);
    } finally {
        result.recomputeStatus();
    }
    showResult(result);
}
Also used : PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 3 with ObjectDelta

use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.

the class OrgMemberPanel method addMembersPerformed.

@Override
protected void addMembersPerformed(QName type, QName relation, List selected, AjaxRequestTarget target) {
    Task operationalTask = getPageBase().createSimpleTask(getTaskName("Add", null, false));
    ObjectDelta delta = prepareDelta(MemberOperation.ADD, type, relation, operationalTask.getResult(), target);
    if (delta == null) {
        return;
    }
    executeMemberOperation(operationalTask, type, createQueryForAdd(selected), delta, TaskCategory.EXECUTE_CHANGES, target);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 4 with ObjectDelta

use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.

the class OrgMemberPanel method deleteMemberConfirmPerformed.

private void deleteMemberConfirmPerformed(QueryScope scope, QName relation, AjaxRequestTarget target) {
    getPageBase().hideMainPopup(target);
    Task operationalTask = getPageBase().createSimpleTask(getTaskName("Delete", scope, false));
    ObjectDelta delta = ObjectDelta.createDeleteDelta(FocusType.class, "fakeOid", getPageBase().getPrismContext());
    if (delta == null) {
        return;
    }
    executeMemberOperation(operationalTask, FocusType.COMPLEX_TYPE, createQueryForMemberAction(scope, relation, true), delta, TaskCategory.EXECUTE_CHANGES, target);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 5 with ObjectDelta

use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.

the class OrgMemberPanel method createMemberDelta.

protected ObjectDelta createMemberDelta(MemberOperation operation, QName type, QName relation) throws SchemaException {
    Class classType = WebComponentUtil.qnameToClass(getPageBase().getPrismContext(), type);
    ObjectDelta delta = null;
    switch(operation) {
        case ADD:
            if (isFocus(type)) {
                delta = ObjectDelta.createModificationAddContainer(classType, "fakeOid", FocusType.F_ASSIGNMENT, getPageBase().getPrismContext(), createAssignmentToModify(relation));
            } else {
                delta = ObjectDelta.createModificationAddReference(classType, "fakeOid", ObjectType.F_PARENT_ORG_REF, getPageBase().getPrismContext(), createReference(relation).asReferenceValue());
            }
            break;
        case REMOVE:
            if (isFocus(type)) {
                delta = ObjectDelta.createModificationDeleteContainer(classType, "fakeOid", FocusType.F_ASSIGNMENT, getPageBase().getPrismContext(), createAssignmentToModify(relation));
            } else {
                delta = ObjectDelta.createModificationDeleteReference(classType, "fakeOid", ObjectType.F_PARENT_ORG_REF, getPageBase().getPrismContext(), createReference(relation).asReferenceValue());
            }
            break;
        default:
            break;
    }
    return delta;
}
Also used : ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Aggregations

ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)445 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)363 Task (com.evolveum.midpoint.task.api.Task)326 Test (org.testng.annotations.Test)303 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)242 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)218 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)148 ArrayList (java.util.ArrayList)126 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)103 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)55 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)47 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)42 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)41 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)38 ShadowDiscriminatorObjectDelta (com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta)32 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)31 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)31 Collection (java.util.Collection)31 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)31 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)26