Search in sources :

Example 6 with CompiledGuiProfile

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);
}
Also used : Referencable(com.evolveum.midpoint.prism.Referencable) CSVDataExporter(org.apache.wicket.extensions.markup.html.repeater.data.table.export.CSVDataExporter) IModel(org.apache.wicket.model.IModel) OutputStream(java.io.OutputStream) IDataProvider(org.apache.wicket.markup.repeater.data.IDataProvider) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) BaseSortableDataProvider(com.evolveum.midpoint.web.component.data.BaseSortableDataProvider) SelectableBeanContainerDataProvider(com.evolveum.midpoint.web.component.data.SelectableBeanContainerDataProvider) AjaxIconButton(com.evolveum.midpoint.web.component.AjaxIconButton) ArrayList(java.util.ArrayList) List(java.util.List) ExportingPanel(com.evolveum.midpoint.web.component.dialog.ExportingPanel) AbstractAjaxDownloadBehavior(com.evolveum.midpoint.web.component.AbstractAjaxDownloadBehavior) CompiledGuiProfile(com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile)

Example 7 with CompiledGuiProfile

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);
    });
}
Also used : ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) GuiProfiledPrincipal(com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal) IOException(java.io.IOException) ByteArrayResource(org.apache.wicket.request.resource.ByteArrayResource) CompiledGuiProfile(com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile) URL(java.net.URL)

Example 8 with CompiledGuiProfile

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;
}
Also used : CompiledObjectCollectionView(com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView) CompiledGuiProfile(com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile)

Example 9 with CompiledGuiProfile

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;
}
Also used : CompiledGuiProfile(com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile)

Example 10 with CompiledGuiProfile

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;
}
Also used : MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) Task(com.evolveum.midpoint.task.api.Task) PageTask(com.evolveum.midpoint.web.page.admin.server.PageTask) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CompiledGuiProfile(com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile)

Aggregations

CompiledGuiProfile (com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile)19 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)9 Task (com.evolveum.midpoint.task.api.Task)6 PrismObject (com.evolveum.midpoint.prism.PrismObject)4 Test (org.testng.annotations.Test)4 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)3 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)3 CompiledObjectCollectionView (com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView)2 GuiProfiledPrincipal (com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal)2 ArrayList (java.util.ArrayList)2 RestartResponseException (org.apache.wicket.RestartResponseException)2 ReadOnlyModel (com.evolveum.midpoint.gui.api.model.ReadOnlyModel)1 AssignmentHolderDetailsModel (com.evolveum.midpoint.gui.impl.page.admin.assignmentholder.AssignmentHolderDetailsModel)1 ModelInteractionService (com.evolveum.midpoint.model.api.ModelInteractionService)1 LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)1 Referencable (com.evolveum.midpoint.prism.Referencable)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)1 ExpressionFactory (com.evolveum.midpoint.repo.common.expression.ExpressionFactory)1 VariablesMap (com.evolveum.midpoint.schema.expression.VariablesMap)1