public static List<ObjectDeltaOperation<ShadowType>> findProjectionDeltasInCollection(Collection<ObjectDeltaOperation<? extends ObjectType>> odos) { List<ObjectDeltaOperation<ShadowType>> projectionDeltas = new ArrayList<>(); for (ObjectDeltaOperation<? extends ObjectType> odo : odos) { Class<? extends ObjectType> objectTypeClass = odo.getObjectDelta().getObjectTypeClass(); if (ShadowType.class.equals(objectTypeClass)) { projectionDeltas.add((ObjectDeltaOperation<ShadowType>) odo); } } return projectionDeltas; }
public static ObjectDeltaOperation<? extends ObjectType> findFocusDeltaInCollection(Collection<ObjectDeltaOperation<? extends ObjectType>> odos) { for (ObjectDeltaOperation<? extends ObjectType> odo : odos) { Class<? extends ObjectType> objectTypeClass = odo.getObjectDelta().getObjectTypeClass(); if (!ShadowType.class.equals(objectTypeClass)) { return odo; } } return null; }
public static List<String> findProjectionDeltaOidsInCollection(Collection<ObjectDeltaOperation<? extends ObjectType>> executeChanges) { return findProjectionDeltasInCollection(executeChanges).stream() .map(odo -> odo.getObjectDelta().getOid()) .distinct() .collect(Collectors.toList()); }
private String formatDeltaSummary(Collection<ObjectDeltaOperation<? extends ObjectType>> collection) { if (collection == null) { return "null"; } StringBuilder sb = new StringBuilder("["); Iterator<ObjectDeltaOperation<? extends ObjectType>> iterator = collection.iterator(); while (iterator.hasNext()) { ObjectDeltaOperation<?> delta = iterator.next(); sb.append(delta.getObjectDelta().getOid()).append(":").append(delta.getObjectDelta().getChangeType()); if (iterator.hasNext()) { sb.append(","); } } sb.append("]"); return sb.toString(); }
public static <O extends ObjectType> ObjectDeltaOperation<O> findAddDelta(Collection<ObjectDeltaOperation<? extends ObjectType>> executedChanges, PrismObject<O> object) { for (ObjectDeltaOperation<? extends ObjectType> odo : executedChanges) { Class<? extends ObjectType> objectTypeClass = odo.getObjectDelta().getObjectTypeClass(); if (odo.getObjectDelta().isAdd() && object.getCompileTimeClass().equals(objectTypeClass)) { return (ObjectDeltaOperation<O>) odo; } } return null; }
public List<ObjectDelta<FocusType>> getFocusDeltas() { List<ObjectDelta<FocusType>> retval = new ArrayList<>(); Class c = modelContext.getFocusClass(); if (c != null && FocusType.class.isAssignableFrom(c)) { for (Object o : getFocusExecutedDeltas()) { ObjectDeltaOperation objectDeltaOperation = (ObjectDeltaOperation) o; retval.add(objectDeltaOperation.getObjectDelta()); } } return retval; }
public static PrismReferenceValue determineAuditTargetDeltaOps( Collection<ObjectDeltaOperation<? extends ObjectType>> deltaOps, PrismContext prismContext) { if (deltaOps == null || deltaOps.isEmpty()) { return null; } if (deltaOps.size() == 1) { ObjectDeltaOperation<? extends ObjectType> deltaOp = deltaOps.iterator().next(); return getAuditTarget(deltaOp.getObjectDelta(), prismContext); } for (ObjectDeltaOperation<? extends ObjectType> deltaOp: deltaOps) { if (!ShadowType.class.isAssignableFrom(deltaOp.getObjectDelta().getObjectTypeClass())) { return getAuditTarget(deltaOp.getObjectDelta(), prismContext); } } // Several raw operations, all on shadows, no focus ... this should not happen // But if it does we rather do not specify any target. We should not like to choose // target randomly. That would be confusing. return null; }
public static String findFocusDeltaOidInCollection(Collection<ObjectDeltaOperation<? extends ObjectType>> odos) { ObjectDeltaOperation<? extends ObjectType> odo = findFocusDeltaInCollection(odos); if (odo == null) { return null; } return odo.getObjectDelta().getOid(); }
@Override public boolean isOperationType(EventOperationType eventOperationType) { // we consider an operation to be 'add' when there is 'add' delta among deltas // in a similar way with 'delete' // // alternatively, we could summarize deltas and then decide based on the type of summarized delta (would be a bit inefficient) for (Object o : getFocusExecutedDeltas()) { ObjectDeltaOperation objectDeltaOperation = (ObjectDeltaOperation) o; if (objectDeltaOperation.getObjectDelta().isAdd()) { return eventOperationType == EventOperationType.ADD; } else if (objectDeltaOperation.getObjectDelta().isDelete()) { return eventOperationType == EventOperationType.DELETE; } } return eventOperationType == EventOperationType.MODIFY; }
public static <O extends ObjectType> String findAddDeltaOid(Collection<ObjectDeltaOperation<? extends ObjectType>> executedChanges, PrismObject<O> object) { ObjectDeltaOperation<O> odo = findAddDelta(executedChanges, object); if (odo == null) { return null; } return odo.getObjectDelta().getOid(); }
public void assertExecutionDeltaAdd() { ObjectDeltaOperation<?> delta = getExecutionDelta(0); assert delta.getObjectDelta().isAdd() : "Execution audit record is not add, it is "+delta; }
public <O extends ObjectType,T> void assertOldValue(String message, int index, ChangeType expectedChangeType, Class<O> expectedClass, ItemPath propPath, T... expectedValues) { ObjectDeltaOperation<O> deltaOp = getExecutionDelta(index, expectedChangeType, expectedClass); assert deltaOp != null : (message==null?"":message+": ")+"Delta for "+expectedClass+" of type "+expectedChangeType+" was not found in audit trail"; PropertyDelta<Object> propDelta = deltaOp.getObjectDelta().findPropertyDelta(propPath); assert propDelta != null : "No property delta for "+propPath+" in Delta for "+expectedClass+" of type "+expectedChangeType; Collection<PrismPropertyValue<Object>> estimatedOldValues = propDelta.getEstimatedOldValues(); if (expectedValues == null || expectedValues.length == 0) { if (estimatedOldValues == null || estimatedOldValues.isEmpty()) { return; } else { assert false : (message==null?"":message+": ") + "Empty old values in property delta for "+propPath+" in Delta for "+expectedClass+" of type "+expectedChangeType + ", expected " + Arrays.toString(expectedValues); } } assert estimatedOldValues != null && !estimatedOldValues.isEmpty() : "No old values in property delta for "+propPath+" in Delta for "+expectedClass+" of type "+expectedChangeType; PrismAsserts.assertValues((message==null?"":message+": ") +"Wrong old values in property delta for "+propPath+" in Delta for "+expectedClass+" of type "+expectedChangeType, estimatedOldValues, expectedValues); }
public <O extends ObjectType> ObjectDeltaOperation<O> getExecutionDelta(int index, ChangeType changeType, Class<O> typeClass) { for (ObjectDeltaOperation<? extends ObjectType> deltaOp: getExecutionDeltas(index)) { ObjectDelta<? extends ObjectType> delta = deltaOp.getObjectDelta(); if (delta.getObjectTypeClass() == typeClass && delta.getChangeType() == changeType) { return (ObjectDeltaOperation<O>) deltaOp; } } return null; }
public <O extends ObjectType,T> void assertPropertyReplace(String message, int index, ChangeType expectedChangeType, Class<O> expectedClass, ItemPath propPath, T... expectedValues) { ObjectDeltaOperation<O> deltaOp = getExecutionDelta(index, expectedChangeType, expectedClass); assert deltaOp != null : (message==null?"":message+": ")+"Delta for "+expectedClass+" of type "+expectedChangeType+" was not found in audit trail"; PropertyDelta<Object> propDelta = deltaOp.getObjectDelta().findPropertyDelta(propPath); assert propDelta != null : "No property delta for "+propPath+" in Delta for "+expectedClass+" of type "+expectedChangeType; Collection<PrismPropertyValue<Object>> valuesToReplace = propDelta.getValuesToReplace(); assert valuesToReplace != null : "No values to replace in property delta for "+propPath+" in Delta for "+expectedClass+" of type "+expectedChangeType; if (expectedValues == null || expectedValues.length == 0) { if (valuesToReplace.isEmpty()) { return; } else { assert false : (message==null?"":message+": ") + "Empty values to replace in property delta for "+propPath+" in Delta for "+expectedClass+" of type "+expectedChangeType + ", expected " + Arrays.toString(expectedValues); } } PrismAsserts.assertValues((message==null?"":message+": ") +"Wrong values to replace in property delta for "+propPath+" in Delta for "+expectedClass+" of type "+expectedChangeType, valuesToReplace, expectedValues); }
@Override public List<ShadowType> getShadowsToActivate(Collection<? extends ModelElementContext> projectionContexts) { List<ShadowType> shadows = new ArrayList<>(); for (ModelElementContext<ShadowType> projectionCtx : projectionContexts) { List<? extends ObjectDeltaOperation> executedShadowDelas = projectionCtx.getExecutedDeltas(); for (ObjectDeltaOperation<ShadowType> shadowDelta : executedShadowDelas) { if (shadowDelta.getExecutionResult().getStatus() == OperationResultStatus.SUCCESS && shadowDelta.getObjectDelta().getChangeType() == ChangeType.ADD) { PrismObject<ShadowType> shadow = shadowDelta.getObjectDelta().getObjectToAdd(); PrismProperty<String> pLifecycleState = shadow.findProperty(ShadowType.F_LIFECYCLE_STATE); if (pLifecycleState != null && !pLifecycleState.isEmpty() && SchemaConstants.LIFECYCLE_PROPOSED .equals(pLifecycleState.getRealValue())) { shadows.add(shadow.asObjectable()); } } } } return shadows; }
void addObjectPreAuthorized(ObjectType objectType, Task task, OperationResult result) throws ObjectAlreadyExistsException, SchemaException, ObjectNotFoundException { ObjectDelta<? extends ObjectType> objectDelta = DeltaFactory.Object.createAddDelta(objectType.asPrismObject()); Collection<ObjectDeltaOperation<? extends ObjectType>> ops; try { ops = modelService.executeChanges( singleton(objectDelta), ModelExecuteOptions.createRaw().setPreAuthorized(), task, result); } catch (ExpressionEvaluationException|CommunicationException|ConfigurationException|PolicyViolationException|SecurityViolationException e) { throw new SystemException("Unexpected exception when adding object: " + e.getMessage(), e); } ObjectDeltaOperation odo = ops.iterator().next(); objectType.setOid(odo.getObjectDelta().getOid()); /* ALTERNATIVELY, we can go directly into the repository. (No audit there.) String oid = repositoryService.addObject(objectType.asPrismObject(), null, result); objectType.setOid(oid); */ }
private void invalidateCaches(Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas) { if (executedDeltas == null) { return; } for (ObjectDeltaOperation<? extends ObjectType> executedDelta: executedDeltas) { ObjectDelta<? extends ObjectType> objectDelta = executedDelta.getObjectDelta(); if (objectDelta != null) { if (objectDelta.getObjectTypeClass() == SystemConfigurationType.class) { systemObjectCache.invalidateCaches(); } } //TODO do we still need this? if (objectDelta.getObjectTypeClass() == FunctionLibraryType.class) { cacheRegistry.clearAllCaches(FunctionLibraryType.class, ""); } } }
public static LensObjectDeltaOperation fromLensObjectDeltaOperationType(LensObjectDeltaOperationType jaxb, PrismContext prismContext) throws SchemaException { ObjectDeltaOperation odo = DeltaConvertor.createObjectDeltaOperation(jaxb.getObjectDeltaOperation(), prismContext); LensObjectDeltaOperation retval = new LensObjectDeltaOperation(); retval.setObjectDelta(odo.getObjectDelta()); retval.setExecutionResult(odo.getExecutionResult()); retval.setAudited(jaxb.isAudited()); return retval; }
private <F extends ObjectType> LensObjectDeltaOperation<F> simplifyOperation(ObjectDeltaOperation<F> operation) { LensObjectDeltaOperation<F> rv = new LensObjectDeltaOperation<>(); rv.setObjectDelta(simplifyDelta(operation.getObjectDelta())); rv.setExecutionResult(OperationResult.keepRootOnly(operation.getExecutionResult())); rv.setObjectName(operation.getObjectName()); rv.setResourceName(operation.getResourceName()); rv.setResourceOid(operation.getResourceOid()); return rv; }
public static void toObjectDeltaOperationType(ObjectDeltaOperation delta, ObjectDeltaOperationType odo, DeltaConversionOptions options) throws SchemaException { odo.setObjectDelta(DeltaConvertor.toObjectDeltaType(delta.getObjectDelta(), options)); if (delta.getExecutionResult() != null){ odo.setExecutionResult(delta.getExecutionResult().createOperationResultType()); } if (delta.getObjectName() != null) { odo.setObjectName(new PolyStringType(delta.getObjectName())); } odo.setResourceOid(delta.getResourceOid()); if (delta.getResourceName() != null) { odo.setResourceName(new PolyStringType(delta.getResourceName())); } }