Skip to content

Commit

Permalink
Fix task progress in summary panel
Browse files Browse the repository at this point in the history
This resolves MID-7277.
  • Loading branch information
mederly committed Oct 5, 2021
1 parent 8716c1b commit a8d0c7f
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import com.evolveum.midpoint.gui.impl.page.admin.org.PageOrg;

import com.evolveum.midpoint.gui.impl.page.admin.resource.PageShadow;
import com.evolveum.midpoint.schema.util.task.TaskTypeUtil;
import com.evolveum.midpoint.schema.util.task.*;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.*;
Expand Down Expand Up @@ -120,9 +120,6 @@
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
import com.evolveum.midpoint.schema.util.*;
import com.evolveum.midpoint.schema.util.task.ActivityProgressInformation;
import com.evolveum.midpoint.schema.util.task.ActivityStateUtil;
import com.evolveum.midpoint.schema.util.task.TaskResolver;
import com.evolveum.midpoint.security.api.AuthorizationConstants;
import com.evolveum.midpoint.security.api.MidPointPrincipal;
import com.evolveum.midpoint.task.api.Task;
Expand Down Expand Up @@ -4965,25 +4962,17 @@ public static Long getTimestampAsLong(XMLGregorianCalendar cal, boolean currentI
return calAsLong;
}

public static String getTaskProgressInformation(TaskType taskType, boolean longForm, PageBase pageBase) {
public static String getTaskProgressDescription(TaskInformation taskInformation, boolean longForm, PageBase pageBase) {

// TODO use progress.toLocalizedString after it's implemented

ActivityProgressInformation progress = ActivityProgressInformation.fromRootTask(taskType, TaskResolver.empty());
String partProgressHumanReadable = progress.toHumanReadableString(longForm);
String progressDescription = taskInformation.getProgressDescription(longForm);

if (longForm) {
partProgressHumanReadable = StringUtils.replaceOnce(partProgressHumanReadable, "of", pageBase.getString("TaskSummaryPanel.progress.of"));
partProgressHumanReadable = StringUtils.replaceOnce(partProgressHumanReadable, "buckets", pageBase.getString("TaskSummaryPanel.progress.buckets"));
String temp1 = StringUtils.replaceOnce(progressDescription, "of", pageBase.getString("TaskSummaryPanel.progress.of"));
return StringUtils.replaceOnce(temp1, "buckets", pageBase.getString("TaskSummaryPanel.progress.buckets"));
} else {
return progressDescription;
}

// TODO
// if (progress.getAllPartsCount() > 1) {
// String rv = pageBase.getString("TaskSummaryPanel.progress.info." + (longForm ? "long" : "short"), partProgressHumanReadable, progress.getCurrentPartNumber(), progress.getAllPartsCount());
// return rv;
// }

return partProgressHumanReadable;
}

public static String filterNonDeadProjections(List<ShadowWrapper> projectionWrappers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,10 @@ protected IModel<String> getDisplayNameModel() {
@Override
protected IModel<String> getTitleModel() {
return () -> {
TaskType taskType = getModelObject();
TaskType taskType = getModelObject();
TaskInformation taskInformation = taskInformationModel.getObject();

String rv = WebComponentUtil.getTaskProgressInformation(taskType, true, getPageBase());
String rv = WebComponentUtil.getTaskProgressDescription(taskInformation, true, getPageBase());
if (taskType.getExecutionState() != null) {
switch (taskType.getExecutionState()) {
case SUSPENDED:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ private ActivityBasedTaskInformation(
}

@Override
public String getProgressDescriptionShort() {
return progressInformation.toHumanReadableString(false);
public String getProgressDescription(boolean longForm) {
return progressInformation.toHumanReadableString(longForm);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ private LegacyTaskInformation(
}

@Override
public String getProgressDescriptionShort() {
return itemsProgressInformation.toHumanReadableString(false);
public String getProgressDescription(boolean longForm) {
return itemsProgressInformation.toHumanReadableString(longForm);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ public String debugDump(int indent) {
}

/** Returns short description of progress of the task and its children. */
public abstract String getProgressDescriptionShort();
public String getProgressDescriptionShort() {
return getProgressDescription(false);
}

public abstract String getProgressDescription(boolean longForm);

/**
* Returns number of items failed to be processed by the task and its children, if known.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright (C) 2010-2021 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.model.intest.tasks;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;

import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.Test;

import com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.task.LegacyTaskInformation;
import com.evolveum.midpoint.schema.util.task.TaskInformation;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.TestResource;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ReportDataType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;

/**
* Tests miscellaneous kinds of tasks that do not deserve their own test class.
*/
@ContextConfiguration(locations = {"classpath:ctx-model-intest-test-main.xml"})
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class TestMiscTasks extends AbstractInitializedModelIntegrationTest {

private static final File TEST_DIR = new File("src/test/resources/tasks/misc");

private static final TestResource<TaskType> TASK_DELETE_REPORT_DATA =
new TestResource<>(TEST_DIR, "task-delete-report-data.xml", "d3351dff-4c72-4985-8a9c-f8d46ffb328f");

/**
* MID-7277
*/
@Test
public void test100DeleteReportData() throws Exception {
given();
Task task = getTestTask();
OperationResult result = task.getResult();

ReportDataType reportData = new ReportDataType(PrismContext.get())
.name("waste data");
repoAddObject(reportData.asPrismObject(), result);

when();

addTask(TASK_DELETE_REPORT_DATA, result);
waitForTaskCloseOrSuspend(TASK_DELETE_REPORT_DATA.oid, 10000);

then();

TaskType taskAfter = assertTask(TASK_DELETE_REPORT_DATA.oid, "after")
.display()
.assertSuccess()
.assertClosed()
.assertProgress(1)
.getObjectable();

TaskInformation information = TaskInformation.createForTask(taskAfter, taskAfter);
assertThat(information).isInstanceOf(LegacyTaskInformation.class);
assertThat(information.getProgressDescriptionShort()).as("progress description").isEqualTo("100.0%");

assertNoRepoObject(ReportDataType.class, reportData.getOid());
}

/**
* MID-7277
*/
@Test
public void test110DeleteReportDataAgain() throws Exception {
given();
Task task = getTestTask();
OperationResult result = task.getResult();

when();

suspendAndDeleteTasks(TASK_DELETE_REPORT_DATA.oid);
addTask(TASK_DELETE_REPORT_DATA, result);
waitForTaskCloseOrSuspend(TASK_DELETE_REPORT_DATA.oid, 10000);

then();

TaskType taskAfter = assertTask(TASK_DELETE_REPORT_DATA.oid, "after")
.display()
.assertSuccess()
.assertClosed()
.assertProgress(0)
.getObjectable();

TaskInformation information = TaskInformation.createForTask(taskAfter, taskAfter);
assertThat(information).isInstanceOf(LegacyTaskInformation.class);
assertThat(information.getProgressDescriptionShort()).as("progress description").isEqualTo("0");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!--
~ Copyright (C) 2010-2021 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<task xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
oid="d3351dff-4c72-4985-8a9c-f8d46ffb328f">
<name>delete</name>
<extension xmlns:mext="http://midpoint.evolveum.com/xml/ns/public/model/extension-3">
<mext:objectQuery/>
<mext:objectType>ReportDataType</mext:objectType>
<mext:optionRaw>true</mext:optionRaw>
</extension>
<ownerRef oid="00000000-0000-0000-0000-000000000002" type="UserType">
<!-- administrator -->
</ownerRef>
<executionState>runnable</executionState>
<handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/synchronization/task/delete/handler-3</handlerUri>
</task>
1 change: 1 addition & 0 deletions model/model-intest/testng-integration-full.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<class name="com.evolveum.midpoint.model.intest.tasks.TestProgressReporting"/>
<class name="com.evolveum.midpoint.model.intest.tasks.TestNoOpTask"/>
<class name="com.evolveum.midpoint.model.intest.tasks.TestThresholds"/>
<class name="com.evolveum.midpoint.model.intest.tasks.TestMiscTasks"/>
</classes>
</test>
<test name="Async updates" preserve-order="true" parallel="false" verbose="10">
Expand Down

0 comments on commit a8d0c7f

Please sign in to comment.