Search in sources :

Example 11 with ObjectDeltaOperationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType in project midpoint by Evolveum.

the class AbstractTestForExchangeConnector method modifyRoleAssignment.

protected boolean modifyRoleAssignment(Class clazz, String oid, boolean isAdd, String... roleOids) throws FaultMessage {
    ItemDeltaType assignmentDelta = new ItemDeltaType();
    if (isAdd) {
        assignmentDelta.setModificationType(ModificationTypeType.ADD);
    } else {
        assignmentDelta.setModificationType(ModificationTypeType.DELETE);
    }
    assignmentDelta.setPath(ModelClientUtil.createItemPathType("assignment"));
    for (String roleOid : roleOids) {
        AssertJUnit.assertNotNull("role OID is null", roleOid);
        assignmentDelta.getValue().add(createRoleAssignment(roleOid));
    }
    ObjectDeltaType deltaType = new ObjectDeltaType();
    deltaType.setObjectType(ModelClientUtil.getTypeQName(clazz));
    deltaType.setChangeType(ChangeTypeType.MODIFY);
    deltaType.setOid(oid);
    deltaType.getItemDelta().add(assignmentDelta);
    ObjectDeltaListType deltaListType = new ObjectDeltaListType();
    deltaListType.getDelta().add(deltaType);
    ObjectDeltaOperationListType objectDeltaOperationList = modelPort.executeChanges(deltaListType, null);
    Boolean success = null;
    for (ObjectDeltaOperationType objectDeltaOperation : objectDeltaOperationList.getDeltaOperation()) {
        if (oid.equals(objectDeltaOperation.getObjectDelta().getOid())) {
            if (!OperationResultStatusType.SUCCESS.equals(objectDeltaOperation.getExecutionResult().getStatus())) {
                System.out.println("*** Operation result = " + objectDeltaOperation.getExecutionResult().getStatus() + ": " + objectDeltaOperation.getExecutionResult().getMessage());
                success = false;
            } else {
                if (success == null) {
                    success = true;
                }
            }
        }
    }
    return Boolean.TRUE.equals(success);
}
Also used : ObjectDeltaOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ObjectDeltaOperationListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType) ObjectDeltaListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)

Example 12 with ObjectDeltaOperationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType in project midpoint by Evolveum.

the class AuditController method rollBackTime.

private <O extends ObjectType> PrismObject<O> rollBackTime(PrismObject<O> object, List<AuditEventRecordType> changeTrail) throws SchemaException {
    for (AuditEventRecordType event : changeTrail) {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Applying event {} ({})", event.getEventIdentifier(), event.getTimestamp());
        }
        List<ObjectDeltaOperationType> deltaOperations = event.getDelta();
        for (ObjectDeltaOperationType deltaOperation : deltaOperations) {
            if (!isApplicable(deltaOperation, object, event)) {
                continue;
            }
            ObjectDelta<O> objectDelta = DeltaConvertor.createObjectDelta(deltaOperation.getObjectDelta(), prismContext);
            if (objectDelta.isDelete()) {
                throw new SchemaException("Delete delta found in the audit trail." + " Object history cannot be reconstructed.");
            }
            if (objectDelta.isAdd()) {
                throw new SchemaException("Add delta found in the audit trail." + " Object history cannot be reconstructed.");
            }
            ObjectDelta<O> reverseDelta = objectDelta.createReverseDelta();
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Applying delta (reverse):\n{}", reverseDelta.debugDump(1));
            }
            reverseDelta.applyTo(object);
        }
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Object after application of event {} ({}):\n{}", event.getEventIdentifier(), event.getTimestamp(), object.debugDump(1));
        }
    }
    return object;
}
Also used : AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType)

Example 13 with ObjectDeltaOperationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType in project midpoint by Evolveum.

the class AuditController method getObjectFromLastEvent.

/**
 * Side effect: removes the last event.
 *
 * The reason is that we don't want to use it when rolling back the time later in
 * {@link #rollBackTime(PrismObject, List)}. It is the reference event that we want to
 * know the object state on.
 */
private <O extends ObjectType> PrismObject<O> getObjectFromLastEvent(PrismObject<O> object, List<AuditEventRecordType> changeTrail, String eventIdentifier) {
    if (changeTrail.isEmpty()) {
        return object;
    }
    AuditEventRecordType lastEvent = changeTrail.remove(changeTrail.size() - 1);
    if (!eventIdentifier.equals(lastEvent.getEventIdentifier())) {
        throw new IllegalStateException("Wrong last event identifier, expected " + eventIdentifier + " but was " + lastEvent.getEventIdentifier());
    }
    List<ObjectDeltaOperationType> lastEventDeltasOperations = lastEvent.getDelta();
    for (ObjectDeltaOperationType lastEventDeltasOperation : lastEventDeltasOperations) {
        if (!isApplicable(lastEventDeltasOperation, object, lastEvent)) {
            continue;
        }
        ObjectDeltaType objectDelta = lastEventDeltasOperation.getObjectDelta();
        if (objectDelta.getChangeType() == ChangeTypeType.ADD) {
            // We are lucky. This is object add, so we have complete object there.
            // No need to roll back the operations.
            // noinspection unchecked
            PrismObject<O> objectToAdd = objectDelta.getObjectToAdd().asPrismObject();
            LOGGER.trace("Taking object from add delta in last event {}:\n{}", lastEvent.getEventIdentifier(), objectToAdd.debugDumpLazily(1));
            return objectToAdd;
        }
    }
    return null;
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType)

Example 14 with ObjectDeltaOperationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType in project midpoint by Evolveum.

the class SqlAuditServiceImpl method convertDelta.

private MAuditDelta convertDelta(ObjectDeltaOperationType deltaOperation, MAuditEventRecord auditRow) {
    MAuditDelta mAuditDelta = new MAuditDelta();
    mAuditDelta.recordId = auditRow.id;
    try {
        ObjectDeltaType delta = deltaOperation.getObjectDelta();
        if (delta != null) {
            DeltaConversionOptions options = DeltaConversionOptions.createSerializeReferenceNames();
            options.setEscapeInvalidCharacters(isEscapingInvalidCharacters(auditConfiguration));
            String serializedDelta = DeltaConvertor.serializeDelta(delta, options, PrismContext.LANG_XML);
            // serializedDelta is transient, needed for changed items later
            mAuditDelta.serializedDelta = serializedDelta;
            mAuditDelta.delta = RUtil.getBytesFromSerializedForm(serializedDelta, sqlConfiguration().isUseZipAudit());
            mAuditDelta.deltaOid = delta.getOid();
            mAuditDelta.deltaType = MiscUtil.enumOrdinal(RUtil.getRepoEnumValue(ChangeType.toChangeType(delta.getChangeType()), RChangeType.class));
            for (ItemDeltaType itemDelta : delta.getItemDelta()) {
                ItemPath path = itemDelta.getPath().getItemPath();
                CanonicalItemPath canonical = schemaService.createCanonicalItemPath(path, delta.getObjectType());
                for (int i = 0; i < canonical.size(); i++) {
                    auditRow.addChangedItem(canonical.allUpToIncluding(i).asString());
                }
            }
        }
        OperationResultType executionResult = deltaOperation.getExecutionResult();
        if (executionResult != null) {
            mAuditDelta.status = MiscUtil.enumOrdinal(RUtil.getRepoEnumValue(executionResult.getStatus(), ROperationResultStatus.class));
            // Note that escaping invalid characters and using toString for unsupported types is safe in the
            // context of operation result serialization.
            String full = schemaService.createStringSerializer(PrismContext.LANG_XML).options(SerializationOptions.createEscapeInvalidCharacters().serializeUnsupportedTypesAsString(true)).serializeRealValue(executionResult, SchemaConstantsGenerated.C_OPERATION_RESULT);
            mAuditDelta.fullResult = RUtil.getBytesFromSerializedForm(full, sqlConfiguration().isUseZipAudit());
        }
        mAuditDelta.resourceOid = deltaOperation.getResourceOid();
        if (deltaOperation.getObjectName() != null) {
            mAuditDelta.objectNameOrig = deltaOperation.getObjectName().getOrig();
            mAuditDelta.objectNameNorm = deltaOperation.getObjectName().getNorm();
        }
        if (deltaOperation.getResourceName() != null) {
            mAuditDelta.resourceNameOrig = deltaOperation.getResourceName().getOrig();
            mAuditDelta.resourceNameNorm = deltaOperation.getResourceName().getNorm();
        }
        mAuditDelta.checksum = RUtil.computeChecksum(mAuditDelta.delta, mAuditDelta.fullResult);
    } catch (Exception ex) {
        throw new SystemException("Problem during audit delta conversion", ex);
    }
    return mAuditDelta;
}
Also used : MAuditDelta(com.evolveum.midpoint.repo.sql.audit.beans.MAuditDelta) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) SystemException(com.evolveum.midpoint.util.exception.SystemException) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 15 with ObjectDeltaOperationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType in project midpoint by Evolveum.

the class AuditInsertion method collectChangedItemPaths.

/**
 * Returns distinct collected changed item paths, or null, never an empty array.
 */
private String[] collectChangedItemPaths(List<ObjectDeltaOperationType> deltaOperations) {
    Set<String> changedItemPaths = new HashSet<>();
    for (ObjectDeltaOperationType deltaOperation : deltaOperations) {
        ObjectDeltaType delta = deltaOperation.getObjectDelta();
        for (ItemDeltaType itemDelta : delta.getItemDelta()) {
            ItemPath path = itemDelta.getPath().getItemPath();
            CanonicalItemPath canonical = repoContext.prismContext().createCanonicalItemPath(path, delta.getObjectType());
            for (int i = 0; i < canonical.size(); i++) {
                changedItemPaths.add(canonical.allUpToIncluding(i).asString());
            }
        }
    }
    return changedItemPaths.isEmpty() ? null : changedItemPaths.toArray(String[]::new);
}
Also used : ObjectDeltaOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ObjectDeltaOperationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType)28 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)23 ObjectDeltaOperationListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType)12 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)12 ObjectDeltaListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType)11 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)9 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)6 QName (javax.xml.namespace.QName)5 Test (org.testng.annotations.Test)4 SystemException (com.evolveum.midpoint.util.exception.SystemException)3 AuditEventRecordType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType)3 ModelExecuteOptionsType (com.evolveum.midpoint.xml.ns._public.common.common_3.ModelExecuteOptionsType)3 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)3 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)3 CanonicalItemPath (com.evolveum.midpoint.prism.path.CanonicalItemPath)2 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 MAuditDelta (com.evolveum.midpoint.repo.sql.audit.beans.MAuditDelta)2 DeltaConversionOptions (com.evolveum.midpoint.schema.DeltaConversionOptions)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2