Skip to content

Commit

Permalink
misc fixes and improvments (download missing objects)
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Apr 16, 2024
1 parent 62ad58b commit 9a839ca
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package com.evolveum.midpoint.studio.action;

import com.evolveum.midpoint.studio.ui.configuration.EnvironmentsConfigurable;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;

/**
* Created by Viliam Repan (lazyman).
*/
public class ShowEnvironmentConfigurationAction extends AnAction {
public class ShowConfigurationAction extends AnAction {

private final Class<? extends Configurable> configurable;

public ShowConfigurationAction(@NotNull Class<? extends Configurable> configurable) {
this.configurable = configurable;
}

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Expand All @@ -19,7 +25,7 @@ public void actionPerformed(@NotNull AnActionEvent e) {
return;
}

ShowSettingsUtil.getInstance().showSettingsDialog(project, EnvironmentsConfigurable.class);
ShowSettingsUtil.getInstance().showSettingsDialog(project, configurable);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class DownloadMissingNotificationAction extends NotificationAction {

private final Project project;

private final List<ObjectReferenceType> references;
private final List<MissingRefObject> data;

/**
* @param data list of missing references from cleanup task. It will be used to compute
Expand All @@ -33,12 +33,13 @@ public DownloadMissingNotificationAction(
super(TEXT);

this.project = project;

this.references = MissingRefUtils.computeDownloadOnly(project, data);
this.data = data;
}

@Override
public void actionPerformed(AnActionEvent e, Notification notification) {
List<ObjectReferenceType> references = MissingRefUtils.computeDownloadOnly(project, data);

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

Expand All @@ -48,6 +49,6 @@ public boolean isDumbAware() {
}

public boolean isVisible() {
return !references.isEmpty();
return !data.isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.evolveum.midpoint.studio.impl;

import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.studio.action.ShowEnvironmentConfigurationAction;
import com.evolveum.midpoint.studio.action.ShowConfigurationAction;
import com.evolveum.midpoint.studio.impl.configuration.MidPointService;
import com.evolveum.midpoint.studio.impl.ide.MavenManagerListener;
import com.evolveum.midpoint.studio.impl.lang.codeInsight.NonexistentNamespaceUriCompletionProvider;
import com.evolveum.midpoint.studio.util.StudioLocalization;
import com.evolveum.midpoint.studio.ui.configuration.CredentialsConfigurable;
import com.evolveum.midpoint.studio.ui.configuration.EnvironmentsConfigurable;
import com.evolveum.midpoint.studio.util.MidPointUtils;
import com.evolveum.midpoint.studio.util.RunnableUtils;
import com.evolveum.midpoint.studio.util.StudioLocalization;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.codeInspection.ex.ToolsImpl;
import com.intellij.facet.FacetManager;
Expand Down Expand Up @@ -161,7 +163,7 @@ private void validateStudioConfiguration(Project project) {

MidPointUtils.publishNotification(project, NOTIFICATION_KEY,
StudioLocalization.message("MidPointStartupActivity.checkFacet.title"),
StudioLocalization.message("MidPointStartupActivity.checkFacet.msg", module.getName()),
StudioLocalization.message("MidPointStartupActivity.checkFacet.msg", module.getName()), // todo this ignores parameter???
NotificationType.INFORMATION,
NotificationAction.createExpiring(StudioLocalization.message("MidPointStartupActivity.checkFacet.addFacet"), (evt, notification) -> addFacetPerformed(module)),
NotificationAction.createExpiring(StudioLocalization.message("MidPointStartupActivity.checkFacet.dontAsk"), (evt, notification) -> dontAskAboutMidpointConfigurationAgainPerformed(project)));
Expand Down Expand Up @@ -198,10 +200,32 @@ private void validateCredentialsConfiguration(Module module) {
}

// todo check whether there is credentials.kdbx and master password is available and valid
validateProjectCredentialsConfiguration(project);

validateEnvironmentsConfiguration(module);
}

private void validateProjectCredentialsConfiguration(Project project) {
EncryptionService service = EncryptionService.getInstance(project);
EncryptionService.StatusMessage status = service.getStatus();

if (status.getStatus() == EncryptionService.Status.OK) {
return;
}

MidPointUtils.publishNotification(project, NOTIFICATION_KEY,
StudioLocalization.message("MidPointStartupActivity.checkProjectCredentials.title"),
StudioLocalization.message(
"MidPointStartupActivity.checkProjectCredentials.msg", status.getMessage()),
NotificationType.INFORMATION,
NotificationAction.createExpiring(
StudioLocalization.message("MidPointStartupActivity.checkProjectCredentials.openConfiguration"),
(evt, notification) -> new ShowConfigurationAction(CredentialsConfigurable.class).actionPerformed(evt)),
NotificationAction.createExpiring(
StudioLocalization.message("MidPointStartupActivity.checkProjectCredentials.dontAsk"),
(evt, notification) -> dontAskAboutCredentialsAgainPerformed(project)));
}

private void validateEnvironmentsConfiguration(Module module) {
Project project = module.getProject();

Expand All @@ -220,15 +244,15 @@ private void validateEnvironmentsConfiguration(Module module) {
}

MidPointUtils.publishNotification(project, NOTIFICATION_KEY,
StudioLocalization.message("MidPointStartupActivity.checkCredentials.title"),
StudioLocalization.message("MidPointStartupActivity.checkCredentials.msg", module.getName()),
StudioLocalization.message("MidPointStartupActivity.checkEnvironmentCredentials.title"),
StudioLocalization.message("MidPointStartupActivity.checkEnvironmentCredentials.msg", module.getName()),
NotificationType.INFORMATION,
NotificationAction.createExpiring(StudioLocalization.message("MidPointStartupActivity.checkCredentials.openConfiguration"), (evt, notification) -> openEnvironmentsConfiguration(evt)),
NotificationAction.createExpiring(StudioLocalization.message("MidPointStartupActivity.checkCredentials.dontAsk"), (evt, notification) -> dontAskAboutCredentialsAgainPerformed(project)));
}

private void openEnvironmentsConfiguration(AnActionEvent evt) {
new ShowEnvironmentConfigurationAction().actionPerformed(evt);
NotificationAction.createExpiring(
StudioLocalization.message("MidPointStartupActivity.checkCredentials.openConfiguration"),
(evt, notification) -> new ShowConfigurationAction(EnvironmentsConfigurable.class).actionPerformed(evt)),
NotificationAction.createExpiring(
StudioLocalization.message("MidPointStartupActivity.checkCredentials.dontAsk"),
(evt, notification) -> dontAskAboutCredentialsAgainPerformed(project)));
}

private void dontAskAboutCredentialsAgainPerformed(Project project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public static void runDownloadTask(@NotNull Project project, List<ObjectReferenc
ObjectTypes.getObjectTypeFromTypeQName(ref.getType())))
.toList();

if (objectRefs.isEmpty()) {
MidPointUtils.publishNotification(
project, "Download missing", "Information", "No references to download.", NotificationType.INFORMATION);
}

DownloadTask task = new DownloadTask(project, objectRefs, null, null, showOnly, true, false);
task.setEnvironment(env);
task.setOpenAfterDownload(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
/**
* Service that simplifies localization of MidPoint related keys.
* <p>
* todo create singleton from this instead of service!
* todo this should probably also implement {@link com.evolveum.midpoint.common.LocalizationService}
*/
public class StudioLocalization {
Expand Down Expand Up @@ -87,11 +86,20 @@ public String translate(String key, String defaultValue) {
return defaultValue;
}

public String translate(String key, String defaultValue, Object[] params) {
String msg = translate(key, defaultValue);
if (msg == null) {
msg = defaultValue;
}

return String.format(msg, params);
}

@NotNull
public static String message(@NotNull
@PropertyKey(resourceBundle = "messages.MidPointStudio")
String key, Object... params) {
String value = get().translate(key);
String value = get().translate(key, key, params);
return value != null ? value : key;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MidPointStartupActivity.checkFacet.title=Found MidPoint Studio configuration
MidPointStartupActivity.checkFacet.msg=Do you want to add MidPoint Studio facet to module {0}?
MidPointStartupActivity.checkFacet.msg=Do you want to add MidPoint Studio facet to module %s?
MidPointStartupActivity.checkFacet.addFacet=Add facet
MidPointStartupActivity.checkFacet.dontAsk=Don't ask again
ComboEnvironments.noneSelected=None Selected
Expand All @@ -23,10 +23,14 @@ MidPointConfigurable.download.title=Types to Download
MidPointConfigurable.download.include=Include:
MidPointConfigurable.download.exclude=Exclude:
MidPointConfigurable.download.limit=Download limit:
MidPointStartupActivity.checkCredentials.title=Environment credentials warning
MidPointStartupActivity.checkCredentials.msg=Project contains environments without username and/or password defined.
MidPointStartupActivity.checkEnvironmentCredentials.title=Environment credentials warning
MidPointStartupActivity.checkEnvironmentCredentials.msg=Project contains environments without username and/or password defined.
MidPointStartupActivity.checkCredentials.openConfiguration=Open configuration
MidPointStartupActivity.checkCredentials.dontAsk=Don't show again
MidPointStartupActivity.checkProjectCredentials.title=Project credentials warning
MidPointStartupActivity.checkProjectCredentials.msg=Project credentials not configured properly, reason: %s
MidPointStartupActivity.checkProjectCredentials.openConfiguration=Open configuration
MidPointStartupActivity.checkProjectCredentials.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

0 comments on commit 9a839ca

Please sign in to comment.