Skip to content

Commit

Permalink
Fix displaying work for deletion tasks
Browse files Browse the repository at this point in the history
The information about auxiliary archetype was not put into the task.

This should resolve MID-7984.
  • Loading branch information
mederly committed Oct 11, 2022
1 parent 1dd5cf9 commit 799b0d6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ String deleteObjectsAsync(@NotNull QName type, @Nullable ObjectQuery objectQuery

task.setName(taskName);
task.setRootActivityDefinition(definition);
task.addArchetypeInformationIfMissing(SystemObjectsType.ARCHETYPE_UTILITY_TASK.value());
task.addArchetypeInformation(SystemObjectsType.ARCHETYPE_UTILITY_TASK.value());
task.addAuxiliaryArchetypeInformation(SystemObjectsType.ARCHETYPE_OBJECTS_DELETE_TASK.value());

getModelInteractionService().switchToBackground(task, result);
return task.getOid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ default boolean isTightlyBound() {
*/
void setCategory(String category);

// TODO Rework all three following archetype-setting methods

/**
* Adds an archetype for the task. Assumes that the task will NOT undergo full model processing,
* so this method will do everything by itself: creates an assignment, roleMembershipRef and archetypeRef.
Expand All @@ -406,13 +408,20 @@ default boolean isTightlyBound() {
* (although it should work also for them).
*/
@Experimental
void addArchetypeInformation(String archetypeOid);
void addArchetypeInformation(@NotNull String archetypeOid);

/**
* As {@link #addArchetypeInformation(String)} but executed only if there's no archetype currently set.
*/
@Experimental
void addArchetypeInformationIfMissing(String archetypeOid);
void addArchetypeInformationIfMissing(@NotNull String archetypeOid);

/**
* As {@link #addArchetypeInformation(String)} but assumes that the archetype is auxiliary one, so does not check if
* another archetype (with a different OID) is already there. I.e., checks only the presence of the OID in question.
*/
@Experimental
void addAuxiliaryArchetypeInformation(@NotNull String archetypeOid);
//endregion

//region Task extension "get" operations + also arbitrary "get" operations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,17 @@ public void setCategory(String category) {
}

@Override
public void addArchetypeInformation(String archetypeOid) {
public void addArchetypeInformation(@NotNull String archetypeOid) {
throw new UnsupportedOperationException();
}

@Override
public void addArchetypeInformationIfMissing(String archetypeOid) {
public void addAuxiliaryArchetypeInformation(@NotNull String archetypeOid) {
throw new UnsupportedOperationException();
}

@Override
public void addArchetypeInformationIfMissing(@NotNull String archetypeOid) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public class TaskQuartzImpl implements Task {
* @param operationName if null, default op. name will be used
*/
public static TaskQuartzImpl createNew(@NotNull TaskManagerQuartzImpl taskManager, String operationName) {
TaskType taskBean = new TaskType(taskManager.getPrismContext())
TaskType taskBean = new TaskType()
.taskIdentifier(taskManager.getBeans().taskPersister.generateTaskIdentifier().toString())
.executionState(TaskExecutionStateType.RUNNABLE)
.schedulingState(TaskSchedulingStateType.READY)
Expand Down Expand Up @@ -1768,12 +1768,25 @@ public String getChannelFromHandler() {
}

@Override
public void addArchetypeInformation(String archetypeOid) {
public void addArchetypeInformation(@NotNull String archetypeOid) {
addArchetypeInformationInternal(archetypeOid, true);
}

private void addArchetypeInformationInternal(@NotNull String archetypeOid, boolean assertNoExistingArchetypes) {
synchronized (prismAccess) {
List<ObjectReferenceType> existingArchetypes = taskPrism.asObjectable().getArchetypeRef();
if (!existingArchetypes.isEmpty()) {
throw new IllegalStateException("Couldn't add archetype " + archetypeOid + " because there is already one: "
+ existingArchetypes + "; in " + this);
if (assertNoExistingArchetypes) {
if (!existingArchetypes.isEmpty()) {
throw new IllegalStateException("Couldn't add archetype " + archetypeOid + " because there is already one: "
+ existingArchetypes + "; in " + this);
}
} else {
// We only check that this particular archetype is not already present.
if (existingArchetypes.stream()
.anyMatch(ref -> archetypeOid.equals(Referencable.getOid(ref)))) {
LOGGER.trace("Archetype {} is already set in {}", archetypeOid, this);
return;
}
}
addContainerable(TaskType.F_ASSIGNMENT,
ObjectTypeUtil.createAssignmentTo(archetypeOid, ObjectTypes.ARCHETYPE, beans.prismContext));
Expand All @@ -1785,15 +1798,20 @@ public void addArchetypeInformation(String archetypeOid) {
}

@Override
public void addArchetypeInformationIfMissing(String archetypeOid) {
public void addArchetypeInformationIfMissing(@NotNull String archetypeOid) {
synchronized (prismAccess) {
List<ObjectReferenceType> existingArchetypes = taskPrism.asObjectable().getArchetypeRef();
if (existingArchetypes.isEmpty()) {
addArchetypeInformation(archetypeOid);
addArchetypeInformationInternal(archetypeOid, false);
}
}
}

@Override
public void addAuxiliaryArchetypeInformation(@NotNull String archetypeOid) {
addArchetypeInformationInternal(archetypeOid, false);
}

// todo thread safety (creating a clone?)
@Override
public TaskActivityStateType getWorkState() {
Expand Down

0 comments on commit 799b0d6

Please sign in to comment.