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);
}
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;
}
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;
}
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;
}
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);
}
Aggregations