Search in sources :

Example 6 with RepositoryService

use of com.evolveum.midpoint.repo.api.RepositoryService in project midpoint by Evolveum.

the class Utils method resolveReferences.

/**
	 * Resolves references contained in given PrismObject.
	 *
	 * @param object
	 * @param repository
	 * @param enforceReferentialIntegrity If true, missing reference causes fatal error when processing (if false, only warning is issued).
	 * @param forceFilterReevaluation If true, references are reevaluated even if OID is present. (Given that filter is present as well, of course.)
	 * @param prismContext
	 * @param result
	 */
public static <T extends ObjectType> void resolveReferences(PrismObject<T> object, RepositoryService repository, boolean enforceReferentialIntegrity, boolean forceFilterReevaluation, EvaluationTimeType resolutionTime, boolean throwExceptionOnFailure, PrismContext prismContext, OperationResult result) {
    Visitor visitor = visitable -> {
        if (!(visitable instanceof PrismReferenceValue)) {
            return;
        }
        resolveRef((PrismReferenceValue) visitable, repository, enforceReferentialIntegrity, forceFilterReevaluation, resolutionTime, prismContext, object.toString(), throwExceptionOnFailure, result);
    };
    object.accept(visitor);
}
Also used : EvaluationTimeType(com.evolveum.prism.xml.ns._public.types_3.EvaluationTimeType) StringUtils(org.apache.commons.lang.StringUtils) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) CryptoUtil(com.evolveum.midpoint.common.crypto.CryptoUtil) com.evolveum.midpoint.prism.query(com.evolveum.midpoint.prism.query) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Trace(com.evolveum.midpoint.util.logging.Trace) ExpressionConstants(com.evolveum.midpoint.schema.constants.ExpressionConstants) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ArrayList(java.util.ArrayList) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) Handler(com.evolveum.midpoint.util.Handler) ScriptExpression(com.evolveum.midpoint.model.common.expression.script.ScriptExpression) Visitor(com.evolveum.midpoint.prism.Visitor) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) com.evolveum.midpoint.model.impl.lens(com.evolveum.midpoint.model.impl.lens) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) ModelExpressionThreadLocalHolder(com.evolveum.midpoint.model.impl.expr.ModelExpressionThreadLocalHolder) Task(com.evolveum.midpoint.task.api.Task) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ExpressionEnvironment(com.evolveum.midpoint.model.impl.expr.ExpressionEnvironment) QueryConvertor(com.evolveum.midpoint.prism.marshaller.QueryConvertor) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) Nullable(org.jetbrains.annotations.Nullable) ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) List(java.util.List) ModelConstants(com.evolveum.midpoint.model.impl.ModelConstants) Protector(com.evolveum.midpoint.prism.crypto.Protector) SystemException(com.evolveum.midpoint.util.exception.SystemException) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) ObjectImporter(com.evolveum.midpoint.model.impl.importer.ObjectImporter) Validate(org.apache.commons.lang.Validate) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) Visitor(com.evolveum.midpoint.prism.Visitor)

Example 7 with RepositoryService

use of com.evolveum.midpoint.repo.api.RepositoryService in project midpoint by Evolveum.

the class MidpointUtil method recordEventInTask.

// additional delta is a bit hack ... TODO refactor (but without splitting the modify operation!)
public static void recordEventInTask(CaseEventType event, ObjectDeltaType additionalDelta, String taskOid, OperationResult result) {
    RepositoryService cacheRepositoryService = getCacheRepositoryService();
    PrismContext prismContext = getPrismContext();
    try {
        S_ItemEntry deltaBuilder = DeltaBuilder.deltaFor(TaskType.class, getPrismContext()).item(F_WORKFLOW_CONTEXT, F_EVENT).add(event);
        if (additionalDelta != null) {
            PrismObject<TaskType> task = cacheRepositoryService.getObject(TaskType.class, taskOid, null, result);
            WfPrimaryChangeProcessorStateType state = WfContextUtil.getPrimaryChangeProcessorState(task.asObjectable().getWorkflowContext());
            ObjectTreeDeltasType updatedDelta = ObjectTreeDeltas.mergeDeltas(state.getDeltasToProcess(), additionalDelta, prismContext);
            // assuming it already exists!
            ItemPath deltasToProcessPath = new ItemPath(F_WORKFLOW_CONTEXT, F_PROCESSOR_SPECIFIC_STATE, WfPrimaryChangeProcessorStateType.F_DELTAS_TO_PROCESS);
            ItemDefinition<?> deltasToProcessDefinition = getPrismContext().getSchemaRegistry().findContainerDefinitionByCompileTimeClass(WfPrimaryChangeProcessorStateType.class).findItemDefinition(WfPrimaryChangeProcessorStateType.F_DELTAS_TO_PROCESS);
            deltaBuilder = deltaBuilder.item(deltasToProcessPath, deltasToProcessDefinition).replace(updatedDelta);
        }
        cacheRepositoryService.modifyObject(TaskType.class, taskOid, deltaBuilder.asItemDeltas(), result);
    } catch (ObjectNotFoundException | SchemaException | ObjectAlreadyExistsException e) {
        throw new SystemException("Couldn't record decision to the task " + taskOid + ": " + e.getMessage(), e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SpringApplicationContextHolder.getPrismContext(com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getPrismContext) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) S_ItemEntry(com.evolveum.midpoint.prism.delta.builder.S_ItemEntry) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) SpringApplicationContextHolder.getCacheRepositoryService(com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getCacheRepositoryService) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)7 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 SystemException (com.evolveum.midpoint.util.exception.SystemException)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)2 NotNull (org.jetbrains.annotations.NotNull)2 CryptoUtil (com.evolveum.midpoint.common.crypto.CryptoUtil)1 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)1 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)1 EventHandler (com.evolveum.midpoint.common.validator.EventHandler)1 Validator (com.evolveum.midpoint.common.validator.Validator)1 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)1 ScriptExpression (com.evolveum.midpoint.model.common.expression.script.ScriptExpression)1 ModelConstants (com.evolveum.midpoint.model.impl.ModelConstants)1 ExpressionEnvironment (com.evolveum.midpoint.model.impl.expr.ExpressionEnvironment)1 ModelExpressionThreadLocalHolder (com.evolveum.midpoint.model.impl.expr.ModelExpressionThreadLocalHolder)1