Skip to content

Commit

Permalink
Fix ResourceTaskCreator
Browse files Browse the repository at this point in the history
Originally, it ignored configured task template, as it overwrote it
with its own. Now it tries to just set its own values into it.

Related to MID-9052.
  • Loading branch information
mederly committed Sep 19, 2023
1 parent 78d71dd commit bd91406
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ public class ResourceTaskCreator {
private PredefinedConfigurationType predefinedConfiguration;
private SimulationDefinitionType simulationDefinition;

/** Options provided by the caller. See {@link #submissionOptions()}. */
private ActivitySubmissionOptions submissionOptions;

/** Owner provided by the caller. If set, it has precedence over the owner specified in the options. */
private FocusType owner;

private ResourceTaskCreator(@NotNull ResourceType resource, @NotNull PageBase pageBase) {
Expand All @@ -78,6 +80,7 @@ public ResourceTaskCreator ofFlavor(SynchronizationTaskFlavor flavor) {
return this;
}

@SuppressWarnings("WeakerAccess")
public ResourceTaskCreator ownedByCurrentUser() throws NotLoggedInException {
this.owner = AuthUtil.getPrincipalObjectRequired();
return this;
Expand All @@ -90,6 +93,7 @@ public ResourceTaskCreator withCoordinates(ShadowKindType kind, String intent, Q
return this;
}

@SuppressWarnings("WeakerAccess")
public ResourceTaskCreator withCoordinates(QName objectClass) {
this.objectClass = objectClass;
return this;
Expand Down Expand Up @@ -169,12 +173,16 @@ private ResourceObjectSetType objectSetBean() {
}

private @NotNull ActivitySubmissionOptions submissionOptions() {
return Objects.requireNonNullElseGet(
submissionOptions,
() -> ActivitySubmissionOptions.create())
.withTaskTemplate(new TaskType()
.objectRef(ObjectTypeUtil.createObjectRef(resource)))
.withOwner(owner);
var options = Objects.requireNonNullElseGet(
submissionOptions,
() -> ActivitySubmissionOptions.create());
options = options.updateTaskTemplate(
t -> t.objectRef(ObjectTypeUtil.createObjectRef(resource)));
if (owner != null) {
return options.withOwner(owner);
} else {
return options;
}
}

public @NotNull String submit(@NotNull Task task, @NotNull OperationResult result) throws CommonException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.util.Arrays;
import java.util.Objects;
import java.util.function.Consumer;

import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;

Expand Down Expand Up @@ -56,4 +57,11 @@ public ActivitySubmissionOptions withArchetypes(@NotNull String... oids) {
public ActivitySubmissionOptions withOwner(@Nullable FocusType owner) {
return new ActivitySubmissionOptions(taskTemplate, archetypes, owner);
}

/** Creates or updates {@link #taskTemplate} with specified updater. */
public ActivitySubmissionOptions updateTaskTemplate(@NotNull Consumer<TaskType> taskTemplateUpdater) {
TaskType newTaskTemplate = taskTemplate != null ? taskTemplate.clone() : new TaskType();
taskTemplateUpdater.accept(newTaskTemplate);
return withTaskTemplate(newTaskTemplate);
}
}

0 comments on commit bd91406

Please sign in to comment.