Skip to content

Commit

Permalink
model-api support for bulk actions (MID-637)
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Jul 17, 2014
1 parent ddb8abc commit 4426ba0
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2010-2014 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.
*/

package com.evolveum.midpoint.model.api;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.parser.QueryConvertor;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;
import com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionExpressionType;
import com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExecuteScriptType;
import com.evolveum.midpoint.xml.ns._public.model.scripting_3.ScriptingExpressionType;
import com.evolveum.midpoint.xml.ns._public.model.scripting_3.SearchExpressionType;

import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import java.util.Collection;
import java.util.List;

/**
* Interface of the Model subsystem that provides scripting (bulk actions) operations.
*
* @author mederly
*/
public interface ScriptingService {

/**
* Asynchronously executes simple scripting expressions, consisting of one search command and one action.
*
* @param objectType Object type to search (e.g. c:UserType)
* @param filter Filter to be applied (ObjectFilter)
* @param actionName Action to be executed on objects found (e.g. "disable", "delete", "recompute", etc).
* @param task Task in context of which the script should execute. The task should be "clean", i.e.
* (1) transient, (2) without any handler. This method puts the task into background,
* and assigns ScriptExecutionTaskHandler to it, to execute the script.
* @param parentResult
* @throws SchemaException
*/
public void evaluateExpressionInBackground(QName objectType, ObjectFilter filter, String actionName, Task task, OperationResult parentResult) throws SchemaException;

/**
* Asynchronously executes any scripting expression.
*
* @param expression Expression to be executed.
* @param task Task in context of which the script should execute. The task should be "clean", i.e.
* (1) transient, (2) without any handler. This method puts the task into background,
* and assigns ScriptExecutionTaskHandler to it, to execute the script.
* @param parentResult
* @throws SchemaException
*/
public void evaluateExpressionInBackground(JAXBElement<? extends ScriptingExpressionType> expression, Task task, OperationResult parentResult) throws SchemaException;
}
Expand Up @@ -25,15 +25,19 @@
import java.util.Map;
import java.util.Set;

import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.model.api.ScriptingService;
import com.evolveum.midpoint.model.api.TaskService;
import com.evolveum.midpoint.model.api.WorkflowService;
import com.evolveum.midpoint.model.api.hooks.ReadHook;
import com.evolveum.midpoint.model.impl.scripting.ScriptingExpressionEvaluator;
import com.evolveum.midpoint.wf.api.WorkflowManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSpecificationType;
import com.evolveum.midpoint.xml.ns._public.model.model_context_3.LensContextType;

import com.evolveum.midpoint.xml.ns._public.model.scripting_3.ScriptingExpressionType;
import org.apache.commons.lang.NotImplementedException;
import org.apache.commons.lang.Validate;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -169,7 +173,7 @@
* @author Radovan Semancik
*/
@Component
public class ModelController implements ModelService, ModelInteractionService, TaskService, WorkflowService {
public class ModelController implements ModelService, ModelInteractionService, TaskService, WorkflowService, ScriptingService {

// Constants for OperationResult
public static final String CLASS_NAME_WITH_DOT = ModelController.class.getName() + ".";
Expand Down Expand Up @@ -218,6 +222,9 @@ public class ModelController implements ModelService, ModelInteractionService, T

@Autowired(required = false) // not required in all circumstances
private WorkflowManager workflowManager;

@Autowired
private ScriptingExpressionEvaluator scriptingExpressionEvaluator;

@Autowired(required = true)
private ChangeExecutor changeExecutor;
Expand Down Expand Up @@ -1781,4 +1788,16 @@ public void releaseWorkItem(String workItemId, OperationResult parentResult) {
}
//endregion

//region Scripting (bulka actions)
@Override
public void evaluateExpressionInBackground(QName objectType, ObjectFilter filter, String actionName, Task task, OperationResult parentResult) throws SchemaException {
scriptingExpressionEvaluator.evaluateExpressionInBackground(objectType, filter, actionName, task, parentResult);
}

@Override
public void evaluateExpressionInBackground(JAXBElement<? extends ScriptingExpressionType> expression, Task task, OperationResult parentResult) throws SchemaException {
scriptingExpressionEvaluator.evaluateExpressionInBackground(expression, task, parentResult);
}
//endregion

}

0 comments on commit 4426ba0

Please sign in to comment.