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();
}
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);
}
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());
}
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;
}
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;
}
Aggregations