Skip to content

Commit

Permalink
Recompute bulk action now supports any FocusType (user, role, org) + …
Browse files Browse the repository at this point in the history
…sample.
  • Loading branch information
mederly committed May 26, 2015
1 parent 5ea8c75 commit c335ebc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 7 deletions.
Expand Up @@ -35,6 +35,7 @@
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionExpressionType;

Expand Down Expand Up @@ -67,21 +68,21 @@ public void init() {
@Override
public Data execute(ActionExpressionType expression, Data input, ExecutionContext context, OperationResult result) throws ScriptExecutionException {
for (Item item : input.getData()) {
if (item instanceof PrismObject && UserType.class.isAssignableFrom(((PrismObject) item).getCompileTimeClass())) {
PrismObject<UserType> userPrismObject = (PrismObject) item;
if (item instanceof PrismObject && FocusType.class.isAssignableFrom(((PrismObject) item).getCompileTimeClass())) {
PrismObject<FocusType> focalPrismObject = (PrismObject) item;
try {
LensContext<UserType> syncContext = contextFactory.createRecomputeContext(userPrismObject, context.getTask(), result);
LensContext<FocusType> syncContext = contextFactory.createRecomputeContext(focalPrismObject, context.getTask(), result);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Recomputing user {}: context:\n{}", userPrismObject, syncContext.debugDump());
LOGGER.trace("Recomputing object {}: context:\n{}", focalPrismObject, syncContext.debugDump());
}
clockwork.run(syncContext, context.getTask(), result);
LOGGER.trace("Recomputing of user {}: {}", userPrismObject, result.getStatus());
LOGGER.trace("Recomputing of object {}: {}", focalPrismObject, result.getStatus());
} catch (ObjectNotFoundException|ConfigurationException|SecurityViolationException|PolicyViolationException|ExpressionEvaluationException|ObjectAlreadyExistsException|CommunicationException|SchemaException e) {
throw new ScriptExecutionException("Couldn't recompute user " + userPrismObject + ": " + e.getMessage(), e);
throw new ScriptExecutionException("Couldn't recompute object " + focalPrismObject + ": " + e.getMessage(), e);
}
context.println("Recomputed " + item.toString());
} else {
throw new ScriptExecutionException("Item could not be recomputed, because it is not a PrismObject: " + item.toString());
throw new ScriptExecutionException("Item could not be recomputed, because it is not a focal PrismObject: " + item.toString());
}
}
return Data.createEmpty();
Expand Down
48 changes: 48 additions & 0 deletions samples/tasks/bulk-actions/recompute-selected-orgs.xml
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2015 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>Recompute orgs having orgType=='test'</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:OrgType</s:type>
<s:searchFilter>
<q:equal>
<q:path>orgType</q:path>
<q:value>test</q:value>
</q:equal>
</s:searchFilter>
<s:action>
<s:type>recompute</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 c335ebc

Please sign in to comment.