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