Search in sources :

Example 1 with MutablePrismPropertyDefinition

use of com.evolveum.midpoint.prism.MutablePrismPropertyDefinition in project midpoint by Evolveum.

the class SmsMessageTransport method evaluateExpression.

// A little hack: for single-value cases we always return single-item list (even if the returned value is null)
@NotNull
private List<String> evaluateExpression(ExpressionType expressionType, VariablesMap VariablesMap, boolean multipleValues, String shortDesc, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
    if (expressionType == null) {
        return multipleValues ? emptyList() : singletonList(null);
    }
    QName resultName = new QName(SchemaConstants.NS_C, "result");
    MutablePrismPropertyDefinition<String> resultDef = transportSupport.prismContext().definitionFactory().createPropertyDefinition(resultName, DOMUtil.XSD_STRING);
    if (multipleValues) {
        resultDef.setMaxOccurs(-1);
    }
    Expression<PrismPropertyValue<String>, PrismPropertyDefinition<String>> expression = transportSupport.expressionFactory().makeExpression(expressionType, resultDef, MiscSchemaUtil.getExpressionProfile(), shortDesc, task, result);
    ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, VariablesMap, shortDesc, task);
    PrismValueDeltaSetTriple<PrismPropertyValue<String>> exprResult = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, task, result);
    if (!multipleValues) {
        if (exprResult.getZeroSet().size() > 1) {
            throw new SystemException("Invalid number of return values (" + exprResult.getZeroSet().size() + "), expected at most 1.");
        } else if (exprResult.getZeroSet().isEmpty()) {
            return singletonList(null);
        } else {
        // single-valued response is treated below
        }
    }
    return exprResult.getZeroSet().stream().map(ppv -> ppv.getValue()).collect(Collectors.toList());
}
Also used : Date(java.util.Date) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) ModelExpressionThreadLocalHolder(com.evolveum.midpoint.model.common.expression.ModelExpressionThreadLocalHolder) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) StringUtils(org.apache.commons.lang3.StringUtils) ExpressionConstants(com.evolveum.midpoint.schema.constants.ExpressionConstants) Collections.singletonList(java.util.Collections.singletonList) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) DOMUtil(com.evolveum.midpoint.util.DOMUtil) Transport(com.evolveum.midpoint.notifications.api.transports.Transport) PrismValueDeltaSetTriple(com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple) MiscSchemaUtil(com.evolveum.midpoint.schema.util.MiscSchemaUtil) URI(java.net.URI) TransportSupport(com.evolveum.midpoint.notifications.api.transports.TransportSupport) Collections.emptyList(java.util.Collections.emptyList) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) MutablePrismPropertyDefinition(com.evolveum.midpoint.prism.MutablePrismPropertyDefinition) List(java.util.List) QName(javax.xml.namespace.QName) CredentialsProvider(org.apache.http.client.CredentialsProvider) NotNull(org.jetbrains.annotations.NotNull) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) ObjectUtils.defaultIfNull(org.apache.commons.lang3.ObjectUtils.defaultIfNull) ArrayList(java.util.ArrayList) ClientHttpRequest(org.springframework.http.client.ClientHttpRequest) HttpClient(org.apache.http.client.HttpClient) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) HttpUtil(com.evolveum.midpoint.notifications.impl.util.HttpUtil) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) Event(com.evolveum.midpoint.notifications.api.events.Event) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) Expression(com.evolveum.midpoint.repo.common.expression.Expression) IOException(java.io.IOException) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) HttpStatus(org.springframework.http.HttpStatus) Message(com.evolveum.midpoint.notifications.api.transports.Message) URLEncoder(java.net.URLEncoder) AuthScope(org.apache.http.auth.AuthScope) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) HttpHost(org.apache.http.HttpHost) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) MutablePrismPropertyDefinition(com.evolveum.midpoint.prism.MutablePrismPropertyDefinition) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) QName(javax.xml.namespace.QName) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with MutablePrismPropertyDefinition

use of com.evolveum.midpoint.prism.MutablePrismPropertyDefinition in project midpoint by Evolveum.

the class LegacySimpleSmsTransport method evaluateExpression.

// A little hack: for single-value cases we always return single-item list (even if the returned value is null)
@NotNull
private List<String> evaluateExpression(ExpressionType expressionType, VariablesMap VariablesMap, boolean multipleValues, String shortDesc, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
    if (expressionType == null) {
        return multipleValues ? emptyList() : singletonList(null);
    }
    QName resultName = new QName(SchemaConstants.NS_C, "result");
    MutablePrismPropertyDefinition<String> resultDef = prismContext.definitionFactory().createPropertyDefinition(resultName, DOMUtil.XSD_STRING);
    if (multipleValues) {
        resultDef.setMaxOccurs(-1);
    }
    Expression<PrismPropertyValue<String>, PrismPropertyDefinition<String>> expression = expressionFactory.makeExpression(expressionType, resultDef, MiscSchemaUtil.getExpressionProfile(), shortDesc, task, result);
    ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, VariablesMap, shortDesc, task);
    PrismValueDeltaSetTriple<PrismPropertyValue<String>> exprResult = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, task, result);
    if (!multipleValues) {
        if (exprResult.getZeroSet().size() > 1) {
            throw new SystemException("Invalid number of return values (" + exprResult.getZeroSet().size() + "), expected at most 1.");
        } else if (exprResult.getZeroSet().isEmpty()) {
            return singletonList(null);
        } else {
        // single-valued response is treated below
        }
    }
    return exprResult.getZeroSet().stream().map(ppv -> ppv.getValue()).collect(Collectors.toList());
}
Also used : Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) ModelExpressionThreadLocalHolder(com.evolveum.midpoint.model.common.expression.ModelExpressionThreadLocalHolder) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) StringUtils(org.apache.commons.lang3.StringUtils) ExpressionConstants(com.evolveum.midpoint.schema.constants.ExpressionConstants) Collections.singletonList(java.util.Collections.singletonList) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) DOMUtil(com.evolveum.midpoint.util.DOMUtil) Transport(com.evolveum.midpoint.notifications.api.transports.Transport) TransportUtil(com.evolveum.midpoint.transport.impl.TransportUtil) PrismValueDeltaSetTriple(com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple) MiscSchemaUtil(com.evolveum.midpoint.schema.util.MiscSchemaUtil) URI(java.net.URI) TransportSupport(com.evolveum.midpoint.notifications.api.transports.TransportSupport) Collections.emptyList(java.util.Collections.emptyList) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) MutablePrismPropertyDefinition(com.evolveum.midpoint.prism.MutablePrismPropertyDefinition) List(java.util.List) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) QName(javax.xml.namespace.QName) CredentialsProvider(org.apache.http.client.CredentialsProvider) NotNull(org.jetbrains.annotations.NotNull) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) ObjectUtils.defaultIfNull(org.apache.commons.lang3.ObjectUtils.defaultIfNull) ArrayList(java.util.ArrayList) ClientHttpRequest(org.springframework.http.client.ClientHttpRequest) HttpClient(org.apache.http.client.HttpClient) PrismContext(com.evolveum.midpoint.prism.PrismContext) Qualifier(org.springframework.beans.factory.annotation.Qualifier) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) HttpUtil(com.evolveum.midpoint.notifications.impl.util.HttpUtil) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) Event(com.evolveum.midpoint.notifications.api.events.Event) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) Expression(com.evolveum.midpoint.repo.common.expression.Expression) IOException(java.io.IOException) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) HttpStatus(org.springframework.http.HttpStatus) Message(com.evolveum.midpoint.notifications.api.transports.Message) URLEncoder(java.net.URLEncoder) Component(org.springframework.stereotype.Component) Protector(com.evolveum.midpoint.prism.crypto.Protector) AuthScope(org.apache.http.auth.AuthScope) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) HttpHost(org.apache.http.HttpHost) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) MutablePrismPropertyDefinition(com.evolveum.midpoint.prism.MutablePrismPropertyDefinition) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) QName(javax.xml.namespace.QName) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with MutablePrismPropertyDefinition

use of com.evolveum.midpoint.prism.MutablePrismPropertyDefinition in project midpoint by Evolveum.

the class ExtDictionaryTest method test100ParallelAdd.

@Test
public void test100ParallelAdd() throws Exception {
    for (int round = 0; round < ROUNDS; round++) {
        List<TestingThread> threads = new ArrayList<>();
        for (int i = 0; i < THREADS; i++) {
            final int round1 = round;
            final int thread1 = i;
            Runnable runnable = () -> {
                try {
                    UserType user = new UserType(prismContext).name("u-" + round1 + "-" + thread1);
                    QName propertyName = new QName(NS_TEST, "round" + round1);
                    MutablePrismPropertyDefinition<String> propertyDefinition = prismContext.definitionFactory().createPropertyDefinition(propertyName, DOMUtil.XSD_STRING);
                    PrismProperty<String> property = propertyDefinition.instantiate();
                    property.setRealValue("value");
                    user.asPrismObject().addExtensionItem(property);
                    repositoryService.addObject(user.asPrismObject(), null, new OperationResult("addObject"));
                } catch (RuntimeException e) {
                    throw e;
                } catch (Exception e) {
                    throw new SystemException(e);
                }
            };
            TestingThread thread = new TestingThread(runnable);
            threads.add(thread);
            thread.start();
        }
        for (int i = 0; i < THREADS; i++) {
            TestingThread thread = threads.get(i);
            thread.join(60000L);
            if (thread.throwable != null) {
                fail("Exception in " + thread + ": " + thread.throwable);
            }
        }
    }
    Session session = open();
    // noinspection unchecked
    List<RExtItem> extItems = session.createQuery("from RExtItem").list();
    System.out.println("ext items: " + extItems.size());
    for (RExtItem extItem : extItems) {
        System.out.println(extItem);
        logger.info("{}", extItem);
    }
    session.close();
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SystemException(com.evolveum.midpoint.util.exception.SystemException) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) SystemException(com.evolveum.midpoint.util.exception.SystemException) RExtItem(com.evolveum.midpoint.repo.sql.data.common.any.RExtItem) MutablePrismPropertyDefinition(com.evolveum.midpoint.prism.MutablePrismPropertyDefinition) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Aggregations

MutablePrismPropertyDefinition (com.evolveum.midpoint.prism.MutablePrismPropertyDefinition)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 ArrayList (java.util.ArrayList)3 QName (javax.xml.namespace.QName)3 ModelExpressionThreadLocalHolder (com.evolveum.midpoint.model.common.expression.ModelExpressionThreadLocalHolder)2 Event (com.evolveum.midpoint.notifications.api.events.Event)2 Message (com.evolveum.midpoint.notifications.api.transports.Message)2 Transport (com.evolveum.midpoint.notifications.api.transports.Transport)2 TransportSupport (com.evolveum.midpoint.notifications.api.transports.TransportSupport)2 HttpUtil (com.evolveum.midpoint.notifications.impl.util.HttpUtil)2 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)2 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)2 PrismValueDeltaSetTriple (com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple)2 Expression (com.evolveum.midpoint.repo.common.expression.Expression)2 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)2 ExpressionConstants (com.evolveum.midpoint.schema.constants.ExpressionConstants)2 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)2 VariablesMap (com.evolveum.midpoint.schema.expression.VariablesMap)2 MiscSchemaUtil (com.evolveum.midpoint.schema.util.MiscSchemaUtil)2 Task (com.evolveum.midpoint.task.api.Task)2