use of com.evolveum.midpoint.studio.impl.Environment 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.impl.Environment in project midpoint-studio by Evolveum.
the class SimpleBackgroundableTask method setupMidpointClient.
private MidPointClient setupMidpointClient() {
logToConsole("Setting up MidPoint client");
Environment env = getEnvironment();
midPointService.printToConsole(env, getClass(), "Initializing '" + getTitle() + "' action");
MidPointClient client = new MidPointClient(getProject(), env);
logToConsole("MidPoint client setup done");
return client;
}
use of com.evolveum.midpoint.studio.impl.Environment in project midpoint-studio by Evolveum.
the class BrowseToolPanel method searchPerformed.
private void searchPerformed(AnActionEvent evt, ProgressIndicator indicator) {
LOG.debug("Clearing table");
// clear result table
updateTableModel(null);
// load data
EnvironmentService em = EnvironmentService.getInstance(evt.getProject());
Environment env = em.getSelected();
indicator.setText("Searching objects in environment: " + env.getName());
SearchResultList result = null;
try {
LOG.debug("Setting up midpoint client");
MidPointClient client = new MidPointClient(evt.getProject(), env);
ObjectTypes type = objectType.getSelected();
ObjectQuery query = buildQuery(client);
LOG.debug("Starting search");
result = client.list(type.getClassDefinition(), query, rawSearch);
} catch (Exception ex) {
handleGenericException(env, "Couldn't search objects", ex);
}
LOG.debug("Updating table");
// update result table
updateTableModel(result);
}
use of com.evolveum.midpoint.studio.impl.Environment in project midpoint-studio by Evolveum.
the class BrowseToolPanel method processPerformed.
private void processPerformed(AnActionEvent evt) {
String query = this.query.getText();
ComboQueryType.Type queryType = this.queryType.getSelected();
ObjectTypes type = this.objectType.getSelected();
List<ObjectType> selected = getResultsModel().getSelectedObjects(results);
if (ComboQueryType.Type.QUERY_XML != queryType && StringUtils.isNotEmpty(query)) {
// translate query
EnvironmentService em = EnvironmentService.getInstance(evt.getProject());
Environment env = em.getSelected();
try {
LOG.debug("Setting up midpoint client");
MidPointClient client = new MidPointClient(evt.getProject(), env);
LOG.debug("Translating object query");
ObjectQuery objectQuery = buildQuery(client);
ObjectPaging paging = objectQuery.getPaging();
if (paging != null) {
// cleanup ordering, not necessary for bulk processing
paging.setOrdering(new ObjectOrdering[0]);
}
PrismContext ctx = client.getPrismContext();
QueryConverter converter = ctx.getQueryConverter();
QueryType q = converter.createQueryType(objectQuery);
RunnableUtils.PluginClassCallable<String> callable = new RunnableUtils.PluginClassCallable<>() {
@Override
public String callWithPluginClassLoader() throws Exception {
return ctx.serializerFor(PrismContext.LANG_XML).serializeRealValue(q);
}
};
query = callable.call();
} catch (Exception ex) {
handleGenericException(env, "Couldn't serialize query", ex);
}
}
ProcessResultsDialog dialog = new ProcessResultsDialog(processResultsOptions, query, type, selected);
dialog.show();
if (dialog.isOK() || dialog.isGenerate()) {
processResultsOptions = dialog.buildOptions();
performGenerate(evt, selected, processResultsOptions, !dialog.isGenerate());
}
}
use of com.evolveum.midpoint.studio.impl.Environment in project midpoint-studio by Evolveum.
the class BrowseToolPanel method createFilter.
private ObjectFilter createFilter(PrismContext ctx, boolean oid, boolean name) {
String text = query.getText();
if (StringUtils.isEmpty(text)) {
return null;
}
List<String> filtered = new ArrayList<>();
String[] items = text.split("\n");
for (String item : items) {
item = item.trim();
if (StringUtils.isEmpty(item)) {
continue;
}
filtered.add(item);
}
if (filtered.isEmpty()) {
return null;
}
QueryFactory qf = ctx.queryFactory();
OrFilter or = qf.createOr();
if (oid) {
List<String> filteredOids = filtered;
if (name) {
// if search by name or oid is used, filter out items that can't be used in oid filter
filteredOids = filteredOids.stream().filter(s -> MidPointUtils.UUID_PATTERN.matcher(s).matches()).collect(Collectors.toList());
if (filteredOids.size() != filtered.size()) {
MidPointService ms = MidPointService.getInstance(project);
EnvironmentService em = EnvironmentService.getInstance(project);
Environment env = em.getSelected();
ms.printToConsole(env, BrowseToolPanel.class, "Items in search filed that are not valid OIDs were filtered out (" + (filtered.size() - filteredOids.size()) + ").");
}
}
if (!filteredOids.isEmpty()) {
InOidFilter inOid = qf.createInOid(filteredOids);
or.addCondition(inOid);
}
}
if (name) {
PrismPropertyDefinition def = ctx.getSchemaRegistry().findPropertyDefinitionByElementName(ObjectType.F_NAME);
QName matchingRule = PrismConstants.POLY_STRING_NORM_MATCHING_RULE_NAME;
List<ObjectFilter> filters = new ArrayList<>();
for (String s : filtered) {
ObjectFilter filter = Objects.equals(nameFilterType, Constants.Q_EQUAL_Q) ? EqualFilterImpl.createEqual(ctx.path(ObjectType.F_NAME), def, matchingRule, ctx, s) : SubstringFilterImpl.createSubstring(ctx.path(ObjectType.F_NAME), def, ctx, matchingRule, s, false, false);
filters.add(filter);
}
OrFilter nameOr = qf.createOr(filters);
or.addCondition(nameOr);
}
return or;
}
Aggregations