Search in sources :

Example 6 with MailTemplateTO

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

the class MailTemplateServiceImpl method create.

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

Example 7 with MailTemplateTO

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

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

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

the class MailTemplateLogic method getMailTemplateTO.

private MailTemplateTO getMailTemplateTO(final String key) {
    MailTemplateTO mailTemplateTO = new MailTemplateTO();
    mailTemplateTO.setKey(key);
    return mailTemplateTO;
}
Also used : MailTemplateTO(org.apache.syncope.common.lib.to.MailTemplateTO)

Example 10 with MailTemplateTO

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

the class MailTemplateLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.MAIL_TEMPLATE_DELETE + "')")
public MailTemplateTO delete(final String key) {
    MailTemplate mailTemplate = mailTemplateDAO.find(key);
    if (mailTemplate == null) {
        LOG.error("Could not find mail template '" + key + "'");
        throw new NotFoundException(key);
    }
    List<Notification> notifications = notificationDAO.findByTemplate(mailTemplate);
    if (!notifications.isEmpty()) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InUse);
        sce.getElements().addAll(notifications.stream().map(Entity::getKey).collect(Collectors.toList()));
        throw sce;
    }
    MailTemplateTO deleted = getMailTemplateTO(key);
    mailTemplateDAO.delete(key);
    return deleted;
}
Also used : Entity(org.apache.syncope.core.persistence.api.entity.Entity) MailTemplateTO(org.apache.syncope.common.lib.to.MailTemplateTO) MailTemplate(org.apache.syncope.core.persistence.api.entity.MailTemplate) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Notification(org.apache.syncope.core.persistence.api.entity.Notification) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

MailTemplateTO (org.apache.syncope.common.lib.to.MailTemplateTO)10 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)4 Test (org.junit.jupiter.api.Test)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 ReportTemplateTO (org.apache.syncope.common.lib.to.ReportTemplateTO)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 MailTemplate (org.apache.syncope.core.persistence.api.entity.MailTemplate)1 Notification (org.apache.syncope.core.persistence.api.entity.Notification)1 AddTemplateDialog (org.apache.syncope.ide.eclipse.plugin.dialogs.AddTemplateDialog)1