Skip to content

Commit

Permalink
MID-7785:fix for creating new utility or system tasks from side bar menu
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Mar 29, 2022
1 parent 15d8805 commit 03c03da
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected void onTemplateChosePerformed(CompiledObjectCollectionView collectionV
LOGGER.error("Cannot create prism object for {}. Using object from page model.", PageAssignmentHolderDetails.this.getType());
assignmentHolder = getObjectDetailsModels().getObjectWrapperModel().getObject().getObjectOld().clone();
}
List<ObjectReferenceType> archetypeRef = ObjectCollectionViewUtil.getArchetypeReferencesList(collectionViews);
List<ObjectReferenceType> archetypeRef = PageAssignmentHolderDetails.this.getArchetypeReferencesList(collectionViews);
if (archetypeRef != null) {
AssignmentHolderType holder = assignmentHolder.asObjectable();
archetypeRef.forEach(a -> holder.getAssignment().add(ObjectTypeUtil.createAssignmentTo(a, getPrismContext())));
Expand All @@ -127,6 +127,10 @@ protected void onTemplateChosePerformed(CompiledObjectCollectionView collectionV
};
}

protected List<ObjectReferenceType> getArchetypeReferencesList(CompiledObjectCollectionView collectionViews) {
return ObjectCollectionViewUtil.getArchetypeReferencesList(collectionViews);
}

protected Collection<CompiledObjectCollectionView> findAllApplicableArchetypeViews() {
return getCompiledGuiProfile().findAllApplicableArchetypeViews(getType(), OperationTypeType.ADD);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismObjectWrapper;
import com.evolveum.midpoint.gui.impl.page.admin.assignmentholder.PageAssignmentHolderDetails;
import com.evolveum.midpoint.gui.impl.page.admin.component.TaskOperationalButtonsPanel;
import com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.ObjectDeltaOperation;
Expand All @@ -22,15 +23,16 @@
import com.evolveum.midpoint.security.api.AuthorizationConstants;
import com.evolveum.midpoint.web.page.admin.server.TaskSummaryPanel;
import com.evolveum.midpoint.web.util.OnePageParameterEncoder;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;
import com.evolveum.midpoint.web.util.TaskOperationUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;

import java.util.Collection;
import java.util.List;

@PageDescriptor(
urls = {
Expand Down Expand Up @@ -128,4 +130,13 @@ public void refresh(AjaxRequestTarget target, boolean soft) {
super.refresh(target, soft);
}

@Override
protected Collection<CompiledObjectCollectionView> findAllApplicableArchetypeViews() {
return TaskOperationUtils.getAllApplicableArchetypeForNewTask(this);
}

@Override
protected List<ObjectReferenceType> getArchetypeReferencesList(CompiledObjectCollectionView collectionView) {
return TaskOperationUtils.getArchetypeReferencesList(collectionView);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,7 @@ protected void newObjectPerformed(AjaxRequestTarget target, AssignmentObjectRela
try {
List<ObjectReferenceType> referenceList = new ArrayList<>();
referenceList.addAll(getNewObjectReferencesList(collectionView, relation));
if (referenceList.get(0) != null) {
String oid = referenceList.get(0).getOid();
if (getUtilityArchetypesList().contains(oid)) {
referenceList.add(new ObjectReferenceType()
.type(ArchetypeType.COMPLEX_TYPE)
.oid(SystemObjectsType.ARCHETYPE_UTILITY_TASK.value()));
} else if (getSystemArchetypesList().contains(oid)) {
referenceList.add(new ObjectReferenceType()
.type(ArchetypeType.COMPLEX_TYPE)
.oid(SystemObjectsType.ARCHETYPE_SYSTEM_TASK.value()));
}
}
TaskOperationUtils.addArchetypeReferencesList(referenceList);
WebComponentUtil.initNewObjectWithReference(getPageBase(),
relation != null && CollectionUtils.isNotEmpty(relation.getObjectTypes()) ?
relation.getObjectTypes().get(0) : WebComponentUtil.classToQName(getPrismContext(), getType()),
Expand All @@ -206,44 +195,21 @@ protected boolean isCollectionViewWithoutMorePossibleNewType(CompiledObjectColle
CompiledObjectCollectionView objectCollectionView = getObjectCollectionView();

if (isViewForObjectCollectionType(objectCollectionView, "00000000-0000-0000-0002-000000000007", ObjectCollectionType.COMPLEX_TYPE)){
return getNewTaskInfluencesList(getReportArchetypesList());
return getNewTaskInfluencesList(TaskOperationUtils.getReportArchetypesList());
}

if (isViewForObjectCollectionType(objectCollectionView, SystemObjectsType.ARCHETYPE_UTILITY_TASK.value(), ArchetypeType.COMPLEX_TYPE)) {
return getNewTaskInfluencesList(getUtilityArchetypesList());
return getNewTaskInfluencesList(TaskOperationUtils.getUtilityArchetypesList());
}

if (isViewForObjectCollectionType(objectCollectionView, SystemObjectsType.ARCHETYPE_SYSTEM_TASK.value(), ArchetypeType.COMPLEX_TYPE)) {
return getNewTaskInfluencesList(getSystemArchetypesList());
return getNewTaskInfluencesList(TaskOperationUtils.getSystemArchetypesList());
}
return super.getNewObjectInfluencesList();
}

private List<String> getReportArchetypesList() {
return Arrays.asList(
SystemObjectsType.ARCHETYPE_REPORT_EXPORT_CLASSIC_TASK.value(),
SystemObjectsType.ARCHETYPE_REPORT_IMPORT_CLASSIC_TASK.value(),
SystemObjectsType.ARCHETYPE_REPORT_EXPORT_DISTRIBUTED_TASK.value());
}

private List<String> getUtilityArchetypesList() {
return Arrays.asList(
SystemObjectsType.ARCHETYPE_SHADOW_INTEGRITY_CHECK_TASK.value(),
SystemObjectsType.ARCHETYPE_SHADOWS_REFRESH_TASK.value(),
SystemObjectsType.ARCHETYPE_SHADOWS_DELETE_LONG_TIME_NOT_UPDATED_TASK.value(),
SystemObjectsType.ARCHETYPE_EXECUTE_CHANGE_TASK.value(),
SystemObjectsType.ARCHETYPE_EXECUTE_DETLAS_TASK.value(),
SystemObjectsType.ARCHETYPE_REINDEX_REPOSITORY_TASK.value(),
SystemObjectsType.ARCHETYPE_OBJECT_INTEGRITY_CHECK_TASK.value(),
SystemObjectsType.ARCHETYPE_OBJECTS_DELETE_TASK.value());
}

private List<String> getSystemArchetypesList() {
return Arrays.asList(
SystemObjectsType.ARCHETYPE_VALIDITY_SCANNER_TASK.value(),
SystemObjectsType.ARCHETYPE_TRIGGER_SCANNER_TASK.value(),
SystemObjectsType.ARCHETYPE_PROPAGATION_TASK.value(),
SystemObjectsType.ARCHETYPE_MULTI_PROPAGATION_TASK.value());
protected List<CompiledObjectCollectionView> getAllApplicableArchetypeViews() {
return TaskOperationUtils.getAllApplicableArchetypeForNewTask(getPageBase());
}

private List<CompiledObjectCollectionView> getNewTaskInfluencesList(List<String> oids) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@
*/
package com.evolveum.midpoint.web.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.impl.util.ObjectCollectionViewUtil;
import com.evolveum.midpoint.model.api.TaskService;
import com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
Expand All @@ -23,7 +29,7 @@
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.web.page.admin.server.PageTasks;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.jetbrains.annotations.NotNull;

Expand All @@ -34,6 +40,27 @@ public class TaskOperationUtils {
private static final String OPERATION_RESUME_TASKS = DOT_CLASS + "resumeTasks";
private static final String OPERATION_RUN_NOW_TASKS = DOT_CLASS + "runNowTasks";

private static final List<String> REPORT_ARCHETYPES = Arrays.asList(
SystemObjectsType.ARCHETYPE_REPORT_EXPORT_CLASSIC_TASK.value(),
SystemObjectsType.ARCHETYPE_REPORT_IMPORT_CLASSIC_TASK.value(),
SystemObjectsType.ARCHETYPE_REPORT_EXPORT_DISTRIBUTED_TASK.value());

private static final List<String> UTILITY_ARCHETYPES = Arrays.asList(
SystemObjectsType.ARCHETYPE_SHADOW_INTEGRITY_CHECK_TASK.value(),
SystemObjectsType.ARCHETYPE_SHADOWS_REFRESH_TASK.value(),
SystemObjectsType.ARCHETYPE_SHADOWS_DELETE_LONG_TIME_NOT_UPDATED_TASK.value(),
SystemObjectsType.ARCHETYPE_EXECUTE_CHANGE_TASK.value(),
SystemObjectsType.ARCHETYPE_EXECUTE_DETLAS_TASK.value(),
SystemObjectsType.ARCHETYPE_REINDEX_REPOSITORY_TASK.value(),
SystemObjectsType.ARCHETYPE_OBJECT_INTEGRITY_CHECK_TASK.value(),
SystemObjectsType.ARCHETYPE_OBJECTS_DELETE_TASK.value());

private static final List<String> SYSTEM_ARCHETYPES = Arrays.asList(
SystemObjectsType.ARCHETYPE_VALIDITY_SCANNER_TASK.value(),
SystemObjectsType.ARCHETYPE_TRIGGER_SCANNER_TASK.value(),
SystemObjectsType.ARCHETYPE_PROPAGATION_TASK.value(),
SystemObjectsType.ARCHETYPE_MULTI_PROPAGATION_TASK.value());

/**
* Suspends tasks "intelligently" i.e. tries to recognize whether to suspend a single task,
* or to suspend the whole tree. (Maybe this differentiation should be done by the task manager itself.)
Expand Down Expand Up @@ -158,4 +185,57 @@ private static List<TaskType> getTreeRoots(List<TaskType> selectedTasks) {
.filter(ActivityStateUtil::isManageableTreeRoot)
.collect(Collectors.toList());
}

public static List<CompiledObjectCollectionView> getAllApplicableArchetypeForNewTask(PageBase pageBase) {
@NotNull List<CompiledObjectCollectionView> archetypes = pageBase.getCompiledGuiProfile().findAllApplicableArchetypeViews(
WebComponentUtil.classToQName(PrismContext.get(), TaskType.class), OperationTypeType.ADD);
archetypes.removeIf(archetype -> archetype.getCollection().getCollectionRef().getOid().equals(SystemObjectsType.ARCHETYPE_UTILITY_TASK.value())
|| archetype.getCollection().getCollectionRef().getOid().equals(SystemObjectsType.ARCHETYPE_SYSTEM_TASK.value()));
return archetypes;
}

public static List<String> getReportArchetypesList() {
return REPORT_ARCHETYPES;
}

public static List<String> getUtilityArchetypesList() {
return UTILITY_ARCHETYPES;
}

public static List<String> getSystemArchetypesList() {
return SYSTEM_ARCHETYPES;
}

public static List<ObjectReferenceType> getArchetypeReferencesList(CompiledObjectCollectionView collectionView) {
List<ObjectReferenceType> references = new ArrayList<>();
references.addAll(ObjectCollectionViewUtil.getArchetypeReferencesList(collectionView));
if (references.get(0) != null) {
String oid = references.get(0).getOid();
if (UTILITY_ARCHETYPES.contains(oid)) {
references.add(new ObjectReferenceType()
.type(ArchetypeType.COMPLEX_TYPE)
.oid(SystemObjectsType.ARCHETYPE_UTILITY_TASK.value()));
} else if (SYSTEM_ARCHETYPES.contains(oid)) {
references.add(new ObjectReferenceType()
.type(ArchetypeType.COMPLEX_TYPE)
.oid(SystemObjectsType.ARCHETYPE_SYSTEM_TASK.value()));
}
}
return references;
}

public static void addArchetypeReferencesList(List<ObjectReferenceType> references) {
if (references.get(0) != null) {
String oid = references.get(0).getOid();
if (UTILITY_ARCHETYPES.contains(oid)) {
references.add(new ObjectReferenceType()
.type(ArchetypeType.COMPLEX_TYPE)
.oid(SystemObjectsType.ARCHETYPE_UTILITY_TASK.value()));
} else if (SYSTEM_ARCHETYPES.contains(oid)) {
references.add(new ObjectReferenceType()
.type(ArchetypeType.COMPLEX_TYPE)
.oid(SystemObjectsType.ARCHETYPE_SYSTEM_TASK.value()));
}
}
}
}

0 comments on commit 03c03da

Please sign in to comment.