Skip to content

Commit

Permalink
cleanup task - missing references configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Mar 28, 2024
1 parent 2ca11a0 commit 2430397
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private void publishNotification(

MidPointUtils.publishNotification(
getProject(), notificationKey, "Cleanup warning", msg, type,
new SeeObjectNotificationAction(file), new DownloadMissingNotificationAction(missingReferences));
new SeeObjectNotificationAction(file), new MissingReferencesAction(missingReferences));
}

private boolean onConfirmOptionalCleanup(CleanupEvent<Item<?, ?>> event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class DownloadMissingNotificationAction extends NotificationAction {
Expand All @@ -21,13 +20,6 @@ public DownloadMissingNotificationAction(@NotNull List<ObjectReferenceType> refe
this.references = references;
}

@Override
public void update(@NotNull AnActionEvent e) {
super.update(e);

e.getPresentation().setVisible(!references.isEmpty()); // todo fix, this doesn't work!
}

@Override
public void actionPerformed(AnActionEvent e, Notification notification) {
Project project = e.getProject();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.evolveum.midpoint.studio.impl;

import com.evolveum.midpoint.studio.impl.configuration.ObjectReferencesConfiguration;
import com.evolveum.midpoint.studio.ui.cleanup.MissingObjectRefsDialog;
import com.evolveum.midpoint.studio.util.ActionUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public class MissingReferencesAction extends NotificationAction {

private final List<ObjectReferenceType> data;

public MissingReferencesAction(@NotNull List<ObjectReferenceType> data) {
super("Fix missing objects...");

this.data = data;
}

@Override
public void update(@NotNull AnActionEvent e) {
super.update(e);

// todo fix, this doesn't work! it's not even called. same for download missing notification action
// e.getPresentation().setVisible(!references.isEmpty());
}

@Override
public void actionPerformed(AnActionEvent e, Notification notification) {
Project project = e.getProject();


// todo get settings and pass proper configuration part to dialog

MissingObjectRefsDialog dialog = new MissingObjectRefsDialog(project, List.of());
if (!dialog.showAndGet()) {
return;
}

List<ObjectReferenceType> references = createRefsForDownload(dialog.getData());
if (references.isEmpty()) {
return;
}

ActionUtils.runDownloadTask(project, references, false);
}

private List<ObjectReferenceType> createRefsForDownload(List<ObjectReferencesConfiguration> objects) {
return List.of(); // todo implement
}

@Override
public boolean isDumbAware() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

public enum DownloadActionConfiguration {

NEVER,

ALWAYS,

FILE_NOT_EXISTS,
OBJECT_NOT_AVAILABLE,
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ public class DecisionColumn extends DefaultColumnInfo<Object, Boolean> {

public DecisionColumn(String name, ReferenceDecisionConfiguration decision) {
super(name, o -> {
if (o == null) {
// todo root
}

return true; // todo fix
});

this.decision = decision;

setPreferredWidth(40);
setMinWidth(40);
setMaxWidth(40);
setPreferredWidth(80);
setMinWidth(80);
setMaxWidth(80);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.evolveum.midpoint.studio.ui.cleanup;

import com.evolveum.midpoint.studio.impl.configuration.ObjectReferencesConfiguration;
import com.evolveum.midpoint.studio.ui.MissingObjectRefsEditor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogPanel;
import com.intellij.openapi.ui.DialogWrapper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.List;

public class MissingObjectRefsDialog extends DialogWrapper {

private final MissingObjectRefsEditor editor;

private final DialogPanel panel;

public MissingObjectRefsDialog(@Nullable Project project, @NotNull List<ObjectReferencesConfiguration> objects) {
super(project);

editor = new MissingObjectRefsEditor(project, objects);
panel = editor.createComponent();

init();
}

@Override
protected @Nullable JComponent createCenterPanel() {
return panel;
}

public @NotNull List<ObjectReferencesConfiguration> getData() {
return List.of(); // todo implement
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.evolveum.midpoint.studio.ui.treetable.DefaultTreeTable;

public class MissingObjectsTable extends DefaultTreeTable<MissingObjectTableModel> {
public class MissingObjectRefsTable extends DefaultTreeTable<MissingObjectRefsTableModel> {

public MissingObjectsTable() {
super(new MissingObjectTableModel());
public MissingObjectRefsTable() {
super(new MissingObjectRefsTableModel());

setupComponent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
import java.util.Map;
import java.util.stream.Collectors;

public class MissingObjectTableModel extends DefaultTreeTableModel<List<ObjectReferencesConfiguration>> {
public class MissingObjectRefsTableModel extends DefaultTreeTableModel<List<ObjectReferencesConfiguration>> {

public static final List<ColumnInfo> COLUMNS = List.of(
new ReferenceColumn(),
new DecisionColumn("Download", ReferenceDecisionConfiguration.DOWNLOAD),
new DecisionColumn("Ignore", ReferenceDecisionConfiguration.IGNORE)
);

public MissingObjectTableModel() {
public MissingObjectRefsTableModel() {
super(COLUMNS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public ReferenceColumn() {
}

if (o instanceof ObjectTypes type) {
return StudioLocalization.get().translateEnum(type, "MissingObjectTableModel.unknown");
return StudioLocalization.get().translateEnum(type);
}

if (o instanceof NamedItem ref) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.evolveum.midpoint.studio.ui

import com.evolveum.midpoint.studio.impl.configuration.ObjectReferencesConfiguration
import com.evolveum.midpoint.studio.ui.cleanup.MissingObjectRefsTable
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogPanel
import com.intellij.ui.components.JBScrollPane
import com.intellij.ui.dsl.builder.Align
import com.intellij.ui.dsl.builder.panel

class MissingObjectRefsEditor(val project: Project, val objects: List<ObjectReferencesConfiguration>) {

private val table: MissingObjectRefsTable

init {
table = MissingObjectRefsTable()
table.tableModel.data = objects
}

fun createComponent(): DialogPanel {
return panel {
// todo implement
row {
cell(JBScrollPane(table))
.align(Align.FILL)
}
.resizableRow()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.evolveum.midpoint.studio.ui.configuration

import com.evolveum.midpoint.studio.impl.configuration.*
import com.evolveum.midpoint.studio.ui.cleanup.MissingObjectsTable
import com.evolveum.midpoint.studio.ui.MissingObjectRefsEditor
import com.evolveum.midpoint.studio.ui.cleanup.MissingObjectRefsTable
import com.evolveum.midpoint.studio.util.StudioLocalization
import com.evolveum.midpoint.studio.util.StudioLocalization.message
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType
Expand All @@ -19,7 +20,7 @@ open class MissingReferencesConfigurable(val project: Project) :

private val configuration: MissingReferencesConfiguration

private val table: MissingObjectsTable
private val editor: MissingObjectRefsEditor

init {
// todo remove, obtain it from cleanup service, implement apply/reset
Expand All @@ -37,25 +38,24 @@ open class MissingReferencesConfigurable(val project: Project) :

configuration.objects.add(obj)

table = MissingObjectsTable()
table.tableModel.data = configuration.objects
editor = MissingObjectRefsEditor(project, configuration.objects)
}

override fun createPanel(): DialogPanel {
return panel {
groupRowsRange(message("MissingReferencesConfigurable.missingObjects")) {
row {
cell(table)
cell(editor.createComponent())
.align(Align.FILL)
}
.resizableRow()
.rowComment(message("MissingReferencesConfigurable.missingObjects.comment"))
row(message("MissingReferencesConfigurable.action")) {
row(message("MissingReferencesConfigurable.defaultAction")) {
comboBox(
listOf(
null,
DownloadActionConfiguration.NEVER,
DownloadActionConfiguration.ALWAYS,
DownloadActionConfiguration.FILE_NOT_EXISTS
DownloadActionConfiguration.OBJECT_NOT_AVAILABLE
),
SimpleListCellRenderer.create(
StudioLocalization.get().translate("DownloadActionConfiguration.null")
Expand All @@ -66,6 +66,7 @@ open class MissingReferencesConfigurable(val project: Project) :
{ configuration.action = it }
)
}
.rowComment(message("MissingReferencesConfigurable.defaultAction.comment"))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ MidPointConfigurable.download.limit=Download limit:
MidPointStartupActivity.checkCredentials.title=Environment credentials warning
MidPointStartupActivity.checkCredentials.msg=Project contains environments without username and/or password defined.
MidPointStartupActivity.checkCredentials.openConfiguration=Open configuration
MidPointStartupActivity.checkCredentials.dontAsk=Don't ask again
MidPointStartupActivity.checkCredentials.dontAsk=Don't show again
midpoint.new.project=Generating MidPoint Maven project
CleanupConfigurable.title=Objects cleanup
CleanupConfigurable.cleanupPaths.comment=Table allows to configure how cleanup operation should process item paths.
Expand Down Expand Up @@ -81,8 +81,9 @@ MissingReferencesConfigurable.title=Missing objects
MissingReferencesConfigurable.missingObjects=Missing objects
MissingReferencesConfigurable.missingObjects.comment=Table allows to configure how missing object references should be handled when executing cleanup file.
MissingObjectTableModel.all=All
MissingObjectTableModel.unknown=Unknown
MissingReferencesConfigurable.action=Download:
MissingReferencesConfigurable.defaultAction=Default download action:
MissingReferencesConfigurable.defaultAction.comment=Default download action when object can't be resolved locally.
DownloadActionConfiguration.null=Undefined
DownloadActionConfiguration.ALWAYS=Always
DownloadActionConfiguration.FILE_NOT_EXISTS=When not available
DownloadActionConfiguration.OBJECT_NOT_AVAILABLE=Object not available
DownloadActionConfiguration.NEVER=Never

0 comments on commit 2430397

Please sign in to comment.