Skip to content

Commit

Permalink
Support for "full queries" (incl. paging) in bulk actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Sep 26, 2016
1 parent 4d53597 commit 99f58ce
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 14 deletions.
Expand Up @@ -159,10 +159,17 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="query" type="q:QueryType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Query to apply when searching for instances. (Alternative to searchFilter. This is tried as the first one.)
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="searchFilter" type="q:SearchFilterType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Filter to apply when searching for instances.
Filter to apply when searching for instances. (Alternative to query. This is tried as second one.)
</xsd:documentation>
</xsd:annotation>
</xsd:element>
Expand Down
Expand Up @@ -25,6 +25,7 @@
import com.evolveum.midpoint.prism.parser.QueryConvertor;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.QueryJaxbConvertor;
import com.evolveum.midpoint.schema.ResultHandler;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.result.OperationResult;
Expand Down Expand Up @@ -67,7 +68,13 @@ public <T extends ObjectType> Data evaluate(final SearchExpressionType searchExp
Class<T> objectClass = (Class) ObjectTypes.getObjectTypeFromTypeQName(searchExpression.getType()).getClassDefinition();

ObjectQuery objectQuery = null;
if (searchExpression.getSearchFilter() != null) {
if (searchExpression.getQuery() != null) {
try {
objectQuery = QueryJaxbConvertor.createObjectQuery(objectClass, searchExpression.getQuery(), prismContext);
} catch (SchemaException e) {
throw new ScriptExecutionException("Couldn't parse object query due to schema exception", e);
}
} else if (searchExpression.getSearchFilter() != null) {
// todo resolve variable references in the filter
objectQuery = new ObjectQuery();
try {
Expand Down
Expand Up @@ -18,16 +18,18 @@
<s:search xmlns:s="http://midpoint.evolveum.com/xml/ns/public/model/scripting-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3">
<s:type>c:UserType</s:type>
<s:searchFilter>
<or xmlns="http://prism.evolveum.com/xml/ns/public/query-3">
<equal>
<path>c:name</path>
<value>administrator</value>
</equal>
<equal>
<path>c:name</path>
<value>jack</value>
</equal>
</or>
</s:searchFilter>
<s:query>
<filter xmlns="http://prism.evolveum.com/xml/ns/public/query-3">
<or>
<equal>
<path>c:name</path>
<value>administrator</value>
</equal>
<equal>
<path>c:name</path>
<value>jack</value>
</equal>
</or>
</filter>
</s:query>
</s:search>
55 changes: 55 additions & 0 deletions samples/tasks/bulk-actions/list-selected-users-ordered.xml
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2016 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<objects xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3">

<task>
<name>Log information on users starting with 'b'</name>
<extension>
<scext:executeScript xmlns:scext="http://midpoint.evolveum.com/xml/ns/public/model/scripting/extension-3">
<s:search xmlns:s="http://midpoint.evolveum.com/xml/ns/public/model/scripting-3">
<s:type>c:UserType</s:type>
<s:query>
<q:filter>
<q:substring>
<q:matching>polyStringNorm</q:matching>
<q:path>c:name</q:path>
<q:value>b</q:value>
<q:anchorStart>true</q:anchorStart>
</q:substring>
</q:filter>
<q:paging>
<q:orderBy>name</q:orderBy>
</q:paging>
</s:query>
<s:action>
<s:type>log</s:type>
</s:action>
</s:search>
</scext:executeScript>
</extension>
<ownerRef oid="00000000-0000-0000-0000-000000000002"/>
<executionStatus>runnable</executionStatus>

<category>BulkActions</category>
<handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/scripting/handler-3</handlerUri>
<recurrence>single</recurrence>
</task>

</objects>

0 comments on commit 99f58ce

Please sign in to comment.