Skip to content

Commit

Permalink
Add auto-completion of archetypes to report tasks
Browse files Browse the repository at this point in the history
This feature (providing archetype based on work type) is implemented for
most tasks. However, report-related ones lacked it. This is now fixed.

This resolves MID-7866.

Other changes:
 - Removed workaround for MID-7328 and MID-7331 (no deregistration)
from ActivityBasedTaskHandler.
 - Removed duplicate initialization in report-impl tests.
  • Loading branch information
mederly committed Sep 29, 2022
1 parent 7fd8669 commit 613bc03
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@

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

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

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
Expand All @@ -38,7 +41,9 @@ public class ClassicReportExportActivityHandler
implements ActivityHandler<ClassicReportExportWorkDefinition, ClassicReportExportActivityHandler> {

private static final Trace LOGGER = TraceManager.getTrace(ClassicReportExportActivityHandler.class);

private static final String LEGACY_HANDLER_URI = "http://midpoint.evolveum.com/xml/ns/public/report/handler-3";
private static final String ARCHETYPE_OID = SystemObjectsType.ARCHETYPE_REPORT_EXPORT_CLASSIC_TASK.value();

@Autowired ActivityHandlerRegistry registry;
@Autowired ReportServiceImpl reportService;
Expand Down Expand Up @@ -95,4 +100,9 @@ public void unregister() {
public String getIdentifierPrefix() {
return "report-export";
}

@Override
public @Nullable String getDefaultArchetypeOid() {
return ARCHETYPE_OID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ClassicReportImportWorkDefinitionType;

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

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
Expand All @@ -37,6 +40,8 @@
public class ClassicReportImportActivityHandler
implements ActivityHandler<ClassicReportImportWorkDefinition, ClassicReportImportActivityHandler> {

private static final String ARCHETYPE_OID = SystemObjectsType.ARCHETYPE_REPORT_IMPORT_CLASSIC_TASK.value();

@Autowired ActivityHandlerRegistry registry;
@Autowired ReportServiceImpl reportService;
@Autowired @Qualifier("modelObjectResolver") ObjectResolver objectResolver;
Expand Down Expand Up @@ -69,4 +74,9 @@ public void unregister() {
public String getIdentifierPrefix() {
return "report-import";
}

@Override
public @Nullable String getDefaultArchetypeOid() {
return ARCHETYPE_OID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -53,6 +54,8 @@ public class DistributedReportExportActivityHandler

private static final Trace LOGGER = TraceManager.getTrace(DistributedReportExportActivityHandler.class);

private static final String ARCHETYPE_OID = SystemObjectsType.ARCHETYPE_REPORT_EXPORT_DISTRIBUTED_TASK.value();

@Autowired ActivityHandlerRegistry registry;
@Autowired CommonTaskBeans commonTaskBeans;
@Autowired ReportServiceImpl reportService;
Expand Down Expand Up @@ -146,4 +149,9 @@ private String getType(ReportType report) {
public String getIdentifierPrefix() {
return "distributed-report-export";
}

@Override
public @Nullable String getDefaultArchetypeOid() {
return ARCHETYPE_OID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public abstract class EmptyReportIntegrationTest extends AbstractModelIntegrationTest {

public static final int DONT_COUNT_ROWS = -1;
static final int DONT_COUNT_ROWS = -1;

static final File TEST_DIR_REPORTS = new File("src/test/resources/reports");
static final File TEST_DIR_COMMON = new File("src/test/resources/common");
Expand Down Expand Up @@ -147,8 +147,15 @@ public abstract class EmptyReportIntegrationTest extends AbstractModelIntegratio
static final TestResource<TaskType> TASK_EXPORT_CLASSIC = new TestResource<>(TEST_DIR_REPORTS,
"task-export.xml", "d3a13f2e-a8c0-4f8c-bbf9-e8996848bddf");

protected static final File USER_ADMINISTRATOR_FILE = new File(TEST_DIR_COMMON, "user-administrator.xml");
protected static final File ROLE_SUPERUSER_FILE = new File(TEST_DIR_COMMON, "role-superuser.xml");
private static final TestResource<ArchetypeType> ARCHETYPE_TASK_REPORT_EXPORT_CLASSIC = new TestResource<>(TEST_DIR_COMMON,
"archetype-task-report-export-classic.xml", "00000000-0000-0000-0000-000000000511");
private static final TestResource<ArchetypeType> ARCHETYPE_TASK_REPORT_EXPORT_DISTRIBUTED = new TestResource<>(TEST_DIR_COMMON,
"archetype-task-report-export-distributed.xml", "00000000-0000-0000-0000-000000000512");
private static final TestResource<ArchetypeType> ARCHETYPE_TASK_REPORT_IMPORT_CLASSIC = new TestResource<>(TEST_DIR_COMMON,
"archetype-task-report-import-classic.xml", "00000000-0000-0000-0000-000000000510");

private static final File USER_ADMINISTRATOR_FILE = new File(TEST_DIR_COMMON, "user-administrator.xml");
private static final File ROLE_SUPERUSER_FILE = new File(TEST_DIR_COMMON, "role-superuser.xml");
protected static final File SYSTEM_CONFIGURATION_FILE = new File(TEST_DIR_COMMON, "system-configuration.xml");

@Override
Expand All @@ -157,7 +164,7 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
commonInitialization(initResult);
}

void commonInitialization(OperationResult initResult)
private void commonInitialization(OperationResult initResult)
throws CommonException, EncryptionException, IOException {
repoAddObjectFromFile(ROLE_SUPERUSER_FILE, RepoAddOptions.createOverwrite(), false, initResult);

Expand All @@ -171,6 +178,12 @@ void commonInitialization(OperationResult initResult)

PrismObject<UserType> userAdministrator = repoAddObjectFromFile(USER_ADMINISTRATOR_FILE, RepoAddOptions.createOverwrite(), false, initResult);
login(userAdministrator);

repoAdd(ARCHETYPE_TASK_REPORT_EXPORT_CLASSIC, initResult);
repoAdd(ARCHETYPE_TASK_REPORT_EXPORT_DISTRIBUTED, initResult);
repoAdd(ARCHETYPE_TASK_REPORT_IMPORT_CLASSIC, initResult);

activityBasedTaskHandler.setAvoidAutoAssigningArchetypes(false); // We test auto-assigning of archetypes here
}

void createUsers(int users, Task initTask, OperationResult initResult) throws CommonException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ private void runTest(TestResource<ReportType> reportResource, int expectedRows,

assertTask(TASK_EXPORT_CLASSIC.oid, "after")
.assertSuccess()
.display();
.display()
.assertHasArchetype(SystemObjectsType.ARCHETYPE_REPORT_EXPORT_CLASSIC_TASK.value());

PrismObject<ReportType> report = getObject(ReportType.class, reportResource.oid);
basicCheckOutputFile(report, expectedRows, expectedColumns, lastLine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public void test100ImportUsers() throws Exception {

assertTask(TASK_IMPORT_CLASSIC.oid, "after")
.assertSuccess()
.display();
.display()
.assertHasArchetype(SystemObjectsType.ARCHETYPE_REPORT_IMPORT_CLASSIC_TASK.value());

PrismObject<UserType> user1 = searchObjectByName(UserType.class, "testUser01");
assertNotNull("User testUser01 was not created", user1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.io.File;
import java.util.List;

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

import org.testng.annotations.Test;

import com.evolveum.midpoint.prism.PrismContext;
Expand All @@ -20,10 +22,6 @@
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.TestResource;
import com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectCollectionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.WorkDefinitionsType;
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;

public class TestCsvReportMultiNode extends TestCsvReport {
Expand All @@ -44,7 +42,6 @@ public class TestCsvReportMultiNode extends TestCsvReport {
@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);
commonInitialization(initResult);

repoAdd(TASK_DISTRIBUTED_EXPORT_USERS, initResult);
repoAdd(TASK_DISTRIBUTED_EXPORT_AUDIT, initResult);
Expand Down Expand Up @@ -74,7 +71,8 @@ public void test100ExportUsers() throws Exception {

assertTask(TASK_DISTRIBUTED_EXPORT_USERS.oid, "after")
.assertSuccess()
.display();
.display()
.assertHasArchetype(SystemObjectsType.ARCHETYPE_REPORT_EXPORT_DISTRIBUTED_TASK.value());

PrismObject<ReportType> report = getObject(ReportType.class, REPORT_OBJECT_COLLECTION_USERS.oid);
basicCheckOutputFile(report, 1004, 2, null);
Expand Down Expand Up @@ -158,7 +156,8 @@ private void auditTest() throws Exception {

assertTask(TASK_DISTRIBUTED_EXPORT_AUDIT.oid, "after")
.assertSuccess()
.display();
.display()
.assertHasArchetype(SystemObjectsType.ARCHETYPE_REPORT_EXPORT_DISTRIBUTED_TASK.value());

assertNotificationMessage(REPORT_AUDIT_COLLECTION_WITH_DEFAULT_COLUMN);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!--
~ Copyright (c) 2020 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->
<archetype oid="00000000-0000-0000-0000-000000000511"
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3">
<name>Report export task</name>
<!-- We need only the existence of this object. -->
</archetype>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!--
~ Copyright (c) 2020 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->
<archetype oid="00000000-0000-0000-0000-000000000512"
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3">
<name>Distributed report export task</name>
<!-- We need only the existence of this object. -->
</archetype>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!--
~ Copyright (c) 2020 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->
<archetype oid="00000000-0000-0000-0000-000000000510"
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3">
<name>Report import task</name>
<!-- We need only the existence of this object. -->
</archetype>
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ public void initialize() {

@PreDestroy
public void destroy() {
// Temporarily disabled - as a workaround for MID-7328 and MID-7331
// taskManager.unregisterHandler(HANDLER_URI);
// taskManager.setDefaultHandlerUri(null);
taskManager.unregisterHandler(HANDLER_URI);
taskManager.setDefaultHandlerUri(null);
}

public CommonTaskBeans getBeans() {
Expand Down

0 comments on commit 613bc03

Please sign in to comment.