Skip to content

Commit

Permalink
task intent autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Sep 28, 2021
1 parent 86e97a2 commit 7dce257
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4730,6 +4730,12 @@ public static AssignmentHolderType getObjectFromAddDeltyForCase(CaseType aCase)
return null;
}

public static boolean isResourceRelatedTask(TaskType task) {
return WebComponentUtil.hasArchetypeAssignment(task, SystemObjectsType.ARCHETYPE_RECONCILIATION_TASK.value())
|| WebComponentUtil.hasArchetypeAssignment(task, SystemObjectsType.ARCHETYPE_LIVE_SYNC_TASK.value())
|| WebComponentUtil.hasArchetypeAssignment(task, SystemObjectsType.ARCHETYPE_IMPORT_TASK.value());
}

public static boolean isRefreshEnabled(PageBase pageBase, QName type) {
CompiledGuiProfile cup = pageBase.getCompiledGuiProfile();
if (cup == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
import java.util.Collections;
import java.util.Iterator;
import javax.annotation.PostConstruct;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.api.prism.wrapper.*;
import com.evolveum.midpoint.prism.Referencable;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.apache.wicket.extensions.ajax.markup.html.autocomplete.StringAutoCompleteRenderer;
import org.springframework.stereotype.Component;

import com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel;
import com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismPropertyWrapper;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.gui.api.util.WebPrismUtil;
Expand All @@ -27,9 +31,6 @@
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.web.component.prism.InputPanel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;

//FIXME serializable?
@Component
Expand All @@ -47,7 +48,11 @@ protected InputPanel getPanel(PrismPropertyPanelContext<String> panelCtx) {
@Override
public Iterator<String> getIterator(String input) {
PrismPropertyWrapper<String> itemWrapper = panelCtx.unwrapWrapperModel();
PrismReferenceValue objectRef = WebPrismUtil.findSingleReferenceValue(itemWrapper, ItemPath.create(TaskType.F_OBJECT_REF));
PrismReferenceValue objectRef = findResourceReference(itemWrapper);

if (objectRef == null || objectRef.getOid() == null) {
return Collections.emptyIterator();
}

Task task = panelCtx.getPageBase().createSimpleTask("load resource");
PrismObject<ResourceType> resourceType = WebModelServiceUtils.loadObject(objectRef, ResourceType.COMPLEX_TYPE, panelCtx.getPageBase(), task, task.getResult());
Expand All @@ -56,7 +61,7 @@ public Iterator<String> getIterator(String input) {
return Collections.emptyIterator();
}

PrismPropertyValue<ShadowKindType> kindPropValue = WebPrismUtil.findSinglePropertyValue(itemWrapper, ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_KIND));
PrismPropertyValue<ShadowKindType> kindPropValue = findKind(itemWrapper);
if (kindPropValue == null) {
return Collections.emptyIterator();
}
Expand All @@ -67,7 +72,57 @@ public Iterator<String> getIterator(String input) {

@Override
public <IW extends ItemWrapper<?, ?>> boolean match(IW wrapper) {
return wrapper.getPath().equivalent(ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_INTENT));
PrismObjectWrapper<?> objectWrapper = wrapper.findObjectWrapper();
if (objectWrapper == null) {
return false;
}

ObjectType object = objectWrapper.getObject().asObjectable();
if (!(object instanceof TaskType)) {
return false;
}

TaskType task = (TaskType) object;
if (WebComponentUtil.isResourceRelatedTask(task) && wrapper.getPath().startsWith(ItemPath.create(TaskType.F_ACTIVITY, ActivityDefinitionType.F_WORK)) && wrapper.getPath().lastName().equivalent(ResourceObjectSetType.F_INTENT)) {
return true;
}
return false;
}

//TODO coppied from TaskObjectClassFactory
private PrismReferenceValue findResourceReference(PrismPropertyWrapper<String> itemWrapper) {
PrismContainerValueWrapper<?> parent = itemWrapper.getParent();
if (parent == null) {
return null;
}
try {
PrismReferenceWrapper<Referencable> resourceRefWrapper = parent.findReference(ResourceObjectSetType.F_RESOURCE_REF);
if (resourceRefWrapper == null) {
return null;
}

return resourceRefWrapper.getValue().getNewValue();
} catch (SchemaException e) {
return null;
}
// WebPrismUtil.findSingleReferenceValue(itemWrapper, ItemPath.create(TaskType.F_OBJECT_REF))
}

private PrismPropertyValue<ShadowKindType> findKind(PrismPropertyWrapper<String> itemWrapper) {
PrismContainerValueWrapper<?> parent = itemWrapper.getParent();
if (parent == null) {
return null;
}
try {
PrismPropertyWrapper<ShadowKindType> kindWrapper = parent.findProperty(ResourceObjectSetType.F_KIND);
if (kindWrapper == null) {
return null;
}

return kindWrapper.getValue().getNewValue();
} catch (SchemaException e) {
return null;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,13 @@ protected boolean alwaysReload() {
}

TaskType task = (TaskType) object;
if (isResourceRelatedTask(task) && wrapper.getPath().startsWith(ItemPath.create(TaskType.F_ACTIVITY, ActivityDefinitionType.F_WORK)) && wrapper.getPath().lastName().equivalent(ResourceObjectSetType.F_OBJECTCLASS)) {
if (WebComponentUtil.isResourceRelatedTask(task) && wrapper.getPath().startsWith(ItemPath.create(TaskType.F_ACTIVITY, ActivityDefinitionType.F_WORK)) && wrapper.getPath().lastName().equivalent(ResourceObjectSetType.F_OBJECTCLASS)) {
return true;
}
return false;
// return wrapper.getPath().equivalent(ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_OBJECTCLASS));
}

private boolean isResourceRelatedTask(TaskType task) {
return WebComponentUtil.hasArchetypeAssignment(task, SystemObjectsType.ARCHETYPE_RECONCILIATION_TASK.value())
|| WebComponentUtil.hasArchetypeAssignment(task, SystemObjectsType.ARCHETYPE_LIVE_SYNC_TASK.value())
|| WebComponentUtil.hasArchetypeAssignment(task, SystemObjectsType.ARCHETYPE_IMPORT_TASK.value());
}

private PrismReferenceValue findResourceReference(PrismPropertyWrapper<QName> itemWrapper) {
PrismContainerValueWrapper<?> parent = itemWrapper.getParent();
if (parent == null) {
Expand Down

0 comments on commit 7dce257

Please sign in to comment.