use of com.evolveum.midpoint.studio.client.MidPointObject in project midpoint-studio by Evolveum.
the class CleanupFileTask method processObject.
@Override
public ProcessObjectResult processObject(MidPointObject object) throws Exception {
String newContent = cleanupObject(object);
MidPointObject newObject = MidPointObject.copy(object);
newObject.setContent(newContent);
return new ProcessObjectResult(null).object(newObject);
}
use of com.evolveum.midpoint.studio.client.MidPointObject in project midpoint-studio by Evolveum.
the class DiffLocalTask method doRun.
@Override
protected void doRun(ProgressIndicator indicator) {
super.doRun(indicator);
VirtualFile[] selectedFiles = ApplicationManager.getApplication().runReadAction((Computable<VirtualFile[]>) () -> event.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY));
List<VirtualFile> toProcess = MidPointUtils.filterXmlFiles(selectedFiles);
if (toProcess.size() != 2) {
midPointService.printToConsole(getEnvironment(), DiffLocalTask.class, "Too many files selected, should be only two.");
return;
}
VirtualFile firstFile = toProcess.get(0);
VirtualFile secondFile = toProcess.get(1);
List<MidPointObject> firstSet = loadObjects(firstFile);
if (firstSet == null) {
return;
}
List<MidPointObject> secondSet = loadObjects(secondFile);
if (secondSet == null) {
return;
}
if (firstSet.size() != secondSet.size()) {
midPointService.printToConsole(getEnvironment(), DiffLocalTask.class, "Number of objects doesn't match in selected files: " + firstSet.size() + " vs. " + secondSet.size());
return;
}
RunnableUtils.runWriteActionAndWait(() -> {
Writer writer = null;
VirtualFile vf = null;
try {
List<String> deltas = new ArrayList<>();
for (int i = 0; i < firstSet.size(); i++) {
MidPointObject first = firstSet.get(i);
MidPointObject second = secondSet.get(i);
deltas.add(createDiffXml(first, firstFile, LocationType.LOCAL, second, secondFile, LocationType.LOCAL));
}
vf = createScratchAndWriteDiff(deltas);
} catch (Exception ex) {
// failed.incrementAndGet();
//
midPointService.printToConsole(getEnvironment(), DiffLocalTask.class, "Failed to compare files " + firstFile.getPath() + " with " + secondFile.getPath(), ex);
} finally {
IOUtils.closeQuietly(writer);
}
MidPointUtils.openFile(getProject(), vf);
});
}
use of com.evolveum.midpoint.studio.client.MidPointObject 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.client.MidPointObject in project midpoint-studio by Evolveum.
the class GeneratorTask method uploadContent.
private void uploadContent(ProgressIndicator indicator, String content) {
Project project = getProject();
Environment env = getEnvironment();
updateIndicator(indicator, "Content created, uploading to " + env.getName());
MidPointService mm = MidPointService.getInstance(project);
MidPointClient client = new MidPointClient(project, env);
List<MidPointObject> objects = MidPointUtils.parseText(project, content, null, NOTIFICATION_KEY);
int fail = 0;
int success = 0;
for (MidPointObject object : objects) {
try {
OperationResult result = UploadExecuteTask.uploadExecute(client, object);
boolean problem = result != null && !result.isSuccess();
if (problem) {
fail++;
String msg = "Upload status of " + object.getName() + " was " + result.getStatus();
mm.printToConsole(env, getClass(), msg);
MidPointUtils.publishNotification(project, NOTIFICATION_KEY, "Warning", msg, NotificationType.WARNING, new ShowResultNotificationAction(result));
} else {
success++;
mm.printToConsole(env, getClass(), "Content uploaded successfuly");
}
} catch (Exception ex) {
fail++;
mm.printToConsole(env, getClass(), "Couldn't upload generated content. Reason: " + ex.getMessage());
MidPointUtils.publishExceptionNotification(project, env, GeneratorTask.class, NOTIFICATION_KEY, "Couldn't upload generated content", ex);
}
}
showNotificationAfterFinish(project, success, fail);
updateIndicator(indicator, "Content uploaded");
}
use of com.evolveum.midpoint.studio.client.MidPointObject in project midpoint-studio by Evolveum.
the class RefreshTask method processFiles.
private void processFiles(ProgressIndicator indicator, Environment env, List<VirtualFile> files) {
MidPointService mm = MidPointService.getInstance(getProject());
MidPointClient client = new MidPointClient(getProject(), env);
int current = 0;
for (VirtualFile file : files) {
ProgressManager.checkCanceled();
current++;
indicator.setFraction((double) current / files.size());
List<MidPointObject> objects = new ArrayList<>();
RunnableUtils.runWriteActionAndWait(() -> {
MidPointUtils.forceSaveAndRefresh(getProject(), file);
List<MidPointObject> obj = MidPointUtils.parseProjectFile(getProject(), file, NOTIFICATION_KEY);
obj = ClientUtils.filterObjectTypeOnly(obj);
objects.addAll(obj);
});
if (objects.isEmpty()) {
state.incrementSkipped();
mm.printToConsole(env, RefreshAction.class, "Skipped file " + file.getPath() + " no objects found (parsed).");
continue;
}
List<String> newObjects = new ArrayList<>();
for (MidPointObject object : objects) {
ProgressManager.checkCanceled();
ObjectTypes type = object.getType();
try {
MidPointObject newObject = client.get(type.getClassDefinition(), object.getOid(), new SearchOptions().raw(true));
if (newObject == null) {
state.incrementMissing();
newObjects.add(object.getContent());
mm.printToConsole(env, RefreshAction.class, "Couldn't find object " + type.getTypeQName().getLocalPart() + "(" + object.getOid() + ").");
continue;
}
newObjects.add(newObject.getContent());
state.incrementProcessed();
} catch (Exception ex) {
state.incrementFailed();
newObjects.add(object.getContent());
mm.printToConsole(env, RefreshAction.class, "Error getting object" + type.getTypeQName().getLocalPart() + "(" + object.getOid() + ")", ex);
}
}
RunnableUtils.runWriteActionAndWait(() -> {
try (Writer writer = new OutputStreamWriter(file.getOutputStream(this), file.getCharset())) {
if (newObjects.size() > 1) {
writer.write(ClientUtils.OBJECTS_XML_PREFIX);
writer.write('\n');
}
for (String obj : newObjects) {
writer.write(obj);
}
if (newObjects.size() > 1) {
writer.write(ClientUtils.OBJECTS_XML_SUFFIX);
writer.write('\n');
}
} catch (IOException ex) {
state.incrementFailed();
mm.printToConsole(env, RefreshAction.class, "Failed to write refreshed file " + file.getPath(), ex);
}
});
}
NotificationType type = state.missing > 0 || state.failed > 0 || state.skipped > 0 ? NotificationType.WARNING : NotificationType.INFORMATION;
String msg = buildFinishedNotification();
MidPointUtils.publishNotification(getProject(), NOTIFICATION_KEY, "Refresh Action", msg, type);
}
Aggregations