Skip to content

Commit

Permalink
MID-8969: use only ObjectClass for reclassification task
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Aug 10, 2023
1 parent 5399f10 commit 3999f95
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.gui.impl.page.admin.abstractrole.component.TaskAwareExecutor;
import com.evolveum.midpoint.gui.impl.page.admin.resource.component.ResourceObjectsPanel;
import com.evolveum.midpoint.model.api.ActivitySubmissionOptions;
import com.evolveum.midpoint.prism.PrismObject;
Expand All @@ -21,6 +22,7 @@
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.web.component.AjaxIconButton;

import com.evolveum.midpoint.web.component.dialog.ConfirmationPanel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.apache.wicket.ajax.AjaxRequestTarget;
Expand All @@ -44,7 +46,11 @@ public abstract class ReloadableButton extends AjaxIconButton {
private final PageBase pageBase;

public ReloadableButton(String id, PageBase pageBase) {
super(id, Model.of(""), pageBase.createStringResource("ReloadableButton.reload"));
this(id, pageBase, PageBase.createStringResourceStatic("ReloadableButton.reload"));
}

public ReloadableButton(String id, PageBase pageBase, IModel<String> buttonLabel) {
super(id, Model.of(""), buttonLabel);
this.pageBase = pageBase;
}

Expand Down Expand Up @@ -74,21 +80,13 @@ private IModel<String> createIconModel() {
};
}

@Override
public void onClick(AjaxRequestTarget target) {
private void onClickReloadButton(AjaxRequestTarget target) {
taskOidForReloaded = pageBase.taskAwareExecutor(target, OPERATION_RELOAD)
.withOpResultOptions(
OpResult.Options.create()
.withHideSuccess(true)
.withHideInProgress(true))
.run((task, result) -> pageBase.getModelInteractionService().submit(
createActivityDefinition(),
ActivitySubmissionOptions.create()
.withTaskTemplate(new TaskType()
.name(getTaskName())
.cleanupAfterCompletion(XmlTypeConverter.createDuration("PT0S"))),
task, result)
);
.run(getTaskExecutor());
reloadedBehaviour = new AjaxSelfUpdatingTimerBehavior(Duration.ofSeconds(5)) {

@Override
Expand Down Expand Up @@ -123,11 +121,50 @@ protected void onPostProcessTarget(AjaxRequestTarget target) {
refresh(target);
}

@Override
public final void onClick(AjaxRequestTarget target) {
if (useConfirmationPopup()) {
IModel<String> confirmModel = getConfirmMessage();

ConfirmationPanel confirmationPanel = new ConfirmationPanel(pageBase.getMainPopupBodyId(), confirmModel) {
@Override
public void yesPerformed(AjaxRequestTarget target) {
onClickReloadButton(target);
}
};
pageBase.showMainPopup(confirmationPanel, target);
} else {
onClickReloadButton(target);
}
}

protected IModel<String> getConfirmMessage() {
return Model.of("");
}

protected boolean useConfirmationPopup() {
return false;
}

protected TaskAwareExecutor.Executable<String> getTaskExecutor() {
return (task, result) -> pageBase.getModelInteractionService().submit(
createActivityDefinition(),
ActivitySubmissionOptions.create()
.withTaskTemplate(new TaskType()
.name(getTaskName())
.cleanupAfterCompletion(XmlTypeConverter.createDuration("PT0S"))),
task, result);
}

protected abstract void refresh(AjaxRequestTarget target);

protected abstract ActivityDefinitionType createActivityDefinition() throws SchemaException;
protected ActivityDefinitionType createActivityDefinition() throws SchemaException {
return null;
}

protected abstract String getTaskName();
protected String getTaskName() {
return null;
}

@Override
protected void onComponentTag(ComponentTag tag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,30 @@

package com.evolveum.midpoint.gui.impl.page.admin.resource.component;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.api.component.result.OpResult;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;

import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.gui.impl.component.button.ReloadableButton;
import com.evolveum.midpoint.gui.impl.component.search.wrapper.AssociationSearchItemWrapper;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.gui.impl.page.admin.abstractrole.component.TaskAwareExecutor;
import com.evolveum.midpoint.schema.SchemaConstantsGenerated;
import com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition;
import com.evolveum.midpoint.schema.util.task.ActivityDefinitionBuilder;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.web.component.input.DurationWithOneElementPanel;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;

import com.evolveum.midpoint.web.component.dialog.ConfirmationPanel;
import com.evolveum.midpoint.xml.ns._public.model.scripting_3.*;

import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;

import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;

import jakarta.xml.bind.JAXBElement;
import org.apache.wicket.Component;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
Expand All @@ -65,7 +56,6 @@
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.GetOperationOptionsBuilder;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ObjectQueryUtil;
Expand All @@ -75,7 +65,6 @@
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.AjaxIconButton;
import com.evolveum.midpoint.web.component.dialog.ConfirmationPanel;
import com.evolveum.midpoint.web.component.input.DropDownChoicePanel;
import com.evolveum.midpoint.web.component.input.ResourceObjectTypeChoiceRenderer;
import com.evolveum.midpoint.web.component.util.SelectableBean;
Expand All @@ -89,8 +78,6 @@
import com.evolveum.wicket.chartjs.ChartConfiguration;
import com.evolveum.wicket.chartjs.ChartJsPanel;

import org.jetbrains.annotations.Nullable;

public abstract class ResourceObjectsPanel extends AbstractObjectMainPanel<ResourceType, ResourceDetailsModel> {

private static final Trace LOGGER = TraceManager.getTrace(ResourceObjectsPanel.class);
Expand Down Expand Up @@ -438,54 +425,77 @@ protected String getTaskName() {
}

private AjaxIconButton createReclassifyButton(String buttonId) {
AjaxIconButton reclassify = new AjaxIconButton(buttonId, Model.of("fa fa-rotate-right"),
createStringResource("ResourceCategorizedPanel.button.reclassify")) {

ReloadableButton reclassify = new ReloadableButton(
buttonId, getPageBase(), createStringResource("ResourceCategorizedPanel.button.reclassify")) {

@Override
public void onClick(AjaxRequestTarget target) {
IModel<String> confirmModel;
protected void refresh(AjaxRequestTarget target) {
target.add(getShadowTable());
}

confirmModel = getPageBase().createStringResource(
@Override
protected TaskAwareExecutor.Executable<String> getTaskExecutor() {
return createReclassifyTask();
}

@Override
protected boolean useConfirmationPopup() {
return true;
}

@Override
protected IModel<String> getConfirmMessage() {
return getPageBase().createStringResource(
"ResourceCategorizedPanel.button.reclassify.confirmation.objectClass",
getObjectClass() != null ? getObjectClass().getLocalPart() : null);

ConfirmationPanel confirmationPanel = new ConfirmationPanel(getPageBase().getMainPopupBodyId(), confirmModel) {
@Override
public void yesPerformed(AjaxRequestTarget target) {
createReclassifyTask(target);
getShadowTable().startRefreshing(target);
target.add(getShadowTable());
}
};
getPageBase().showMainPopup(confirmationPanel, target);
}
};

// AjaxIconButton reclassify = new AjaxIconButton(buttonId, Model.of("fa fa-rotate-right"),
// createStringResource("ResourceCategorizedPanel.button.reclassify")) {
//
// @Override
// public void onClick(AjaxRequestTarget target) {
// IModel<String> confirmModel;
//
// confirmModel = getPageBase().createStringResource(
// "ResourceCategorizedPanel.button.reclassify.confirmation.objectClass",
// getObjectClass() != null ? getObjectClass().getLocalPart() : null);
//
// ConfirmationPanel confirmationPanel = new ConfirmationPanel(getPageBase().getMainPopupBodyId(), confirmModel) {
// @Override
// public void yesPerformed(AjaxRequestTarget target) {
// createReclassifyTask(target);
// getShadowTable().startRefreshing(target);
// target.add(getShadowTable());
// }
// };
// getPageBase().showMainPopup(confirmationPanel, target);
// }
// };
reclassify.add(AttributeAppender.append("class", "btn btn-primary btn-sm mr-2"));
reclassify.setOutputMarkupId(true);
reclassify.showTitleAsLabel(true);
reclassify.add(new VisibleBehaviour(() -> getObjectClass() != null));
return reclassify;
}

private void createReclassifyTask(AjaxRequestTarget target) throws RestartResponseException {
getPageBase().taskAwareExecutor(target, OPERATION_RECLASSIFY_SHADOWS)
.runVoid((task, result) -> {
ResourceType resource = getObjectWrapperObject().asObjectable();
ResourceTaskCreator.forResource(resource, getPageBase())
.ofFlavor(SynchronizationTaskFlavor.IMPORT)
.withCoordinates(
getKind(),
getIntent(),
getObjectClass())
.withExecutionMode(ExecutionModeType.PREVIEW)
.withPredefinedConfiguration(PredefinedConfigurationType.DEVELOPMENT)
.withSubmissionOptions(
ActivitySubmissionOptions.create()
.withTaskTemplate(new TaskType()
.name("Reclassifying objects on " + resource.getName())
.cleanupAfterCompletion(XmlTypeConverter.createDuration("PT0S"))))
.submit(task, result);
});
private TaskAwareExecutor.Executable<String> createReclassifyTask() throws RestartResponseException {
return (task, result) -> {
ResourceType resource = getObjectWrapperObject().asObjectable();
return ResourceTaskCreator.forResource(resource, getPageBase())
.ofFlavor(SynchronizationTaskFlavor.IMPORT)
.withCoordinates(getObjectClass())
.withExecutionMode(ExecutionModeType.PREVIEW)
.withPredefinedConfiguration(PredefinedConfigurationType.DEVELOPMENT)
.withSubmissionOptions(
ActivitySubmissionOptions.create()
.withTaskTemplate(new TaskType()
.name("Reclassifying objects on " + resource.getName())
.cleanupAfterCompletion(XmlTypeConverter.createDuration("PT0S"))))
.submit(task, result);
};
}

private ResourceObjectTypeDefinitionType getSelectedObjectType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public ResourceTaskCreator withCoordinates(ShadowKindType kind, String intent, Q
return this;
}

public ResourceTaskCreator withCoordinates(QName objectClass) {
this.objectClass = objectClass;
return this;
}

public ResourceTaskCreator withExecutionMode(ExecutionModeType executionMode) {
this.executionMode = executionMode;
return this;
Expand Down

0 comments on commit 3999f95

Please sign in to comment.