Skip to content

Commit

Permalink
cleanup path configurable, better converters for configuration serial…
Browse files Browse the repository at this point in the history
…ization
  • Loading branch information
1azyman committed Nov 29, 2023
1 parent 57f0fe9 commit 657a48e
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.evolveum.midpoint.studio.impl;

import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.studio.util.ObjectTypesConverter;
import com.evolveum.midpoint.studio.util.ObjectTypesListConverter;
import com.intellij.util.xmlb.annotations.OptionTag;

import java.io.Serializable;
Expand Down Expand Up @@ -45,10 +45,10 @@ public class MidPointSettings implements Serializable {

private boolean ignoreMissingKeys;

@OptionTag(converter = ObjectTypesConverter.class)
@OptionTag(converter = ObjectTypesListConverter.class)
private List<ObjectTypes> downloadTypesInclude;

@OptionTag(converter = ObjectTypesConverter.class)
@OptionTag(converter = ObjectTypesListConverter.class)
private List<ObjectTypes> downloadTypesExclude;

private int typesToDownloadLimit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.evolveum.midpoint.studio.impl.configuration;

import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.studio.util.CleanupPathActionConverter;
import com.evolveum.midpoint.studio.util.ObjectTypesConverter;
import com.intellij.util.xmlb.annotations.OptionTag;
import org.jetbrains.annotations.NotNull;

import java.io.Serializable;
Expand All @@ -9,10 +12,13 @@

public class CleanupPath implements Serializable, Comparable<CleanupPath> {

@OptionTag(converter = ObjectTypesConverter.class)
private ObjectTypes type;

private String path;


@OptionTag(converter = CleanupPathActionConverter.class)
private CleanupPathAction action;

@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.evolveum.midpoint.studio.impl.configuration;

import java.util.Arrays;

public enum CleanupPathAction {

REMOVE("remove"),
Expand All @@ -17,4 +19,15 @@ public enum CleanupPathAction {
public String value() {
return value;
}

public static CleanupPathAction getState(String value) {
if (value == null) {
return null;
}

return Arrays.stream(values())
.filter(s -> value.equals(s.value()))
.findFirst()
.orElse(null);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.evolveum.midpoint.studio.ui;

import com.evolveum.midpoint.studio.impl.MidPointSettings;
import com.evolveum.midpoint.studio.util.ObjectTypesConverter;
import com.evolveum.midpoint.studio.util.ObjectTypesListConverter;
import com.intellij.openapi.options.ConfigurationException;
import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -43,7 +43,7 @@ private void initInputFields() {
logRestCommunication.setSelected(settings.isPrintRestCommunicationToConsole());
restClientTimeout.setText(Integer.toString(settings.getRestResponseTimeout()));

ObjectTypesConverter converter = new ObjectTypesConverter();
ObjectTypesListConverter converter = new ObjectTypesListConverter();
typesIncluded.setText(converter.toString(settings.getDownloadTypesInclude()));
typesExcluded.setText(converter.toString(settings.getDownloadTypesExclude()));

Expand All @@ -70,7 +70,7 @@ public MidPointSettings getSettings() {
settings.setRestResponseTimeout(Integer.parseInt(restClientTimeout.getText()));
}

ObjectTypesConverter converter = new ObjectTypesConverter();
ObjectTypesListConverter converter = new ObjectTypesListConverter();
settings.setDownloadTypesInclude(converter.fromString(typesIncluded.getText()));
settings.setDownloadTypesExclude(converter.fromString(typesExcluded.getText()));

Expand Down Expand Up @@ -104,7 +104,7 @@ private void validateInteger(String number, String message) throws Configuration

private void validateTypes(String types, String message) throws ConfigurationException {
try {
ObjectTypesConverter.fromString(types, false);
ObjectTypesListConverter.fromString(types, false);
} catch (RuntimeException ex) {
throw new ConfigurationException(message + ex.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.evolveum.midpoint.studio.impl.configuration.CleanupPath;
import com.intellij.openapi.project.Project;
import com.intellij.ui.AddEditRemovePanel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
Expand All @@ -11,7 +12,7 @@ public class CleanupPathsPanel extends AddEditRemovePanel<CleanupPath> {

private final Project project;

public CleanupPathsPanel(Project project) {
public CleanupPathsPanel(@NotNull Project project) {
super(new CleanupPathsModel(), new ArrayList<>(), null);

this.project = project;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.evolveum.midpoint.studio.util;

import com.evolveum.midpoint.studio.impl.configuration.CleanupPathAction;
import com.intellij.util.xmlb.Converter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class CleanupPathActionConverter extends Converter<CleanupPathAction> {

@Override
public @Nullable CleanupPathAction fromString(@NotNull String value) {
return CleanupPathAction.getState(value);
}

@Override
public @Nullable String toString(@NotNull CleanupPathAction value) {
return value.value();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,26 @@

import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.intellij.util.xmlb.Converter;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

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

/**
* Created by Viliam Repan (lazyman).
*/
public class ObjectTypesConverter extends Converter<List<ObjectTypes>> {
public class ObjectTypesConverter extends Converter<ObjectTypes> {

public static @Nullable List<ObjectTypes> fromString(@NotNull String value, boolean ignoreWrongValue) {
if (value == null || value.isEmpty()) {
return new ArrayList<>();
}

List<ObjectTypes> result = new ArrayList<>();

String[] types = value.split(",");
for (String type : types) {
try {
ObjectTypes ot = ObjectTypes.getObjectType(type);
if (ot != null) {
result.add(ot);
}
} catch (RuntimeException ex) {
if (!ignoreWrongValue) {
throw ex;
}
@Override
public @Nullable ObjectTypes fromString(@NotNull String value) {
for (ObjectTypes type : ObjectTypes.values()) {
if (Objects.equals(value, type.getValue())) {
return type;
}
}

return result;
}

@Override
public @Nullable List<ObjectTypes> fromString(@NotNull String value) {
return fromString(value, true);
return null;
}

@Override
public @Nullable String toString(@NotNull List<ObjectTypes> value) {
if (value == null || value.isEmpty()) {
return null;
}

List<String> types = new ArrayList<>();
value.forEach(v -> types.add(v.getValue()));

return StringUtils.join(types, ",");
public @Nullable String toString(@NotNull ObjectTypes value) {
return value.getValue();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.evolveum.midpoint.studio.util;

import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.intellij.util.xmlb.Converter;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

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

/**
* Created by Viliam Repan (lazyman).
*/
public class ObjectTypesListConverter extends Converter<List<ObjectTypes>> {

public static @Nullable List<ObjectTypes> fromString(@NotNull String value, boolean ignoreWrongValue) {
if (value == null || value.isEmpty()) {
return new ArrayList<>();
}

List<ObjectTypes> result = new ArrayList<>();

String[] types = value.split(",");
for (String type : types) {
try {
ObjectTypes ot = ObjectTypes.getObjectType(type);
if (ot != null) {
result.add(ot);
}
} catch (RuntimeException ex) {
if (!ignoreWrongValue) {
throw ex;
}
}
}

return result;
}

@Override
public @Nullable List<ObjectTypes> fromString(@NotNull String value) {
return fromString(value, true);
}

@Override
public @Nullable String toString(@NotNull List<ObjectTypes> value) {
if (value == null || value.isEmpty()) {
return null;
}

List<String> types = new ArrayList<>();
value.forEach(v -> types.add(v.getValue()));

return StringUtils.join(types, ",");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import com.evolveum.midpoint.studio.util.StudioBundle
import com.intellij.openapi.options.BoundSearchableConfigurable
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogPanel
import com.intellij.ui.dsl.builder.AlignX
import com.intellij.ui.dsl.builder.AlignY
import com.intellij.ui.dsl.builder.Align
import com.intellij.ui.dsl.builder.panel
import java.util.*
import java.util.stream.Collectors
import kotlin.streams.toList

class CleanupConfigurable(val project: Project) :
BoundSearchableConfigurable(StudioBundle.message("CleanupConfigurable.title"), "") {
Expand All @@ -25,7 +23,8 @@ class CleanupConfigurable(val project: Project) :

override fun reset() {
val list = CleanupService.getInstance(project).settings.cleanupPaths.stream().map { p -> p.copy() }.collect(
Collectors.toList())
Collectors.toList()
)

cleanupPathsPanel.data = list
}
Expand All @@ -40,8 +39,7 @@ class CleanupConfigurable(val project: Project) :
return panel {
row() {
cell(cleanupPathsPanel)
.align(AlignX.FILL)
.align(AlignY.FILL)
.align(Align.FILL)
}
.resizableRow()
.rowComment(StudioBundle.message("CleanupConfigurable.cleanupPaths.comment"))
Expand Down

0 comments on commit 657a48e

Please sign in to comment.