Search in sources :

Example 6 with ReportTemplateTO

use of org.apache.syncope.common.lib.to.ReportTemplateTO 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 7 with ReportTemplateTO

use of org.apache.syncope.common.lib.to.ReportTemplateTO in project syncope by apache.

the class ResourceExplorerTopComponent method folderRightClickAction.

private void folderRightClickAction(final MouseEvent evt, final DefaultMutableTreeNode node) {
    JPopupMenu menu = new JPopupMenu();
    JMenuItem addItem = new JMenuItem("New");
    menu.add(addItem);
    addItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            String name = JOptionPane.showInputDialog("Enter Name");
            boolean added = false;
            if (!"exit".equals(e.getActionCommand())) {
                if (node.getUserObject().equals(PluginConstants.MAIL_TEMPLATES)) {
                    MailTemplateTO mailTemplate = new MailTemplateTO();
                    mailTemplate.setKey(name);
                    added = mailTemplateManagerService.create(mailTemplate);
                    mailTemplateManagerService.setFormat(name, MailTemplateFormat.HTML, IOUtils.toInputStream("//Enter Content here", encodingPattern));
                    mailTemplateManagerService.setFormat(name, MailTemplateFormat.TEXT, IOUtils.toInputStream("//Enter Content here", encodingPattern));
                    try {
                        openMailEditor(name);
                    } catch (IOException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                } else {
                    ReportTemplateTO reportTemplate = new ReportTemplateTO();
                    reportTemplate.setKey(name);
                    added = reportTemplateManagerService.create(reportTemplate);
                    reportTemplateManagerService.setFormat(name, ReportTemplateFormat.FO, IOUtils.toInputStream("//Enter content here", encodingPattern));
                    reportTemplateManagerService.setFormat(name, ReportTemplateFormat.CSV, IOUtils.toInputStream("//Enter content here", encodingPattern));
                    reportTemplateManagerService.setFormat(name, ReportTemplateFormat.HTML, IOUtils.toInputStream("//Enter content here", encodingPattern));
                    try {
                        openReportEditor(name);
                    } catch (IOException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                }
                if (added) {
                    node.add(new DefaultMutableTreeNode(name));
                    treeModel.reload(node);
                } else {
                    JOptionPane.showMessageDialog(null, "Error while creating new element", "Error", JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    });
    menu.show(evt.getComponent(), evt.getX(), evt.getY());
}
Also used : MailTemplateTO(org.apache.syncope.common.lib.to.MailTemplateTO) ReportTemplateTO(org.apache.syncope.common.lib.to.ReportTemplateTO) ActionListener(java.awt.event.ActionListener) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ActionEvent(java.awt.event.ActionEvent) IOException(java.io.IOException) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu)

Example 8 with ReportTemplateTO

use of org.apache.syncope.common.lib.to.ReportTemplateTO in project syncope by apache.

the class ResourceExplorerTopComponent method addReportXslts.

private void addReportXslts() {
    List<ReportTemplateTO> reportTemplates = reportTemplateManagerService.list();
    for (ReportTemplateTO reportTemplate : reportTemplates) {
        reportXslts.add(new DefaultMutableTreeNode(reportTemplate.getKey()));
    }
    treeModel.reload();
}
Also used : ReportTemplateTO(org.apache.syncope.common.lib.to.ReportTemplateTO) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 9 with ReportTemplateTO

use of org.apache.syncope.common.lib.to.ReportTemplateTO in project syncope by apache.

the class ReportTemplateServiceImpl method create.

@Override
public Response create(final ReportTemplateTO reportTemplateTO) {
    ReportTemplateTO created = logic.create(reportTemplateTO.getKey());
    URI location = uriInfo.getAbsolutePathBuilder().path(created.getKey()).build();
    return Response.created(location).header(RESTHeaders.RESOURCE_KEY, created.getKey()).build();
}
Also used : ReportTemplateTO(org.apache.syncope.common.lib.to.ReportTemplateTO) URI(java.net.URI)

Example 10 with ReportTemplateTO

use of org.apache.syncope.common.lib.to.ReportTemplateTO in project syncope by apache.

the class ReportTemplateLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.REPORT_TEMPLATE_DELETE + "')")
public ReportTemplateTO delete(final String key) {
    ReportTemplate reportTemplate = reportTemplateDAO.find(key);
    if (reportTemplate == null) {
        LOG.error("Could not find report template '" + key + "'");
        throw new NotFoundException(key);
    }
    List<Report> reports = reportDAO.findByTemplate(reportTemplate);
    if (!reports.isEmpty()) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InUse);
        sce.getElements().addAll(reports.stream().map(Entity::getKey).collect(Collectors.toList()));
        throw sce;
    }
    ReportTemplateTO deleted = getReportTemplateTO(key);
    reportTemplateDAO.delete(key);
    return deleted;
}
Also used : Entity(org.apache.syncope.core.persistence.api.entity.Entity) ReportTemplateTO(org.apache.syncope.common.lib.to.ReportTemplateTO) Report(org.apache.syncope.core.persistence.api.entity.Report) ReportTemplate(org.apache.syncope.core.persistence.api.entity.ReportTemplate) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ReportTemplateTO (org.apache.syncope.common.lib.to.ReportTemplateTO)10 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)4 Test (org.junit.jupiter.api.Test)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 MailTemplateTO (org.apache.syncope.common.lib.to.MailTemplateTO)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1 Response (javax.ws.rs.core.Response)1 MailTemplateService (org.apache.syncope.common.rest.api.service.MailTemplateService)1 ReportTemplateService (org.apache.syncope.common.rest.api.service.ReportTemplateService)1 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)1 Entity (org.apache.syncope.core.persistence.api.entity.Entity)1 Report (org.apache.syncope.core.persistence.api.entity.Report)1 ReportTemplate (org.apache.syncope.core.persistence.api.entity.ReportTemplate)1 AddTemplateDialog (org.apache.syncope.ide.eclipse.plugin.dialogs.AddTemplateDialog)1