Search in sources :

Example 21 with RepositoryService

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

the class TaskManagerQuartzImpl method createTaskInstance.

@Override
@NotNull
public Task createTaskInstance(PrismObject<TaskType> taskPrism, String operationName, OperationResult parentResult) throws SchemaException {
    OperationResult result = parentResult.createSubresult(DOT_INTERFACE + "createTaskInstance");
    result.addParam("taskPrism", taskPrism);
    //Note: we need to be Spring Bean Factory Aware, because some repo implementations are in scope prototype
    RepositoryService repoService = (RepositoryService) this.beanFactory.getBean("repositoryService");
    TaskQuartzImpl task = new TaskQuartzImpl(this, taskPrism, repoService, operationName);
    task.resolveOwnerRef(result);
    result.recordSuccessIfUnknown();
    return task;
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) NotNull(org.jetbrains.annotations.NotNull)

Example 22 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 23 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)

Example 24 with RepositoryService

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

the class TransportServiceImpl method init.

@PostConstruct
public void init() {
    transportSupport = new TransportSupport() {

        @Override
        public PrismContext prismContext() {
            return prismContext;
        }

        @Override
        public ExpressionFactory expressionFactory() {
            return expressionFactory;
        }

        @Override
        public RepositoryService repositoryService() {
            return repositoryService;
        }

        @Override
        public Protector protector() {
            return protector;
        }

        @Override
        public ApplicationContext applicationContext() {
            return applicationContext;
        }
    };
    registerLegacyTransports();
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) PrismContext(com.evolveum.midpoint.prism.PrismContext) TransportSupport(com.evolveum.midpoint.notifications.api.transports.TransportSupport) Protector(com.evolveum.midpoint.prism.crypto.Protector) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) PostConstruct(javax.annotation.PostConstruct)

Example 25 with RepositoryService

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

the class ObjectDeltaUpdater method handleObjectTextInfoChanges.

private void handleObjectTextInfoChanges(Class<? extends ObjectType> type, Collection<? extends ItemDelta<?, ?>> modifications, PrismObject<?> prismObject, RObject object) {
    FullTextSearchConfigurationType config = repositoryService.getFullTextSearchConfiguration();
    if (!FullTextSearchUtil.isObjectTextInfoRecomputationNeeded(config, type, modifications)) {
        return;
    }
    Set<RObjectTextInfo> newInfos = RObjectTextInfo.createItemsSet((ObjectType) prismObject.asObjectable(), object, new RepositoryContext(repositoryService, prismContext, relationRegistry, extItemDictionary, repositoryConfiguration));
    if (newInfos == null || newInfos.isEmpty()) {
        object.getTextInfoItems().clear();
    } else {
        Set<String> existingTexts = object.getTextInfoItems().stream().map(info -> info.getText()).collect(Collectors.toSet());
        Set<String> newTexts = newInfos.stream().map(info -> info.getText()).collect(Collectors.toSet());
        object.getTextInfoItems().removeIf(existingInfo -> !newTexts.contains(existingInfo.getText()));
        for (RObjectTextInfo newInfo : newInfos) {
            if (!existingTexts.contains(newInfo.getText())) {
                object.getTextInfoItems().add(newInfo);
            }
        }
    }
}
Also used : PrismIdentifierGenerator(com.evolveum.midpoint.repo.sql.util.PrismIdentifierGenerator) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Session(org.hibernate.Session) Autowired(org.springframework.beans.factory.annotation.Autowired) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Trace(com.evolveum.midpoint.util.logging.Trace) FullTextSearchConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchConfigurationType) RObjectTextInfo(com.evolveum.midpoint.repo.sql.data.common.RObjectTextInfo) DebugUtil(com.evolveum.midpoint.util.DebugUtil) StringUtils(org.apache.commons.lang3.StringUtils) SqlRepositoryConfiguration(com.evolveum.midpoint.repo.sql.SqlRepositoryConfiguration) FullTextSearchUtil(com.evolveum.midpoint.schema.util.FullTextSearchUtil) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) EquivalenceStrategy(com.evolveum.midpoint.prism.equivalence.EquivalenceStrategy) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) PrismContext(com.evolveum.midpoint.prism.PrismContext) RepositoryContext(com.evolveum.midpoint.repo.sql.data.RepositoryContext) RelationRegistry(com.evolveum.midpoint.schema.RelationRegistry) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) Collection(java.util.Collection) Set(java.util.Set) PrismObject(com.evolveum.midpoint.prism.PrismObject) Collectors(java.util.stream.Collectors) ObjectUpdater(com.evolveum.midpoint.repo.sql.helpers.ObjectUpdater) Component(org.springframework.stereotype.Component) PrismEntityMapper(com.evolveum.midpoint.repo.sql.helpers.modify.PrismEntityMapper) RepoModifyOptions(com.evolveum.midpoint.repo.api.RepoModifyOptions) ManagedType(javax.persistence.metamodel.ManagedType) ExtItemDictionary(com.evolveum.midpoint.repo.sql.data.common.dictionary.ExtItemDictionary) RObjectType(com.evolveum.midpoint.repo.sql.data.common.other.RObjectType) EntityRegistry(com.evolveum.midpoint.repo.sql.helpers.modify.EntityRegistry) RObject(com.evolveum.midpoint.repo.sql.data.common.RObject) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) RShadow(com.evolveum.midpoint.repo.sql.data.common.RShadow) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) RepositoryContext(com.evolveum.midpoint.repo.sql.data.RepositoryContext) FullTextSearchConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchConfigurationType) RObjectTextInfo(com.evolveum.midpoint.repo.sql.data.common.RObjectTextInfo)

Aggregations

RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)27 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)20 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 PrismContext (com.evolveum.midpoint.prism.PrismContext)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)8 Test (org.testng.annotations.Test)8 ObjectTypes (com.evolveum.midpoint.schema.constants.ObjectTypes)7 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)7 ArrayList (java.util.ArrayList)6 Collection (java.util.Collection)6 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)5 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)5 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)4 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)4 List (java.util.List)4 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 Trace (com.evolveum.midpoint.util.logging.Trace)3 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)3 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)3