Skip to content

Commit

Permalink
task page visibility improvements, new panel for ExecuteScriptType, f…
Browse files Browse the repository at this point in the history
…ix for CleanupTaskHandler.getArchetypeOid()
  • Loading branch information
katkav committed Mar 25, 2020
1 parent 6ab193b commit 27e57f7
Show file tree
Hide file tree
Showing 10 changed files with 545 additions and 347 deletions.
Expand Up @@ -4540,10 +4540,34 @@ public static Class<? extends PageBase> resolveSelfPage() {
return null;
}

public static <AH extends AssignmentHolderType> boolean hasAnyArchetypeAssignemnt(AH assignmentHolder) {
if (assignmentHolder.getAssignment() == null) {
return false;
}
List<AssignmentType> archetypeAssignments = assignmentHolder.getAssignment()
.stream()
.filter(assignmentType -> WebComponentUtil.isArchetypeAssignment(assignmentType)).collect(Collectors.toList());
return CollectionUtils.isNotEmpty(archetypeAssignments);
}

public static boolean isArchetypeAssignment(AssignmentType assignmentType) {
if (assignmentType.getTargetRef() == null) {
return false;
}
return QNameUtil.match(assignmentType.getTargetRef().getType(), ArchetypeType.COMPLEX_TYPE);
}


public static <AH extends AssignmentHolderType> boolean hasArchetypeAssignment(AH assignmentHolder, String archetypeOid) {
if (assignmentHolder.getAssignment() == null) {
return false;
}
List<AssignmentType> archetypeAssignments = assignmentHolder.getAssignment()
.stream()
.filter(assignmentType -> WebComponentUtil.isArchetypeAssignment(assignmentType)
&& archetypeOid.equals(assignmentType.getTargetRef().getOid()))
.collect(Collectors.toList());
return CollectionUtils.isNotEmpty(archetypeAssignments);
}

}
@@ -0,0 +1,67 @@
/*
* 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.
*/

package com.evolveum.midpoint.gui.impl.factory;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.ThreadContext;
import org.apache.wicket.model.IModel;

import com.evolveum.midpoint.gui.api.util.ModelServiceLocator;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExecuteScriptType;

public class ExecuteScriptModel implements IModel<String> {

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

private IModel<ExecuteScriptType> baseModel;
private ModelServiceLocator locator;

public ExecuteScriptModel(IModel<ExecuteScriptType> model, ModelServiceLocator locator) {
this.baseModel = model;
this.locator = locator;
}


@Override
public String getObject() {
try {
ExecuteScriptType value = baseModel.getObject();
if (value == null) {
return null;
}

return locator.getPrismContext().xmlSerializer().serializeRealValue(value);
} catch (Exception e) {
// TODO handle!!!!
LoggingUtils.logUnexpectedException(LOGGER, "Cannot serialize script", e);
ThreadContext.getSession().error("Cannot serialize script: " + e.getMessage());
// getSession().error("Cannot serialize filter");
}
return null;
}

@Override
public void setObject(String object) {
if (StringUtils.isBlank(object)) {
return;
}

try {
ExecuteScriptType script = locator.getPrismContext().parserFor(object).parseRealValue(ExecuteScriptType.class);
baseModel.setObject(script);
} catch (Exception e) {
// TODO handle!!!!
LoggingUtils.logUnexpectedException(LOGGER, "Cannot parse script", e);
ThreadContext.getSession().error("Cannot parse script: " + e.getMessage());
// getSession().error("Cannot parse filter");
}
}
}
@@ -0,0 +1,44 @@
/*
* 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.
*/

package com.evolveum.midpoint.gui.impl.factory;

import org.apache.wicket.markup.html.panel.Panel;

import com.evolveum.midpoint.gui.api.factory.AbstractGuiComponentFactory;
import com.evolveum.midpoint.gui.api.prism.ItemWrapper;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.web.component.input.TextAreaPanel;
import com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExecuteScriptType;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class ExecuteScriptWrapperFactory extends AbstractGuiComponentFactory<ExecuteScriptType> {

@PostConstruct
public void register() {
getRegistry().addToRegistry(this);
}

@Override
public <IW extends ItemWrapper> boolean match(IW wrapper) {
return QNameUtil.match(ExecuteScriptType.COMPLEX_TYPE, wrapper.getTypeName());
}

@Override
public Integer getOrder() {
return super.getOrder() - 1;
}

@Override
protected Panel getPanel(PrismPropertyPanelContext<ExecuteScriptType> panelCtx) {
return new TextAreaPanel<>(panelCtx.getComponentId(), new ExecuteScriptModel(panelCtx.getRealValueModel(), panelCtx.getPageBase()), 100);
}
}
Expand Up @@ -74,7 +74,6 @@ public PrismObjectWrapper<O> createObjectWrapper(PrismObject<O> object, ItemStat
context.setShowEmpty(ItemStatus.ADDED == status);
objectWrapper.setExpanded(true);
PrismContainerValueWrapper<O> valueWrapper = createValueWrapper(objectWrapper, object.getValue(), ItemStatus.ADDED == status ? ValueStatus.ADDED : ValueStatus.NOT_CHANGED, context);
objectWrapper.getValues().clear();
objectWrapper.getValues().add(valueWrapper);

registry.registerWrapperPanel(object.getDefinition().getTypeName(), PrismContainerPanel.class);
Expand Down
Expand Up @@ -400,20 +400,29 @@ public boolean isRefreshEnabled() {
return false;
}

public void refresh(AjaxRequestTarget target) {
public void refresh(AjaxRequestTarget target) {
refresh(target, true);
}

public void refresh(AjaxRequestTarget target, boolean soft) {

if (!isAdd()) {
getObjectModel().reset();
}
target.add(getSummaryPanel());
target.add(getOperationalButtonsPanel());
target.add(getFeedbackPanel());

for (Component component : getMainPanel().getTabbedPanel()) {
if (component instanceof RefreshableTabPanel) {
for (Component c : ((RefreshableTabPanel) component).getComponentsToUpdate()) {
target.add(c);
if (soft) {
for (Component component : getMainPanel().getTabbedPanel()) {
if (component instanceof RefreshableTabPanel) {
for (Component c : ((RefreshableTabPanel) component).getComponentsToUpdate()) {
target.add(c);
}
}
}
} else {
target.add(getMainPanel().getTabbedPanel());
}
}

Expand Down
Expand Up @@ -88,6 +88,8 @@ public class PageTask extends PageAdminObjectDetails<TaskType> implements Refres

private Boolean refreshEnabled;

private TaskTabsVisibility taskTabsVisibility;

public PageTask() {
initialize(null);
}
Expand Down Expand Up @@ -541,6 +543,8 @@ private String createResumePauseButtonLabel() {

@Override
protected AbstractObjectMainPanel<TaskType> createMainPanel(String id) {
taskTabsVisibility = new TaskTabsVisibility();
taskTabsVisibility.computeAll(this, getObjectWrapper());
return new TaskMainPanel(id, getObjectModel(), this);
}

Expand Down Expand Up @@ -575,4 +579,22 @@ public boolean isRefreshEnabled() {
return refreshEnabled;

}

@Override
public void refresh(AjaxRequestTarget target) {
TaskTabsVisibility taskTabsVisibilityNew = new TaskTabsVisibility();
taskTabsVisibilityNew.computeAll(this, getObjectWrapper());

boolean soft = false;
if (taskTabsVisibilityNew.equals(taskTabsVisibility)) {
soft = true;
}

taskTabsVisibility = taskTabsVisibilityNew;
super.refresh(target, soft);
}

public TaskTabsVisibility getTaskTabVisibilty() {
return taskTabsVisibility;
}
}
Expand Up @@ -7,9 +7,7 @@
package com.evolveum.midpoint.web.page.admin.server;

import java.util.*;
import java.util.stream.Collectors;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.RestartResponseException;
Expand Down Expand Up @@ -80,7 +78,7 @@ protected void onUpdatePerformed(AjaxRequestTarget target) {
return;
}

if (!hasArchetypeAssignemnt()) {
if (!WebComponentUtil.hasAnyArchetypeAssignemnt(getTask())) {
try {
PrismContainerWrapper<AssignmentType> archetypeAssignment = TaskBasicTabPanel.this.getModelObject().findContainer(TaskType.F_ASSIGNMENT);
PrismContainerValue<AssignmentType> archetypeAssignmentValue = archetypeAssignment.getItem().createNewValue();
Expand Down Expand Up @@ -111,7 +109,7 @@ protected void onUpdatePerformed(AjaxRequestTarget target) {

@Override
public boolean isVisible() {
return !hasArchetypeAssignemnt() || isSystemArchetypeAssignemnt() || isUtilityArchetypeAssignemnt();
return satisfyArchetypeAssignment();
}

});
Expand All @@ -136,9 +134,9 @@ public boolean isVisible() {
}

private ItemVisibility getBasicTabVisibility(ItemPath path) {
if (ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_CLEANUP_POLICIES).equivalent(path)) {
return ItemVisibility.HIDDEN;
}
// if (ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_CLEANUP_POLICIES).equivalent(path)) {
// return ItemVisibility.HIDDEN;
// }

if (TaskType.F_SUBTASK_REF.equivalent(path)) {
return ItemVisibility.HIDDEN;
Expand All @@ -162,7 +160,7 @@ private ItemVisibility getBasicTabVisibility(ItemPath path) {
return ItemVisibility.AUTO;
}

if (hasArchetypeAssignemnt() && !isUtilityArchetypeAssignemnt() && !isSystemArchetypeAssignemnt()) {
if (!satisfyArchetypeAssignment()) {
//Visibility defined in archetype definition
return ItemVisibility.AUTO;
}
Expand Down Expand Up @@ -253,7 +251,7 @@ private boolean getBasicTabEditability(ItemPath path) {
return false;
}

if ((!hasArchetypeAssignemnt() || isSystemArchetypeAssignemnt() || isUtilityArchetypeAssignemnt()) && getTask().getHandlerUri() == null) {
if (satisfyArchetypeAssignment() && getTask().getHandlerUri() == null) {
return false;
}

Expand All @@ -273,6 +271,12 @@ private boolean getBasicTabEditability(ItemPath path) {

}

private boolean satisfyArchetypeAssignment() {
return !WebComponentUtil.hasAnyArchetypeAssignemnt(getTask())
|| WebComponentUtil.hasArchetypeAssignment(getTask(), SystemObjectsType.ARCHETYPE_SYSTEM_TASK.value())
|| WebComponentUtil.hasArchetypeAssignment(getTask(), SystemObjectsType.ARCHETYPE_UTILITY_TASK.value());
}

private ItemMandatoryHandler getItemMandatoryHandler() {
return itemWrapper -> {
if (TaskType.F_RECURRENCE.equivalent(itemWrapper.getPath())) {
Expand All @@ -282,42 +286,7 @@ private ItemMandatoryHandler getItemMandatoryHandler() {
};
}

private boolean hasArchetypeAssignemnt() {
TaskType task = getTask();
if (task.getAssignment() == null) {
return false;
}
List<AssignmentType> archetypeAssignments = task.getAssignment()
.stream()
.filter(assignmentType -> WebComponentUtil.isArchetypeAssignment(assignmentType)).collect(Collectors.toList());
return CollectionUtils.isNotEmpty(archetypeAssignments);
}

private boolean isSystemArchetypeAssignemnt() {
TaskType task = getTask();
if (task.getAssignment() == null) {
return false;
}
List<AssignmentType> archetypeAssignments = task.getAssignment()
.stream()
.filter(assignmentType -> WebComponentUtil.isArchetypeAssignment(assignmentType)
&& SystemObjectsType.ARCHETYPE_SYSTEM_TASK.value().equals(assignmentType.getTargetRef().getOid()))
.collect(Collectors.toList());
return CollectionUtils.isNotEmpty(archetypeAssignments);
}

private boolean isUtilityArchetypeAssignemnt() {
TaskType task = getTask();
if (task.getAssignment() == null) {
return false;
}
List<AssignmentType> archetypeAssignments = task.getAssignment()
.stream()
.filter(assignmentType -> WebComponentUtil.isArchetypeAssignment(assignmentType)
&& SystemObjectsType.ARCHETYPE_UTILITY_TASK.value().equals(assignmentType.getTargetRef().getOid()))
.collect(Collectors.toList());
return CollectionUtils.isNotEmpty(archetypeAssignments);
}

@Override
public Collection<Component> getComponentsToUpdate() {
Expand Down

0 comments on commit 27e57f7

Please sign in to comment.