Search in sources :

Example 1 with ReportTemplateService

use of org.apache.syncope.common.rest.api.service.ReportTemplateService in project syncope by apache.

the class SyncopeView method makeActions.

private void makeActions() {
    loginAction = new Action() {

        public void run() {
            Shell shell = viewer.getControl().getShell();
            LoginDialog dialog = new LoginDialog(shell);
            dialog.create();
            if (dialog.open() == Window.OK) {
                String deploymentUrl = dialog.getDeploymentUrl();
                String username = dialog.getUsername();
                String password = dialog.getPassword();
                vcp.deploymentUrl = deploymentUrl;
                vcp.username = username;
                vcp.password = password;
                updateTreeViewer();
            }
        }
    };
    loginAction.setText(LOGIN_ACTION_TEXT);
    loginAction.setToolTipText(LOGIN_ACTION_TOOLTIP_TEXT);
    refreshAction = new Action() {

        public void run() {
            updateTreeViewer();
        }
    };
    refreshAction.setText(REFRESH_ACTION_TEXT);
    refreshAction.setToolTipText(REFRESH_ACTION_TOOLTIP_TEXT);
    doubleClickAction = new Action() {

        public void run() {
            ISelection selection = viewer.getSelection();
            Object obj = ((IStructuredSelection) selection).getFirstElement();
            if (!(obj instanceof TreeParent)) {
                openTemplateInEditor((TreeObject) obj);
            } else {
                viewer.expandToLevel(obj, 1);
            }
        }
    };
    readAction = new Action() {

        public void run() {
            ISelection selection = viewer.getSelection();
            TreeObject obj = (TreeObject) ((IStructuredSelection) selection).getFirstElement();
            openTemplateInEditor(obj);
        }
    };
    readAction.setText(READ_ACTION_TEXT);
    addAction = new Action() {

        public void run() {
            ISelection selection = viewer.getSelection();
            TreeParent tp = (TreeParent) ((IStructuredSelection) selection).getFirstElement();
            Shell shell = viewer.getControl().getShell();
            AddTemplateDialog addTemplateDialog = new AddTemplateDialog(shell);
            addTemplateDialog.create();
            if (addTemplateDialog.open() == Window.OK) {
                String key = addTemplateDialog.getKey();
                try {
                    if (tp.getName().equals(MAIL_TEMPLATE_LABEL)) {
                        MailTemplateService mailTemplateService = SYNCOPE_CLIENT.getService(MailTemplateService.class);
                        MailTemplateTO mtto = new MailTemplateTO();
                        mtto.setKey(key);
                        mailTemplateService.create(mtto);
                    } else if (tp.getName().equals(REPORT_TEMPLATE_LABEL)) {
                        ReportTemplateService reportTemplateService = SYNCOPE_CLIENT.getService(ReportTemplateService.class);
                        ReportTemplateTO rtto = new ReportTemplateTO();
                        rtto.setKey(key);
                        reportTemplateService.create(rtto);
                    }
                    updateTreeViewer();
                } catch (final SyncopeClientException e) {
                    if (e.toString().contains("EntityExists")) {
                        MessageDialog.openError(shell, "Template already exists", "A template named " + key + " already exists.");
                    }
                }
            }
        }
    };
    addAction.setText(ADD_ACTION_TEXT);
    removeAction = new Action() {

        public void run() {
            ISelection selection = viewer.getSelection();
            TreeObject obj = (TreeObject) ((IStructuredSelection) selection).getFirstElement();
            TreeParent tp = (TreeParent) vcp.getParent(obj);
            if (MAIL_TEMPLATE_LABEL.equals(tp.getName())) {
                MailTemplateService mailTemplateService = SYNCOPE_CLIENT.getService(MailTemplateService.class);
                mailTemplateService.delete(obj.getName());
            } else if (tp.getName().equals(REPORT_TEMPLATE_LABEL)) {
                ReportTemplateService reportTemplateService = SYNCOPE_CLIENT.getService(ReportTemplateService.class);
                reportTemplateService.delete(obj.getName());
            }
            updateTreeViewer();
        }
    };
    removeAction.setText(REMOVE_ACTION_TEXT);
}
Also used : ReportTemplateService(org.apache.syncope.common.rest.api.service.ReportTemplateService) Action(org.eclipse.jface.action.Action) AddTemplateDialog(org.apache.syncope.ide.eclipse.plugin.dialogs.AddTemplateDialog) ReportTemplateTO(org.apache.syncope.common.lib.to.ReportTemplateTO) MailTemplateService(org.apache.syncope.common.rest.api.service.MailTemplateService) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Shell(org.eclipse.swt.widgets.Shell) MailTemplateTO(org.apache.syncope.common.lib.to.MailTemplateTO) ISelection(org.eclipse.jface.viewers.ISelection) LoginDialog(org.apache.syncope.ide.eclipse.plugin.dialogs.LoginDialog)

Example 2 with ReportTemplateService

use of org.apache.syncope.common.rest.api.service.ReportTemplateService in project syncope by apache.

the class SyncopeView method setReportTemplateContent.

public static void setReportTemplateContent(final String key, final ReportTemplateFormat format, final String content) {
    ReportTemplateService reportTemplateService = SYNCOPE_CLIENT.getService(ReportTemplateService.class);
    reportTemplateService.setFormat(key, format, new ByteArrayInputStream(content.getBytes()));
}
Also used : ReportTemplateService(org.apache.syncope.common.rest.api.service.ReportTemplateService) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 3 with ReportTemplateService

use of org.apache.syncope.common.rest.api.service.ReportTemplateService in project syncope by apache.

the class SyncopeView method openTemplateInEditor.

protected void openTemplateInEditor(final TreeObject obj) {
    TreeParent tp = (TreeParent) vcp.getParent(obj);
    if (MAIL_TEMPLATE_LABEL.equals(tp.getName())) {
        final MailTemplateService mailTemplateService = SYNCOPE_CLIENT.getService(MailTemplateService.class);
        final String[] templateData = new String[2];
        final String[] editorTitles = { TEMPLATE_FORMAT_HTML, TEMPLATE_FORMAT_TEXT };
        final String[] editorToolTips = { obj.getName(), obj.getName() };
        Job job = new Job(LOADING_TEMPLATE_FORMAT_LABEL) {

            @Override
            protected IStatus run(final IProgressMonitor arg0) {
                templateData[0] = getStringFromTemplate(mailTemplateService, obj.getName(), MailTemplateFormat.HTML);
                templateData[1] = getStringFromTemplate(mailTemplateService, obj.getName(), MailTemplateFormat.TEXT);
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            getViewSite().getPage().openEditor(new TemplateEditorInput(templateData, editorTitles, editorToolTips), TemplateEditor.ID);
                        } catch (final PartInitException e) {
                            e.printStackTrace();
                        }
                    }
                });
                return Status.OK_STATUS;
            }

            private String getStringFromTemplate(final MailTemplateService mailTemplateService, final String name, final MailTemplateFormat format) {
                try {
                    InputStream inpstream = (InputStream) (mailTemplateService.getFormat(name, format)).getEntity();
                    Scanner sc = new Scanner(inpstream);
                    String templateContent = sc.nextLine();
                    while (sc.hasNext()) {
                        templateContent += "\n" + sc.nextLine();
                    }
                    sc.close();
                    return (templateContent);
                } catch (final SyncopeClientException e) {
                    if (ClientExceptionType.NotFound.equals(e.getType())) {
                        return "";
                    }
                }
                return null;
            }
        };
        job.setUser(true);
        job.schedule();
    } else if (tp.getName().equals(REPORT_TEMPLATE_LABEL)) {
        final ReportTemplateService reportTemplateService = SYNCOPE_CLIENT.getService(ReportTemplateService.class);
        final String[] templateData = new String[3];
        final String[] editorTitles = { TEMPLATE_FORMAT_CSV, TEMPLATE_FORMAT_XSL_FO, TEMPLATE_FORMAT_XSL_HTML };
        final String[] editorToolTips = { obj.getName(), obj.getName(), obj.getName() };
        Job job = new Job(LOADING_TEMPLATE_FORMAT_LABEL) {

            @Override
            protected IStatus run(final IProgressMonitor arg0) {
                templateData[0] = getStringFromTemplate(reportTemplateService, obj.getName(), ReportTemplateFormat.CSV);
                templateData[1] = getStringFromTemplate(reportTemplateService, obj.getName(), ReportTemplateFormat.FO);
                templateData[2] = getStringFromTemplate(reportTemplateService, obj.getName(), ReportTemplateFormat.HTML);
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            getViewSite().getPage().openEditor(new TemplateEditorInput(templateData, editorTitles, editorToolTips), TemplateEditor.ID);
                        } catch (final PartInitException e) {
                            e.printStackTrace();
                        }
                    }
                });
                return Status.OK_STATUS;
            }

            private String getStringFromTemplate(final ReportTemplateService reportTemplateService, final String name, final ReportTemplateFormat format) {
                try {
                    InputStream inpstream = (InputStream) (reportTemplateService.getFormat(name, format)).getEntity();
                    Scanner sc = new Scanner(inpstream);
                    String templateContent = sc.nextLine();
                    while (sc.hasNext()) {
                        templateContent += "\n" + sc.nextLine();
                    }
                    sc.close();
                    return (templateContent);
                } catch (final SyncopeClientException e) {
                    if (ClientExceptionType.NotFound.equals(e.getType())) {
                        return "";
                    }
                }
                return null;
            }
        };
        job.setUser(true);
        job.schedule();
    }
}
Also used : ReportTemplateService(org.apache.syncope.common.rest.api.service.ReportTemplateService) Scanner(java.util.Scanner) IStatus(org.eclipse.core.runtime.IStatus) MailTemplateService(org.apache.syncope.common.rest.api.service.MailTemplateService) ReportTemplateFormat(org.apache.syncope.common.lib.types.ReportTemplateFormat) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) TemplateEditorInput(org.apache.syncope.ide.eclipse.plugin.editors.TemplateEditorInput) MailTemplateFormat(org.apache.syncope.common.lib.types.MailTemplateFormat) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PartInitException(org.eclipse.ui.PartInitException) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

ReportTemplateService (org.apache.syncope.common.rest.api.service.ReportTemplateService)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)2 MailTemplateService (org.apache.syncope.common.rest.api.service.MailTemplateService)2 InputStream (java.io.InputStream)1 Scanner (java.util.Scanner)1 MailTemplateTO (org.apache.syncope.common.lib.to.MailTemplateTO)1 ReportTemplateTO (org.apache.syncope.common.lib.to.ReportTemplateTO)1 MailTemplateFormat (org.apache.syncope.common.lib.types.MailTemplateFormat)1 ReportTemplateFormat (org.apache.syncope.common.lib.types.ReportTemplateFormat)1 AddTemplateDialog (org.apache.syncope.ide.eclipse.plugin.dialogs.AddTemplateDialog)1 LoginDialog (org.apache.syncope.ide.eclipse.plugin.dialogs.LoginDialog)1 TemplateEditorInput (org.apache.syncope.ide.eclipse.plugin.editors.TemplateEditorInput)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Job (org.eclipse.core.runtime.jobs.Job)1 Action (org.eclipse.jface.action.Action)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Shell (org.eclipse.swt.widgets.Shell)1