Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Sep 28, 2022
2 parents ff68e42 + 03f082d commit 254f691
Show file tree
Hide file tree
Showing 30 changed files with 189 additions and 435 deletions.
26 changes: 0 additions & 26 deletions config/initial-objects/040-role-enduser.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,30 +242,4 @@
</owner>
</object>
</authorization>
<authorization>
<name>self-owned-task-add-execute-changes</name>
<description>
Authorization to create a new 'execute changes' task owned by a currently logged-in user.
This is needed to execute asynchronous operations from the GUI.
</description>
<action>http://midpoint.evolveum.com/xml/ns/public/security/authorization-model-3#add</action>
<object>
<type>TaskType</type>
<filter>
<q:or>
<q:equal>
<q:path>handlerUri</q:path>
<q:value>http://midpoint.evolveum.com/xml/ns/public/model/synchronization/task/execute/handler-3</q:value>
</q:equal>
<q:equal>
<q:path>handlerUri</q:path>
<q:value>http://midpoint.evolveum.com/xml/ns/public/model/iterative-scripting/handler-3</q:value> <!-- members-related operations -->
</q:equal>
</q:or>
</filter>
<owner>
<special>self</special>
</owner>
</object>
</authorization>
</role>

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.text.Collator;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
Expand Down Expand Up @@ -87,7 +86,6 @@
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.model.NonEmptyModel;
import com.evolveum.midpoint.gui.api.model.ReadOnlyModel;
import com.evolveum.midpoint.gui.api.model.ReadOnlyValueModel;
import com.evolveum.midpoint.gui.api.page.PageAdminLTE;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.prism.wrapper.*;
Expand Down Expand Up @@ -236,6 +234,7 @@ public final class WebComponentUtil {
/**
* To be used only for tests when there's no MidpointApplication.
* (Quite a hack. Replace eventually by a more serious solution.)
* TODO: Not used anymore, consider removal? (If not used in 2024, just delete it.)
*/
private static RelationRegistry staticallyProvidedRelationRegistry;

Expand Down Expand Up @@ -641,49 +640,6 @@ public static <T extends Containerable> QName containerClassToQName(PrismContext
return prismContext.getSchemaRegistry().findComplexTypeDefinitionByCompileTimeClass(clazz).getTypeName();
}

public static TaskType createIterativeChangeExecutionTask(String taskName, QName applicableType, ObjectQuery query,
@Nullable ObjectDelta<? extends ObjectType> delta, ModelExecuteOptions options, PageBase pageBase) throws SchemaException {

TaskType task = new TaskType(pageBase.getPrismContext());

MidPointPrincipal owner = AuthUtil.getPrincipalUser();

ObjectReferenceType ownerRef = new ObjectReferenceType();
ownerRef.setOid(owner.getOid());
ownerRef.setType(UserType.COMPLEX_TYPE);
task.setOwnerRef(ownerRef);

task.setBinding(TaskBindingType.LOOSE);
task.setExecutionState(TaskExecutionStateType.RUNNABLE);
task.setSchedulingState(TaskSchedulingStateType.READY);
task.setThreadStopAction(ThreadStopActionType.RESTART);

ScheduleType schedule = new ScheduleType();
schedule.setMisfireAction(MisfireActionType.EXECUTE_IMMEDIATELY);
task.setSchedule(schedule);

task.setName(WebComponentUtil.createPolyFromOrigString(taskName));

IterativeChangeExecutionWorkDefinitionType workDef =
new IterativeChangeExecutionWorkDefinitionType(PrismContext.get())
.beginObjects()
.type(applicableType)
.query(pageBase.getQueryConverter().createQueryType(query))
.<IterativeChangeExecutionWorkDefinitionType>end()
.delta(DeltaConvertor.toObjectDeltaType(delta))
.executionOptions(toModelExecutionOptionsBean(options));

// @formatter:off
task.setActivity(
new ActivityDefinitionType(PrismContext.get())
.beginWork()
.iterativeChangeExecution(workDef)
.end());
// @formatter:on

return task;
}

public static boolean canSuspendTask(TaskType task, PageBase pageBase) {
return pageBase.isAuthorized(ModelAuthorizationAction.SUSPEND_TASK, task.asPrismObject())
&& (isRunnableTask(task) || isRunningTask(task) || isWaitingTask(task));
Expand Down Expand Up @@ -1041,15 +997,6 @@ public static <T extends Enum> IModel<List<T>> createReadonlyModelFromEnum(final
};
}

// use for small enums only
@NotNull
public static <T extends Enum> IModel<List<T>> createReadonlyValueModelFromEnum(@NotNull Class<T> type, @NotNull Predicate<T> filter) {
return new ReadOnlyValueModel<>(
Arrays.stream(type.getEnumConstants())
.filter(filter)
.collect(Collectors.toList()));
}

/**
* Simulates task category using task archetype.
*/
Expand Down Expand Up @@ -3364,8 +3311,8 @@ public void onClick(AjaxRequestTarget target) {
} else {
oids = CollectionUtils.emptyIfNull(selectedObjectsSupplier.get())
.stream()
.filter(o -> o.getOid() != null)
.map(o -> o.getOid())
.filter(Objects::nonNull)
.collect(Collectors.toSet());
}
if (!oids.isEmpty()) {
Expand All @@ -3375,6 +3322,8 @@ public void onClick(AjaxRequestTarget target) {
if (principal == null) {
throw new SecurityViolationException("No current user");
}
// TODO deduplicate with ModelInteractionService.submitTaskFromTemplate
// (after improving that method)
TaskType newTask = pageBase.getModelService().getObject(TaskType.class, templateOid,
createCollection(createExecutionPhase()), pageBase.createSimpleTask(operation), result).asObjectable();
newTask.setName(PolyStringType.fromOrig(newTask.getName().getOrig() + " " + (int) (Math.random() * 10000)));
Expand All @@ -3393,6 +3342,7 @@ public void onClick(AjaxRequestTarget target) {
}
objectSet.setQuery(query);
workDef.setObjects(objectSet);
// TODO consider if the user needs to have authorization to add the task
ObjectDelta<TaskType> delta = DeltaFactory.Object.createAddDelta(newTask.asPrismObject());
Collection<ObjectDeltaOperation<? extends ObjectType>> executedChanges = saveTask(delta, result, pageBase);
String newTaskOid = ObjectDeltaOperation.findAddDeltaOid(executedChanges, newTask.asPrismObject());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,29 +171,6 @@ public static <O extends ObjectType> List<ObjectReferenceType> createObjectRefer
return null;
}

public static String runTask(TaskType taskToRun, Task operationalTask, OperationResult parentResult, PageBase pageBase) {
try {
ObjectDelta<TaskType> delta = DeltaFactory.Object.createAddDelta(taskToRun.asPrismObject());
pageBase.getPrismContext().adopt(delta);
Collection<ObjectDeltaOperation<?>> deltaOperationRes = pageBase.getModelService().executeChanges(MiscUtil.createCollection(delta), null,
operationalTask, parentResult);
if (StringUtils.isEmpty(delta.getOid()) && deltaOperationRes != null && !deltaOperationRes.isEmpty()) {
ObjectDeltaOperation deltaOperation = deltaOperationRes.iterator().next();
delta.setOid(deltaOperation.getObjectDelta().getOid());
}
parentResult.setInProgress();
parentResult.setBackgroundTaskOid(delta.getOid());
return delta.getOid();
} catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException
| ExpressionEvaluationException | CommunicationException | ConfigurationException
| PolicyViolationException | SecurityViolationException e) {
parentResult.recordFatalError(pageBase.createStringResource("WebModelUtils.couldntRunTask", e.getMessage()).getString(), e);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't run task " + e.getMessage(), e);
return null;
}

}

public static <O extends ObjectType> PrismObject<O> loadObject(PrismReferenceValue objectRef, QName expectedTargetType, PageBase pageBase, Task task, OperationResult result) {
if (objectRef == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ protected void searchPerformed(AjaxRequestTarget target){

private void deletePerformed(AjaxRequestTarget target) {
getModelObject().setVisible(false);
getModelObject().setValue(getModelObject().getDefaultValue());
SearchPanel panel = findParent(SearchPanel.class);
panel.displayedSearchItemsModelReset();
panel.refreshSearchForm(target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public VariablesMap getFilterVariables(VariablesMap defaultVariables, PageBase p
VariablesMap variables = defaultVariables == null ? new VariablesMap() : defaultVariables;
List<AbstractSearchItemWrapper> items = getItems();
items.forEach(item -> {
if (StringUtils.isNotEmpty(item.getParameterName()) && item.isApplyFilter(SearchBoxModeType.BASIC)) {
if (StringUtils.isNotEmpty(item.getParameterName())) {
Object parameterValue = item.getValue() != null ? item.getValue().getValue() : null;
TypedValue value = new TypedValue(parameterValue, item.getParameterValueType());
variables.put(item.getParameterName(), value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@ public static <C extends Containerable> PropertySearchItemWrapper createPropert
if (searchItemWrapper instanceof DateSearchItemWrapper) {
((DateSearchItemWrapper) searchItemWrapper).setInterval(false);
}
searchItemWrapper.setCanConfigure(false);
}

if (item.isVisibleByDefault() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,8 @@ public Collection<ObjectDeltaOperation<? extends ObjectType>> executeChangesInBa
ModelExecuteOptions options, Task task, OperationResult result, AjaxRequestTarget target) {

try {

configureTask(deltas, options, task);

TaskManager taskManager = progressAwarePage.getTaskManager();
taskManager.switchToBackground(task, result);
result.setBackgroundTaskOid(task.getOid());
progressAwarePage.getModelInteractionService().switchToBackground(task, result);
} catch (Exception e) {
result.recordFatalError(e);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ private static void submitTaskIfPossible(@Nullable Task task, AjaxRequestTarget
OperationResult taskResult = task.getResult();
OperationResult result = taskResult.createSubresult(OP_SUBMIT_TASK);
try {
pageBase.getTaskManager().switchToBackground(task, result);
pageBase.getModelInteractionService().switchToBackground(task, result);
} catch (Throwable t) {
result.recordFatalError(t);
throw t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@

package com.evolveum.midpoint.gui.impl.page.admin.component;

import com.evolveum.midpoint.model.api.ModelInteractionService;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.schema.ObjectDeltaOperation;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.TaskManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

import org.apache.wicket.ajax.AjaxRequestTarget;

import java.util.Collection;

/**
* A page that supports progress reporting, e.g. page for editing users, orgs, roles.
* <p>
Expand All @@ -32,5 +29,8 @@ public interface ProgressReportingAwarePage {
void continueEditing(AjaxRequestTarget target);

TaskManager getTaskManager();

ModelInteractionService getModelInteractionService();

PrismContext getPrismContext();
}

This file was deleted.

0 comments on commit 254f691

Please sign in to comment.