use of com.evolveum.midpoint.studio.client.MidPointObject 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