use of com.evolveum.midpoint.studio.impl.SearchOptions 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.SearchOptions in project midpoint-studio by Evolveum.
the class DownloadTask method downloadByOid.
private void downloadByOid() {
List<VirtualFile> files = new ArrayList<>();
for (Pair<String, ObjectTypes> pair : oids) {
try {
LOG.debug("Downloading " + pair);
MidPointObject obj = client.get(pair.getSecond().getClassDefinition(), pair.getFirst(), new SearchOptions().raw(raw));
if (obj == null) {
continue;
}
LOG.debug("Storing file");
RunnableUtils.runWriteActionAndWait(() -> {
VirtualFile file = saveFile(obj);
if (file != null) {
files.add(file);
}
});
LOG.debug("File saved");
} catch (Exception ex) {
MidPointUtils.publishExceptionNotification(getProject(), getEnvironment(), DownloadTask.class, NOTIFICATION_KEY, "Exception occurred when getting object " + pair.getFirst() + " (" + pair.getSecond().getTypeQName().getLocalPart() + ")", ex);
}
}
if (!files.isEmpty() && openAfterDownload) {
ApplicationManager.getApplication().invokeAndWait(() -> MidPointUtils.openFile(getProject(), files.get(0)));
}
}
use of com.evolveum.midpoint.studio.impl.SearchOptions in project midpoint-studio by Evolveum.
the class DownloadTask method showByOid.
private void showByOid(Writer out) {
for (Pair<String, ObjectTypes> oid : oids) {
try {
MidPointObject object = client.get(oid.getSecond().getClassDefinition(), oid.getFirst(), new SearchOptions().raw(raw));
if (object == null) {
continue;
}
String content = oids.size() > 1 ? MidPointUtils.updateObjectRootElementToObject(object.getContent()) : object.getContent();
IOUtils.write(content, out);
} catch (Exception ex) {
MidPointUtils.publishExceptionNotification(getProject(), getEnvironment(), DownloadTask.class, NOTIFICATION_KEY, "Exception occurred when getting object " + oid.getFirst() + " (" + oid.getSecond().getTypeQName().getLocalPart() + ")", ex);
}
}
}
use of com.evolveum.midpoint.studio.impl.SearchOptions in project midpoint-studio by Evolveum.
the class SetLoggerTask method doRun.
@Override
protected void doRun(ProgressIndicator indicator) {
super.doRun(indicator);
indicator.setIndeterminate(false);
List<ClassLoggerConfigurationType> newLoggers = buildClassLoggers();
if (newLoggers == null || newLoggers.isEmpty()) {
noChangeNeeded();
return;
}
Environment env = getEnvironment();
LOG.debug("Downloading system configuration");
PrismObject<SystemConfigurationType> configPrism;
try {
MidPointObject object = client.get(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), new SearchOptions());
if (object == null) {
return;
}
configPrism = (PrismObject) client.parseObject(object.getContent());
indicator.setFraction(0.5);
} catch (Exception ex) {
MidPointUtils.publishException(getProject(), env, getClass(), NOTIFICATION_KEY, "Couldn't download and parse system configuration", ex);
return;
}
LOG.debug("Updating logging configuration");
SystemConfigurationType config = configPrism.asObjectable();
LoggingConfigurationType logging = config.getLogging();
if (logging == null) {
logging = new LoggingConfigurationType();
config.setLogging(logging);
}
List<ClassLoggerConfigurationType> existing = logging.getClassLogger();
Map<String, ClassLoggerConfigurationType> existingMap = existing.stream().collect(Collectors.toMap(o -> o.getPackage(), o -> o, (a, b) -> a));
boolean changed = false;
for (ClassLoggerConfigurationType cl : newLoggers) {
ClassLoggerConfigurationType existingLogger = existingMap.get(cl.getPackage());
if (existingLogger == null) {
LOG.debug("Adding new class logger ", cl.getPackage(), " with level ", cl.getLevel());
existing.add(cl);
changed = true;
} else {
if (existingLogger.getLevel() != cl.getLevel()) {
LOG.debug("Updating class logger ", existingLogger.getPackage(), " with level ", cl.getLevel());
existingLogger.setLevel(cl.getLevel());
changed = true;
}
}
}
if (!changed) {
noChangeNeeded();
indicator.setFraction(1);
return;
}
LOG.debug("Uploading system configuration");
try {
UploadResponse resp = client.upload(configPrism, Arrays.asList(ModelExecuteOptionsType.F_OVERWRITE.getLocalPart()));
OperationResult result = resp.getResult();
if (result != null && !result.isSuccess()) {
String msg = "Upload status of system configuration was " + result.getStatus();
midPointService.printToConsole(env, getClass(), msg);
MidPointUtils.publishNotification(getProject(), NOTIFICATION_KEY, "Warning", msg, NotificationType.WARNING, new ShowResultNotificationAction(result));
} else {
midPointService.printToConsole(env, getClass(), "System configuration uploaded");
}
indicator.setFraction(1);
} catch (Exception ex) {
MidPointUtils.publishException(getProject(), env, getClass(), NOTIFICATION_KEY, "Exception occurred during system configuration upload", ex);
}
}
Aggregations