use of com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile in project midpoint by Evolveum.
the class CsvDownloadButtonPanel method initLayout.
private void initLayout() {
CSVDataExporter csvDataExporter = new CSVDataExporter() {
private static final long serialVersionUID = 1L;
@Override
public <T> void exportData(IDataProvider<T> dataProvider, List<IExportableColumn<T, ?>> columns, OutputStream outputStream) {
if (dataProvider instanceof SelectableBeanContainerDataProvider) {
// TODO implement more nicely
((SelectableBeanContainerDataProvider) dataProvider).setExport(true);
}
try {
((BaseSortableDataProvider) dataProvider).setExportSize(true);
super.exportData(dataProvider, getExportableColumns(), outputStream);
((BaseSortableDataProvider) dataProvider).setExportSize(false);
} catch (Exception ex) {
LOGGER.error("Unable to export data,", ex);
} finally {
if (dataProvider instanceof SelectableBeanContainerDataProvider) {
((SelectableBeanContainerDataProvider) dataProvider).setExport(false);
}
}
}
@Override
protected <T> IModel<T> wrapModel(IModel<T> model) {
if (model.getObject() == null) {
return () -> (T) "";
}
if (model.getObject() instanceof Referencable) {
return () -> {
String value = WebModelServiceUtils.resolveReferenceName((Referencable) model.getObject(), getPageBase());
return (T) (value == null ? "" : value);
};
}
return super.wrapModel(model);
}
};
IModel<String> name = Model.of("");
final AbstractAjaxDownloadBehavior ajaxDownloadBehavior = new AbstractAjaxDownloadBehavior() {
private static final long serialVersionUID = 1L;
@Override
public IResourceStream getResourceStream() {
return new ExportToolbar.DataExportResourceStreamWriter(csvDataExporter, getDataTable());
}
public String getFileName() {
if (StringUtils.isEmpty(name.getObject())) {
return CsvDownloadButtonPanel.this.getFilename();
}
return name.getObject();
}
};
add(ajaxDownloadBehavior);
AjaxIconButton exportDataLink = new AjaxIconButton(ID_EXPORT_DATA, new Model<>("fa fa-download"), createStringResource("CsvDownloadButtonPanel.export")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
long exportSizeLimit = -1;
try {
CompiledGuiProfile adminGuiConfig = getPageBase().getCompiledGuiProfile();
if (adminGuiConfig.getDefaultExportSettings() != null && adminGuiConfig.getDefaultExportSettings().getSizeLimit() != null) {
exportSizeLimit = adminGuiConfig.getDefaultExportSettings().getSizeLimit();
}
} catch (Exception ex) {
LOGGER.error("Unable to get csv export size limit,", ex);
}
boolean askForSizeLimitConfirmation;
if (exportSizeLimit < 0) {
askForSizeLimitConfirmation = false;
} else {
if (canCountBeforeExporting) {
IDataProvider<?> dataProvider = getDataTable().getDataProvider();
long size = dataProvider.size();
askForSizeLimitConfirmation = size > exportSizeLimit;
} else {
// size is unknown
askForSizeLimitConfirmation = true;
}
}
Long useExportSizeLimit = null;
if (askForSizeLimitConfirmation) {
useExportSizeLimit = exportSizeLimit;
}
exportableColumnsIndex.clear();
ExportingPanel exportingPanel = new ExportingPanel(getPageBase().getMainPopupBodyId(), getDataTable(), exportableColumnsIndex, useExportSizeLimit, name) {
private static final long serialVersionUID = 1L;
@Override
public void exportPerformed(AjaxRequestTarget target) {
ajaxDownloadBehavior.initiate(target);
}
};
getPageBase().showMainPopup(exportingPanel, target);
}
};
add(exportDataLink);
}
use of com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile in project midpoint by Evolveum.
the class UserMenuPanel method loadJpegPhotoModel.
private IModel<AbstractResource> loadJpegPhotoModel() {
return new ReadOnlyModel<>(() -> {
GuiProfiledPrincipal principal = AuthUtil.getPrincipalUser();
if (principal == null) {
return null;
}
CompiledGuiProfile profile = principal.getCompiledGuiProfile();
byte[] jpegPhoto = profile.getJpegPhoto();
if (jpegPhoto == null) {
URL placeholder = UserMenuPanel.class.getClassLoader().getResource("static/img/placeholder.png");
if (placeholder == null) {
return null;
}
try {
jpegPhoto = IOUtils.toByteArray(placeholder);
} catch (IOException e) {
LOGGER.error("Cannot load placeholder for photo.");
return null;
}
}
return new ByteArrayResource("image/jpeg", jpegPhoto);
});
}
use of com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile in project midpoint by Evolveum.
the class WebComponentUtil method isRefreshEnabled.
public static boolean isRefreshEnabled(PageBase pageBase, QName type) {
CompiledGuiProfile cup = pageBase.getCompiledGuiProfile();
if (cup == null) {
return false;
}
List<CompiledObjectCollectionView> views = cup.getObjectCollectionViews();
if (CollectionUtils.isEmpty(views)) {
return false;
}
for (CompiledObjectCollectionView view : views) {
if (QNameUtil.match(type, view.getContainerType())) {
if (view.getRefreshInterval() != null) {
return true;
}
}
}
return false;
}
use of com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile in project midpoint by Evolveum.
the class ObjectTabVisibleBehavior method isVisible.
@Override
public boolean isVisible() {
PrismObject<O> object = objectModel.getObject();
if (object == null) {
return true;
}
CompiledGuiProfile config = pageBase.getCompiledGuiProfile();
// find all object form definitions for specified type, if there is none we'll show all default tabs
List<ObjectFormType> forms = findObjectForm(config, object);
if (forms.isEmpty()) {
return true;
}
// we'll try to find includeDefault, if there is includeDefault=true, we can return true (all tabs visible)
for (ObjectFormType form : forms) {
if (BooleanUtils.isTrue(form.isIncludeDefaultForms())) {
return true;
}
}
for (ObjectFormType form : forms) {
FormSpecificationType spec = form.getFormSpecification();
if (spec == null || StringUtils.isEmpty(spec.getPanelUri())) {
continue;
}
if (Objects.equals(uiAuthorizationUrl, spec.getPanelUri())) {
return true;
}
}
return false;
}
use of com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile in project midpoint by Evolveum.
the class WebComponentUtil method isNewDesignEnabled.
public static boolean isNewDesignEnabled() {
MidPointApplication app = MidPointApplication.get();
ModelInteractionService service = app.getModelInteractionService();
Task task = app.createSimpleTask("get compiledGui profile");
OperationResult result = task.getResult();
try {
CompiledGuiProfile compiledGuiProfile = service.getCompiledGuiProfile(task, result);
return compiledGuiProfile.isUseNewDesign();
} catch (Throwable e) {
LOGGER.error("Cannot get compiled gui profile, {}", e.getMessage(), e);
}
// if somthing happen just return true, by default we want new design
return true;
}
Aggregations