use of com.evolveum.midpoint.studio.impl.Environment in project midpoint-studio by Evolveum.
the class EncryptedPropertiesSerializer method serialize.
public void serialize(List<EncryptedProperty> properties, File file) throws IOException {
if (file.exists()) {
file.delete();
}
file.createNewFile();
Properties props = new Properties() {
/**
* not very nice way to make properties sorted when stored to file
*/
@Override
public Set<Map.Entry<Object, Object>> entrySet() {
Set<Map.Entry<Object, Object>> set = new TreeSet<>((o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare((String) o1.getKey(), (String) o2.getKey()));
set.addAll(super.entrySet());
return set;
}
};
int i = 0;
for (EncryptedProperty property : properties) {
String prefix = "property." + i + ".";
putProperty(props, prefix + "key", property.getKey());
putProperty(props, prefix + "value", property.getValue());
putProperty(props, prefix + "description", property.getDescription());
if (property.getEnvironment() != null) {
Environment env = environmentService.get(property.getEnvironment());
if (env != null) {
putProperty(props, prefix + "environment", env.getName());
}
}
i++;
}
try (Writer w = new FileWriter(file, StandardCharsets.UTF_8)) {
props.store(w, null);
}
}
use of com.evolveum.midpoint.studio.impl.Environment in project midpoint-studio by Evolveum.
the class DiffRemoteTask method processFiles.
private void processFiles(ProgressIndicator indicator, List<VirtualFile> files) {
Environment env = getEnvironment();
int skipped = 0;
int missing = 0;
AtomicInteger diffed = new AtomicInteger(0);
AtomicInteger failed = new AtomicInteger(0);
int current = 0;
for (VirtualFile file : files) {
ProgressManager.checkCanceled();
current++;
indicator.setFraction((double) current / files.size());
List<MidPointObject> objects;
try {
objects = loadObjectsFromFile(file);
} catch (Exception ex) {
failed.incrementAndGet();
midPointService.printToConsole(env, DiffRemoteTask.class, "Couldn't load objects from file " + file.getPath(), ex);
continue;
}
if (objects.isEmpty()) {
skipped++;
midPointService.printToConsole(env, DiffRemoteTask.class, "Skipped file " + file.getPath() + " no objects found (parsed).");
continue;
}
Map<String, MidPointObject> remoteObjects = new HashMap<>();
for (MidPointObject object : objects) {
ProgressManager.checkCanceled();
try {
MidPointObject newObject = client.get(object.getType().getClassDefinition(), object.getOid(), new SearchOptions().raw(true));
if (newObject == null) {
missing++;
midPointService.printToConsole(env, DiffRemoteTask.class, "Couldn't find object " + object.getType().getTypeQName().getLocalPart() + "(" + object.getOid() + ").");
continue;
}
MidPointObject obj = MidPointObject.copy(object);
obj.setContent(newObject.getContent());
remoteObjects.put(obj.getOid(), obj);
diffed.incrementAndGet();
} catch (Exception ex) {
failed.incrementAndGet();
midPointService.printToConsole(env, DiffRemoteTask.class, "Error getting object" + object.getType().getTypeQName().getLocalPart() + "(" + object.getOid() + ")", ex);
}
}
RunnableUtils.runWriteActionAndWait(() -> {
Writer writer = null;
VirtualFile vf = null;
try {
List<String> deltas = new ArrayList<>();
for (MidPointObject local : objects) {
MidPointObject remote = remoteObjects.get(local.getOid());
if (remote == null) {
continue;
}
deltas.add(createDiffXml(local, file, LocationType.LOCAL, remote, null, LocationType.REMOTE));
}
vf = createScratchAndWriteDiff(deltas);
} catch (Exception ex) {
failed.incrementAndGet();
midPointService.printToConsole(env, DiffRemoteTask.class, "Failed to compare file " + file.getPath(), ex);
} finally {
IOUtils.closeQuietly(writer);
}
MidPointUtils.openFile(getProject(), vf);
});
}
NotificationType type = missing > 0 || failed.get() > 0 || skipped > 0 ? NotificationType.WARNING : NotificationType.INFORMATION;
StringBuilder msg = new StringBuilder();
msg.append("Compared ").append(diffed.get()).append(" objects<br/>");
msg.append("Missing ").append(missing).append(" objects<br/>");
msg.append("Failed to compare ").append(failed.get()).append(" objects<br/>");
msg.append("Skipped ").append(skipped).append(" files");
MidPointUtils.publishNotification(getProject(), NOTIFICATION_KEY, TITLE, msg.toString(), type);
}
use of com.evolveum.midpoint.studio.impl.Environment in project midpoint-studio by Evolveum.
the class DownloadSelectedTypesTask method doRun.
@Override
protected void doRun(ProgressIndicator indicator) {
super.doRun(indicator);
MidPointSettings settings = midPointService.getSettings();
if (settings.getTypesToDownloadLimit() == 0 && settings.getDownloadTypesInclude().isEmpty() && settings.getDownloadTypesExclude().isEmpty()) {
// probably
MidPointSettings defaults = MidPointSettings.createDefaultSettings();
settings.setDownloadTypesInclude(defaults.getDownloadTypesInclude());
settings.setDownloadTypesExclude(defaults.getDownloadTypesExclude());
settings.setTypesToDownloadLimit(defaults.getTypesToDownloadLimit());
midPointService.settingsUpdated();
}
if (settings.getTypesToDownloadLimit() <= 0) {
MidPointUtils.publishNotification(getProject(), NOTIFICATION_KEY, "Download Selected Types", "Download limit set to zero. Done.", NotificationType.WARNING);
return;
}
Environment environment = getEnvironment();
PrismContext ctx = ServiceFactory.DEFAULT_PRISM_CONTEXT;
QueryFactory qf = ctx.queryFactory();
ObjectPaging paging = qf.createPaging(0, settings.getTypesToDownloadLimit(), ctx.path(ObjectType.F_NAME), OrderDirection.ASCENDING);
ObjectQuery query = qf.createQuery(null, paging);
List<ObjectTypes> typesToDownload = determineTypesToDownload(settings);
for (ObjectTypes type : typesToDownload) {
try {
DownloadTask dt = new DownloadTask(event, null, type, query, false, false, true);
dt.setEnvironment(environment);
dt.setOpenAfterDownload(false);
dt.download(indicator);
} catch (Exception ex) {
midPointService.printToConsole(environment, getClass(), "Couldn't download objects of type '" + type.getValue() + "'. Reason: " + ex.getMessage());
}
}
}
use of com.evolveum.midpoint.studio.impl.Environment in project midpoint-studio by Evolveum.
the class GeneratorTask method writeContent.
private void writeContent(ProgressIndicator indicator, String content) {
updateIndicator(indicator, "Content created, writing to file");
Project project = getProject();
Environment env = getEnvironment();
RunnableUtils.runWriteActionAndWait(() -> {
VirtualFile file = null;
Writer out = null;
try {
file = FileUtils.createScratchFile(project, env);
out = new BufferedWriter(new OutputStreamWriter(file.getOutputStream(GeneratorTask.this), file.getCharset()));
IOUtils.write(content, out);
FileEditorManager fem = FileEditorManager.getInstance(project);
fem.openFile(file, true, true);
} catch (IOException ex) {
MidPointUtils.publishExceptionNotification(project, env, GeneratorTask.class, NOTIFICATION_KEY, "Couldn't store generated content to file " + (file != null ? file.getName() : "[null]"), ex);
} finally {
IOUtils.closeQuietly(out);
}
});
updateIndicator(indicator, "File saved");
}
use of com.evolveum.midpoint.studio.impl.Environment in project midpoint-studio by Evolveum.
the class GeneratorTask method doRun.
@Override
protected void doRun(ProgressIndicator indicator) {
super.doRun(indicator);
updateIndicator(indicator, "Starting generator");
Project project = getProject();
Environment env = getEnvironment();
String content = generator.generate(project, objects, options);
if (options.isUseActivities()) {
try {
content = MidPointUtils.upgradeTaskToUseActivities(content);
} catch (Exception ex) {
midPointService.printToConsole(env, getClass(), "Couldn't update generate task to use activities. Reason: " + ex.getMessage());
MidPointUtils.publishExceptionNotification(project, env, GeneratorTask.class, NOTIFICATION_KEY, "Couldn't update generate task to use activities", ex);
}
}
if (!execute) {
writeContent(indicator, content);
} else {
uploadContent(indicator, content);
}
}
Aggregations