use of com.evolveum.midpoint.studio.client.MidPointObject 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.client.MidPointObject in project midpoint-studio by Evolveum.
the class DownloadTask method downloadByQuery.
private void downloadByQuery() {
List<VirtualFile> files = new ArrayList<>();
try {
SearchResult result = client.search(type.getClassDefinition(), query, raw);
if (result == null || result.getObjects() == null) {
return;
}
LOG.debug("Storing file");
RunnableUtils.runWriteActionAndWait(() -> {
for (MidPointObject obj : result.getObjects()) {
VirtualFile file = saveFile(obj);
if (file != null) {
files.add(file);
}
}
});
LOG.debug("Files saved");
} catch (Exception ex) {
MidPointUtils.publishExceptionNotification(getProject(), getEnvironment(), DownloadTask.class, NOTIFICATION_KEY, "Exception occurred when searching for " + type.getValue(), ex);
}
if (!files.isEmpty() && openAfterDownload) {
ApplicationManager.getApplication().invokeAndWait(() -> MidPointUtils.openFile(getProject(), files.get(0)));
}
}
use of com.evolveum.midpoint.studio.client.MidPointObject in project midpoint-studio by Evolveum.
the class ObjectsBackgroundableTask method processObjects.
protected ProcessFileObjectsResult processObjects(ProgressIndicator indicator, List<MidPointObject> objects, VirtualFile file) {
if (objects.isEmpty()) {
state.incrementSkippedFile();
midPointService.printToConsole(null, RefreshAction.class, "Skipped file " + (file != null ? file.getPath() : "<unknown>") + " no objects found (parsed).");
return new ProcessFileObjectsResult();
}
List<String> newObjects = new ArrayList<>();
boolean stop = false;
int current = 0;
for (MidPointObject object : objects) {
ProgressManager.checkCanceled();
current++;
if (indicator != null) {
indicator.setFraction((double) current / objects.size());
}
if (shouldSkipObjectProcessing(object)) {
newObjects.add(object.getContent());
state.incrementSkipped();
continue;
}
ProcessObjectResult result = processObject(object, new ExtendedCallable<>() {
@Override
public String describe() {
return object.getName() + "(" + object.getOid() + ")";
}
@Override
public ProcessObjectResult call() throws Exception {
return processObject(object);
}
});
if (!result.shouldContinue()) {
state.setStopOnError();
stop = true;
break;
}
MidPointObject newObject = result.object();
if (newObject != null) {
newObjects.add(newObject.getContent());
}
}
return new ProcessFileObjectsResult(newObjects, stop);
}
use of com.evolveum.midpoint.studio.client.MidPointObject in project midpoint-studio by Evolveum.
the class ObjectsBackgroundableTask method processFile.
protected boolean processFile(VirtualFile file) {
try {
List<MidPointObject> objects = loadObjectsFromFile(file);
ProcessFileObjectsResult result = processObjects(null, objects, file);
List<String> newObjects = result.getNewObjects();
boolean checkChanges = false;
if (objects.size() == newObjects.size()) {
for (int i = 0; i < objects.size(); i++) {
MidPointObject object = objects.get(i);
if (!Objects.equals(object.getContent(), newObjects.get(i))) {
checkChanges = true;
break;
}
}
}
if (checkChanges && isUpdateObjectAfterProcessing()) {
writeObjectsToFile(file, newObjects);
}
if (result.isStop()) {
state.incrementProcessedFile();
return false;
}
} catch (Exception ex) {
state.incrementSkippedFile();
midPointService.printToConsole(null, getClass(), "Couldn't process file " + (file != null ? file.getPath() : "<unknown>") + ", reason: " + ex.getMessage(), ex);
}
state.incrementProcessedFile();
return true;
}
use of com.evolveum.midpoint.studio.client.MidPointObject in project midpoint-studio by Evolveum.
the class VerifyAction method processFiles.
private void processFiles(AnActionEvent evt, MidPointService mm, Environment env, List<VirtualFile> files) {
ObjectValidator validator = new ObjectValidator(MidPointUtils.DEFAULT_PRISM_CONTEXT);
validator.setAllWarnings();
MidPointClient client = new MidPointClient(evt.getProject(), env);
for (VirtualFile file : files) {
RunnableUtils.runReadAction(() -> {
try {
List<MidPointObject> objects = MidPointUtils.parseProjectFile(evt.getProject(), file, NOTIFICATION_KEY);
for (MidPointObject obj : objects) {
try {
PrismObject object = client.parseObject(obj.getContent());
ValidationResult validationResult = validator.validate(object);
for (ValidationItem validationItem : validationResult.getItems()) {
String msg = buildValidationItem(object, validationItem);
mm.printToConsole(env, VerifyAction.class, msg);
}
} catch (Exception ex) {
mm.printToConsole(env, VerifyAction.class, "Couldn't parse object '" + obj.getName() + "'(" + obj.getType() + ") from file '" + file.getPath() + "', reason: " + ex.getMessage());
}
}
} catch (Exception ex) {
mm.printToConsole(env, VerifyAction.class, "Couldn't parse objects from file '" + file.getPath() + "', reason: " + ex.getMessage());
}
});
}
}
Aggregations